Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SignoffDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.signoff.Signoff');
19 
20 class SignoffDAO extends DAO {
24  function SignoffDAO() {
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  $signoff = $this->newDataObject();
76  $signoff->setSymbolic($symbolic);
77  $signoff->setAssocType($assocType);
78  $signoff->setAssocId($assocId);
79  $signoff->setUserId($userId);
80  $signoff->setUserGroupId($userGroupId);
81  $signoff->setFileId($fileId);
82  $signoff->setFileRevision($fileRevision);
83  $this->insertObject($signoff);
84  return $signoff;
85  }
86 
96  function signoffExists($symbolic, $assocType, $assocId, $userId = null, $userGroupId = null) {
97  $sql = 'SELECT COUNT(*) FROM signoffs WHERE symbolic = ? AND assoc_type = ? AND assoc_id = ?';
98  $params = array($symbolic, (int) $assocType, (int) $assocId);
99 
100  if ($userId) {
101  $sql .= ' AND user_id = ?';
102  $params[] = (int) $userId;
103  }
104 
105  if ($userGroupId) {
106  $sql .= ' AND user_group_id = ?';
107  $params[] = (int) $userGroupId;
108  }
109 
110  $result = $this->retrieve($sql, $params);
111 
112  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
113 
114  $result->Close();
115  return $returner;
116  }
117 
122  function newDataObject() {
123  return new Signoff();
124  }
125 
131  function _fromRow($row) {
132  $signoff = $this->newDataObject();
133 
134  $signoff->setId($row['signoff_id']);
135  $signoff->setAssocType($row['assoc_type']);
136  $signoff->setAssocId($row['assoc_id']);
137  $signoff->setSymbolic($row['symbolic']);
138  $signoff->setUserId($row['user_id']);
139  $signoff->setFileId($row['file_id']);
140  $signoff->setFileRevision($row['file_revision']);
141  $signoff->setDateNotified($this->datetimeFromDB($row['date_notified']));
142  $signoff->setDateUnderway($this->datetimeFromDB($row['date_underway']));
143  $signoff->setDateCompleted($this->datetimeFromDB($row['date_completed']));
144  $signoff->setDateAcknowledged($this->datetimeFromDB($row['date_acknowledged']));
145  $signoff->setUserGroupId($row['user_group_id']);
146 
147  return $signoff;
148  }
149 
155  function insertObject($signoff) {
156  $this->update(
157  sprintf(
158  'INSERT INTO signoffs
159  (symbolic, assoc_type, assoc_id, user_id, user_group_id, file_id, file_revision, date_notified, date_underway, date_completed, date_acknowledged)
160  VALUES
161  (?, ?, ?, ?, ?, ?, ?, %s, %s, %s, %s)',
162  $this->datetimeToDB($signoff->getDateNotified()),
163  $this->datetimeToDB($signoff->getDateUnderway()),
164  $this->datetimeToDB($signoff->getDateCompleted()),
165  $this->datetimeToDB($signoff->getDateAcknowledged())
166  ),
167  array(
168  $signoff->getSymbolic(),
169  (int) $signoff->getAssocType(),
170  (int) $signoff->getAssocId(),
171  (int) $signoff->getUserId(),
172  $this->nullOrInt($signoff->getUserGroupId()),
173  $this->nullOrInt($signoff->getFileId()),
174  $this->nullOrInt($signoff->getFileRevision())
175  )
176  );
177  $signoff->setId($this->getInsertId());
178  return $signoff->getId();
179  }
180 
186  function updateObject($signoff) {
187  $returner = $this->update(
188  sprintf(
189  'UPDATE signoffs
190  SET symbolic = ?,
191  assoc_type = ?,
192  assoc_id = ?,
193  user_id = ?,
194  user_group_id = ?,
195  file_id = ?,
196  file_revision = ?,
197  date_notified = %s,
198  date_underway = %s,
199  date_completed = %s,
200  date_acknowledged = %s
201  WHERE signoff_id = ?',
202  $this->datetimeToDB($signoff->getDateNotified()),
203  $this->datetimeToDB($signoff->getDateUnderway()),
204  $this->datetimeToDB($signoff->getDateCompleted()),
205  $this->datetimeToDB($signoff->getDateAcknowledged())
206  ),
207  array(
208  $signoff->getSymbolic(),
209  (int) $signoff->getAssocType(),
210  (int) $signoff->getAssocId(),
211  (int) $signoff->getUserId(),
212  $this->nullOrInt($signoff->getUserGroupId()),
213  $this->nullOrInt($signoff->getFileId()),
214  $this->nullOrInt($signoff->getFileRevision()),
215  (int) $signoff->getId()
216  )
217  );
218  return $returner;
219  }
220 
226  function deleteObject($signoff) {
227  assert(is_a($signoff, 'Signoff'));
228  return $this->deleteObjectById($signoff->getId());
229  }
230 
236  function deleteObjectById($signoffId) {
237  $this->update('DELETE FROM notifications WHERE assoc_type = ? AND assoc_id = ?', array((int) ASSOC_TYPE_SIGNOFF, (int) $signoffId));
238  return $this->update('DELETE FROM signoffs WHERE signoff_id = ?', array((int) $signoffId));
239  }
240 
253  function getBySymbolic($symbolic, $assocType, $assocId, $userId = null,
254  $userGroupId = null, $fileId = null, $fileRevision = null) {
255 
256  $sql = 'SELECT * FROM signoffs WHERE symbolic = ? AND assoc_type = ? AND assoc_id = ?';
257  $params = array($symbolic, (int) $assocType, (int) $assocId);
258 
259  if ($userId) {
260  $sql .= ' AND user_id = ?';
261  $params[] = (int) $userId;
262  }
263 
264  if ($userGroupId) {
265  $sql .= ' AND user_group_id = ?';
266  $params[] = (int) $userGroupId;
267  }
268 
269  if ($fileId) {
270  $sql .= ' AND file_id = ?';
271  $params[] = (int) $fileId;
272  }
273 
274  if ($fileRevision) {
275  $sql .= ' AND file_revision = ?';
276  $params[] = (int) $fileRevision;
277  }
278 
279  $result = $this->retrieve($sql, $params);
280 
281  $returner = null;
282  if ($result->RecordCount() != 0) {
283  $returner = $this->_fromRow($result->GetRowAssoc(false));
284  }
285  $result->Close();
286  return $returner;
287  }
288 
299  function getAllBySymbolic($symbolic, $assocType = null, $assocId = null, $userId = null, $userGroupId = null) {
300  return $this->_getAllInternally($symbolic, $assocType, $assocId, $userId, $userGroupId);
301  }
302 
313  function getAllByAssocType($assocType, $assocId, $symbolic = null, $userId = null, $userGroupId = null) {
314  return $this->_getAllInternally($symbolic, $assocType, $assocId, $userId, $userGroupId);
315  }
316 
322  function getByUserId($userId) {
323  $sql = 'SELECT * FROM signoffs WHERE user_id = ?';
324  $params = array((int) $userId);
325 
326  $result = $this->retrieve($sql, $params);
327 
328  return new DAOResultFactory($result, $this, '_fromRow', array('id'));
329  }
330 
337  function getByFileRevision($fileId, $revision = null) {
338  $sql = 'SELECT * FROM signoffs WHERE file_id = ?';
339  $params = array((int)$fileId);
340  if ($revision) {
341  $sql .= ' AND file_revision = ?';
342  $params[] = (int)$revision;
343  }
344  $result = $this->retrieve($sql, $params);
345  return new DAOResultFactory($result, $this, '_fromRow', array('id'));
346  }
347 
358  function getUsersBySymbolic($symbolic, $assocType, $assocId, $userGroupId = null, $unique = true) {
359  $selectDistinct = $unique ? 'SELECT DISTINCT' : 'SELECT';
360 
361  $sql = $selectDistinct . ' u.* FROM users u, signoffs s
362  WHERE u.user_id = s.user_id AND s.symbolic = ? AND s.assoc_type = ? AND s.assoc_id = ?';
363  $params = array($symbolic, (int) $assocType, (int) $assocId);
364 
365  if ($userGroupId) {
366  $sql .= ' AND s.user_group_id = ?';
367  $params[] = (int) $userGroupId;
368  }
369 
370  $result = $this->retrieve($sql, $params);
371 
372  $userDao = DAORegistry::getDAO('UserDAO');
373  return new DAOResultFactory($result, $userDao, '_returnUserFromRow');
374  }
375 
380  function getStageIdBySymbolic($symbolic) {
381  switch ($symbolic) {
382  case 'SIGNOFF_COPYEDITING':
383  return WORKFLOW_STAGE_ID_EDITING;
384  break;
385  case 'SIGNOFF_PROOFING':
386  return WORKFLOW_STAGE_ID_PRODUCTION;
387  break;
388  default:
389  assert(false);
390  }
391  }
392 
398  function transferSignoffs($oldUserId, $newUserId) {
399  return $this->update(
400  'UPDATE signoffs
401  SET user_id = ?
402  WHERE user_id = ?',
403  array(
404  (int) $oldUserId,
405  (int) $newUserId
406  )
407  );
408  }
409 
414  function getInsertId() {
415  return parent::_getInsertId('signoffs', 'signoff_id');
416  }
417 
422  function getAllSymbolics() {
423  return array(
424  'SIGNOFF_COPYEDITING',
425  'SIGNOFF_PROOFING',
426  'SIGNOFF_FAIR_COPY',
427  'SIGNOFF_REVIEW_REVISION',
428  'SIGNOFF_SIGNOFF'
429  );
430  }
431 
432 
433  //
434  // Private helper methods.
435  //
446  function _getAllInternally($symbolic = null, $assocType = null, $assocId = null, $userId = null, $userGroupId = null) {
447  $sql = 'SELECT * FROM signoffs';
448 
449  if ($symbolic) {
450  $conditions[] = 'symbolic = ?';
451  $params[] = $symbolic;
452  }
453 
454  if ($assocType) {
455  $conditions[] = 'assoc_type = ?';
456  $params[] = (int) $assocType;
457  }
458 
459  if ($assocId) {
460  $conditions[] = 'assoc_id = ?';
461  $params[] = (int) $assocId;
462  }
463 
464  if ($userId) {
465  $conditions[] = 'user_id = ?';
466  $params[] = (int) $userId;
467  }
468 
469  if ($userGroupId) {
470  $conditions[] = 'user_group_id = ?';
471  $params[] = (int) $userGroupId;
472  }
473 
474  if (count($conditions) > 0) {
475  $sql .= ' WHERE ' . implode(' AND ', $conditions);
476  }
477 
478  $sql .= ' ORDER BY signoff_id';
479 
480  $result = $this->retrieve($sql, $params);
481 
482  return new DAOResultFactory($result, $this, '_fromRow', array('id'));
483  }
484 }
485 
486 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
Basic class describing a signoff.
Definition: Signoff.inc.php:23
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getBySymbolic($symbolic, $assocType, $assocId, $userId=null, $userGroupId=null, $fileId=null, $fileRevision=null)
getAllByAssocType($assocType, $assocId, $symbolic=null, $userId=null, $userGroupId=null)
deleteObject($signoff)
_getAllInternally($symbolic=null, $assocType=null, $assocId=null, $userId=null, $userGroupId=null)
getByFileRevision($fileId, $revision=null)
getUsersBySymbolic($symbolic, $assocType, $assocId, $userGroupId=null, $unique=true)
datetimeFromDB($dt)
Definition: DAO.inc.php:313
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
signoffExists($symbolic, $assocType, $assocId, $userId=null, $userGroupId=null)
getByUserId($userId)
Operations for retrieving and modifying Signoff objects.
transferSignoffs($oldUserId, $newUserId)
updateObject($signoff)
build($symbolic, $assocType, $assocId, $userId=null, $userGroupId=null, $fileId=null, $fileRevision=null)
getById($signoffId, $assocType=null, $assocId=null)
deleteObjectById($signoffId)
getStageIdBySymbolic($symbolic)
insertObject($signoff)
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getAllBySymbolic($symbolic, $assocType=null, $assocId=null, $userId=null, $userGroupId=null)