From 7103f47b66b5bf41478437f18b923b725b298176 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 12 Sep 2009 11:38:48 -0400 Subject: [PATCH] Move static resource related methods to Kronolith_Resource:: --- kronolith/lib/Resource.php | 99 +++++++++++++++++++++++++++++++++++++++++++ kronolith/resources/index.php | 4 +- 2 files changed, 101 insertions(+), 2 deletions(-) diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php index 2c28dba44..b7465e922 100644 --- a/kronolith/lib/Resource.php +++ b/kronolith/lib/Resource.php @@ -53,4 +53,103 @@ class Kronolith_Resource return false; } + /** + * Adds a new resource to storage + * + * @param Kronolith_Resource $resource + * + * @return unknown_type + */ + static public function addResource($resource) + { + // Create a new calendar id. + $calendar = 'resource_' . hash('md5', microtime()); + $resource->set('calendar', $calendar); + $driver = Kronolith::getDriver('Resource'); + + return $driver->save($resource); + } + + /** + * Return a list of resources that the current user has access to at the + * specified permission level. Right now, all users have PERMS_READ, but + * only system admins have PERMS_EDIT | PERMS_DELETE + * + * @return array of Kronolith_Resource objects + */ + static public function listResources($perms = PERMS_READ, $params = array()) + { + if (($perms & (PERMS_EDIT | PERMS_DELETE)) && !Horde_Auth::isAdmin()) { + return array(); + } + + // Query kronolith_resource table for all(?) available resources? + // maybe by 'type' or 'name'? type would be arbitrary? + $driver = Kronolith::getDriver('Resource'); + return $driver->listResources($params); + } + + /** + * Determine if the provided calendar id represents a resource's calendar. + * + * @param $calendar + * @return unknown_type + */ + static public function isResourceCalendar($calendar) + { + if (strncmp($calendar, 'resource_', 9) === 0) { + return true; + } + + return false; + } + + /** + * Function to check availability and set response status for each resource + * attached to the event. + * + * @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/resources/index.php b/kronolith/resources/index.php index cf2339842..7082606d6 100644 --- a/kronolith/resources/index.php +++ b/kronolith/resources/index.php @@ -17,7 +17,7 @@ if (!Horde_Auth::getAuth()) { } $edit_url_base = Horde::applicationUrl('resources/edit.php'); $edit_img = Horde::img('edit.png', _("Edit"), null, $registry->getImageDir('horde')); -$resources = Kronolith::listResources(); +$resources = Kronolith_Resource::listResources(); $display_url_base = Horde::applicationUrl('month.php', true, -1); $delete_url_base = Horde::applicationUrl('resources/delete.php'); $delete_img = Horde::img('delete.png', _("Delete"), null, $registry->getImageDir('horde')); @@ -89,7 +89,7 @@ function shorten_url($url, $separator = '...', $first_chunk_length = 35, $last_c // 'category' => 'conference rooms'); // //$resource = new Kronolith_Resource_Single($new); -//$results = Kronolith::addResource($resource); +//$results = Kronolith_Resource::addResource($resource); //var_dump($results); ?> \ No newline at end of file -- 2.11.0