getOptions() protected method

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)
protected getOptions ( ) : array
return array The field option objects.
Ejemplo 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;
 }
Ejemplo n.º 2
0
Archivo: Model.php Proyecto: 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];
 }