1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace ICanBoogie;
13
14 use ICanBoogie\I18n\FormattedString;
15
16 17 18
19 class DeleteOperation extends Operation
20 {
21 22 23 24 25 26 27
28 protected function get_controls()
29 {
30 return [
31
32 self::CONTROL_PERMISSION => Module::PERMISSION_MANAGE,
33 self::CONTROL_RECORD => true,
34 self::CONTROL_OWNERSHIP => true
35
36 ] + parent::get_controls();
37 }
38
39 protected function validate(Errors $errors)
40 {
41 return true;
42 }
43
44 45 46
47 protected function process()
48 {
49 $key = $this->key;
50
51 if (!$this->module->model->delete($key))
52 {
53 throw new Exception('Unable to delete the record %key from %module.', [
54
55 'key' => $key,
56 'module' => $this->module->title
57
58 ]);
59 }
60
61 if ($this->request['redirect_to'])
62 {
63 $this->response->location = $this->request['redirect_to'];
64 }
65
66 $this->response->message = new FormattedString('The record %key has been deleted from %module.', [
67
68 'key' => $key,
69 'module' => $this->module->title
70
71 ]);
72
73 return $key;
74 }
75 }