1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage HTML
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Utility class to render a list view sidebar
14 *
15 * @since 3.0
16 */
17 abstract class JHtmlSidebar
18 {
19 /**
20 * Menu entries
21 *
22 * @var array
23 * @since 3.0
24 */
25 protected static $entries = array();
26
27 /**
28 * Filters
29 *
30 * @var array
31 * @since 3.0
32 */
33 protected static $filters = array();
34
35 /**
36 * Value for the action attribute of the form.
37 *
38 * @var string
39 * @since 3.0
40 */
41 protected static $action = '';
42
43 /**
44 * Render the sidebar.
45 *
46 * @return string The necessary HTML to display the sidebar
47 *
48 * @since 3.0
49 */
50 public static function render()
51 {
52 // Collect display data
53 $data = new stdClass;
54 $data->list = static::getEntries();
55 $data->filters = static::getFilters();
56 $data->action = static::getAction();
57 $data->displayMenu = count($data->list);
58 $data->displayFilters = count($data->filters);
59 $data->hide = JFactory::getApplication()->input->getBool('hidemainmenu');
60
61 // Create a layout object and ask it to render the sidebar
62 $layout = new JLayoutFile('joomla.sidebars.submenu');
63
64 return $layout->render($data);
65 }
66
67 /**
68 * Method to add a menu item to submenu.
69 *
70 * @param string $name Name of the menu item.
71 * @param string $link URL of the menu item.
72 * @param bool $active True if the item is active, false otherwise.
73 *
74 * @return void
75 *
76 * @since 3.0
77 */
78 public static function addEntry($name, $link = '', $active = false)
79 {
80 static::$entries[] = array($name, $link, $active);
81 }
82
83 /**
84 * Returns an array of all submenu entries
85 *
86 * @return array
87 *
88 * @since 3.0
89 */
90 public static function getEntries()
91 {
92 return static::$entries;
93 }
94
95 /**
96 * Method to add a filter to the submenu
97 *
98 * @param string $label Label for the menu item.
99 * @param string $name Name for the filter. Also used as id.
100 * @param string $options Options for the select field.
101 * @param bool $noDefault Don't the label as the empty option
102 *
103 * @return void
104 *
105 * @since 3.0
106 */
107 public static function addFilter($label, $name, $options, $noDefault = false)
108 {
109 static::$filters[] = array('label' => $label, 'name' => $name, 'options' => $options, 'noDefault' => $noDefault);
110 }
111
112 /**
113 * Returns an array of all filters
114 *
115 * @return array
116 *
117 * @since 3.0
118 */
119 public static function getFilters()
120 {
121 return static::$filters;
122 }
123
124 /**
125 * Set value for the action attribute of the filter form
126 *
127 * @param string $action Value for the action attribute of the form
128 *
129 * @return void
130 *
131 * @since 3.0
132 */
133 public static function setAction($action)
134 {
135 static::$action = $action;
136 }
137
138 /**
139 * Get value for the action attribute of the filter form
140 *
141 * @return string
142 *
143 * @since 3.0
144 */
145 public static function getAction()
146 {
147 return static::$action;
148 }
149 }
150