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 FOFFormFieldActions extends JFormFieldList implements FOFFormField
21 {
22 protected $static;
23
24 protected $repeatable;
25
26
27 public $rowid;
28
29
30 public $item;
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 protected function getConfig()
74 {
75
76
77 $config = array(
78 'published' => 1,
79 'unpublished' => 1,
80 'archived' => 0,
81 'trash' => 0,
82 'all' => 0,
83 );
84
85 $stack = array();
86
87 if (isset($this->element['show_published']))
88 {
89 $config['published'] = FOFStringUtils::toBool($this->element['show_published']);
90 }
91
92 if (isset($this->element['show_unpublished']))
93 {
94 $config['unpublished'] = FOFStringUtils::toBool($this->element['show_unpublished']);
95 }
96
97 if (isset($this->element['show_archived']))
98 {
99 $config['archived'] = FOFStringUtils::toBool($this->element['show_archived']);
100 }
101
102 if (isset($this->element['show_trash']))
103 {
104 $config['trash'] = FOFStringUtils::toBool($this->element['show_trash']);
105 }
106
107 if (isset($this->element['show_all']))
108 {
109 $config['all'] = FOFStringUtils::toBool($this->element['show_all']);
110 }
111
112 return $config;
113 }
114
115 116 117 118 119 120 121
122 protected function getOptions()
123 {
124 return null;
125 }
126
127 128 129 130 131 132 133
134 protected function getPublishedField($enabledFieldName)
135 {
136 $attributes = array(
137 'name' => $enabledFieldName,
138 'type' => 'published',
139 );
140
141 if ($this->element['publish_up'])
142 {
143 $attributes['publish_up'] = (string) $this->element['publish_up'];
144 }
145
146 if ($this->element['publish_down'])
147 {
148 $attributes['publish_down'] = (string) $this->element['publish_down'];
149 }
150
151 foreach ($attributes as $name => $value)
152 {
153 if (!is_null($value))
154 {
155 $renderedAttributes[] = $name . '="' . $value . '"';
156 }
157 }
158
159 $publishedXml = new SimpleXMLElement('<field ' . implode(' ', $renderedAttributes) . ' />');
160
161 $publishedField = new FOFFormFieldPublished($this->form);
162
163
164 $publishedField->item = $this->item;
165 $publishedField->rowid = $this->rowid;
166 $publishedField->setup($publishedXml, $this->item->{$enabledFieldName});
167
168 return $publishedField;
169 }
170
171 172 173 174 175 176 177 178
179 public function getStatic()
180 {
181 throw new Exception(__CLASS__ . ' cannot be used in single item display forms');
182 }
183
184 185 186 187 188 189 190 191
192 public function getRepeatable()
193 {
194 if (!($this->item instanceof FOFTable))
195 {
196 throw new Exception(__CLASS__ . ' needs a FOFTable to act upon');
197 }
198
199 $config = $this->getConfig();
200
201
202 $prefix = '';
203 $checkbox = 'cb';
204 $publish_up = null;
205 $publish_down = null;
206 $enabled = true;
207
208 $html = '<div class="btn-group">';
209
210
211 if ($publishedFieldName = $this->item->getColumnAlias('enabled'))
212 {
213 if ($config['published'] || $config['unpublished'])
214 {
215
216 $publishedField = $this->getPublishedField($publishedFieldName);
217
218
219 $html .= $publishedField->getRepeatable();
220 }
221
222 if ($config['archived'])
223 {
224 $archived = $this->item->{$publishedFieldName} == 2 ? true : false;
225
226
227 $action = $archived ? 'unarchive' : 'archive';
228 JHtml::_('actionsdropdown.' . $action, 'cb' . $this->rowid, $prefix);
229 }
230
231 if ($config['trash'])
232 {
233 $trashed = $this->item->{$publishedFieldName} == -2 ? true : false;
234
235 $action = $trashed ? 'untrash' : 'trash';
236 JHtml::_('actionsdropdown.' . $action, 'cb' . $this->rowid, $prefix);
237 }
238
239
240 if ($config['archived'] || $config['trash'])
241 {
242 $html .= JHtml::_('actionsdropdown.render', $this->item->title);
243 }
244 }
245
246 $html .= '</div>';
247
248 return $html;
249 }
250 }
251