00001 <?php
00002
00016
00017
00018
00019 import('submission.proofreader.ProofreaderSubmission');
00020
00021 class ProofreaderSubmissionDAO extends DAO {
00023 var $articleDao;
00024 var $articleCommentDao;
00025 var $editAssignmentDao;
00026 var $proofAssignmentDao;
00027 var $layoutAssignmentDao;
00028 var $galleyDao;
00029 var $suppFileDao;
00030
00034 function ProofreaderSubmissionDAO() {
00035 parent::DAO();
00036
00037 $this->articleDao = &DAORegistry::getDAO('ArticleDAO');
00038 $this->articleCommentDao = &DAORegistry::getDAO('ArticleCommentDAO');
00039 $this->proofAssignmentDao = &DAORegistry::getDAO('ProofAssignmentDAO');
00040 $this->editAssignmentDao = &DAORegistry::getDAO('EditAssignmentDAO');
00041 $this->layoutAssignmentDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
00042 $this->galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00043 $this->suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00044 }
00045
00051 function &getSubmission($articleId, $journalId = null) {
00052 $primaryLocale = Locale::getPrimaryLocale();
00053 $locale = Locale::getLocale();
00054
00055 $params = array(
00056 'title',
00057 $primaryLocale,
00058 'title',
00059 $locale,
00060 'abbrev',
00061 $primaryLocale,
00062 'abbrev',
00063 $locale,
00064 $articleId
00065 );
00066 if ($journalId) $params[] = $journalId;
00067
00068 $result = &$this->retrieve(
00069 'SELECT a.*,
00070 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00071 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
00072 FROM articles a
00073 LEFT JOIN sections s ON s.section_id = a.section_id
00074 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00075 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00076 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00077 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00078 WHERE article_id = ?' .
00079 ($journalId?' AND a.journal_id = ?':''),
00080 $params
00081 );
00082
00083 $returner = null;
00084 if ($result->RecordCount() != 0) {
00085 $returner = &$this->_returnSubmissionFromRow($result->GetRowAssoc(false));
00086 }
00087
00088 $result->Close();
00089 unset($result);
00090
00091 return $returner;
00092 }
00093
00099 function &_returnSubmissionFromRow(&$row) {
00100 $submission = &new ProofreaderSubmission();
00101 $this->articleDao->_articleFromRow($submission, $row);
00102 $submission->setMostRecentProofreadComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_PROOFREAD, $row['article_id']));
00103 $submission->setProofAssignment($this->proofAssignmentDao->getProofAssignmentByArticleId($row['article_id']));
00104
00105
00106 $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
00107 $submission->setEditAssignments($editAssignments->toArray());
00108
00109
00110 $submission->setLayoutAssignment($this->layoutAssignmentDao->getLayoutAssignmentByArticleId($row['article_id']));
00111
00112 $submission->setGalleys($this->galleyDao->getGalleysByArticle($row['article_id']));
00113
00114 $submission->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['article_id']));
00115
00116 $submission->setMostRecentLayoutComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_LAYOUT, $row['article_id']));
00117
00118 HookRegistry::call('ProofreaderSubmissionDAO::_returnProofreaderSubmissionFromRow', array(&$submission, &$row));
00119
00120 return $submission;
00121 }
00122
00127 function updateSubmission(&$submission) {
00128
00129 $proofreadAssignment =& $submission->getProofAssignment();
00130 $this->proofAssignmentDao->updateProofAssignment($proofAssignment);
00131 }
00132
00146 function &getSubmissions($proofreaderId, $journalId = null, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $active = true, $rangeInfo = null) {
00147 $primaryLocale = Locale::getPrimaryLocale();
00148 $locale = Locale::getLocale();
00149
00150 $params = array(
00151 'title',
00152 $primaryLocale,
00153 'title',
00154 $locale,
00155 'abbrev',
00156 $primaryLocale,
00157 'abbrev',
00158 $locale,
00159 'title',
00160 $proofreaderId
00161 );
00162 if (isset($journalId)) $params[] = $journalId;
00163
00164 $searchSql = '';
00165
00166 if (!empty($search)) switch ($searchField) {
00167 case SUBMISSION_FIELD_TITLE:
00168 if ($searchMatch === 'is') {
00169 $searchSql = ' AND LOWER(atl.setting_value) = LOWER(?)';
00170 } else {
00171 $searchSql = ' AND LOWER(atl.setting_value) LIKE LOWER(?)';
00172 $search = '%' . $search . '%';
00173 }
00174 $params[] = $search;
00175 break;
00176 case SUBMISSION_FIELD_AUTHOR:
00177 $first_last = $this->_dataSource->Concat('aa.first_name', '\' \'', 'aa.last_name');
00178 $first_middle_last = $this->_dataSource->Concat('aa.first_name', '\' \'', 'aa.middle_name', '\' \'', 'aa.last_name');
00179 $last_comma_first = $this->_dataSource->Concat('aa.last_name', '\', \'', 'aa.first_name');
00180 $last_comma_first_middle = $this->_dataSource->Concat('aa.last_name', '\', \'', 'aa.first_name', '\' \'', 'aa.middle_name');
00181
00182 if ($searchMatch === 'is') {
00183 $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(?))";
00184 } else {
00185 $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(?))";
00186 $search = '%' . $search . '%';
00187 }
00188 $params[] = $params[] = $params[] = $params[] = $params[] = $search;
00189 break;
00190 case SUBMISSION_FIELD_EDITOR:
00191 $first_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.last_name');
00192 $first_middle_last = $this->_dataSource->Concat('ed.first_name', '\' \'', 'ed.middle_name', '\' \'', 'ed.last_name');
00193 $last_comma_first = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name');
00194 $last_comma_first_middle = $this->_dataSource->Concat('ed.last_name', '\', \'', 'ed.first_name', '\' \'', 'ed.middle_name');
00195 if ($searchMatch === 'is') {
00196 $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(?))";
00197 } else {
00198 $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(?))";
00199 $search = '%' . $search . '%';
00200 }
00201 $params[] = $params[] = $params[] = $params[] = $params[] = $search;
00202 break;
00203 }
00204
00205 if (!empty($dateFrom) || !empty($dateTo)) switch($dateField) {
00206 case SUBMISSION_FIELD_DATE_SUBMITTED:
00207 if (!empty($dateFrom)) {
00208 $searchSql .= ' AND a.date_submitted >= ' . $this->datetimeToDB($dateFrom);
00209 }
00210 if (!empty($dateTo)) {
00211 $searchSql .= ' AND a.date_submitted <= ' . $this->datetimeToDB($dateTo);
00212 }
00213 break;
00214 case SUBMISSION_FIELD_DATE_COPYEDIT_COMPLETE:
00215 if (!empty($dateFrom)) {
00216 $searchSql .= ' AND c.date_final_completed >= ' . $this->datetimeToDB($dateFrom);
00217 }
00218 if (!empty($dateTo)) {
00219 $searchSql .= ' AND c.date_final_completed <= ' . $this->datetimeToDB($dateTo);
00220 }
00221 break;
00222 case SUBMISSION_FIELD_DATE_LAYOUT_COMPLETE:
00223 if (!empty($dateFrom)) {
00224 $searchSql .= ' AND l.date_completed >= ' . $this->datetimeToDB($dateFrom);
00225 }
00226 if (!empty($dateTo)) {
00227 $searchSql .= ' AND l.date_completed <= ' . $this->datetimeToDB($dateTo);
00228 }
00229 break;
00230 case SUBMISSION_FIELD_DATE_PROOFREADING_COMPLETE:
00231 if (!empty($dateFrom)) {
00232 $searchSql .= ' AND p.date_proofreader_completed >= ' . $this->datetimeToDB($dateFrom);
00233 }
00234 if (!empty($dateTo)) {
00235 $searchSql .= 'AND p.date_proofreader_completed <= ' . $this->datetimeToDB($dateTo);
00236 }
00237 break;
00238 }
00239 $sql = 'SELECT DISTINCT
00240 a.*,
00241 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00242 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
00243 FROM
00244 articles a
00245 INNER JOIN article_authors aa ON (aa.article_id = a.article_id)
00246 INNER JOIN proof_assignments p ON (p.article_id = a.article_id)
00247 LEFT JOIN sections s ON s.section_id = a.section_id
00248 LEFT JOIN copyed_assignments c ON (c.article_id = a.article_id)
00249 LEFT JOIN edit_assignments e ON (e.article_id = a.article_id)
00250 LEFT JOIN users ed ON (e.editor_id = ed.user_id)
00251 LEFT JOIN layouted_assignments l ON (l.article_id = a.article_id)
00252 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00253 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00254 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00255 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00256 LEFT JOIN article_settings atl ON (a.article_id = atl.article_id AND atl.setting_name = ?)
00257 WHERE
00258 p.proofreader_id = ? AND
00259 ' . (isset($journalId)?'a.journal_id = ? AND':'') . '
00260 p.date_proofreader_notified IS NOT NULL';
00261
00262 if ($active) {
00263 $sql .= ' AND p.date_proofreader_completed IS NULL';
00264 } else {
00265 $sql .= ' AND p.date_proofreader_completed IS NOT NULL';
00266 }
00267
00268 $result = &$this->retrieveRange($sql . ' ' . $searchSql, $params, $rangeInfo);
00269
00270 $returner = &new DAOResultFactory ($result, $this, '_returnSubmissionFromRow');
00271 return $returner;
00272 }
00273
00279 function getSubmissionsCount($proofreaderId, $journalId) {
00280 $submissionsCount = array();
00281 $submissionsCount[0] = 0;
00282 $submissionsCount[1] = 0;
00283
00284 $sql = 'SELECT p.date_proofreader_completed FROM articles a INNER JOIN proof_assignments p ON (p.article_id = a.article_id) LEFT JOIN sections s ON s.section_id = a.section_id WHERE p.proofreader_id = ? AND a.journal_id = ? AND p.date_proofreader_notified IS NOT NULL';
00285
00286 $result = &$this->retrieve($sql, array($proofreaderId, $journalId));
00287
00288 while (!$result->EOF) {
00289 if ($result->fields['date_proofreader_completed'] == null) {
00290 $submissionsCount[0] += 1;
00291 } else {
00292 $submissionsCount[1] += 1;
00293 }
00294 $result->moveNext();
00295 }
00296
00297 return $submissionsCount;
00298 }
00299 }
00300
00301 ?>