Add method to get all user preferences for an app-key pair

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2021-04-14 18:39:06 +02:00
parent a011b7021e
commit 43b90e2e89
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
2 changed files with 35 additions and 0 deletions

View File

@ -535,6 +535,30 @@ class AllConfig implements \OCP\IConfig {
return $userIDs;
}
/**
* Returns all user configs set for an appid-key pair
*
* @param string $appId the app ID to get the app configs from
* @param string $key thekey to get the app configs from
* @return array<string, string> - array with the following structure:
* [ $userId => $value ]
*/
public function getUserValuesForKey(string $appId, string $key): array {
// TODO - FIXME
$this->fixDIInit();
$data = [];
$query = $this->connection->getQueryBuilder();
$query->select('userid', 'configvalue')
->from('preferences')
->where($query->expr()->eq('appid', $query->createNamedParameter($appId)))
->andWhere($query->expr()->eq('configkey', $query->createNamedParameter($key)));
$result = $query->execute()->fetchAll();
$userIds = array_column($result, 'userid');
$values = array_column($result, 'configvalue');
return array_combine($userIds, $values);
}
public function getSystemConfig() {
return $this->systemConfig;
}

View File

@ -257,4 +257,15 @@ interface IConfig {
* @since 8.0.0
*/
public function getUsersForUserValue($appName, $key, $value);
/**
* Returns all user configs set for an appid-key pair
*
* @param string $appId the app ID to get the app configs from
* @param string $key thekey to get the app configs from
* @return array<string, string> - array with the following structure:
* [ $userId => $value ]
* @since 22.0.0
*/
public function getUserValuesForKey(string $appId, string $key): array;
}