PageRenderTime 28ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ojs/ojs-2.3.2-1/classes/submission/copyeditor/CopyeditorSubmissionDAO.inc.php

https://github.com/mcrider/pkpUpgradeTestSuite
PHP | 343 lines | 255 code | 35 blank | 53 comment | 26 complexity | f6c9b700fb57b3b0a20162f3597d54d3 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @file classes/submission/copyeditor/CopyeditorSubmissionDAO.inc.php
  4. *
  5. * Copyright (c) 2003-2009 John Willinsky
  6. * Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
  7. *
  8. * @class CopyeditorSubmissionDAO
  9. * @ingroup submission
  10. * @see CopyeditorSubmission
  11. *
  12. * @brief Operations for retrieving and modifying CopyeditorSubmission objects.
  13. */
  14. // $Id$
  15. import('submission.copyeditor.CopyeditorSubmission');
  16. class CopyeditorSubmissionDAO extends DAO {
  17. var $articleDao;
  18. var $authorDao;
  19. var $userDao;
  20. var $editAssignmentDao;
  21. var $articleFileDao;
  22. var $suppFileDao;
  23. var $galleyDao;
  24. var $articleCommentDao;
  25. /**
  26. * Constructor.
  27. */
  28. function CopyeditorSubmissionDAO() {
  29. parent::DAO();
  30. $this->articleDao =& DAORegistry::getDAO('ArticleDAO');
  31. $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
  32. $this->userDao =& DAORegistry::getDAO('UserDAO');
  33. $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
  34. $this->articleDao =& DAORegistry::getDAO('ArticleDAO');
  35. $this->articleFileDao =& DAORegistry::getDAO('ArticleFileDAO');
  36. $this->articleCommentDao =& DAORegistry::getDAO('ArticleCommentDAO');
  37. $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
  38. $this->galleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
  39. }
  40. /**
  41. * Retrieve a copyeditor submission by article ID.
  42. * @param $articleId int
  43. * @return CopyeditorSubmission
  44. */
  45. function &getCopyeditorSubmission($articleId) {
  46. $primaryLocale = Locale::getPrimaryLocale();
  47. $locale = Locale::getLocale();
  48. $result =& $this->retrieve(
  49. 'SELECT a.*,
  50. e.editor_id,
  51. COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
  52. COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
  53. FROM articles a
  54. LEFT JOIN edit_assignments e ON (a.article_id = e.article_id)
  55. LEFT JOIN sections s ON (s.section_id = a.section_id)
  56. LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
  57. LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
  58. LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
  59. LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
  60. WHERE a.article_id = ?',
  61. array(
  62. 'title',
  63. $primaryLocale,
  64. 'title',
  65. $locale,
  66. 'abbrev',
  67. $primaryLocale,
  68. 'abbrev',
  69. $locale,
  70. $articleId
  71. )
  72. );
  73. $returner = null;
  74. if ($result->RecordCount() != 0) {
  75. $returner =& $this->_returnCopyeditorSubmissionFromRow($result->GetRowAssoc(false));
  76. }
  77. $result->Close();
  78. unset($result);
  79. return $returner;
  80. }
  81. /**
  82. * Internal function to return a CopyeditorSubmission object from a row.
  83. * @param $row array
  84. * @return CopyeditorSubmission
  85. */
  86. function &_returnCopyeditorSubmissionFromRow(&$row) {
  87. $copyeditorSubmission = new CopyeditorSubmission();
  88. // Article attributes
  89. $this->articleDao->_articleFromRow($copyeditorSubmission, $row);
  90. // Editor Assignment
  91. $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
  92. $copyeditorSubmission->setEditAssignments($editAssignments->toArray());
  93. // Comments
  94. $copyeditorSubmission->setMostRecentCopyeditComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_COPYEDIT, $row['article_id']));
  95. $copyeditorSubmission->setMostRecentLayoutComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_LAYOUT, $row['article_id']));
  96. // Files
  97. // Information for Layout table access
  98. $copyeditorSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['article_id']));
  99. $copyeditorSubmission->setGalleys($this->galleyDao->getGalleysByArticle($row['article_id']));
  100. HookRegistry::call('CopyeditorSubmissionDAO::_returnCopyeditorSubmissionFromRow', array(&$copyeditorSubmission, &$row));
  101. return $copyeditorSubmission;
  102. }
  103. /**
  104. * Get all submissions for a copyeditor of a journal.
  105. * @param $copyeditorId int
  106. * @param $journalId int optional
  107. * @param $searchField int SUBMISSION_FIELD_... constant
  108. * @param $searchMatch String 'is' or 'contains' or 'startsWith'
  109. * @param $search String Search string
  110. * @param $dateField int SUBMISSION_FIELD_DATE_... constant
  111. * @param $dateFrom int Search from timestamp
  112. * @param $dateTo int Search to timestamp
  113. * @return array CopyeditorSubmissions
  114. */
  115. 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) {
  116. $locale = Locale::getLocale();
  117. $primaryLocale = Locale::getPrimaryLocale();
  118. $params = array(
  119. 'title', // Section title
  120. $primaryLocale,
  121. 'title',
  122. $locale,
  123. 'abbrev', // Section abbrev
  124. $primaryLocale,
  125. 'abbrev',
  126. $locale,
  127. 'cleanTitle', // Article title
  128. $primaryLocale,
  129. 'cleanTitle', // Article title
  130. $locale,
  131. ASSOC_TYPE_ARTICLE,
  132. 'SIGNOFF_COPYEDITING_FINAL',
  133. ASSOC_TYPE_ARTICLE,
  134. 'SIGNOFF_LAYOUT',
  135. ASSOC_TYPE_ARTICLE,
  136. 'SIGNOFF_PROOFREADING_PROOFREADER',
  137. ASSOC_TYPE_ARTICLE,
  138. 'SIGNOFF_COPYEDITING_INITIAL'
  139. );
  140. if (isset($journalId)) $params[] = $journalId;
  141. $params[] = $copyeditorId;
  142. $searchSql = '';
  143. if (!empty($search)) switch ($searchField) {
  144. case SUBMISSION_FIELD_TITLE:
  145. if ($searchMatch === 'is') {
  146. $searchSql = ' AND LOWER(atl.setting_value) = LOWER(?)';
  147. } elseif ($searchMatch === 'contains') {
  148. $searchSql = ' AND LOWER(atl.setting_value) LIKE LOWER(?)';
  149. $search = '%' . $search . '%';
  150. } else { // $searchMatch === 'startsWith'
  151. $searchSql = ' AND LOWER(atl.setting_value) LIKE LOWER(?)';
  152. $search = $search . '%';
  153. }
  154. $params[] = $search;
  155. break;
  156. case SUBMISSION_FIELD_AUTHOR:
  157. $first_last = $this->_dataSource->Concat('aa.first_name', '\' \'', 'aa.last_name');
  158. $first_middle_last = $this->_dataSource->Concat('aa.first_name', '\' \'', 'aa.middle_name', '\' \'', 'aa.last_name');
  159. $last_comma_first = $this->_dataSource->Concat('aa.last_name', '\', \'', 'aa.first_name');
  160. $last_comma_first_middle = $this->_dataSource->Concat('aa.last_name', '\', \'', 'aa.first_name', '\' \'', 'aa.middle_name');
  161. if ($searchMatch === 'is') {
  162. $searchSql = " AND (LOWER(aa.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(?))";
  163. } elseif ($searchMatch === 'contains') {
  164. $searchSql = " AND (LOWER(aa.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(?))";
  165. $search = '%' . $search . '%';
  166. } else { // $searchMatch === 'startsWith'
  167. $searchSql = " AND (LOWER(aa.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(?))";
  168. $search = $search . '%';
  169. }
  170. $params[] = $params[] = $params[] = $params[] = $params[] = $search;
  171. break;
  172. case SUBMISSION_FIELD_EDITOR:
  173. $first_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.last_name');
  174. $first_middle_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.middle_name', '\' \'', 'ed.last_name');
  175. $last_comma_first = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name');
  176. $last_comma_first_middle = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name', '\' \'', 'ed.middle_name');
  177. if ($searchMatch === 'is') {
  178. $searchSql = " AND (LOWER(ed.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(?))";
  179. } elseif ($searchMatch === 'contains') {
  180. $searchSql = " AND (LOWER(ed.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(?))";
  181. $search = '%' . $search . '%';
  182. } else { // $searchMatch === 'startsWith'
  183. $searchSql = " AND (LOWER(ed.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(?))";
  184. $search = $search . '%';
  185. }
  186. $params[] = $params[] = $params[] = $params[] = $params[] = $search;
  187. break;
  188. }
  189. if (!empty($dateFrom) || !empty($dateTo)) switch($dateField) {
  190. case SUBMISSION_FIELD_DATE_SUBMITTED:
  191. if (!empty($dateFrom)) {
  192. $searchSql .= ' AND a.date_submitted >= ' . $this->datetimeToDB($dateFrom);
  193. }
  194. if (!empty($dateTo)) {
  195. $searchSql .= ' AND a.date_submitted <= ' . $this->datetimeToDB($dateTo);
  196. }
  197. break;
  198. case SUBMISSION_FIELD_DATE_COPYEDIT_COMPLETE:
  199. if (!empty($dateFrom)) {
  200. $searchSql .= ' AND scp.date_completed >= ' . $this->datetimeToDB($dateFrom);
  201. }
  202. if (!empty($dateTo)) {
  203. $searchSql .= ' AND scp.date_completed <= ' . $this->datetimeToDB($dateTo);
  204. }
  205. break;
  206. case SUBMISSION_FIELD_DATE_LAYOUT_COMPLETE:
  207. if (!empty($dateFrom)) {
  208. $searchSql .= ' AND sle.date_completed >= ' . $this->datetimeToDB($dateFrom);
  209. }
  210. if (!empty($dateTo)) {
  211. $searchSql .= ' AND sle.date_completed <= ' . $this->datetimeToDB($dateTo);
  212. }
  213. break;
  214. case SUBMISSION_FIELD_DATE_PROOFREADING_COMPLETE:
  215. if (!empty($dateFrom)) {
  216. $searchSql .= ' AND spr.date_completed >= ' . $this->datetimeToDB($dateFrom);
  217. }
  218. if (!empty($dateTo)) {
  219. $searchSql .= 'AND spr.date_completed <= ' . $this->datetimeToDB($dateTo);
  220. }
  221. break;
  222. }
  223. $sql = 'SELECT DISTINCT
  224. a.*,
  225. scpi.date_notified AS date_assigned,
  226. scpf.date_completed AS date_completed,
  227. COALESCE(atl.setting_value, atpl.setting_value) AS submission_title,
  228. aap.last_name AS author_name,
  229. COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
  230. COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
  231. FROM
  232. articles a
  233. INNER JOIN article_authors aa ON (aa.article_id = a.article_id)
  234. LEFT JOIN article_authors aap ON (aap.article_id = a.article_id AND aap.primary_contact = 1)
  235. LEFT JOIN sections s ON (s.section_id = a.section_id)
  236. LEFT JOIN edit_assignments e ON (e.article_id = a.article_id)
  237. LEFT JOIN users ed ON (e.editor_id = ed.user_id)
  238. LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
  239. LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
  240. LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
  241. LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
  242. LEFT JOIN article_settings atpl ON (atpl.article_id = a.article_id AND atpl.setting_name = ? AND atpl.locale = ?)
  243. LEFT JOIN article_settings atl ON (a.article_id = atl.article_id AND atl.setting_name = ? AND atl.locale = ?)
  244. LEFT JOIN signoffs scpf ON (a.article_id = scpf.assoc_id AND scpf.assoc_type = ? AND scpf.symbolic = ?)
  245. LEFT JOIN signoffs sle ON (a.article_id = sle.assoc_id AND sle.assoc_type = ? AND sle.symbolic = ?)
  246. LEFT JOIN signoffs spr ON (a.article_id = spr.assoc_id AND spr.assoc_type = ? AND spr.symbolic = ?)
  247. LEFT JOIN signoffs scpi ON (a.article_id = scpi.assoc_id AND scpi.assoc_type = ? AND scpi.symbolic = ?)
  248. WHERE
  249. ' . (isset($journalId)?'a.journal_id = ? AND':'') . '
  250. scpi.user_id = ? AND
  251. (' . ($active?'':'NOT ') . ' ((scpi.date_notified IS NOT NULL AND scpi.date_completed IS NULL) OR (scpf.date_notified IS NOT NULL AND scpf.date_completed IS NULL))) ';
  252. $result =& $this->retrieveRange(
  253. $sql . ' ' . $searchSql . ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : ''),
  254. count($params)==1?array_shift($params):$params,
  255. $rangeInfo);
  256. $returner = new DAOResultFactory($result, $this, '_returnCopyeditorSubmissionFromRow');
  257. return $returner;
  258. }
  259. /**
  260. * Get count of active and complete assignments
  261. * @param copyeditorId int
  262. * @param journalId int
  263. */
  264. function getSubmissionsCount($copyeditorId, $journalId) {
  265. $submissionsCount = array();
  266. $submissionsCount[0] = 0;
  267. $submissionsCount[1] = 0;
  268. $sql = 'SELECT
  269. scf.date_completed
  270. FROM
  271. articles a
  272. LEFT JOIN sections s ON (s.section_id = a.section_id)
  273. LEFT JOIN signoffs scf ON (a.article_id = scf.assoc_id AND scf.assoc_type = ? AND scf.symbolic = ?)
  274. LEFT JOIN signoffs sci ON (a.article_id = sci.assoc_id AND sci.assoc_type = ? AND sci.symbolic = ?)
  275. WHERE
  276. a.journal_id = ? AND sci.user_id = ? AND sci.date_notified IS NOT NULL';
  277. $result =& $this->retrieve($sql, array(ASSOC_TYPE_ARTICLE, 'SIGNOFF_COPYEDITING_FINAL', ASSOC_TYPE_ARTICLE, 'SIGNOFF_COPYEDITING_INITIAL', $journalId, $copyeditorId));
  278. while (!$result->EOF) {
  279. if ($result->fields['date_completed'] == null) {
  280. $submissionsCount[0] += 1;
  281. } else {
  282. $submissionsCount[1] += 1;
  283. }
  284. $result->moveNext();
  285. }
  286. $result->Close();
  287. unset($result);
  288. return $submissionsCount;
  289. }
  290. /**
  291. * Map a column heading value to a database value for sorting
  292. * @param string
  293. * @return string
  294. */
  295. function getSortMapping($heading) {
  296. switch ($heading) {
  297. case 'id': return 'a.article_id';
  298. case 'assignDate': return 'date_assigned';
  299. case 'dateCompleted': return 'date_completed';
  300. case 'section': return 'section_abbrev';
  301. case 'authors': return 'author_name';
  302. case 'title': return 'submission_title';
  303. case 'status': return 'a.status';
  304. default: return null;
  305. }
  306. }
  307. }
  308. ?>