X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fuser.php;h=cea85c6ff6b45151ba46ac2ae3509febf0b9c75e;hb=5dd9d82327c44b3d5ce999c44a088f23e6b8ed8c;hp=54a3737fdaff9c152ef8acfa075b4ea0c58ff33a;hpb=4ca15c312b905eea712b71d077c7a8b24f9d3b01;p=platal.git diff --git a/classes/user.php b/classes/user.php index 54a3737..cea85c6 100644 --- a/classes/user.php +++ b/classes/user.php @@ -1,6 +1,6 @@ id(); + } + if ($login instanceof Profile) { $this->_profile = $login; $this->_profile_fetched = true; @@ -135,11 +139,12 @@ class User extends PlUser throw new UserNotFoundException($res->fetchColumn(1)); } - protected static function loadMainFieldsFromUIDs(array $uids, $sorted = null) + protected static function loadMainFieldsFromUIDs(array $uids, $sorted = null, $count = null, $offset = null) { - $uids = array_map(array('XDB', 'escape'), $uids); + global $globals; $joins = ''; $orderby = ''; + $fields = array(); if (!is_null($sorted)) { $order = array(); $with_ap = false; @@ -147,7 +152,7 @@ class User extends PlUser foreach (explode(',', $sorted) as $part) { $desc = ($part[0] == '-'); if ($desc) { - $part = substr($desc, 1); + $part = substr($part, 1); } switch ($part) { case 'promo': @@ -161,6 +166,11 @@ class User extends PlUser case 'display_name': $part = 'a.display_name'; break; + case 'directory_name': + $part = 'pd.directory_name'; + $with_pd = true; + $with_ap = true; + break; default: $part = null; } @@ -181,7 +191,25 @@ class User extends PlUser $orderby = 'ORDER BY ' . implode(', ', $order); } } - global $globals; + if ($globals->asso('id')) { + $joins .= XDB::format("LEFT JOIN groupex.membres AS gpm ON (gpm.uid = a.uid AND gpm.asso_id = {?})\n", $globals->asso('id')); + $fields[] = 'gpm.perms AS group_perms'; + $fields[] = 'gpm.comm AS group_comm'; + } + if (count($fields) > 0) { + $fields = ', ' . implode(', ', $fields); + } else { + $fields = ''; + } + $limit = ''; + if (!is_null($count)) { + if (!is_null($offset)) { + $limit = ' LIMIT ' . $offset . ', ' . $count; + } else { + $limit = ' LIMIT ' . $count; + } + } + $uids = array_map(array('XDB', 'escape'), $uids); return XDB::iterator('SELECT a.uid, a.hruid, a.registration_date, CONCAT(af.alias, \'@' . $globals->mail->domain . '\') AS forlife, CONCAT(ab.alias, \'@' . $globals->mail->domain . '\') AS bestalias, @@ -190,14 +218,14 @@ class User extends PlUser a.email_format, a.is_admin, a.state, a.type, a.skin, FIND_IN_SET(\'watch\', a.flags) AS watch, a.comment, a.weak_password IS NOT NULL AS weak_access, - a.token IS NOT NULL AS token_access + a.token IS NOT NULL AS token_access ' . $fields . ' FROM accounts AS a INNER JOIN account_types AS at ON (at.type = a.type) LEFT JOIN aliases AS af ON (af.id = a.uid AND af.type = \'a_vie\') LEFT JOIN aliases AS ab ON (ab.id = a.uid AND FIND_IN_SET(\'bestalias\', ab.flags)) ' . $joins . ' WHERE a.uid IN (' . implode(', ', $uids) . ') - ' . $orderby); + ' . $orderby . $limit); } // Implementation of the data loader. @@ -282,6 +310,22 @@ class User extends PlUser return $this->profile()->promo(); } + public function firstName() + { + if (!$this->hasProfile()) { + return $this->displayName(); + } + return $this->profile()->firstName(); + } + + public function lastName() + { + if (!$this->hasProfile()) { + return ''; + } + return $this->profile()->lastName(); + } + /** Return the main profile attached with this account if any. */ public function profile() @@ -326,18 +370,32 @@ class User extends PlUser /** Get all the aliases the user belongs to. */ - public function emailAliases($domain = null) + public function emailAliases($domain = null, $type = 'user', $sub_state = false) { + $join = XDB::format('(vr.redirect = {?} OR vr.redirect = {?}) ', + $this->forlifeEmail(), $this->m4xForlifeEmail()); $where = ''; if (!is_null($domain)) { - $where = XDB::format(' AND alias LIKE CONCAT("%@", {?})', $domain); - } - return XDB::fetchColumn('SELECT v.alias - FROM virtual AS v - INNER JOIN virtual_redirect AS vr ON (v.vid = vr.vid) - WHERE (vr.redirect = {?} OR vr.redirect = {?}) - ' . $where, - $this->forlifeEmail(), $this->m4xForlifeEmail()); + $where = XDB::format('WHERE v.alias LIKE CONCAT("%@", {?})', $domain); + } + if (!is_null($type)) { + if (empty($where)) { + $where = XDB::format('WHERE v.type = {?}', $type); + } else { + $where .= XDB::format(' AND v.type = {?}', $type); + } + } + if ($sub_state) { + return XDB::fetchAllAssoc('alias', 'SELECT v.alias, vr.redirect IS NOT NULL AS sub + FROM virtual AS v + LEFT JOIN virtual_redirect AS vr ON (v.vid = vr.vid AND ' . $join . ') + ' . $where); + } else { + return XDB::fetchColumn('SELECT v.alias + FROM virtual AS v + INNER JOIN virtual_redirect AS vr ON (v.vid = vr.vid AND ' . $join . ') + ' . $where); + } } /** Get the alternative forlife email @@ -390,9 +448,9 @@ class User extends PlUser } // Fetch a set of users from a list of UIDs - public static function getBuildUsersWithUIDs(array $uids, $sortby = null) + public static function getBuildUsersWithUIDs(array $uids, $sortby = null, $count = null, $offset = null) { - $fields = self::loadMainFieldsFromUIDs($uids, $sortby); + $fields = self::loadMainFieldsFromUIDs($uids, $sortby, $count, $offset); $users = array(); while (($list = $fields->next())) { $users[] = User::getSilentWithValues(null, $list);