Overview

Packages

  • Tree

Classes

  • Horde_Tree
  • Horde_Tree_Base
  • Horde_Tree_Exception
  • Horde_Tree_Html
  • Horde_Tree_Jquerymobile
  • Horde_Tree_Select
  • Horde_Tree_Simplehtml
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The Horde_Tree_Jquerymobile class provides rendering of a tree as a jQuery
  4:  * Mobile list view.
  5:  *
  6:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (LGPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
 10:  *
 11:  * @author   Michael Slusarz <slusarz@horde.org>
 12:  * @author   Jan Schneider <jan@horde.org>
 13:  * @category Horde
 14:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 15:  * @package  Tree
 16:  */
 17: class Horde_Tree_Jquerymobile extends Horde_Tree_Base
 18: {
 19:     /**
 20:      * Allowed parameters for nodes.
 21:      *
 22:      * @var array
 23:      */
 24:     protected $_allowed = array(
 25:         'class',
 26:         'icon',
 27:         'special',
 28:         'url',
 29:         'urlattributes',
 30:     );
 31: 
 32:     /**
 33:      * Returns the tree.
 34:      *
 35:      * @return string  The HTML code of the rendered tree.
 36:      */
 37:     public function getTree($static = false)
 38:     {
 39:         $tree = '';
 40:         foreach (array(true, false) as $special) {
 41:             foreach ($this->_root_nodes as $node_id) {
 42:                 $tree .= $this->_buildTree($node_id, $special);
 43:             }
 44:         }
 45: 
 46:         return $tree;
 47:     }
 48: 
 49:     /**
 50:      * Recursive function to walk through the tree array and build the output.
 51:      *
 52:      * @param string $node_id  The Node ID.
 53:      *
 54:      * @return string  The tree rendering.
 55:      */
 56:     protected function _buildTree($node_id, $special)
 57:     {
 58:         $node = $this->_nodes[$node_id];
 59:         $output = '';
 60: 
 61:         if ($node['special'] == $special) {
 62:             $output = '<li';
 63:             if (isset($node['class'])) {
 64:                 $output .= ' class="' . $node['class'] . '"';
 65:             }
 66:             $output .= '>';
 67:             if (isset($node['extra'][Horde_Tree::EXTRA_LEFT])) {
 68:                 $output .= implode(' ', $node['extra'][Horde_Tree::EXTRA_LEFT]);
 69:             }
 70:             if (!empty($node['url'])) {
 71:                 $output .= '<a href="' . (string)$node['url'] . '"';
 72:                 if (isset($node['urlattributes'])) {
 73:                     foreach ($node['urlattributes'] as $attribute => $value) {
 74:                         $output .= ' ' . $attribute . '="' . htmlspecialchars($value) . '"';
 75:                     }
 76:                 }
 77:                 $output .= '>';
 78:             }
 79:             $output .= $this->_getIcon($node_id) . $node['label'];
 80:             if (!empty($node['url'])) {
 81:                 $output .= '</a>';
 82:             }
 83:             if (isset($node['extra'][Horde_Tree::EXTRA_RIGHT])) {
 84:                 $output .= '<span class="ui-li-count">' . implode(' ', $node['extra'][Horde_Tree::EXTRA_RIGHT]) . '</span>';
 85:             }
 86:             $output .= '</li>';
 87:         }
 88: 
 89:         if (isset($node['children'])) {
 90:             foreach ($node['children'] as $val) {
 91:                 $output .= $this->_buildTree($val, $special);
 92:             }
 93:         }
 94: 
 95:         return $output;
 96:     }
 97: 
 98:     /**
 99:      * Sets the icon for the node.
100:      *
101:      * @param string $node_id  The Node ID.
102:      *
103:      * @return string  The node icon for the tree line.
104:      */
105:     protected function _getIcon($node_id)
106:     {
107:         $node = $this->_nodes[$node_id];
108:         if (empty($node['icon'])) {
109:             return '';
110:         }
111:         return '<img src="' . $node['icon'] . '" class="ui-li-icon">';
112:     }
113: 
114: }
115: 
API documentation generated by ApiGen