From: Michael J. Rubinsky Date: Mon, 17 Aug 2009 17:40:06 +0000 (-0400) Subject: Flesh out some methods in Event and Driver to deal with auto accepting X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2b79e7914be31c9181abcce664520d5e26366712;p=horde.git Flesh out some methods in Event and Driver to deal with auto accepting resource requests --- diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index e74359999..bfc584f67 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -534,6 +534,16 @@ class Kronolith_Driver_Sql extends Kronolith_Driver */ public function saveEvent($event) { + /* Deal with Kronolith_Resources before anything else is done */ + foreach ($event->getResources() as $resource) { + if ($resource->isFree($this)) { + $resource->attachToEvent($this); + $event->addResource($resource, Kronolith::RESPONSE_ACCEPTED); + } else { + $event->addResource($resource, Kronolith::RESPONSE_DECLINED); + } + } + if ($event->isStored() || $event->exists()) { $values = array(); diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index 1afaba319..98cc900e6 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -125,6 +125,18 @@ abstract class Kronolith_Event public $attendees = array(); /** + * All resources of this event. + * + * This is an associative array where keys are resource uids values are + * associative arrays with keys attendance and response... actually, do we + * *need* an attendence setting for resources? Shouldn't they be required + * by definition? + * + * @var unknown_type + */ + protected $_resources = array(); + + /** * The start time of the event. * * @var Horde_Date @@ -1529,6 +1541,62 @@ abstract class Kronolith_Event } } + /** + * Adds a Kronolith_Resource to this event. + * No validation or acceptence/denial is done here...it should be done + * when saving the Event so we can capture any errors? + * + * @param Kronolith_Resource $resource The resource to add + * + * @return void + */ + public function addResource($resource, $response) + { + $this->_resources[$resource->uid] = array( + 'attendance' => Kronolith::PART_REQUIRED, + 'response' => $response, + 'name' => $resource->name + ); + } + + /** + * Remove a Kronolith_Resource from this event + * + * @param Kronolith_Resource $resource The resource to remove + * + * @return void + */ + function removeResource($resource) + { + if (isset($this->_resources[$resource->uid])) { + unset ($this->_resources[$resource->uid]); + } + } + + /** + * Returns the entire resources array. + * + * @return array A copy of the attendees array. + */ + public function getResources() + { + return $this->_resources; + } + + /** + * Checks to see whether the specified resource is associated with this + * event. + * + * @param string $uid The resource uid. + * + * @return boolean True if the specified attendee is present for this + * event. + */ + public function hasResource($uid) + { + return isset($this->_resources[$uid]); + } + public function isAllDay() { return $this->allday || diff --git a/kronolith/lib/Event/Sql.php b/kronolith/lib/Event/Sql.php index 05161eb64..11b10de52 100644 --- a/kronolith/lib/Event/Sql.php +++ b/kronolith/lib/Event/Sql.php @@ -116,6 +116,9 @@ class Kronolith_Event_Sql extends Kronolith_Event if (isset($SQLEvent['event_attendees'])) { $this->attendees = array_change_key_case($driver->convertFromDriver(unserialize($SQLEvent['event_attendees']))); } + if (isset($SQLEvent['event_resources'])) { + $this->_resources = array_change_key_case($driver->convertFromDriver(unserialize($SQLEvent['event_resources']))); + } if (isset($SQLEvent['event_description'])) { $this->description = $driver->convertFromDriver($SQLEvent['event_description']); } @@ -141,6 +144,7 @@ class Kronolith_Event_Sql extends Kronolith_Event $this->_properties['event_private'] = (int)$this->isPrivate(); $this->_properties['event_status'] = $this->getStatus(); $this->_properties['event_attendees'] = serialize($driver->convertToDriver($this->getAttendees())); + $this->_properties['event_resources'] = serialize($driver->convertToDriver($this->getResources())); $this->_properties['event_modified'] = $_SERVER['REQUEST_TIME']; if ($this->isAllDay()) { diff --git a/kronolith/lib/Resource/Base.php b/kronolith/lib/Resource/Base.php index 7a9f6e0a8..590013e5a 100644 --- a/kronolith/lib/Resource/Base.php +++ b/kronolith/lib/Resource/Base.php @@ -47,10 +47,7 @@ class Kronolith_Resource_Base /** * Adds $event to this resource's calendar - thus blocking the time - * for any other event. Also responsible for setting the attendence status - * for the resource in the event object. i.e. calling addResource() (just - * like updating an attendee is done by calling addAttendee on the same - * attendee again). + * for any other event. * * @param $event * @return unknown_type