public function save($resource)
{
if ($resource->getId()) {
- $query = 'UPDATE kronolith_resources SET resource_name = ?, resource_calendar = ?, resource_category = ? , resource_description = ?, resource_response_type = ? WHERE resource_id = ?';
- $values = array($resource->get('name'), $resource->get('calendar'), $resource->get('category'), $resource->get('description'), $resource->get('response_type'), $resource->getId());
+ $query = 'UPDATE kronolith_resources SET resource_name = ?, resource_calendar = ?, resource_category = ? , resource_description = ?, resource_response_type = ?, resource_type = ?, resource_members = ? WHERE resource_id = ?';
+ $values = array($resource->get('name'), $resource->get('calendar'), $resource->get('category'), $resource->get('description'), $resource->get('response_type'), $resource->get('type'), $resource->get('members'), $resource->getId());
$result = $this->_write_db->query($query, $values);
if ($result instanceof PEAR_Error) {
throw new Horde_Exception($result->getMessage());
*
* @param int $id The key for the Kronolith_Resource
*
- * @return array A hash of resource object properties
+ * @return Kronolith_Resource_Single || Kronolith_Resource_Group
* @throws Horde_Exception
*/
public function getResource($id)
{
- $query = 'SELECT resource_id, resource_name, resource_calendar, resource_category, resource_description, resource_response_type FROM kronolith_resources WHERE resource_id = ?';
+ $query = 'SELECT resource_id, resource_name, resource_calendar, resource_category, resource_description, resource_response_type, resource_type, resource_members FROM kronolith_resources WHERE resource_id = ?';
$results = $this->_db->getRow($query, array($id), DB_FETCHMODE_ASSOC);
if ($results instanceof PEAR_Error) {
throw new Horde_Exception('Resource not found');
}
- return new Kronolith_Resource_Single($this->_fromDriver($results));
+ $class = 'Kronolith_Resource_' . $results['resource_type'];
+ if (!class_exists($class)) {
+ throw new Horde_Exception(sprintf(_("Could not load the class definition for %s"), $class));
+ }
+
+ return new $class($this->_fromDriver($results));
}
/**
*/
public function listResources($filter = array())
{
- $query = 'SELECT resource_id, resource_name, resource_calendar, resource_category, resource_description, resource_response_type FROM kronolith_resources';
+ $query = 'SELECT resource_id, resource_name, resource_calendar, resource_category, resource_description, resource_response_type, resource_type, resource_members FROM kronolith_resources';
if (count($filter)) {
$clause = ' WHERE ';
$i = 0;
$return = array();
foreach ($results as $key => $result) {
- $return[$key] = new Kronolith_Resource_Single($this->_fromDriver(array_merge(array('resource_id' => $key), $result)));
+ $class = 'Kronolith_Resource_' . $result['resource_type'];
+ $return[$key] = new $class($this->_fromDriver(array_merge(array('resource_id' => $key), $result)));
}
return $return;
*/
public function set($property, $value)
{
- //if (in_array($property, array('name', 'category', 'calendar', 'description'))) {
- $this->_params[$property] = $value;
- //}
+ $this->_params[$property] = $value;
}
/**
*/
public function get($property)
{
- $property = str_replace('resource_', '', $property);
- return !empty($this->_params[$property]) ? $this->_params[$property] : false;
+ $property = str_replace('resource_', '', $property);
+ if ($property == 'type' && empty($this->_params['type'])) {
+ return (self instanceof Kronolith_Resource_Single) ? 'Single' : 'Group';
+ }
+
+ return !empty($this->_params[$property]) ? $this->_params[$property] : false;
}
/**
if (empty($this->_selectedResource)) {
return parent::get($property);
} else {
- return $this->_selectedResoruce->get($property);
+ return $this->_selectedResource->get($property);
+ }
+ }
+
+ public function getId()
+ {
+ if (!empty($this->_selectedResource)) {
+ return $this->_selectedResource->getId();
+ } else {
+ return parent::getId();
}
}
$resources = unserialize($this->get('members'));
/* Iterate over all resources until one with no conflicts is found */
- $conflict = false;
foreach ($resources as $resource_id) {
+ $conflict = false;
$resource = $this->_driver->getResource($resource_id);
$busy = Kronolith::listEvents($start, $end, array($resource->get('calendar')));
if ($busy instanceof PEAR_Error) {
$e->hasStatus(Kronolith::STATUS_FREE)) &&
$e->getUID() !== $uid) {
- if (!($e->start->compareDateTime($end) >= 1 ||
- $e->end->compareDateTime($start) <= -1)) {
+ if (!($e->start->compareDateTime($end) >= 0) &&
+ !($e->end->compareDateTime($start) <= 0)) {
// Not free, continue to the next resource
$conflict = true;
*/
public function addEvent($event)
{
- if (empty($this->_selectedResource)) {
- $this->isFree($event);
- }
-// /* Make sure it's not already attached. */
-// $uid = $event->getUID();
-// $existing = $driver->getByUID($uid, array($this->get('calendar')));
-// if (!($existing instanceof PEAR_Error)) {
-// /* Already attached, just update */
-// $existing->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0')));
-// $existing->status = $event->status;
-// $existing->save();
-// } else {
-// /* Create a new event */
-// $e = $driver->getEvent();
-// $e->setCalendar($this->get('calendar'));
-// $e->fromiCalendar($event->toiCalendar(new Horde_iCalendar('2.0')));
-// $e->save();
-// }
+ throw new Horde_Exception(_("Events should be added to the Single resource object, not directly to the Group object."));
}
/**