1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 JFormHelper::loadFieldClass('checkbox');
12
13 14 15 16 17 18 19
20 class FOFFormFieldCheckbox extends JFormFieldCheckbox implements FOFFormField
21 {
22 protected $static;
23
24 protected $repeatable;
25
26
27 public $item;
28
29
30 public $rowid;
31
32 33 34 35 36 37 38 39 40
41 public function __get($name)
42 {
43 switch ($name)
44 {
45 case 'static':
46 if (empty($this->static))
47 {
48 $this->static = $this->getStatic();
49 }
50
51 return $this->static;
52 break;
53
54 case 'repeatable':
55 if (empty($this->repeatable))
56 {
57 $this->repeatable = $this->getRepeatable();
58 }
59
60 return $this->repeatable;
61 break;
62
63 default:
64 return parent::__get($name);
65 }
66 }
67
68 69 70 71 72 73 74 75
76 public function getStatic()
77 {
78 $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
79 $value = $this->element['value'] ? (string) $this->element['value'] : '1';
80 $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
81 $onclick = $this->element['onclick'] ? ' onclick="' . (string) $this->element['onclick'] . '"' : '';
82 $required = $this->required ? ' required="required" aria-required="true"' : '';
83
84 if (empty($this->value))
85 {
86 $checked = (isset($this->element['checked'])) ? ' checked="checked"' : '';
87 }
88 else
89 {
90 $checked = ' checked="checked"';
91 }
92
93 return '<span id="' . $this->id . '" ' . $class . '>' .
94 '<input type="checkbox" name="' . $this->name . '" id="' . $this->id . '"' . ' value="'
95 . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $class . $checked . $disabled . $onclick . $required . ' />' .
96 '</span>';
97 }
98
99 100 101 102 103 104 105 106
107 public function getRepeatable()
108 {
109 $class = $this->element['class'] ? (string) $this->element['class'] : '';
110 $value = $this->element['value'] ? (string) $this->element['value'] : '1';
111 $disabled = ((string) $this->element['disabled'] == 'true') ? ' disabled="disabled"' : '';
112 $onclick = $this->element['onclick'] ? ' onclick="' . (string) $this->element['onclick'] . '"' : '';
113 $required = $this->required ? ' required="required" aria-required="true"' : '';
114
115 if (empty($this->value))
116 {
117 $checked = (isset($this->element['checked'])) ? ' checked="checked"' : '';
118 }
119 else
120 {
121 $checked = ' checked="checked"';
122 }
123
124 return '<span class="' . $this->id . ' ' . $class . '">' .
125 '<input type="checkbox" name="' . $this->name . '" class="' . $this->id . ' ' . $class . '"' . ' value="'
126 . htmlspecialchars($value, ENT_COMPAT, 'UTF-8') . '"' . $checked . $disabled . $onclick . $required . ' />' .
127 '</span>';
128 }
129 }
130