00001 <?php
00002
00016
00017
00018
00019 import('submission.copyeditor.CopyeditorSubmission');
00020
00021 class CopyeditorSubmissionDAO extends DAO {
00022 var $articleDao;
00023 var $authorDao;
00024 var $userDao;
00025 var $editAssignmentDao;
00026 var $layoutAssignmentDao;
00027 var $articleFileDao;
00028 var $suppFileDao;
00029 var $galleyDao;
00030 var $articleCommentDao;
00031 var $proofAssignmentDao;
00032
00036 function CopyeditorSubmissionDAO() {
00037 parent::DAO();
00038 $this->articleDao = &DAORegistry::getDAO('ArticleDAO');
00039 $this->authorDao = &DAORegistry::getDAO('AuthorDAO');
00040 $this->userDao = &DAORegistry::getDAO('UserDAO');
00041 $this->editAssignmentDao = &DAORegistry::getDAO('EditAssignmentDAO');
00042 $this->layoutAssignmentDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
00043 $this->articleDao = &DAORegistry::getDAO('ArticleDAO');
00044 $this->articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
00045 $this->articleCommentDao = &DAORegistry::getDAO('ArticleCommentDAO');
00046 $this->proofAssignmentDao = &DAORegistry::getDAO('ProofAssignmentDAO');
00047 $this->suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00048 $this->galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00049 }
00050
00056 function &getCopyeditorSubmission($articleId) {
00057 $primaryLocale = Locale::getPrimaryLocale();
00058 $locale = Locale::getLocale();
00059 $result = &$this->retrieve(
00060 'SELECT a.*,
00061 e.editor_id,
00062 c.*,
00063 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00064 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
00065 FROM articles a
00066 LEFT JOIN edit_assignments e ON (a.article_id = e.article_id)
00067 LEFT JOIN sections s ON (s.section_id = a.section_id)
00068 LEFT JOIN copyed_assignments c ON (c.article_id = a.article_id)
00069 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00070 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00071 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00072 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00073 WHERE a.article_id = ?',
00074 array(
00075 'title',
00076 $primaryLocale,
00077 'title',
00078 $locale,
00079 'abbrev',
00080 $primaryLocale,
00081 'abbrev',
00082 $locale,
00083 $articleId
00084 )
00085 );
00086
00087 $returner = null;
00088 if ($result->RecordCount() != 0) {
00089 $returner = &$this->_returnCopyeditorSubmissionFromRow($result->GetRowAssoc(false));
00090 }
00091
00092 $result->Close();
00093 unset($result);
00094
00095 return $returner;
00096 }
00097
00103 function &_returnCopyeditorSubmissionFromRow(&$row) {
00104 $copyeditorSubmission = &new CopyeditorSubmission();
00105
00106
00107 $this->articleDao->_articleFromRow($copyeditorSubmission, $row);
00108
00109
00110 $copyeditorSubmission->setCopyedId($row['copyed_id']);
00111 $copyeditorSubmission->setCopyeditorId($row['copyeditor_id']);
00112 $copyeditorSubmission->setCopyeditor($this->userDao->getUser($row['copyeditor_id']), true);
00113 $copyeditorSubmission->setDateNotified($this->datetimeFromDB($row['date_notified']));
00114 $copyeditorSubmission->setDateUnderway($this->datetimeFromDB($row['date_underway']));
00115 $copyeditorSubmission->setDateCompleted($this->datetimeFromDB($row['date_completed']));
00116 $copyeditorSubmission->setDateAcknowledged($this->datetimeFromDB($row['date_acknowledged']));
00117 $copyeditorSubmission->setDateAuthorNotified($this->datetimeFromDB($row['date_author_notified']));
00118 $copyeditorSubmission->setDateAuthorUnderway($this->datetimeFromDB($row['date_author_underway']));
00119 $copyeditorSubmission->setDateAuthorCompleted($this->datetimeFromDB($row['date_author_completed']));
00120 $copyeditorSubmission->setDateAuthorAcknowledged($this->datetimeFromDB($row['date_author_acknowledged']));
00121 $copyeditorSubmission->setDateFinalNotified($this->datetimeFromDB($row['date_final_notified']));
00122 $copyeditorSubmission->setDateFinalUnderway($this->datetimeFromDB($row['date_final_underway']));
00123 $copyeditorSubmission->setDateFinalCompleted($this->datetimeFromDB($row['date_final_completed']));
00124 $copyeditorSubmission->setDateFinalAcknowledged($this->datetimeFromDB($row['date_final_acknowledged']));
00125 $copyeditorSubmission->setInitialRevision($row['initial_revision']);
00126 $copyeditorSubmission->setEditorAuthorRevision($row['editor_author_revision']);
00127 $copyeditorSubmission->setFinalRevision($row['final_revision']);
00128
00129
00130 $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
00131 $copyeditorSubmission->setEditAssignments($editAssignments->toArray());
00132
00133
00134 $copyeditorSubmission->setMostRecentCopyeditComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_COPYEDIT, $row['article_id']));
00135 $copyeditorSubmission->setMostRecentLayoutComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_LAYOUT, $row['article_id']));
00136
00137
00138
00139
00140 if ($row['initial_revision'] != null) {
00141 $copyeditorSubmission->setInitialCopyeditFile($this->articleFileDao->getArticleFile($row['copyedit_file_id'], $row['initial_revision']));
00142 }
00143
00144
00145 $copyeditorSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['article_id']));
00146 $copyeditorSubmission->setGalleys($this->galleyDao->getGalleysByArticle($row['article_id']));
00147
00148
00149 if ($row['editor_author_revision'] != null) {
00150 $copyeditorSubmission->setEditorAuthorCopyeditFile($this->articleFileDao->getArticleFile($row['copyedit_file_id'], $row['editor_author_revision']));
00151 }
00152
00153
00154 if ($row['final_revision'] != null) {
00155 $copyeditorSubmission->setFinalCopyeditFile($this->articleFileDao->getArticleFile($row['copyedit_file_id'], $row['final_revision']));
00156 }
00157
00158 $copyeditorSubmission->setLayoutAssignment($this->layoutAssignmentDao->getLayoutAssignmentByArticleId($row['article_id']));
00159 $copyeditorSubmission->setProofAssignment($this->proofAssignmentDao->getProofAssignmentByArticleId($row['article_id']));
00160
00161 HookRegistry::call('CopyeditorSubmissionDAO::_returnCopyeditorSubmissionFromRow', array(&$copyeditorSubmission, &$row));
00162
00163 return $copyeditorSubmission;
00164 }
00165
00170 function insertCopyeditorSubmission(&$copyeditorSubmission) {
00171 $this->update(
00172 sprintf('INSERT INTO copyed_assignments
00173 (article_id, copyeditor_id, date_notified, date_underway, date_completed, date_acknowledged, date_author_notified, date_author_underway, date_author_completed, date_author_acknowledged, date_final_notified, date_final_underway, date_final_completed, date_final_acknowledged, initial_revision, editor_author_revision, final_revision)
00174 VALUES
00175 (?, ?, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, ?, ?, ?)',
00176 $this->datetimeToDB($copyeditorSubmission->getDateNotified()), $this->datetimeToDB($copyeditorSubmission->getDateUnderway()), $this->datetimeToDB($copyeditorSubmission->getDateCompleted()), $this->datetimeToDB($copyeditorSubmission->getDateAcknowledged()), $this->datetimeToDB($copyeditorSubmission->getDateAuthorNotified()), $this->datetimeToDB($copyeditorSubmission->getDateAuthorUnderway()), $this->datetimeToDB($copyeditorSubmission->getDateAuthorCompleted()), $this->datetimeToDB($copyeditorSubmission->getDateAuthorAcknowledged()), $this->datetimeToDB($copyeditorSubmission->getDateFinalNotified()), $this->datetimeToDB($copyeditorSubmission->getDateFinalUnderway()), $this->datetimeToDB($copyeditorSubmission->getDateFinalCompleted()), $this->datetimeToDB($copyeditorSubmission->getDateFinalAcknowledged())),
00177 array(
00178 $copyeditorSubmission->getArticleId(),
00179 $copyeditorSubmission->getCopyeditorId() === null ? 0 : $copyeditorSubmission->getCopyeditorId(),
00180 $copyeditorSubmission->getInitialRevision(),
00181 $copyeditorSubmission->getEditorAuthorRevision(),
00182 $copyeditorSubmission->getFinalRevision()
00183 )
00184 );
00185
00186 $copyeditorSubmission->setCopyedId($this->getInsertCopyedId());
00187 return $copyeditorSubmission->getCopyedId();
00188 }
00189
00194 function updateCopyeditorSubmission(&$copyeditorSubmission) {
00195 $this->update(
00196 sprintf('UPDATE copyed_assignments
00197 SET
00198 article_id = ?,
00199 copyeditor_id = ?,
00200 date_notified = %s,
00201 date_underway = %s,
00202 date_completed = %s,
00203 date_acknowledged = %s,
00204 date_author_notified = %s,
00205 date_author_underway = %s,
00206 date_author_completed = %s,
00207 date_author_acknowledged = %s,
00208 date_final_notified = %s,
00209 date_final_underway = %s,
00210 date_final_completed = %s,
00211 date_final_acknowledged = %s,
00212 initial_revision = ?,
00213 editor_author_revision = ?,
00214 final_revision = ?
00215 WHERE copyed_id = ?',
00216 $this->datetimeToDB($copyeditorSubmission->getDateNotified()), $this->datetimeToDB($copyeditorSubmission->getDateUnderway()), $this->datetimeToDB($copyeditorSubmission->getDateCompleted()), $this->datetimeToDB($copyeditorSubmission->getDateAcknowledged()), $this->datetimeToDB($copyeditorSubmission->getDateAuthorNotified()), $this->datetimeToDB($copyeditorSubmission->getDateAuthorUnderway()), $this->datetimeToDB($copyeditorSubmission->getDateAuthorCompleted()), $this->datetimeToDB($copyeditorSubmission->getDateAuthorAcknowledged()), $this->datetimeToDB($copyeditorSubmission->getDateFinalNotified()), $this->datetimeToDB($copyeditorSubmission->getDateFinalUnderway()), $this->datetimeToDB($copyeditorSubmission->getDateFinalCompleted()), $this->datetimeToDB($copyeditorSubmission->getDateFinalAcknowledged())),
00217 array(
00218 $copyeditorSubmission->getArticleId(),
00219 $copyeditorSubmission->getCopyeditorId() === null ? 0 : $copyeditorSubmission->getCopyeditorId(),
00220 $copyeditorSubmission->getInitialRevision(),
00221 $copyeditorSubmission->getEditorAuthorRevision(),
00222 $copyeditorSubmission->getFinalRevision(),
00223 $copyeditorSubmission->getCopyedId()
00224 )
00225 );
00226 }
00227
00240 function &getCopyeditorSubmissionsByCopyeditorId($copyeditorId, $journalId = null, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $active = true, $rangeInfo = null) {
00241 $locale = Locale::getLocale();
00242 $primaryLocale = Locale::getPrimaryLocale();
00243 $params = array(
00244 'title',
00245 $primaryLocale,
00246 'title',
00247 $locale,
00248 'abbrev',
00249 $primaryLocale,
00250 'abbrev',
00251 $locale,
00252 'title'
00253 );
00254
00255 if (isset($journalId)) $params[] = $journalId;
00256 $params[] = $copyeditorId;
00257
00258 $searchSql = '';
00259
00260 if (!empty($search)) switch ($searchField) {
00261 case SUBMISSION_FIELD_TITLE:
00262 if ($searchMatch === 'is') {
00263 $searchSql = ' AND LOWER(atl.setting_value) = LOWER(?)';
00264 } else {
00265 $searchSql = ' AND LOWER(atl.setting_value) LIKE LOWER(?)';
00266 $search = '%' . $search . '%';
00267 }
00268 $params[] = $search;
00269 break;
00270 case SUBMISSION_FIELD_AUTHOR:
00271 $first_last = $this->_dataSource->Concat('aa.first_name', '\' \'', 'aa.last_name');
00272 $first_middle_last = $this->_dataSource->Concat('aa.first_name', '\' \'', 'aa.middle_name', '\' \'', 'aa.last_name');
00273 $last_comma_first = $this->_dataSource->Concat('aa.last_name', '\', \'', 'aa.first_name');
00274 $last_comma_first_middle = $this->_dataSource->Concat('aa.last_name', '\', \'', 'aa.first_name', '\' \'', 'aa.middle_name');
00275
00276 if ($searchMatch === 'is') {
00277 $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(?))";
00278 } else {
00279 $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(?))";
00280 $search = '%' . $search . '%';
00281 }
00282 $params[] = $params[] = $params[] = $params[] = $params[] = $search;
00283 break;
00284 case SUBMISSION_FIELD_EDITOR:
00285 $first_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.last_name');
00286 $first_middle_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.middle_name', '\' \'', 'ed.last_name');
00287 $last_comma_first = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name');
00288 $last_comma_first_middle = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name', '\' \'', 'ed.middle_name');
00289 if ($searchMatch === 'is') {
00290 $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(?))";
00291 } else {
00292 $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(?))";
00293 $search = '%' . $search . '%';
00294 }
00295 $params[] = $params[] = $params[] = $params[] = $params[] = $search;
00296 break;
00297 }
00298
00299 if (!empty($dateFrom) || !empty($dateTo)) switch($dateField) {
00300 case SUBMISSION_FIELD_DATE_SUBMITTED:
00301 if (!empty($dateFrom)) {
00302 $searchSql .= ' AND a.date_submitted >= ' . $this->datetimeToDB($dateFrom);
00303 }
00304 if (!empty($dateTo)) {
00305 $searchSql .= ' AND a.date_submitted <= ' . $this->datetimeToDB($dateTo);
00306 }
00307 break;
00308 case SUBMISSION_FIELD_DATE_COPYEDIT_COMPLETE:
00309 if (!empty($dateFrom)) {
00310 $searchSql .= ' AND c.date_final_completed >= ' . $this->datetimeToDB($dateFrom);
00311 }
00312 if (!empty($dateTo)) {
00313 $searchSql .= ' AND c.date_final_completed <= ' . $this->datetimeToDB($dateTo);
00314 }
00315 break;
00316 case SUBMISSION_FIELD_DATE_LAYOUT_COMPLETE:
00317 if (!empty($dateFrom)) {
00318 $searchSql .= ' AND l.date_completed >= ' . $this->datetimeToDB($dateFrom);
00319 }
00320 if (!empty($dateTo)) {
00321 $searchSql .= ' AND l.date_completed <= ' . $this->datetimeToDB($dateTo);
00322 }
00323 break;
00324 case SUBMISSION_FIELD_DATE_PROOFREADING_COMPLETE:
00325 if (!empty($dateFrom)) {
00326 $searchSql .= ' AND p.date_proofreader_completed >= ' . $this->datetimeToDB($dateFrom);
00327 }
00328 if (!empty($dateTo)) {
00329 $searchSql .= 'AND p.date_proofreader_completed <= ' . $this->datetimeToDB($dateTo);
00330 }
00331 break;
00332 }
00333
00334 $sql = 'SELECT DISTINCT
00335 a.*,
00336 c.*,
00337 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00338 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
00339 FROM
00340 articles a
00341 INNER JOIN article_authors aa ON (aa.article_id = a.article_id)
00342 LEFT JOIN sections s ON (s.section_id = a.section_id)
00343 LEFT JOIN copyed_assignments c ON (c.article_id = a.article_id)
00344 LEFT JOIN edit_assignments e ON (e.article_id = a.article_id)
00345 LEFT JOIN users ed ON (e.editor_id = ed.user_id)
00346 LEFT JOIN layouted_assignments l ON (l.article_id = a.article_id)
00347 LEFT JOIN proof_assignments p ON (p.article_id = a.article_id)
00348 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00349 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00350 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00351 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00352 LEFT JOIN article_settings atl ON (a.article_id = atl.article_id AND atl.setting_name = ?)
00353 WHERE
00354 ' . (isset($journalId)?'a.journal_id = ? AND':'') . '
00355 c.copyeditor_id = ? AND
00356 (' . ($active?'':'NOT ') . ' ((c.date_notified IS NOT NULL AND c.date_completed IS NULL) OR (c.date_final_notified IS NOT NULL AND c.date_final_completed IS NULL))) ';
00357
00358 $result = &$this->retrieveRange(
00359 $sql . ' ' . $searchSql . ' ORDER BY a.article_id ASC',
00360 count($params)==1?array_shift($params):$params,
00361 $rangeInfo);
00362
00363 $returner = &new DAOResultFactory($result, $this, '_returnCopyeditorSubmissionFromRow');
00364 return $returner;
00365 }
00366
00371 function getInsertCopyedId() {
00372 return $this->getInsertId('copyed_assignments', 'copyed_id');
00373 }
00374
00380 function getSubmissionsCount($copyeditorId, $journalId) {
00381 $submissionsCount = array();
00382 $submissionsCount[0] = 0;
00383 $submissionsCount[1] = 0;
00384
00385 $sql = 'SELECT c.date_final_completed FROM articles a LEFT JOIN sections s ON (s.section_id = a.section_id) LEFT JOIN copyed_assignments c ON (c.article_id = a.article_id) WHERE a.journal_id = ? AND c.copyeditor_id = ? AND c.date_notified IS NOT NULL';
00386
00387 $result = &$this->retrieve($sql, array($journalId, $copyeditorId));
00388
00389 while (!$result->EOF) {
00390 if ($result->fields['date_final_completed'] == null) {
00391 $submissionsCount[0] += 1;
00392 } else {
00393 $submissionsCount[1] += 1;
00394 }
00395 $result->moveNext();
00396 }
00397
00398 $result->Close();
00399 unset($result);
00400
00401 return $submissionsCount;
00402 }
00403 }
00404
00405 ?>