partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit b03558d06d14b09e779fb847625d674ae6af1daf
parent f57173906e005bdd4936a374acfedcf65ff328fe
Author: Felicitus <felicitus@felicitus.org>
Date:   Sat, 12 May 2012 09:54:22 +0200

Added missing "getPreferences" method

Diffstat:
Msrc/backend/de/RaumZeitLabor/PartKeepr/User/User.php | 20+++++++++++++++++---
Msrc/backend/de/RaumZeitLabor/PartKeepr/UserPreference/UserPreference.php | 18++++++++++++++++++
Mtests/User/UserTest.php | 4+++-
3 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/User/User.php b/src/backend/de/RaumZeitLabor/PartKeepr/User/User.php @@ -189,6 +189,7 @@ class User extends BaseEntity implements Serializable, Deserializable { * * @param string $preferenceKey The preference key * @param string $preferenceValue The preference value + * @throws EntityNotPersistantException Thrown if the entity is not persistant */ public function setPreference ($preferenceKey, $preferenceValue) { return UserPreference::setPreference($this, $preferenceKey, $preferenceValue); @@ -199,7 +200,8 @@ class User extends BaseEntity implements Serializable, Deserializable { * * @param string $preferenceKey The preference key * @return UserPreference The user preference object - * @thorws UserPreferenceNotFoundException If the preference key was not found + * @throws UserPreferenceNotFoundException If the preference key was not found + * @throws EntityNotPersistantException Thrown if the entity is not persistant */ public function getPreference ($preferenceKey) { return UserPreference::getPreference($this, $preferenceKey); @@ -210,7 +212,8 @@ class User extends BaseEntity implements Serializable, Deserializable { * * @param string $preferenceKey The preference key * @return UserPreference The user preference object - * @thorws UserPreferenceNotFoundException If the preference key was not found + * @throws UserPreferenceNotFoundException If the preference key was not found + * @throws EntityNotPersistantException Thrown if the entity is not persistant */ public function getPreferenceValue ($preferenceKey) { return UserPreference::getPreferenceValue($this, $preferenceKey); @@ -221,13 +224,24 @@ class User extends BaseEntity implements Serializable, Deserializable { * * @param string $preferenceKey The preference key * @return UserPreference The user preference object - * @thorws UserPreferenceNotFoundException If the preference key was not found + * @throws UserPreferenceNotFoundException If the preference key was not found + * @throws EntityNotPersistantException Thrown if the entity is not persistant */ public function deletePreference ($preferenceKey) { return UserPreference::deletePreference($this, $preferenceKey); } /** + * Returns all user preferences for this user + * + * @param none + * @return Array An array of UserPreference objects + * @throws EntityNotPersistantException Thrown if the entity is not persistant + */ + public function getPreferences () { + return UserPreference::getPreferences($this); + } + /** * Loads a user by name. * * @param $username string The username to query diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/UserPreference/UserPreference.php b/src/backend/de/RaumZeitLabor/PartKeepr/UserPreference/UserPreference.php @@ -158,6 +158,24 @@ class UserPreference implements Serializable { } /** + * Returns all preferences for the given user + * @param User $user The user + * @throws EntityNotPersistantException Thrown if the user entity is not persistent + */ + public static function getPreferences (User $user) { + if (!PartKeepr::getEM()->contains($user)) { + throw new EntityNotPersistantException(); + } + + $dql = "SELECT up FROM de\RaumZeitLabor\PartKeepr\UserPreference\UserPreference up WHERE up.user = :user"; + + $query = PartKeepr::getEM()->createQuery($dql); + $query->setParameter("user", $user); + + return $query->getResult(); + } + + /** * Returns a specific preference object for the given user * * @param User $user The user to retrieve the preference for diff --git a/tests/User/UserTest.php b/tests/User/UserTest.php @@ -140,9 +140,11 @@ class UserTest extends \PHPUnit_Framework_TestCase { $this->assertEquals("foo", $user->getPreferenceValue("test")); $this->assertEquals("foo", $user->getPreference("test")->getValue()); + $this->assertEquals(1, count($user->getPreferences())); + $user->deletePreference("test"); - echo $user->getId(); + UserManager::getInstance()->deleteUser($user->getId()); }