+ protected static function loadMainFieldsFromUIDs(array $uids, $sorted = null, $count = null, $offset = null)
+ {
+ global $globals;
+ $joins = '';
+ $orderby = '';
+ $fields = array();
+ if (!is_null($sorted)) {
+ $order = array();
+ $with_ap = false;
+ $with_pd = false;
+ foreach (explode(',', $sorted) as $part) {
+ $desc = ($part[0] == '-');
+ if ($desc) {
+ $part = substr($part, 1);
+ }
+ switch ($part) {
+ case 'promo':
+ $with_pd = true;
+ $with_ap = true;
+ $part = 'IF (pd.promo IS NULL, \'ext\', pd.promo)';
+ break;
+ case 'full_name':
+ $part = 'a.full_name';
+ break;
+ 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 (!is_null($part)) {
+ if ($desc) {
+ $part .= ' DESC';
+ }
+ $order[] = $part;
+ }
+ }
+ if (count($order) > 0) {
+ if ($with_ap) {
+ $joins .= "LEFT JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET('owner', ap.perms))\n";
+ }
+ if ($with_pd) {
+ $joins .= "LEFT JOIN profile_display AS pd ON (pd.pid = ap.pid)\n";
+ }
+ $orderby = 'ORDER BY ' . implode(', ', $order);
+ }
+ }
+ 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,
+ a.full_name, a.display_name, a.sex = \'female\' AS gender,
+ IF(a.state = \'active\', at.perms, \'\') AS perms,
+ 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 ' . $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 . $limit);
+ }
+