Flesh out some methods in Event and Driver to deal with auto accepting
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 17 Aug 2009 17:40:06 +0000 (13:40 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:47 +0000 (16:53 -0400)
resource requests

kronolith/lib/Driver/Sql.php
kronolith/lib/Event.php
kronolith/lib/Event/Sql.php
kronolith/lib/Resource/Base.php

index e743599..bfc584f 100644 (file)
@@ -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();
 
index 1afaba3..98cc900 100644 (file)
@@ -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 ||
index 05161eb..11b10de 100644 (file)
@@ -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()) {
index 7a9f6e0..590013e 100644 (file)
@@ -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