Fixes issue#88, issue#89 (getDisplayNames function)

This commit is contained in:
Marcin Łojewski
2019-01-19 10:07:52 +01:00
parent b8581b1098
commit a06e316327

View File

@@ -393,16 +393,18 @@ final class UserBackend extends ABackend implements
["app" => $this->appName] ["app" => $this->appName]
); );
if (empty($this->properties[DB::USER_NAME_COLUMN])) { $users = $this->getUsers(
return false; $search, $limit, $offset, function ($user) {
return $user;
} }
);
$users = $this->getUsers($search, $limit, $offset);
$names = []; $names = [];
foreach ($users as $user) { foreach ($users as $user) {
if (!is_null($user->name)) { if (is_null($user->name)) {
$names[$user] = $user->name; $names[$user->uid] = $user->uid;
} else {
$names[$user->uid] = $user->name;
} }
} }
@@ -417,10 +419,11 @@ final class UserBackend extends ABackend implements
/** /**
* @inheritdoc * @inheritdoc
*/ */
public function getUsers($search = "", $limit = null, $offset = null) public function getUsers(
{ $search = "", $limit = null, $offset = null, $callback = null
) {
$this->logger->debug( $this->logger->debug(
"Entering getUsers($search, $limit, $offset)", "Entering getUsers($search, $limit, $offset, $callback)",
["app" => $this->appName] ["app" => $this->appName]
); );
@@ -448,15 +451,17 @@ final class UserBackend extends ABackend implements
$this->cache->set("user_" . $user->uid, $user); $this->cache->set("user_" . $user->uid, $user);
} }
$users = array_map( $callback = is_callable($callback)
function ($user) { ? $callback
: function ($user) {
return $user->uid; return $user->uid;
}, $users };
); $users = array_map($callback, $users);
$this->cache->set($cacheKey, $users); $this->cache->set($cacheKey, $users);
$this->logger->debug( $this->logger->debug(
"Returning getUsers($search, $limit, $offset): count(" . count( "Returning getUsers($search, $limit, $offset, $callback): count("
. count(
$users $users
) . ")", ["app" => $this->appName] ) . ")", ["app" => $this->appName]
); );