Open Journal Systems  3.0.0
 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  return $userSettings;
119  }
120 
130  function updateSetting($userId, $name, $value, $type = null, $assocType = null, $assocId = null) {
131  $result = $this->retrieve(
132  'SELECT COUNT(*)
133  FROM user_settings
134  WHERE user_id = ? AND
135  setting_name = ?
136  AND assoc_type = ?
137  AND assoc_id = ?',
138  array((int) $userId, $name, (int) $assocType, (int) $assocId)
139  );
140 
141  $value = $this->convertToDB($value, $type);
142  if ($result->fields[0] == 0) {
143  $returner = $this->update(
144  'INSERT INTO user_settings
145  (user_id, setting_name, assoc_type, assoc_id, setting_value, setting_type)
146  VALUES
147  (?, ?, ?, ?, ?, ?)',
148  array(
149  (int) $userId,
150  $name,
151  (int) $assocType,
152  (int) $assocId,
153  $value,
154  $type
155  )
156  );
157  } else {
158  $returner = $this->update(
159  'UPDATE user_settings
160  SET setting_value = ?,
161  setting_type = ?
162  WHERE user_id = ? AND
163  setting_name = ? AND
164  assoc_type = ?
165  AND assoc_id = ?',
166  array(
167  $value,
168  $type,
169  (int) $userId,
170  $name,
171  (int) $assocType,
172  (int) $assocId
173  )
174  );
175  }
176 
177  $result->Close();
178  return $returner;
179  }
180 
188  function deleteSetting($userId, $name, $assocType = null, $assocId = null) {
189  return $this->update(
190  'DELETE FROM user_settings WHERE user_id = ? AND setting_name = ? AND assoc_type = ? AND assoc_id = ?',
191  array((int) $userId, $name, (int) $assocType, (int) $assocId)
192  );
193  }
194 
199  function deleteSettings($userId) {
200  return $this->update(
201  'DELETE FROM user_settings WHERE user_id = ?', $userId
202  );
203  }
204 }
205 
206 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
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:84
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:335
convertToDB($value, &$type)
Definition: DAO.inc.php:391
& getSettingsByAssoc($userId, $assocType=null, $assocId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
Operations for retrieving and modifying user settings.