Open Journal Systems  3.3.0
EditDecisionDAO.inc.php
1 <?php
2 
16 // Bring in editor decision constants
17 // FIXME: These should be standardized into lib-pkp.
18 import('classes.workflow.EditorDecisionActionsManager');
19 
20 class EditDecisionDAO extends DAO {
21 
29  function updateEditorDecision($submissionId, $editorDecision, $stageId = null, $reviewRound = null) {
30  if ($editorDecision['editDecisionId'] == null) {
31  $this->update(
32  sprintf(
33  'INSERT INTO edit_decisions
34  (submission_id, review_round_id, stage_id, round, editor_id, decision, date_decided)
35  VALUES (?, ?, ?, ?, ?, ?, %s)',
36  $this->datetimeToDB($editorDecision['dateDecided'])
37  ),
38  array(
39  (int) $submissionId,
40  is_a($reviewRound, 'ReviewRound') ? (int) $reviewRound->getId() : 0,
41  is_a($reviewRound, 'ReviewRound') ? $reviewRound->getStageId() : (int) $stageId,
42  is_a($reviewRound, 'ReviewRound') ? (int) $reviewRound->getRound() : REVIEW_ROUND_NONE,
43  (int) $editorDecision['editorId'],
44  $editorDecision['decision']
45  )
46  );
47  }
48  }
49 
54  function deleteDecisionsBySubmissionId($submissionId) {
55  return $this->update(
56  'DELETE FROM edit_decisions WHERE submission_id = ?',
57  (int) $submissionId
58  );
59  }
60 
70  function getEditorDecisions($submissionId, $stageId = null, $round = null, $editorId = null) {
71  $params = array((int) $submissionId);
72  if ($stageId) $params[] = (int) $stageId;
73  if ($round) $params[] = (int) $round;
74  if ($editorId) $params[] = (int) $editorId;
75 
76  $result = $this->retrieve(
77  'SELECT edit_decision_id, editor_id, decision,
78  date_decided, review_round_id, stage_id, round
79  FROM edit_decisions
80  WHERE submission_id = ?
81  ' . ($stageId?' AND stage_id = ?':'') . '
82  ' . ($round?' AND round = ?':'') . '
83  ' . ($editorId?' AND editor_id = ?':'') . '
84  ORDER BY date_decided ASC',
85  $params
86  );
87 
88  $decisions = array();
89  while (!$result->EOF) {
90  $decisions[] = array(
91  'editDecisionId' => $result->fields['edit_decision_id'],
92  'reviewRoundId' => $result->fields['review_round_id'],
93  'stageId' => $result->fields['stage_id'],
94  'round' => $result->fields['round'],
95  'editorId' => $result->fields['editor_id'],
96  'decision' => $result->fields['decision'],
97  'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
98  );
99  $result->MoveNext();
100  }
101  $result->Close();
102  return $decisions;
103  }
104 
110  function transferEditorDecisions($oldUserId, $newUserId) {
111  $this->update(
112  'UPDATE edit_decisions SET editor_id = ? WHERE editor_id = ?',
113  array((int) $newUserId, (int) $oldUserId)
114  );
115  }
116 
126  function findValidPendingRevisionsDecision($submissionId, $expectedStageId, $revisionDecision = SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS) {
127  $postReviewDecisions = array(SUBMISSION_EDITOR_DECISION_SEND_TO_PRODUCTION);
128  $revisionDecisions = array(SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS, SUBMISSION_EDITOR_DECISION_RESUBMIT);
129  if (!in_array($revisionDecision, $revisionDecisions)) return null;
130 
131  $editDecisionDao = DAORegistry::getDAO('EditDecisionDAO'); /* @var $editDecisionDao EditDecisionDAO */
132  $editorDecisions = $editDecisionDao->getEditorDecisions($submissionId);
133  $workingDecisions = array_reverse($editorDecisions);
134  $pendingRevisionDecision = null;
135 
136  foreach ($workingDecisions as $decision) {
137  if (in_array($decision['decision'], $postReviewDecisions)) {
138  // Decisions at later stages do not override the pending revisions one.
139  continue;
140  } elseif ($decision['decision'] == $revisionDecision) {
141  if ($decision['stageId'] == $expectedStageId) {
142  $pendingRevisionDecision = $decision;
143  // Only the last pending revisions decision is relevant.
144  break;
145  } else {
146  // Both internal and external pending revisions decisions are
147  // valid at the same time. Continue to search.
148  continue;
149  }
150 
151  } else {
152  break;
153  }
154  }
155 
156  return $pendingRevisionDecision;
157  }
158 
166  function responseExists($decision, $submissionId) {
167  $stageId = $decision['stageId'];
168  $round = $decision['round'];
169  $sentRevisions = false;
170 
171  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
172  $reviewRound = $reviewRoundDao->getReviewRound($submissionId, $stageId, $round);
173 
174  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
175  import('lib.pkp.classes.submission.SubmissionFile'); // Bring the file constants.
176  $submissionFiles = $submissionFileDao->getRevisionsByReviewRound($reviewRound, SUBMISSION_FILE_REVIEW_REVISION);
177 
178  if (is_array($submissionFiles)) {
179  foreach ($submissionFiles as $file) {
180  if ($file->getDateUploaded() > $decision['dateDecided']) {
181  $sentRevisions = true;
182  break;
183  }
184  }
185  }
186 
187  return $sentRevisions;
188  }
189 }
190 
191 
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
EditDecisionDAO\updateEditorDecision
updateEditorDecision($submissionId, $editorDecision, $stageId=null, $reviewRound=null)
Definition: EditDecisionDAO.inc.php:29
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
EditDecisionDAO\getEditorDecisions
getEditorDecisions($submissionId, $stageId=null, $round=null, $editorId=null)
Definition: EditDecisionDAO.inc.php:70
EditDecisionDAO
Operations for retrieving and modifying editor decisions.
Definition: EditDecisionDAO.inc.php:20
EditDecisionDAO\findValidPendingRevisionsDecision
findValidPendingRevisionsDecision($submissionId, $expectedStageId, $revisionDecision=SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS)
Definition: EditDecisionDAO.inc.php:126
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
EditDecisionDAO\responseExists
responseExists($decision, $submissionId)
Definition: EditDecisionDAO.inc.php:166
EditDecisionDAO\transferEditorDecisions
transferEditorDecisions($oldUserId, $newUserId)
Definition: EditDecisionDAO.inc.php:110
DAO\datetimeToDB
datetimeToDB($dt)
Definition: DAO.inc.php:299
EditDecisionDAO\deleteDecisionsBySubmissionId
deleteDecisionsBySubmissionId($submissionId)
Definition: EditDecisionDAO.inc.php:54
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31