Index: openacs-4/packages/dotlrn-calendar/sql/oracle/dotlrn-calendar-create.sql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn-calendar/sql/oracle/dotlrn-calendar-create.sql,v diff -u -r1.4 -r1.5 --- openacs-4/packages/dotlrn-calendar/sql/oracle/dotlrn-calendar-create.sql 29 Mar 2002 19:16:43 -0000 1.4 +++ openacs-4/packages/dotlrn-calendar/sql/oracle/dotlrn-calendar-create.sql 6 May 2002 22:06:18 -0000 1.5 @@ -14,16 +14,11 @@ -- details. -- - +-- The dotlrn-calendar applet's implimentation of the dotlrn applet contract -- --- The calendar applet for dotLRN --- copyright 2001, OpenForce --- distributed under GPL v2.0 --- --- -- ben,arjun@openforce.net -- --- 10/05/2001 +-- $Id$ -- @@ -37,8 +32,6 @@ 'dotlrn_calendar' ); - -- add all the hooks - -- GetPrettyName foo := acs_sc_impl.new_alias ( 'dotlrn_applet', @@ -57,6 +50,15 @@ 'TCL' ); + -- RemoveApplet + foo := acs_sc_impl.new_alias ( + 'dotlrn_applet', + 'dotlrn_calendar', + 'RemoveApplet', + 'dotlrn_calendar::remove_applet', + 'TCL' + ); + -- AddAppletToCommunity foo := acs_sc_impl.new_alias ( 'dotlrn_applet', @@ -66,12 +68,12 @@ 'TCL' ); - -- RemoveApplet + -- RemoveAppletFromCommunity foo := acs_sc_impl.new_alias ( 'dotlrn_applet', 'dotlrn_calendar', - 'RemoveApplet', - 'dotlrn_calendar::remove_applet', + 'RemoveAppletFromCommunity', + 'dotlrn_calendar::remove_applet_from_community', 'TCL' ); @@ -84,21 +86,21 @@ 'TCL' ); - -- AddUserToCommunity + -- RemoveUser foo := acs_sc_impl.new_alias ( 'dotlrn_applet', 'dotlrn_calendar', - 'AddUserToCommunity', - 'dotlrn_calendar::add_user_to_community', + 'RemoveUser', + 'dotlrn_calendar::remove_user', 'TCL' ); - -- RemoveUser + -- AddUserToCommunity foo := acs_sc_impl.new_alias ( 'dotlrn_applet', 'dotlrn_calendar', - 'RemoveUser', - 'dotlrn_calendar::remove_user', + 'AddUserToCommunity', + 'dotlrn_calendar::add_user_to_community', 'TCL' ); 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.43 -r1.44 --- openacs-4/packages/dotlrn-calendar/tcl/dotlrn-calendar-procs.tcl 30 Apr 2002 21:34:33 -0000 1.43 +++ openacs-4/packages/dotlrn-calendar/tcl/dotlrn-calendar-procs.tcl 6 May 2002 22:06:18 -0000 1.44 @@ -14,28 +14,19 @@ # details. # - -# Procs for DOTLRN calendar Applet -# Copyright 2001 OpenForce, inc. -# Distributed under the GNU GPL v2 -# -# October 26th, 2001 -# - ad_library { - Procs to set up the dotLRN calendar applet + TCL implimentation of the dotlrn applet contract for calendar @author ben@openforce.net,arjun@openforce.net - @creation-date 2001-10-26 - + @version $Id$ } namespace eval dotlrn_calendar { ad_proc -public package_key { } { - get the package_key this applet deals with + the package_key this applet deals with } { return "calendar" } @@ -68,7 +59,10 @@ ad_proc -public get_user_default_page {} { return the user default page to add the portlet to } { - return [ad_parameter -package_id [apm_package_id_from_key dotlrn-calendar] user_default_page] + return [ad_parameter \ + -package_id [apm_package_id_from_key dotlrn-calendar] \ + user_default_page + ] } ad_proc -public add_applet { @@ -91,66 +85,65 @@ 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_proc -public add_applet_to_community { community_id } { Add the calendar applet to a specific dotlrn community } { - # add this element to the portal template. + # add this element to the community portal # 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 portal_id [dotlrn_community::get_portal_id -community_id $community_id] + calendar_portlet::make_self_available $portal_id + set element_id [portal::add_element \ + -pretty_name [get_pretty_name] \ + -force_region 2 \ + $portal_id \ + [calendar_portlet::my_name] + ] - calendar_portlet::make_self_available $portal_template_id - - set element_id \ - [portal::add_element \ - -pretty_name [get_pretty_name] \ - -force_region 2 \ - $portal_template_id \ - [calendar_portlet::my_name]] - - # 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 \ - -portal_id $portal_template_id \ - -page_name [get_user_default_page] \ + -portal_id $portal_id \ + -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 \ -page_id $page_id \ - $portal_template_id \ + $portal_id \ 0 ] - return } - - # 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] + set group_calendar_id [calendar_create \ + [ad_conn "user_id"] \ + "f" \ + "[dotlrn_community::get_community_name $community_id] Public Calendar" + ] - # set the group_calendar_id parameter in the portal template, + # set the group_calendar_id parameter in the comm's portal portal::set_element_param \ $element_id "calendar_id" $group_calendar_id set element_id [calendar_full_portlet::add_self_to_page \ - -page_id $page_id \ - $portal_template_id \ - $group_calendar_id + -page_id $page_id \ + $portal_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_admin_portal_id -community_id $community_id] calendar_admin_portlet::make_self_available $admin_portal_id @@ -179,7 +172,9 @@ # reinstantiating calendar portal::mapping::new \ -node_id \ - [site_nodes::get_node_id_from_child -parent_node_id $node_id -name [package_key]] \ + [site_nodes::get_node_id_from_child_name \ + -parent_node_id $node_id \ + -name [package_key]] \ -object_id $group_calendar_id # Becase the context_id of calendar dosen't point to the community @@ -188,41 +183,120 @@ # 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 - # ns_log notice "aks16 granted" + 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 \ + -privilege "admin" # 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 + set members_segment_id [dotlrn_community::get_rel_segment_id \ + -community_id $community_id \ + -rel_type dotlrn_member_rel + ] + permission::grant \ + -party_id $members_segment_id \ + -object_id $group_calendar_id \ + -privilege "read" return $group_calendar_id } ad_proc -public remove_applet_from_community { community_id - package_id + comm_package_id } { remove the applet from the community - } { - ad_return_complaint 1 "aks1" + } { + set group_calendar_id [get_group_calendar_id -community_id $community_id] + + # aks debug + ad_return_complaint 1 "aks2: [site_nodes::get_node_id_from_child_name -parent_node_id [site_nodes::get_node_id_from_package_id -package_id $comm_package_id] -name [package_key] ]" - # XXX - # Remove all instances of the calendar portlet! (this is some - # serious stuff!) - # Dropping all messages, forums - # Killing the package + # 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" + + 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] + + calendar_admin_portlet::make_self_unavailable $admin_portal_id + + set admin_element_id [portal::get_element_ids_by_ds \ + $admin_portal_id \ + [calendar_admin_portlet::my_name] + ] + + portal::remove_element $admin_element_id + + + # now for the "regular" calendar portlet from the comm's portal + set portal_id [dotlrn_community::get_portal_id \ + -community_id $community_id + ] + + calendar_portlet::make_self_unavailable $portal_id + + portal::remove_element [portal::get_element_id_by_ds \ + $portal_id \ + [calendar_portlet::my_name] + ] + + # now for the "full calendar" portlet from the comm's portal + calendar_full_portlet::make_self_unavailable $portal_id + + portal::remove_element [portal::get_element_id_by_ds \ + $portal_id \ + [calendar_full_portlet::my_name] + ] + + # and finally kill the group calendar + calendar_delete $group_calendar_id + + # delete the package instance and the site node where it's mounted + + # XXX it appears that the only way to get the package id + # of the calendar package mounted at this point, is through + # the comm_id/comm_package_id and the url, this should be better! + dotlrn::unmount_package -package_id $package_id + } ad_proc -public add_user { user_id } { 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] + # 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 " @@ -236,96 +310,64 @@ set calendar_id [calendar_create $user_id "t" $cal_name] # Here we map the calendar to the main dotlrn package - portal::mapping::new \ - -node_id \ - [site_nodes::get_node_id_from_child -parent_node_id [dotlrn::get_node_id] -name [package_key]] \ - -object_id $calendar_id + set node_id [site_nodes::get_node_id_from_child_name \ + -parent_node_id [dotlrn::get_node_id] \ + -name [package_key] + ] + portal::mapping::new -node_id $node_id -object_id $calendar_id } - # add this PE to the user's workspace! set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] + calendar_portlet::make_self_available $workspace_portal_id + calendar_full_portlet::make_self_available $workspace_portal_id - # Add the portlet here - if { $workspace_portal_id != "" } { - calendar_portlet::make_self_available $workspace_portal_id + # add the "day summary" pe to the user's first workspace page + set element_id [calendar_portlet::add_self_to_page \ + $workspace_portal_id \ + $calendar_id + ] - # (ben) I changed this to be added to the front page now, because - # the one we're adding to calendar is the full calendar thing, not the summary - set element_id [calendar_portlet::add_self_to_page \ - $workspace_portal_id \ - $calendar_id] + # but add the "full calendar" pe to the workspace page specified above + set page_id [portal::get_page_id \ + -portal_id $workspace_portal_id \ + -page_name [get_user_default_page] + ] - set element_id [calendar_full_portlet::add_self_to_page \ - -page_id [portal::get_page_id -portal_id $workspace_portal_id \ - -page_name [get_user_default_page]] \ - $workspace_portal_id \ - $calendar_id] - } - + set element_id [calendar_full_portlet::add_self_to_page \ + -page_id $page_id \ + $workspace_portal_id \ + $calendar_id + ] } - ad_proc -public add_user_to_community { - community_id + ad_proc -public remove_user { user_id } { - Add a user to a community + Remove a user entirely } { - - # Get the user per comm portal_id by callback - set portal_id [dotlrn_community::get_portal_id $community_id $user_id] - - if { [exists_and_not_null $portal_id] } { - # get the group_calendar_id by callback - set g_cal_id [portal::get_element_param \ - [lindex [portal::get_element_ids_by_ds \ - [portal::get_portal_template_id $portal_id] \ - [calendar_portlet::my_name]] 0] \ - "calendar_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 $portal_id $g_cal_id - } - - # Now for the user workspace - # set this calendar_id in the workspace portal + # FIXME remove the mapping?? set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] + set calendar_id [calendar_have_private_p -return_id 1 $user_id] - # get the comm's calendar_id, and add it as a param to the - # ws portal's calendar portal element - if { [exists_and_not_null $workspace_portal_id] } { - calendar_portlet::add_self_to_page $workspace_portal_id $g_cal_id + calendar_portlet::remove_self_from_page $workspace_portal_id $calendar_id + calendar_portlet::make_self_unavailable $workspace_portal_id - calendar_full_portlet::add_self_to_page \ - $workspace_portal_id \ - $g_cal_id - } + calendar_full_portlet::remove_self_from_page $workspace_portal_id $calendar_id + calendar_full_portlet::make_self_unavailable $workspace_portal_id } - ad_proc -public remove_user { + ad_proc -public add_user_to_community { + community_id user_id } { - Remove a user entirely + 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] - 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 - - } + calendar_portlet::add_self_to_page $workspace_portal_id $g_cal_id + calendar_full_portlet::add_self_to_page $workspace_portal_id $g_cal_id } ad_proc -public remove_user_from_community { @@ -334,26 +376,10 @@ } { 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]] - - # 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 g_cal_id [get_group_calendar_id -community_id $community_id] set workspace_portal_id [dotlrn::get_workspace_portal_id $user_id] - - # Remove the portlet - if {![empty_string_p $workspace_portal_id]} { - calendar_portlet::remove_self_from_page $workspace_portal_id $package_id - calendar_full_portlet::remove_self_from_page $workspace_portal_id $package_id - } + calendar_portlet::remove_self_from_page $workspace_portal_id $g_cal_id + calendar_full_portlet::remove_self_from_page $workspace_portal_id $g_cal_id } # @@ -365,16 +391,16 @@ } { Find the group_calendar_id for the given community } { + set portal_id [dotlrn_community::get_portal_id \ + -community_id $community_id + ] - # get the portal_template_id for this comm - set portal_template_id [dotlrn_community::get_portal_template_id $community_id] - # get the calendar element for this community set element_id [portal::get_element_ids_by_ds \ - $portal_template_id \ - [calendar_portlet::my_name]] + $portal_id \ + [calendar_portlet::my_name] + ] - # [lindex element_ids 0] return [portal::get_element_param $element_id "calendar_id"] }