1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 JFormHelper::loadFieldClass('list');
12
13 14 15 16 17 18 19
20 class FOFFormFieldPublished extends JFormFieldList 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 protected function getOptions()
76 {
77 $options = parent::getOptions();
78
79 if (!empty($options))
80 {
81 return $options;
82 }
83
84
85
86
87 $config = array(
88 'published' => 1,
89 'unpublished' => 1,
90 'archived' => 0,
91 'trash' => 0,
92 'all' => 0,
93 );
94
95 $configMap = array(
96 'show_published' => array('published', 1),
97 'show_unpublished' => array('unpublished', 1),
98 'show_archived' => array('archived', 0),
99 'show_trash' => array('trash', 0),
100 'show_all' => array('all', 0),
101 );
102
103 foreach ($configMap as $attribute => $preferences)
104 {
105 list($configKey, $default) = $preferences;
106
107 switch (strtolower($this->element[$attribute]))
108 {
109 case 'true':
110 case '1':
111 case 'yes':
112 $config[$configKey] = true;
113
114 case 'false':
115 case '0':
116 case 'no':
117 $config[$configKey] = false;
118
119 default:
120 $config[$configKey] = $default;
121 }
122 }
123
124 if ($config['published'])
125 {
126 $stack[] = JHtml::_('select.option', '1', JText::_('JPUBLISHED'));
127 }
128
129 if ($config['unpublished'])
130 {
131 $stack[] = JHtml::_('select.option', '0', JText::_('JUNPUBLISHED'));
132 }
133
134 if ($config['archived'])
135 {
136 $stack[] = JHtml::_('select.option', '2', JText::_('JARCHIVED'));
137 }
138
139 if ($config['trash'])
140 {
141 $stack[] = JHtml::_('select.option', '-2', JText::_('JTRASHED'));
142 }
143
144 if ($config['all'])
145 {
146 $stack[] = JHtml::_('select.option', '*', JText::_('JALL'));
147 }
148
149 return $stack;
150 }
151
152 153 154 155 156 157 158 159
160 public function getStatic()
161 {
162 $class = $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
163
164 return '<span id="' . $this->id . '" ' . $class . '>' .
165 htmlspecialchars(FOFFormFieldList::getOptionName($this->getOptions(), $this->value), ENT_COMPAT, 'UTF-8') .
166 '</span>';
167 }
168
169 170 171 172 173 174 175 176
177 public function getRepeatable()
178 {
179 if (!($this->item instanceof FOFTable))
180 {
181 throw new Exception(__CLASS__ . ' needs a FOFTable to act upon');
182 }
183
184
185 $prefix = '';
186 $checkbox = 'cb';
187 $publish_up = null;
188 $publish_down = null;
189 $enabled = true;
190
191
192 if ($this->element['prefix'])
193 {
194 $prefix = (string) $this->element['prefix'];
195 }
196
197 if ($this->element['checkbox'])
198 {
199 $checkbox = (string) $this->element['checkbox'];
200 }
201
202 if ($this->element['publish_up'])
203 {
204 $publish_up = (string) $this->element['publish_up'];
205 }
206
207 if ($this->element['publish_down'])
208 {
209 $publish_down = (string) $this->element['publish_down'];
210 }
211
212
213
214 return JHTML::_('jgrid.published', $this->value, $this->rowid, $prefix, $enabled, $checkbox, $publish_up, $publish_down);
215 }
216 }
217