calendar::item::new (public)

 calendar::item::new -start_date start_date -end_date end_date \
    -name name -description description [ -calendar_id calendar_id ] \
    [ -item_type_id item_type_id ] [ -package_id package_id ] \
    [ -location location ] [ -related_link_url related_link_url ] \
    [ -related_link_text related_link_text ] \
    [ -redirect_to_rel_link_p redirect_to_rel_link_p ] \
    [ -cal_uid cal_uid ] [ -ical_vars ical_vars ]

Defined in packages/calendar/tcl/cal-item-procs.tcl

Insert a new calendar item into the database

Switches:
-start_date
(required)
-end_date
(required)
-name
(required)
-description
(required)
-calendar_id
(optional)
-item_type_id
(optional)
-package_id
(optional)
-location
(optional)
-related_link_url
(optional)
-related_link_text
(optional)
-redirect_to_rel_link_p
(optional)
-cal_uid
(optional)
-ical_vars
(optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_cal_item_add_delete cal_item_add_delete (test calendar) calendar::item::new calendar::item::new test_cal_item_add_delete->calendar::item::new test_cal_item_edit_recurrence cal_item_edit_recurrence (test calendar) test_cal_item_edit_recurrence->calendar::item::new _ _ (public) calendar::item::new->_ ad_conn ad_conn (public) calendar::item::new->ad_conn ad_return_complaint ad_return_complaint (public) calendar::item::new->ad_return_complaint ad_script_abort ad_script_abort (public) calendar::item::new->ad_script_abort calendar::do_notifications calendar::do_notifications (public) calendar::item::new->calendar::do_notifications packages/calendar/www/cal-item-new.tcl packages/calendar/ www/cal-item-new.tcl packages/calendar/www/cal-item-new.tcl->calendar::item::new

Testcases:
cal_item_edit_recurrence, cal_item_add_delete
Source code:
    if {$package_id eq ""} {
        set package_id [ad_conn package_id]
    }
    if {[dates_valid_p -start_date $start_date -end_date $end_date]} {
        set creation_ip [ad_conn peeraddr]
        set creation_user [ad_conn user_id]

        set activity_id [db_exec_plsql insert_activity {} ]

        #
        # In case we have a cal_uid, save it in the cal_uids table
        # together with the ical_vars.
        #
        if {$cal_uid ne ""} {
            db_dml insert_cal_uid {}
        }

        # Convert from user timezone to system timezone
        if { $start_date ne $end_date } {

            # Convert to server timezone only if it's not an all-day event
            # otherwise, keep the start and end time as 00:00

            set start_date [lc_time_conn_to_system $start_date]
            set end_date [lc_time_conn_to_system $end_date]
        }

        set timespan_id [db_exec_plsql insert_timespan {}]

        # create the cal_item
        # we are leaving the name and description fields in acs_event
        # blank to abide by the definition that an acs_event is an acs_activity
        # with added on temporal information

        # by default, the cal_item permissions
        # are going to be inherited from the calendar permissions
        set cal_item_id [db_exec_plsql cal_item_add {}]

        db_dml set_item_type_id "update cal_items set item_type_id=:item_type_id where cal_item_id=:cal_item_id"

        # removing inherited permissions
        if { $calendar_id ne "" && [calendar::personal_p -calendar_id $calendar_id] } {
            permission::set_not_inherit -object_id $cal_item_id
        }

        ::permission::grant  -object_id $cal_item_id  -party_id $creation_user  -privilege admin

        calendar::do_notifications -mode New -cal_item_id $cal_item_id
        return $cal_item_id

    } else {
        ad_return_complaint 1 [_ calendar.start_time_before_end_time]
        ad_script_abort
    }
Generic XQL file:
<fullquery name="calendar::item::new.insert_cal_uid">
    <querytext>
        insert into cal_uids 
            (cal_uid, on_which_activity, ical_vars)
        values
            (:cal_uid, :activity_id, :ical_vars)
    </querytext>
</fullquery>
packages/calendar/tcl/cal-item-procs.xql

PostgreSQL XQL file:
<fullquery name="calendar::item::new.insert_activity">
    <querytext>
	select acs_activity__new (
					null,
					:name,
					:description,
					'f',
					null,
					'acs_activity', 
					now(),
					:creation_user,
					:creation_ip,
					null
	)

      </querytext>
</fullquery>

<fullquery name="calendar::item::new.insert_timespan">
    <querytext>
	select timespan__new (    
					:start_date::timestamptz,
					:end_date::timestamptz
	) 

      </querytext>
</fullquery>

<fullquery name="calendar::item::new.cal_item_add">
    <querytext>
	select cal_item__new (
					null,
					:calendar_id,
					:name,
					null,
                                        null,
                                        null,
					:timespan_id,
					:activity_id,
					null, 
					'cal_item',
					:calendar_id,
					now(),
					:creation_user,
					:creation_ip,
					:package_id,					
					:location,
					:related_link_url,
					:related_link_text,
					:redirect_to_rel_link_p
	)

     </querytext>
</fullquery>
packages/calendar/tcl/cal-item-procs-postgresql.xql

Oracle XQL file:
<fullquery name="calendar::item::new.insert_activity">
    <querytext>
      
	begin
	:1 := acs_activity.new (
	  name          => :name,
	  description   => :description,
	  creation_user => :creation_user,
	  creation_ip   => :creation_ip
	);
	end;
    
      </querytext>
</fullquery>

<fullquery name="calendar::item::new.insert_timespan">
    <querytext>
      
	begin
	:1 := timespan.new(
	  start_date => to_date(:start_date,'YYYY-MM-DD HH24:MI'),
	  end_date   => to_date(:end_date,'YYYY-MM-DD HH24:MI')
	);
	end;
    
      </querytext>
</fullquery>

<fullquery name="calendar::item::new.cal_item_add">
    <querytext>
      
	begin
	:1 := cal_item.new(
	  on_which_calendar      => :calendar_id,
          name                   => :name, 
	  activity_id            => :activity_id,
          timespan_id            => :timespan_id,
          item_type_id           => :item_type_id,
	  creation_user          => :creation_user,
	  creation_ip            => :creation_ip,
          context_id             => :calendar_id,
          package_id             => :package_id,	  
	  location               => :location,
	  related_link_url       => :related_link_url,
	  related_link_text      => :related_link_text,
	  redirect_to_rel_link_p => :redirect_to_rel_link_p
	);
	end;
    
      </querytext>
</fullquery>
packages/calendar/tcl/cal-item-procs-oracle.xql

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