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