XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
AvatarEditAction.class.php
1<?php
7
8if (!defined('XOOPS_ROOT_PATH')) {
9 exit();
10}
11
12require_once XOOPS_MODULE_PATH . '/user/class/AbstractEditAction.class.php';
13require_once XOOPS_MODULE_PATH . '/user/admin/forms/AvatarAdminEditForm.class.php';
14
16{
17 public function _getId()
18 {
19 return xoops_getrequest('avatar_id');
20 }
21
22 public function &_getHandler()
23 {
24 $handler =& xoops_getmodulehandler('avatar');
25 return $handler;
26 }
27
28 public function _setupActionForm()
29 {
30 $this->mActionForm =new User_AvatarAdminEditForm();
31 $this->mActionForm->prepare();
32 }
33
34 public function _doExecute()
35 {
36 if (null != $this->mActionForm->mFormFile) {
37 if (!$this->mActionForm->mFormFile->saveAs(XOOPS_UPLOAD_PATH)) {
38 return false;
39 }
40
41 if (null != $this->mActionForm->mOldFileName && 'blank.gif' != $this->mActionForm->mOldFileName) {
42 @unlink(XOOPS_UPLOAD_PATH . '/' . $this->mActionForm->mOldFileName);
43
44 //
45 // Change user_avatar of all users who are setting this avatar.
46 //
47 if (!$this->mObject->isNew()) {
48 $linkHandler =& xoops_getmodulehandler('avatar_user_link');
49 $criteria =new Criteria('avatar_id', $this->mObject->get('avatar_id'));
50 $linkArr =& $linkHandler->getObjects($criteria);
51
52 $userHandler =& xoops_gethandler('user');
53 foreach ($linkArr as $link) {
54 $user =& $userHandler->get($link->get('user_id'));
55
56 if (is_object($user)) {
57 $user->set('user_avatar', $this->mObject->get('avatar_file'));
58 $userHandler->insert($user);
59 }
60 unset($user);
61 }
62 }
63 }
64 }
65
66 return parent::_doExecute();
67 }
68
69 public function executeViewInput(&$controller, &$xoopsUser, &$render)
70 {
71 $render->setTemplateName('avatar_edit.html');
72 $render->setAttribute('actionForm', $this->mActionForm);
73 $render->setAttribute('object', $this->mObject);
74 }
75
76 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
77 {
78 $controller->executeForward('./index.php?action=AvatarList');
79 }
80
81 public function executeViewError(&$controller, &$xoopsUser, &$render)
82 {
83 $controller->executeRedirect('./index.php?action=AvatarList', 1, _MD_USER_ERROR_DBUPDATE_FAILED);
84 }
85
86 public function executeViewCancel(&$controller, &$xoopsUser, &$render)
87 {
88 $controller->executeForward('./index.php?action=AvatarList');
89 }
90}