Start fleshing out the code to implement resources
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 17 Aug 2009 21:06:15 +0000 (17:06 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:47 +0000 (16:53 -0400)
kronolith/lib/Driver/Sql.php
kronolith/lib/Resource.php
kronolith/lib/Resource/Single.php [new file with mode: 0644]

index bfc584f..8234624 100644 (file)
@@ -763,6 +763,15 @@ class Kronolith_Driver_Sql extends Kronolith_Driver
         return true;
     }
 
+    public function saveResource($resource)
+    {
+        $query = 'INSERT INTO kronolith_resources (resource_uid, resource_name, resource_calendar, resource_category)';
+        $cols_values = ' VALUES (?, ?, ?, ?, ?)';
+        $id = $this->_db->nextId('kronolity_resources');
+        $values = array($id, $resource->name, $resource->calendar_id, $resource->category);
+        $result = $this->_write_db->query($query, $values);
+    }
+
     /**
      * Attempts to open a connection to the SQL server.
      *
index d822783..66e8dbd 100644 (file)
@@ -22,7 +22,12 @@ class Kronolith_Resource
      */
     static public function addResource($resource)
     {
+        // Create a new calendar id.
+        $calendar = hash('md5', microtime());
+        $resource->calendar_id = $calendar;
 
+        $driver = Kronolith::getDriver('Sql');
+        $driver->saveResource($resource);
     }
 
     /**
diff --git a/kronolith/lib/Resource/Single.php b/kronolith/lib/Resource/Single.php
new file mode 100644 (file)
index 0000000..09dafc0
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Kronolith_Resource implementation to represent a single resource.
+ *
+ */
+class Kronolith_Resource_Single extends Kronolith_Resource_Base
+{
+    /**
+     * Should this take an event, or a time range?
+     *
+     * @param $startTime
+     * @param $endTime
+     * @return unknown_type
+     */
+    public function isFree($startTime, $endTime)
+    {
+
+    }
+
+    /**
+     * Adds $event to this resource's calendar - thus blocking the time
+     * for any other event.
+     *
+     * @param $event
+     *
+     * @return unknown_type
+     * @throws Horde_Exception
+     */
+    public function attachToEvent($event)
+    {
+        /* Get a driver for this resource's calendar */
+        $driver = Kronolith::getDriver(null, $this->calendar_id);
+        /* Make sure it's not already attached. */
+        $uid = $event->getUID();
+        $existing = $driver->getByUID($uid, array($this->calendar_id));
+        if (!($existing instanceof PEAR_Error)) {
+            throw new Horde_Exception(_("Already Exists"));
+        }
+
+        /* Create a new event */
+        $e = $driver->getEvent();
+        $e->setCalendar($this->calendar_id);
+        $e->fromiCalendar($event->toiCalendar($iCal = new Horde_iCalendar('2.0')));
+        $e->save();
+    }
+
+    /**
+     * Remove this event from resource's calendar
+     *
+     * @param $event
+     * @return unknown_type
+     */
+    public function detachFromEvent($event)
+    {
+
+    }
+
+    /**
+     * 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.
+     * @return unknown_type
+     */
+    public function getFreeBusy()
+    {
+
+    }
+
+}
\ No newline at end of file