getOptionName() public static method

Gets the active option's label given an array of JHtml options
public static getOptionName ( array $data, mixed $selected = null, string $optKey = 'value', string $optText = 'text', boolean $selectFirst = true ) : mixed
$data array The JHtml options to parse
$selected mixed The currently selected value
$optKey string Key name
$optText string Value name
$selectFirst boolean Should I automatically select the first option?
return mixed The label of the currently selected option
Ejemplo n.º 1
0
 /**
  * Gets the active option's label given an array of JHtml options
  *
  * @param   array   $data      The JHtml options to parse
  * @param   mixed   $selected  The currently selected value
  * @param   string  $groupKey  Group name
  * @param   string  $optKey    Key name
  * @param   string  $optText   Value name
  *
  * @return  mixed   The label of the currently selected option
  */
 public static function getOptionName($data, $selected = null, $groupKey = 'items', $optKey = 'value', $optText = 'text')
 {
     if ($groupKey) {
     }
     // Keeps phpStorm from freaking out
     $ret = null;
     foreach ($data as $dataKey => $group) {
         if (is_array($group)) {
             $label = $group[$optText];
             $noGroup = false;
         } elseif (is_object($group)) {
             // Sub-list is in a property of an object
             $label = $group->{$optText};
             $noGroup = false;
         } else {
             throw new InvalidGroupContents(get_called_class());
         }
         if ($noGroup) {
             $label = '';
         }
         $match = GenericList::getOptionName($data, $selected, $optKey, $optText);
         if (!is_null($match)) {
             $ret = array('group' => $label, 'item' => $match);
             break;
         }
     }
     return $ret;
 }
Ejemplo n.º 2
0
 /**
  * Get the rendering of this field type for static display, e.g. in a single
  * item view (typically a "read" task).
  *
  * @since 2.0
  *
  * @return  string  The field HTML
  */
 public function getStatic()
 {
     $class = $this->class ? ' class="' . $this->class . '"' : '';
     return '<span id="' . $this->id . '" ' . $class . '>' . htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') . '</span>';
 }
Ejemplo n.º 3
0
 /**
  * Get the rendering of this field type for a repeatable (grid) display,
  * e.g. in a view listing many item (typically a "browse" task)
  *
  * @since 2.0
  *
  * @return  string  The field HTML
  */
 public function getRepeatable()
 {
     if (isset($this->element['legacy'])) {
         return $this->getInput();
     }
     $class = $this->class ? $this->class : '';
     $db = $this->form->getContainer()->platform->getDbo();
     $query = $db->getQuery(true)->select('a.id AS value, a.title AS text')->from('#__usergroups AS a')->group('a.id, a.title')->order('a.id ASC')->order($db->qn('title') . ' ASC');
     // Get the options.
     $options = $db->setQuery($query)->loadObjectList();
     return '<span class="' . $this->id . ' ' . $class . '">' . htmlspecialchars(GenericList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') . '</span>';
 }
Ejemplo n.º 4
0
 /**
  * Get the rendering of this field type for a repeatable (grid) display,
  * e.g. in a view listing many item (typically a "browse" task)
  *
  * @since 2.0
  *
  * @return  string  The field HTML
  */
 public function getRepeatable()
 {
     if (isset($this->element['legacy'])) {
         return $this->getInput();
     }
     $class = $this->class ? $this->class : '';
     return '<span class="' . $this->id . ' ' . $class . '">' . htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') . '</span>';
 }
Ejemplo n.º 5
0
 /**
  * Method to get the field input markup.
  *
  * @param   array   $fieldOptions  Options to be passed into the field
  *
  * @return  string  The field HTML
  */
 public function getFieldContents(array $fieldOptions = array())
 {
     $id = isset($fieldOptions['id']) ? 'id="' . $fieldOptions['id'] . '" ' : '';
     $class = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : '');
     return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' . htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') . '</span>';
 }
Ejemplo n.º 6
0
 /**
  * Method to get the field input markup.
  *
  * @param   array   $fieldOptions  Options to be passed into the field
  *
  * @return  string  The field HTML
  */
 public function getFieldContents(array $fieldOptions = array())
 {
     $id = isset($fieldOptions['id']) ? 'id="' . $fieldOptions['id'] . '" ' : '';
     $class = $this->class . (isset($fieldOptions['class']) ? ' ' . $fieldOptions['class'] : '');
     $params = $this->getOptions();
     $db = $this->form->getContainer()->platform->getDbo();
     $query = $db->getQuery(true)->select('a.id AS value, a.title AS text')->from('#__viewlevels AS a')->group('a.id, a.title, a.ordering')->order('a.ordering ASC')->order($db->qn('title') . ' ASC');
     // Get the options.
     $options = $db->setQuery($query)->loadObjectList();
     // If params is an array, push these options to the array
     if (is_array($params)) {
         $options = array_merge($params, $options);
     } elseif ($params) {
         array_unshift($options, JHtml::_('select.option', '', JText::_('JOPTION_ACCESS_SHOW_ALL_LEVELS')));
     }
     return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' . htmlspecialchars(GenericList::getOptionName($options, $this->value), ENT_COMPAT, 'UTF-8') . '</span>';
 }
Ejemplo n.º 7
0
Archivo: Model.php Proyecto: Joal01/fof
 /**
  * Get the rendering of this field type for a repeatable (grid) display,
  * e.g. in a view listing many item (typically a "browse" task)
  *
  * @since 2.0
  *
  * @return  string  The field HTML
  */
 public function getRepeatable()
 {
     // Get field parameters
     $class = $this->class ? $this->class : $this->id;
     $format_string = $this->element['format'] ? (string) $this->element['format'] : '';
     $link_url = $this->element['url'] ? (string) $this->element['url'] : '';
     $empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : '';
     if ($link_url && $this->item instanceof DataModel) {
         $link_url = $this->parseFieldTags($link_url);
     } else {
         $link_url = false;
     }
     if ($this->element['empty_replacement']) {
         $empty_replacement = (string) $this->element['empty_replacement'];
     }
     $value = GenericList::getOptionName($this->getOptions(), $this->value);
     // Get the (optionally formatted) value
     if (!empty($empty_replacement) && empty($value)) {
         $value = JText::_($empty_replacement);
     }
     if (empty($format_string)) {
         $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8');
     } else {
         $value = sprintf($format_string, $value);
     }
     // Create the HTML
     $html = '<span class="' . $class . '">';
     if ($link_url) {
         $html .= '<a href="' . $link_url . '">';
     }
     $html .= $value;
     if ($link_url) {
         $html .= '</a>';
     }
     $html .= '</span>';
     return $html;
 }
Ejemplo n.º 8
0
 /**
  * Gets the active option's label given an array of JHtml options
  *
  * @param   array   $data      The JHtml options to parse
  * @param   mixed   $selected  The currently selected value
  * @param   string  $groupKey  Group name
  * @param   string  $optKey    Key name
  * @param   string  $optText   Value name
  *
  * @return  mixed   The label of the currently selected option
  */
 public static function getOptionName($data, $selected = null, $groupKey = 'items', $optKey = 'value', $optText = 'text')
 {
     if ($groupKey) {
     }
     // Keeps phpStorm from freaking out
     $ret = null;
     foreach ($data as $dataKey => $group) {
         $noGroup = true;
         if (is_array($group) || is_object($group)) {
             $label = $dataKey;
             // If the key is a string, most likely is the title of group
             if (is_string($dataKey)) {
                 $noGroup = false;
             }
         } else {
             throw new InvalidGroupContents(get_called_class());
         }
         if ($noGroup) {
             $label = '';
         }
         $match = GenericList::getOptionName($group, $selected, $optKey, $optText, false);
         if (!is_null($match)) {
             $ret = array('group' => $label, 'item' => $match);
             break;
         }
     }
     return $ret;
 }