XCL Web Application Platform 2.5.0
The XoopsCube Legacy Project
Loading...
Searching...
No Matches
users.php
1<?php
2
3if (!defined('XOOPS_ROOT_PATH')) {
4 exit();
5}
6
7class UserUsersObject extends XoopsSimpleObject
8{
9 //
10 // TODO naming rule
11 //
12 public $Groups = [];
13 public $_mGroupsLoadedFlag = false;
14
15 public $_mRankLoadedFlag = false;
16 public $mRank;
17
18 public function UserUsersObject()
19 {
20 self::__construct();
21 }
22
23 public function __construct()
24 {
25 static $initVars;
26 if (isset($initVars)) {
27 $this->mVars = $initVars;
28 return;
29 }
30 $this->initVar('uid', XOBJ_DTYPE_INT, 0, true);
31 $this->initVar('name', XOBJ_DTYPE_STRING, '', false, 60);
32 $this->initVar('uname', XOBJ_DTYPE_STRING, '', true, 25);
33 $this->initVar('email', XOBJ_DTYPE_STRING, '', true, 60);
34 $this->initVar('url', XOBJ_DTYPE_STRING, '', false, 100);
35 $this->initVar('user_avatar', XOBJ_DTYPE_STRING, 'blank.gif', false, 30);
36 $this->initVar('user_regdate', XOBJ_DTYPE_INT, time(), true);
37 $this->initVar('user_icq', XOBJ_DTYPE_STRING, '', false, 15);
38 $this->initVar('user_from', XOBJ_DTYPE_STRING, '', false, 100);
39 $this->initVar('user_sig', XOBJ_DTYPE_TEXT, '', false);
40 $this->initVar('user_viewemail', XOBJ_DTYPE_BOOL, '0', false);
41 $this->initVar('actkey', XOBJ_DTYPE_STRING, '', false, 8);
42 $this->initVar('user_aim', XOBJ_DTYPE_STRING, '', false, 18);
43 $this->initVar('user_yim', XOBJ_DTYPE_STRING, '', false, 25);
44 $this->initVar('user_msnm', XOBJ_DTYPE_STRING, '', false, 100);
45 $this->initVar('pass', XOBJ_DTYPE_STRING, '', false, 191);
46 $this->initVar('posts', XOBJ_DTYPE_INT, '0', false);
47 $this->initVar('attachsig', XOBJ_DTYPE_BOOL, '0', false);
48 $this->initVar('rank', XOBJ_DTYPE_INT, '0', false);
49 $this->initVar('level', XOBJ_DTYPE_INT, '1', false);
50 $this->initVar('theme', XOBJ_DTYPE_STRING, '', false, 100);
51 $this->initVar('timezone_offset', XOBJ_DTYPE_FLOAT, '0.0', false);
52 $this->initVar('last_login', XOBJ_DTYPE_INT, '0', false);
53 $this->initVar('umode', XOBJ_DTYPE_STRING, '', false, 10);
54 $this->initVar('uorder', XOBJ_DTYPE_BOOL, '0', false);
55 $this->initVar('notify_method', XOBJ_DTYPE_INT, '1', false);
56 $this->initVar('notify_mode', XOBJ_DTYPE_INT, '0', false);
57 $this->initVar('user_occ', XOBJ_DTYPE_STRING, '', false, 100);
58 $this->initVar('bio', XOBJ_DTYPE_TEXT, '', false);
59 $this->initVar('user_intrest', XOBJ_DTYPE_STRING, '', false, 150);
60 $this->initVar('user_mailok', XOBJ_DTYPE_BOOL, '1', false);
61 $initVars = $this->mVars;
62 }
63
64 public function getGroups()
65 {
66 return $this->Groups;
67 }
68
69 public function getNumGroups()
70 {
71 $this->_loadGroups();
72 return count($this->Groups);
73 }
74
75 //
76 // TODO naming rule
77 //
78 public function _loadGroups()
79 {
80 if (!$this->_mGroupsLoadedFlag) {
81 $handler = &xoops_getmodulehandler('groups_users_link', 'user');
82 $links = &$handler->getObjects(new Criteria('uid', $this->get('uid')));
83 foreach ($links as $link) {
84 $this->Groups[] = $link->get('groupid');
85 }
86 }
87
88 $this->_mGroupsLoadedFlag = true;
89 }
90
91
92 public function _loadRank()
93 {
94 if (!$this->_mRankLoadedFlag) {
95 $t_rank = xoops_getrank($this->get('rank'), $this->get('posts'));
96 $rank_id = $t_rank['id'];
97
98 $handler = &xoops_getmodulehandler('ranks');
99 $this->mRank = &$handler->get($rank_id);
100
101 $this->_mRankLoadedFlag = true;
102 }
103 }
104
105 public function getRank()
106 {
107 if (!$this->_mRankLoadedFlag) {
108 $this->_loadRank();
109 }
110
111 return $this->mRank;
112 }
113}
114
116{
117 public $mTable = 'users';
118 public $mPrimary = 'uid';
119 public $mClass = 'UserUsersObject';
120
121 public function &get($id)
122 {
123 $obj = &parent::get($id);
124
125 if (is_object($obj)) {
126 $obj->_loadGroups();
127 }
128
129 return $obj;
130 }
131
132 public function &getObjects($criteria = null, $limit = null, $start = null, $id_as_key = false)
133 {
134 $objects = &parent::getObjects($criteria, $limit, $start, $id_as_key);
135
136 if (is_countable($objects) ? count($objects) : 0) {
137 foreach (array_keys($objects) as $key) {
138 $objects[$key]->_loadGroups();
139 }
140 }
141
142 return $objects;
143 }
144
155 public function &getUids($criteria = null, $limit = null, $start = null, $id_as_key = false)
156 {
157 $ret = [];
158
159 $sql = 'SELECT uid FROM ' . $this->mTable;
160
161 $limit = 0;
162 $start = 0;
163
164 if (null !== $criteria && $criteria instanceof \CriteriaElement) {
165 $where = $this->_makeCriteria4sql($criteria);
166
167 if (trim($where)) {
168 $sql .= ' WHERE ' . $where;
169 }
170
171 $sorts = [];
172 foreach ($criteria->getSorts() as $sort) {
173 $sorts[] = $sort['sort'] . ' ' . $sort['order'];
174 }
175 if ('' != $criteria->getSort()) {
176 $sql .= ' ORDER BY ' . implode(',', $sorts);
177 }
178
179 $limit = $criteria->getLimit();
180 $start = $criteria->getStart();
181 }
182
183 $result = $this->db->query($sql, $limit, $start);
184 if (!$result) {
185 return $ret;
186 }
187
188 while ($row = $this->db->fetchArray($result)) {
189 $ret[] = $row['uid'];
190 }
191
192 return $ret;
193 }
194
195 public function insert(&$user, $force = false)
196 {
197 // check pass column length of users table
198 if (!defined('XCUBE_CORE_USER_PASS_LEN_FIXED') && is_callable('User_Utils::checkUsersPassColumnLength')) {
200 }
201
202 if (parent::insert($user, $force)) {
203 $flag = true;
204
205 $user->_loadGroups();
206
207 $handler = &xoops_getmodulehandler('groups_users_link', 'user');
208 $oldLinkArr = &$handler->getObjects(new Criteria('uid', $user->get('uid')), $force);
209
210 //
211 // Delete
212 //
213 $oldGroupidArr = [];
214 foreach (array_keys($oldLinkArr) as $key) {
215 $oldGroupidArr[] = $oldLinkArr[$key]->get('groupid');
216 if (!in_array($oldLinkArr[$key]->get('groupid'), $user->Groups)) {
217 $handler->delete($oldLinkArr[$key], $force);
218 }
219 }
220
221 foreach ($user->Groups as $gid) {
222 if (!in_array($gid, $oldGroupidArr)) {
223 $link = &$handler->create();
224
225 $link->set('groupid', $gid);
226 $link->set('uid', $user->get('uid'));
227
228 $flag = &$handler->insert($link, $force);
229
230 unset($link);
231 }
232 }
233
234 return $flag;
235 }
236
237 return false;
238 }
239}
static checkUsersPassColumnLength()
& getObjects($criteria=null, $limit=null, $start=null, $id_as_key=false)
Definition users.php:132
& getUids($criteria=null, $limit=null, $start=null, $id_as_key=false)
Definition users.php:155