- while (($list = $fields->next())) {
- $table[$list['uid']] = User::getSilentWithValues(null, $list);
+ if ($fetchProfile) {
+ $profiles = Profile::iterOverUIDS($uids, true);
+ $profile = $profiles->next();
+ }
+
+ /** We iterate through the users, moving in
+ * profiles when they match the user ID :
+ * there can be users without a profile, but not
+ * the other way around.
+ */
+ while (($user = $users->next())) {
+ if ($fetchProfile) {
+ if ($profile->owner_id == $user->id()) {
+ $user->_profile = $profile;
+ $profile = $profiles->next();
+ }
+ $user->_profile_fetched = true;
+ }
+ $table[$user->id()] = $user;
+ }
+
+ // Build the result with respect to input order.
+ if (is_null($orig)) {
+ return $table;
+ } else {
+ foreach ($data as $key=>$entry) {
+ if (isset($entry[$orig])) {
+ $entry[$dest] = $table[$entry[$orig]];
+ $data[$key] = $entry;
+ }
+ }
+ return $data;