/** * Method to parse a list of categories into a HTML selectbox * * @access public * @param int ID of current item * @param int ID of parent category * @return string HTML output */ public function selectCategories($name = '', $params = array()) { // Fetch all categories $parent_id = isset($params['parent_id']) ? $params['parent_id'] : null; $categories = SimplelistsHTML::getCategories($parent_id); // Remove the current category if (isset($params['self'])) { foreach ($categories as $index => $category) { if ($category->id == $params['self']) { unset($categories[$index]); break; } } } // If the $item_id is set, find all the current categories for a SimpleLists item $current = isset($params['item_id']) ? SimplelistsHTML::getCurrentCategory($categories, $params['item_id']) : null; $current = isset($params['current']) ? $params['current'] : $current; // If no current is set, and if the count of categories is 1, select the first category list if (empty($current) && count($categories) == 1) { $current = $categories[0]->id; } // Define extra HTML-arguments $extra = ''; // If $multiple is true, we assume we're in the Item Edit form if (isset($params['multiple']) && $params['multiple'] == 1) { $size = count($categories) < 10 ? count($categories) : 10; $extra .= 'size="' . $size . '" multiple'; } // If $none is true, we include an extra option if (isset($params['nullvalue']) && $params['nullvalue'] == 1) { $nulltitle = isset($params['nulltitle']) ? $params['nulltitle'] : JText::_('COM_SIMPLELISTS_SELECT_CATEGORY'); array_unshift($categories, JHTML::_('select.option', 0, '- ' . $nulltitle . ' -', 'id', 'title')); } // If $javascript is true, we submit the form as soon as an option has been selected if (isset($params['javascript']) && $params['javascript'] == 1) { $extra .= 'onchange="document.adminForm.submit();"'; } return JHTML::_('select.genericlist', $categories, $name, $extra, 'id', 'title', $current); }