Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
ReviewAssignmentDAO.inc.php
1 <?php
2 
17 import('classes.submission.reviewAssignment.ReviewAssignment');
18 import('lib.pkp.classes.submission.reviewAssignment.PKPReviewAssignmentDAO');
19 
21  var $articleFileDao;
22  var $suppFileDao;
23  var $articleCommentsDao;
24 
28  function ReviewAssignmentDAO() {
29  parent::PKPReviewAssignmentDAO();
30  $this->articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
31  $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
32  $this->articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
33  }
34 
40  function _getSubmissionReviewFileId($submissionId) {
41  $result =& $this->retrieve(
42  'SELECT review_file_id FROM articles WHERE article_id = ?',
43  (int) $submissionId
44  );
45  $returner = isset($result->fields[0]) ? $result->fields[0] : null;
46  $result->Close();
47  unset($result);
48  return $returner;
49  }
50 
56  function &getReviewAssignmentById($reviewId) {
57  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
58  $returner =& $this->getById($reviewId);
59  return $returner;
60  }
61 
67  function &getReviewAssignmentsByArticleId($articleId, $round = null) {
68  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
69  $returner =& $this->getBySubmissionId($articleId, $round);
70  return $returner;
71  }
72 
78  function &getReviewAssignmentsByUserId($userId) {
79  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
80  $returner =& $this->getByUserId($userId);
81  return $returner;
82  }
83 
89  function &getReviewAssignmentsByReviewFormId($reviewFormId) {
90  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
91  $returner =& $this->getByReviewFormId($reviewFormId);
92  return $returner;
93  }
94 
100  function &getReviewFilesByRound($articleId) {
101  $returner = array();
102 
103  $result =& $this->retrieve(
104  'SELECT f.*, r.round as round
105  FROM review_rounds r,
106  article_files f,
107  articles a
108  WHERE a.article_id = r.submission_id AND
109  r.submission_id = ? AND
110  r.submission_id = f.article_id AND
111  f.file_id = a.review_file_id AND
112  f.revision = r.review_revision',
113  (int) $articleId
114  );
115 
116  while (!$result->EOF) {
117  $row = $result->GetRowAssoc(false);
118  $returner[$row['round']] =& $this->articleFileDao->_returnArticleFileFromRow($row);
119  $result->MoveNext();
120  }
121 
122  $result->Close();
123  unset($result);
124 
125  return $returner;
126  }
127 
133  function &getAuthorViewableFilesByRound($articleId) {
134  $files = array();
135 
136  $result =& $this->retrieve(
137  'SELECT f.*, r.reviewer_id, r.review_id
138  FROM review_assignments r,
139  article_files f
140  WHERE reviewer_file_id = file_id AND
141  viewable = 1 AND
142  r.submission_id = ?
143  ORDER BY r.round, r.reviewer_id, r.review_id',
144  array((int) $articleId)
145  );
146 
147  while (!$result->EOF) {
148  $row = $result->GetRowAssoc(false);
149  if (!isset($files[$row['round']]) || !is_array($files[$row['round']])) {
150  $files[$row['round']] = array();
151  $thisReviewerId = $row['reviewer_id'];
152  $reviewerIndex = 0;
153  } else if ($thisReviewerId != $row['reviewer_id']) {
154  $thisReviewerId = $row['reviewer_id'];
155  $reviewerIndex++;
156  }
157 
158  $thisArticleFile =& $this->articleFileDao->_returnArticleFileFromRow($row);
159  $files[$row['round']][$reviewerIndex][$row['review_id']][] = $thisArticleFile;
160  $result->MoveNext();
161  }
162 
163  $result->Close();
164  unset($result);
165 
166  return $files;
167  }
168 
174  function deleteReviewAssignmentsByArticle($articleId) {
175  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
176  return $this->deleteBySubmissionId($articleId);
177  }
178 
183  function getAverageQualityRatings($journalId) {
184  $averageQualityRatings = Array();
185  $result =& $this->retrieve(
186  'SELECT r.reviewer_id, AVG(r.quality) AS average, COUNT(r.quality) AS count
187  FROM review_assignments r, articles a
188  WHERE r.submission_id = a.article_id AND
189  a.journal_id = ?
190  GROUP BY r.reviewer_id',
191  (int) $journalId
192  );
193 
194  while (!$result->EOF) {
195  $row = $result->GetRowAssoc(false);
196  $averageQualityRatings[$row['reviewer_id']] = array('average' => $row['average'], 'count' => $row['count']);
197  $result->MoveNext();
198  }
199 
200  $result->Close();
201  unset($result);
202 
203  return $averageQualityRatings;
204  }
205 
210  function getCompletedReviewCounts($journalId) {
211  $returner = Array();
212  $result =& $this->retrieve(
213  'SELECT r.reviewer_id, COUNT(r.review_id) AS count
214  FROM review_assignments r,
215  articles a
216  WHERE r.submission_id = a.article_id AND
217  a.journal_id = ? AND
218  r.date_completed IS NOT NULL AND
219  r.cancelled = 0
220  GROUP BY r.reviewer_id',
221  (int) $journalId
222  );
223 
224  while (!$result->EOF) {
225  $row = $result->GetRowAssoc(false);
226  $returner[$row['reviewer_id']] = $row['count'];
227  $result->MoveNext();
228  }
229 
230  $result->Close();
231  unset($result);
232 
233  return $returner;
234  }
235 
240  function newDataObject() {
241  $reviewAssignment = new ReviewAssignment();
242  $reviewAssignment->setStageId(1); // Ensure correct default is used
243  return $reviewAssignment;
244  }
245 
251  function &_fromRow(&$row) {
252  $reviewAssignment =& parent::_fromRow($row);
253  $reviewFileId = $this->_getSubmissionReviewFileId($reviewAssignment->getSubmissionId());
254  $reviewAssignment->setReviewFileId($reviewFileId);
255 
256  // Files
257  $reviewAssignment->setReviewFile($this->articleFileDao->getArticleFile($reviewFileId, $row['review_revision']));
258  $reviewAssignment->setReviewerFile($this->articleFileDao->getArticleFile($row['reviewer_file_id']));
259  $reviewAssignment->setReviewerFileRevisions($this->articleFileDao->getArticleFileRevisions($row['reviewer_file_id']));
260  $reviewAssignment->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['submission_id']));
261 
262  // Comments
263  $reviewAssignment->setMostRecentPeerReviewComment($this->articleCommentDao->getMostRecentArticleComment($row['submission_id'], COMMENT_TYPE_PEER_REVIEW, $row['review_id']));
264 
265  HookRegistry::call('ReviewAssignmentDAO::_fromRow', array(&$reviewAssignment, &$row));
266  return $reviewAssignment;
267  }
268 
272  function getReviewRoundJoin() {
273  return 'r.submission_id = r2.submission_id AND r.round = r2.round';
274  }
275 }
276 
277 ?>
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
deleteReviewAssignmentsByArticle($articleId)
& getBySubmissionId($submissionId, $round=null, $stageId=null)
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
_getSubmissionReviewFileId($submissionId)
& getDAO($name, $dbconn=null)
& getAuthorViewableFilesByRound($articleId)
call($hookName, $args=null)
Class for DAO relating reviewers to submissions.
& getReviewAssignmentsByReviewFormId($reviewFormId)
& getReviewAssignmentsByArticleId($articleId, $round=null)
Describes review assignment properties.
Class for DAO relating reviewers to articles.