etp::define_content_type (public)

 etp::define_content_type content_type pretty_name pretty_plural \
    attribute_metadata

Defined in packages/edit-this-page/tcl/etp-procs.tcl

Call this at server startup time to register the extended page attributes for a particular content type. It ensures that there is a corresponding entry in acs_object_types for the content type, and that for each of the extended page attributes given there is an appropriate entry in acs_attributes. Also, a namespace variable stores all extended page attributes in memory data structure for quick retrieval.

Extended page attribute values are stored in the acs_attribute_values table (so-called "generic" storage) to prevent the necessity of creating a table for each content type. This is the reason we're not using the attribute procs defined in the acs-subsite package, as they only support type-specific storage.

NOTE: get the attribute metadata right the first time. If you decide to add a new attribute to an existing object type, the procedure will create it for you. But it won't process updates to existing attributes or remove them. You'll have to do that by hand.

Parameters:
content_type - The content type you're registering. This name must be unique across all pages that must store extended page attributes.
pretty_name - The display name for the content type
pretty_plural - The plural form of the display name
attribute_metadata - A list of records describing each extended page attribute. Each record is a list containing the following values (in sequence):
  • attribute_name
  • pretty_name
  • pretty_plural
  • datatype (must be one of the entries in acs_datatypes: string, boolean, number, integer, date, etc.)
  • html (a string containing html attributes for the input control. useful attributes are "size=X" to specify the size of standard input controls, and "rows=X cols=X" to specify the size of a textarea. Textareas will be used only if the datatype is string and html specifies rows or cols.)
  • default_value (can either be a string denoting a single default value, or the name of a callback function you've defined in the etp namespace which is used to provide values for select lists).
# TODO: other features are needed such as making an attribute optional # and also specifying options for select lists.
Author:
Luke Pond
Created:
2001-05-31

Partial Call Graph (max 5 caller/called nodes):
%3 etp::make_content_type etp::make_content_type (public) etp::define_content_type etp::define_content_type etp::make_content_type->etp::define_content_type packages/edit-this-page/tcl/etp-init.tcl packages/edit-this-page/ tcl/etp-init.tcl packages/edit-this-page/tcl/etp-init.tcl->etp::define_content_type db_0or1row db_0or1row (public) etp::define_content_type->db_0or1row db_exec_plsql db_exec_plsql (public) etp::define_content_type->db_exec_plsql etp::create_search_impl etp::create_search_impl (public) etp::define_content_type->etp::create_search_impl

Testcases:
No testcase defined.
Source code:
    variable content_types
    if {![info exists content_types]} {
    array set content_types [list]
    }

    # probably should use content_type functions instead
    # DaveB
    # anyway we make sure new types are children of etp_page_revision
    # ensure an entry in acs_object_types
    
    if { ![db_0or1row object_type_exists ""] } {
    db_exec_plsql object_type_create ""
    }

    set attribute_metadata_with_ids [list]

    # for each attribute, ensure an entry in acs_attributes
    foreach attribute $attribute_metadata {
    if {[llength $attribute] != 6} {
        ns_log Error "etp::define_content_type ($content_type) failed:
        attribute_metadata record has incorrect format"
        return
    }

    lassign $attribute a_name a_pretty_name a_pretty_plural a_datatype a_html a_default

    if { ![db_0or1row attribute_exists ""] } {
        set attribute_id [db_exec_plsql attribute_create ""]
    }
    lappend attribute $attribute_id
    lappend attribute_metadata_with_ids $attribute    
    }

    set content_types($content_type$attribute_metadata_with_ids
    # add service contract implementations for content_type if necessary
    # creates search service contract implementation if it doesn't
    # already exist
    etp::create_search_impl -content_type $content_type
Generic XQL file:
<fullquery name="etp::define_content_type.object_type_exists">
    <querytext>
	select 1 from acs_object_types
	 where object_type = :content_type
</querytext>
</fullquery>

<fullquery name="etp::define_content_type.attribute_exists">
    <querytext>
	    select attribute_id from acs_attributes
	     where object_type = :content_type
	       and attribute_name = :a_name
</querytext>
</fullquery>
packages/edit-this-page/tcl/etp-procs.xql

PostgreSQL XQL file:
<fullquery name="etp::define_content_type.object_type_create">
    <querytext>
	    select acs_object_type__create_type (
	        :content_type,
	        :pretty_name,
	        :pretty_plural,
	        'etp_page_revision',
	        null,
	        null,
	        null,
	        'f',
	        null,
	        null
	    )
</querytext>
</fullquery>

<fullquery name="etp::define_content_type.attribute_create">
    <querytext>
		select acs_attribute__create_attribute (
		    :content_type,
		    :a_name,
		    :a_datatype,
		    :a_pretty_name,
		    :a_pretty_plural,
		    null,
		    null,
		    :a_default,
		    1,
		    1,
		    null,
		    'generic',
		    'f'
		)
</querytext>
</fullquery>
packages/edit-this-page/tcl/etp-procs-postgresql.xql

Oracle XQL file:
<fullquery name="etp::define_content_type.object_type_create">
    <querytext>
	begin
	    acs_object_type.create_type (
	        object_type    => :content_type,
	        pretty_name    => :pretty_name,
	        pretty_plural  => :pretty_plural,
	        supertype      => 'content_revision',
	        table_name     => :content_type,
	        id_column      => :content_type
	    );
	end;
</querytext>
</fullquery>

<fullquery name="etp::define_content_type.attribute_create">
    <querytext>
	begin
		:1 := acs_attribute.create_attribute (
		    object_type      => :content_type,
		    attribute_name   => :a_name,
		    datatype         => :a_datatype,
		    pretty_name      => :a_pretty_name,
		    pretty_plural    => :a_pretty_plural,
		    default_value    => :a_default,
		    min_n_values     => 1,
		    max_n_values     => 1,
		    storage          => 'generic'
		);
	end;
</querytext>
</fullquery>
packages/edit-this-page/tcl/etp-procs-oracle.xql

[ hide source ] | [ make this the default ]
Show another procedure: