1: | <?php |
2: | |
3: | namespace Aurora\System\Classes; |
4: | |
5: | trait DisabledModulesTrait |
6: | { |
7: | public function isModuleDisabled($sModuleName) |
8: | { |
9: | $aDisabledModules = $this->getDisabledModules(); |
10: | |
11: | return in_array($sModuleName, $aDisabledModules); |
12: | } |
13: | |
14: | public function getDisabledModules() |
15: | { |
16: | $sDisabledModules = $this->getExtendedProp('DisabledModules'); |
17: | $sDisabledModules = isset($sDisabledModules) ? \trim($sDisabledModules) : ''; |
18: | $aDisabledModules = !empty($sDisabledModules) ? [$sDisabledModules] : []; |
19: | if (substr_count($sDisabledModules, "|") > 0) { |
20: | $aDisabledModules = explode("|", $sDisabledModules); |
21: | } |
22: | |
23: | return $aDisabledModules; |
24: | } |
25: | |
26: | public function clearDisabledModules() |
27: | { |
28: | $this->setExtendedProp('DisabledModules', ''); |
29: | $this->save(); |
30: | } |
31: | |
32: | public function disableModule($sModuleName) |
33: | { |
34: | $aDisabledModules = $this->getDisabledModules(); |
35: | if (!in_array($sModuleName, $aDisabledModules)) { |
36: | $aDisabledModules[] = $sModuleName; |
37: | |
38: | $aDisabledModules = array_filter($aDisabledModules, function ($var) { |
39: | return !empty($var); |
40: | }); |
41: | $this->setExtendedProp('DisabledModules', implode("|", $aDisabledModules)); |
42: | $this->save(); |
43: | } |
44: | } |
45: | |
46: | public function disableModules($aModules) |
47: | { |
48: | $aDisabledModules = $this->getDisabledModules(); |
49: | foreach ($aModules as $sModuleName) { |
50: | if (!in_array($sModuleName, $aDisabledModules)) { |
51: | $aDisabledModules[] = $sModuleName; |
52: | |
53: | $aDisabledModules = array_filter($aDisabledModules, function ($var) { |
54: | return !empty($var); |
55: | }); |
56: | } |
57: | } |
58: | $this->setExtendedProp('DisabledModules', implode("|", $aDisabledModules)); |
59: | $this->save(); |
60: | } |
61: | |
62: | public function enableModule($sModuleName) |
63: | { |
64: | $aDisabledModules = $this->getDisabledModules(); |
65: | |
66: | if (($iKey = array_search($sModuleName, $aDisabledModules)) !== false) { |
67: | unset($aDisabledModules[$iKey]); |
68: | $this->setExtendedProp('DisabledModules', implode("|", $aDisabledModules)); |
69: | $this->save(); |
70: | } |
71: | } |
72: | |
73: | public function enableModules($aModules) |
74: | { |
75: | $aDisabledModules = $this->getDisabledModules(); |
76: | |
77: | foreach ($aModules as $sModuleName) { |
78: | if (($iKey = array_search($sModuleName, $aDisabledModules)) !== false) { |
79: | unset($aDisabledModules[$iKey]); |
80: | } |
81: | } |
82: | $this->setExtendedProp('DisabledModules', implode("|", $aDisabledModules)); |
83: | $this->save(); |
84: | } |
85: | } |
86: | |