Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
PKPUserSettingsDAO.inc.php
1 <?php
2 
18 class PKPUserSettingsDAO extends DAO {
22  function PKPUserSettingsDAO() {
23  parent::DAO();
24  }
25 
34  function &getSetting($userId, $name, $assocType = null, $assocId = null) {
35  $result =& $this->retrieve(
36  'SELECT setting_value,
37  setting_type
38  FROM user_settings
39  WHERE user_id = ? AND
40  setting_name = ? AND
41  assoc_type = ? AND
42  assoc_id = ?',
43  array(
44  (int) $userId,
45  $name,
46  (int) $assocType,
47  (int) $assocId
48  )
49  );
50 
51  if ($result->RecordCount() != 0) {
52  $row =& $result->getRowAssoc(false);
53  $returner = $this->convertFromDB($row['setting_value'], $row['setting_type']);
54  } else {
55  $returner = null;
56  }
57 
58  return $returner;
59  }
60 
70  function &getUsersBySetting($name, $value, $type = null, $assocType = null, $assocId = null) {
71  $userDao =& DAORegistry::getDAO('UserDAO');
72 
73  $value = $this->convertToDB($value, $type);
74  $result =& $this->retrieve(
75  'SELECT u.*
76  FROM users u,
77  user_settings s
78  WHERE u.user_id = s.user_id AND
79  s.setting_name = ? AND
80  s.setting_value = ? AND
81  s.assoc_type = ? AND
82  s.assoc_id = ?',
83  array($name, $value, (int) $assocType, (int) $assocId)
84  );
85 
86  $returner = new DAOResultFactory($result, $userDao, '_returnUserFromRow');
87  return $returner;
88  }
89 
97  function &getSettingsByAssoc($userId, $assocType = null, $assocId = null) {
98  $userSettings = array();
99 
100  $result =& $this->retrieve(
101  'SELECT setting_name,
102  setting_value,
103  setting_type
104  FROM user_settings
105  WHERE user_id = ? AND
106  assoc_type = ?
107  AND assoc_id = ?',
108  array((int) $userId, (int) $assocType, (int) $assocId)
109  );
110 
111  while (!$result->EOF) {
112  $row =& $result->getRowAssoc(false);
113  $value = $this->convertFromDB($row['setting_value'], $row['setting_type']);
114  $userSettings[$row['setting_name']] = $value;
115  $result->MoveNext();
116  }
117  $result->Close();
118  unset($result);
119 
120  return $userSettings;
121  }
122 
132  function updateSetting($userId, $name, $value, $type = null, $assocType = null, $assocId = null) {
133  $result = $this->retrieve(
134  'SELECT COUNT(*)
135  FROM user_settings
136  WHERE user_id = ? AND
137  setting_name = ?
138  AND assoc_type = ?
139  AND assoc_id = ?',
140  array((int) $userId, $name, (int) $assocType, (int) $assocId)
141  );
142 
143  $value = $this->convertToDB($value, $type);
144  if ($result->fields[0] == 0) {
145  $returner = $this->update(
146  'INSERT INTO user_settings
147  (user_id, setting_name, assoc_type, assoc_id, setting_value, setting_type)
148  VALUES
149  (?, ?, ?, ?, ?, ?)',
150  array(
151  (int) $userId,
152  $name,
153  (int) $assocType,
154  (int) $assocId,
155  $value,
156  $type
157  )
158  );
159  } else {
160  $returner = $this->update(
161  'UPDATE user_settings
162  SET setting_value = ?,
163  setting_type = ?
164  WHERE user_id = ? AND
165  setting_name = ? AND
166  assoc_type = ?
167  AND assoc_id = ?',
168  array(
169  $value,
170  $type,
171  (int) $userId,
172  $name,
173  (int) $assocType,
174  (int) $assocId
175  )
176  );
177  }
178 
179  $result->Close();
180  unset($result);
181 
182  return $returner;
183  }
184 
192  function deleteSetting($userId, $name, $assocType = null, $assocId = null) {
193  return $this->update(
194  'DELETE FROM user_settings WHERE user_id = ? AND setting_name = ? AND assoc_type = ? AND assoc_id = ?',
195  array((int) $userId, $name, (int) $assocType, (int) $assocId)
196  );
197  }
198 
203  function deleteSettings($userId) {
204  return $this->update(
205  'DELETE FROM user_settings WHERE user_id = ?', $userId
206  );
207  }
208 }
209 
210 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
deleteSetting($userId, $name, $assocType=null, $assocId=null)
& getSetting($userId, $name, $assocType=null, $assocId=null)
& getUsersBySetting($name, $value, $type=null, $assocType=null, $assocId=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
updateSetting($userId, $name, $value, $type=null, $assocType=null, $assocId=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
convertFromDB($value, $type)
Definition: DAO.inc.php:338
& getDAO($name, $dbconn=null)
convertToDB($value, &$type)
Definition: DAO.inc.php:394
& getSettingsByAssoc($userId, $assocType=null, $assocId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
Operations for retrieving and modifying user settings.