/** * 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; }
/** * 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; }
/** * Method to get the field input markup. * * @return string The field input markup. * @since 1.6 */ public function getInput() { // Initialize variables. $html = array(); $attr = ''; // Initialize some field attributes. $attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : ''; $attr .= (string) $this->element['disabled'] == 'true' ? ' disabled="disabled"' : ''; $attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : ''; $attr .= $this->multiple ? ' multiple="multiple"' : ''; // Initialize JavaScript field attributes. $attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : ''; // Get the field groups. $groups = (array) $this->getGroups(); // Create a read-only list (no name) with a hidden input to store the value. if ((string) $this->element['readonly'] == 'true') { $html[] = GantryHTMLSelect::groupedlist($groups, null, array('list.attr' => $attr, 'id' => $this->id, 'list.select' => $this->value, 'group.items' => null, 'option.key.toHtml' => false, 'option.text.toHtml' => false)); $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>'; } else { $html[] = GantryHTMLSelect::groupedlist($groups, $this->name, array('list.attr' => $attr, 'id' => $this->id, 'list.select' => $this->value, 'group.items' => null, 'option.key.toHtml' => false, 'option.text.toHtml' => false)); } return implode($html); }
/** * Generates a selection list of integers. * * @param int The start integer * @param int The end integer * @param int The increment * @param string The value of the HTML name attribute * @param mixed Additional HTML attributes for the <select> tag, an array of * attributes, or an array of options. Treated as options if it is the last * argument passed. * @param mixed The key that is selected * @param string The printf format to be applied to the number * @return string HTML for the select list */ public static function integerlist($start, $end, $inc, $name, $attribs = null, $selected = null, $format = '') { // Set default options $options = array_merge(GantryHTMLSelect::$formatOptions, array('format.depth' => 0, 'option.format' => '', 'id' => null)); if (is_array($attribs) && func_num_args() == 5) { // Assume we have an options array $options = array_merge($options, $attribs); // Extract the format and remove it from downstream options $format = $options['option.format']; unset($options['option.format']); } else { // Get options from the parameters $options['list.attr'] = $attribs; $options['list.select'] = $selected; } $start = intval($start); $end = intval($end); $inc = intval($inc); $data = array(); for ($i = $start; $i <= $end; $i += $inc) { $data[$i] = $format ? sprintf($format, $i) : $i; } // Tell genericlist() to use array keys $options['option.key'] = null; return GantryHTMLSelect::genericlist($data, $name, $options); }