Index: openacs-4/packages/dotlrn/sql/oracle/dotlrn-init.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/sql/oracle/dotlrn-init.sql,v diff -u -r1.20 -r1.21 --- openacs-4/packages/dotlrn/sql/oracle/dotlrn-init.sql 28 Apr 2002 04:08:41 -0000 1.20 +++ openacs-4/packages/dotlrn/sql/oracle/dotlrn-init.sql 20 May 2002 21:39:37 -0000 1.21 @@ -14,84 +14,223 @@ -- details. -- - -- -- The DotLRN basic system --- copyright 2001, OpenForce, Inc. --- distributed under the GNU GPL v2 -- --- for Oracle 8/8i. (We're guessing 9i works, too). +-- @author Ben Adida (ben@openforce.net) +-- @creation-date 2001-09-25 +-- @version $Id$ -- --- ben@openforce.net --- September 25th, 2001 --- we remember September 11th, 2001 +-- @note We remember September 11th, 2001 -- declare foo dotlrn_community_types.community_type%TYPE; + bar integer; begin - -- Create the base community type - foo := dotlrn_community_type.new ( + + -- create the base community type + foo := dotlrn_community_type.new( community_type => 'dotlrn_community', parent_type => null, pretty_name => 'Community', pretty_plural => 'Communities', description => 'Communities - the base community type' ); + update acs_object_types + set table_name = 'dotlrn_community', + package_name = 'dotlrn_community' + where object_type = 'dotlrn_community'; + + -- these are the possible attributes of a community + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'header_font', + datatype => 'string', + pretty_name => 'Header Font', + pretty_plural => 'Header Fonts', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); + + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'header_font_size', + datatype => 'string', + pretty_name => 'Header Font Size', + pretty_plural => 'Header Font Sizes', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); + + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'header_font_color', + datatype => 'string', + pretty_name => 'Header Font Color', + pretty_plural => 'Header Font Colors', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); + + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'header_logo_item_id', + datatype => 'integer', + pretty_name => 'Header Logo Item ID', + pretty_plural => 'Header Logo Item ID', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); + -- create the dotlrn_class community type - foo := dotlrn_community_type.new ( + foo := dotlrn_community_type.new( community_type => 'dotlrn_class_instance', parent_type => 'dotlrn_community', pretty_name => 'Class', pretty_plural => 'Classes', description => 'e.g. 6.001' ); + update acs_object_types + set table_name = 'dotlrn_class_instance', + package_name = 'dotlrn_class_instance' + where object_type = 'dotlrn_class_instance'; + -- create the dotlrn_club community type - foo := dotlrn_community_type.new ( + foo := dotlrn_community_type.new( community_type => 'dotlrn_club', parent_type => 'dotlrn_community', pretty_name => 'Club', pretty_plural => 'Clubs', description => 'e.g. Alumni' ); + update acs_object_types + set table_name = 'dotlrn_club', + package_name = 'dotlrn_club' + where object_type = 'dotlrn_club'; + -- create the user_workspace community_type -- aks - it's a hack for portal templates - foo := dotlrn_community_type.new ( + foo := dotlrn_community_type.new( community_type => 'user_workspace', parent_type => 'dotlrn_community', pretty_name => 'User Workspace', pretty_plural => 'User Workspaces', description => 'dummy type for User Workspace portal templates' ); + -- create roles + acs_rel_type.create_role( + role => 'student', + pretty_name => 'Student', + pretty_plural => 'Students' + ); - update acs_object_types set table_name = 'dotlrn_community', package_name = 'dotlrn_community' where object_type = 'dotlrn_community'; - update acs_object_types set table_name = 'dotlrn_class_instance', package_name = 'dotlrn_class_instance' where object_type = 'dotlrn_class_instance'; - update acs_object_types set table_name = 'dotlrn_club', package_name = 'dotlrn_club' where object_type = 'dotlrn_club'; + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'student_role_pretty_name', + datatype => 'string', + pretty_name => 'Student Role Pretty Name', + pretty_plural => 'Student Role Pretty Names', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); - -- create roles - acs_rel_type.create_role ('student', 'Student', 'Students'); - acs_rel_type.create_role ('course_assistant', 'Course Assistant', 'Course Assistants'); - acs_rel_type.create_role ('teaching_assistant', 'Teaching Assistant', 'Teaching Assistants'); - acs_rel_type.create_role ('instructor', 'Professor', 'Professors'); - acs_rel_type.create_role ('course_admin', 'Course Administrator', 'Course Administrators'); - acs_rel_type.create_role ('admin', 'Administrator', 'Administrators'); -end; -/ -show errors + acs_rel_type.create_role( + role => 'course_assistant', + pretty_name => 'Course Assistant', + pretty_plural => 'Course Assistants' + ); + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'coure_assistant_role_pretty_name', + datatype => 'string', + pretty_name => 'Course Assistant Role Pretty Name', + pretty_plural => 'Course Assistant Role Pretty Names', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); --- --- Object Types and Attributes --- + acs_rel_type.create_role( + role => 'teaching_assistant', + pretty_name => 'Teaching Assistant', + pretty_plural => 'Teaching Assistants' + ); -declare - foo integer; -begin - acs_rel_type.create_type ( + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'teaching_assistant_role_pretty_name', + datatype => 'string', + pretty_name => 'Teaching Assistant Role Pretty Name', + pretty_plural => 'Teaching Assistant Role Pretty Names', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); + + acs_rel_type.create_role( + role => 'instructor', + pretty_name => 'Professor', + pretty_plural => 'Professors' + ); + + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'instructor_role_pretty_name', + datatype => 'string', + pretty_name => 'Professor Role Pretty Name', + pretty_plural => 'Professor Role Pretty Names', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); + + acs_rel_type.create_role( + role => 'course_admin', + pretty_name => 'Course Administrator', + pretty_plural => 'Course Administrators' + ); + + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'course_admin_role_pretty_name', + datatype => 'string', + pretty_name => 'Course Adminsitrator Role Pretty Name', + pretty_plural => 'Course Adminsitrator Role Pretty Names', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); + + acs_rel_type.create_role( + role => 'admin', + pretty_name => 'Administrator', + pretty_plural => 'Administrators' + ); + + bar := acs_attribute.create_attribute( + object_type => 'dotlrn_community', + attribute_name => 'admin_role_pretty_name', + datatype => 'string', + pretty_name => 'Administrator Role Pretty Name', + pretty_plural => 'RAdministrator ole Pretty Names', + min_n_values => 0, + max_n_values => 1, + storage => 'generic' + ); + + -- create basic rel_types + acs_rel_type.create_type( rel_type => 'dotlrn_member_rel', supertype => 'membership_rel', pretty_name => 'dotLRN Community Membership', @@ -105,7 +244,7 @@ min_n_rels_two => 0, max_n_rels_two => null ); - acs_rel_type.create_type ( + acs_rel_type.create_type( rel_type => 'dotlrn_admin_rel', supertype => 'dotlrn_member_rel', pretty_name => 'dotLRN Admin Community Membership', @@ -119,10 +258,8 @@ min_n_rels_two => 0, max_n_rels_two => null ); - -- - -- and now for the attributes - -- - foo:= acs_attribute.create_attribute ( + -- all rels to communities must have a portal_id + bar := acs_attribute.create_attribute( object_type => 'dotlrn_member_rel', attribute_name => 'portal_id', datatype => 'integer', Index: openacs-4/packages/dotlrn/tcl/community-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/tcl/community-procs.tcl,v diff -u -r1.123 -r1.124 --- openacs-4/packages/dotlrn/tcl/community-procs.tcl 19 May 2002 16:22:27 -0000 1.123 +++ openacs-4/packages/dotlrn/tcl/community-procs.tcl 20 May 2002 21:39:38 -0000 1.124 @@ -16,7 +16,7 @@ ad_library { - Procs to manage DOTLRN Communities + Procs to manage dotLRN Communities @author Ben Adida (ben@openforce.net) @author Arjun Sanyal (arjun@openforce.net) @@ -1748,4 +1748,130 @@ acs_sc_call dotlrn_applet $op $list_args $applet_key } + ad_proc -public get_available_attributes {} { + get a list of the attributes that we can get/set for dotLRN communities + } { + return [util_memoize {dotlrn_community::get_available_attributes_not_cached}] + } + + ad_proc -private get_available_attributes_not_cached {} { + return [db_list_of_ns_sets select_available_attributes {}] + } + + ad_proc -public get_attributes { + {-community_id ""} + } { + get the attributes of a given community + } { + if {[empty_string_p $community_id]} { + set community_id [get_community_id] + } + + return [util_memoize "dotlrn_community::get_attributes_not_cached -community_id $community_id"] + } + + ad_proc -private get_attributes_not_cached { + {-community_id:required} + } { + return [db_list_of_ns_sets select_attributes {}] + } + + ad_proc -public get_attribute { + {-community_id ""} + {-attribute_name:required} + } { + get the value for an attribute of this community + } { + set attr_value "" + foreach pair [get_attributes -community_id $community_id] { + if {[string match $attribute_name [ns_set get $pair attribute_name]]} { + set attr_value [ns_set get $pair attr_value] + break + } + } + + return $attr_value + } + + ad_proc -public set_attributes { + {-community_id ""} + {-pairs:required} + } { + set attributes for a certain community + } { + foreach pair $pairs { + set_attribute -community_id $community_id -attribute_name [lindex $pair 0] -attribute_value [lindex $pair 1] + } + } + + ad_proc -public set_attribute { + {-community_id ""} + {-attribute_name:required} + {-attribute_value:required} + } { + set an attribute of this community + } { + # this is serious, we are trying to set an attribute that doesn't + # exist + set attribute_id [get_attribute_id -attribute_name $attribute_name] + if {[empty_string_p $attribute_id]} { + error "dotlrn_community::set_attribute: invalid attribute $attribute_name" + } + + # we don't accept empty values (essentially, we are making the + # acs_attribute_values.attr_value not null, which it is not in the db). + if {[empty_string_p $attribute_value]} { + return + } + + if {[empty_string_p $community_id]} { + set community_id [get_community_id] + } + + # we assume that if the value of this attribute is null then we must + # insert a new row for this attribute, if it's not null then we simply + # update it's value. this is not enforced in the database since the + # acs_attribute_values.attr_value column does not have a "not null" + # constraint but we will enforce it via our api. if someone circumvents + # our api then they can die and rot in hell. + if {[empty_string_p [get_attribute -community_id $community_id -attribute_name $attribute_name]} { + db_dml insert_attribute {} + } else { + db_dml update_attribute_value {} + } + + util_memoize_flush "dotlrn_community::get_attributes_not_cached -community_id $community_id" + } + + ad_proc -public get_attribute_id { + {-attribute_name:required} + } { + get the attribute id of an attribute + } { + set attribute_id "" + + foreach pair [get_available_attributes] { + if {[string match $attribute_name [ns_set get $pair attribute_name]]} { + set attribute_id [ns_set get $pair attribute_id] + break + } + } + + return $attribute_id + } + + ad_proc -public attribute_valid_p { + {-attribute_name:required} + } { + is this a valid attribute for dotlrn communities? + } { + set valid_p 0 + + if {![empty_string_p [get_attribute_id -attribute_name $attribute_name]]} { + set valid_p 1 + } + + return $valid_p + } + } Index: openacs-4/packages/dotlrn/tcl/community-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/tcl/community-procs.xql,v diff -u -r1.59 -r1.60 --- openacs-4/packages/dotlrn/tcl/community-procs.xql 15 May 2002 05:18:10 -0000 1.59 +++ openacs-4/packages/dotlrn/tcl/community-procs.xql 20 May 2002 21:39:38 -0000 1.60 @@ -523,4 +523,42 @@ + + + select attribute_id, + attribute_name + from acs_attributes + where object_type = 'dotlrn_community' + + + + + + select acs_attributes.attribute_name, + acs_attribute_values.attr_value + from acs_attributes, + acs_attribute_values + where acs_attribute_values.object_id = :community_id + and acs_attribute_values.attribute_id = acs_attributes.attribute_id + + + + + + insert + into acs_attribute_values + (object_id, attribute_id, attr_value) + values + (:community_id, :attribute_id, :attribute_value) + + + + + + update acs_attribute_values + set attr_value = :attribute_value + where object_id = :community_id + + +