From 666b5915371bc69503a72018a8df6a04b8f5f1a8 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Mon, 17 Aug 2009 17:06:15 -0400 Subject: [PATCH] Start fleshing out the code to implement resources --- kronolith/lib/Driver/Sql.php | 9 +++++ kronolith/lib/Resource.php | 5 +++ kronolith/lib/Resource/Single.php | 69 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 kronolith/lib/Resource/Single.php diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index bfc584f67..82346249c 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -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. * diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php index d822783f9..66e8dbd2f 100644 --- a/kronolith/lib/Resource.php +++ b/kronolith/lib/Resource.php @@ -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 index 000000000..09dafc0fc --- /dev/null +++ b/kronolith/lib/Resource/Single.php @@ -0,0 +1,69 @@ +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 -- 2.11.0