19 public $mAvatarObjects = [];
20 public $mActionForm =
null;
21 public $mpageArr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 0];
23 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
26 $this->mActionForm->prepare();
29 $this->mAvatarWidth = $moduleConfig[
'avatar_width'];
30 $this->mAvatarHeight = $moduleConfig[
'avatar_height'];
31 $this->mAvatarMaxfilesize = $moduleConfig[
'avatar_maxsize'];
35 public function &_getHandler()
37 $handler =& xoops_getmodulehandler(
'avatar');
41 public function &_getPageNavi()
43 $navi =
new XCube_PageNavigator($this->_getBaseUrl(), XCUBE_PAGENAVI_START | XCUBE_PAGENAVI_PERPAGE);
45 $root =& XCube_Root::getSingleton();
46 $perpage = $root->mContext->mRequest->getRequest($navi->mPrefix.
'perpage');
48 if (isset($perpage) && 0 == (
int)$perpage) {
54 public function &_getFilterForm()
60 public function _getBaseUrl()
62 return './index.php?action=AvatarList';
65 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
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);
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);
82 $render->setAttribute(
'avatar_width', $this->mAvatarWidth);
83 $render->setAttribute(
'avatar_height', $this->mAvatarHeight);
84 $render->setAttribute(
'avatar_maxsize', $this->mAvatarMaxfilesize);
87 public function execute(&$controller, &$xoopsUser)
89 $form_cancel = $controller->mRoot->mContext->mRequest->getRequest(
'_form_control_cancel');
90 if (
null != $form_cancel) {
91 return USER_FRAME_VIEW_CANCEL;
94 $this->mActionForm->fetch();
95 $this->mActionForm->validate();
97 if ($this->mActionForm->hasError()) {
98 return $this->_processConfirm($controller, $xoopsUser);
100 return $this->_processSave($controller, $xoopsUser);
104 public function _processConfirm(&$controller, &$xoopsUser)
106 $nameArr = $this->mActionForm->get(
'name');
107 $avatarHandler =& xoops_getmodulehandler(
'avatar');
111 foreach (array_keys($nameArr) as $aid) {
112 $avatar =& $avatarHandler->get($aid);
113 if (is_object($avatar)) {
114 $this->mAvatarObjects[$aid] =& $avatar;
119 return USER_FRAME_VIEW_INPUT;
122 public function _processSave(&$controller, &$xoopsUser)
124 $nameArr = $this->mActionForm->get(
'name');
125 $avatarHandler =& xoops_getmodulehandler(
'avatar');
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;
147 $linkHandler =& xoops_getmodulehandler(
'avatar_user_link');
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);
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);
169 return USER_FRAME_VIEW_ERROR;
174 return USER_FRAME_VIEW_SUCCESS;
185 $render->setTemplateName(
'avatar_list_confirm.html');
186 $render->setAttribute(
'avatarObjects', $this->mAvatarObjects);
187 $render->setAttribute(
'actionForm', $this->mActionForm);
193 $t_arr = $this->mActionForm->get(
'name');
194 $render->setAttribute(
'aids', array_keys($t_arr));
199 public function executeViewSuccess(&$controller, &$xoopsUser, &$renderer)
201 $controller->executeForward(
'./index.php?action=AvatarList');
204 public function executeViewError(&$controller, &$xoopsUser, &$renderer)
206 $controller->executeRedirect(
'./index.php?action=AvatarList', 1, _MD_USER_ERROR_DBUPDATE_FAILED);
209 public function executeViewCancel(&$controller, &$xoopsUser, &$renderer)
211 $controller->executeForward(
'./index.php?action=AvatarList');