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