1 <?php
2
3 4 5 6 7 8 9 10
11
12 namespace Icybee\Modules\Modules;
13
14 use ICanBoogie\I18n;
15
16 17 18
19 class DeactivateOperation extends \ICanBoogie\Operation
20 {
21 protected function get_controls()
22 {
23 return array
24 (
25 self::CONTROL_PERMISSION => Module::PERMISSION_ADMINISTER
26 )
27
28 + parent::get_controls();
29 }
30
31 32 33
34 protected function validate(\ICanboogie\Errors $errors)
35 {
36 global $core;
37
38 if ($this->key)
39 {
40 foreach (array_keys($this->key) as $module_id)
41 {
42 $n = $core->modules->usage($module_id);
43
44 if ($n)
45 {
46 $errors[] = $errors->format
47 (
48 'The module %title cannot be disabled, :count modules are using it.', array
49 (
50 'title' => I18n\t($module_id, array(), array('scope' => 'module_title')),
51 ':count' => $n
52 )
53 );
54 }
55 }
56 }
57
58 return $errors;
59 }
60
61 protected function process()
62 {
63 global $core;
64
65 $enabled = array_keys($core->modules->enabled_modules_descriptors);
66 $enabled = array_combine($enabled, $enabled);
67
68 if ($this->key)
69 {
70 foreach (array_keys($this->key) as $key)
71 {
72 unset($enabled[$key]);
73 unset($core->modules[$key]);
74 }
75 }
76
77 $core->vars['enabled_modules'] = array_values($enabled);
78
79 $this->response->location = \ICanBoogie\Routing\contextualize('/admin/' . $this->module->id);
80
81 return true;
82 }
83 }