1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Form Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Form; |
10
|
|
|
|
11
|
|
|
use Joomla\Form\Html\Select as HtmlSelect; |
12
|
|
|
|
13
|
|
|
FormHelper::loadFieldClass('list'); |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Form Field class for the Joomla Framework. |
17
|
|
|
* Provides a select list of integers with specified first, last and step values. |
18
|
|
|
* |
19
|
|
|
* @since 1.0 |
20
|
|
|
* @deprecated The joomla/form package is deprecated |
21
|
|
|
*/ |
22
|
|
|
class Field_Integer extends Field_List |
|
|
|
|
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* The form field type. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
* @since 1.0 |
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 1.0 |
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
|
|
View Code Duplication |
elseif ($step < 0) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
// Build the options array backwards. |
67
|
|
|
for ($i = $first; $i >= $last; $i += $step) |
68
|
|
|
{ |
69
|
|
|
$options[] = HtmlSelect::option($i); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
View Code Duplication |
else |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
// Build the options array. |
75
|
|
|
for ($i = $first; $i <= $last; $i += $step) |
76
|
|
|
{ |
77
|
|
|
$options[] = HtmlSelect::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
|
|
|
} |
87
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.