Convert Operator to updated Horde_Registry_Application usage
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 20 Jan 2010 06:17:18 +0000 (23:17 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 20 Jan 2010 16:32:59 +0000 (09:32 -0700)
operator/export.php
operator/graphgen.php
operator/lib/Application.php
operator/lib/Form/SearchCDR.php
operator/lib/Operator.php
operator/search.php
operator/viewgraph.php

index e64137e..7ea3e83 100644 (file)
@@ -9,12 +9,11 @@
  */
 
 require_once dirname(__FILE__) . '/lib/Application.php';
-
-$operator = new Operator_Application(array('init' => true));
-$cache = &$GLOBALS['cache'];
+Horde_Registry::appInit('operator');
 
 require_once OPERATOR_BASE . '/lib/Form/SearchCDR.php';
 
+$cache = $GLOBALS['cache'];
 $renderer = new Horde_Form_Renderer();
 $vars = Horde_Variables::getDefaultVariables();
 $data = array();
index d7da100..870f88f 100644 (file)
@@ -9,8 +9,8 @@
  */
 
 require_once dirname(__FILE__) . '/lib/Application.php';
+Horde_Registry::appInit('operator');
 
-$operator = new Operator_Application(array('init' => true));
 $cache = &$GLOBALS['cache'];
 
 // Work around warnings in Image_Graph
index 1e9b232..58ba65a 100644 (file)
@@ -2,7 +2,8 @@
 /**
  * Shout application interface.
  *
- * This file defines Shout's application interface.
+ * This file defines Horde's core API interface. Other core Horde libraries
+ * can interact with Operator through this API.
  *
  * Copyright 2006-2010 Alkaloid Networks (http://projects.alkaloid.net/)
  *
@@ -11,8 +12,9 @@
  * http://www.opensource.org/licenses/bsd-license.html.
  *
  * @author  Ben Klang <ben@alkaloid.net>
- * @package Shout
+ * @package Operator
  */
+
 if (!defined('OPERATOR_BASE')) {
     define('OPERATOR_BASE', dirname(__FILE__). '/..');
 }
@@ -33,69 +35,57 @@ require_once HORDE_BASE . '/lib/core.php';
 
 class Operator_Application extends Horde_Registry_Application
 {
+    /**
+     * The application's version.
+     *
+     * @var string
+     */
     public $version = 'H4 (1.0-git)';
+
+    /**
+     * TODO
+     */
     public $driver = null;
 
-    public function __construct($args = array())
+    /**
+     * TODO
+     */
+    static protected $_perms = array();
+
+    /**
+     * Initialization function.
+     *
+     * Global variables defined:
+     *   $cache - TODO
+     */
+    protected function _init()
     {
-        if (!empty($args['init'])) {
-
-            // Registry.
-            $GLOBALS['registry'] = Horde_Registry::singleton();
-            $registry = &$GLOBALS['registry'];
-
-            try {
-                $registry->pushApp('operator');
-            } catch (Horde_Exception $e) {
-                if ($e->getCode() == 'permission_denied') {
-                    Horde::authenticationFailureRedirect();
-                }
-                Horde::fatal($e, __FILE__, __LINE__, false);
-            }
-            $conf = &$GLOBALS['conf'];
-            @define('OPERATOR_TEMPLATES', $registry->get('templates'));
-
-            // Notification system.
-            $GLOBALS['notification'] = &Horde_Notification::singleton();
-            $notification = &$GLOBALS['notification'];
-            $notification->attach('status');
-
-            // Define the base file path of Operator.
-            @define('OPERATOR_BASE', dirname(__FILE__) . '/..');
+        // Operator backend.
+        $this->driver = Operator_Driver::factory();
 
-            // Operator base library
-            require_once OPERATOR_BASE . '/lib/Operator.php';
-
-            // Operator backend.
-            require_once OPERATOR_BASE . '/lib/Driver.php';
-            $this->driver = Operator_Driver::factory();
-
-            // Caching system for storing DB results
-            $GLOBALS['cache'] = &Horde_Cache::singleton($conf['cache']['driver'],
-                                    Horde::getDriverConfig('cache', $conf['cache']['driver']));
-
-            // Start output compression.
-            Horde::compressOutput();
-        }
+        // Caching system for storing DB results
+        $GLOBALS['cache'] = Horde_Cache::singleton($GLOBALS['conf']['cache']['driver'], Horde::getDriverConfig('cache', $GLOBALS['conf']['cache']['driver']));
     }
 
+    /**
+     * TODO
+     */
     public function perms()
     {
-        static $perms = array();
-
-        if (!empty($perms)) {
-            return $perms;
+        if (!empty(self::$_perms)) {
+            return self::$_perms;
         }
 
-        $perms['tree']['operator']['accountcodes'] = false;
-        $perms['title']['operator:accountcodes'] = _("Account Codes");
+        self::$_perms['tree']['operator']['accountcodes'] = false;
+        self::$_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;
+            self::$_perms['tree']['operator']['accountcodes'][$accountcode] = false;
+            self::$_perms['title']['operator:accountcodes:' . $accountcode] = $accountcode;
         }
 
-        return $perms;
+        return self::$_perms;
     }
+
 }
index 52b61a3..f886f0d 100644 (file)
@@ -110,9 +110,6 @@ class ExportCDRForm extends SearchCDRForm
     public function execute()
     {
         global $operator;
-        if (empty($operator) || empty($operator->driver)) {
-            $operator = new Operator_Application(array('init' => true));
-        }
 
         $start = new Horde_Date($this->_vars->get('startdate'));
         $end = new Horde_Date($this->_vars->get('enddate'));
index c707be9..6d6963f 100644 (file)
@@ -96,9 +96,6 @@ class Operator {
     public static function getAccountCodes($permfilter = false)
     {
         global $operator;
-        if (empty($operator) || empty($operator->driver)) {
-            $operator = new Operator_Application(array('init' => true));
-        }
 
         // Set up arrays for filtering
         $keys = $values = $operator->driver->getAccountCodes();
index 987890d..00d47cd 100644 (file)
@@ -9,12 +9,11 @@
  */
 
 require_once dirname(__FILE__) . '/lib/Application.php';
-
-$operator = new Operator_Application(array('init' => true));
-$cache = &$GLOBALS['cache'];
+Horde_Registry::appInit('operator');
 
 require_once OPERATOR_BASE . '/lib/Form/SearchCDR.php';
 
+$cache = $GLOBALS['cache'];
 $renderer = new Horde_Form_Renderer();
 $vars = Horde_Variables::getDefaultVariables();
 $data = array();
index 71a4b2d..b8787e4 100644 (file)
@@ -9,12 +9,11 @@
  */
 
 require_once dirname(__FILE__) . '/lib/Application.php';
-
-$operator = new Operator_Application(array('init' => true));
-$cache = &$GLOBALS['cache'];
+Horde_Registry::appInit('operator');
 
 require_once OPERATOR_BASE . '/lib/Form/SearchCDR.php';
 
+$cache = $GLOBALS['cache'];
 $renderer = new Horde_Form_Renderer();
 $vars = Horde_Variables::getDefaultVariables();