From: Michael J. Rubinsky Date: Fri, 11 Sep 2009 23:42:07 +0000 (-0400) Subject: Move checkResources() to Kronolith::, and out of the concrete Event_Sql driver. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=04069c8914935391d3113e93098da03dccc96e8d;p=horde.git Move checkResources() to Kronolith::, and out of the concrete Event_Sql driver. 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). --- diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index 8c9e4b205..060bb6587 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -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(); diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index b6094a6c8..1d003c31f 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -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') && diff --git a/kronolith/lib/Event/Sql.php b/kronolith/lib/Event/Sql.php index 992089d8c..11b10de52 100644 --- a/kronolith/lib/Event/Sql.php +++ b/kronolith/lib/Event/Sql.php @@ -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)); - } - } diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 539524bbe..b0b29039d 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -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) {