1 | <?php |
||
26 | class ManageController extends AppController |
||
27 | { |
||
28 | |||
29 | /** |
||
30 | * Shows a list of all the blocks & widgets. |
||
31 | * |
||
32 | * @return void |
||
33 | */ |
||
34 | public function index() |
||
54 | |||
55 | /** |
||
56 | * Creates a new custom block. |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | public function add() |
||
91 | |||
92 | /** |
||
93 | * Edits the given block by ID. |
||
94 | * |
||
95 | * The event `Block.<handler>.validate` will be automatically triggered, |
||
96 | * so custom block's (those handled by plugins <> "Block") can be validated |
||
97 | * before persisted. |
||
98 | * |
||
99 | * @param string $id Block's ID |
||
100 | * @return void |
||
101 | * @throws \Cake\ORM\Exception\RecordNotFoundException if no block is not found |
||
102 | */ |
||
103 | public function edit($id) |
||
135 | |||
136 | /** |
||
137 | * Deletes the given block by ID. |
||
138 | * |
||
139 | * Only custom blocks can be deleted (those with "Block" has handler). |
||
140 | * |
||
141 | * @param string $id Block's ID |
||
142 | * @return void Redirects to previous page |
||
143 | * @throws \Cake\ORM\Exception\RecordNotFoundException if no record can be found |
||
144 | * given a primary key value |
||
145 | * @throws \InvalidArgumentException When $primaryKey has an incorrect number |
||
146 | * of elements |
||
147 | */ |
||
148 | public function delete($id) |
||
170 | |||
171 | /** |
||
172 | * Edits the given block by ID. |
||
173 | * |
||
174 | * @param string $id Block's ID |
||
175 | * @return void Redirects to previous page |
||
176 | * @throws \Cake\ORM\Exception\RecordNotFoundException if no block is not found |
||
177 | */ |
||
178 | public function duplicate($id) |
||
196 | |||
197 | /** |
||
198 | * Reorders blocks based on the order provided via POST. |
||
199 | * |
||
200 | * @return bool True on success, false otherwise |
||
201 | */ |
||
202 | protected function _reorder() |
||
203 | { |
||
204 | if (!empty($this->request->data['regions'])) { |
||
205 | foreach ($this->request->data['regions'] as $theme => $regions) { |
||
206 | foreach ($regions as $region => $ids) { |
||
207 | $ordering = 0; |
||
208 | foreach ($ids as $id) { |
||
209 | $blockRegion = $this->Blocks |
||
210 | ->BlockRegions |
||
211 | ->newEntity([ |
||
212 | 'id' => $id, |
||
213 | 'theme' => $theme, |
||
214 | 'region' => $region, |
||
215 | 'ordering' => $ordering |
||
216 | ]); |
||
217 | $blockRegion->isNew(false); |
||
218 | $this->Blocks->BlockRegions->save($blockRegion); |
||
219 | $ordering++; |
||
220 | } |
||
221 | } |
||
222 | } |
||
223 | |||
224 | return true; |
||
225 | } |
||
226 | |||
227 | return false; |
||
228 | } |
||
229 | |||
230 | /** |
||
231 | * Sets "languages" variable for later use in FormHelper. |
||
232 | * |
||
233 | * @return void |
||
234 | */ |
||
235 | protected function _setLanguages() |
||
239 | |||
240 | /** |
||
241 | * Sets "roles" variable for later use in FormHelper. |
||
242 | * |
||
243 | * @return void |
||
244 | */ |
||
245 | protected function _setRoles() |
||
251 | |||
252 | /** |
||
253 | * Sets "regions" variable for later use in FormHelper. |
||
254 | * |
||
255 | * This variable is used to properly fill inputs in the "Theme Region" |
||
256 | * section of the add/edit form. |
||
257 | * |
||
258 | * @param null|\Block\Model\Entity\Block $block If a block entity is provided it |
||
259 | * will be used to guess which regions has been already selected in each theme, |
||
260 | * so we can properly show the selectbox in the form with the corrects |
||
261 | * options selected. |
||
262 | * @return void |
||
263 | */ |
||
264 | protected function _setRegions($block = null) |
||
291 | |||
292 | /** |
||
293 | * Prepares incoming data from Form's POST and patches the given entity. |
||
294 | * |
||
295 | * @param \Block\Model\Entity\Block $block BLock to patch with incoming |
||
296 | * POST data |
||
297 | * @return \Cake\Datasource\EntityInterface Patched entity |
||
298 | */ |
||
299 | protected function _patchEntity($block) |
||
330 | } |
||
331 |