From: Michael J. Rubinsky Date: Wed, 19 Aug 2009 14:47:53 +0000 (-0400) Subject: implement basic listing method...no filters yet. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=084736318e52e00e7024405dc8ae136fea68be15;p=horde.git implement basic listing method...no filters yet. --- diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index 7a11f3387..6a86da808 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -761,6 +761,7 @@ class Kronolith_Driver_Sql extends Kronolith_Driver * @param $resource * * @return Kronolith_Resource object + * @throws Horde_Exception */ public function saveResource($resource) { @@ -788,6 +789,14 @@ class Kronolith_Driver_Sql extends Kronolith_Driver return $resource; } + /** + * Obtain a Kronolith_Resource by the resource's id + * + * @param int $id The key for the Kronolith_Resource + * + * @return array A hash of resource object properties + * @throws Horde_Exception + */ public function getResource($id) { $query = 'SELECT resource_id, resource_name, resource_calendar, resource_category FROM kronolith_resources WHERE resource_id = ?'; @@ -807,6 +816,14 @@ class Kronolith_Driver_Sql extends Kronolith_Driver return $return; } + /** + * Obtain the resource id associated with the given calendar uid. + * + * @param string $calendar The calendar's uid + * + * @return int The Kronolith_Resource id + * @throws Horde_Exception + */ public function getResourceIdByCalendar($calendar) { $query = 'SELECT resource_id FROM kronolith_resources WHERE resource_calendar = ?'; @@ -822,6 +839,24 @@ class Kronolith_Driver_Sql extends Kronolith_Driver } /** + * Return a list of Kronolith_Resources + * + * This method will likely be a moving target as group resources are + * fleshed out. + * + */ + function listResources($params = array()) + { + $query = 'SELECT resource_id, resource_name, resource_calendar, resource_category FROM kronolith_resources'; + $results = $this->_db->getAll($query, null, DB_FETCHMODE_ASSOC); + if ($results instanceof PEAR_Error) { + throw new Horde_Exception($results->getMessage()); + } + + return $results; + } + + /** * Attempts to open a connection to the SQL server. * * @return boolean True. diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php index bb2a0934f..d67d09538 100644 --- a/kronolith/lib/Resource.php +++ b/kronolith/lib/Resource.php @@ -22,7 +22,7 @@ class Kronolith_Resource /** * - * @return unknown_type + * @return array of Kronolith_Resource objects */ static public function listResources($params = array()) { @@ -32,7 +32,13 @@ class Kronolith_Resource self::$_driver = Kronolith::getDriver('Sql'); } - self::$_driver->listResources($params); + $resources = self::$_driver->listResources($params); + $return = array(); + foreach ($resources as $resource) { + $return[] = new Kronolith_Resource_Single($resource); + } + + return $return; } /** diff --git a/kronolith/lib/Resource/Single.php b/kronolith/lib/Resource/Single.php index 7a71f7252..cfbe3b0b7 100644 --- a/kronolith/lib/Resource/Single.php +++ b/kronolith/lib/Resource/Single.php @@ -63,9 +63,8 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base } /** - * Obtain the freebusy information for this resource. Takes into account - * if this is a group of resources or not. (Returns the cumulative FB info - * for all the resources in the group. + * Obtain the freebusy information for this resource. + * * @return unknown_type */ public function getFreeBusy($startstamp = null, $endstamp = null, $asObject = false) diff --git a/kronolith/resources.php b/kronolith/resources.php index abec90c16..a8cc38a52 100644 --- a/kronolith/resources.php +++ b/kronolith/resources.php @@ -17,10 +17,13 @@ $new = array('name' => _("N329SP"), //var_dump($results); /* Test adding resource to event */ -$resource = Kronolith_Resource::getResource(6); -$driver = Kronolith::getDriver('Sql'); -$event = $driver->getByUID('20090817131028.10427ipjxgq69hk4@localhost'); -$event->addResource($resource, Kronolith::RESPONSE_NONE); -$event->save(); +//$resource = Kronolith_Resource::getResource(6); +//$driver = Kronolith::getDriver('Sql'); +//$event = $driver->getByUID('20090730102515.90466g7f034lxucc@localhost'); +//$event->addResource($resource, Kronolith::RESPONSE_NONE); +//$event->save(); +// +//var_dump($resource->getFreeBusy(null, null, true)); -var_dump($resource->getFreeBusy(null, null, true)); \ No newline at end of file +/* Test listing resources */ +var_dump(Kronolith_Resource::listResources()); \ No newline at end of file