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.39 -r1.40 --- openacs-4/packages/dotlrn-calendar/tcl/dotlrn-calendar-procs.tcl 2 Apr 2002 06:13:47 -0000 1.39 +++ openacs-4/packages/dotlrn-calendar/tcl/dotlrn-calendar-procs.tcl 8 Apr 2002 22:00:46 -0000 1.40 @@ -23,46 +23,46 @@ # ad_library { - + Procs to set up the dotLRN calendar applet - + @author ben@openforce.net,arjun@openforce.net @creation-date 2001-10-26 - + } namespace eval dotlrn_calendar { - + ad_proc -public package_key { } { - get the package_key this applet deals with + get the package_key this applet deals with } { - return "calendar" + return "calendar" } ad_proc -public applet_key {} { return "dotlrn_calendar" } - + ad_proc -public get_url { } { - get the package_key this applet deals with + get the package_key this applet deals with } { - return "/[package_key]" + return "/[package_key]" } ad_proc portal_element_key { } { - return the portal element key + return the portal element key } { - return "calendar-portlet" + return "calendar-portlet" } ad_proc -public get_pretty_name { } { - returns the pretty name + returns the pretty name } { - return "Calendar" + return "Calendar" } ad_proc -public get_user_default_page {} { @@ -73,17 +73,17 @@ ad_proc -public add_applet { } { - Called for one time init - must be repeatable! - @return new pkg_id or 0 on failure + Called for one time init - must be repeatable! + @return new pkg_id or 0 on failure } { - # FIXME: won't work with multiple dotlrn instances + # FIXME: won't work with multiple dotlrn instances # Use the package_key for the -url param - "/" are not allowed! - if {![dotlrn::is_package_mounted -package_key [package_key]]} { + if {![dotlrn::is_package_mounted -package_key [package_key]]} { dotlrn::mount_package \ -package_key [package_key] \ -url [package_key] \ -directory_p "t" - } + } # register/activate self with dotlrn # our service contract is in the db, but we must tell dotlrn @@ -92,36 +92,36 @@ } ad_proc -public add_applet_to_community { - community_id + community_id } { - Add the calendar applet to a specific dotlrn community + Add the calendar applet to a specific dotlrn community } { - # set up a nice name for the comm's calendar - set cal_name "[dotlrn_community::get_community_name $community_id] Public Calendar" + # set up a nice name for the comm's calendar + set cal_name "[dotlrn_community::get_community_name $community_id] Public Calendar" - # create the community's calendar, the "f" is for a public calendar - set group_calendar_id \ - [calendar_create [ad_conn "user_id"] "f" $cal_name] + # create the community's calendar, the "f" is for a public calendar + set group_calendar_id \ + [calendar_create [ad_conn "user_id"] "f" $cal_name] - # add this element to the portal template. - # do this directly, don't use calendar_portlet::add_self_to_page here - set portal_template_id \ - [dotlrn_community::get_portal_template_id $community_id] - - calendar_portlet::make_self_available $portal_template_id + # add this element to the portal template. + # do this directly, don't use calendar_portlet::add_self_to_page here + set portal_template_id \ + [dotlrn_community::get_portal_template_id $community_id] - set element_id \ + calendar_portlet::make_self_available $portal_template_id + + set element_id \ [portal::add_element \ - -pretty_name [get_pretty_name] \ + -pretty_name [get_pretty_name] \ -force_region 2 \ $portal_template_id \ [calendar_portlet::my_name]] - # set the group_calendar_id parameter in the portal template, - portal::set_element_param \ - $element_id "calendar_id" $group_calendar_id + # set the group_calendar_id parameter in the portal template, + portal::set_element_param \ + $element_id "calendar_id" $group_calendar_id - # add the "full calendar" portlet to the commnuity's "calendar" page, + # add the "full calendar" portlet to the commnuity's "calendar" page, # similar to the same thing on a user's wsp. use the get_user_def_page # func here too set page_id [portal::get_page_id \ @@ -132,90 +132,90 @@ set element_id [calendar_full_portlet::add_self_to_page \ -page_id $page_id \ $portal_template_id \ - $group_calendar_id + $group_calendar_id ] # Add the admin portlet, too - set admin_portal_id \ - [dotlrn_community::get_community_admin_portal_id $community_id] + set admin_portal_id \ + [dotlrn_community::get_community_admin_portal_id $community_id] - calendar_admin_portlet::make_self_available $admin_portal_id + calendar_admin_portlet::make_self_available $admin_portal_id - set element_id \ - [portal::add_element $admin_portal_id \ - [calendar_admin_portlet::my_name]] + set element_id \ + [portal::add_element $admin_portal_id \ + [calendar_admin_portlet::my_name]] - # set the group_calendar_id parameter in the admin portal. - portal::set_element_param \ - $element_id "calendar_id" $group_calendar_id - + # set the group_calendar_id parameter in the admin portal. + portal::set_element_param \ + $element_id "calendar_id" $group_calendar_id + # automount calendar in this community set node_id [site_nodes::get_node_id_from_url \ -url [dotlrn_community::get_url_from_package_id \ -package_id [dotlrn_community::get_package_id $community_id]]] - + set package_id [dotlrn::mount_package \ -parent_node_id $node_id \ -package_key [package_key] \ -url [package_key] \ -directory_p "t"] - + # 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] - ad_permission_grant $admin_segment_id $group_calendar_id admin + set admin_segment_id [dotlrn_community::get_rel_segment_id -community_id $community_id -rel_type dotlrn_admin_rel] + ad_permission_grant $admin_segment_id $group_calendar_id admin # ns_log notice "aks16 granted" # same thing for reading, cause it's not granted by context_id (ben) set members_segment_id [dotlrn_community::get_rel_segment_id -community_id $community_id -rel_type dotlrn_member_rel] ad_permission_grant $members_segment_id $group_calendar_id read - return $group_calendar_id + return $group_calendar_id } ad_proc -public remove_applet { - community_id - package_id + community_id + package_id } { - remove the applet from the community + remove the applet from the community } { - # XXX + # XXX - # Remove all instances of the calendar portlet! (this is some - # serious stuff!) - # Dropping all messages, forums - # Killing the package + # Remove all instances of the calendar portlet! (this is some + # serious stuff!) + # Dropping all messages, forums + # Killing the package } ad_proc -public add_user { - user_id + user_id } { - Called once when a user is added as a dotlrn user + Called once when a user is added as a dotlrn user } { - # Check if there is a calendar ID - set calendar_id [calendar_have_private_p -return_id 1 $user_id] + # Check if there is a calendar ID + set calendar_id [calendar_have_private_p -return_id 1 $user_id] - 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 - "] - - # create a private, global calendar for this user - set cal_name "$user_name's Personal Calendar" - set calendar_id [calendar_create $user_id "t" $cal_name] - } - - # add this PE to the user's workspace! - set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] + 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 + "] - # Add the portlet here + # create a private, global calendar for this user + set cal_name "$user_name's Personal Calendar" + set calendar_id [calendar_create $user_id "t" $cal_name] + } + + # add this PE to the user's workspace! + set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] + + # Add the portlet here if { $workspace_portal_id != "" } { calendar_portlet::make_self_available $workspace_portal_id @@ -235,13 +235,13 @@ } ad_proc -public add_user_to_community { - community_id - user_id + community_id + user_id } { - Add a user to a community + Add a user to a community } { # Get the portal_id by callback - set portal_id [dotlrn_community::get_portal_id $community_id $user_id] + set portal_id [dotlrn_community::get_portal_id $community_id $user_id] # get the group_calendar_id by callback set g_cal_id [portal::get_element_param \ @@ -250,18 +250,18 @@ [calendar_portlet::my_name]] 0] \ "calendar_id"] - # Make the calendar DS available to this page - calendar_portlet::make_self_available $portal_id + # Make the calendar DS available to this page + calendar_portlet::make_self_available $portal_id - # Call the portal element to be added correctly - calendar_portlet::add_self_to_page \ + # Call the portal element to be added correctly + calendar_portlet::add_self_to_page \ $portal_id $g_cal_id - # Now for the user workspace - # set this calendar_id in the workspace portal + # Now for the user workspace + # set this calendar_id in the workspace portal set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] - + # get the comm's calendar_id, and add it as a param to the # ws portal's calendar portal element if { $workspace_portal_id != "" } { @@ -274,10 +274,10 @@ # This means I have to go fix the way permissions are assigned # at applet creation time (ben) # - # aks debug + # aks debug # ns_log notice "aks13 $user_id $g_cal_id calendar_read" - # ad_permission_grant $user_id $g_cal_id calendar_read - # ad_permission_grant $user_id $g_cal_id calendar_show + # ad_permission_grant $user_id $g_cal_id calendar_read + # ad_permission_grant $user_id $g_cal_id calendar_show # ns_log notice "aks14 read + show granted to user $user_id and cal $g_cal_id" } @@ -287,27 +287,42 @@ } { Remove a user entirely } { - # FIXME: nothing for now + set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] + + if {![empty_string_p $workspace_portal_id]} { + set calendar_id [calendar_have_private_p -return_id 1 $user_id] + + calendar_portlet::remove_self_from_page $workspace_portal_id $calendar_id + + calendar_full_portlet::remove_self_from_page \ + -page_id [portal::get_page_id -portal_id $workspace_portal_id \ + -page_name [get_user_default_page]] \ + $workspace_portal_id \ + $calendar_id + + calendar_portlet::make_self_unavailable $workspace_portal_id + + } } ad_proc -public remove_user_from_community { - community_id - user_id + community_id + user_id } { - Remove a user from a community + Remove a user from a community } { - # Get the portal_id - set portal_id [dotlrn_community::get_portal_id $community_id $user_id] - - # Get the package_id by callback - set package_id [dotlrn_community::get_applet_package_id $community_id [applet_key]] + # Get the portal_id + set portal_id [dotlrn_community::get_portal_id $community_id $user_id] - # Remove the portal element - calendar_portlet::remove_self_from_page $portal_id $package_id + # Get the package_id by callback + set package_id [dotlrn_community::get_applet_package_id $community_id [applet_key]] - # Buh Bye. - calendar_portlet::make_self_unavailable $portal_id + # Remove the portal element + calendar_portlet::remove_self_from_page $portal_id $package_id + # Buh Bye. + calendar_portlet::make_self_unavailable $portal_id + # Remove from main workspace set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] @@ -320,8 +335,8 @@ # # Some dotlrn_calendar specific procs - # - + # + ad_proc -public get_group_calendar_id { {-community_id:required} } { @@ -336,10 +351,8 @@ $portal_template_id \ [calendar_portlet::my_name]] - # [lindex element_ids 0] + # [lindex element_ids 0] return [portal::get_element_param $element_id "calendar_id"] } - - }