From: Michael J. Rubinsky Date: Mon, 28 Sep 2009 16:53:22 +0000 (-0400) Subject: Remove listResources from Kronolth_Resource and refactor code to X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=175d88ff8782699347b27161471748c989dffcd6;p=horde.git Remove listResources from Kronolth_Resource and refactor code to use Kronolith_Driver_Resource::listResources instead. --- diff --git a/kronolith/attendees.php b/kronolith/attendees.php index a91703966..44c25db70 100644 --- a/kronolith/attendees.php +++ b/kronolith/attendees.php @@ -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]); } diff --git a/kronolith/lib/Driver/Resource.php b/kronolith/lib/Driver/Resource.php index b17350bd8..7a1b6db5a 100644 --- a/kronolith/lib/Driver/Resource.php +++ b/kronolith/lib/Driver/Resource.php @@ -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 '; diff --git a/kronolith/lib/Forms/CreateResourceGroup.php b/kronolith/lib/Forms/CreateResourceGroup.php index 6902ae10d..9cc1a9557 100644 --- a/kronolith/lib/Forms/CreateResourceGroup.php +++ b/kronolith/lib/Forms/CreateResourceGroup.php @@ -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')); diff --git a/kronolith/lib/Forms/EditResourceGroup.php b/kronolith/lib/Forms/EditResourceGroup.php index 210fc555e..42fed516f 100644 --- a/kronolith/lib/Forms/EditResourceGroup.php +++ b/kronolith/lib/Forms/EditResourceGroup.php @@ -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')); diff --git a/kronolith/lib/Resource.php b/kronolith/lib/Resource.php index e2971f3c9..2c28dba44 100644 --- a/kronolith/lib/Resource.php +++ b/kronolith/lib/Resource.php @@ -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. diff --git a/kronolith/resources/groups/index.php b/kronolith/resources/groups/index.php index 046cf6df8..db2346ca7 100644 --- a/kronolith/resources/groups/index.php +++ b/kronolith/resources/groups/index.php @@ -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')); diff --git a/kronolith/resources/index.php b/kronolith/resources/index.php index 0d21a40eb..9c760435c 100644 --- a/kronolith/resources/index.php +++ b/kronolith/resources/index.php @@ -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'));