1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Pages;
13
14 15 16
17 class UpdateTreeOperation extends \ICanBoogie\Operation
18 {
19 protected function get_controls()
20 {
21 return array
22 (
23 self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER
24 )
25
26 + parent::get_controls();
27 }
28
29 protected function validate(\ICanboogie\Errors $errors)
30 {
31 $order = $this->request['order'];
32 $relation = $this->request['relation'];
33
34 if ($order && $relation)
35 {
36 foreach ($order as $nid)
37 {
38 if (!isset($relation[$nid]))
39 {
40 $errors['relation'] = $errors->format("Missing relation for nid %nid.", array('nid' => $nid));
41 }
42 }
43 }
44 else
45 {
46 if (!$order)
47 {
48 $errors['order'] = $errors->format("The %param param is required", array('param' => 'order'));
49 }
50
51 if (!$relation)
52 {
53 $errors['relation'] = $errors->format("The %param param is required", array('param' => 'relation'));
54 }
55 }
56
57 return !$errors->count();
58 }
59
60 protected function process()
61 {
62 $w = 0;
63 $update = $this->module->model->prepare('UPDATE {self} SET `parentid` = ?, `weight` = ? WHERE `{primary}` = ? LIMIT 1');
64
65 $order = $this->request['order'];
66 $relation = $this->request['relation'];
67
68 foreach ($order as $nid)
69 {
70 $parent_id = $relation[$nid];
71
72
73
74 $update($parent_id, $w++, $nid);
75 }
76
77 return true;
78 }
79 }