Open Journal Systems  2.4.8
 All Classes Namespaces Functions Variables Groups Pages
CopyeditorSubmissionDAO.inc.php
1 <?php
2 
20 import('classes.submission.copyeditor.CopyeditorSubmission');
21 
23  var $articleDao;
24  var $authorDao;
25  var $userDao;
26  var $editAssignmentDao;
27  var $articleFileDao;
28  var $suppFileDao;
29  var $galleyDao;
30  var $articleCommentDao;
31 
36  parent::DAO();
37  $this->articleDao =& DAORegistry::getDAO('ArticleDAO');
38  $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
39  $this->userDao =& DAORegistry::getDAO('UserDAO');
40  $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
41  $this->articleDao =& DAORegistry::getDAO('ArticleDAO');
42  $this->articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
43  $this->articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
44  $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
45  $this->galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
46  }
47 
53  function &getCopyeditorSubmission($articleId) {
54  $primaryLocale = AppLocale::getPrimaryLocale();
55  $locale = AppLocale::getLocale();
56  $result =& $this->retrieve(
57  'SELECT a.*,
58  e.editor_id,
59  COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
60  COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
61  FROM articles a
62  LEFT JOIN edit_assignments e ON (a.article_id = e.article_id)
63  LEFT JOIN sections s ON (s.section_id = a.section_id)
64  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
65  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
66  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
67  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
68  WHERE a.article_id = ?',
69  array(
70  'title',
71  $primaryLocale,
72  'title',
73  $locale,
74  'abbrev',
75  $primaryLocale,
76  'abbrev',
77  $locale,
78  $articleId
79  )
80  );
81 
82  $returner = null;
83  if ($result->RecordCount() != 0) {
84  $returner =& $this->_returnCopyeditorSubmissionFromRow($result->GetRowAssoc(false));
85  }
86 
87  $result->Close();
88  unset($result);
89 
90  return $returner;
91  }
92 
99  $copyeditorSubmission = new CopyeditorSubmission();
100 
101  // Article attributes
102  $this->articleDao->_articleFromRow($copyeditorSubmission, $row);
103 
104  // Editor Assignment
105  $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
106  $copyeditorSubmission->setEditAssignments($editAssignments->toArray());
107 
108  // Comments
109  $copyeditorSubmission->setMostRecentCopyeditComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_COPYEDIT, $row['article_id']));
110  $copyeditorSubmission->setMostRecentLayoutComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_LAYOUT, $row['article_id']));
111 
112  // Files
113 
114  // Information for Layout table access
115  $copyeditorSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['article_id']));
116  $copyeditorSubmission->setGalleys($this->galleyDao->getGalleysByArticle($row['article_id']));
117 
118  HookRegistry::call('CopyeditorSubmissionDAO::_returnCopyeditorSubmissionFromRow', array(&$copyeditorSubmission, &$row));
119 
120  return $copyeditorSubmission;
121  }
122 
135  function &getCopyeditorSubmissionsByCopyeditorId($copyeditorId, $journalId = null, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $active = true, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
136  $locale = AppLocale::getLocale();
137  $primaryLocale = AppLocale::getPrimaryLocale();
138  $params = array(
139  'title', // Section title
140  $primaryLocale,
141  'title',
142  $locale,
143  'abbrev', // Section abbrev
144  $primaryLocale,
145  'abbrev',
146  $locale,
147  'cleanTitle', // Article clean title
148  'cleanTitle', // Article clean title
149  $locale,
150  'title', // Article title
151  'title', // Article title
152  $locale,
153  ASSOC_TYPE_ARTICLE,
154  'SIGNOFF_COPYEDITING_FINAL',
155  ASSOC_TYPE_ARTICLE,
156  'SIGNOFF_LAYOUT',
157  ASSOC_TYPE_ARTICLE,
158  'SIGNOFF_PROOFREADING_PROOFREADER',
159  ASSOC_TYPE_ARTICLE,
160  'SIGNOFF_COPYEDITING_INITIAL'
161  );
162 
163  if (isset($journalId)) $params[] = $journalId;
164  $params[] = $copyeditorId;
165 
166  $searchSql = '';
167 
168  if (!empty($search)) switch ($searchField) {
169  case SUBMISSION_FIELD_ID:
170  switch ($searchMatch) {
171  case 'is':
172  $params[] = (int) $search;
173  $searchSql = ' AND a.article_id = ?';
174  break;
175  case 'contains':
176  $search = '%' . $search . '%';
177  $params[] = $search;
178  $searchSql = ' AND CONCAT(a.article_id) LIKE ?';
179  break;
180  case 'startsWith':
181  $search = $search . '%';
182  $params[] = $search;
183  $searchSql = 'AND CONCAT(a.article_id) LIKE ?';
184  break;
185  }
186  break;
187  case SUBMISSION_FIELD_TITLE:
188  if ($searchMatch === 'is') {
189  $searchSql = ' AND LOWER(atl.setting_value) = LOWER(?)';
190  } elseif ($searchMatch === 'contains') {
191  $searchSql = ' AND LOWER(atl.setting_value) LIKE LOWER(?)';
192  $search = '%' . $search . '%';
193  } else { // $searchMatch === 'startsWith'
194  $searchSql = ' AND LOWER(atl.setting_value) LIKE LOWER(?)';
195  $search = $search . '%';
196  }
197  $params[] = $search;
198  break;
199  case SUBMISSION_FIELD_AUTHOR:
200  $searchSql = $this->_generateUserNameSearchSQL($search, $searchMatch, 'aa.', $params);
201  break;
202  case SUBMISSION_FIELD_EDITOR:
203  $searchSql = $this->_generateUserNameSearchSQL($search, $searchMatch, 'ed.', $params);
204  break;
205  }
206 
207  if (!empty($dateFrom) || !empty($dateTo)) switch($dateField) {
208  case SUBMISSION_FIELD_DATE_SUBMITTED:
209  if (!empty($dateFrom)) {
210  $searchSql .= ' AND a.date_submitted >= ' . $this->datetimeToDB($dateFrom);
211  }
212  if (!empty($dateTo)) {
213  $searchSql .= ' AND a.date_submitted <= ' . $this->datetimeToDB($dateTo);
214  }
215  break;
216  case SUBMISSION_FIELD_DATE_COPYEDIT_COMPLETE:
217  if (!empty($dateFrom)) {
218  $searchSql .= ' AND scp.date_completed >= ' . $this->datetimeToDB($dateFrom);
219  }
220  if (!empty($dateTo)) {
221  $searchSql .= ' AND scp.date_completed <= ' . $this->datetimeToDB($dateTo);
222  }
223  break;
224  case SUBMISSION_FIELD_DATE_LAYOUT_COMPLETE:
225  if (!empty($dateFrom)) {
226  $searchSql .= ' AND sle.date_completed >= ' . $this->datetimeToDB($dateFrom);
227  }
228  if (!empty($dateTo)) {
229  $searchSql .= ' AND sle.date_completed <= ' . $this->datetimeToDB($dateTo);
230  }
231  break;
232  case SUBMISSION_FIELD_DATE_PROOFREADING_COMPLETE:
233  if (!empty($dateFrom)) {
234  $searchSql .= ' AND spr.date_completed >= ' . $this->datetimeToDB($dateFrom);
235  }
236  if (!empty($dateTo)) {
237  $searchSql .= 'AND spr.date_completed <= ' . $this->datetimeToDB($dateTo);
238  }
239  break;
240  }
241 
242  $sql = 'SELECT DISTINCT
243  a.*,
244  scpi.date_notified AS date_assigned,
245  scpf.date_completed AS date_completed,
246  SUBSTRING(COALESCE(atl.setting_value, atpl.setting_value) FROM 1 FOR 255) AS submission_clean_title,
247  aap.last_name AS author_name,
248  SUBSTRING(COALESCE(stl.setting_value, stpl.setting_value) FROM 1 FOR 255) AS section_title,
249  SUBSTRING(COALESCE(sal.setting_value, sapl.setting_value) FROM 1 FOR 255) AS section_abbrev
250  FROM articles a
251  LEFT JOIN published_articles pa ON (a.article_id = pa.article_id)
252  LEFT JOIN issues i ON (pa.issue_id = i.issue_id)
253  LEFT JOIN authors aa ON (aa.submission_id = a.article_id)
254  LEFT JOIN authors aap ON (aap.submission_id = a.article_id AND aap.primary_contact = 1)
255  LEFT JOIN sections s ON (s.section_id = a.section_id)
256  LEFT JOIN edit_assignments e ON (e.article_id = a.article_id)
257  LEFT JOIN users ed ON (e.editor_id = ed.user_id)
258  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
259  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
260  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
261  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
262  LEFT JOIN article_settings actpl ON (actpl.article_id = a.article_id AND actpl.setting_name = ? AND actpl.locale = a.locale)
263  LEFT JOIN article_settings actl ON (a.article_id = actl.article_id AND actl.setting_name = ? AND actl.locale = ?)
264  LEFT JOIN article_settings atpl ON (atpl.article_id = a.article_id AND atpl.setting_name = ? AND atpl.locale = a.locale)
265  LEFT JOIN article_settings atl ON (a.article_id = atl.article_id AND atl.setting_name = ? AND atl.locale = ?)
266  LEFT JOIN signoffs scpf ON (a.article_id = scpf.assoc_id AND scpf.assoc_type = ? AND scpf.symbolic = ?)
267  LEFT JOIN signoffs sle ON (a.article_id = sle.assoc_id AND sle.assoc_type = ? AND sle.symbolic = ?)
268  LEFT JOIN signoffs spr ON (a.article_id = spr.assoc_id AND spr.assoc_type = ? AND spr.symbolic = ?)
269  LEFT JOIN signoffs scpi ON (a.article_id = scpi.assoc_id AND scpi.assoc_type = ? AND scpi.symbolic = ?)
270  WHERE
271  ' . (isset($journalId)?'a.journal_id = ? AND':'') . '
272  scpi.user_id = ? AND
273  (' . ($active?'': 'NOT ') . ' (i.date_published IS NULL AND a.status = ' . STATUS_QUEUED . ')) ';
274 
275  $result =& $this->retrieveRange(
276  $sql . ' ' . $searchSql . ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : ''),
277  count($params)==1?array_shift($params):$params,
278  $rangeInfo);
279 
280  $returner = new DAOResultFactory($result, $this, '_returnCopyeditorSubmissionFromRow');
281  return $returner;
282  }
283 
287  function _generateUserNameSearchSQL($search, $searchMatch, $prefix, &$params) {
288  $first_last = $this->concat($prefix.'first_name', '\' \'', $prefix.'last_name');
289  $first_middle_last = $this->concat($prefix.'first_name', '\' \'', $prefix.'middle_name', '\' \'', $prefix.'last_name');
290  $last_comma_first = $this->concat($prefix.'last_name', '\', \'', $prefix.'first_name');
291  $last_comma_first_middle = $this->concat($prefix.'last_name', '\', \'', $prefix.'first_name', '\' \'', $prefix.'middle_name');
292  if ($searchMatch === 'is') {
293  $searchSql = " AND (LOWER({$prefix}last_name) = LOWER(?) OR LOWER($first_last) = LOWER(?) OR LOWER($first_middle_last) = LOWER(?) OR LOWER($last_comma_first) = LOWER(?) OR LOWER($last_comma_first_middle) = LOWER(?))";
294  } elseif ($searchMatch === 'contains') {
295  $searchSql = " AND (LOWER({$prefix}last_name) LIKE LOWER(?) OR LOWER($first_last) LIKE LOWER(?) OR LOWER($first_middle_last) LIKE LOWER(?) OR LOWER($last_comma_first) LIKE LOWER(?) OR LOWER($last_comma_first_middle) LIKE LOWER(?))";
296  $search = '%' . $search . '%';
297  } else { // $searchMatch === 'startsWith'
298  $searchSql = " AND (LOWER({$prefix}last_name) LIKE LOWER(?) OR LOWER($first_last) LIKE LOWER(?) OR LOWER($first_middle_last) LIKE LOWER(?) OR LOWER($last_comma_first) LIKE LOWER(?) OR LOWER($last_comma_first_middle) LIKE LOWER(?))";
299  $search = $search . '%';
300  }
301  $params[] = $params[] = $params[] = $params[] = $params[] = $search;
302  return $searchSql;
303  }
304 
310  function getSubmissionsCount($copyeditorId, $journalId) {
311  $sectionEditorSubmissionDao =& DAORegistry::getDAO('SectionEditorSubmissionDAO');
312  $stats = $sectionEditorSubmissionDao->getCopyeditorStatistics($journalId, $copyeditorId);
313  return array(
314  0 => isset($stats[$copyeditorId]['incomplete'])?$stats[$copyeditorId]['incomplete']:0,
315  1 => isset($stats[$copyeditorId]['complete'])?$stats[$copyeditorId]['complete']:0
316  );
317  }
318 
324  function getSortMapping($heading) {
325  switch ($heading) {
326  case 'id': return 'a.article_id';
327  case 'assignDate': return 'date_assigned';
328  case 'dateCompleted': return 'date_completed';
329  case 'section': return 'section_abbrev';
330  case 'authors': return 'author_name';
331  case 'title': return 'submission_clean_title';
332  case 'status': return 'a.status';
333  default: return null;
334  }
335  }
336 }
337 
338 ?>
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
CopyeditorSubmission class.
getSubmissionsCount($copyeditorId, $journalId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
concat()
Definition: DAO.inc.php:52
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
& getCopyeditorSubmissionsByCopyeditorId($copyeditorId, $journalId=null, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, $active=true, $rangeInfo=null, $sortBy=null, $sortDirection=SORT_DIRECTION_ASC)
& getDAO($name, $dbconn=null)
call($hookName, $args=null)
_generateUserNameSearchSQL($search, $searchMatch, $prefix, &$params)
Operations for retrieving and modifying CopyeditorSubmission objects.
datetimeToDB($dt)
Definition: DAO.inc.php:296
getDirectionMapping($direction)
Definition: DAO.inc.php:588