X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=blobdiff_plain;f=includes%2Fuser%2FCentralIdLookup.php;h=618b7f07ed71da9b3ff23884bfc0d09abb15279a;hb=1ed097a16517656998d3e4d00d4e60d710a88f25;hp=2ced6e2516afe6681e40406ff22b98ca566b9bba;hpb=a5be382adfdad4678eec18413c6a118cb3284daf;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/user/CentralIdLookup.php b/includes/user/CentralIdLookup.php index 2ced6e2516..618b7f07ed 100644 --- a/includes/user/CentralIdLookup.php +++ b/includes/user/CentralIdLookup.php @@ -157,6 +157,27 @@ abstract class CentralIdLookup implements IDBAccessObject { return $idToName[$id]; } + /** + * Given a an array of central user IDs, return the (local) user names. + * @param int[] $ids Central user IDs + * @param int|User $audience One of the audience constants, or a specific user + * @param int $flags IDBAccessObject read flags + * @return string[] User names + * @since 1.30 + */ + public function namesFromCentralIds( + array $ids, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL + ) { + $idToName = array_fill_keys( $ids, false ); + $names = $this->lookupCentralIds( $idToName, $audience, $flags ); + $names = array_unique( $names ); + $names = array_filter( $names, function ( $name ) { + return $name !== false && $name !== ''; + } ); + + return array_values( $names ); + } + /** * Given a (local) user name, return the central ID * @note There's no requirement that the user name actually exists locally, @@ -174,6 +195,27 @@ abstract class CentralIdLookup implements IDBAccessObject { return $nameToId[$name]; } + /** + * Given an array of (local) user names, return the central IDs. + * @param string[] $names Canonicalized user names + * @param int|User $audience One of the audience constants, or a specific user + * @param int $flags IDBAccessObject read flags + * @return int[] User IDs + * @since 1.30 + */ + public function centralIdsFromNames( + array $names, $audience = self::AUDIENCE_PUBLIC, $flags = self::READ_NORMAL + ) { + $nameToId = array_fill_keys( $names, false ); + $ids = $this->lookupUserNames( $nameToId, $audience, $flags ); + $ids = array_unique( $ids ); + $ids = array_filter( $ids, function ( $id ) { + return $id !== false; + } ); + + return array_values( $ids ); + } + /** * Given a central user ID, return a local User object * @note Unlike nameFromCentralId(), this does guarantee that the local