Move static resource related methods to Kronolith_Resource::
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 12 Sep 2009 15:38:48 +0000 (11:38 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:54 +0000 (16:53 -0400)
kronolith/attendees.php
kronolith/delete.php
kronolith/lib/Event.php
kronolith/lib/Forms/CreateResource.php
kronolith/lib/FreeBusy.php
kronolith/lib/Kronolith.php
kronolith/lib/Resource.php
kronolith/resources/index.php

index 5f01e53..42e3519 100644 (file)
@@ -21,7 +21,7 @@ $resources = (isset($_SESSION['kronolith']['resources']) &&
               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');
index 37ffe6b..2f94072 100644 (file)
@@ -11,7 +11,7 @@
 
 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;
index 1d003c3..8a683e2 100644 (file)
@@ -317,7 +317,7 @@ abstract class Kronolith_Event
         }
 
         // 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') &&
index d0c89fa..af13c38 100644 (file)
@@ -50,7 +50,7 @@ class Kronolith_CreateResourceForm extends Horde_Form {
                      'max_reservations' => $this->_vars->get('max_reservations'));
 
         $resource = new Kronolith_Resource_Single($new);
-        return $results = Kronolith::addResource($resource);
+        return $results = Kronolith_Resource::addResource($resource);
     }
 
 }
index a931e4c..a5d1a67 100644 (file)
@@ -35,7 +35,7 @@ class Kronolith_FreeBusy {
         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 : '';
index 1697844..3d87b89 100644 (file)
@@ -2034,95 +2034,13 @@ class Kronolith
     }
 
     /**
-     * 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)) {
index 356964e..72b6c39 100644 (file)
@@ -14,9 +14,108 @@ class Kronolith_Resource
     /**
      *
      */
-    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
index cf23398..7082606 100644 (file)
@@ -17,7 +17,7 @@ if (!Horde_Auth::getAuth()) {
 }
 $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'));
@@ -89,7 +89,7 @@ function shorten_url($url, $separator = '...', $first_chunk_length = 35, $last_c
 //             '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