Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
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 {
24  function EditDecisionDAO() {
25  parent::DAO();
26  }
27 
35  function updateEditorDecision($submissionId, $editorDecision, $stageId = null, $reviewRound = null) {
36  if ($editorDecision['editDecisionId'] == null) {
37  $this->update(
38  sprintf(
39  'INSERT INTO edit_decisions
40  (submission_id, review_round_id, stage_id, round, editor_id, decision, date_decided)
41  VALUES (?, ?, ?, ?, ?, ?, %s)',
42  $this->datetimeToDB($editorDecision['dateDecided'])
43  ),
44  array(
45  (int) $submissionId,
46  is_a($reviewRound, 'ReviewRound') ? (int) $reviewRound->getId() : 0,
47  is_a($reviewRound, 'ReviewRound') ? $reviewRound->getStageId() : (int) $stageId,
48  is_a($reviewRound, 'ReviewRound') ? (int) $reviewRound->getRound() : REVIEW_ROUND_NONE,
49  (int) $editorDecision['editorId'],
50  $editorDecision['decision']
51  )
52  );
53  }
54  }
55 
60  function deleteDecisionsBySubmissionId($submissionId) {
61  return $this->update(
62  'DELETE FROM edit_decisions WHERE submission_id = ?',
63  (int) $submissionId
64  );
65  }
66 
75  function getEditorDecisions($submissionId, $stageId = null, $round = null) {
76  $params = array((int) $submissionId);
77  if ($stageId) $params[] = (int) $stageId;
78  if ($round) $params[] = (int) $round;
79 
80  $result = $this->retrieve(
81  'SELECT edit_decision_id, editor_id, decision,
82  date_decided, review_round_id, stage_id, round
83  FROM edit_decisions
84  WHERE submission_id = ?
85  ' . ($stageId?' AND stage_id = ?':'') . '
86  ' . ($round?' AND round = ?':'') . '
87  ORDER BY date_decided ASC',
88  $params
89  );
90 
91  $decisions = array();
92  while (!$result->EOF) {
93  $decisions[] = array(
94  'editDecisionId' => $result->fields['edit_decision_id'],
95  'reviewRoundId' => $result->fields['review_round_id'],
96  'stageId' => $result->fields['stage_id'],
97  'round' => $result->fields['round'],
98  'editorId' => $result->fields['editor_id'],
99  'decision' => $result->fields['decision'],
100  'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
101  );
102  $result->MoveNext();
103  }
104  $result->Close();
105  return $decisions;
106  }
107 
113  function transferEditorDecisions($oldUserId, $newUserId) {
114  $this->update(
115  'UPDATE edit_decisions SET editor_id = ? WHERE editor_id = ?',
116  array((int) $newUserId, (int) $oldUserId)
117  );
118  }
119 
128  function findValidPendingRevisionsDecision($submissionId, $expectedStageId) {
129  $editDecisionDao = DAORegistry::getDAO('EditDecisionDAO');
130  $editorDecisions = $editDecisionDao->getEditorDecisions($submissionId);
131  $workingDecisions = array_reverse($editorDecisions);
132  $postReviewDecisions = array(SUBMISSION_EDITOR_DECISION_SEND_TO_PRODUCTION);
133  $pendingRevisionDecision = null;
134 
135  foreach ($workingDecisions as $decision) {
136  if (in_array($decision['decision'], $postReviewDecisions)) {
137  // Decisions at later stages do not override the pending revisions one.
138  continue;
139  } elseif ($decision['decision'] == SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS) {
140  if ($decision['stageId'] == $expectedStageId) {
141  $pendingRevisionDecision = $decision;
142  // Only the last pending revisions decision is relevant.
143  break;
144  } else {
145  // Both internal and external pending revisions decisions are
146  // valid at the same time. Continue to search.
147  continue;
148  }
149 
150  } else {
151  break;
152  }
153  }
154 
155  return $pendingRevisionDecision;
156  }
157 
165  function responseExists($decision, $submissionId) {
166  $stageId = $decision['stageId'];
167  $round = $decision['round'];
168  $sentRevisions = false;
169 
170  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO');
171  $reviewRound = $reviewRoundDao->getReviewRound($submissionId, $stageId, $round);
172 
173  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
174  import('lib.pkp.classes.submission.SubmissionFile'); // Bring the file constants.
175  $submissionFiles = $submissionFileDao->getRevisionsByReviewRound($reviewRound, SUBMISSION_FILE_REVIEW_REVISION);
176 
177  if (is_array($submissionFiles)) {
178  foreach ($submissionFiles as $file) {
179  if ($file->getDateUploaded() > $decision['dateDecided']) {
180  $sentRevisions = true;
181  break;
182  }
183  }
184  }
185 
186  return $sentRevisions;
187  }
188 }
189 
190 ?>
static & getDAO($name, $dbconn=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
findValidPendingRevisionsDecision($submissionId, $expectedStageId)
deleteDecisionsBySubmissionId($submissionId)
transferEditorDecisions($oldUserId, $newUserId)
updateEditorDecision($submissionId, $editorDecision, $stageId=null, $reviewRound=null)
Operations for retrieving and modifying editor decisions.
getEditorDecisions($submissionId, $stageId=null, $round=null)
responseExists($decision, $submissionId)
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208