XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AvatarListAction.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_MODULE_PATH . '/user/class/AbstractListAction.class.php';
13require_once XOOPS_MODULE_PATH . '/user/admin/forms/AvatarFilterForm.class.php';
14require_once XOOPS_MODULE_PATH . '/user/admin/forms/AvatarListForm.class.php';
15
17{
18
19 public $mAvatarObjects = [];
20 public $mActionForm = null;
21 public $mpageArr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 0];
22
23 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
24 {
25 $this->mActionForm =new User_AvatarListForm();
26 $this->mActionForm->prepare();
27
28 // Since XCL 2.3.x @gigamaster added avatar info
29 $this->mAvatarWidth = $moduleConfig['avatar_width'];
30 $this->mAvatarHeight = $moduleConfig['avatar_height'];
31 $this->mAvatarMaxfilesize = $moduleConfig['avatar_maxsize'];
32 }
33
34
35 public function &_getHandler()
36 {
37 $handler =& xoops_getmodulehandler('avatar');
38 return $handler;
39 }
40
41 public function &_getPageNavi()
42 {
43 $navi =new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
44
45 $root =& XCube_Root::getSingleton();
46 $perpage = $root->mContext->mRequest->getRequest($navi->mPrefix.'perpage');
47
48 if (isset($perpage) && 0 == (int)$perpage) {
49 $navi->setPerpage(0);
50 }
51 return $navi;
52 }
53
54 public function &_getFilterForm()
55 {
56 $filter =new User_AvatarFilterForm($this->_getPageNavi(), $this->_getHandler());
57 return $filter;
58 }
59
60 public function _getBaseUrl()
61 {
62 return './index.php?action=AvatarList';
63 }
64
65 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
66 {
67 $render->setTemplateName('avatar_list.html');
68 $render->setAttribute('objects', $this->mObjects);
69 $render->setAttribute('pageNavi', $this->mFilter->mNavi);
70 $render->setAttribute('actionForm', $this->mActionForm);
71 $render->setAttribute('pageArr', $this->mpageArr);
72 $render->setAttribute('filterForm', $this->mFilter);
73
74 $avt_handler =& $this->_getHandler();
75 $savatar_total = $avt_handler->getCount(new Criteria('avatar_type', 'S'));
76 $cavatar_total = $avt_handler->getCount(new Criteria('avatar_type', 'C'));
77 $render->setAttribute('savatarTotal', $savatar_total);
78 $render->setAttribute('cavatarTotal', $cavatar_total);
79 $render->setAttribute('avatarTotal', $savatar_total+$cavatar_total);
80
81 // Since XCL 2.3.x @gigamaster added avatar info
82 $render->setAttribute('avatar_width', $this->mAvatarWidth);
83 $render->setAttribute('avatar_height', $this->mAvatarHeight);
84 $render->setAttribute('avatar_maxsize', $this->mAvatarMaxfilesize);
85 }
86
87 public function execute(&$controller, &$xoopsUser)
88 {
89 $form_cancel = $controller->mRoot->mContext->mRequest->getRequest('_form_control_cancel');
90 if (null != $form_cancel) {
91 return USER_FRAME_VIEW_CANCEL;
92 }
93
94 $this->mActionForm->fetch();
95 $this->mActionForm->validate();
96
97 if ($this->mActionForm->hasError()) {
98 return $this->_processConfirm($controller, $xoopsUser);
99 } else {
100 return $this->_processSave($controller, $xoopsUser);
101 }
102 }
103
104 public function _processConfirm(&$controller, &$xoopsUser)
105 {
106 $nameArr = $this->mActionForm->get('name');
107 $avatarHandler =& xoops_getmodulehandler('avatar');
108 //
109 // Do mapping.
110 //
111 foreach (array_keys($nameArr) as $aid) {
112 $avatar =& $avatarHandler->get($aid);
113 if (is_object($avatar)) {
114 $this->mAvatarObjects[$aid] =& $avatar;
115 }
116 unset($avatar);
117 }
118
119 return USER_FRAME_VIEW_INPUT;
120 }
121
122 public function _processSave(&$controller, &$xoopsUser)
123 {
124 $nameArr = $this->mActionForm->get('name');
125 $avatarHandler =& xoops_getmodulehandler('avatar');
126
127 foreach (array_keys($nameArr) as $aid) {
128 $avatar =& $avatarHandler->get($aid);
129 if (is_object($avatar)) {
130 $olddata['name'] = $avatar->get('avatar_name');
131 $olddata['display'] = $avatar->get('avatar_display');
132 $olddata['weight'] = $avatar->get('avatar_weight');
133 $newdata['name'] = $this->mActionForm->get('name', $aid);
134 $newdata['display'] = $this->mActionForm->get('display', $aid);
135 $newdata['weight'] = $this->mActionForm->get('weight', $aid);
136 if (count(array_diff_assoc($olddata, $newdata)) > 0) {
137 $avatar->set('avatar_name', $this->mActionForm->get('name', $aid));
138 $avatar->set('avatar_display', $this->mActionForm->get('display', $aid));
139 $avatar->set('avatar_weight', $this->mActionForm->get('weight', $aid));
140 if (!$avatarHandler->insert($avatar)) {
141 return USER_FRAME_VIEW_ERROR;
142 }
143 }//count if
144 }//object if
145 }//foreach
146
147 $linkHandler =& xoops_getmodulehandler('avatar_user_link');
148
149 foreach (array_keys($nameArr) as $aid) {
150 if (1 == $this->mActionForm->get('delete', $aid)) {
151 $avatar =& $avatarHandler->get($aid);
152 if (is_object($avatar)) {
153 $criteria =new Criteria('avatar_id', $aid);
154 $linkArr =& $linkHandler->getObjects($criteria);
155
156 if ($avatarHandler->delete($avatar)) {
157 if ((is_countable($linkArr) ? count($linkArr) : 0) > 0) {
158 $userHandler =& xoops_gethandler('user');
159 foreach ($linkArr as $link) {
160 $user =& $userHandler->get($link->get('user_id'));
161 if (is_object($user)) {
162 $user->set('user_avatar', 'blank.gif');
163 $userHandler->insert($user);
164 }
165 unset($user);
166 }
167 }
168 } else {
169 return USER_FRAME_VIEW_ERROR;
170 }
171 }
172 }
173 }
174 return USER_FRAME_VIEW_SUCCESS;
175 }
176
183 public function executeViewInput(&$controller, &$xoopsUser, &$render)
184 {
185 $render->setTemplateName('avatar_list_confirm.html');
186 $render->setAttribute('avatarObjects', $this->mAvatarObjects);
187 $render->setAttribute('actionForm', $this->mActionForm);
188
189 //
190 // To support a template designer, this send the list of mid that
191 // actionForm kept.
192 //
193 $t_arr = $this->mActionForm->get('name');
194 $render->setAttribute('aids', array_keys($t_arr));
195 }
196
197
198 // @todo @gigamaster Check change $render to $renderer
199 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
200 {
201 $controller->executeForward('./index.php?action=AvatarList');
202 }
203
204 public function executeViewError(&$controller, &$xoopsUser, &$renderer)
205 {
206 $controller->executeRedirect('./index.php?action=AvatarList', 1, _MD_USER_ERROR_DBUPDATE_FAILED);
207 }
208
209 public function executeViewCancel(&$controller, &$xoopsUser, &$renderer)
210 {
211 $controller->executeForward('./index.php?action=AvatarList');
212 }
213}
executeViewInput(&$controller, &$xoopsUser, &$render)