00001 <?php
00002
00016
00017
00018
00019 import('article.Article');
00020
00021 class ArticleDAO extends DAO {
00022 var $authorDao;
00023
00027 function ArticleDAO() {
00028 parent::DAO();
00029 $this->authorDao = &DAORegistry::getDAO('AuthorDAO');
00030 }
00031
00036 function getLocaleFieldNames() {
00037 return array(
00038 'title', 'abstract', 'coverPageAltText', 'showCoverPage', 'hideCoverPageToc', 'hideCoverPageAbstract', 'originalFileName', 'fileName', 'width', 'height',
00039 'discipline', 'subjectClass', 'subject', 'coverageGeo', 'coverageChron', 'coverageSample', 'type', 'sponsor'
00040 );
00041 }
00042
00047 function updateLocaleFields(&$article) {
00048 $this->updateDataObjectSettings('article_settings', $article, array(
00049 'article_id' => $article->getArticleId()
00050 ));
00051 }
00052
00059 function &getArticle($articleId, $journalId = null) {
00060 $primaryLocale = Locale::getPrimaryLocale();
00061 $locale = Locale::getLocale();
00062 $params = array(
00063 'title',
00064 $primaryLocale,
00065 'title',
00066 $locale,
00067 'abbrev',
00068 $primaryLocale,
00069 'abbrev',
00070 $locale,
00071 $articleId
00072 );
00073 $sql = 'SELECT a.*,
00074 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00075 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
00076 FROM articles a
00077 LEFT JOIN sections s ON s.section_id = a.section_id
00078 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00079 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00080 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00081 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00082 WHERE article_id = ?';
00083 if ($journalId !== null) {
00084 $sql .= ' AND a.journal_id = ?';
00085 $params[] = $journalId;
00086 }
00087
00088 $result = &$this->retrieve($sql, $params);
00089
00090 $returner = null;
00091 if ($result->RecordCount() != 0) {
00092 $returner = &$this->_returnArticleFromRow($result->GetRowAssoc(false));
00093 }
00094
00095 $result->Close();
00096 unset($result);
00097
00098 return $returner;
00099 }
00100
00106 function &_returnArticleFromRow(&$row) {
00107 $article = &new Article();
00108 $this->_articleFromRow($article, $row);
00109 return $article;
00110 }
00111
00117 function _articleFromRow(&$article, &$row) {
00118 $article->setArticleId($row['article_id']);
00119 $article->setUserId($row['user_id']);
00120 $article->setJournalId($row['journal_id']);
00121 $article->setSectionId($row['section_id']);
00122 $article->setSectionTitle($row['section_title']);
00123 $article->setSectionAbbrev($row['section_abbrev']);
00124 $article->setLanguage($row['language']);
00125 $article->setCommentsToEditor($row['comments_to_ed']);
00126 $article->setDateSubmitted($this->datetimeFromDB($row['date_submitted']));
00127 $article->setDateStatusModified($this->datetimeFromDB($row['date_status_modified']));
00128 $article->setLastModified($this->datetimeFromDB($row['last_modified']));
00129 $article->setStatus($row['status']);
00130 $article->setSubmissionProgress($row['submission_progress']);
00131 $article->setCurrentRound($row['current_round']);
00132 $article->setSubmissionFileId($row['submission_file_id']);
00133 $article->setRevisedFileId($row['revised_file_id']);
00134 $article->setReviewFileId($row['review_file_id']);
00135 $article->setEditorFileId($row['editor_file_id']);
00136 $article->setCopyeditFileId($row['copyedit_file_id']);
00137 $article->setPages($row['pages']);
00138 $article->setFastTracked($row['fast_tracked']);
00139 $article->setHideAuthor($row['hide_author']);
00140 $article->setCommentsStatus($row['comments_status']);
00141
00142
00143 $article->setAuthors($this->authorDao->getAuthorsByArticle($row['article_id']));
00144
00145 $this->getDataObjectSettings('article_settings', 'article_id', $row['article_id'], $article);
00146
00147 HookRegistry::call('ArticleDAO::_returnArticleFromRow', array(&$article, &$row));
00148
00149 }
00150
00155 function insertArticle(&$article) {
00156 $article->stampModified();
00157 $this->update(
00158 sprintf('INSERT INTO articles
00159 (user_id, journal_id, section_id, language, comments_to_ed, date_submitted, date_status_modified, last_modified, status, submission_progress, current_round, submission_file_id, revised_file_id, review_file_id, editor_file_id, copyedit_file_id, pages, fast_tracked, hide_author, comments_status)
00160 VALUES
00161 (?, ?, ?, ?, ?, %s, %s, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00162 $this->datetimeToDB($article->getDateSubmitted()), $this->datetimeToDB($article->getDateStatusModified()), $this->datetimeToDB($article->getLastModified())),
00163 array(
00164 $article->getUserId(),
00165 $article->getJournalId(),
00166 $article->getSectionId(),
00167 $article->getLanguage(),
00168 $article->getCommentsToEditor(),
00169 $article->getStatus() === null ? STATUS_QUEUED : $article->getStatus(),
00170 $article->getSubmissionProgress() === null ? 1 : $article->getSubmissionProgress(),
00171 $article->getCurrentRound() === null ? 1 : $article->getCurrentRound(),
00172 $article->getSubmissionFileId(),
00173 $article->getRevisedFileId(),
00174 $article->getReviewFileId(),
00175 $article->getEditorFileId(),
00176 $article->getCopyeditFileId(),
00177 $article->getPages(),
00178 $article->getFastTracked()?1:0,
00179 $article->getHideAuthor() === null ? 0 : $article->getHideAuthor(),
00180 $article->getCommentsStatus() === null ? 0 : $article->getCommentsStatus()
00181 )
00182 );
00183
00184 $article->setArticleId($this->getInsertArticleId());
00185 $this->updateLocaleFields($article);
00186
00187
00188 $authors = &$article->getAuthors();
00189 for ($i=0, $count=count($authors); $i < $count; $i++) {
00190 $authors[$i]->setArticleId($article->getArticleId());
00191 $this->authorDao->insertAuthor($authors[$i]);
00192 }
00193
00194 return $article->getArticleId();
00195 }
00196
00201 function updateArticle(&$article) {
00202 $article->stampModified();
00203 $this->update(
00204 sprintf('UPDATE articles
00205 SET
00206 user_id = ?,
00207 section_id = ?,
00208 language = ?,
00209 comments_to_ed = ?,
00210 date_submitted = %s,
00211 date_status_modified = %s,
00212 last_modified = %s,
00213 status = ?,
00214 submission_progress = ?,
00215 current_round = ?,
00216 submission_file_id = ?,
00217 revised_file_id = ?,
00218 review_file_id = ?,
00219 editor_file_id = ?,
00220 copyedit_file_id = ?,
00221 pages = ?,
00222 fast_tracked = ?,
00223 hide_author = ?,
00224 comments_status = ?
00225 WHERE article_id = ?',
00226 $this->datetimeToDB($article->getDateSubmitted()), $this->datetimeToDB($article->getDateStatusModified()), $this->datetimeToDB($article->getLastModified())),
00227 array(
00228 $article->getUserId(),
00229 $article->getSectionId(),
00230 $article->getLanguage(),
00231 $article->getCommentsToEditor(),
00232 $article->getStatus(),
00233 $article->getSubmissionProgress(),
00234 $article->getCurrentRound(),
00235 $article->getSubmissionFileId(),
00236 $article->getRevisedFileId(),
00237 $article->getReviewFileId(),
00238 $article->getEditorFileId(),
00239 $article->getCopyeditFileId(),
00240 $article->getPages(),
00241 $article->getFastTracked(),
00242 $article->getHideAuthor(),
00243 $article->getCommentsStatus(),
00244 $article->getArticleId()
00245 )
00246 );
00247
00248 $this->updateLocaleFields($article);
00249
00250
00251 $authors = &$article->getAuthors();
00252 for ($i=0, $count=count($authors); $i < $count; $i++) {
00253 if ($authors[$i]->getAuthorId() > 0) {
00254 $this->authorDao->updateAuthor($authors[$i]);
00255 } else {
00256 $this->authorDao->insertAuthor($authors[$i]);
00257 }
00258 }
00259
00260
00261 $removedAuthors = $article->getRemovedAuthors();
00262 for ($i=0, $count=count($removedAuthors); $i < $count; $i++) {
00263 $this->authorDao->deleteAuthorById($removedAuthors[$i], $article->getArticleId());
00264 }
00265
00266
00267 $this->authorDao->resequenceAuthors($article->getArticleId());
00268 }
00269
00274 function deleteArticle(&$article) {
00275 return $this->deleteArticleById($article->getArticleId());
00276 }
00277
00282 function deleteArticleById($articleId) {
00283 $this->authorDao->deleteAuthorsByArticle($articleId);
00284
00285 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00286 $publishedArticleDao->deletePublishedArticleByArticleId($articleId);
00287
00288 $commentDao = &DAORegistry::getDAO('CommentDAO');
00289 $commentDao->deleteCommentsByArticle($articleId);
00290
00291 $articleNoteDao = &DAORegistry::getDAO('ArticleNoteDAO');
00292 $articleNoteDao->clearAllArticleNotes($articleId);
00293
00294 $sectionEditorSubmissionDao = &DAORegistry::getDAO('SectionEditorSubmissionDAO');
00295 $sectionEditorSubmissionDao->deleteDecisionsByArticle($articleId);
00296 $sectionEditorSubmissionDao->deleteReviewRoundsByArticle($articleId);
00297
00298 $reviewAssignmentDao = &DAORegistry::getDAO('ReviewAssignmentDAO');
00299 $reviewAssignmentDao->deleteReviewAssignmentsByArticle($articleId);
00300
00301 $editAssignmentDao = &DAORegistry::getDAO('EditAssignmentDAO');
00302 $editAssignmentDao->deleteEditAssignmentsByArticle($articleId);
00303
00304 $copyAssignmentDao = &DAORegistry::getDAO('CopyAssignmentDAO');
00305 $copyAssignmentDao->deleteCopyAssignmentsByArticle($articleId);
00306
00307 $layoutAssignmentDao = &DAORegistry::getDAO('LayoutAssignmentDAO');
00308 $layoutAssignmentDao->deleteLayoutAssignmentsByArticle($articleId);
00309
00310 $proofAssignmentDao = &DAORegistry::getDAO('ProofAssignmentDAO');
00311 $proofAssignmentDao->deleteProofAssignmentsByArticle($articleId);
00312
00313 $articleCommentDao = &DAORegistry::getDAO('ArticleCommentDAO');
00314 $articleCommentDao->deleteArticleComments($articleId);
00315
00316 $articleGalleyDao = &DAORegistry::getDAO('ArticleGalleyDAO');
00317 $articleGalleyDao->deleteGalleysByArticle($articleId);
00318
00319 $articleSearchDao = &DAORegistry::getDAO('ArticleSearchDAO');
00320 $articleSearchDao->deleteArticleKeywords($articleId);
00321
00322 $articleEventLogDao = &DAORegistry::getDAO('ArticleEventLogDAO');
00323 $articleEventLogDao->deleteArticleLogEntries($articleId);
00324
00325 $articleEmailLogDao = &DAORegistry::getDAO('ArticleEmailLogDAO');
00326 $articleEmailLogDao->deleteArticleLogEntries($articleId);
00327
00328 $articleEventLogDao = &DAORegistry::getDAO('ArticleEventLogDAO');
00329 $articleEventLogDao->deleteArticleLogEntries($articleId);
00330
00331 $suppFileDao = &DAORegistry::getDAO('SuppFileDAO');
00332 $suppFileDao->deleteSuppFilesByArticle($articleId);
00333
00334
00335 import('file.ArticleFileManager');
00336 $articleFileDao = &DAORegistry::getDAO('ArticleFileDAO');
00337 $articleFiles = &$articleFileDao->getArticleFilesByArticle($articleId);
00338
00339 $articleFileManager = &new ArticleFileManager($articleId);
00340 foreach ($articleFiles as $articleFile) {
00341 $articleFileManager->deleteFile($articleFile->getFileId());
00342 }
00343
00344 $articleFileDao->deleteArticleFiles($articleId);
00345
00346 $this->update('DELETE FROM article_settings WHERE article_id = ?', $articleId);
00347 $this->update('DELETE FROM articles WHERE article_id = ?', $articleId);
00348 }
00349
00356 function &getArticlesByJournalId($journalId) {
00357 $primaryLocale = Locale::getPrimaryLocale();
00358 $locale = Locale::getLocale();
00359 $articles = array();
00360
00361 $result = &$this->retrieve(
00362 'SELECT a.*,
00363 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00364 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
00365 FROM articles a
00366 LEFT JOIN sections s ON s.section_id = a.section_id
00367 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00368 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00369 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00370 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00371 WHERE a.journal_id = ?',
00372 array(
00373 'title',
00374 $primaryLocale,
00375 'title',
00376 $locale,
00377 'abbrev',
00378 $primaryLocale,
00379 'abbrev',
00380 $locale,
00381 $journalId
00382 )
00383 );
00384
00385 $returner = &new DAOResultFactory($result, $this, '_returnArticleFromRow');
00386 return $returner;
00387 }
00388
00393 function deleteArticlesByJournalId($journalId) {
00394 $articles = $this->getArticlesByJournalId($journalId);
00395
00396 while (!$articles->eof()) {
00397 $article = &$articles->next();
00398 $this->deleteArticleById($article->getArticleId());
00399 }
00400 }
00401
00408 function &getArticlesByUserId($userId, $journalId = null) {
00409 $primaryLocale = Locale::getPrimaryLocale();
00410 $locale = Locale::getLocale();
00411 $params = array(
00412 'title',
00413 $primaryLocale,
00414 'title',
00415 $locale,
00416 'abbrev',
00417 $primaryLocale,
00418 'abbrev',
00419 $locale,
00420 $userId
00421 );
00422 if ($journalId) $params[] = $journalId;
00423 $articles = array();
00424
00425 $result = &$this->retrieve(
00426 'SELECT a.*,
00427 COALESCE(stl.setting_value, stpl.setting_value) AS section_title,
00428 COALESCE(sal.setting_value, sapl.setting_value) AS section_abbrev
00429 FROM articles a
00430 LEFT JOIN sections s ON s.section_id = a.section_id
00431 LEFT JOIN section_settings stpl ON (s.section_id = stpl.section_id AND stpl.setting_name = ? AND stpl.locale = ?)
00432 LEFT JOIN section_settings stl ON (s.section_id = stl.section_id AND stl.setting_name = ? AND stl.locale = ?)
00433 LEFT JOIN section_settings sapl ON (s.section_id = sapl.section_id AND sapl.setting_name = ? AND sapl.locale = ?)
00434 LEFT JOIN section_settings sal ON (s.section_id = sal.section_id AND sal.setting_name = ? AND sal.locale = ?)
00435 WHERE a.user_id = ?' .
00436 (isset($journalId)?' AND a.journal_id = ?':''),
00437 $params
00438 );
00439
00440 while (!$result->EOF) {
00441 $articles[] = &$this->_returnArticleFromRow($result->GetRowAssoc(false));
00442 $result->MoveNext();
00443 }
00444
00445 $result->Close();
00446 unset($result);
00447
00448 return $articles;
00449 }
00450
00456 function getArticleJournalId($articleId) {
00457 $result = &$this->retrieve(
00458 'SELECT journal_id FROM articles WHERE article_id = ?', $articleId
00459 );
00460 $returner = isset($result->fields[0]) ? $result->fields[0] : false;
00461
00462 $result->Close();
00463 unset($result);
00464
00465 return $returner;
00466 }
00467
00475 function incompleteSubmissionExists($articleId, $userId, $journalId) {
00476 $result = &$this->retrieve(
00477 'SELECT submission_progress FROM articles WHERE article_id = ? AND user_id = ? AND journal_id = ? AND date_submitted IS NULL',
00478 array($articleId, $userId, $journalId)
00479 );
00480 $returner = isset($result->fields[0]) ? $result->fields[0] : false;
00481
00482 $result->Close();
00483 unset($result);
00484
00485 return $returner;
00486 }
00487
00493 function changeArticleStatus($articleId, $status) {
00494 $this->update(
00495 'UPDATE articles SET status = ? WHERE article_id = ?', array($status, $articleId)
00496 );
00497 }
00498
00503 function removeArticlesFromSection($sectionId) {
00504 $this->update(
00505 'UPDATE articles SET section_id = null WHERE section_id = ?', $sectionId
00506 );
00507 }
00508
00513 function getInsertArticleId() {
00514 return $this->getInsertId('articles', 'article_id');
00515 }
00516 }
00517
00518 ?>