1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Comments;
13
14 use ICanBoogie\Errors;
15
16 class PatchOperation extends \ICanBoogie\Operation
17 {
18 protected function get_controls()
19 {
20 return array
21 (
22 self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER
23 )
24
25 + parent::get_controls();
26 }
27
28 protected function validate(Errors $errors)
29 {
30 $status = $this->request['status'];
31
32 if ($status !== null && !in_array($status, array(Comment::STATUS_APPROVED, Comment::STATUS_PENDING, Comment::STATUS_SPAM)))
33 {
34 throw new \InvalidArgumentException('Invalid status value: ' . $status);
35 }
36
37 return $errors;
38 }
39
40 protected function process()
41 {
42 $record = $this->record;
43
44
45
46 $status = $this->request['status'];
47
48 if ($status)
49 {
50 static $status_names = array
51 (
52 Comment::STATUS_APPROVED => 'Approved',
53 Comment::STATUS_PENDING => 'Pending',
54 Comment::STATUS_SPAM => 'Spam'
55 );
56
57 $record->status = $status;
58 }
59
60
61
62 $record->save();
63
64 return true;
65 }
66 }