XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
BlockListAction.class.php
1<?php
11
12if (!defined('XOOPS_ROOT_PATH')) {
13 exit();
14}
15
16require_once XOOPS_MODULE_PATH . '/legacy/class/AbstractListAction.class.php';
17require_once XOOPS_MODULE_PATH . '/legacy/admin/forms/BlockFilterForm.class.php';
18require_once XOOPS_MODULE_PATH . '/legacy/admin/forms/BlockListForm.class.php';
19
21{
22 public $mBlockObjects = [];
23 public $mActionForm = null;
24 public $mpageArr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 0];
25
26 public function prepare(&$controller, &$xoopsUser)
27 {
28 $this->mActionForm =new Legacy_BlockListForm();
29 $this->mActionForm->prepare();
30 }
31
32 public function &_getHandler()
33 {
34 $handler =& xoops_getmodulehandler('newblocks');
35 return $handler;
36 }
37
38 public function &_getFilterForm()
39 {
40 $filter =new Legacy_BlockFilterForm($this->_getPageNavi(), $this->_getHandler());
41 return $filter;
42 }
43
44 public function &_getPageNavi()
45 {
46 $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
47
48 $root =& XCube_Root::getSingleton();
49 $perpage = $root->mContext->mRequest->getRequest($navi->mPrefix.'perpage');
50
51 if (isset($perpage) && 0 == (int)$perpage) {
52 $navi->setPerpage(0);
53 }
54
55 // naao added selectedMid filter
56 $selectedMid = (int)$root->mContext->mRequest->getRequest('selmid') ;
57 if (0 !== $selectedMid) {
58 $navi->addExtra('selmid', $selectedMid);
59 }
60 $selectedGid = (int)$root->mContext->mRequest->getRequest('selgid') ;
61 if (0 !== $selectedGid) {
62 $navi->addExtra('selgid', $selectedGid);
63 }
64 return $navi;
65 }
66
67 public function _getBaseUrl()
68 {
69 return './index.php?action=BlockList';
70 }
71
72 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
73 {
74 $render->setTemplateName('block_list.html');
75 foreach (array_keys($this->mObjects) as $key) {
76 $this->mObjects[$key]->loadModule();
77 $this->mObjects[$key]->loadColumn();
78 $this->mObjects[$key]->loadCachetime();
79 }
80
81 $render->setAttribute('objects', $this->mObjects);
82 $render->setAttribute('pageNavi', $this->mFilter->mNavi);
83
84 $render->setAttribute('modules', $controller->mActiveModules);
85 $render->setAttribute('filterForm', $this->mFilter);
86 $render->setAttribute('pageArr', $this->mpageArr);
87
88 // added query for view module pages
89 $root =& XCube_Root::getSingleton();
90 $render->setAttribute('selectedMid', $root->mContext->mRequest->getRequest('selmid'));
91 $handler =& xoops_gethandler('module');
92 $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
93 $criteria->add(new Criteria('isactive', 1));
94 $criteria->add(new Criteria('weight', 0, '>'));
95 $view_modules = $handler->getObjects($criteria);
96 $render->setAttribute('view_modules', $view_modules);
97
98 // added query for groups
99 $handler =& xoops_gethandler('group');
100 $groupArr =& $handler->getObjects();
101 $render->setAttribute('groupArr', $groupArr);
102 $render->setAttribute('selectedGid', $root->mContext->mRequest->getRequest('selgid'));
103
104 //
105 // Load cache-time pattern objects and set.
106 //
107 $handler =& xoops_gethandler('cachetime');
108 $cachetimeArr =& $handler->getObjects();
109 $render->setAttribute('cachetimeArr', $cachetimeArr);
110 $render->setAttribute('actionForm', $this->mActionForm);
111 //
112 $handler =& xoops_getmodulehandler('columnside');
113 $columnSideArr =& $handler->getObjects();
114 $render->setAttribute('columnSideArr', $columnSideArr);
115
116 $block_handler =& $this->_getHandler();
117 $block_total = $block_handler->getCount();
118 $inactive_block_total = $block_handler->getCount(new Criteria('isactive', 0));
119 $active_block_total = $block_total-$inactive_block_total;
120 $render->setAttribute('BlockTotal', $block_total);
121 $render->setAttribute('ActiveBlockTotal', $active_block_total);
122 $render->setAttribute('InactiveBlockTotal', $inactive_block_total);
123
124 $active_installed_criteria = new CriteriaCompo(new Criteria('visible', 1));
125 $active_installed_criteria->add(new Criteria('isactive', 1));
126 $active_installed_block_total = $block_handler->getCount($active_installed_criteria);
127 $render->setAttribute('ActiveInstalledBlockTotal', $active_installed_block_total);
128 $render->setAttribute('ActiveUninstalledBlockTotal', $active_block_total - $active_installed_block_total);
129
130 $inactive_installed_criteria = new CriteriaCompo(new Criteria('visible', 1));
131 $inactive_installed_criteria->add(new Criteria('isactive', 0));
132 $inactive_installed_block_total = $block_handler->getCount($inactive_installed_criteria);
133 $render->setAttribute('InactiveInstalledBlockTotal', $inactive_installed_block_total);
134 $render->setAttribute('InactiveUninstalledBlockTotal', $inactive_block_total - $inactive_installed_block_total);
135 }
136
137
138 public function execute(&$controller, &$xoopsUser)
139 {
140 $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
141 if (null !== $form_cancel) {
142 return LEGACY_FRAME_VIEW_CANCEL;
143 }
144
145 $this->mActionForm->fetch();
146 $this->mActionForm->validate();
147
148 if ($this->mActionForm->hasError()) {
149 return $this->_processConfirm($controller, $xoopsUser);
150 }
151
152 return $this->_processSave($controller, $xoopsUser);
153 }
154
155 public function _processConfirm(&$controller, &$xoopsUser)
156 {
157 $titleArr = $this->mActionForm->get('title');
158 $blockHandler =& xoops_getmodulehandler('newblocks');
159 //
160 // Do mapping.
161 //
162 foreach (array_keys($titleArr) as $bid) {
163 $block =& $blockHandler->get($bid);
164 if (is_object($block) && 1 == $block->get('isactive') && 1 == $block->get('visible')) {
165 $this->mBlockObjects[$bid] =& $block;
166 $this->mBlockObjects[$bid]->loadColumn();
167 $this->mBlockObjects[$bid]->loadCachetime();
168 }
169 unset($block);
170 }
171
172 return LEGACY_FRAME_VIEW_INPUT;
173 }
174
175 public function _processSave(&$controller, &$xoopsUser)
176 {
177 $titleArr = $this->mActionForm->get('title');
178 $blockHandler =& xoops_getmodulehandler('newblocks');
179
180 foreach (array_keys($titleArr) as $bid) {
181 $block =& $blockHandler->get($bid);
182 if (is_object($block) && 1 == $block->get('isactive') && 1 == $block->get('visible')) {
183 $olddata['title'] = $block->get('title');
184 $olddata['weight'] = $block->get('weight');
185 $olddata['side'] = $block->get('side');
186 $olddata['bcachetime'] = $block->get('bcachetime');
187 $newdata['title'] = $this->mActionForm->get('title', $bid);
188 $newdata['weight'] = $this->mActionForm->get('weight', $bid);
189 $newdata['side'] = $this->mActionForm->get('side', $bid);
190 $newdata['bcachetime'] = $this->mActionForm->get('bcachetime', $bid);
191 if (count(array_diff_assoc($olddata, $newdata)) > 0) {
192 $block->set('title', $this->mActionForm->get('title', $bid));
193 $block->set('weight', $this->mActionForm->get('weight', $bid));
194 $block->set('side', $this->mActionForm->get('side', $bid));
195 $block->set('bcachetime', $this->mActionForm->get('bcachetime', $bid));
196 $block->set('last_modified', time());
197 if (!$blockHandler->insert($block)) {
198 return LEGACY_FRAME_VIEW_ERROR;
199 }
200 }//count if
201 }//object if
202 }
203
204 //uninstall process
205 foreach (array_keys($titleArr) as $bid) {
206 if (1 == $this->mActionForm->get('uninstall', $bid)) {
207 $block =& $blockHandler->get($bid);
208 if (is_object($block) && 1 == $block->get('isactive') && 1 == $block->get('visible')) {
209 $block->set('visible', 0);
210 if (!$blockHandler->insert($block)) {
211 return LEGACY_FRAME_VIEW_ERROR;
212 }
213 }//object if
214 }//if
215 }
216
217 return LEGACY_FRAME_VIEW_SUCCESS;
218 }
219
220
221 public function executeViewInput(&$controller, &$xoopsUser, &$render)
222 {
223 $render->setTemplateName('block_list_confirm.html');
224 $render->setAttribute('blockObjects', $this->mBlockObjects);
225 $render->setAttribute('actionForm', $this->mActionForm);
226
227 $t_arr = $this->mActionForm->get('title');
228 $render->setAttribute('bids', array_keys($t_arr));
229
230 $handler =& xoops_getmodulehandler('columnside');
231 $columnSideArr =& $handler->getObjects($criteria = null, $id_as_key = true);
232 $render->setAttribute('columnSideArr', $columnSideArr);
233 $handler =& xoops_gethandler('cachetime');
234 $cachetimeArr =& $handler->getObjects($criteria = null, $id_as_key = true);
235 $render->setAttribute('cachetimeArr', $cachetimeArr);
236 }
237
238 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
239 {
240 $controller->executeForward('./index.php?action=BlockList');
241 }
242
243 public function executeViewError(&$controller, &$xoopsUser, &$render)
244 {
245 $controller->executeRedirect('./index.php?action=BlockInstallList', 1, _MD_LEGACY_ERROR_DBUPDATE_FAILED);
246 }
247
248 public function executeViewCancel(&$controller, &$xoopsUser, &$renderer)
249 {
250 $controller->executeForward('./index.php?action=BlockList');
251 }
252}