Remove listResources from Kronolth_Resource and refactor code to
authorMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 28 Sep 2009 16:53:22 +0000 (12:53 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Tue, 29 Sep 2009 20:53:58 +0000 (16:53 -0400)
use Kronolith_Driver_Resource::listResources instead.

kronolith/attendees.php
kronolith/lib/Driver/Resource.php
kronolith/lib/Forms/CreateResourceGroup.php
kronolith/lib/Forms/EditResourceGroup.php
kronolith/lib/Resource.php
kronolith/resources/groups/index.php
kronolith/resources/index.php

index a917039..44c25db 100644 (file)
@@ -227,7 +227,7 @@ case 'clear':
 }
 
 /* Get list of resources for select list, and remove those we already added */
-$allResources = Kronolith_Resource::listResources();
+$allResources = Kronolith::getDriver('Resource')->listResources();
 foreach (array_keys($resources) as $id) {
     unset($allResources[$id]);
 }
index b17350b..7a1b6db 100644 (file)
@@ -497,13 +497,18 @@ class Kronolith_Driver_Resource extends Kronolith_Driver_Sql
     /**
      * Return a list of Kronolith_Resources
      *
-     * This method will likely be a moving target as group resources are
-     * fleshed out.
+     * Right now, all users have PERMS_READ, but only system admins have
+     * PERMS_EDIT | PERMS_DELETE
      *
+     * @param int $perms     A PERMS_* constant.
      * @param array $filter  A hash of field/values to filter on.
      */
-    public function listResources($filter = array())
+    public function listResources($perms = PERMS_READ, $filter = array())
     {
+        if (($perms & (PERMS_EDIT | PERMS_DELETE)) && !Horde_Auth::isAdmin()) {
+            return array();
+        }
+
         $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 ';
index 6902ae1..9cc1a95 100644 (file)
@@ -28,7 +28,7 @@ class Kronolith_CreateResourceGroupForm extends Horde_Form {
     {
         parent::Horde_Form($vars, _("Create Resource"));
 
-        $resources = Kronolith_Resource::listResources(PERMS_READ, array('type' => 'Single'));
+        $resources = Kronolith::getDriver('Resource')->listResources(PERMS_READ, array('type' => 'Single'));
         $enum = array();
         foreach ($resources as $resource) {
             $enum[$resource->getId()] = htmlspecialchars($resource->get('name'));
index 210fc55..42fed51 100644 (file)
@@ -33,7 +33,7 @@ class Kronolith_EditResourceGroupForm extends Horde_Form {
         $this->_resource = &$resource;
         parent::Horde_Form($vars, sprintf(_("Edit %s"), $resource->get('name')));
 
-        $resources = Kronolith_Resource::listResources(PERMS_READ, array('type' => 'Single'));
+        $resources = Kronolith::getDriver('Resource')->listResources(PERMS_READ, array('type' => 'Single'));
         $enum = array();
         foreach ($resources as $r) {
             $enum[$r->getId()] = htmlspecialchars($r->get('name'));
index e2971f3..2c28dba 100644 (file)
@@ -38,25 +38,6 @@ class Kronolith_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 string $calendar  The calendar identifier to check.
index 046cf6d..db2346c 100644 (file)
@@ -18,7 +18,7 @@ if (!Horde_Auth::getAuth()) {
 $edit_url_base = Horde::applicationUrl('resources/groups/edit.php');
 $edit_img = Horde::img('edit.png', _("Edit"), null, $registry->getImageDir('horde'));
 
-$resources = Kronolith_Resource::listResources(PERMS_EDIT, array('type' => 'Group'));
+$resources = Kronolith::getDriver('Resource')->listResources(PERMS_EDIT, array('type' => 'Group'));
 //$display_url_base = Horde::applicationUrl('month.php', true, -1);
 $delete_url_base = Horde::applicationUrl('resources/groups/delete.php');
 $delete_img = Horde::img('delete.png', _("Delete"), null, $registry->getImageDir('horde'));
index 0d21a40..9c76043 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_Resource::listResources(PERMS_READ, array('type' => 'Single'));
+$resources = Kronolith::getDriver('Resource')->listResources(PERMS_READ, array('type' => 'Single'));
 $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'));