1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 12 13 14 15 16 17
18 class FOFFormFieldOrdering extends JFormField implements FOFFormField
19 {
20 protected $static;
21
22 protected $repeatable;
23
24
25 public $item;
26
27
28 public $rowid;
29
30 31 32 33 34 35 36 37 38
39 public function __get($name)
40 {
41 switch ($name)
42 {
43 case 'static':
44 if (empty($this->static))
45 {
46 $this->static = $this->getStatic();
47 }
48
49 return $this->static;
50 break;
51
52 case 'repeatable':
53 if (empty($this->repeatable))
54 {
55 $this->repeatable = $this->getRepeatable();
56 }
57
58 return $this->repeatable;
59 break;
60
61 default:
62 return parent::__get($name);
63 }
64 }
65
66 67 68 69 70 71 72
73 protected function getInput()
74 {
75 $html = array();
76 $attr = '';
77
78
79 $attr .= !empty($this->class) ? ' class="' . $this->class . '"' : '';
80 $attr .= $this->disabled ? ' disabled' : '';
81 $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : '';
82
83
84 $attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
85
86 $this->item = $this->form->getModel()->getItem();
87
88 $keyfield = $this->item->getKeyName();
89 $itemId = $this->item->$keyfield;
90
91 $query = $this->getQuery();
92
93
94 if ($this->readonly)
95 {
96 $html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $itemId ? 0 : 1);
97 $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
98 }
99 else
100 {
101
102 $html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $itemId ? 0 : 1);
103 }
104
105 return implode($html);
106 }
107
108 109 110 111 112 113 114 115
116 public function getStatic()
117 {
118 throw new Exception(__CLASS__ . ' cannot be used in single item display forms');
119 }
120
121 122 123 124 125 126 127 128
129 public function getRepeatable()
130 {
131 if (!($this->item instanceof FOFTable))
132 {
133 throw new Exception(__CLASS__ . ' needs a FOFTable to act upon');
134 }
135
136 $class = isset($this->element['class']) ? $this->element['class'] : 'input-mini';
137 $icon = isset($this->element['icon']) ? $this->element['icon'] : 'icon-menu';
138
139 $html = '';
140
141 $view = $this->form->getView();
142
143 $ordering = $view->getLists()->order == 'ordering';
144
145 if (!$view->hasAjaxOrderingSupport())
146 {
147
148 $disabled = $ordering ? '' : 'disabled="disabled"';
149 $html .= '<span>';
150 $html .= $view->pagination->orderUpIcon($this->rowid, true, 'orderup', 'Move Up', $ordering);
151 $html .= '</span><span>';
152 $html .= $view->pagination->orderDownIcon($this->rowid, $view->pagination->total, true, 'orderdown', 'Move Down', $ordering);
153 $html .= '</span>';
154 $html .= '<input type="text" name="order[]" size="5" value="' . $this->value . '" ' . $disabled;
155 $html .= 'class="text-area-order" style="text-align: center" />';
156 }
157 else
158 {
159
160 if ($view->getPerms()->editstate)
161 {
162 $disableClassName = '';
163 $disabledLabel = '';
164
165 $hasAjaxOrderingSupport = $view->hasAjaxOrderingSupport();
166
167 if (!$hasAjaxOrderingSupport['saveOrder'])
168 {
169 $disabledLabel = JText::_('JORDERINGDISABLED');
170 $disableClassName = 'inactive tip-top';
171 }
172
173 $orderClass = $ordering ? 'order-enabled' : 'order-disabled';
174
175 $html .= '<div class="' . $orderClass . '">';
176 $html .= '<span class="sortable-handler ' . $disableClassName . '" title="' . $disabledLabel . '" rel="tooltip">';
177 $html .= '<i class="' . $icon . '"></i>';
178 $html .= '</span>';
179
180 if ($ordering)
181 {
182 $html .= '<input type="text" name="order[]" size="5" class="' . $class . ' text-area-order" value="' . $this->value . '" />';
183 }
184
185 $html .= '</div>';
186 }
187 else
188 {
189 $html .= '<span class="sortable-handler inactive" >';
190 $html .= '<i class="' . $icon . '"></i>';
191 $html .= '</span>';
192 }
193 }
194
195 return $html;
196 }
197
198 199 200 201 202 203 204
205 protected function getQuery()
206 {
207 $ordering = $this->name;
208 $title = $this->element['ordertitle'] ? (string) $this->element['ordertitle'] : $this->item->getColumnAlias('title');
209
210 $db = FOFPlatform::getInstance()->getDbo();
211 $query = $db->getQuery(true);
212 $query->select(array($db->quoteName($ordering, 'value'), $db->quoteName($title, 'text')))
213 ->from($db->quoteName($this->item->getTableName()))
214 ->order($ordering);
215
216 return $query;
217 }
218 }
219