Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
LayoutEditorSubmissionDAO.inc.php
1 <?php
2 
17 import('classes.submission.layoutEditor.LayoutEditorSubmission');
18 
22  var $layoutDao;
23  var $galleyDao;
24  var $editAssignmentDao;
25  var $suppFileDao;
26  var $articleCommentDao;
27 
32  parent::DAO();
33 
34  $this->articleDao =& DAORegistry::getDAO('ArticleDAO');
35  $this->galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
36  $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
37  $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
38  $this->articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
39  }
40 
46  function &getSubmission($articleId, $journalId = null) {
47  $primaryLocale = AppLocale::getPrimaryLocale();
48  $locale = AppLocale::getLocale();
49  $params = array(
50  'title',
51  $primaryLocale,
52  'title',
53  $locale,
54  'abbrev',
55  $primaryLocale,
56  'abbrev',
57  $locale,
58  $articleId
59  );
60  if ($journalId) $params[] = $journalId;
61  $result =& $this->retrieve(
62  'SELECT
63  a.*,
64  COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
65  COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
66  FROM articles a
67  LEFT JOIN sections s ON s.section_id = a.section_id
68  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
69  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
70  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
71  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
72  WHERE a.article_id = ?' .
73  ($journalId?' AND a.journal_id = ?':''),
74  $params
75  );
76 
77  $returner = null;
78  if ($result->RecordCount() != 0) {
79  $returner =& $this->_returnSubmissionFromRow($result->GetRowAssoc(false));
80  }
81 
82  $result->Close();
83  unset($result);
84 
85  return $returner;
86  }
87 
93  function &_returnSubmissionFromRow(&$row) {
94  $submission = new LayoutEditorSubmission();
95  $this->articleDao->_articleFromRow($submission, $row);
96 
97  // Comments
98  $submission->setMostRecentLayoutComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_LAYOUT, $row['article_id']));
99  $submission->setMostRecentProofreadComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_PROOFREAD, $row['article_id']));
100 
101  $submission->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['article_id']));
102 
103  $submission->setGalleys($this->galleyDao->getGalleysByArticle($row['article_id']));
104 
105  $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
106  $submission->setEditAssignments($editAssignments->toArray());
107 
108  HookRegistry::call('LayoutEditorSubmissionDAO::_returnLayoutEditorSubmissionFromRow', array(&$submission, &$row));
109 
110  return $submission;
111  }
112 
126  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) {
127  $primaryLocale = AppLocale::getPrimaryLocale();
128  $locale = AppLocale::getLocale();
129  $params = array(
130  'title', // Section title
131  $primaryLocale,
132  'title',
133  $locale,
134  'abbrev', // Section abbrev.
135  $primaryLocale,
136  'abbrev',
137  $locale,
138  'cleanTitle', // Article title
139  'cleanTitle',
140  $locale,
141  ASSOC_TYPE_ARTICLE,
142  'SIGNOFF_COPYEDITING_FINAL',
143  ASSOC_TYPE_ARTICLE,
144  'SIGNOFF_LAYOUT',
145  ASSOC_TYPE_ARTICLE,
146  'SIGNOFF_PROOFREADING_LAYOUT',
147  ASSOC_TYPE_ARTICLE,
148  'SIGNOFF_COPYEDITING_INITIAL',
149  $editorId
150  );
151  if (isset($journalId)) $params[] = $journalId;
152 
153  $searchSql = '';
154 
155  if (!empty($search)) switch ($searchField) {
156  case SUBMISSION_FIELD_ID:
157  $params[] = (int) $search;
158  $searchSql = ' AND a.article_id = ?';
159  break;
160  case SUBMISSION_FIELD_TITLE:
161  if ($searchMatch === 'is') {
162  $searchSql = ' AND LOWER(atl.setting_value) = LOWER(?)';
163  } elseif ($searchMatch === 'contains') {
164  $searchSql = ' AND LOWER(atl.setting_value) LIKE LOWER(?)';
165  $search = '%' . $search . '%';
166  } else { // $searchMatch === 'startsWith'
167  $searchSql = ' AND LOWER(atl.setting_value) LIKE LOWER(?)';
168  $search = $search . '%';
169  }
170  $params[] = $search;
171  break;
172  case SUBMISSION_FIELD_AUTHOR:
173  $searchSql = $this->_generateUserNameSearchSQL($search, $searchMatch, 'aa.', $params);
174  break;
175  case SUBMISSION_FIELD_EDITOR:
176  $searchSql = $this->_generateUserNameSearchSQL($search, $searchMatch, 'ed.', $params);
177  break;
178  }
179 
180  if (!empty($dateFrom) || !empty($dateTo)) switch($dateField) {
181  case SUBMISSION_FIELD_DATE_SUBMITTED:
182  if (!empty($dateFrom)) {
183  $searchSql .= ' AND a.date_submitted >= ' . $this->datetimeToDB($dateFrom);
184  }
185  if (!empty($dateTo)) {
186  $searchSql .= ' AND a.date_submitted <= ' . $this->datetimeToDB($dateTo);
187  }
188  break;
189  case SUBMISSION_FIELD_DATE_COPYEDIT_COMPLETE:
190  if (!empty($dateFrom)) {
191  $searchSql .= ' AND scp.date_completed >= ' . $this->datetimeToDB($dateFrom);
192  }
193  if (!empty($dateTo)) {
194  $searchSql .= ' AND scp.date_completed <= ' . $this->datetimeToDB($dateTo);
195  }
196  break;
197  case SUBMISSION_FIELD_DATE_LAYOUT_COMPLETE:
198  if (!empty($dateFrom)) {
199  $searchSql .= ' AND sle.date_completed >= ' . $this->datetimeToDB($dateFrom);
200  }
201  if (!empty($dateTo)) {
202  $searchSql .= ' AND sle.date_completed <= ' . $this->datetimeToDB($dateTo);
203  }
204  break;
205  case SUBMISSION_FIELD_DATE_PROOFREADING_COMPLETE:
206  if (!empty($dateFrom)) {
207  $searchSql .= ' AND spr.date_completed >= ' . $this->datetimeToDB($dateFrom);
208  }
209  if (!empty($dateTo)) {
210  $searchSql .= 'AND spr.date_completed <= ' . $this->datetimeToDB($dateTo);
211  }
212  break;
213  }
214 
215  $sql = 'SELECT DISTINCT
216  a.*,
217  sle.date_notified AS notified_date,
218  sle.date_completed AS completed_date,
219  aap.last_name AS author_name,
220  SUBSTRING(COALESCE(atl.setting_value, atpl.setting_value) FROM 1 FOR 255) AS submission_title,
221  SUBSTRING(COALESCE(stl.setting_value, stpl.setting_value) FROM 1 FOR 255) AS section_title,
222  SUBSTRING(COALESCE(sal.setting_value, sapl.setting_value) FROM 1 FOR 255) AS section_abbrev
223  FROM articles a
224  LEFT JOIN authors aa ON (aa.submission_id = a.article_id)
225  LEFT JOIN authors aap ON (aap.submission_id = a.article_id AND aap.primary_contact = 1)
226  LEFT JOIN sections s ON s.section_id = a.section_id
227  LEFT JOIN edit_assignments e ON (e.article_id = a.article_id)
228  LEFT JOIN users ed ON (e.editor_id = ed.user_id)
229  LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
230  LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
231  LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
232  LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
233  LEFT JOIN article_settings atpl ON (atpl.article_id = a.article_id AND atpl.setting_name = ? AND atpl.locale = a.locale)
234  LEFT JOIN article_settings atl ON (a.article_id = atl.article_id AND atl.setting_name = ? AND atl.locale = ?)
235  LEFT JOIN signoffs scpf ON (a.article_id = scpf.assoc_id AND scpf.assoc_type = ? AND scpf.symbolic = ?)
236  LEFT JOIN signoffs sle ON (a.article_id = sle.assoc_id AND sle.assoc_type = ? AND sle.symbolic = ?)
237  LEFT JOIN signoffs spr ON (a.article_id = spr.assoc_id AND spr.assoc_type = ? AND spr.symbolic = ?)
238  LEFT JOIN signoffs scpi ON (a.article_id = scpi.assoc_id AND scpi.assoc_type = ? AND scpi.symbolic = ?)
239  WHERE
240  sle.user_id = ? AND
241  ' . (isset($journalId)?'a.journal_id = ? AND':'') . '
242  sle.date_notified IS NOT NULL';
243 
244  if ($active) {
245  $sql .= ' AND a.status = ' . STATUS_QUEUED;
246  } else {
247  $sql .= ' AND a.status <> ' . STATUS_QUEUED;
248  }
249 
250  $result =& $this->retrieveRange(
251  $sql . ' ' . $searchSql . ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : ''),
252  count($params)==1?array_shift($params):$params,
253  $rangeInfo
254  );
255 
256  $returner = new DAOResultFactory($result, $this, '_returnSubmissionFromRow');
257  return $returner;
258  }
259 
263  function _generateUserNameSearchSQL($search, $searchMatch, $prefix, &$params) {
264  $first_last = $this->concat($prefix.'first_name', '\' \'', $prefix.'last_name');
265  $first_middle_last = $this->concat($prefix.'first_name', '\' \'', $prefix.'middle_name', '\' \'', $prefix.'last_name');
266  $last_comma_first = $this->concat($prefix.'last_name', '\', \'', $prefix.'first_name');
267  $last_comma_first_middle = $this->concat($prefix.'last_name', '\', \'', $prefix.'first_name', '\' \'', $prefix.'middle_name');
268  if ($searchMatch === 'is') {
269  $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(?))";
270  } elseif ($searchMatch === 'contains') {
271  $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(?))";
272  $search = '%' . $search . '%';
273  } else { // $searchMatch === 'startsWith'
274  $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(?))";
275  $search = $search . '%';
276  }
277  $params[] = $params[] = $params[] = $params[] = $params[] = $search;
278  return $searchSql;
279  }
280 
286  function getSubmissionsCount($editorId, $journalId) {
287  $submissionsCount = array();
288  $submissionsCount[0] = 0;
289  $submissionsCount[1] = 0;
290 
291  $sql = 'SELECT
292  a.status
293  FROM
294  articles a
295  LEFT JOIN signoffs sl ON (a.article_id = sl.assoc_id AND sl.assoc_type = ? AND sl.symbolic = ?)
296  LEFT JOIN signoffs spl ON (a.article_id = spl.assoc_id AND spl.assoc_type = ? AND spl.symbolic = ?)
297  LEFT JOIN sections s ON (s.section_id = a.section_id)
298  WHERE
299  sl.user_id = ? AND a.journal_id = ? AND sl.date_notified IS NOT NULL';
300 
301  $result =& $this->retrieve($sql, array(ASSOC_TYPE_ARTICLE, 'SIGNOFF_LAYOUT', ASSOC_TYPE_ARTICLE, 'SIGNOFF_PROOFREADING_LAYOUT', $editorId, $journalId));
302  while (!$result->EOF) {
303  if ($result->fields['status'] == STATUS_QUEUED) {
304  $submissionsCount[0] += 1;
305  } else {
306  $submissionsCount[1] += 1;
307  }
308  $result->moveNext();
309  }
310 
311  $result->Close();
312  unset($result);
313 
314  return $submissionsCount;
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_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
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)