Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
AuthorSubmissionDAO.inc.php
1 <?php
2 
17 import('classes.submission.author.AuthorSubmission');
18 
19 class AuthorSubmissionDAO extends DAO {
20  var $articleDao;
21  var $authorDao;
22  var $userDao;
23  var $reviewAssignmentDao;
24  var $articleFileDao;
25  var $suppFileDao;
26  var $copyeditorSubmissionDao;
27  var $articleCommentDao;
28  var $galleyDao;
29 
33  function AuthorSubmissionDAO() {
34  parent::DAO();
35  $this->articleDao =& DAORegistry::getDAO('ArticleDAO');
36  $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
37  $this->userDao =& DAORegistry::getDAO('UserDAO');
38  $this->reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
39  $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
40  $this->articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
41  $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
42  $this->copyeditorSubmissionDao =& DAORegistry::getDAO('CopyeditorSubmissionDAO');
43  $this->articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
44  $this->galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
45  }
46 
52  function &getAuthorSubmission($articleId) {
53  $primaryLocale = AppLocale::getPrimaryLocale();
54  $locale = AppLocale::getLocale();
55  $result =& $this->retrieve(
56  'SELECT a.*,
57  COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
58  COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
59  FROM articles a
60  LEFT JOIN sections s ON (s.section_id = a.section_id)
61  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
62  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
63  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
64  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
65  WHERE a.article_id = ?',
66  array(
67  'title',
68  $primaryLocale,
69  'title',
70  $locale,
71  'abbrev',
72  $primaryLocale,
73  'abbrev',
74  $locale,
75  $articleId,
76  )
77  );
78 
79  $returner = null;
80  if ($result->RecordCount() != 0) {
81  $returner =& $this->_returnAuthorSubmissionFromRow($result->GetRowAssoc(false));
82  }
83 
84  $result->Close();
85  unset($result);
86 
87  return $returner;
88  }
89 
95  function &_returnAuthorSubmissionFromRow(&$row) {
96  $authorSubmission = new AuthorSubmission();
97 
98  // Article attributes
99  $this->articleDao->_articleFromRow($authorSubmission, $row);
100 
101  // Editor Assignment
102  $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
103  $authorSubmission->setEditAssignments($editAssignments->toArray());
104 
105  // Editor Decisions
106  for ($i = 1; $i <= $row['current_round']; $i++) {
107  $authorSubmission->setDecisions($this->getEditorDecisions($row['article_id'], $i), $i);
108  }
109 
110  // Review Assignments
111  for ($i = 1; $i <= $row['current_round']; $i++) {
112  $authorSubmission->setReviewAssignments($this->reviewAssignmentDao->getBySubmissionId($row['article_id'], $i), $i);
113  }
114 
115  // Comments
116  $authorSubmission->setMostRecentEditorDecisionComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_EDITOR_DECISION, $row['article_id']));
117  $authorSubmission->setMostRecentCopyeditComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_COPYEDIT, $row['article_id']));
118  $authorSubmission->setMostRecentProofreadComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_PROOFREAD, $row['article_id']));
119  $authorSubmission->setMostRecentLayoutComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_LAYOUT, $row['article_id']));
120 
121  // Files
122  $authorSubmission->setSubmissionFile($this->articleFileDao->getArticleFile($row['submission_file_id']));
123  $authorSubmission->setRevisedFile($this->articleFileDao->getArticleFile($row['revised_file_id']));
124  $authorSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['article_id']));
125  for ($i = 1; $i <= $row['current_round']; $i++) {
126  $authorSubmission->setAuthorFileRevisions($this->articleFileDao->getArticleFileRevisions($row['revised_file_id'], $i), $i);
127  }
128  for ($i = 1; $i <= $row['current_round']; $i++) {
129  $authorSubmission->setEditorFileRevisions($this->articleFileDao->getArticleFileRevisions($row['editor_file_id'], $i), $i);
130  }
131  $authorSubmission->setGalleys($this->galleyDao->getGalleysByArticle($row['article_id']));
132 
133  HookRegistry::call('AuthorSubmissionDAO::_returnAuthorSubmissionFromRow', array(&$authorSubmission, &$row));
134 
135  return $authorSubmission;
136  }
137 
142  function updateAuthorSubmission(&$authorSubmission) {
143  // Update article
144  if ($authorSubmission->getId()) {
145  $article =& $this->articleDao->getArticle($authorSubmission->getId());
146 
147  // Only update fields that an author can actually edit.
148  $article->setRevisedFileId($authorSubmission->getRevisedFileId());
149  $article->setDateStatusModified($authorSubmission->getDateStatusModified());
150  $article->setLastModified($authorSubmission->getLastModified());
151  // FIXME: These two are necessary for designating the
152  // original as the review version, but they are probably
153  // best not exposed like this.
154  $article->setReviewFileId($authorSubmission->getReviewFileId());
155  $article->setEditorFileId($authorSubmission->getEditorFileId());
156 
157  $this->articleDao->updateArticle($article);
158  }
159 
160  }
161 
167  function &getAuthorSubmissions($authorId, $journalId, $active = true, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
168  $primaryLocale = AppLocale::getPrimaryLocale();
169  $locale = AppLocale::getLocale();
170  $result =& $this->retrieveRange(
171  'SELECT a.*,
172  COALESCE(atl.setting_value, atpl.setting_value) AS submission_title,
173  aa.last_name AS author_name,
174  COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
175  COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
176  FROM articles a
177  LEFT JOIN authors aa ON (aa.submission_id = a.article_id AND aa.primary_contact = 1)
178  LEFT JOIN article_settings atpl ON (atpl.article_id = a.article_id AND atpl.setting_name = ? AND atpl.locale = a.locale)
179  LEFT JOIN article_settings atl ON (atl.article_id = a.article_id AND atl.setting_name = ? AND atl.locale = ?)
180  LEFT JOIN sections s ON (s.section_id = a.section_id)
181  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
182  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
183  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
184  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
185  WHERE a.user_id = ? AND a.journal_id = ? AND ' .
186  ($active?('a.status = ' . STATUS_QUEUED):('(a.status <> ' . STATUS_QUEUED . ' AND a.submission_progress = 0)')) .
187  ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : ''),
188  array(
189  'cleanTitle',
190  'cleanTitle',
191  $locale,
192  'title',
193  $primaryLocale,
194  'title',
195  $locale,
196  'abbrev',
197  $primaryLocale,
198  'abbrev',
199  $locale,
200  $authorId,
201  $journalId
202  ),
203  $rangeInfo
204  );
205 
206  $returner = new DAOResultFactory($result, $this, '_returnAuthorSubmissionFromRow');
207  return $returner;
208  }
209 
210  //
211  // Miscellaneous
212  //
213 
219  function getEditorDecisions($articleId, $round = null) {
220  $decisions = array();
221 
222  if ($round == null) {
223  $result =& $this->retrieve(
224  'SELECT edit_decision_id, editor_id, decision, date_decided FROM edit_decisions WHERE article_id = ? ORDER BY date_decided ASC', $articleId
225  );
226  } else {
227  $result =& $this->retrieve(
228  'SELECT edit_decision_id, editor_id, decision, date_decided FROM edit_decisions WHERE article_id = ? AND round = ? ORDER BY date_decided ASC',
229  array($articleId, $round)
230  );
231  }
232 
233  while (!$result->EOF) {
234  $decisions[] = array(
235  'editDecisionId' => $result->fields['edit_decision_id'],
236  'editorId' => $result->fields['editor_id'],
237  'decision' => $result->fields['decision'],
238  'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
239  );
240  $result->moveNext();
241  }
242 
243  $result->Close();
244  unset($result);
245 
246  return $decisions;
247  }
248 
254  function getSubmissionsCount($authorId, $journalId) {
255  $submissionsCount = array();
256  $submissionsCount[0] = 0; //pending items
257  $submissionsCount[1] = 0; //all non-pending items
258 
259  $sql = 'SELECT count(*), status FROM articles a LEFT JOIN sections s ON (s.section_id = a.section_id) WHERE a.journal_id = ? AND a.user_id = ? GROUP BY a.status';
260 
261  $result =& $this->retrieve($sql, array($journalId, $authorId));
262 
263  while (!$result->EOF) {
264  if ($result->fields['status'] != 1) {
265  $submissionsCount[1] += $result->fields[0];
266  } else {
267  $submissionsCount[0] += $result->fields[0];
268  }
269  $result->moveNext();
270  }
271 
272  $result->Close();
273  unset($result);
274 
275  return $submissionsCount;
276  }
277 
283  function getSortMapping($heading) {
284  switch ($heading) {
285  case 'status': return 'a.status';
286  case 'id': return 'a.article_id';
287  case 'submitDate': return 'a.date_submitted';
288  case 'section': return 'section_abbrev';
289  case 'authors': return 'author_name';
290  case 'title': return 'submission_title';
291  case 'active': return 'a.submission_progress';
292  case 'views': return 'galley_views';
293  case 'status': return 'a.status';
294  default: return null;
295  }
296  }
297 }
298 
299 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getSubmissionsCount($authorId, $journalId)
updateAuthorSubmission(&$authorSubmission)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
AuthorSubmission class.
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getEditorDecisions($articleId, $round=null)
Operations for retrieving and modifying AuthorSubmission objects.
& getDAO($name, $dbconn=null)
call($hookName, $args=null)
getDirectionMapping($direction)
Definition: DAO.inc.php:588
& getAuthorSubmissions($authorId, $journalId, $active=true, $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)