From e07639582cde389d23cb250a61785b806887b8a9 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Fri, 18 Sep 2009 00:35:11 -0400 Subject: [PATCH] Refactor a bit. Move Kronolith_Resource::checkResources to Kronolith_Resource_*::getResponse() and remove the responsibilty of adding the event. --- kronolith/attendees.php | 1 + kronolith/lib/Resource.php | 50 --------------------------------------- kronolith/lib/Resource/Single.php | 26 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 50 deletions(-) diff --git a/kronolith/attendees.php b/kronolith/attendees.php index 7dcd11286..9f67594d3 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -101,6 +101,7 @@ case 'add': // Any new resources? if (!empty($newResource)) { + /* Get the requested resource */ $resource = Kronolith::getDriver('Resource')->getResource($newResource); diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php index 59f90ff55..fdfccf821 100644 --- a/kronolith/lib/Resource.php +++ b/kronolith/lib/Resource.php @@ -105,54 +105,4 @@ class Kronolith_Resource return false; } - /** - * Function to check availability and set response status for each resource - * attached to the event. - * - * @param Kronolith_Event $event The event object to check the resources of - * - * @return void - */ - static public function checkResources($event) - { - foreach ($event->getResources() as $id => $resource) { - - /* Get the resource */ - $r = Kronolith::getDriver('Resource')->getResource($id); - - /* Determine if we have to calculate, or just auto-reply */ - $type = $r->getResponseType(); - switch($type) { - case Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT: - $r->addEvent($event); - $event->addResource($r, Kronolith::RESPONSE_ACCEPTED); - break; - case Kronolith_Resource::RESPONSETYPE_AUTO: - if ($r->isFree($event)) { - $r->addEvent($event); - $event->addResource($r, Kronolith::RESPONSE_ACCEPTED); - } else { - $event->addResource($r, Kronolith::RESPONSE_DECLINED); - } - break; - - case Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE: - $event->addResource($r, Kronolith::RESPONSE_DECLINED); - break; - - case Kronolith_Resource::RESPONSETYPE_NONE: - $event->addResource($r, Kronolith::RESPONSE_NONE); - break; - - case Kronolith_Resource::RESPONSETYPE_MANUAL: - // Would be nice to be able to utilize iTips, but - // no idea how that would work right now...resources are not - // user accounts etc...for now, just set as NONE - $event->addResource($r, Kronolith::RESONSE_NONE); - break; - } - - } - } - } \ No newline at end of file diff --git a/kronolith/lib/Resource/Single.php b/kronolith/lib/Resource/Single.php index eec8c097c..f7e31b045 100644 --- a/kronolith/lib/Resource/Single.php +++ b/kronolith/lib/Resource/Single.php @@ -117,6 +117,32 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base } /** + * Check avilability and return an appropriate Kronolith response code. + * + * @param Kronolith_Event $event The event to check on + * + * @return integer Kronolith::RESPONSE* constant + */ + function getResponse($event) + { + switch($this->getResponseType()) { + case Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT: + return Kronolith::RESPONSE_ACCEPTED; + case Kronolith_Resource::RESPONSETYPE_AUTO: + if ($this->isFree($event)) { + return Kronolith::RESPONSE_ACCEPTED; + } else { + return Kronolith::RESPONSE_DECLINED; + } + case Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE: + return Kronolith::RESPONSE_DECLINED; + case Kronolith_Resource::RESPONSETYPE_NONE: + case Kronolith_Resource::RESPONSETYPE_MANUAL: + return Kronolith::RESPONSE_NONE; + } + } + + /** * Obtain the freebusy information for this resource. * * @return unknown_type -- 2.11.0