root/devel/mod/rpc/lib/class_user.php

Revision 1022, 9.2 kB (checked in by ben, 2 years ago)

All icons are now displayed using the user_icon_html function; all user full names are displayed using the user_name function. This is to allow potential plugins to do things like hide names if required (eg in a school situation), and add bling to the icon.

  • Property svn:eol-style set to native
Line 
1 <?php
2
3     Class User extends ElggObject
4     {
5         // Class variables have public access. With PHP5 and up they can be declared private.
6         
7         var $username;
8         var $email;
9         var $name;
10         var $alias;
11         var $code;
12         var $icon;
13         var $icon_quota;
14         var $file_quota;
15         var $template_id;
16         var $firstname;
17         var $lastname;
18         var $user_type;
19         var $blogs;
20         var $folders;
21         var $type = 'user';
22
23         var $exists;
24         
25         /**
26          *
27          */
28         function User($var)
29         {
30             global $CFG;
31             $this->exists = false;
32
33             // Both username or userid may be passed
34             if (is_numeric($var))
35             {
36                 // Numeric, we probably received a userid
37                 $info = get_record('users','ident',$var);
38             }
39             elseif(is_string($var))
40             {
41                 // String, we probably recieved a username
42                 $info = get_record('users','username',$var);
43             }
44
45             if (!empty($info)) {
46                 $this->exists = true;
47
48                 $this->ident           = $info->ident;
49                 $this->username        = $info->username;
50                 $this->email           = $info->email;
51                 $this->name            = user_name($info->ident);
52                 $this->alias           = $info->alias;
53                 $this->code            = $info->code;
54                 $this->icon_quota      = $info->icon_quota;
55                 $this->file_quota      = $info->file_quota;
56                 $this->user_type       = $info->user_type;
57                 $this->owner           = $info->owner;
58
59                 ereg('^([a-zA-Z]*) (.*)', $this->name, $groups);
60                 $this->firstname       = trim($groups[1]);
61                 $this->lastname        = trim($groups[2]);
62                 
63                 // Load the weblog id's, starting with communities
64
65                 // Need to select two fields to collect instead of just u.ident else
66                 // this very handy datalib function will return false...
67                 $communities = get_records_sql('SELECT DISTINCT u.ident,u.name
68                                                FROM '.$CFG->prefix.'friends f
69                                                JOIN '.$CFG->prefix.'users u
70                                                ON u.ident = f.friend
71                                                WHERE f.owner = ?
72                                                AND u.user_type = ?',array($this->ident,'community'));
73
74                 $this->blogs = array();
75
76                 // Add the own weblog id (is same as user id)
77                 $this->blogs[] = $this->ident;
78
79                 // Add the communities
80                 if ($communities) {
81                     foreach($communities as $community) {
82                         $this->blogs[] = $community->ident;
83                     }
84                 }
85
86                 $this->icon = user_icon_html($info->ident,100,true);
87             }
88         }
89
90         /**
91          *
92          */
93         function exists()
94         {
95             return $this->exists;
96         }
97
98         /**
99          *
100          */
101         function getUserName()
102         {
103             return $this->username;
104         }
105
106         /**
107          *
108          */
109         function getEmail()
110         {
111             return $this->email;
112         }
113
114         /**
115          *
116          */
117         function getName()
118         {
119             return $this->name;
120         }
121
122         /**
123          *
124          */
125         function getAlias()
126         {
127             return $this->alias;
128         }
129
130         /**
131          *
132          */
133         function getCode()
134         {
135             return $this->code;
136         }
137
138         /**
139          *
140          */
141         function getUserIcon()
142         {
143             return $this->icon;
144         }
145
146         /**
147          *
148          */
149         function getIconQuota()
150         {
151             return $this->icon_quota;
152         }
153
154         /**
155          *
156          */
157         function getFileQuota()
158         {
159             return $this->file_quota;
160         }
161
162         /**
163          *
164          */
165         function getTemplateId()
166         {
167             return $this->template_id;
168         }
169
170         /**
171          *
172          */
173         function getUserType()
174         {
175             return $this->user_type;
176         }
177
178         /**
179          *
180          */
181         function getFirstName()
182         {
183             return $this->firstname;
184         }
185
186         /**
187          *
188          */
189         function getLastName()
190         {
191             return $this->lastname;
192         }
193
194         /**
195          *
196          */
197         function getPersonalUrl()
198         {
199             $url = url . $this->username . "/";
200             return $url;
201         }
202
203         /**
204          *
205          */
206         function getBlogs()
207         {
208             return $this->blogs;
209         }
210
211         /**
212          *
213          */
214         function getFolders()
215         {
216             if (isset($this->folders))
217             {
218                 // A bit awkward, but create a list of folder id's. Needed for the xml-rpc
219                 // code to determine a default upload folder
220                 $folders = get_records('file_folders','files_owner',$this->ident);
221
222                 $this->folders = array();
223
224                 // Add the folders
225                 if (is_array($folders)) {
226                     foreach($folders as $folder) {
227                         $this->folders[] = $folder->ident;
228                     }
229                 }
230             }
231
232             return $this->folders;
233         }
234
235         /**
236          * Get a folder id by name
237          *
238          * Utility function. Needed by the xml-rpc code for determining
239          * the default upload folder which will be referenced by name.
240          */
241         function getFolderId($name)
242         {
243             global $CFG;
244             $id = "";
245             if ($folder = get_record_select('file_folders','name = ? AND files_owner = ?',array($name,$this->ident))) {
246                 return $folder->ident;
247             }
248             else
249             {
250                 return $id;
251             }
252         }
253
254         /**
255          *
256          */
257         function getFriends($limit = null)
258         {
259             global $CFG;
260             // Unlimited if not passed or 0/empty
261             if ($limit == null || $limit == 0 || $limit == "")
262             {
263                 $inject_limit = "";
264             }
265             else
266             {
267                 $inject_limit = " limit $limit";
268             }
269             $friends = array();
270
271             if ($result = get_records_sql('SELECT f.friend AS user_id,u.name
272                                           FROM '.$CFG->prefix.'friends f
273                                           JOIN '.$CFG->prefix.'users u
274                                           ON u.ident = f.friend
275                                           WHERE f.owner = ?
276                                           AND u.user_type = ? '.$inject_limit,
277                                           array($this->ident,'person'))) {
278                 foreach ($result as $friend) {
279                     $friends[] = $friend->user_id;
280                 }
281             }
282             
283             return $friends;
284         }
285
286         /**
287          *
288          */
289         function getFriendOf($limit = null)
290         {
291             global $CFG;
292             // Unlimited if not passed or 0/empty
293             if ($limit == null || $limit == 0 || $limit == "")
294             {
295                 $inject_limit = "";
296             }
297             else
298             {
299                 $inject_limit = " limit $limit";
300             }
301
302
303             $friend_of = array();
304
305             if ($result = get_records_sql('SELECT u.ident AS user_id, u.name
306                                           FROM '.$CFG->prefix.'friends f
307                                           LEFT JOIN '.$CFG->prefix.'users u
308                                           ON u.ident = f.owner
309                                           WHERE f.friend = ?
310                                           AND u.user_type = ? '.$inject_limit,
311                                           array($this->ident,'person'))) {
312                 foreach ($result as $named_by) {
313                     $friend_of[] = $named_by->user_id;
314                 }
315             }
316
317             return $friend_of;
318         }
319
320         /**
321          *
322          */
323         function setUserName($val)
324         {
325             $this->username = $val;
326         }
327
328         /**
329          *
330          */
331         function setEmail($val)
332         {
333             $this->email = $val;
334         }
335
336         /**
337          *
338          */
339         function setName($val)
340         {
341             $this->name = $val;
342         }
343
344         /**
345          *
346          */
347         function setAlias($val)
348         {
349             $this->alias = $val;
350         }
351
352         /**
353          *
354          */
355         function setCode($val)
356         {
357             $this->code = $val;
358         }
359
360         /**
361          *
362          */
363         function setIconQuota($val)
364         {
365             $this->icon_quota = $val;
366         }
367
368         /**
369          *
370          */
371         function setFileQuota($val)
372         {
373             $this->file_quota = $val;
374         }
375
376         /**
377          *
378          */
379         function setTemplateId($val)
380         {
381             $this->template_id = $val;
382         }
383     }
384 ?>
385
Note: See TracBrowser for help on using the browser.