Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
PKPSignoffDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.signoff.Signoff');
19 
20 class PKPSignoffDAO extends DAO {
24  function PKPSignoffDAO() {
25  parent::DAO();
26  }
27 
33  function getById($signoffId, $assocType = null, $assocId = null) {
34  $params = array((int) $signoffId);
35  if ($assocType !== null) $params[] = (int) $assocType;
36  if ($assocId !== null) $params[] = (int) $assocId;
37  $result =& $this->retrieve(
38  'SELECT * FROM signoffs WHERE signoff_id = ?'
39  . ($assocType !== null?' AND assoc_type = ?':'')
40  . ($assocId !== null?' AND assoc_id = ?':''),
41  $params
42  );
43 
44  $returner = null;
45  if ($result->RecordCount() != 0) {
46  $returner =& $this->_fromRow($result->GetRowAssoc(false));
47  }
48  $result->Close();
49  return $returner;
50  }
51 
64  function &build($symbolic, $assocType, $assocId, $userId = null,
65  $userGroupId = null, $fileId = null, $fileRevision = null) {
66 
67  // If one exists, fetch and return.
68  $signoff = $this->getBySymbolic(
69  $symbolic, $assocType, $assocId, $userId,
70  $userGroupId, $fileId, $fileRevision
71  );
72  if ($signoff) return $signoff;
73 
74  // Otherwise, build one.
75  unset($signoff);
76  $signoff = $this->newDataObject();
77  $signoff->setSymbolic($symbolic);
78  $signoff->setAssocType($assocType);
79  $signoff->setAssocId($assocId);
80  $signoff->setUserId($userId);
81  $signoff->setUserGroupId($userGroupId);
82  $signoff->setFileId($fileId);
83  $signoff->setFileRevision($fileRevision);
84  $this->insertObject($signoff);
85  return $signoff;
86  }
87 
97  function signoffExists($symbolic, $assocType, $assocId, $userId = null, $userGroupId = null) {
98  $sql = 'SELECT COUNT(*) FROM signoffs WHERE symbolic = ? AND assoc_type = ? AND assoc_id = ?';
99  $params = array($symbolic, (int) $assocType, (int) $assocId);
100 
101  if ($userId) {
102  $sql .= ' AND user_id = ?';
103  $params[] = (int) $userId;
104  }
105 
106  if ($userGroupId) {
107  $sql .= ' AND user_group_id = ?';
108  $params[] = (int) $userGroupId;
109  }
110 
111  $result =& $this->retrieve($sql, $params);
112 
113  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
114 
115  $result->Close();
116  unset($result);
117 
118  return $returner;
119  }
120 
125  function newDataObject() {
126  return new Signoff();
127  }
128 
134  function &_fromRow(&$row) {
135  $signoff = $this->newDataObject();
136 
137  $signoff->setId($row['signoff_id']);
138  $signoff->setAssocType($row['assoc_type']);
139  $signoff->setAssocId($row['assoc_id']);
140  $signoff->setSymbolic($row['symbolic']);
141  $signoff->setUserId($row['user_id']);
142  $signoff->setFileId($row['file_id']);
143  $signoff->setFileRevision($row['file_revision']);
144  $signoff->setDateNotified($this->datetimeFromDB($row['date_notified']));
145  $signoff->setDateUnderway($this->datetimeFromDB($row['date_underway']));
146  $signoff->setDateCompleted($this->datetimeFromDB($row['date_completed']));
147  $signoff->setDateAcknowledged($this->datetimeFromDB($row['date_acknowledged']));
148  $signoff->setUserGroupId($row['user_group_id']);
149 
150  return $signoff;
151  }
152 
158  function insertObject(&$signoff) {
159  $this->update(
160  sprintf(
161  'INSERT INTO signoffs
162  (symbolic, assoc_type, assoc_id, user_id, user_group_id, file_id, file_revision, date_notified, date_underway, date_completed, date_acknowledged)
163  VALUES
164  (?, ?, ?, ?, ?, ?, ?, %s, %s, %s, %s)',
165  $this->datetimeToDB($signoff->getDateNotified()),
166  $this->datetimeToDB($signoff->getDateUnderway()),
167  $this->datetimeToDB($signoff->getDateCompleted()),
168  $this->datetimeToDB($signoff->getDateAcknowledged())
169  ),
170  array(
171  $signoff->getSymbolic(),
172  (int) $signoff->getAssocType(),
173  (int) $signoff->getAssocId(),
174  (int) $signoff->getUserId(),
175  $this->nullOrInt($signoff->getUserGroupId()),
176  $this->nullOrInt($signoff->getFileId()),
177  $this->nullOrInt($signoff->getFileRevision())
178  )
179  );
180  $signoff->setId($this->getInsertId());
181  return $signoff->getId();
182  }
183 
189  function updateObject(&$signoff) {
190  $returner = $this->update(
191  sprintf(
192  'UPDATE signoffs
193  SET symbolic = ?,
194  assoc_type = ?,
195  assoc_id = ?,
196  user_id = ?,
197  user_group_id = ?,
198  file_id = ?,
199  file_revision = ?,
200  date_notified = %s,
201  date_underway = %s,
202  date_completed = %s,
203  date_acknowledged = %s
204  WHERE signoff_id = ?',
205  $this->datetimeToDB($signoff->getDateNotified()),
206  $this->datetimeToDB($signoff->getDateUnderway()),
207  $this->datetimeToDB($signoff->getDateCompleted()),
208  $this->datetimeToDB($signoff->getDateAcknowledged())
209  ),
210  array(
211  $signoff->getSymbolic(),
212  (int) $signoff->getAssocType(),
213  (int) $signoff->getAssocId(),
214  (int) $signoff->getUserId(),
215  $this->nullOrInt($signoff->getUserGroupId()),
216  $this->nullOrInt($signoff->getFileId()),
217  $this->nullOrInt($signoff->getFileRevision()),
218  (int) $signoff->getId()
219  )
220  );
221  return $returner;
222  }
223 
229  function deleteObject($signoff) {
230  return $this->deleteObjectById($signoff->getId());
231  }
232 
238  function deleteObjectById($signoffId) {
239  return $this->update('DELETE FROM signoffs WHERE signoff_id = ?', array((int) $signoffId));
240  }
241 
254  function &getBySymbolic($symbolic, $assocType, $assocId, $userId = null,
255  $userGroupId = null, $fileId = null, $fileRevision = null) {
256 
257  $sql = 'SELECT * FROM signoffs WHERE symbolic = ? AND assoc_type = ? AND assoc_id = ?';
258  $params = array($symbolic, (int) $assocType, (int) $assocId);
259 
260  if ($userId) {
261  $sql .= ' AND user_id = ?';
262  $params[] = (int) $userId;
263  }
264 
265  if ($userGroupId) {
266  $sql .= ' AND user_group_id = ?';
267  $params[] = (int) $userGroupId;
268  }
269 
270  if ($fileId) {
271  $sql .= ' AND file_id = ?';
272  $params[] = (int) $fileId;
273  }
274 
275  if ($fileRevision) {
276  $sql .= ' AND file_revision = ?';
277  $params[] = (int) $fileRevision;
278  }
279 
280  $result =& $this->retrieve($sql, $params);
281 
282  $returner = null;
283  if ($result->RecordCount() != 0) {
284  $returner = $this->_fromRow($result->GetRowAssoc(false));
285  }
286  $result->Close();
287  return $returner;
288  }
289 
300  function &getAllBySymbolic($symbolic, $assocType = null, $assocId = null, $userId = null, $userGroupId = null) {
301  $returner =& $this->_getAllInternally($symbolic, $assocType, $assocId, $userId, $userGroupId);
302  return $returner;
303  }
304 
315  function &getAllByAssocType($assocType, $assocId, $symbolic = null, $userId = null, $userGroupId = null) {
316  $returner =& $this->_getAllInternally($symbolic, $assocType, $assocId, $userId, $userGroupId);
317  return $returner;
318  }
319 
325  function &getByUserId($userId) {
326  $sql = 'SELECT * FROM signoffs WHERE user_id = ?';
327  $params = array((int) $userId);
328 
329  $result =& $this->retrieve($sql, $params);
330 
331  $returner = new DAOResultFactory($result, $this, '_fromRow', array('id'));
332  return $returner;
333  }
334 
341  function &getByFileRevision($fileId, $revision = null) {
342  $sql = 'SELECT * FROM signoffs WHERE file_id = ?';
343  $params = array((int)$fileId);
344  if ($revision) {
345  $sql .= ' AND file_revision = ?';
346  $params[] = (int)$revision;
347  }
348  $result =& $this->retrieve($sql, $params);
349  $returner = new DAOResultFactory($result, $this, '_fromRow', array('id'));
350  return $returner;
351  }
352 
363  function &getUsersBySymbolic($symbolic, $assocType, $assocId, $userGroupId = null, $unique = true) {
364  $selectDistinct = $unique ? 'SELECT DISTINCT' : 'SELECT';
365 
366  $sql = $selectDistinct . ' u.* FROM users u, signoffs s
367  WHERE u.user_id = s.user_id AND s.symbolic = ? AND s.assoc_type = ? AND s.assoc_id = ?';
368  $params = array($symbolic, (int) $assocType, (int) $assocId);
369 
370  if ($userGroupId) {
371  $sql .= ' AND s.user_group_id = ?';
372  $params[] = (int) $userGroupId;
373  }
374 
375  $result =& $this->retrieve($sql, $params);
376 
377  $userDao =& DAORegistry::getDAO('UserDAO');
378  $returner = new DAOResultFactory($result, $userDao, '_returnUserFromRow');
379  return $returner;
380  }
381 
387  function transferSignoffs($oldUserId, $newUserId) {
388  return $this->update(
389  'UPDATE signoffs
390  SET user_id = ?
391  WHERE user_id = ?',
392  array(
393  (int) $oldUserId,
394  (int) $newUserId
395  )
396  );
397  }
398 
403  function getInsertId() {
404  return parent::getInsertId('signoffs', 'signoff_id');
405  }
406 
411  function getAllSymbolics() {
412  return array(
413  'SIGNOFF_COPYEDITING',
414  'SIGNOFF_PROOFING',
415  'SIGNOFF_FAIR_COPY',
416  'SIGNOFF_REVIEW_REVISION',
417  'SIGNOFF_SIGNOFF'
418  );
419  }
420 
421 
422  //
423  // Private helper methods.
424  //
435  function &_getAllInternally($symbolic = null, $assocType = null, $assocId = null, $userId = null, $userGroupId = null) {
436  $sql = 'SELECT * FROM signoffs';
437 
438  if ($symbolic) {
439  $conditions[] = 'symbolic = ?';
440  $params[] = $symbolic;
441  }
442 
443  if ($assocType) {
444  $conditions[] = 'assoc_type = ?';
445  $params[] = (int) $assocType;
446  }
447 
448  if ($assocId) {
449  $conditions[] = 'assoc_id = ?';
450  $params[] = (int) $assocId;
451  }
452 
453  if ($userId) {
454  $conditions[] = 'user_id = ?';
455  $params[] = (int) $userId;
456  }
457 
458  if ($userGroupId) {
459  $conditions[] = 'user_group_id = ?';
460  $params[] = (int) $userGroupId;
461  }
462 
463  if (count($conditions) > 0) {
464  $sql .= ' WHERE ' . implode(' AND ', $conditions);
465  }
466 
467  $sql .= ' ORDER BY signoff_id';
468 
469  $result =& $this->retrieve($sql, $params);
470 
471  $returner = new DAOResultFactory($result, $this, '_fromRow', array('id'));
472  return $returner;
473  }
474 }
475 
476 ?>
& getByUserId($userId)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
deleteObject($signoff)
Basic class describing a signoff.
Definition: Signoff.inc.php:22
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
& build($symbolic, $assocType, $assocId, $userId=null, $userGroupId=null, $fileId=null, $fileRevision=null)
updateObject(&$signoff)
& getBySymbolic($symbolic, $assocType, $assocId, $userId=null, $userGroupId=null, $fileId=null, $fileRevision=null)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
insertObject(&$signoff)
Operations for retrieving and modifying Signoff objects.
deleteObjectById($signoffId)
& getDAO($name, $dbconn=null)
& getAllBySymbolic($symbolic, $assocType=null, $assocId=null, $userId=null, $userGroupId=null)
& getByFileRevision($fileId, $revision=null)
& getUsersBySymbolic($symbolic, $assocType, $assocId, $userGroupId=null, $unique=true)
datetimeToDB($dt)
Definition: DAO.inc.php:296
transferSignoffs($oldUserId, $newUserId)
signoffExists($symbolic, $assocType, $assocId, $userId=null, $userGroupId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getAllByAssocType($assocType, $assocId, $symbolic=null, $userId=null, $userGroupId=null)
getById($signoffId, $assocType=null, $assocId=null)
& _getAllInternally($symbolic=null, $assocType=null, $assocId=null, $userId=null, $userGroupId=null)