From 9c599f3eea7b5d6028b3f5c7907c3d571d624b0e Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Sat, 5 Jul 2008 15:53:39 +0000 Subject: [PATCH] Add Permissions API Make sure cache is initialized when Operator::getAccountCodes() is called staticly --- lib/Operator.php | 10 ++++++++-- lib/api.php | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 lib/api.php diff --git a/lib/Operator.php b/lib/Operator.php index e31e1a64a..1dc2fd70a 100644 --- a/lib/Operator.php +++ b/lib/Operator.php @@ -2,7 +2,7 @@ /** * Operator Base Class. * - * $Horde: incubator/operator/lib/Operator.php,v 1.6 2008/07/05 14:38:23 bklang Exp $ + * $Horde: incubator/operator/lib/Operator.php,v 1.7 2008/07/05 15:53:39 bklang Exp $ * * Copyright 2008 Alkaloid Networks LLC * @@ -90,7 +90,13 @@ class Operator { */ function getAccountCodes() { - global $cache, $operator_driver; + global $operator_driver; + + if (!isset($GLOBALS['cache'])) { + $cache = &Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver'])); + } else { + $cache =& $GLOBALS['cache']; + } // Use 0 lifetime to allow cache lifetime to be set when storing the // object. diff --git a/lib/api.php b/lib/api.php new file mode 100644 index 000000000..ae92a72d4 --- /dev/null +++ b/lib/api.php @@ -0,0 +1,41 @@ + array(), + 'type' => '{urn:horde}stringArray'); + +function _operator_perms() +{ + static $perms = array(); + + if (!empty($perms)) { + return $perms; + } + + @define('OPERATOR_BASE', dirname(__FILE__) . '/..'); + require_once OPERATOR_BASE . '/lib/base.php'; + + $perms['tree']['operator']['accountcodes'] = false; + $perms['title']['operator:accountcodes'] = _("Account Codes"); + + $accountcodes = Operator::getAccountCodes(); + foreach ($accountcodes as $accountcode) { + $perms['tree']['operator']['accountcodes'][$accountcode] = false; + $perms['title']['operator:accountcodes:' . $accountcode] = $accountcode; + } + + return $perms; +} -- 2.11.0