Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-05-21 13:11:47 +0400
committerJoas Schilling <nickvergessen@gmx.de>2014-05-21 13:14:52 +0400
commitcf3cd572b0410e6db7255e3373c8ec8230c4af5c (patch)
treed105ab44ec29f8ee7c17630bdc3de7d3645d88a4 /lib/private/preferences.php
parent9b23a210c9b33c40364e207b5791e550efd2b72f (diff)
Add a method to get the values for multiple users to OC\Preferences
Diffstat (limited to 'lib/private/preferences.php')
-rw-r--r--lib/private/preferences.php35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/private/preferences.php b/lib/private/preferences.php
index e6d9f28b1d6..c0000804aa5 100644
--- a/lib/private/preferences.php
+++ b/lib/private/preferences.php
@@ -206,6 +206,41 @@ class Preferences {
}
/**
+ * Gets the preference for an array of users
+ * @param string $app
+ * @param string $key
+ * @param array $users
+ * @return array Mapped values: userid => value
+ */
+ public function getValueForUsers($app, $key, $users) {
+ if (empty($users) || !is_array($users)) return array();
+
+ $chunked_users = array_chunk($users, 50, true);
+ $placeholders_50 = implode(',', array_fill(0, 50, '?'));
+
+ $userValues = array();
+ foreach ($chunked_users as $chunk) {
+ $queryParams = $chunk;
+ array_unshift($queryParams, $key);
+ array_unshift($queryParams, $app);
+
+ $placeholders = (sizeof($chunk) == 50) ? $placeholders_50 : implode(',', array_fill(0, sizeof($users), '?'));
+
+ $query = 'SELECT `userid`, `configvalue` '
+ . ' FROM `*PREFIX*preferences` '
+ . ' WHERE `appid` = ? AND `configkey` = ?'
+ . ' AND `userid` IN (' . $placeholders . ')';
+ $result = $this->conn->executeQuery($query, $queryParams);
+
+ while ($row = $result->fetch()) {
+ $userValues[$row['userid']] = $row['configvalue'];
+ }
+ }
+
+ return $userValues;
+ }
+
+ /**
* Deletes a key
* @param string $user user
* @param string $app app