/** * Deletes a key-value combination from the database. * * (non-PHPdoc) * @see PartKeepr\Service.RestfulService::destroy() */ public function destroy() { if ($this->hasParameter("user_id") && SessionManager::getCurrentSession()->getUser()->isAdmin()) { UserPreference::deletePreference(User::loadById($this->getParameter("user_id")), $this->getParameter("key")); } else { UserPreference::deletePreference($this->getUser(), $this->getParameter("key")); } }
/** * Makes sure that an exception is thrown when attempting to delete a preference if the user is not persistant yet. * * @expectedException PartKeepr\Util\Exceptions\EntityNotPersistantException */ public function testDeleteNonPersistantUserPreference() { $user = new User(); UserPreference::deletePreference($user, "test"); }
/** * Deletes the given preference * * @param string $preferenceKey The preference key * @return UserPreference The user preference object * @throws UserPreferenceNotFoundException If the preference key was not found * @throws EntityNotPersistantException Thrown if the entity is not persistant */ public function deletePreference($preferenceKey) { UserPreference::deletePreference($this, $preferenceKey); }