Forum OpenACS Development: Calendar Create

Collapse
Posted by Iuri Sampaio on
Hi there,

The ad_proc "calendar::create owner_id private_p calendar_name" allows owner_id only as parties. Is it possible to create a calendar per content_item ?

I've created a custom subtype of content_item and it'd be great if it was possible to associate calendars respectively, without having to create an application group for every new content_item.

Best wishes,

Collapse
2: Re: Calendar Create (response to 1)
Posted by Iuri Sampaio on
So far,
I've found a way around, creating a new group and group_type.
Is there a better way to solve it?
Collapse
3: Re: Calendar Create (response to 2)
Posted by Gustaf Neumann on
The "owner_id" of the calendar has to be a party, since the API makes the owner the admin of the calendar, ... and the admin has to be a "party". You should be able to pass the creator of the content item as "owner_id".

Alternatively to subtypes, you can use "attachments::attach" [1] to associate a calendar (or calendar-item) to a "content_item"(or "content_revision"). The attachment makes sure, that the associated object is deleted, whenever the owner-object is deleted... There are certainly more than the mentioned ways, but these certainly depend unrevealed on application needs.

[1] https://openacs.org/api-doc/proc-view?proc=attachments::attach&source_p=1

Collapse
4: Re: Calendar Create (response to 3)
Posted by Iuri Sampaio on
Hi Gustaf,
Indeed, the best way would be to pass the creator of the content item. However, I hit the problem, because of a constraint in calendar pkg: The owner must be one, and only one, personal calendar.

Thus, I have to option:
1. Create a fictitious party and party_type;
2. Remove calendar constraint;

So far, I opted for solution 1. However, I'm going to study more the scenario, then I can have better and more enlightening ideas.

p.s. Attachment is not a solution because, by definition, the content item will never have an attachment.

Collapse
5: Re: Calendar Create (response to 4)
Posted by Iuri Sampaio on
Database operation "0or1row" failed (exception NSINT, "Query returned more than one row.")

SQL:
select calendar_id
from calendars
where owner_id = '698'
and private_p = 't'

while executing
"ns_pg_bind 0or1row nsdb0 {
select calendar_id

Collapse
6: Re: Calendar Create (response to 5)
Posted by Gustaf Neumann on
Don't define the calendar as private. The definition of "private calendars" in the calendar package is not great. The baseline assumption there is that the owner has just one private calendar.

There is no definition in OpenACS that states that "the content item will never have an attachment". The basic attachment API is designed for attaching/detaching arbitrary objects to other arbitrary objects (see table definition below), while some other parts of the API and the web-interface assume content from the content repository/file storage. You should be able to use at least attach/unattach.

-gn

          Table "public.attachments"
   Column   |  Type   |       Modifiers       
------------+---------+-----------------------
 object_id  | integer | not null
 item_id    | integer | not null
 approved_p | boolean | not null default true
Indexes:
    "attachments_pk" PRIMARY KEY, btree (object_id, item_id)
    "attachments_item_id_idx" btree (item_id)
Foreign-key constraints:
    "attachments_item_id_fk" FOREIGN KEY (item_id) REFERENCES acs_objects(object_id) ON DELETE CASCADE
    "attachments_object_id_fk" FOREIGN KEY (object_id) REFERENCES acs_objects(object_id) ON DELETE CASCADE