return true;
}
+ /**
+ * Save or update a Kronolith_Resource
+ *
+ * @param $resource
+ *
+ * @return Kronolith_Resource object
+ */
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);
+ if (!empty($resource->uid)) {
+ $query = 'UPDATE kronolith_resources SET resource_name = ?, resource_calendar = ?, resource_category = ? WHERE resource_uid = ?';
+ $values = array($resource->name, $resource->calendar_id, $resource->category, $resource->uid);
+ $result = $this->_write_db->query($query, $values);
+ if (!($result instanceof PEAR_Error)) {
+ throw new Horde_Exception($result->getMessage());
+ }
+ } else {
+ $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 . $cols_values, $values);
+ if (!($result instanceof PEAR_Error)) {
+ return true;
+ } else {
+ throw new Horde_Exception($result->getMessage());
+ }
+ $resource->setUid($id);
+ }
+
+ return $resource;
}
/**
* Kronolith resources
*
*/
-class Kronolith_Resource_Base
+abstract class Kronolith_Resource_Base
{
protected $_params = array();
protected $_uid = '';
*/
public function __get($property)
{
- return $this->_params[$property];
+ if ($property == 'uid') {
+ return $this->_uid;
+ }
+
+ if (isset($this->_params[$property])) {
+ return $this->_params[$property];
+ } else {
+ throw new Horde_Exception(sprintf(_("Invalid property, %s, requested in Kronolith_Resource"), $property));
+ }
}
/**
*/
abstract public function getFreeBusy();
+ /**
+ * Sets the current resource's id. Must not be an existing resource.
+ *
+ * @param int $id The id for this resource
+ *
+ * @return unknown_type
+ */
+ abstract public function setUid($id);
+
}
\ No newline at end of file
--- /dev/null
+<?php
+/**
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ */
+require_once dirname(__FILE__) . '/lib/base.php';
+
+$title = _("Edit resources");
+require KRONOLITH_TEMPLATES . '/common-header.inc';
+
+/* Test some resource crap */
+$new = array('name' => _("N329SP"),
+ 'category' => 'test');
+
+$resource = new Kronolith_Resource_Single($new);
+$results = Kronolith_Resource::addResource($resource);
+var_dump($results);
\ No newline at end of file