*/
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();
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);
}
*/
public function addResource($resource, $response)
{
- $this->_resources[$resource->uid] = array(
+ $this->_resources[$resource->id] = array(
'attendance' => Kronolith::PART_REQUIRED,
'response' => $response,
'name' => $resource->name
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));
+ }
+
}
<?php
/**
+ * Base class for dealing with Kronolith_Resource objects. Handles basic
+ * creation/deletion/listing by delegating to the underlying Kronolith_Driver
+ * object.
*
+ * For now, assume SQL driver only. Could probably easily extend this to use
+ * different backend drivers if/when support is added to those drivers for
+ * resources.
+ *
+ * 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 <mrubinsk@horde.org>
+ * @package Kronolith
*/
class Kronolith_Resource
{
static public function getResource($id)
{
$driver = Kronolith::getDriver('Sql');
-
return new Kronolith_Resource_Single($driver->getResource($id));
}
*
* 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?
* @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
* @param $event
* @return unknown_type
*/
- abstract public function attachToEvent($event);
+ abstract public function addEvent($event);
/**
* Remove this event from resource's calendar
* @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
/**
* 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 <mrubinsk@horde.org>
+ * @package Kronolith
*/
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();
}
/**
* @param $event
* @return unknown_type
*/
- public function detachFromEvent($event)
+ public function removeEvent($event)
{
}
$title = _("Edit resources");
require KRONOLITH_TEMPLATES . '/common-header.inc';
-/* Test some resource crap */
+/* Test creating a new resource */
$new = array('name' => _("N329SP"),
'category' => 'test');
//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();