From: Michael J. Rubinsky Date: Tue, 18 Aug 2009 20:05:19 +0000 (-0400) Subject: Need to move the acceptance/denial of requests to the resource object X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=809ffc71da48c8709266c77bb0ee5e659ff32463;p=horde.git Need to move the acceptance/denial of requests to the resource object itself...otherwise, the internal properties array won't be serialized before saving. --- diff --git a/kronolith/lib/Driver/Sql.php b/kronolith/lib/Driver/Sql.php index 25a3999c7..65bea9a35 100644 --- a/kronolith/lib/Driver/Sql.php +++ b/kronolith/lib/Driver/Sql.php @@ -534,16 +534,8 @@ class Kronolith_Driver_Sql extends Kronolith_Driver */ public function saveEvent($event) { - /* Deal with Kronolith_Resources before anything else is done */ - foreach ($event->getResources() as $resource) { - if ($resource->isFree($this)) { - $resource->attachToEvent($this); - $event->addResource($resource, Kronolith::RESPONSE_ACCEPTED); - } else { - $event->addResource($resource, Kronolith::RESPONSE_DECLINED); - } - } - + /* Check for acceptence/denial of resources */ + $event->checkResources(); if ($event->isStored() || $event->exists()) { $values = array(); @@ -808,7 +800,6 @@ class Kronolith_Driver_Sql extends Kronolith_Driver throw new Horde_Exception('Resource not found'); } $return = array(); - var_dump($results); foreach ($results as $field => $value) { $return[str_replace('resource_', '', $field)] = $this->convertFromDriver($value); } diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index 98cc900e6..06d6c219b 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -1552,7 +1552,7 @@ abstract class Kronolith_Event */ public function addResource($resource, $response) { - $this->_resources[$resource->uid] = array( + $this->_resources[$resource->id] = array( 'attendance' => Kronolith::PART_REQUIRED, 'response' => $response, 'name' => $resource->name diff --git a/kronolith/lib/Event/Sql.php b/kronolith/lib/Event/Sql.php index 11b10de52..915241b7c 100644 --- a/kronolith/lib/Event/Sql.php +++ b/kronolith/lib/Event/Sql.php @@ -207,4 +207,26 @@ class Kronolith_Event_Sql extends Kronolith_Event return $this->_properties; } + /** + * Function to check availability and auto accept/decline for each resource + * attached to this event. Needed here instead of in Kronolith_Driver::saveEvent + * since the _properties array is already built at that point. + * + * @return unknown_type + */ + public function checkResources() + { + foreach ($this->_resources as $id => $resource) { + $r = Kronolith_Resource::getResource($id); + if ($r->isFree($this)) { + $r->addEvent($this); + $this->addResource($r, Kronolith::RESPONSE_ACCEPTED); + } else { + $this->addResource($r, Kronolith::RESPONSE_DECLINED); + } + } + $driver = $this->getDriver(); + $this->_properties['event_resources'] = serialize($driver->convertToDriver($this->_resources)); + } + } diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php index 093df485e..15bc6a74c 100644 --- a/kronolith/lib/Resource.php +++ b/kronolith/lib/Resource.php @@ -1,6 +1,20 @@ + * @package Kronolith */ class Kronolith_Resource { @@ -45,7 +59,6 @@ class Kronolith_Resource static public function getResource($id) { $driver = Kronolith::getDriver('Sql'); - return new Kronolith_Resource_Single($driver->getResource($id)); } diff --git a/kronolith/lib/Resource/Base.php b/kronolith/lib/Resource/Base.php index f0b7e4f0c..1c874daf2 100644 --- a/kronolith/lib/Resource/Base.php +++ b/kronolith/lib/Resource/Base.php @@ -22,7 +22,7 @@ abstract class Kronolith_Resource_Base * * Properties: * name - Display name of resource. - * calendar_id - The calendar associated with this resource. + * calendar - The calendar associated with this resource. * category - The category of this resource...an arbitrary label used * to group multiple resources for the resource_group implementation * properties - any other properties this resource may have? @@ -51,7 +51,7 @@ abstract class Kronolith_Resource_Base * @param $endTime * @return unknown_type */ - abstract public function isFree($startTime, $endTime); + abstract public function isFree($event); /** * Adds $event to this resource's calendar - thus blocking the time @@ -60,7 +60,7 @@ abstract class Kronolith_Resource_Base * @param $event * @return unknown_type */ - abstract public function attachToEvent($event); + abstract public function addEvent($event); /** * Remove this event from resource's calendar @@ -68,7 +68,7 @@ abstract class Kronolith_Resource_Base * @param $event * @return unknown_type */ - abstract public function detachFromEvent($event); + abstract public function removeEvent($event); /** * Obtain the freebusy information for this resource. Takes into account diff --git a/kronolith/lib/Resource/Single.php b/kronolith/lib/Resource/Single.php index ad034df90..1181ef6b2 100644 --- a/kronolith/lib/Resource/Single.php +++ b/kronolith/lib/Resource/Single.php @@ -2,6 +2,13 @@ /** * Kronolith_Resource implementation to represent a single resource. * + * Copyright 2009 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Michael J. Rubinsky + * @package Kronolith */ class Kronolith_Resource_Single extends Kronolith_Resource_Base { @@ -12,36 +19,36 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base * @param $endTime * @return unknown_type */ - public function isFree($startTime, $endTime) + public function isFree($event) { - + return true; } /** - * Adds $event to this resource's calendar - thus blocking the time - * for any other event. + * Adds $event to this resource's calendar or updates the current entry + * of the event in the calendar. * * @param $event * - * @return unknown_type - * @throws Horde_Exception + * @return void */ - public function attachToEvent($event) + public function addEvent($event) { /* Get a driver for this resource's calendar */ - $driver = Kronolith::getDriver(null, $this->calendar_id); + $driver = Kronolith::getDriver(null, $this->calendar); /* Make sure it's not already attached. */ $uid = $event->getUID(); - $existing = $driver->getByUID($uid, array($this->calendar_id)); + $existing = $driver->getByUID($uid, array($this->calendar)); if (!($existing instanceof PEAR_Error)) { - throw new Horde_Exception(_("Already Exists")); + $existing->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0'))); + $existing->save(); + } else { + /* Create a new event */ + $e = $driver->getEvent(); + $e->setCalendar($this->calendar); + $e->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0'))); + $e->save(); } - - /* Create a new event */ - $e = $driver->getEvent(); - $e->setCalendar($this->calendar_id); - $e->fromiCalendar($event->toiCalendar($iCal = new Horde_iCalendar('2.0'))); - $e->save(); } /** @@ -50,7 +57,7 @@ class Kronolith_Resource_Single extends Kronolith_Resource_Base * @param $event * @return unknown_type */ - public function detachFromEvent($event) + public function removeEvent($event) { } diff --git a/kronolith/resources.php b/kronolith/resources.php index e15ba9a5b..251c6a3f9 100644 --- a/kronolith/resources.php +++ b/kronolith/resources.php @@ -8,7 +8,7 @@ require_once dirname(__FILE__) . '/lib/base.php'; $title = _("Edit resources"); require KRONOLITH_TEMPLATES . '/common-header.inc'; -/* Test some resource crap */ +/* Test creating a new resource */ $new = array('name' => _("N329SP"), 'category' => 'test'); @@ -17,4 +17,8 @@ $new = array('name' => _("N329SP"), //var_dump($results); /* Test adding resource to event */ -var_dump(Kronolith_Resource::getResource(6)); \ No newline at end of file +$resource = Kronolith_Resource::getResource(6); +$driver = Kronolith::getDriver('Sql'); +$event = $driver->getByUID('20090610181329.12687chinwtntsg8@localhost'); +$event->addResource($resource, Kronolith::RESPONSE_NONE); +$event->save();