is_array($_SESSION['kronolith']['resources']))
? $_SESSION['kronolith']['resources']
: array();
-$allResources = Kronolith::listResources();
+$allResources = Kronolith_Resource::listResources();
// Get the action ID and value. This specifies what action the user initiated.
$actionID = Horde_Util::getFormData('actionID');
require_once dirname(__FILE__) . '/lib/base.php';
-if (Kronolith::isResourceCalendar($c = Horde_Util::getFormData('calendar'))) {
+if (Kronolith_Resource::isResourceCalendar($c = Horde_Util::getFormData('calendar'))) {
$driver = 'Resource';
} else {
$driver = null;
}
// TODO: Should this go here?
- Kronolith::checkResources($this);
+ Kronolith_Resource::checkResources($this);
$this->toDriver();
$result = $this->getDriver()->saveEvent($this);
if (!is_a($result, 'PEAR_Error') &&
'max_reservations' => $this->_vars->get('max_reservations'));
$resource = new Kronolith_Resource_Single($new);
- return $results = Kronolith::addResource($resource);
+ return $results = Kronolith_Resource::addResource($resource);
}
}
if (is_a($share, 'PEAR_Error')) {
// Might be a Kronolith_Resource
try {
- $resource = Kronolith::isResourceCalendar($calendar[0]);
+ $resource = Kronolith_Resource::isResourceCalendar($calendar[0]);
$owner = $calendar[0];
} catch (Horde_Exception $e) {
return $returnObj ? $share : '';
}
/**
- * Adds a new resource to storage
+ * Obtain an internal calendar. Use this where we don't know if we will
+ * have a Horde_Share or a Kronolith_Resource based calendar.
*
- * @param Kronolith_Resource $resource
+ * @param string $target The calendar id to retrieve.
*
- * @return unknown_type
+ * @return mixed Kronolith_Resource or Horde_Share_Object
*/
- static public function addResource($resource)
- {
- // Create a new calendar id.
- $calendar = 'resource_' . hash('md5', microtime());
- $resource->set('calendar', $calendar);
- $driver = Kronolith::getDriver('Resource');
-
- return $driver->save($resource);
- }
-
- /**
- * Return a list of resources that the current user has access to at the
- * specified permission level. Right now, all users have PERMS_READ, but
- * only system admins have PERMS_EDIT | PERMS_DELETE
- *
- * @return array of Kronolith_Resource objects
- */
- static public function listResources($perms = PERMS_READ, $params = array())
- {
- if (($perms & (PERMS_EDIT | PERMS_DELETE)) && !Horde_Auth::isAdmin()) {
- return array();
- }
-
- // Query kronolith_resource table for all(?) available resources?
- // maybe by 'type' or 'name'? type would be arbitrary?
- $driver = Kronolith::getDriver('Resource');
- return $driver->listResources($params);
- }
-
- static public function isResourceCalendar($calendar)
- {
- if (strncmp($calendar, 'resource_', 9) === 0) {
- return true;
- }
-
- return false;
- }
-
- /**
- * Function to check availability and auto accept/decline for each resource
- * attached to the event.
- *
- * @return unknown_type
- */
- static public function checkResources($event)
- {
- foreach ($event->getResources() as $id => $resource) {
-
- /* Get the resource */
- $r = Kronolith::getDriver('Resource')->getResource($id);
-
- /* Determine if we have to calculate, or just auto-reply */
- $type = $r->getResponseType();
- switch($type) {
- case Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT:
- $r->addEvent($event);
- $event->addResource($r, Kronolith::RESPONSE_ACCEPTED);
- break;
- case Kronolith_Resource::RESPONSETYPE_AUTO:
- if ($r->isFree($event)) {
- $r->addEvent($event);
- $event->addResource($r, Kronolith::RESPONSE_ACCEPTED);
- } else {
- $event->addResource($r, Kronolith::RESPONSE_DECLINED);
- }
- break;
-
- case Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE:
- $event->addResource($r, Kronolith::RESPONSE_DECLINED);
- break;
-
- case Kronolith_Resource::RESPONSETYPE_NONE:
- $event->addResource($r, Kronolith::RESPONSE_NONE);
- break;
-
- case Kronolith_Resource::RESPONSETYPE_MANUAL:
- //???
- break;
- }
-
- }
- }
-
static public function getInternalCalendar($target)
{
if (self::isResourceCalendar($target)) {
/**
*
*/
- public function factory($driver, $params)
+ static public function factory($driver, $params)
{
}
+ /**
+ * Adds a new resource to storage
+ *
+ * @param Kronolith_Resource $resource
+ *
+ * @return unknown_type
+ */
+ static public function addResource($resource)
+ {
+ // Create a new calendar id.
+ $calendar = 'resource_' . hash('md5', microtime());
+ $resource->set('calendar', $calendar);
+ $driver = Kronolith::getDriver('Resource');
+
+ return $driver->save($resource);
+ }
+
+ /**
+ * Return a list of resources that the current user has access to at the
+ * specified permission level. Right now, all users have PERMS_READ, but
+ * only system admins have PERMS_EDIT | PERMS_DELETE
+ *
+ * @return array of Kronolith_Resource objects
+ */
+ static public function listResources($perms = PERMS_READ, $params = array())
+ {
+ if (($perms & (PERMS_EDIT | PERMS_DELETE)) && !Horde_Auth::isAdmin()) {
+ return array();
+ }
+
+ // Query kronolith_resource table for all(?) available resources?
+ // maybe by 'type' or 'name'? type would be arbitrary?
+ $driver = Kronolith::getDriver('Resource');
+ return $driver->listResources($params);
+ }
+
+ /**
+ * Determine if the provided calendar id represents a resource's calendar.
+ *
+ * @param $calendar
+ * @return unknown_type
+ */
+ static public function isResourceCalendar($calendar)
+ {
+ if (strncmp($calendar, 'resource_', 9) === 0) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Function to check availability and set response status for each resource
+ * attached to the event.
+ *
+ * @return void
+ */
+ static public function checkResources($event)
+ {
+ foreach ($event->getResources() as $id => $resource) {
+
+ /* Get the resource */
+ $r = Kronolith::getDriver('Resource')->getResource($id);
+
+ /* Determine if we have to calculate, or just auto-reply */
+ $type = $r->getResponseType();
+ switch($type) {
+ case Kronolith_Resource::RESPONSETYPE_ALWAYS_ACCEPT:
+ $r->addEvent($event);
+ $event->addResource($r, Kronolith::RESPONSE_ACCEPTED);
+ break;
+ case Kronolith_Resource::RESPONSETYPE_AUTO:
+ if ($r->isFree($event)) {
+ $r->addEvent($event);
+ $event->addResource($r, Kronolith::RESPONSE_ACCEPTED);
+ } else {
+ $event->addResource($r, Kronolith::RESPONSE_DECLINED);
+ }
+ break;
+
+ case Kronolith_Resource::RESPONSETYPE_ALWAYS_DECLINE:
+ $event->addResource($r, Kronolith::RESPONSE_DECLINED);
+ break;
+
+ case Kronolith_Resource::RESPONSETYPE_NONE:
+ $event->addResource($r, Kronolith::RESPONSE_NONE);
+ break;
+
+ case Kronolith_Resource::RESPONSETYPE_MANUAL:
+ // Would be nice to be able to utilize iTips, but
+ // no idea how that would work right now...resources are not
+ // user accounts etc...for now, just set as NONE
+ $event->addResource($r, Kronolith::RESONSE_NONE);
+ break;
+ }
+
+ }
+ }
+
}
\ No newline at end of file
}
$edit_url_base = Horde::applicationUrl('resources/edit.php');
$edit_img = Horde::img('edit.png', _("Edit"), null, $registry->getImageDir('horde'));
-$resources = Kronolith::listResources();
+$resources = Kronolith_Resource::listResources();
$display_url_base = Horde::applicationUrl('month.php', true, -1);
$delete_url_base = Horde::applicationUrl('resources/delete.php');
$delete_img = Horde::img('delete.png', _("Delete"), null, $registry->getImageDir('horde'));
// 'category' => 'conference rooms');
//
//$resource = new Kronolith_Resource_Single($new);
-//$results = Kronolith::addResource($resource);
+//$results = Kronolith_Resource::addResource($resource);
//var_dump($results);
?>
</div>
\ No newline at end of file