4 * @file classes/user/PKPUserSettingsDAO.inc.php
6 * Copyright (c) 2003-2009 John Willinsky
7 * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
9 * @class PKPUserSettingsDAO
13 * @brief Operations for retrieving and modifying user settings.
16 // $Id: PKPUserSettingsDAO.inc.php,v 1.2 2009/08/18 23:44:08 asmecher Exp $
19 class PKPUserSettingsDAO
extends DAO
{
21 * Retrieve a user setting value.
24 * @param $assocType int
28 function &getSetting($userId, $name, $assocType = null, $assocId = null) {
29 $result =& $this->retrieve(
30 'SELECT setting_value,
45 if ($result->RecordCount() != 0) {
46 $row =& $result->getRowAssoc(false);
47 $returner = $this->convertFromDB($row['setting_value'], $row['setting_type']);
56 * Retrieve all users by setting name and value.
60 * @param $assocType int
62 * @return DAOResultFactory matching Users
64 function &getUsersBySetting($name, $value, $type = null, $assocType = null, $assocId = null) {
65 $userDao =& DAORegistry
::getDAO('UserDAO');
67 $value = $this->convertToDB($value, $type);
68 $result =& $this->retrieve(
72 WHERE u.user_id = s.user_id AND
73 s.setting_name = ? AND
74 s.setting_value = ? AND
77 array($name, $value, (int) $assocType, (int) $assocId)
80 $returner = new DAOResultFactory($result, $userDao, '_returnUserFromRow');
85 * Retrieve all settings for a user by association info.
87 * @param $assocType int
91 function &getSettingsByAssoc($userId, $assocType = null, $assocId = null) {
92 $userSettings = array();
94 $result =& $this->retrieve(
102 array((int) $userId, (int) $assocType, (int) $assocId)
105 while (!$result->EOF
) {
106 $row =& $result->getRowAssoc(false);
107 $value = $this->convertFromDB($row['setting_value'], $row['setting_type']);
108 $userSettings[$row['setting_name']] = $value;
114 return $userSettings;
118 * Add/update a user setting.
120 * @param $name string
121 * @param $value mixed
122 * @param $type string data type of the setting. If omitted, type will be guessed
123 * @param $assocType int
124 * @param $assocId int
126 function updateSetting($userId, $name, $value, $type = null, $assocType = null, $assocId = null) {
127 $result = $this->retrieve(
130 WHERE user_id = ? AND
134 array((int) $userId, $name, (int) $assocType, (int) $assocId)
137 $value = $this->convertToDB($value, $type);
138 if ($result->fields
[0] == 0) {
139 $returner = $this->update(
140 'INSERT INTO user_settings
141 (user_id, setting_name, assoc_type, assoc_id, setting_value, setting_type)
154 $returner = $this->update(
155 'UPDATE user_settings
156 SET setting_value = ?,
158 WHERE user_id = ? AND
180 * Delete a user setting.
182 * @param $name string
183 * @param $assocType int
184 * @param $assocId int
186 function deleteSetting($userId, $name, $assocType = null, $assocId = null) {
187 return $this->update(
188 'DELETE FROM user_settings WHERE user_id = ? AND setting_name = ? AND assoc_type = ? AND assoc_id = ?',
189 array((int) $userId, $name, (int) $assocType, (int) $assocId)
194 * Delete all settings for a user.
197 function deleteSettings($userId) {
198 return $this->update(
199 'DELETE FROM user_settings WHERE user_id = ?', $userId