summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2014-06-05 11:49:13 +0200
committerJoas Schilling <nickvergessen@gmx.de>2014-06-05 11:50:43 +0200
commit879237f32ac4af820fddd2d07ca342000f5723eb (patch)
treeb399d03680fa807f0b3238a7530bff1717ad5084
parentff3ded6cb2f8542c3b2a083f4dabc83ccfa1888e (diff)
downloadnextcloud-server-879237f32ac4af820fddd2d07ca342000f5723eb.tar.gz
nextcloud-server-879237f32ac4af820fddd2d07ca342000f5723eb.zip
Add method to get users by their preference
-rw-r--r--lib/private/preferences.php22
-rw-r--r--tests/lib/preferences.php16
2 files changed, 38 insertions, 0 deletions
diff --git a/lib/private/preferences.php b/lib/private/preferences.php
index a4bfc650d08..f1de95a5e11 100644
--- a/lib/private/preferences.php
+++ b/lib/private/preferences.php
@@ -243,6 +243,28 @@ class Preferences {
}
/**
+ * Gets the users for a preference
+ * @param string $app
+ * @param string $key
+ * @param string $value
+ * @return array
+ */
+ public function getUsersForValue($app, $key, $value) {
+ $users = array();
+
+ $query = 'SELECT `userid` '
+ . ' FROM `*PREFIX*preferences` '
+ . ' WHERE `appid` = ? AND `configkey` = ? AND `configvalue` = ?';
+ $result = $this->conn->executeQuery($query, array($app, $key, $value));
+
+ while ($row = $result->fetch()) {
+ $users[] = $row['userid'];
+ }
+
+ return $users;
+ }
+
+ /**
* Deletes a key
* @param string $user user
* @param string $app app
diff --git a/tests/lib/preferences.php b/tests/lib/preferences.php
index 499be914fb7..a4259a8f349 100644
--- a/tests/lib/preferences.php
+++ b/tests/lib/preferences.php
@@ -221,6 +221,22 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase {
$this->assertEquals('someothervalue', $values['AnotherUser']);
}
+ public function testGetValueUsers()
+ {
+ // Prepare data
+ $query = \OC_DB::prepare('INSERT INTO `*PREFIX*preferences` VALUES(?, ?, ?, ?)');
+ $query->execute(array('SomeUser', 'testGetUsersForValue', 'somekey', 'somevalue'));
+ $query->execute(array('AnotherUser', 'testGetUsersForValue', 'somekey', 'someothervalue'));
+ $query->execute(array('AUser', 'testGetUsersForValue', 'somekey', 'somevalue'));
+
+ $preferences = new OC\Preferences(\OC_DB::getConnection());
+ $this->assertEquals(array('SomeUser', 'AUser'), $preferences->getUsersForValue('testGetUsersForValue', 'somekey', 'somevalue'));
+
+ // Clean DB after the test
+ $query = \OC_DB::prepare('DELETE FROM `*PREFIX*preferences` WHERE `appid` = ?');
+ $query->execute(array('testGetUsersForValue'));
+ }
+
public function testDeleteKey()
{
$connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);