9b1d41eada5be5cb8d32acf2dafa1e64810d5a5b
2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class User
extends PlUser
24 private $_profile_fetched = false
;
25 private $_profile = null
;
27 // Additional fields (non core)
28 protected $promo = null
;
30 // Implementation of the login to uid method.
31 protected function getLogin($login)
36 throw new UserNotFoundException();
39 if ($login instanceof User
) {
43 if ($login instanceof Profile
) {
44 $this->_profile
= $login;
45 $this->_profile_fetched
= true
;
46 $res = XDB
::query('SELECT ap.uid
47 FROM account_profiles AS ap
48 WHERE ap.pid = {?} AND FIND_IN_SET(\'owner\', perms)',
50 if ($res->numRows()) {
51 return $res->fetchOneCell();
53 throw new UserNotFoundException();
56 // If $data is an integer, fetches directly the result.
57 if (is_numeric($login)) {
58 $res = XDB
::query('SELECT a.uid
60 WHERE a.uid = {?}', $login);
61 if ($res->numRows()) {
62 return $res->fetchOneCell();
65 throw new UserNotFoundException();
68 // Checks whether $login is a valid hruid or not.
69 $res = XDB
::query('SELECT a.uid
71 WHERE a.hruid = {?}', $login);
72 if ($res->numRows()) {
73 return $res->fetchOneCell();
76 // From now, $login can only by an email alias, or an email redirection.
77 // If it doesn't look like a valid address, appends the plat/al's main domain.
78 $login = trim(strtolower($login));
79 if (strstr($login, '@') === false
) {
80 $login = $login . '@' . $globals->mail
->domain
;
83 // Checks if $login is a valid alias on the main domains.
84 list($mbox, $fqdn) = explode('@', $login);
85 if ($fqdn == $globals->mail
->domain ||
$fqdn == $globals->mail
->domain2
) {
86 $res = XDB
::query('SELECT a.uid
88 INNER JOIN aliases AS al ON (al.uid = a.uid AND al.type IN (\'alias\', \'a_vie\'))
89 WHERE al.alias = {?}', $mbox);
90 if ($res->numRows()) {
91 return $res->fetchOneCell();
94 /** TODO: implements this by inspecting the profile.
95 if (preg_match('/^(.*)\.([0-9]{4})$/u', $mbox, $matches)) {
96 $res = XDB::query('SELECT a.uid
98 INNER JOIN aliases AS al ON (al.id = a.uid AND al.type IN ('alias', 'a_vie'))
99 WHERE al.alias = {?} AND a.promo = {?}', $matches[1], $matches[2]);
100 if ($res->numRows() == 1) {
101 return $res->fetchOneCell();
105 throw new UserNotFoundException();
108 // Looks for $login as an email alias from the dedicated alias domain.
109 if ($fqdn == $globals->mail
->alias_dom ||
$fqdn == $globals->mail
->alias_dom2
) {
110 $res = XDB
::query("SELECT redirect
111 FROM virtual_redirect
112 INNER JOIN virtual USING(vid)
113 WHERE alias = {?}", $mbox . '@' . $globals->mail
->alias_dom
);
114 if ($redir = $res->fetchOneCell()) {
115 // We now have a valid alias, which has to be translated to an hruid.
116 list($alias, $alias_fqdn) = explode('@', $redir);
117 $res = XDB
::query("SELECT a.uid
119 LEFT JOIN aliases AS al ON (al.uid = a.uid AND al.type IN ('alias', 'a_vie'))
120 WHERE al.alias = {?}", $alias);
121 if ($res->numRows()) {
122 return $res->fetchOneCell();
126 throw new UserNotFoundException();
129 // Looks for an account with the given email.
130 $res = XDB
::query('SELECT a.uid
132 WHERE a.email = {?}', $login);
133 if ($res->numRows() == 1) {
134 return $res->fetchOneCell();
137 // Otherwise, we do suppose $login is an email redirection.
138 $res = XDB
::query("SELECT a.uid
140 LEFT JOIN emails AS e ON (e.uid = a.uid)
141 WHERE e.email = {?}", $login);
142 if ($res->numRows() == 1) {
143 return $res->fetchOneCell();
146 throw new UserNotFoundException($res->fetchColumn(1));
149 protected static function loadMainFieldsFromUIDs(array $uids, $respect_order = true
)
154 if ($globals->asso('id')) {
155 $joins .= XDB
::format("LEFT JOIN group_members AS gpm ON (gpm.uid = a.uid AND gpm.asso_id = {?})\n", $globals->asso('id'));
156 $fields[] = 'gpm.perms AS group_perms';
157 $fields[] = 'gpm.comm AS group_comm';
159 if (count($fields) > 0) {
160 $fields = ', ' . implode(', ', $fields);
165 if ($respect_order) {
166 $order = 'ORDER BY ' . XDB
::formatCustomOrder('a.uid', $uids);
171 $uids = array_map(array('XDB', 'escape'), $uids);
173 return XDB
::iterator('SELECT a.uid, a.hruid, a.registration_date, ah.alias AS homonym,
174 IF (af.alias IS NULL, a.email, CONCAT(af.alias, \'@' . $globals->mail
->domain
. '\')) AS forlife,
175 CONCAT(af.alias, \'@' . $globals->mail
->domain2
. '\') AS forlife_alternate,
176 IF (ab.alias IS NULL, a.email, CONCAT(ab.alias, \'@' . $globals->mail
->domain
. '\')) AS bestalias,
177 CONCAT(ab.alias, \'@' . $globals->mail
->domain2
. '\') AS bestalias_alternate,
178 a.full_name, a.display_name, a.sex = \'female\' AS gender,
179 IF(a.state = \'active\', at.perms, \'\') AS perms,
180 a.email_format, a.is_admin, a.state, a.type, a.skin,
181 FIND_IN_SET(\'watch\', a.flags) AS watch, a.comment,
182 a.weak_password IS NOT NULL AS weak_access,
183 a.token IS NOT NULL AS token_access,
184 (e.email IS NULL AND NOT FIND_IN_SET(\'googleapps\', eo.storage)) AND a.state != \'pending\' AS lost
187 INNER JOIN account_types AS at ON (at.type = a.type)
188 LEFT JOIN aliases AS af ON (af.uid = a.uid AND af.type = \'a_vie\')
189 LEFT JOIN aliases AS ab ON (ab.uid = a.uid AND FIND_IN_SET(\'bestalias\', ab.flags))
190 LEFT JOIN aliases AS ah ON (ah.uid = a.uid AND ah.type = \'homonyme\')
191 LEFT JOIN emails AS e ON (e.uid = a.uid AND e.flags = \'active\')
192 LEFT JOIN email_options AS eo ON (eo.uid = a.uid)
194 WHERE a.uid IN (' . implode(', ', $uids) . ')
199 // Implementation of the data loader.
200 protected function loadMainFields()
202 if ($this->hruid
!== null
&& $this->forlife
!== null
203 && $this->bestalias
!== null
&& $this->display_name
!== null
204 && $this->full_name
!== null
&& $this->perms
!== null
205 && $this->gender
!== null
&& $this->email_format
!== null
) {
208 $this->fillFromArray(self
::loadMainFieldsFromUIDs(array($this->uid
))->next());
211 // Specialization of the fillFromArray method, to implement hacks to enable
212 // lazy loading of user's main properties from the session.
213 // TODO(vzanotti): remove the conversion hacks once the old codebase will
214 // stop being used actively.
215 protected function fillFromArray(array $values)
217 // Also, if display_name and full_name are not known, but the user's
218 // surname and last name are, we can construct the former two.
219 if (isset($values['prenom']) && isset($values['nom'])) {
220 if (!isset($values['display_name'])) {
221 $values['display_name'] = ($values['prenom'] ?
$values['prenom'] : $values['nom']);
223 if (!isset($values['full_name'])) {
224 $values['full_name'] = $values['prenom'] . ' ' . $values['nom'];
228 // We also need to convert the gender (usually named "femme"), and the
229 // email format parameter (valued "texte" instead of "text").
230 if (isset($values['femme'])) {
231 $values['gender'] = (bool
) $values['femme'];
233 if (isset($values['mail_fmt'])) {
234 $values['email_format'] = $values['mail_fmt'];
237 parent
::fillFromArray($values);
240 // Specialization of the buildPerms method
241 // This function build 'generic' permissions for the user. It does not take
242 // into account page specific permissions (e.g X.net group permissions)
243 protected function buildPerms()
245 if (!is_null($this->perm_flags
)) {
248 if ($this->perms
=== null
) {
249 $this->loadMainFields();
251 $this->perm_flags
= self
::makePerms($this->perms
, $this->is_admin
);
254 // We do not want to store the password in the object.
255 // So, fetch it 'on demand'
256 public function password()
258 return XDB
::fetchOneCell('SELECT a.password
260 WHERE a.uid = {?}', $this->id());
263 /** Overload PlUser::promo(): there no promo defined for a user in the current
264 * schema. The promo is a field from the profile.
266 public function promo()
268 if (!$this->hasProfile()) {
271 return $this->profile()->promo();
274 public function firstName()
276 if (!$this->hasProfile()) {
277 return $this->displayName();
279 return $this->profile()->firstName();
282 public function lastName()
284 if (!$this->hasProfile()) {
287 return $this->profile()->lastName();
290 /** Return the main profile attached with this account if any.
292 public function profile()
294 if (!$this->_profile_fetched
) {
295 $this->_profile_fetched
= true
;
296 $this->_profile
= Profile
::get($this);
298 return $this->_profile
;
301 /** Return true if the user has an associated profile.
303 public function hasProfile()
305 return !is_null($this->profile());
308 /** Check if the user can edit to given profile.
310 public function canEdit(Profile
$profile)
312 // XXX: Check permissions (e.g. secretary permission)
313 // and flags from the profile
314 return XDB
::fetchOneCell('SELECT pid
315 FROM account_profiles
316 WHERE uid = {?} AND pid = {?}',
317 $this->id(), $profile->id());
320 /** Get the email alias of the user.
322 public function emailAlias()
325 $data = $this->emailAliases($globals->mail
->alias_dom
);
326 if (count($data) > 0) {
327 return array_pop($data);
332 /** Get all the aliases the user belongs to.
334 public function emailAliases($domain = null
, $type = 'user', $sub_state = false
)
336 $join = XDB
::format('(vr.redirect = {?} OR vr.redirect = {?}) ',
337 $this->forlifeEmail(), $this->m4xForlifeEmail());
339 if (!is_null($domain)) {
340 $where = XDB
::format('WHERE v.alias LIKE CONCAT("%@", {?})', $domain);
342 if (!is_null($type)) {
344 $where = XDB
::format('WHERE v.type = {?}', $type);
346 $where .= XDB
::format(' AND v.type = {?}', $type);
350 return XDB
::fetchAllAssoc('alias', 'SELECT v.alias, vr.redirect IS NOT NULL AS sub
352 LEFT JOIN virtual_redirect AS vr ON (v.vid = vr.vid AND ' . $join . ')
355 return XDB
::fetchColumn('SELECT v.alias
357 INNER JOIN virtual_redirect AS vr ON (v.vid = vr.vid AND ' . $join . ')
362 /** Get the alternative forlife email
363 * TODO: remove this uber-ugly hack. The issue is that you need to remove
364 * all @m4x.org addresses in virtual_redirect first.
365 * XXX: This is juste to make code more readable, to be remove as soon as possible
367 public function m4xForlifeEmail()
370 trigger_error('USING M4X FORLIFE', E_USER_NOTICE
);
371 return $this->login() . '@' . $globals->mail
->domain2
;
375 /** Get marketing informations
377 private function fetchMarketingData()
379 if (isset($this->last_known_email
)) {
382 // FIXME: We should fetch the last known email as well as the pending registration email (they aren't the same !)
383 $infos = XDB
::fetchOneAssoc('SELECT IF (MAX(m.last) > p.relance, MAX(m.last), p.relance) AS last_relance,
384 p.email AS last_known_email
385 FROM register_pending AS p
386 LEFT JOIN register_marketing AS m ON (p.uid = m.uid)
388 GROUP BY p.uid', $this->id());
390 $infos = array('last_relance' => null
, 'last_known_email' => null
);
392 $this->fillFromArray($infos);
395 public function lastMarketingRelance()
397 $this->fetchMarketingData();
398 return $this->last_relance
;
401 public function lastKnownEmail()
403 $this->fetchMarketingData();
404 return $this->last_known_email
;
408 /** Format of the emails sent by the site
410 public function setEmailFormat($format)
412 Platal
::assert($format == self
::FORMAT_HTML ||
$format == self
::FORMAT_TEXT
,
413 "Invalid email format \"$format\"");
414 XDB
::execute("UPDATE accounts
415 SET email_format = {?}
417 $format, $this->uid
);
418 $this->email_format
= $format;
422 /** Get watch informations
424 private function fetchWatchData()
426 if (isset($this->watch_actions
)) {
429 $watch = XDB
::fetchOneAssoc('SELECT flags AS watch_flags, actions AS watch_actions,
430 UNIX_TIMESTAMP(last) AS watch_last
432 WHERE uid = {?}', $this->id());
433 $watch['watch_flags'] = new PlFlagSet($watch['watch_flags']);
434 $watch['watch_actions'] = new PlFlagSet($watch['watch_actions']);
435 $watch['watch_promos'] = XDB
::fetchColumn('SELECT promo
437 WHERE uid = {?}', $this->id());
438 $watch['watch_users'] = XDB
::fetchColumn('SELECT ni_id
440 WHERE uid = {?}', $this->id());
441 $this->fillFromArray($watch);
444 public function watchType($type)
446 $this->fetchWatchData();
447 return $this->watch_actions
->hasFlag($type);
450 public function watchContacts()
452 $this->fetchWatchData();
453 return $this->watch_flags
->hasFlag('contacts');
456 public function watchEmail()
458 $this->fetchWatchData();
459 return $this->watch_flags
->hasFlag('mail');
462 public function watchPromos()
464 $this->fetchWatchData();
465 return $this->watch_promos
;
468 public function watchUsers()
470 $this->fetchWatchData();
471 return $this->watch_users
;
474 public function watchLast()
476 $this->fetchWatchData();
477 return $this->watch_last
;
480 public function invalidWatchCache()
482 unset($this->watch_actions
);
483 unset($this->watch_users
);
484 unset($this->watch_last
);
485 unset($this->watch_promos
);
490 private $contacts = null
;
491 private function fetchContacts()
493 if (is_null($this->contacts
)) {
494 $this->contacts
= XDB
::fetchAllAssoc('contact', 'SELECT *
501 public function iterContacts()
503 $this->fetchContacts();
504 return Profile
::iterOverPIDs(array_keys($this->contacts
));
507 public function getContacts()
509 $this->fetchContacts();
510 return Profile
::getBulkProfilesWithPIDs(array_keys($this->contacts
));
513 public function isContact(Profile
&$profile)
515 $this->fetchContacts();
516 return isset($this->contacts
[$profile->id()]);
519 public function isWatchedUser(Profile
&$profile)
521 return in_array($profile->id(), $this->watchUsers());
525 private $groups = null
;
526 public function groups()
528 if (is_null($this->groups
)) {
529 $this->groups
= XDB
::fetchAllAssoc('asso_id', 'SELECT asso_id, perms, comm
534 return $this->groups
;
537 public function groupNames($institutions = false
)
540 $where = ' AND (g.cat = \'GroupesX\' OR g.cat = \'Institutions\')';
544 return XDB
::fetchAllAssoc('SELECT g.diminutif, g.nom, g.site
545 FROM group_members AS gm
546 LEFT JOIN groups AS g ON (g.id = gm.asso_id)
547 WHERE gm.uid = {?}' . $where,
553 * *always deletes in: account_lost_passwords, register_marketing,
554 * register_pending, register_subs, watch_nonins, watch, watch_promo
555 * *always keeps in: account_types, accounts, aliases, axletter_ins, carvas,
556 * group_members, homonyms, newsletter_ins, register_mstats,
557 * *deletes if $clearAll: account_auth_openid, announce_read, contacts,
558 * email_options, email_send_save, emails, forum_innd, forum_profiles,
559 * forum_subs, gapps_accounts, gapps_nicknames, group_announces_read,
560 * group_member_sub_requests, reminder, requests, requests_hidden,
561 * virtual, virtual_redirect, ML
562 * *modifies if $clearAll: accounts
565 * *$clearAll == false: when a user dies, her family still needs to keep in
566 * touch with the community.
567 * *$clearAll == true: in every other case we want the account to be fully
568 * deleted so that it can not be used anymore.
570 public function clear($clearAll = true
)
572 XDB
::execute('DELETE FROM account_lost_passwords, register_marketing,
573 register_pending, register_subs, watch_nonins,
579 $groupIds = XDB
::iterator('SELECT asso_id
583 while ($groupId = $groupIds->next()) {
584 $group = Group
::get($groupId);
585 if ($group->notif_unsub
) {
586 $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl');
587 $admins = $group->iterAdmins();
588 while ($admin = $admins->next()) {
589 $mailer->addTo($admin);
591 $mailer->assign('group', $group->shortname
);
592 $mailer->assign('user', $this);
593 $mailer->assign('selfdone', false
);
598 XDB
::execute('DELETE FROM account_auth_openid, announce_read, contacts,
599 email_options, email_send_save, emails,
600 forum_innd, forum_profiles, forum_subs,
601 gapps_accounts, gapps_nicknames, group_announces_read,
602 group_members, group_member_sub_requests, reminder, requests,
606 XDB
::execute("UPDATE accounts
607 SET registration_date = 0, state = 'pending', password = NULL,
608 weak_password = NULL, token = NULL, is_admin = 0
612 XDB
::execute('DELETE v.*
614 INNER JOIN virtual_redirect AS r ON (v.vid = r.vid)
615 WHERE redirect = {?} OR redirect = {?}',
616 $this->forlifeEmail(), $this->m4xForlifeEmail());
617 XDB
::execute('DELETE FROM virtual_redirect
618 WHERE redirect = {?} OR redirect = {?}',
619 $this->forlifeEmail(), $this->m4xForlifeEmail());
621 if ($globals->mailstorage
->googleapps_domain
) {
622 require_once 'googleapps.inc.php';
624 if (GoogleAppsAccount
::account_status($uid)) {
625 $account = new GoogleAppsAccount($user);
631 $mmlist = new MMList($this);
632 $mmlist->kill($alias, $clearAll);
635 // Merge all infos in other user and then clean this one
636 public function mergeIn(User
&$newuser) {
637 if ($this->profile() ||
!$newuser->id()) {
638 // don't disable user with profile in this way
641 // TODO check all tables to see if there is no other info to use
643 $newemail = $newuser->forlifeEmail();
644 if (!$newemail && $this->forlifeEmail()) {
645 XDB
::execute("UPDATE accounts
647 WHERE uid = {?} AND email IS NULL",
648 $this->forlifeEmail(), $newuser->id());
649 $newemail = $this->forlifeEmail();
652 // change email used in aliases and mailing lists
653 if ($this->forlifeEmail() != $newemail && $this->forlifeEmail()) {
654 // virtual_redirect (email aliases)
655 XDB
::execute("DELETE v1
656 FROM virtual_redirect AS v1, virtual_redirect AS v2
657 WHERE v1.vid = v2.vid AND v1.redirect = {?} AND v2.redirect = {?}",
658 $this->forlifeEmail(), $newemail);
659 XDB
::execute("UPDATE virtual_redirect
661 WHERE redirect = {?}",
662 $newemail, $this->forlifeEmail());
664 // require_once 'mmlist.php';
666 // group mailing lists
667 $group_domains = XDB
::fetchColumn("SELECT g.mail_domain
669 INNER JOIN group_members AS gm ON(g.id = gm.asso_id)
670 WHERE g.mail_domain != '' AND gm.uid = {?}",
672 foreach ($group_domains as $mail_domain) {
673 $mmlist = new MMList($this, $mail_domain);
674 $mmlist->replace_email_in_all($this->forlifeEmail(), $newmail);
677 $mmlist = new MMList($this);
678 $mmlist->replace_email_in_all($this->forlifeEmail(), $newmail);
681 // group_members (xnet group membership)
682 XDB
::execute("DELETE g1
683 FROM group_members AS g1, group_members AS g2
684 WHERE g1.uid = {?} AND g2.uid = {?} AND g1.asso_id = g2.asso_id",
685 $this->id(), $newuser->id());
686 XDB
::execute("UPDATE group_members
689 $this->id(), $newuser->id());
691 XDB
::execute("DELETE FROM accounts WHERE uid = {?}", $this->id());
696 // Return permission flags for a given permission level.
697 public static function makePerms($perms, $is_admin)
699 $flags = new PlFlagSet($perms);
700 $flags->addFlag(PERMS_USER
);
702 $flags->addFlag(PERMS_ADMIN
);
707 // Implementation of the default user callback.
708 public static function _default_user_callback($login, $results)
710 $result_count = count($results);
711 if ($result_count == 0 ||
!S
::admin()) {
712 Platal
::page()->trigError("Il n'y a pas d'utilisateur avec l'identifiant : $login");
714 Platal
::page()->trigError("Il y a $result_count utilisateurs avec cet identifiant : " . join(', ', $results));
718 // Implementation of the static email locality checker.
719 public static function isForeignEmailAddress($email)
722 if (strpos($email, '@') === false
) {
726 list($user, $dom) = explode('@', $email);
727 return $dom != $globals->mail
->domain
&&
728 $dom != $globals->mail
->domain2
&&
729 $dom != $globals->mail
->alias_dom
&&
730 $dom != $globals->mail
->alias_dom2
;
733 public static function isVirtualEmailAddress($email)
736 if (strpos($email, '@') === false
) {
740 list($user, $dom) = explode('@', $email);
741 return $dom == $globals->mail
->alias_dom
742 ||
$dom == $globals->mail
->alias_dom2
;
745 /* Tries to find pending accounts with an hruid close to $login. */
746 public static function getPendingAccounts($login, $iterator = false
)
750 if (strpos($login, '@') === false
) {
754 list($login, $domain) = explode('@', $login);
756 if ($domain && $domain != $globals->mail
->domain
&& $domain != $globals->mail
->domain2
) {
760 $sql = "SELECT uid, full_name
762 WHERE state = 'pending' AND REPLACE(hruid, '-', '') LIKE
763 CONCAT('%', REPLACE(REPLACE(REPLACE({?}, ' ', ''), '-', ''), '\'', ''), '%')
766 return XDB
::iterator($sql, $login);
768 $res = XDB
::query($sql, $login);
769 return $res->fetchAllAssoc();
774 public static function iterOverUIDs($uids, $respect_order = true
)
776 return new UserIterator(self
::loadMainFieldsFromUIDs($uids, $respect_order));
779 /** Fetch a set of users from a list of UIDs
780 * @param $data The list of uids to fetch, or an array of arrays
781 * @param $orig If $data is an array of arrays, the subfield where uids are stored
782 * @param $dest If $data is an array of arrays, the subfield to fill with Users
783 * @param $fetchProfile Whether to fetch Profiles as well
784 * @return either an array of $uid => User, or $data with $data[$i][$dest] = User
786 public static function getBulkUsersWithUIDs(array $data, $orig = null
, $dest = null
, $fetchProfile = true
)
788 // Fetch the list of uids
789 if (is_null($orig)) {
792 if (is_null($dest)) {
796 foreach ($data as $key=>$entry) {
797 if (isset($entry[$orig])) {
798 $uids[] = $entry[$orig];
804 if (count($uids) == 0) {
807 $users = self
::iterOverUIDs($uids, true
);
811 $profiles = Profile
::iterOverUIDS($uids, true
);
812 if ($profiles != null
) {
813 $profile = $profiles->next();
819 /** We iterate through the users, moving in
820 * profiles when they match the user ID :
821 * there can be users without a profile, but not
822 * the other way around.
824 while (($user = $users->next())) {
826 if ($profile != null
&& $profile->owner_id
== $user->id()) {
827 $user->_profile
= $profile;
828 $profile = $profiles->next();
830 $user->_profile_fetched
= true
;
832 $table[$user->id()] = $user;
835 // Build the result with respect to input order.
836 if (is_null($orig)) {
839 foreach ($data as $key=>$entry) {
840 if (isset($entry[$orig])) {
841 $entry[$dest] = $table[$entry[$orig]];
842 $data[$key] = $entry;
849 public static function getBulkUsersFromDB($fetchProfile = true
)
851 $args = func_get_args();
852 $uids = call_user_func_array(array('XDB', 'fetchColumn'), $args);
853 return self
::getBulkUsersWithUIDs($uids, null
, null
, $fetchProfile);
857 /** Iterator over a set of Users
858 * @param an XDB::Iterator obtained from a User::loadMainFieldsFromUIDs
860 class UserIterator
implements PlIterator
864 public function __construct($dbiter)
866 $this->dbiter
= $dbiter;
869 public function next()
871 $data = $this->dbiter
->next();
875 return User
::getSilentWithValues(null
, $data);
879 public function total()
881 return $this->dbiter
->total();
884 public function first()
886 return $this->dbiter
->first();
889 public function last()
891 return $this->dbiter
->last();
895 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: