Move checkResources() to Kronolith::, and out of the concrete Event_Sql driver.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 11 Sep 2009 23:42:07 +0000 (19:42 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:54 +0000 (16:53 -0400)
Move code for auto-accepting resources out of the Event driver and put
it into Kronolith:: Call it from Kronolith_Event::save() method (not 100%
sure about leaving it there, or just calling it in client code before saving
where appropriate).

kronolith/lib/Driver/Sql.php
kronolith/lib/Event.php
kronolith/lib/Event/Sql.php
kronolith/lib/Kronolith.php

index 8c9e4b2..060bb65 100644 (file)
@@ -535,7 +535,6 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
     public function saveEvent($event)
     {
         /* Check for acceptence/denial of resources */
-        $event->checkResources();
         if ($event->isStored() || $event->exists()) {
             $values = array();
 
index b6094a6..1d003c3 100644 (file)
@@ -316,6 +316,8 @@ abstract class Kronolith_Event
             return PEAR::raiseError('Event not yet initialized');
         }
 
+        // TODO: Should this go here?
+        Kronolith::checkResources($this);
         $this->toDriver();
         $result = $this->getDriver()->saveEvent($this);
         if (!is_a($result, 'PEAR_Error') &&
index 992089d..11b10de 100644 (file)
@@ -207,27 +207,4 @@ class Kronolith_Event_Sql extends Kronolith_Event
         return $this->_properties;
     }
 
-    /**
-     * Function to check availability and auto accept/decline for each resource
-     * attached to this event. Needed here instead of in Kronolith_Driver::saveEvent
-     * since self::_properties is already built at that point, and since it's
-     * not public, we need to access it from within this class.
-     *
-     * @return unknown_type
-     */
-    public function checkResources()
-    {
-        foreach ($this->_resources as $id => $resource) {
-            $r = Kronolith::getDriver('Resource')->getResource($id);
-            if ($r->isFree($this)) {
-                $r->addEvent($this);
-                $this->addResource($r, Kronolith::RESPONSE_ACCEPTED);
-            } else {
-                $this->addResource($r, Kronolith::RESPONSE_DECLINED);
-            }
-        }
-        $driver = $this->getDriver();
-        $this->_properties['event_resources'] = serialize($driver->convertToDriver($this->_resources));
-    }
-
 }
index 539524b..b0b2903 100644 (file)
@@ -2078,6 +2078,24 @@ class Kronolith
         return false;
     }
 
+    /**
+     * Function to check availability and auto accept/decline for each resource
+     * attached to the event.
+     *
+     * @return unknown_type
+     */
+    static public function checkResources($event)
+    {
+        foreach ($event->getResources() as $id => $resource) {
+            $r = Kronolith::getDriver('Resource')->getResource($id);
+            if ($r->isFree($event)) {
+                $r->addEvent($event);
+                $event->addResource($r, Kronolith::RESPONSE_ACCEPTED);
+            } else {
+                $event->addResource($r, Kronolith::RESPONSE_DECLINED);
+            }
+        }
+    }
 
     static public function getInternalCalendar($target)
     {