XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
ModuleListAction.class.php
1<?php
10
11if (!defined('XOOPS_ROOT_PATH')) {
12 exit();
13}
14
15require_once XOOPS_LEGACY_PATH . '/admin/forms/ModuleListFilterForm.class.php';
16require_once XOOPS_LEGACY_PATH . '/admin/forms/ModuleListForm.class.php';
17
18class Legacy_ModuleListAction extends Legacy_Action
19{
20 public $mModuleObjects = [];
21 public $mFilter = null;
22
23 public $mActionForm = null;
24
25 public function prepare(&$controller, &$xoopsUser)
26 {
27 $this->mActionForm =new Legacy_ModuleListForm();
28 $this->mActionForm->prepare();
29 }
30
31
32 public function getDefaultView(&$controller, &$xoopsUser)
33 {
34 $this->mFilter =new Legacy_ModuleListFilterForm();
35 $this->mFilter->fetch();
36
37 $moduleHandler =& xoops_gethandler('module');
38 $this->mModuleObjects =& $moduleHandler->getObjects($this->mFilter->getCriteria());
39
40 return LEGACY_FRAME_VIEW_INDEX;
41 }
42
43 public function execute(&$controller, &$xoopsUser)
44 {
45 $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
46 if (null !== $form_cancel) {
47 return LEGACY_FRAME_VIEW_CANCEL;
48 }
49
50 $this->mActionForm->fetch();
51 $this->mActionForm->validate();
52
53 if ($this->mActionForm->hasError()) {
54 return $this->_processConfirm($controller, $xoopsUser);
55 } else {
56 $result = $this->_processSave($controller, $xoopsUser);
57 if (LEGACY_FRAME_VIEW_SUCCESS === $result) {
58 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleListSave.Success', new XCube_Ref($this->mActionForm));
59 } else {
60 XCube_DelegateUtils::call('Legacy.Admin.Event.ModuleListSave.Fail', new XCube_Ref($this->mActionForm));
61 }
62 return $result;
63 }
64 }
65
66 public function _processConfirm(&$controller, &$xoopsUser)
67 {
68 $moduleHandler =& xoops_gethandler('module');
69 $t_objectArr =& $moduleHandler->getObjects();
70
71 //
72 // Do mapping.
73 //
74 foreach ($t_objectArr as $module) {
75 $this->mModuleObjects[$module->get('mid')] =& $module;
76 unset($module);
77 }
78
79 return LEGACY_FRAME_VIEW_INPUT;
80 }
81
82 public function _processSave(&$controller, &$xoopsUser)
83 {
84 $moduleHandler =& xoops_gethandler('module');
85 $blockHandler =& xoops_gethandler('block');
86 $t_objectArr =& $moduleHandler->getObjects();
87
88 $successFlag = true;
89 foreach ($t_objectArr as $module) {
90 $mid = $module->get('mid');
91 $olddata['name'] = $module->get('name');
92 $olddata['weight'] = $module->get('weight');
93 $olddata['isactive'] = $module->get('isactive');
94 $newdata['name'] = $this->mActionForm->get('name', $mid);
95 $newdata['weight'] = $this->mActionForm->get('weight', $mid);
96 $newdata['isactive'] = $this->mActionForm->get('isactive', $mid);
97 if (count(array_diff_assoc($olddata, $newdata)) > 0) {
98 $module->set('name', $this->mActionForm->get('name', $mid));
99 $module->set('weight', $this->mActionForm->get('weight', $mid));
100 $module->set('isactive', $this->mActionForm->get('isactive', $mid));
101
102 //
103 // Store & Sync isactive of blocks with isactive of the module.
104 //
105 if ($moduleHandler->insert($module)) {
106 $successFlag &= true;
107 $blockHandler->syncIsActive($module->get('mid'), $module->get('isactive'));
108 } else {
109 $successFlag = false;
110 }
111 }
112 }
113
114 return $successFlag ? LEGACY_FRAME_VIEW_SUCCESS : LEGACY_FRAME_VIEW_ERROR;
115 }
116
123 public function executeViewInput(&$controller, &$xoopsUser, &$render)
124 {
125 $render->setTemplateName('module_list_confirm.html');
126 $render->setAttribute('moduleObjects', $this->mModuleObjects);
127 $render->setAttribute('actionForm', $this->mActionForm);
128
129 //
130 // To support a template writer, this sends the list of mid that
131 // actionForm kept.
132 //
133 $t_arr = $this->mActionForm->get('name');
134 $render->setAttribute('mids', array_keys($t_arr));
135 }
136
137 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
138 {
139 $render->setTemplateName('module_list.html');
140 $render->setAttribute('actionForm', $this->mActionForm);
141
142 //
143 // Load info before we assign these to template.
144 //
145 foreach (array_keys($this->mModuleObjects) as $key) {
146 $this->mModuleObjects[$key]->loadInfo($this->mModuleObjects[$key]->get('dirname'));
147 }
148
149 $render->setAttribute('moduleObjects', $this->mModuleObjects);
150
151 $moduleHandler =& xoops_gethandler('module');
152 $module_total = $moduleHandler->getCount();
153 $active_module_total = $moduleHandler->getCount(new Criteria('isactive', 1));
154 $render->setAttribute('ModuleTotal', $module_total);
155 $render->setAttribute('activeModuleTotal', $active_module_total);
156 $render->setAttribute('inactiveModuleTotal', $module_total - $active_module_total);
157 }
158
159 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
160 {
161 $controller->executeForward('./index.php?action=ModuleList');
162 }
163
164 public function executeViewError(&$controller, &$xoopsUser, &$renderer)
165 {
166 $controller->executeRedirect('./index.php?action=ModuleList', 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
167 }
168
169 public function executeViewCancel(&$controller, &$xoopsUser, &$renderer)
170 {
171 $controller->executeForward('./index.php?action=ModuleList');
172 }
173}
executeViewInput(&$controller, &$xoopsUser, &$render)