Esempio n. 1
0
 /**
  * Method to get the field options.
  *
  * @return	array	The field option objects.
  * @since	1.6
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     // Initialize some field attributes.
     $first = (int) $this->element['first'];
     $last = (int) $this->element['last'];
     $step = (int) $this->element['step'];
     // Sanity checks.
     if ($step == 0) {
         // Step of 0 will create an endless loop.
         return $options;
     } else {
         if ($first < $last && $step < 0) {
             // A negative step will never reach the last number.
             return $options;
         } else {
             if ($first > $last && $step > 0) {
                 // A position step will never reach the last number.
                 return $options;
             }
         }
     }
     // Build the options array.
     for ($i = $first; $i <= $last; $i += $step) {
         $options[] = GantryHTMLSelect::option($i);
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
Esempio n. 2
0
 /**
  * Method to get the field options.
  *
  * @return	array	The field option objects.
  * @since	1.6
  */
 protected function getOptions()
 {
     // Initialize variables.
     $options = array();
     foreach ($this->element->children() as $option) {
         // Only add <option /> elements.
         if ($option->getName() != 'option') {
             continue;
         }
         // Create a new option object based on the <option /> element.
         $tmp = GantryHTMLSelect::option((string) $option['value'], trim((string) $option), 'value', 'text', (string) $option['disabled'] == 'true');
         // Set some option attributes.
         $tmp->class = (string) $option['class'];
         // Set some JavaScript option attributes.
         $tmp->onclick = (string) $option['onclick'];
         // Add the option object to the result set.
         $options[] = $tmp;
     }
     reset($options);
     return $options;
 }
Esempio n. 3
0
 /**
  * Method to get the field option groups.
  *
  * @return	array	The field option objects as a nested array in groups.
  * @since	1.6
  */
 protected function getGroups()
 {
     // Initialize variables.
     $groups = array();
     $label = 0;
     foreach ($this->element->children() as $element) {
         switch ($element->getName()) {
             // The element is an <option />
             case 'option':
                 // Initialize the group if necessary.
                 if (!isset($groups[$label])) {
                     $groups[$label] = array();
                 }
                 // Create a new option object based on the <option /> element.
                 $tmp = GantryHTMLSelect::option($element['value'] ? (string) $element['value'] : trim((string) $element), JText::_(trim((string) $element)), 'value', 'text', (string) $element['disabled'] == 'true');
                 // Set some option attributes.
                 $tmp->class = (string) $element['class'];
                 // Set some JavaScript option attributes.
                 $tmp->onclick = (string) $element['onclick'];
                 // Add the option.
                 $groups[$label][] = $tmp;
                 break;
                 // The element is a <group />
             // The element is a <group />
             case 'group':
                 // Get the group label.
                 if ($groupLabel = (string) $element['label']) {
                     $label = $groupLabel;
                 }
                 // Initialize the group if necessary.
                 if (!isset($groups[$label])) {
                     $groups[$label] = array();
                 }
                 // Iterate through the children and build an array of options.
                 foreach ($element->children() as $option) {
                     // Only add <option /> elements.
                     if ($option->getName() != 'option') {
                         continue;
                     }
                     // Create a new option object based on the <option /> element.
                     $tmp = GantryHTMLSelect::option($element['value'] ? (string) $element['value'] : JText::_(trim((string) $element)), JText::_(trim((string) $element)), 'value', 'text', (string) $element['disabled'] == 'true');
                     // Set some option attributes.
                     $tmp->class = (string) $element['class'];
                     // Set some JavaScript option attributes.
                     $tmp->onclick = (string) $element['onclick'];
                     // Add the option.
                     $groups[$label][] = $tmp;
                 }
                 if ($groupLabel) {
                     $label = count($groups);
                 }
                 break;
                 // Unknown element type.
             // Unknown element type.
             default:
                 //TODO Handle Error
                 //JError::raiseError(500, JText::sprintf('JLIB_FORM_ERROR_FIELDS_GROUPEDLIST_ELEMENT_NAME', $element->getName()));
                 break;
         }
     }
     reset($groups);
     return $groups;
 }