XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
UserViewAction.class.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7require_once XOOPS_MODULE_PATH . '/user/class/AbstractViewAction.class.php';
8require_once XOOPS_MODULE_PATH . '/user/admin/forms/UserRecountForm.class.php';
9
11{
12 public $mActionForm = null;
13
17 public $mGetUserPosts = null;
18
19 public function __construct()
20 {
21 parent::__construct();
22 $this->mGetUserPosts =new XCube_Delegate();
23 $this->mGetUserPosts->register('User_UserViewAction.GetUserPosts');
24 }
25
26 public function prepare(&$controller, &$xoopsUser, $moduleConfig)
27 {
28 parent::prepare($controller, $xoopsUser, $moduleConfig);
29 $this->mActionForm =new User_RecountForm();
30 $this->mActionForm->prepare();
31 }
32
33 public function _getId()
34 {
35 return xoops_getrequest('uid');
36 }
37
38 public function &_getHandler()
39 {
40 $handler =& xoops_getmodulehandler('users');
41 return $handler;
42 }
43
44 public function getDefaultView(&$controller, &$xoopsUser)
45 {
46 if (is_object($this->mObject)) {
47 $this->mActionForm->load($this->mObject);
48 }
49
50 $ret = parent::getDefaultView($controller, $xoopsUser);
51
52 //
53 // Because this class implemented 'execute()', convet the status here.
54 //
55 if (USER_FRAME_VIEW_SUCCESS == $ret) {
56 return USER_FRAME_VIEW_INDEX;
57 } else {
58 return $ret;
59 }
60 }
61
62 public function execute(&$controller, &$xoopsUser)
63 {
64 if (null == $this->mObject) {
65 return USER_FRAME_VIEW_ERROR;
66 }
67
68 $this->mActionForm->load($this->mObject);
69
70 $this->mActionForm->fetch();
71 $this->mActionForm->validate();
72
73 if ($this->mActionForm->hasError()) {
74 return $this->getDefaultView($controller, $xoopsUser);
75 }
76
77 //
78 // Do 'recount'
79 //
80 $posts = 0;
81 $this->mGetUserPosts->call(new XCube_Ref($posts), $this->mObject);
82
83 $handler =& xoops_getmodulehandler('users');
84 return $handler->insert($this->mObject) ? USER_FRAME_VIEW_SUCCESS
85 : USER_FRAME_VIEW_ERROR;
86 }
87
88 public function executeViewIndex(&$controller, &$xoopsUser, &$render)
89 {
90 $render->setTemplateName('user_view.html');
91 $render->setAttribute('actionForm', $this->mActionForm);
92 $render->setAttribute('object', $this->mObject);
93
94 $render->setAttribute('rank', $this->mObject->getRank());
95
96 $handler =& xoops_gethandler('timezone');
97 $timezone =& $handler->get($this->mObject->get('timezone_offset'));
98 $render->setAttribute('timezone', $timezone);
99
100 //
101 // TODO dirty code... :(
102 //
103 $umodeOptions = ['nest' => _NESTED, 'flat' => _FLAT, 'thread' => _THREADED];
104 $render->setAttribute('umode', $umodeOptions[$this->mObject->get('umode')]);
105
106 $uorderOptions = [0 => _OLDESTFIRST, 1 => _NEWESTFIRST];
107 $render->setAttribute('uorder', $uorderOptions[$this->mObject->get('uorder')]);
108
109 //
110 // Notifications. (TODO Also dirty...)
111 //
112 $controller->mRoot->mLanguageManager->loadPageTypeMessageCatalog('notification');
113 require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
114
115 $methodOptions = [
116 XOOPS_NOTIFICATION_METHOD_DISABLE => _NOT_METHOD_DISABLE,
117 XOOPS_NOTIFICATION_METHOD_PM => _NOT_METHOD_PM,
118 XOOPS_NOTIFICATION_METHOD_EMAIL => _NOT_METHOD_EMAIL
119 ];
120 $render->setAttribute('notify_method', $methodOptions[$this->mObject->get('notify_method')]);
121
122 $modeOptions = [
123 XOOPS_NOTIFICATION_MODE_SENDALWAYS => _NOT_MODE_SENDALWAYS,
124 XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE => _NOT_MODE_SENDONCE,
125 XOOPS_NOTIFICATION_MODE_SENDONCETHENWAIT => _NOT_MODE_SENDONCEPERLOGIN
126 ];
127 $render->setAttribute('notify_mode', $modeOptions[$this->mObject->get('notify_mode')]);
128
129 $definitions = [];
130 $profile = null;
131 XCube_DelegateUtils::call('Legacy_Profile.GetDefinition', new XCube_Ref($definitions), 'view');
132 XCube_DelegateUtils::call('Legacy_Profile.GetProfile', new XCube_Ref($profile), $this->mObject->get('uid'));
133 $render->setAttribute('definitions', $definitions);
134 $render->setAttribute('data', $profile);
135 }
136
137 public function executeViewSuccess(&$controller, &$xoopsUser, &$render)
138 {
139 $controller->executeRedirect('./index.php?action=UserView&uid=' . $this->mObject->get('uid'), 1, _AD_USER_MESSAGE_RECOUNT_SUCCESS);
140 }
141
142 public function executeViewError(&$controller, &$xoopsUser, &$render)
143 {
144 $controller->executeRedirect('./index.php?action=UserList', 1, _AD_USER_ERROR_CONTENT_IS_NOT_FOUND);
145 }
146}
[Final] Used for the simple mechanism for common delegation in XCube.