00001 <?php
00002
00016
00017
00018
00019 import('submission.author.AuthorSubmission');
00020
00021 class AuthorSubmissionDAO extends DAO {
00022 var $articleDao;
00023 var $authorDao;
00024 var $userDao;
00025 var $reviewAssignmentDao;
00026 var $articleFileDao;
00027 var $suppFileDao;
00028 var $copyeditorSubmissionDao;
00029 var $articleCommentDao;
00030 var $layoutAssignmentDao;
00031 var $proofAssignmentDao;
00032 var $galleyDao;
00033
00037 function AuthorSubmissionDAO() {
00038 parent::DAO();
00039 $this->articleDao = &DAORegistry::getDAO('ArticleDAO');
00040 $this->authorDao = &DAORegistry::getDAO('AuthorDAO');
00041 $this->userDao = &DAORegistry::getDAO('UserDAO');
00042 $this->reviewAssignmentDao = &DAORegistry::getDAO('ReviewAssignmentDAO');
00043 $this->editAssignmentDao = &DAORegistry::getDAO('EditAssignmentDAO');
00044 $this->articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
00045 $this->suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00046 $this->copyeditorSubmissionDao = &DAORegistry::getDAO('CopyeditorSubmissionDAO');
00047 $this->articleCommentDao = &DAORegistry::getDAO('ArticleCommentDAO');
00048 $this->layoutAssignmentDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
00049 $this->proofAssignmentDao = &DAORegistry::getDAO('ProofAssignmentDAO');
00050 $this->galleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00051 }
00052
00058 function &getAuthorSubmission($articleId) {
00059 $primaryLocale = Locale::getPrimaryLocale();
00060 $locale = Locale::getLocale();
00061 $result = &$this->retrieve(
00062 'SELECT a.*,
00063 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00064 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev,
00065 c.copyed_id, c.copyeditor_id, c.date_notified AS copyeditor_date_notified, c.date_underway AS copyeditor_date_underway, c.date_completed AS copyeditor_date_completed, c.date_acknowledged AS copyeditor_date_acknowledged, c.date_author_notified AS ce_date_author_notified, c.date_author_underway AS ce_date_author_underway, c.date_author_completed AS ce_date_author_completed,
00066 c.date_author_acknowledged AS ce_date_author_acknowledged, c.date_final_notified AS ce_date_final_notified, c.date_final_underway AS ce_date_final_underway, c.date_final_completed AS ce_date_final_completed, c.date_final_acknowledged AS ce_date_final_acknowledged, c.initial_revision AS copyeditor_initial_revision, c.editor_author_revision AS ce_editor_author_revision,
00067 c.final_revision AS copyeditor_final_revision
00068 FROM articles a
00069 LEFT JOIN sections s ON (s.section_id = a.section_id)
00070 LEFT JOIN copyed_assignments c on (a.article_id = c.article_id)
00071 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00072 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00073 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00074 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00075 WHERE a.article_id = ?',
00076 array(
00077 'title',
00078 $primaryLocale,
00079 'title',
00080 $locale,
00081 'abbrev',
00082 $primaryLocale,
00083 'abbrev',
00084 $locale,
00085 $articleId,
00086 )
00087 );
00088
00089 $returner = null;
00090 if ($result->RecordCount() != 0) {
00091 $returner = &$this->_returnAuthorSubmissionFromRow($result->GetRowAssoc(false));
00092 }
00093
00094 $result->Close();
00095 unset($result);
00096
00097 return $returner;
00098 }
00099
00105 function &_returnAuthorSubmissionFromRow(&$row) {
00106 $authorSubmission = &new AuthorSubmission();
00107
00108
00109 $this->articleDao->_articleFromRow($authorSubmission, $row);
00110
00111
00112 $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByArticleId($row['article_id']);
00113 $authorSubmission->setEditAssignments($editAssignments->toArray());
00114
00115
00116 for ($i = 1; $i <= $row['current_round']; $i++) {
00117 $authorSubmission->setDecisions($this->getEditorDecisions($row['article_id'], $i), $i);
00118 }
00119
00120
00121 for ($i = 1; $i <= $row['current_round']; $i++) {
00122 $authorSubmission->setReviewAssignments($this->reviewAssignmentDao->getReviewAssignmentsByArticleId($row['article_id'], $i), $i);
00123 }
00124
00125
00126 $authorSubmission->setMostRecentEditorDecisionComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_EDITOR_DECISION, $row['article_id']));
00127 $authorSubmission->setMostRecentCopyeditComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_COPYEDIT, $row['article_id']));
00128 $authorSubmission->setMostRecentProofreadComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_PROOFREAD, $row['article_id']));
00129 $authorSubmission->setMostRecentLayoutComment($this->articleCommentDao->getMostRecentArticleComment($row['article_id'], COMMENT_TYPE_LAYOUT, $row['article_id']));
00130
00131
00132 $authorSubmission->setSubmissionFile($this->articleFileDao->getArticleFile($row['submission_file_id']));
00133 $authorSubmission->setRevisedFile($this->articleFileDao->getArticleFile($row['revised_file_id']));
00134 $authorSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByArticle($row['article_id']));
00135 for ($i = 1; $i <= $row['current_round']; $i++) {
00136 $authorSubmission->setAuthorFileRevisions($this->articleFileDao->getArticleFileRevisions($row['revised_file_id'], $i), $i);
00137 }
00138 for ($i = 1; $i <= $row['current_round']; $i++) {
00139 $authorSubmission->setEditorFileRevisions($this->articleFileDao->getArticleFileRevisions($row['editor_file_id'], $i), $i);
00140 }
00141 $authorSubmission->setGalleys($this->galleyDao->getGalleysByArticle($row['article_id']));
00142
00143
00144 if ($row['copyeditor_initial_revision'] != null) {
00145 $authorSubmission->setInitialCopyeditFile($this->articleFileDao->getArticleFile($row['copyedit_file_id'], $row['copyeditor_initial_revision']));
00146 }
00147
00148
00149 if ($row['ce_editor_author_revision'] != null) {
00150 $authorSubmission->setEditorAuthorCopyeditFile($this->articleFileDao->getArticleFile($row['copyedit_file_id'], $row['ce_editor_author_revision']));
00151 }
00152
00153
00154 if ($row['copyeditor_final_revision'] != null) {
00155 $authorSubmission->setFinalCopyeditFile($this->articleFileDao->getArticleFile($row['copyedit_file_id'], $row['copyeditor_final_revision']));
00156 }
00157
00158
00159 $authorSubmission->setCopyedId($row['copyed_id']);
00160 $authorSubmission->setCopyeditorId($row['copyeditor_id']);
00161 $authorSubmission->setCopyeditor($this->userDao->getUser($row['copyeditor_id']), true);
00162 $authorSubmission->setCopyeditorDateNotified($this->datetimeFromDB($row['copyeditor_date_notified']));
00163 $authorSubmission->setCopyeditorDateUnderway($this->datetimeFromDB($row['copyeditor_date_underway']));
00164 $authorSubmission->setCopyeditorDateCompleted($this->datetimeFromDB($row['copyeditor_date_completed']));
00165 $authorSubmission->setCopyeditorDateAcknowledged($this->datetimeFromDB($row['copyeditor_date_acknowledged']));
00166 $authorSubmission->setCopyeditorDateAuthorNotified($this->datetimeFromDB($row['ce_date_author_notified']));
00167 $authorSubmission->setCopyeditorDateAuthorUnderway($this->datetimeFromDB($row['ce_date_author_underway']));
00168 $authorSubmission->setCopyeditorDateAuthorCompleted($this->datetimeFromDB($row['ce_date_author_completed']));
00169 $authorSubmission->setCopyeditorDateAuthorAcknowledged($this->datetimeFromDB($row['ce_date_author_acknowledged']));
00170 $authorSubmission->setCopyeditorDateFinalNotified($this->datetimeFromDB($row['ce_date_final_notified']));
00171 $authorSubmission->setCopyeditorDateFinalUnderway($this->datetimeFromDB($row['ce_date_final_underway']));
00172 $authorSubmission->setCopyeditorDateFinalCompleted($this->datetimeFromDB($row['ce_date_final_completed']));
00173 $authorSubmission->setCopyeditorDateFinalAcknowledged($this->datetimeFromDB($row['ce_date_final_acknowledged']));
00174 $authorSubmission->setCopyeditorInitialRevision($row['copyeditor_initial_revision']);
00175 $authorSubmission->setCopyeditorEditorAuthorRevision($row['ce_editor_author_revision']);
00176 $authorSubmission->setCopyeditorFinalRevision($row['copyeditor_final_revision']);
00177
00178
00179 $authorSubmission->setLayoutAssignment($this->layoutAssignmentDao->getLayoutAssignmentByArticleId($row['article_id']));
00180
00181
00182 $authorSubmission->setProofAssignment($this->proofAssignmentDao->getProofAssignmentByArticleId($row['article_id']));
00183
00184 HookRegistry::call('AuthorSubmissionDAO::_returnAuthorSubmissionFromRow', array(&$authorSubmission, &$row));
00185
00186 return $authorSubmission;
00187 }
00188
00193 function updateAuthorSubmission(&$authorSubmission) {
00194
00195 if ($authorSubmission->getArticleId()) {
00196 $article = &$this->articleDao->getArticle($authorSubmission->getArticleId());
00197
00198
00199 $article->setRevisedFileId($authorSubmission->getRevisedFileId());
00200 $article->setDateStatusModified($authorSubmission->getDateStatusModified());
00201 $article->setLastModified($authorSubmission->getLastModified());
00202
00203
00204
00205 $article->setReviewFileId($authorSubmission->getReviewFileId());
00206 $article->setEditorFileId($authorSubmission->getEditorFileId());
00207
00208 $this->articleDao->updateArticle($article);
00209 }
00210
00211
00212
00213 if ($authorSubmission->getCopyedId()) {
00214 $copyeditorSubmission = &$this->copyeditorSubmissionDao->getCopyeditorSubmission($authorSubmission->getArticleId());
00215
00216
00217 $copyeditorSubmission->setDateAuthorUnderway($authorSubmission->getCopyeditorDateAuthorUnderway());
00218 $copyeditorSubmission->setDateAuthorCompleted($authorSubmission->getCopyeditorDateAuthorCompleted());
00219 $copyeditorSubmission->setDateFinalNotified($authorSubmission->getCopyeditorDateFinalNotified());
00220 $copyeditorSubmission->setEditorAuthorRevision($authorSubmission->getCopyeditorEditorAuthorRevision());
00221 $copyeditorSubmission->setDateStatusModified($authorSubmission->getDateStatusModified());
00222 $copyeditorSubmission->setLastModified($authorSubmission->getLastModified());
00223
00224 $this->copyeditorSubmissionDao->updateCopyeditorSubmission($copyeditorSubmission);
00225 }
00226 }
00227
00233 function &getAuthorSubmissions($authorId, $journalId, $active = true, $rangeInfo = null) {
00234 $primaryLocale = Locale::getPrimaryLocale();
00235 $locale = Locale::getLocale();
00236 $result = &$this->retrieveRange(
00237 'SELECT a.*,
00238 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00239 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev,
00240 c.copyed_id, c.copyeditor_id, c.date_notified AS copyeditor_date_notified, c.date_underway AS copyeditor_date_underway, c.date_completed AS copyeditor_date_completed, c.date_acknowledged AS copyeditor_date_acknowledged, c.date_author_notified AS ce_date_author_notified, c.date_author_underway AS ce_date_author_underway, c.date_author_completed AS ce_date_author_completed,
00241 c.date_author_acknowledged AS ce_date_author_acknowledged, c.date_final_notified AS ce_date_final_notified, c.date_final_underway AS ce_date_final_underway, c.date_final_completed AS ce_date_final_completed, c.date_final_acknowledged AS ce_date_final_acknowledged, c.initial_revision AS copyeditor_initial_revision, c.editor_author_revision AS ce_editor_author_revision,
00242 c.final_revision AS copyeditor_final_revision
00243 FROM articles a
00244 LEFT JOIN sections s ON (s.section_id = a.section_id)
00245 LEFT JOIN copyed_assignments c on (a.article_id = c.article_id)
00246 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00247 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00248 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00249 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00250 WHERE a.user_id = ? AND a.journal_id = ? AND ' .
00251 ($active?'a.status = 1':'(a.status <> 1 AND a.submission_progress = 0)'),
00252 array(
00253 'title',
00254 $primaryLocale,
00255 'title',
00256 $locale,
00257 'abbrev',
00258 $primaryLocale,
00259 'abbrev',
00260 $locale,
00261 $authorId,
00262 $journalId
00263 ),
00264 $rangeInfo
00265 );
00266
00267 $returner = &new DAOResultFactory($result, $this, '_returnAuthorSubmissionFromRow');
00268 return $returner;
00269 }
00270
00271
00272
00273
00274
00280 function getEditorDecisions($articleId, $round = null) {
00281 $decisions = array();
00282
00283 if ($round == null) {
00284 $result = &$this->retrieve(
00285 'SELECT edit_decision_id, editor_id, decision, date_decided FROM edit_decisions WHERE article_id = ? ORDER BY date_decided ASC', $articleId
00286 );
00287 } else {
00288 $result = &$this->retrieve(
00289 'SELECT edit_decision_id, editor_id, decision, date_decided FROM edit_decisions WHERE article_id = ? AND round = ? ORDER BY date_decided ASC',
00290 array($articleId, $round)
00291 );
00292 }
00293
00294 while (!$result->EOF) {
00295 $decisions[] = array(
00296 'editDecisionId' => $result->fields['edit_decision_id'],
00297 'editorId' => $result->fields['editor_id'],
00298 'decision' => $result->fields['decision'],
00299 'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
00300 );
00301 $result->moveNext();
00302 }
00303
00304 $result->Close();
00305 unset($result);
00306
00307 return $decisions;
00308 }
00309
00315 function getSubmissionsCount($authorId, $journalId) {
00316 $submissionsCount = array();
00317 $submissionsCount[0] = 0;
00318 $submissionsCount[1] = 0;
00319
00320 $sql = 'SELECT count(*), status FROM articles a LEFT JOIN sections s ON (s.section_id = a.section_id) LEFT JOIN copyed_assignments c on (a.article_id = c.article_id) WHERE a.journal_id = ? AND a.user_id = ? GROUP BY a.status';
00321
00322 $result = &$this->retrieve($sql, array($journalId, $authorId));
00323
00324 while (!$result->EOF) {
00325 if ($result->fields['status'] != 1) {
00326 $submissionsCount[1] += $result->fields[0];
00327 } else {
00328 $submissionsCount[0] += $result->fields[0];
00329 }
00330 $result->moveNext();
00331 }
00332
00333 $result->Close();
00334 unset($result);
00335
00336 return $submissionsCount;
00337 }
00338 }
00339
00340 ?>