implement basic listing method...no filters yet.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 19 Aug 2009 14:47:53 +0000 (10:47 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:49 +0000 (16:53 -0400)
kronolith/lib/Driver/Sql.php
kronolith/lib/Resource.php
kronolith/lib/Resource/Single.php
kronolith/resources.php

index 7a11f33..6a86da8 100644 (file)
@@ -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.
index bb2a093..d67d095 100644 (file)
@@ -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;
     }
 
     /**
index 7a71f72..cfbe3b0 100644 (file)
@@ -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)
index abec90c..a8cc38a 100644 (file)
@@ -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