<?php
/***************************************************************************
- * Copyright (C) 2003-2008 Polytechnique.org *
+ * Copyright (C) 2003-2009 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
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)
{
global $globals;
$joins = '';
foreach (explode(',', $sorted) as $part) {
$desc = ($part[0] == '-');
if ($desc) {
- $part = substr($desc, 1);
+ $part = substr($part, 1);
}
switch ($part) {
case 'promo':
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;
}
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,
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.
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()
/** 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
}
// 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);