function display($tpl = null) { $task = JRequest::getCmd('task', NULL); $cmd = JRequest::getCmd('cmd', NULL); switch ($task) { case 'group': $groups = JFormFieldSelectGroup::getGroups($cmd); $output = ''; foreach ($groups as $group) { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } $data = $output; break; case 'company': $groups = JFormFieldSelectGroup::getCompany($cmd); $output = ''; $select = 1; foreach ($groups as $group) { if ($cmd && $group->value && $select) { $output .= '<option value="' . $group->value . '" selected>' . $group->text . '</option>'; $select = 0; } else { $output .= '<option value="' . $group->value . '">' . $group->text . '</option>'; } } $data = $output; break; default: break; } $document =& JFactory::getDocument(); $document->setMimeEncoding('application/json'); echo json_encode($data); return false; }
static function getCompany($group) { $options = parent::getCompany($group, false); if (sizeof($options) > 1) { $options[0] = JHtml::_('select.option', 0, 'All Companies'); } return $options; }
static function getCompany($group) { $options = parent::getCompany($group, false); // the first one is always "select a company" // if == 2, than it really means there is only one eligbile company, then go ahead and remove the first generated one // so the first one doesn't count, and if there is more than 2, means there's more than one eligible company if (sizeof($options) == 2) { unset($options[0]); // remove element $options = array_values($options); // re-index the array } elseif (sizeof($options) > 2) { $options[0] = JHtml::_('select.option', 0, 'All Companies'); } return $options; }