Commit 59b0cd6c authored by Frank Bergmann's avatar Frank Bergmann

- Comitting OpenACS 5.9

parent e8a7b68f
......@@ -7,16 +7,16 @@
<initial-install-p>f</initial-install-p>
<singleton-p>t</singleton-p>
<version name="0.6.1" url="http://openacs.org/repository/download/apm/acs-events-0.6.1.apm">
<version name="0.6d8" url="http://openacs.org/repository/download/apm/acs-events-0.6d8.apm">
<owner url="http://openacs.org">OpenACS</owner>
<summary>API support for relationships between intervals in time, activities, and parties.</summary>
<release-date>2006-02-18</release-date>
<release-date>2014-11-27</release-date>
<vendor url="http://openacs.org">OpenACS</vendor>
<description format="text/html">The events service is primarily intended for use by writers of application packages and other service packages. The service allows developers to specify and manipulate relationships (possibly recurring) between an object and another object.</description>
<maturity>0</maturity>
<provides url="acs-events" version="0.6.1"/>
<requires url="acs-kernel" version="5.5.0"/>
<maturity>2</maturity>
<provides url="acs-events" version="0.6d8"/>
<requires url="acs-kernel" version="5.8.1"/>
<callbacks>
</callbacks>
......
This diff is collapsed.
......@@ -14,8 +14,6 @@ drop table acs_event_party_map;
drop index acs_events_recurrence_id_idx;
drop table acs_events;
drop sequence acs_events_sequence;
drop view acs_events_seq;
\i recurrence-drop.sql
\i timespan-drop.sql
......
This diff is collapsed.
......@@ -7,116 +7,139 @@
--
-- $Id$
create function dow_to_int (
--
-- Convert string to day of the week
--
-- Note that the output of extract(dow from timestamp) and to_char(timestamp,'D')
-- are different! to_char is more consistent with Oracle, so we only use to_char.
--
-- @author jowell@jsabino.com
--
-- @param weekday Day of the week string to be converted to Postgres int representation
--
-- @return integer corresponding to Postgres representation of day of the week (Sunday = 0)
--
varchar
)
returns integer as '
declare
dow_to_int__weekday alias for $1;
-- added
select define_function_args('dow_to_int','weekday');
--
-- procedure dow_to_int/1
--
--
-- Convert string to day of the week
--
-- Note that the output of extract(dow from timestamp) and to_char(timestamp,'D')
-- are different! to_char is more consistent with Oracle, so we only use to_char.
--
-- @author jowell@jsabino.com
--
-- @param weekday Day of the week string to be converted to Postgres int representation
--
-- @return integer corresponding to Postgres representation of day of the week (Sunday = 0)
--
CREATE OR REPLACE FUNCTION dow_to_int(
dow_to_int__weekday varchar
) RETURNS integer AS $$
DECLARE
v_dow integer;
begin
BEGIN
-- Brute force (what can I say?).
select (case trim(upper(dow_to_int__weekday))
when ''SUNDAY'' then 1
when ''SUN'' then 1
when ''MONDAY'' then 2
when ''MON'' then 2
when ''TUESDAY'' then 3
when ''TUES'' then 3
when ''TUE'' then 3
when ''WEDNESDAY'' then 4
when ''WED'' then 4
when ''WEDS'' then 4
when ''THURSDAY'' then 5
when ''THURS'' then 5
when ''THUR'' then 5
when ''THU'' then 5
when ''FRIDAY'' then 6
when ''FRI'' then 6
when ''SATURDAY'' then 7
when ''SAT'' then 7
when 'SUNDAY' then 1
when 'SUN' then 1
when 'MONDAY' then 2
when 'MON' then 2
when 'TUESDAY' then 3
when 'TUES' then 3
when 'TUE' then 3
when 'WEDNESDAY' then 4
when 'WED' then 4
when 'WEDS' then 4
when 'THURSDAY' then 5
when 'THURS' then 5
when 'THUR' then 5
when 'THU' then 5
when 'FRIDAY' then 6
when 'FRI' then 6
when 'SATURDAY' then 7
when 'SAT' then 7
else -1
end) into v_dow
from dual;
if v_dow < 0
then
raise exception ''Day of the week unknown'';
raise exception 'Day of the week unknown';
end if;
return v_dow;
end;' language 'plpgsql';
create function to_interval (
--
-- Convert an integer to the specified interval
--
-- Utility function so we do not have to remember how to escape
-- double quotes when we typecast an integer to an interval
--
-- @author jowell@jsabino.com
--
-- @param interval_number Integer to convert to interval
-- @param interval_units Interval units
--
-- @return interval equivalent of interval_number, in interval_units units
--
integer,
varchar
)
returns interval as '
declare
interval__number alias for $1;
interval__units alias for $2;
begin
END;
$$ LANGUAGE plpgsql;
-- added
select define_function_args('to_interval','number,units');
--
-- procedure to_interval/2
--
--
-- Convert an integer to the specified interval
--
-- Utility function so we do not have to remember how to escape
-- double quotes when we typecast an integer to an interval
--
-- @author jowell@jsabino.com
--
-- @param interval_number Integer to convert to interval
-- @param interval_units Interval units
--
-- @return interval equivalent of interval_number, in interval_units units
--
CREATE OR REPLACE FUNCTION to_interval(
interval__number integer,
interval__units varchar
) RETURNS interval AS $$
DECLARE
BEGIN
-- We should probably do unit checking at some point
return ('''''''' || interval__number || '' '' || interval__units || '''''''')::interval;
end;' language 'plpgsql';
create function next_day (
--
-- Equivalent of Oracle next_day function
--
-- @author jowell@jsabino.com
--
-- @param somedate Reference date
-- @param weekday Day of the week to find
--
-- @return The date of the next weekday that is later than somedate
--
timestamptz, -- somedate
varchar -- weekday
)
returns timestamptz as '
declare
next_day__somedate alias for $1;
next_day__weekday alias for $2;
return ('''' || interval__number || ' ' || interval__units || '''')::interval;
END;
$$ LANGUAGE plpgsql;
-- added
select define_function_args('next_day','somedate,weekday');
--
-- procedure next_day/2
--
--
-- Equivalent of Oracle next_day function
--
-- @author jowell@jsabino.com
--
-- @param somedate Reference date
-- @param weekday Day of the week to find
--
-- @return The date of the next weekday that is later than somedate
--
CREATE OR REPLACE FUNCTION next_day(
next_day__somedate timestamptz,
next_day__weekday varchar
) RETURNS timestamptz AS $$
DECLARE
v_dow integer;
v_ref_dow integer;
v_add_days integer;
begin
BEGIN
-- I cant find a function that converts days of the week to
-- the corresponding integer value, so I roll my own (above)
-- We avoid extract(dow from timestamp) because of incompatible output with to_char.
v_ref_dow := dow_to_int(next_day__weekday);
v_dow := to_number(to_char(next_day__somedate,''D''),''9'');
v_dow := to_number(to_char(next_day__somedate,'D'),'9');
-- If next_day___weekday is the same day of the week as
-- next_day__somedate, we add a full week.
......@@ -128,55 +151,69 @@ begin
end if;
-- Do date math
return next_day__somedate + to_interval(v_add_days,''days'');
end;' language 'plpgsql';
create function add_months (
--
-- Equivalent of Oracle add_months function
--
-- @author jowell@jsabino.com
--
-- @param somedate Reference date
-- @param n_months Day of the week to find
--
-- @return The date plus n_months full months
--
timestamptz,
integer
)
returns timestamptz as '
declare
add_months__somedate alias for $1;
add_months__n_months alias for $2;
begin
return next_day__somedate + to_interval(v_add_days,'days');
END;
$$ LANGUAGE plpgsql;
-- added
select define_function_args('add_months','somedate,n_months');
--
-- procedure add_months/2
--
--
-- Equivalent of Oracle add_months function
--
-- @author jowell@jsabino.com
--
-- @param somedate Reference date
-- @param n_months Day of the week to find
--
-- @return The date plus n_months full months
--
CREATE OR REPLACE FUNCTION add_months(
add_months__somedate timestamptz,
add_months__n_months integer
) RETURNS timestamptz AS $$
DECLARE
BEGIN
-- Date math magic
return add_months__somedate + to_interval(add_months__n_months,''months'');
end;' language 'plpgsql';
create function last_day (
--
-- Equivalent of Oracle last_day function
--
-- @author jowell@jsabino.com
--
-- @param somedate Reference date
--
-- @return The last day of the month containing somedate
--
timestamptz
)
returns timestamptz as '
declare
last_day__somedate alias for $1;
return add_months__somedate + to_interval(add_months__n_months,'months');
END;
$$ LANGUAGE plpgsql;
-- added
select define_function_args('last_day','somedate');
--
-- procedure last_day/1
--
--
-- Equivalent of Oracle last_day function
--
-- @author jowell@jsabino.com
--
-- @param somedate Reference date
--
-- @return The last day of the month containing somedate
--
CREATE OR REPLACE FUNCTION last_day(
last_day__somedate timestamptz
) RETURNS timestamptz AS $$
DECLARE
v_month integer;
v_targetmonth integer;
v_date timestamptz;
v_targetdate timestamptz;
begin
BEGIN
-- Initial values
v_targetdate := last_day__somedate;
......@@ -185,7 +222,7 @@ begin
-- Add up to 31 days to the given date, stop if month changes.
FOR i IN 1..31 LOOP
v_date := last_day__somedate + to_interval(i,''days'');
v_date := last_day__somedate + to_interval(i,'days');
v_month := extract(month from v_date);
if v_month != v_targetmonth
......@@ -199,7 +236,8 @@ begin
return v_targetdate;
end;' language 'plpgsql';
END;
$$ LANGUAGE plpgsql;
......@@ -8,7 +8,6 @@
-- Sequence for recurrence tables
create sequence recurrence_sequence start 1;
create view recurrence_seq as select nextval('recurrence_sequence') as nextval;
-- These columns describe how an event recurs. The are modeled on the Palm DateBook.
-- The interval_type 'custom' indicates that the PL/SQL function referenced in
......@@ -123,38 +122,42 @@ comment on column recurrences.custom_func is '
-- Currently supports only new and delete methods.
--
create function recurrence__new (
--
-- Creates a new recurrence
--
-- @author W. Scott Meeks
--
-- @param interval_type Sets interval_type of new recurrence
-- @param every_nth_interval Sets every_nth_interval of new recurrence
-- @param days_of_week Sets days_of_week of new recurrence
-- @param recur_until Sets recur_until of new recurrence
-- @param custom_func Sets name of custom recurrence function
--
-- @return id of new recurrence
--
varchar, -- recurrence_interval_types.interval_name%TYPE,
integer, -- recurrences.every_nth_interval%TYPE,
varchar, -- recurrences.days_of_week%TYPE default null,
timestamptz, -- recurrences.recur_until%TYPE default null,
varchar -- recurrences.custom_func%TYPE default null
)
returns integer as ' -- recurrences.recurrence_id%TYPE
declare
new__interval_name alias for $1;
new__every_nth_interval alias for $2;
new__days_of_week alias for $3; -- default null,
new__recur_until alias for $4; -- default null,
new__custom_func alias for $5; -- default null
-- added
select define_function_args('recurrence__new','interval_name,every_nth_interval,days_of_week;null,recur_until;null,custom_func;null');
--
-- procedure recurrence__new/5
--
--
-- Creates a new recurrence
--
-- @author W. Scott Meeks
--
-- @param interval_type Sets interval_type of new recurrence
-- @param every_nth_interval Sets every_nth_interval of new recurrence
-- @param days_of_week Sets days_of_week of new recurrence
-- @param recur_until Sets recur_until of new recurrence
-- @param custom_func Sets name of custom recurrence function
--
-- @return id of new recurrence
--
CREATE OR REPLACE FUNCTION recurrence__new(
new__interval_name varchar,
new__every_nth_interval integer,
new__days_of_week varchar, -- default null,
new__recur_until timestamptz, -- default null,
new__custom_func varchar -- default null
) RETURNS integer AS $$
DECLARE
v_recurrence_id recurrences.recurrence_id%TYPE;
v_interval_type_id recurrence_interval_types.interval_type%TYPE;
begin
BEGIN
select recurrence_seq.nextval into v_recurrence_id from dual;
select nextval('recurrence_sequence') into v_recurrence_id from dual;
select interval_type
into v_interval_type_id
......@@ -178,33 +181,40 @@ begin
return v_recurrence_id;
end;' language 'plpgsql';
create function recurrence__delete (
--
-- Deletes the recurrence
-- Note: this will fail if there are any events_with this recurrence
-- because of foreign key constraints. use acs-events__delete instead
--
-- @author W. Scott Meeks
--
-- @param recurrence_id id of recurrence to delete
--
-- @return 0 (procedure dummy)
--
integer -- in recurrences.recurrence_id%TYPE
)
returns integer as '
declare
delete__recurrence_id alias for $1;
begin
END;
$$ LANGUAGE plpgsql;
-- added
select define_function_args('recurrence__delete','recurrence_id');
--
-- procedure recurrence__delete/1
--
--
-- Deletes the recurrence
-- Note: this will fail if there are any events_with this recurrence
-- because of foreign key constraints. use acs-events__delete instead
--
-- @author W. Scott Meeks
--
-- @param recurrence_id id of recurrence to delete
--
-- @return 0 (procedure dummy)
--
CREATE OR REPLACE FUNCTION recurrence__delete(
delete__recurrence_id integer
) RETURNS integer AS $$
DECLARE
BEGIN
delete from recurrences
where recurrence_id = delete__recurrence_id;
return 0;
end;' language 'plpgsql';
END;
$$ LANGUAGE plpgsql;
......@@ -11,4 +11,4 @@ drop table recurrences;
drop table recurrence_interval_types;
drop sequence recurrence_sequence;
drop view recurrence_seq;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -14,4 +14,3 @@ select drop_package('time_interval');
drop table time_intervals;
drop sequence timespan_sequence;
drop view timespan_seq;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment