Index: openacs-4/packages/dotlrn-calendar/tcl/dotlrn-calendar-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-calendar/tcl/dotlrn-calendar-procs.tcl,v diff -u -r1.55 -r1.56 --- openacs-4/packages/dotlrn-calendar/tcl/dotlrn-calendar-procs.tcl 17 May 2002 19:20:16 -0000 1.55 +++ openacs-4/packages/dotlrn-calendar/tcl/dotlrn-calendar-procs.tcl 24 May 2002 01:58:45 -0000 1.56 @@ -16,7 +16,7 @@ ad_library { - TCL implimentation of the dotlrn applet contract for calendar + the dotlrn applet for calendar @author ben@openforce.net,arjun@openforce.net @version $Id$ @@ -26,44 +26,31 @@ ad_proc -public package_key { } { - the package_key this applet deals with + What package does this applet deal with? } { return "calendar" } - ad_proc -public applet_key {} { - return "dotlrn_calendar" - } - - ad_proc -public get_url { + ad_proc -public my_package_key { } { - get the package_key this applet deals with + What's my package key? } { - return "/[package_key]" + return "dotlrn-calendar" } - ad_proc portal_element_key { + ad_proc -public applet_key { } { - return the portal element key + What's my applet key? } { - return "calendar-portlet" + return "dotlrn_calendar" } ad_proc -public get_pretty_name { } { - returns the pretty name } { return "Calendar" } - ad_proc -public get_user_default_page {} { - return the user default page to add the portlet to - } { - # there shouldn't need to be a default here, but this - # call is not working for some reason - return [ad_parameter "user_default_page" dotlrn-calendar "Calendar"] - } - ad_proc -public add_applet { } { Called for one time init - must be repeatable! @@ -78,98 +65,49 @@ -directory_p "t" } - # register/activate self with dotlrn - # our service contract is in the db, but we must tell dotlrn - # that we exist and want to be active dotlrn_applet::add_applet_to_dotlrn -applet_key [applet_key] } ad_proc -public remove_applet { } { One-time destroy for when the entire applet is removed from dotlrn. } { - return + ad_return_complaint 1 "[applet_key] remove_applet not implimented!" } + ad_proc -public calendar_create_helper { + {-community_id:required} + } { + A helper proc to create a calendar for a comm, returns the new calendar_id + } { + # create the community's calendar, the "f" is for a public calendar + set community_name [dotlrn_community::get_community_name $community_id] + return [calendar_create [ad_conn "user_id"] "f" $community_name] + } + ad_proc -public add_applet_to_community { community_id } { Add the calendar applet to a specific dotlrn community } { - # add this element to the community portal - # do this directly, don't use calendar_portlet::add_self_to_page here + set calendar_id [calendar_create_helper -community_id $community_id] + return [add_applet_to_community_helper \ + -community_id $community_id \ + -calendar_id $calendar_id + ] + } - # aks: why direct?? - set portal_id [dotlrn_community::get_portal_id -community_id $community_id] + ad_proc -public add_applet_to_community_helper { + {-community_id:required} + {-calendar_id:required} + } { + Add the calendar applet to a specific dotlrn community - set element_id [portal::add_element \ - -pretty_name [get_pretty_name] \ - -force_region 2 \ - -portal_id $portal_id \ - -portlet_name [calendar_portlet::get_my_name] - ] - - # add the "full calendar" portlet to the community's "calendar" page, - # similar to the same thing on a user's wsp. use the get_user_def_page - set page_name [get_user_default_page] - if {[dotlrn_community::dummy_comm_p -community_id $community_id]} { - # since this is a dummy comm, set a fake g_cal_id - set element_id [calendar_full_portlet::add_self_to_page \ - -portal_id $portal_id \ - -page_name $page_name \ - -calendar_id 0 - ] - return - } - - # create the community's calendar, the "f" is for a public calendar - set group_calendar_id [calendar_create \ - [ad_conn "user_id"] \ - "f" \ - "[dotlrn_community::get_community_name $community_id]" - ] - - # set the group_calendar_id parameter in the comm's portal - portal::set_element_param \ - $element_id "calendar_id" $group_calendar_id - - # This is not scoped, because we are only seeing one group calendar - portal::set_element_param \ - $element_id "scoped_p" "f" - - set element_id [calendar_full_portlet::add_self_to_page \ - -portal_id $portal_id \ - -page_name $page_name \ - -calendar_id $group_calendar_id - ] - - # This is not scoped, because we are only seeing one group calendar - portal::set_element_param \ - $element_id "scoped_p" "f" - - # Add the Class Schedule Portlet - set element_id [calendar_list_portlet::add_self_to_page \ - -portal_id $portal_id \ - -page_name $page_name \ - -calendar_id $group_calendar_id - ] - - # This is not scoped, because we are only seeing one group calendar - portal::set_element_param \ - $element_id "scoped_p" "f" - - # Add the admin portlet, too - set admin_portal_id [dotlrn_community::get_admin_portal_id -community_id $community_id] - - set element_id [portal::add_element \ - -portal_id $admin_portal_id \ - -portlet_name [calendar_admin_portlet::get_my_name] - ] - - # set the group_calendar_id parameter in the admin portal. - portal::set_element_param \ - $element_id "calendar_id" $group_calendar_id - + @params community_id + } { + # + # ** setup stuff ** + # # automount calendar in this community set node_id [site_nodes::get_node_id_from_url \ -url [dotlrn_community::get_url_from_package_id \ @@ -190,21 +128,20 @@ [site_nodes::get_node_id_from_child_name \ -parent_node_id $node_id \ -name [package_key]] \ - -object_id $group_calendar_id + -object_id $calendar_id # Becase the context_id of calendar dosen't point to the community # the calendar_admin perm is not automatically inherited (like # in bboard for example) We must do an explicit grant to the # dotlrn_admin_rel relational segment. dotlrn_ta_rel and dotlrn_instructor_rel # both inherit from the dotlrn_admin_rel, so we don't have to grant to them. - set admin_segment_id [dotlrn_community::get_rel_segment_id \ -community_id $community_id \ -rel_type dotlrn_admin_rel ] permission::grant \ -party_id $admin_segment_id \ - -object_id $group_calendar_id \ + -object_id $calendar_id \ -privilege "admin" # same thing for reading, cause it's not granted by context_id (ben) @@ -214,92 +151,80 @@ ] permission::grant \ -party_id $members_segment_id \ - -object_id $group_calendar_id \ + -object_id $calendar_id \ -privilege "read" - # this should return the package_id - return $package_id - } + # + # ** portlet stuff ** + # - ad_proc -public remove_applet_from_community { - community_id - } { - remove the applet from the community - } { - set group_calendar_id [get_group_calendar_id -community_id $community_id] + # append the calendar_id to the current portlet + set calendar_id $calendar_id + set scoped_p f - # first, revoke the permissions - set members_segment_id [dotlrn_community::get_rel_segment_id \ - -community_id $community_id \ - -rel_type dotlrn_member_rel - ] - set admin_segment_id [dotlrn_community::get_rel_segment_id \ - -community_id $community_id \ - -rel_type dotlrn_admin_rel - ] - - permission::revoke \ - -party_id $members_segment_id \ - -object_id $group_calendar_id \ - -privilege "read" + # + # set up the admin portlet + # - permission::revoke \ - -party_id $admin_segment_id \ - -object_id $group_calendar_id \ - -privilege "admin" - - # delete the "portal node mapping" - portal::mapping::del -object_id $group_calendar_id - - # remove the portlets, params will cascade - # first the admin portlet, from the comm's admin portal set admin_portal_id [dotlrn_community::get_admin_portal_id \ -community_id $community_id ] - - portal::remove_element \ + + calendar_admin_portlet::add_self_to_page \ -portal_id $admin_portal_id \ - -portlet_name [calendar_admin_portlet::get_my_name] + -calendar_id $calendar_id - # now for the "regular" calendar portlet from the comm's portal + # + # set up the Class Schedule Portlet + # + # this is an exception to the general "style", but + # this portlet is only on communities, so we can't + # put this code in add_portlet_helper + set portal_id [dotlrn_community::get_portal_id -community_id $community_id] - # now for the "full calendar" portlet from the comm's portal - portal::remove_element \ + calendar_list_portlet::add_self_to_page \ -portal_id $portal_id \ - -portlet_name [calendar_full_portlet::get_my_name] - - # and finally kill the group calendar - calendar_delete -calendar_id $group_calendar_id + -calendar_id $calendar_id \ + -scoped_p $scoped_p - # delete the package instance and the site node where it's mounted - dotlrn::unmount_community_applet_package \ - -community_id $community_id \ - -package_key [package_key] + # + # set up the calendar and full calendar portlets using add_portlet_helper + # + + set args [ns_set create] + ns_set put $args calendar_id $calendar_id + ns_set put $args scoped_p $scoped_p + ns_set put $args param_action "overwrite" + ns_set put $args full_portlet_page_name "" + + dotlrn_calendar::add_portlet_helper $portal_id $args + + # this should return the package_id + return $package_id } + ad_proc -public remove_applet_from_community { + community_id + } { + remove the applet from the community + } { + ad_return_complaint 1 "[applet_key] remove_applet_from_community not implimented!" + } + ad_proc -public add_user { user_id } { - Called once when a user is added as a dotlrn user + Called once when a user is added as a dotlrn user. + Create a priivate, personal, global calendar for the + user if they don't have one, and add both calendar portlets + to the user's portal } { set calendar_id [calendar_have_private_p -return_id 1 $user_id] - - # if the user already has a personal calendar in the system - # don't make a new one if {$calendar_id == 0} { - # this is lame, but I can't find a proc to do this -# set user_name [db_string user_name_select " -# select first_names || ' ' || last_name as name -# from persons -# where person_id = :user_id -# "] + set calendar_id [calendar_create $user_id "t" "Personal"] - # create a private, global calendar for this user - set cal_name "Personal" - set calendar_id [calendar_create $user_id "t" $cal_name] - # Here we map the calendar to the main dotlrn package set node_id [site_nodes::get_node_id_from_child_name \ -parent_node_id [dotlrn::get_node_id] \ @@ -309,43 +234,22 @@ portal::mapping::new -node_id $node_id -object_id $calendar_id } - set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] - - # add the "day summary" pe to the user's first workspace page - set element_id [calendar_portlet::add_self_to_page \ - -portal_id $workspace_portal_id \ - -calendar_id $calendar_id \ - ] - - # Make sure this is scoped - portal::set_element_param $element_id scoped_p t - - # but add the "full calendar" pe to the workspace page specified above - set element_id [calendar_full_portlet::add_self_to_page \ - -portal_id $workspace_portal_id \ - -page_name [get_user_default_page] \ - -calendar_id $calendar_id - ] - - # Make sure this is scoped - portal::set_element_param $element_id scoped_p t + set args [ns_set create] + ns_set put $args calendar_id $calendar_id + ns_set put $args scoped_p "t" + + # don't use the cached version + dotlrn_calendar::add_portlet_helper \ + [dotlrn::get_portal_id_not_cached -user_id $user_id] \ + $args } ad_proc -public remove_user { user_id } { - Remove a user entirely + Remove a user from dotlrn } { - # FIXME - not tested - set portal_id [dotlrn::get_workspace_portal_id $user_id] - set calendar_id [calendar_have_private_p -return_id 1 $user_id] - - set args [ns_set create args] - ns_set put $args user_id $user_id - ns_set put $args calendar_id $calendar_id - set list_args [list $portal_id $args] - - remove_portlet $portal_id $args + ad_return_complaint 1 "[applet_key] remove_user not implimented!" } ad_proc -public add_user_to_community { @@ -354,16 +258,14 @@ } { Add a user to a community } { - set g_cal_id [get_group_calendar_id -community_id $community_id] - set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] + set calendar_id [get_group_calendar_id -community_id $community_id] + set portal_id [dotlrn::get_portal_id -user_id $user_id] - calendar_portlet::add_self_to_page \ - -portal_id $workspace_portal_id \ - -calendar_id $g_cal_id - - calendar_full_portlet::add_self_to_page \ - -portal_id $workspace_portal_id \ - -calendar_id $g_cal_id + set args [ns_set create] + ns_set put $args calendar_id $calendar_id + ns_set put $args param_action "append" + + dotlrn_calendar::add_portlet_helper $portal_id $args } ad_proc -public remove_user_from_community { @@ -372,55 +274,84 @@ } { Remove a user from a community } { - set portal_id [dotlrn::get_workspace_portal_id $user_id] set calendar_id [get_group_calendar_id -community_id $community_id] + set portal_id [dotlrn::get_portal_id -user_id $user_id] - set args [ns_set create args] - ns_set put $args user_id $user_id - ns_set put $args community_id $community_id + set args [ns_set create] ns_set put $args calendar_id $calendar_id - set list_args [list $portal_id $args] - - remove_portlet $portal_id $args + + dotlrn_calendar::remove_portlet $portal_id $args } ad_proc -public add_portlet { - args + portal_id } { - A helper proc to add the underlying portlet to the given portal. + Set up default params for templates about to call add_portlet_helper - @param args a list-ified array of args defined in add_applet_to_community + @param portal_id } { - ns_log notice "** Error in [get_pretty_name]: 'add_portlet' not implemented!" - ad_return_complaint 1 "Please notifiy the administrator of this error: - ** Error in [get_pretty_name]: 'add_portlet' not implemented!" + set args [ns_set create] + ns_set put $args calendar_id 0 + ns_set put $args full_portlet_page_name [get_community_default_page] + ns_set put $args scoped_p f + + set type [dotlrn::get_type_from_portal_id -portal_id $portal_id] + + if {[string equal $type "user"]} { + # the portlet has a special name on a user portal + ns_set put $args pretty_name "Day Summary" + ns_set put $args full_portlet_page_name [get_user_default_page] + ns_set put $args scoped_p t + } else { + # add this portlet to all types of communities + calendar_list_portlet::add_self_to_page \ + -portal_id $portal_id \ + -calendar_id 0 \ + -scoped_p f + } + + add_portlet_helper $portal_id $args } + ad_proc -private add_portlet_helper { + portal_id + args + } { + Does the call to add the portlet to the portal. + Params for the portlet are sent to this proc by the caller. + } { + calendar_portlet::add_self_to_page \ + -portal_id $portal_id \ + -pretty_name [ns_set get $args "pretty_name"] \ + -calendar_id [ns_set get $args "calendar_id"] \ + -scoped_p [ns_set get $args "scoped_p"] \ + -param_action [ns_set get $args "param_action"] + + calendar_full_portlet::add_self_to_page \ + -portal_id $portal_id \ + -page_name [ns_set get $args "full_portlet_page_name"] \ + -calendar_id [ns_set get $args "calendar_id"] \ + -scoped_p [ns_set get $args "scoped_p"] \ + -param_action [ns_set get $args "param_action"] + } + ad_proc -public remove_portlet { portal_id args } { A helper proc to remove the underlying portlet from the given portal. - + This is alot simpler than add_portlet. + @param portal_id - @param args A list of key-value pairs (possibly user_id, community_id, and more) + @param args An ns_set with the calendar_id. } { - set user_id [ns_set get $args "user_id"] - set community_id [ns_set get $args "community_id"] + calendar_portlet::remove_self_from_page \ + -portal_id $portal_id \ + -calendar_id [ns_set get $args "calendar_id"] - if {![empty_string_p $user_id]} { - # the portal_id is a user's portal - set calendar_id [ns_set get $args "calendar_id"] - } elseif {![empty_string_p $community_id]} { - # the portal_id is a community portal - ad_return_complaint 1 "dotlrn_calendar aks1 unimplimented" - } else { - # the portal_id is a portal template - ad_return_complaint 1 "dotlrn_calendar aks2 unimplimented" - } - - calendar_portlet::remove_self_from_page $portal_id $calendar_id - calendar_full_portlet::remove_self_from_page $portal_id $calendar_id + calendar_full_portlet::remove_self_from_page \ + -portal_id $portal_id \ + -calendar_id [ns_set get $args "calendar_id"] } ad_proc -public clone { @@ -429,9 +360,17 @@ } { Clone this applet's content from the old community to the new one } { - ns_log notice "** Error in [get_pretty_name] 'clone' not implemented!" - ad_return_complaint 1 "Please notifiy the administrator of this error: - ** Error in [get_pretty_name]: 'clone' not implemented!" + ns_log notice "Cloning: [applet_key]" + + # copy the old_comm's item types table + set old_calendar_id [get_group_calendar_id -community_id $old_calendar_id] + db_dml copy_cal_item_types {} + + set calendar_id [calendar_create_helper -community_id $community_id] + return [add_applet_to_community_helper \ + -community_id $community_id \ + -calendar_id $calendar_id + ] } # @@ -456,4 +395,21 @@ return [portal::get_element_param $element_id "calendar_id"] } + ad_proc -public get_user_default_page {} { + The "full calendar" portlet must go on this page of a user's portal + } { + return [parameter::get_from_package_key \ + -package_key [my_package_key] \ + -parameter "user_default_page" + ] + } + + ad_proc -public get_community_default_page {} { + The "full calendar" portlet must go on this page of a comm's portal + } { + return [parameter::get_from_package_key \ + -package_key [my_package_key] \ + -parameter "user_default_page" + ] + } }