Commit 7d34b5ee authored by Frank Bergmann's avatar Frank Bergmann

Initial import

parents
Pipeline #61 failed with stages
<?xml version="1.0"?>
<!-- Generated by the OpenACS Package Manager -->
<package key="acs-events" url="http://openacs.org/repository/apm/packages/acs-events" type="apm_service">
<package-name>Events</package-name>
<pretty-plural>Events</pretty-plural>
<initial-install-p>f</initial-install-p>
<singleton-p>t</singleton-p>
<version name="0.4d2" url="http://openacs.org/repository/download/apm/acs-events-0.4d2.apm">
<owner url="http://openacs.org">OpenACS</owner>
<summary>API support for relationships between intervals in time, activities, and parties.</summary>
<release-date>2003-11-10</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>
<provides url="acs-events" version="0.4d"/>
<callbacks>
</callbacks>
<parameters>
<parameter datatype="number" min_n_values="1" max_n_values="1" name="EventFutureLimit" default="5" description="Maximum number of years to populate the database for recurring events."/>
</parameters>
</version>
</package>
This diff is collapsed.
-- packages/acs-events/sql/acs-events-drop.sql
--
-- $Id$
drop package acs_event;
drop view partially_populated_events;
drop view partially_populated_event_ids;
drop view acs_events_activities;
drop view acs_events_dates;
drop table acs_event_party_map;
drop index acs_events_recurrence_id_idx;
drop table acs_events;
begin
acs_object_type.drop_type ('acs_event');
end;
/
show errors
drop sequence acs_events_seq;
@@recurrence-drop
@@timespan-drop
@@activity-drop
\ No newline at end of file
This diff is collapsed.
-- packages/acs-events/sql/activity-drop.sql
--
-- $Id$
drop package acs_activity;
drop table acs_activity_object_map;
drop table acs_activities;
begin
acs_object_type.drop_type ('acs_activity');
end;
/
show errors
-- packages/acs-events/sql/recurrence-create.sql
--
-- Support for temporal recurrences
--
-- $Id$
-- 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
-- custom_func should be used to generate the recurrences.
-- Sequence for recurrence tables
create sequence recurrence_seq start with 1;
create table recurrence_interval_types (
interval_type integer
constraint recurrence_interval_type_pk primary key,
interval_name varchar2(50) not null
constraint rit_interval_name_un unique
);
set feedback off;
insert into recurrence_interval_types values (1,'day');
insert into recurrence_interval_types values (2,'week');
insert into recurrence_interval_types values (3,'month_by_date');
insert into recurrence_interval_types values (4,'month_by_day');
insert into recurrence_interval_types values (5,'last_of_month');
insert into recurrence_interval_types values (6,'year');
insert into recurrence_interval_types values (7,'custom');
set feedback on;
create table recurrences (
recurrence_id integer
constraint recurrences_pk primary key,
--
-- Indicate the interval type for recurrence (see above)
--
interval_type constraint recurs_interval_type_fk
references recurrence_interval_types not null,
--
-- Indicates how many of the given intervals between recurrences.
-- Must be a positive number!
--
every_nth_interval integer
constraint recurs_every_nth_interval_ck
check(every_nth_interval > 0),
--
-- If recurring on a weekly basis (interval_type = 'week')
-- indicates which days of the week the event recurs on.
-- This is represented as a space separated list of numbers
-- corresponding to days of the week, where 0 corresponds to
-- Sunday, 1 to Monday, and so on. Null indicates no days are set.
-- So for example, '1' indicates recur on Mondays, '3 5' indicates
-- recur on Wednesday and Friday.
--
days_of_week varchar2(20),
--
-- Indicates when this event should stop recurring. Null indicates
-- recur indefinitely.
--
recur_until date,
--
-- Recurring events can be only partially populated if fully populating
-- the events would require inserting too many instances. This
-- column indicates up to what date this event has recurred. This
-- allows further instances to be added if the user attempts to view
-- a date beyond db_populated_until. If recur_until is not null,
-- then this column will always be prior to or the same as recur_until.
-- This column will be null until some recurrences have been added.
--
db_populated_until date,
--
-- This column holds the name of a PL/SQL function that will be called
-- to generate dates of recurrences if interval_type is 'custom'
--
custom_func varchar2(255)
);
-- This is important to prevent locking on update of master table.
-- See http://www.arsdigita.com/bboard/q-and-a-fetch-msg.tcl?msg_id=000KOh
create index recurrences_interval_type_idx on recurrences(interval_type);
comment on table recurrences is '
Desribes how an event recurs.
';
comment on column recurrences.interval_type is '
One of day, week, month_by_date, month_by_day, last_of_month, year, custom.
';
comment on column recurrences.every_nth_interval is '
Indicates how many of the given intervals between recurrences.
';
comment on column recurrences.days_of_week is '
For weekly recurrences, stores which days of the week the event recurs on.
';
comment on column recurrences.recur_until is '
Indicates when this event should stop recurring. Null indicates
recur indefinitely.
';
comment on column recurrences.db_populated_until is '
Indicates the date of the last recurrence added. Used to determine if more
recurrences need to be added.
';
comment on column recurrences.custom_func is '
Stores the name of a PL/SQL function that can be called to generate dates
for special recurrences.
';
-- Recurrence API
--
-- Currently supports only new and delete methods.
--
create or replace package recurrence
as
function 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 optional If provided, sets days_of_week
-- of new recurrence
-- @param recur_until optional If provided, sets recur_until
-- of new recurrence
-- @param custom_func optional If provided, set name of
-- custom recurrence function
-- @return id of new recurrence
--
interval_type in recurrence_interval_types.interval_name%TYPE,
every_nth_interval in recurrences.every_nth_interval%TYPE,
days_of_week in recurrences.days_of_week%TYPE default null,
recur_until in recurrences.recur_until%TYPE default null,
custom_func in recurrences.custom_func%TYPE default null
) return recurrences.recurrence_id%TYPE;
procedure del (
-- Deletes the recurrence
-- @author W. Scott Meeks
-- @param recurrence_id id of recurrence to delete
--
recurrence_id in recurrences.recurrence_id%TYPE
);
end recurrence;
/
show errors
create or replace package body recurrence
as
function new (
interval_type in recurrence_interval_types.interval_name%TYPE,
every_nth_interval in recurrences.every_nth_interval%TYPE,
days_of_week in recurrences.days_of_week%TYPE default null,
recur_until in recurrences.recur_until%TYPE default null,
custom_func in recurrences.custom_func%TYPE default null
) return recurrences.recurrence_id%TYPE
is
recurrence_id recurrences.recurrence_id%TYPE;
interval_type_id recurrence_interval_types.interval_type%TYPE;
begin
select recurrence_seq.nextval into recurrence_id from dual;
select interval_type
into interval_type_id
from recurrence_interval_types
where interval_name = new.interval_type;
insert into recurrences
(recurrence_id,
interval_type,
every_nth_interval,
days_of_week,
recur_until,
custom_func)
values
(recurrence_id,
interval_type_id,
every_nth_interval,
days_of_week,
recur_until,
custom_func);
return recurrence_id;
end new;
-- Note: this will fail if there are any events_with this recurrence
procedure del (
recurrence_id in recurrences.recurrence_id%TYPE
)
is
begin
delete from recurrences
where recurrence_id = recurrence.del.recurrence_id;
end del;
end recurrence;
/
show errors
-- packages/acs-events/sql/recurrence-drop.sql
--
-- $Id$
drop package recurrence;
drop table recurrences;
drop table recurrence_interval_types;
drop sequence recurrence_seq;
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
-- packages/acs-events/sql/timespan-drop.sql
--
-- $Id$
drop package timespan;
drop index timespans_idx;
drop table timespans;
drop package time_interval;
drop table time_intervals;
drop sequence timespan_seq;
This diff is collapsed.
create index time_intervals_start_idx on time_intervals(start_date);
This diff is collapsed.
This diff is collapsed.
-- packages/acs-events/sql/acs-events-drop.sql
--
-- $Id$
-- drop package acs_event;
select drop_package('acs_event');
drop view partially_populated_events;
drop view partially_populated_event_ids;
drop view acs_events_activities;
drop view acs_events_dates;
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
\i activity-drop.sql
\i oracle-compat-drop.sql
-- acs_activity subclasses acs_event object, so we should only delete here.
select acs_object_type__drop_type ('acs_event','f');
This diff is collapsed.
-- packages/acs-events/sql/postgresql/activity-drop.sql
--
-- $Id$
-- drop package acs_activity;
select drop_package('acs_activity');
drop table acs_activity_object_map;
drop table acs_activities;
select acs_object_type__drop_type ('acs_activity','f');
-- packages/acs-events/sql/postgres/oracle-compat-create.sql
--
-- Functions to ease porting from Postgres to Oracle
--
-- @author jowell@jsabino.com
-- @creation-date 2001-06-26
--
-- $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;
v_dow integer;
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
else -1
end) into v_dow
from dual;
if v_dow < 0
then
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
-- 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;
v_dow integer;
v_ref_dow integer;
v_add_days integer;
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'');
-- If next_day___weekday is the same day of the week as
-- next_day__somedate, we add a full week.
if v_dow < v_ref_dow
then
v_add_days := v_ref_dow - v_dow;
else
v_add_days := v_ref_dow - v_dow + 7;
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
-- 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;
v_month integer;
v_targetmonth integer;
v_date timestamptz;
v_targetdate timestamptz;
begin
-- Initial values
v_targetdate := last_day__somedate;
v_targetmonth := extract(month from last_day__somedate);
-- 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_month := extract(month from v_date);
if v_month != v_targetmonth
then
exit;
else
v_targetdate := v_date;
end if;
END LOOP;
return v_targetdate;
end;' language 'plpgsql';
-- packages/acs-events/sql/postgres/oracle-compat-drop.sql
--
-- Drop functions that ease porting from Postgres to Oracle
--
-- @author jowell@jsabino.com
-- @creation-date 2001-06-26
--
-- $Id$
drop function dow_to_int(varchar);
drop function next_day(timestamptz,varchar);
drop function add_months(timestamptz,integer);
drop function last_day(timestamptz);
drop function to_interval(integer,varchar);
This diff is collapsed.
-- packages/acs-events/sql/recurrence-drop.sql
--
-- Drop support for temporal recurrences
--
-- $Id$
-- drop package recurrence;
select drop_package('recurrence');
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.
-- packages/acs-events/sql/postgresql/test/utest-drop.sql
--
-- Drop the unit test package
--
-- @author jowell@jsabino.com
-- @creation-date 2001-06-26
--
-- $Id$
-- For now, we require openacs4 installed.
select drop_package('ut_assert');
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
create index time_intervals_start_idx on time_intervals(start_date);
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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