1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: 19: 20: 21: 22: 23: 24:
25: class PimPluginSetupStatus extends PimPluginSetup {
26:
27:
28:
29: protected $_PimPluginCollection;
30:
31:
32: protected $_PimPluginRelationsCollection;
33:
34:
35: protected $_ApiNavSubCollection;
36:
37: 38: 39: 40: 41:
42: private function _setPimPluginCollection() {
43: return $this->_PimPluginCollection = new PimPluginCollection();
44: }
45:
46: 47: 48: 49: 50:
51: private function _setPimPluginRelationsCollection() {
52: return $this->_PimPluginRelationsCollection = new PimPluginRelationsCollection();
53: }
54:
55: 56: 57: 58: 59:
60: private function _setApiNavSubCollection() {
61: return $this->_ApiNavSubCollection = new cApiNavSubCollection();
62: }
63:
64:
65: 66: 67:
68: public function __construct() {
69:
70:
71:
72: $this->_setPimPluginCollection();
73: $this->_setPimPluginRelationsCollection();
74:
75:
76: $this->_setApiNavSubCollection();
77: }
78:
79: 80: 81: 82: 83:
84: public function changeActiveStatus($pluginId) {
85:
86:
87: self::setPluginId($pluginId);
88:
89:
90: $this->_PimPluginCollection->setWhere('idplugin', cSecurity::toInteger($pluginId));
91: $this->_PimPluginCollection->query();
92: $plugin = $this->_PimPluginCollection->next();
93:
94:
95: $pluginName = $plugin->get('name');
96: $pluginActiveStatus = $plugin->get('active');
97:
98:
99: $this->_PimPluginRelationsCollection->setWhere('idplugin', cSecurity::toInteger($pluginId));
100: $this->_PimPluginRelationsCollection->setWhere('type', 'navs');
101: $this->_PimPluginRelationsCollection->query();
102:
103: if ($pluginActiveStatus == 1) {
104:
105:
106:
107: $this->_updateCheckDependencies();
108:
109: $plugin->set('active', 0);
110: $plugin->store();
111:
112:
113:
114: while (($relation = $this->_PimPluginRelationsCollection->next()) !== false) {
115: $idnavs = $relation->get('iditem');
116: $this->_changeNavSubStatus($idnavs, 0);
117: }
118:
119: parent::info(sprintf(i18n('The plugin <strong>%s</strong> has been sucessfully disabled. To apply the changes please login into backend again.', 'pim'), $pluginName));
120: } else {
121: $plugin->set('active', 1);
122: $plugin->store();
123:
124:
125:
126: while (($relation = $this->_PimPluginRelationsCollection->next()) !== false) {
127: $idnavs = $relation->get('iditem');
128: $this->_changeNavSubStatus($idnavs, 1);
129: }
130:
131: parent::info(sprintf(i18n('The plugin <strong>%s</strong> has been sucessfully enabled. To apply the changes please login into backend again.', 'pim'), $pluginName));
132: }
133: }
134:
135: 136: 137:
138: private function _updateCheckDependencies() {
139:
140:
141:
142: $result = $this->checkDependencies();
143:
144:
145: if ($result === false) {
146: parent::error(sprintf(i18n('This plugin is required by the plugin <strong>%s</strong>, so you can not deactivate it.', 'pim'), parent::_getPluginName()));
147: }
148: }
149:
150: 151: 152: 153: 154: 155: 156:
157: private function _changeNavSubStatus($idnavs, $online) {
158: $this->_ApiNavSubCollection->setWhere('idnavs', cSecurity::toInteger($idnavs));
159: $this->_ApiNavSubCollection->query();
160:
161: $navSub = $this->_ApiNavSubCollection->next();
162: $navSub->set('online', cSecurity::toInteger($online));
163: $navSub->store();
164:
165: return true;
166: }
167:
168: }
169: ?>