Inheritance: extends JFormFieldList, implements FOF30\Form\FieldInterface
Exemplo n.º 1
0
 /**
  * Method to get the field options.
  *
  * Ordering is disabled by default. You can enable ordering by setting the
  * 'order' element in your form field. The other order values are optional.
  *
  * - order					What to order.			Possible values: 'name' or 'value' (default = false)
  * - order_dir				Order direction.		Possible values: 'asc' = Ascending or 'desc' = Descending (default = 'asc')
  * - order_case_sensitive	Order case sensitive.	Possible values: 'true' or 'false' (default = false)
  *
  * @return  array  The field option objects.
  *
  * @since	Ordering is available since FOF 2.1.b2.
  */
 protected function getOptions()
 {
     $options = parent::getOptions();
     $defaultOptions = array(JHtml::_('select.option', 1, \JText::_('JYES')), JHtml::_('select.option', 0, \JText::_('JNO')));
     $options = array_merge($defaultOptions, $options);
     return $options;
 }
Exemplo n.º 2
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;
 }
Exemplo 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>';
 }
Exemplo n.º 4
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>';
 }
Exemplo n.º 5
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>';
 }
Exemplo 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'] : '');
     return '<span ' . ($id ? $id : '') . 'class="' . $class . '">' . htmlspecialchars(GenericList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') . '</span>';
 }
Exemplo n.º 7
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>';
 }
Exemplo n.º 8
0
Arquivo: Model.php Projeto: Joal01/fof
 /**
  * Method to get the field options.
  *
  * @return  array  The field option objects.
  */
 protected function getOptions($forceReset = false)
 {
     static $loadedOptions = array();
     $myFormKey = $this->form->getName();
     if ($forceReset && isset($loadedOptions[$myFormKey])) {
         unset($loadedOptions[$myFormKey]);
     }
     if (!isset($loadedOptions[$myFormKey])) {
         $options = array();
         // Initialize some field attributes.
         $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
         $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
         $translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
         $applyAccess = $this->element['apply_access'] ? (string) $this->element['apply_access'] : 'false';
         $modelName = (string) $this->element['model'];
         $nonePlaceholder = (string) $this->element['none'];
         if (!empty($nonePlaceholder)) {
             $options[] = JHtml::_('select.option', null, JText::_($nonePlaceholder));
         }
         // Process field atrtibutes
         $applyAccess = strtolower($applyAccess);
         $applyAccess = in_array($applyAccess, array('yes', 'on', 'true', '1'));
         // Explode model name into component name and prefix
         $componentName = $this->form->getContainer()->componentName;
         $mName = $modelName;
         if (strpos($modelName, '.') !== false) {
             list($componentName, $mName) = explode('.', $mName, 2);
         }
         // Get the applicable container
         $container = $this->form->getContainer();
         if ($componentName != $container->componentName) {
             $container = Container::getInstance($componentName);
         }
         /** @var DataModel $model */
         $model = $container->factory->model($mName)->setIgnoreRequest(true)->savestate(false);
         // Get the model object
         if ($applyAccess) {
             $model->applyAccessFiltering();
         }
         // Process state variables
         /** @var \SimpleXMLElement $stateoption */
         foreach ($this->element->children() as $stateoption) {
             // Only add <option /> elements.
             if ($stateoption->getName() != 'state') {
                 continue;
             }
             $stateKey = (string) $stateoption['key'];
             $stateValue = (string) $stateoption;
             $model->setState($stateKey, $stateValue);
         }
         // Set the query and get the result list.
         $items = $model->get(true);
         // Build the field options.
         if (!empty($items)) {
             foreach ($items as $item) {
                 if ($translate == true) {
                     $options[] = JHtml::_('select.option', $item->{$key}, JText::_($item->{$value}));
                 } else {
                     $options[] = JHtml::_('select.option', $item->{$key}, $item->{$value});
                 }
             }
         }
         // Merge any additional options in the XML definition.
         $options = array_merge(parent::getOptions(), $options);
         $loadedOptions[$myFormKey] = $options;
     }
     return $loadedOptions[$myFormKey];
 }
Exemplo n.º 9
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;
 }