Simplify; remove unneeded type conversions
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 25 Aug 2010 21:32:38 +0000 (15:32 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 25 Aug 2010 21:42:49 +0000 (15:42 -0600)
framework/Core/lib/Horde/Core/Tree/Javascript.php
horde/lib/Ajax/Application.php

index c842302..f84739a 100644 (file)
@@ -23,7 +23,7 @@ class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
      * @param array $params  @see parent::__construct(). Additional options:
      * <pre>
      * 'jsvar' - The JS variable name to store the tree object in.
-     *           DEFAULT: $_instance
+     *           DEFAULT: Instance name.
      * </pre>
      */
     public function __construct($name, array $params = array())
@@ -34,13 +34,13 @@ class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
         Horde::addScriptFile('hordetree.js', 'horde');
 
         /* Check for a javascript session state. */
-        if (!empty($this->_options['session']) &&
+        if (($session = $this->getOption('session')) &&
             isset($_COOKIE[$this->_instance . '_expanded'])) {
             /* Remove "exp" prefix from cookie value. */
             $nodes = explode(',', substr($_COOKIE[$this->_instance . '_expanded'], 3));
 
             /* Save nodes to the session. */
-            $_SESSION[$this->_options['session']][$this->_instance]['expanded'] = array_combine(
+            $_SESSION[$session][$this->_instance]['expanded'] = array_combine(
                 $nodes,
                 array_fill(0, count($nodes), true)
             );
@@ -100,9 +100,9 @@ class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
             'initTree' => $this->renderNodeDefinitions()
         );
 
-        $js_var = empty($this->_options['jsvar'])
-            ? $this->_instance
-            : $this->_options['jsvar'];
+        if (!($js_var = $this->getOption('jsvar'))) {
+            $js_var = $this->_instance;
+        }
 
         Horde::addInlineScript(array(
             'window.' . $js_var . ' = new Horde_Tree(' . Horde_Serialize::serialize($opts, Horde_Serialize::JSON, $GLOBALS['registry']->getCharset()) . ')'
@@ -125,17 +125,19 @@ class Horde_Core_Tree_Javascript extends Horde_Core_Tree_Html
     /**
      * Returns just the JS node definitions as a string.
      *
-     * @return array  The following keys: 'is_static', 'nodes', 'root_nodes'.
+     * @return object  Object with the following properties: 'is_static',
+     *                 'nodes', 'root_nodes'.
      */
     public function renderNodeDefinitions()
     {
         $this->_buildIndents($this->_root_nodes);
 
-        return array(
-            'is_static' => intval($this->_static),
-            'nodes' => $this->_nodes,
-            'root_nodes' => $this->_root_nodes
-        );
+        $result = new stdClass;
+        $result->is_static = intval($this->_static);
+        $result->nodes = $this->_nodes;
+        $result->root_nodes = $this->_root_nodes;
+
+        return $result;
     }
 
 }
index 393cbd2..542c2db 100644 (file)
@@ -17,26 +17,12 @@ class Horde_Ajax_Application extends Horde_Core_Ajax_Application
     /**
      * AJAX action: Update sidebar.
      *
-     * @return stdClass  An object with the following entries:
-     * <pre>
-     * 'is_static'
-     * 'nodes'
-     * 'root_nodes'
-     * </pre>
+     * @return object  See Horde_Tree_Javascript#renderNodeDefinitions().
      */
     public function sidebarUpdate()
     {
         $sidebar = new Horde_Ui_Sidebar();
-        $tree = $sidebar->getTree();
-
-        $defs = $tree->renderNodeDefinitions();
-
-        $result = new stdClass;
-        $result->is_static = $defs['is_static'];
-        $result->nodes = $defs['nodes'];
-        $result->root_nodes = $defs['root_nodes'];
-
-        return $result;
+        return $sidebar->getTree()->renderNodeDefinitions();
     }
 
 }