Add method to get users by their preference
This commit is contained in:
parent
ff3ded6cb2
commit
879237f32a
|
@ -242,6 +242,28 @@ class Preferences {
|
||||||
return $userValues;
|
return $userValues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Deletes a key
|
||||||
* @param string $user user
|
* @param string $user user
|
||||||
|
|
|
@ -221,6 +221,22 @@ class Test_Preferences_Object extends PHPUnit_Framework_TestCase {
|
||||||
$this->assertEquals('someothervalue', $values['AnotherUser']);
|
$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()
|
public function testDeleteKey()
|
||||||
{
|
{
|
||||||
$connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
|
$connectionMock = $this->getMock('\OC\DB\Connection', array(), array(), '', false);
|
||||||
|
|
Loading…
Reference in New Issue