Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
integer.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Form
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 JFormHelper::loadFieldClass('list');
13 
14 /**
15  * Form Field class for the Joomla Platform.
16  * Provides a select list of integers with specified first, last and step values.
17  *
18  * @package Joomla.Platform
19  * @subpackage Form
20  * @since 11.1
21  */
23 {
24  /**
25  * The form field type.
26  *
27  * @var string
28  * @since 11.1
29  */
30  protected $type = 'Integer';
31 
32  /**
33  * Method to get the field options.
34  *
35  * @return array The field option objects.
36  *
37  * @since 11.1
38  */
39  protected function getOptions()
40  {
41  $options = array();
42 
43  // Initialize some field attributes.
44  $first = (int) $this->element['first'];
45  $last = (int) $this->element['last'];
46  $step = (int) $this->element['step'];
47 
48  // Sanity checks.
49  if ($step == 0)
50  {
51  // Step of 0 will create an endless loop.
52  return $options;
53  }
54  elseif ($first < $last && $step < 0)
55  {
56  // A negative step will never reach the last number.
57  return $options;
58  }
59  elseif ($first > $last && $step > 0)
60  {
61  // A position step will never reach the last number.
62  return $options;
63  }
64  elseif ($step < 0)
65  {
66  // Build the options array backwards.
67  for ($i = $first; $i >= $last; $i += $step)
68  {
69  $options[] = JHtml::_('select.option', $i);
70  }
71  }
72  else
73  {
74  // Build the options array.
75  for ($i = $first; $i <= $last; $i += $step)
76  {
77  $options[] = JHtml::_('select.option', $i);
78  }
79  }
80 
81  // Merge any additional options in the XML definition.
82  $options = array_merge(parent::getOptions(), $options);
83 
84  return $options;
85  }
86 }