XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
RanksListAction.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7require_once XOOPS_MODULE_PATH . '/user/class/AbstractListAction.class.php';
8require_once XOOPS_MODULE_PATH . '/user/admin/forms/RanksFilterForm.class.php';
9require_once XOOPS_MODULE_PATH . '/user/admin/forms/RanksListForm.class.php';
10
12{
13 public $mRanksObjects = [];
14 public $mActionForm = null;
15 public $mpageArr = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90, 100, 0];
16
17 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
18 {
19 $this->mActionForm =new User_RanksListForm();
20 $this->mActionForm->prepare();
21 }
22
23 public function &_getHandler()
24 {
25 $handler =& xoops_getmodulehandler('ranks');
26 return $handler;
27 }
28
29 public function &_getPageNavi()
30 {
31 $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
32
33 $root =& XCube_Root::getSingleton();
34 $perpage = $root->mContext->mRequest->getRequest($navi->mPrefix.'perpage');
35
36 if (isset($perpage) && 0 == (int)$perpage) {
37 $navi->setPerpage(0);
38 }
39 return $navi;
40 }
41
42 public function &_getFilterForm()
43 {
44 $filter =new User_RanksFilterForm($this->_getPageNavi(), $this->_getHandler());
45 return $filter;
46 }
47
48 public function _getBaseUrl()
49 {
50 return './index.php?action=RanksList';
51 }
52
53 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
54 {
55 $render->setTemplateName('ranks_list.html');
56 $render->setAttribute('objects', $this->mObjects);
57 $render->setAttribute('pageNavi', $this->mFilter->mNavi);
58 $render->setAttribute('actionForm', $this->mActionForm);
59 $render->setAttribute('pageArr', $this->mpageArr);
60 $render->setAttribute('filterForm', $this->mFilter);
61 $rank_handler =& $this->_getHandler();
62 $rank_total = $rank_handler->getCount();
63 $rank_s_total = $rank_handler->getCount(new Criteria('rank_special', 1));
64 $render->setAttribute('rankTotal_S', $rank_s_total);
65 $render->setAttribute('rankTotal', $rank_total);
66 }
67
68 public function execute(&$controller, &$xoopsUser)
69 {
70 $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
71 if (null != $form_cancel) {
72 return USER_FRAME_VIEW_CANCEL;
73 }
74
75 $this->mActionForm->fetch();
76 $this->mActionForm->validate();
77
78 if ($this->mActionForm->hasError()) {
79 return $this->_processConfirm($controller, $xoopsUser);
80 } else {
81 return $this->_processSave($controller, $xoopsUser);
82 }
83 }
84
85 public function _processConfirm(&$controller, &$xoopsUser)
86 {
87 $titleArr = $this->mActionForm->get('title');
88 $ranksHandler =& xoops_getmodulehandler('ranks');
89 //
90 // Do mapping.
91 //
92 foreach (array_keys($titleArr) as $rid) {
93 $ranks =& $ranksHandler->get($rid);
94 if (is_object($ranks)) {
95 $this->mRanksObjects[$rid] =& $ranks;
96 }
97 unset($ranks);
98 }
99
100 return USER_FRAME_VIEW_INPUT;
101 }
102
103 public function _processSave(&$controller, &$xoopsUser)
104 {
105 $titleArr = $this->mActionForm->get('title');
106 $ranksHandler =& xoops_getmodulehandler('ranks');
107
108 foreach (array_keys($titleArr) as $rid) {
109 $ranks =& $ranksHandler->get($rid);
110 if (is_object($ranks)) {
111 $olddata['title'] = $ranks->get('rank_title');
112 $olddata['min'] = $ranks->get('rank_min');
113 $olddata['max'] = $ranks->get('rank_max');
114 $newdata['title'] = $this->mActionForm->get('title', $rid);
115 $newdata['min'] = $this->mActionForm->get('min', $rid);
116 $newdata['max'] = $this->mActionForm->get('max', $rid);
117 if (count(array_diff_assoc($olddata, $newdata)) > 0) {
118 $ranks->set('rank_title', $this->mActionForm->get('title', $rid));
119 $ranks->set('rank_min', $this->mActionForm->get('min', $rid));
120 $ranks->set('rank_max', $this->mActionForm->get('max', $rid));
121 if (!$ranksHandler->insert($ranks)) {
122 return USER_FRAME_VIEW_ERROR;
123 }
124 }//count if
125 }//object if
126 }//foreach
127
128 foreach (array_keys($titleArr) as $rid) {
129 if (1 == $this->mActionForm->get('delete', $rid)) {
130 $ranks =& $ranksHandler->get($rid);
131 if (is_object($ranks)) {
132 if (!$ranksHandler->delete($ranks)) {
133 return USER_FRAME_VIEW_ERROR;
134 }
135 }
136 }
137 }
138 return USER_FRAME_VIEW_SUCCESS;
139 }
140
147 public function executeViewInput(&$controller, &$xoopsUser, &$render)
148 {
149 $render->setTemplateName('ranks_list_confirm.html');
150 $render->setAttribute('ranksObjects', $this->mRanksObjects);
151 $render->setAttribute('actionForm', $this->mActionForm);
152
153 //
154 // To support a template writer, this send the list of mid that
155 // actionForm kept.
156 //
157 $t_arr = $this->mActionForm->get('title');
158 $render->setAttribute('rids', array_keys($t_arr));
159 }
160
161// @todo @gigamaster Check change $render to $renderer
162 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
163 {
164 $controller->executeForward('./index.php?action=RanksList');
165 }
166
167 public function executeViewError(&$controller, &$xoopsUser, &$renderer)
168 {
169 $controller->executeRedirect('./index.php?action=RanksList', 1, _MD_USER_ERROR_DBUPDATE_FAILED);
170 }
171
172 public function executeViewCancel(&$controller, &$xoopsUser, &$renderer)
173 {
174 $controller->executeForward('./index.php?action=RanksList');
175 }
176}
executeViewInput(&$controller, &$xoopsUser, &$render)