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