classes/paper/PaperDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 // $Id$
00017 
00018 
00019 import('paper.Paper');
00020 
00021 class PaperDAO extends DAO {
00022    var $authorDao;
00023 
00027    function PaperDAO() {
00028       parent::DAO();
00029       $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
00030    }
00031 
00036    function getAdditionalFieldNames() {
00037       return array('sessionType');
00038    }
00039 
00044    function getLocaleFieldNames() {
00045       return array('title', 'cleanTitle', 'abstract', 'discipline', 'subjectClass', 'subject', 'coverageGeo', 'coverageChron', 'coverageSample', 'type', 'sponsor');
00046    }
00047 
00052    function updateLocaleFields(&$paper) {
00053       $this->updateDataObjectSettings('paper_settings', $paper, array(
00054          'paper_id' => $paper->getId()
00055       ));
00056    }
00057 
00063    function &getPaper($paperId) {
00064       $primaryLocale = AppLocale::getPrimaryLocale();
00065       $locale = AppLocale::getLocale();
00066       $params = array(
00067          'title',
00068          $primaryLocale,
00069          'title',
00070          $locale,
00071          'abbrev',
00072          $primaryLocale,
00073          'abbrev',
00074          $locale,
00075          $paperId
00076       );
00077       $result =& $this->retrieve(
00078          'SELECT  p.*,
00079             COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
00080             COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
00081          FROM  papers p
00082             LEFT JOIN tracks t ON t.track_id = p.track_id
00083             LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
00084             LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
00085             LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
00086             LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
00087          WHERE paper_id = ?',
00088          $params
00089       );
00090 
00091       $returner = null;
00092       if ($result->RecordCount() != 0) {
00093          $returner =& $this->_returnPaperFromRow($result->GetRowAssoc(false));
00094       }
00095 
00096       $result->Close();
00097       unset($result);
00098 
00099       return $returner;
00100    }
00101 
00107    function &_returnPaperFromRow(&$row) {
00108       $paper = new Paper();
00109       $this->_paperFromRow($paper, $row);
00110       return $paper;
00111    }
00112 
00118    function _paperFromRow(&$paper, &$row) {
00119       $schedConfId = $row['sched_conf_id'];
00120       $schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00121       $schedConf =& $schedConfDao->getSchedConf($schedConfId);
00122       $conferenceId = $schedConf->getConferenceId();
00123 
00124       $paper->setId($row['paper_id']);
00125       $paper->setUserId($row['user_id']);
00126       $paper->setSchedConfId($row['sched_conf_id']);
00127       $paper->setTrackId($row['track_id']);
00128       $paper->setDateToPresentations($this->datetimeFromDB($row['date_to_presentations']));
00129       $paper->setDateToArchive($this->datetimeFromDB($row['date_to_archive']));
00130 
00131       $paper->setTrackTitle($row['track_title']);
00132       $paper->setTrackAbbrev($row['track_abbrev']);
00133       $paper->setLanguage($row['language']);
00134       $paper->setCommentsToDirector($row['comments_to_dr']);
00135       $paper->setCitations($row['citations']);
00136       $paper->setDateSubmitted($this->datetimeFromDB($row['date_submitted']));
00137       $paper->setDateStatusModified($this->datetimeFromDB($row['date_status_modified']));
00138       $paper->setLastModified($this->datetimeFromDB($row['last_modified']));
00139       $paper->setDateReminded($this->datetimeFromDB($row['date_reminded']));
00140       $paper->setStartTime($this->datetimeFromDB($row['start_time']));
00141       $paper->setEndTime($this->datetimeFromDB($row['end_time']));
00142       $paper->setStatus($row['status']);
00143       $paper->setSubmissionProgress($row['submission_progress']);
00144       $paper->setReviewMode($row['review_mode']);
00145       $paper->setCurrentStage($row['current_stage']);
00146       $paper->setSubmissionFileId($row['submission_file_id']);
00147       $paper->setRevisedFileId($row['revised_file_id']);
00148       $paper->setReviewFileId($row['review_file_id']);
00149       $paper->setLayoutFileId($row['layout_file_id']);
00150       $paper->setDirectorFileId($row['director_file_id']);
00151       $paper->setPages($row['pages']);
00152       $paper->setCommentsStatus($row['comments_status']);
00153 
00154       $paper->setAuthors($this->authorDao->getAuthorsByPaper($row['paper_id']));
00155 
00156       $this->getDataObjectSettings('paper_settings', 'paper_id', $row['paper_id'], $paper);
00157 
00158       HookRegistry::call('PaperDAO::_returnPaperFromRow', array(&$paper, &$row));
00159 
00160    }
00161 
00166    function insertPaper(&$paper) {
00167       $paper->stampModified();
00168       $this->update(
00169          sprintf('INSERT INTO papers
00170             (user_id,
00171              sched_conf_id,
00172              track_id,
00173              language,
00174              comments_to_dr,
00175              citations,
00176              date_submitted,
00177              date_status_modified,
00178              last_modified,
00179              date_reminded,
00180              start_time,
00181              end_time,
00182              date_to_presentations,
00183              date_to_archive,
00184              status,
00185              submission_progress,
00186              review_mode,
00187              current_stage,
00188              submission_file_id,
00189              revised_file_id,
00190              review_file_id,
00191              layout_file_id,
00192              director_file_id,
00193              pages,
00194              comments_status)
00195             VALUES
00196             (?, ?, ?, ?, ?, ?, %s, %s, %s, %s, %s, %s, %s, %s, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00197             $this->datetimeToDB($paper->getDateSubmitted()), $this->datetimeToDB($paper->getDateStatusModified()), $this->datetimeToDB($paper->getLastModified()), $this->datetimeToDB($paper->getDateReminded()), $this->datetimeToDB($paper->getStartTime()), $this->datetimeToDB($paper->getEndTime()), $this->datetimeToDB($paper->getDateToPresentations()), $this->datetimeToDB($paper->getDateToArchive())),
00198          array(
00199             $paper->getUserId(),
00200             $paper->getSchedConfId(),
00201             $paper->getTrackId(),
00202             $paper->getLanguage(),
00203             $paper->getCommentsToDirector(),
00204             $paper->getCitations(),
00205             $paper->getStatus() === null ? STATUS_QUEUED : $paper->getStatus(),
00206             $paper->getSubmissionProgress() === null ? 1 : $paper->getSubmissionProgress(),
00207             $paper->getReviewMode(),
00208             $paper->getCurrentStage(),
00209             $paper->getSubmissionFileId(),
00210             $paper->getRevisedFileId(),
00211             $paper->getReviewFileId(),
00212             $paper->getLayoutFileId(),
00213             $paper->getDirectorFileId(),
00214             $paper->getPages(),
00215             $paper->getCommentsStatus() === null ? 0 : $paper->getCommentsStatus()
00216          )
00217       );
00218 
00219       $paper->setId($this->getInsertPaperId());
00220       $this->updateLocaleFields($paper);
00221 
00222       // Insert authors for this paper
00223       $authors =& $paper->getAuthors();
00224       for ($i=0, $count=count($authors); $i < $count; $i++) {
00225          $authors[$i]->setPaperId($paper->getId());
00226          $this->authorDao->insertAuthor($authors[$i]);
00227       }
00228 
00229       return $paper->getId();
00230    }
00231 
00236    function updatePaper(&$paper) {
00237       $paper->stampModified();
00238       $this->update(
00239          sprintf('UPDATE papers
00240             SET
00241                user_id = ?,
00242                track_id = ?,
00243                language = ?,
00244                comments_to_dr = ?,
00245                citations = ?,
00246                date_submitted = %s,
00247                date_status_modified = %s,
00248                last_modified = %s,
00249                date_reminded = %s,
00250                start_time = %s,
00251                end_time = %s,
00252                date_to_presentations = %s,
00253                date_to_archive = %s,
00254                status = ?,
00255                submission_progress = ?,
00256                review_mode = ?,
00257                current_stage = ?,
00258                submission_file_id = ?,
00259                revised_file_id = ?,
00260                review_file_id = ?,
00261                layout_file_id = ?,
00262                director_file_id = ?,
00263                pages = ?,
00264                comments_status = ?
00265             WHERE paper_id = ?',
00266             $this->datetimeToDB($paper->getDateSubmitted()), $this->datetimeToDB($paper->getDateStatusModified()), $this->datetimeToDB($paper->getLastModified()), $this->datetimeToDB($paper->getDateReminded()), $this->datetimeToDB($paper->getStartTime()), $this->datetimeToDB($paper->getEndTime()), $this->datetimeToDB($paper->getDateToPresentations()), $this->datetimeToDB($paper->getDateToArchive())),
00267          array(
00268             $paper->getUserId(),
00269             $paper->getTrackId(),
00270             $paper->getLanguage(),
00271             $paper->getCommentsToDirector(),
00272             $paper->getCitations(),
00273             $paper->getStatus(),
00274             $paper->getSubmissionProgress(),
00275             $paper->getReviewMode(),
00276             $paper->getCurrentStage(),
00277             $paper->getSubmissionFileId(),
00278             $paper->getRevisedFileId(),
00279             $paper->getReviewFileId(),
00280             $paper->getLayoutFileId(),
00281             $paper->getDirectorFileId(),
00282             $paper->getPages(),
00283             $paper->getCommentsStatus(),
00284             $paper->getId()
00285          )
00286       );
00287 
00288       // update authors for this paper
00289       $authors =& $paper->getAuthors();
00290       for ($i=0, $count=count($authors); $i < $count; $i++) {
00291          if ($authors[$i]->getId() > 0) {
00292             $this->authorDao->updateAuthor($authors[$i]);
00293          } else {
00294             $this->authorDao->insertAuthor($authors[$i]);
00295          }
00296       }
00297 
00298       // Remove deleted authors
00299       $removedAuthors = $paper->getRemovedAuthors();
00300       for ($i=0, $count=count($removedAuthors); $i < $count; $i++) {
00301          $this->authorDao->deleteAuthorById($removedAuthors[$i], $paper->getId());
00302       }
00303 
00304       $this->updateLocaleFields($paper);
00305 
00306       // Update author sequence numbers
00307       $this->authorDao->resequenceAuthors($paper->getId());
00308    }
00309 
00314    function deletePaper(&$paper) {
00315       return $this->deletePaperById($paper->getId());
00316    }
00317 
00322    function deletePaperById($paperId) {
00323       $this->authorDao->deleteAuthorsByPaper($paperId);
00324 
00325       $publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00326       $publishedPaperDao->deletePublishedPaperByPaperId($paperId);
00327 
00328       $commentDao =& DAORegistry::getDAO('CommentDAO');
00329       $commentDao->deleteCommentsByPaper($paperId);
00330 
00331       $paperNoteDao =& DAORegistry::getDAO('PaperNoteDAO');
00332       $paperNoteDao->clearAllPaperNotes($paperId);
00333 
00334       $trackDirectorSubmissionDao =& DAORegistry::getDAO('TrackDirectorSubmissionDAO');
00335       $trackDirectorSubmissionDao->deleteDecisionsByPaper($paperId);
00336       $trackDirectorSubmissionDao->deleteReviewStagesByPaper($paperId);
00337 
00338       $reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00339       $reviewAssignmentDao->deleteReviewAssignmentsByPaper($paperId);
00340 
00341       $editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00342       $editAssignmentDao->deleteEditAssignmentsByPaper($paperId);
00343 
00344       $paperCommentDao =& DAORegistry::getDAO('PaperCommentDAO');
00345       $paperCommentDao->deletePaperComments($paperId);
00346 
00347       $paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00348       $paperGalleyDao->deleteGalleysByPaper($paperId);
00349 
00350       $paperSearchDao =& DAORegistry::getDAO('PaperSearchDAO');
00351       $paperSearchDao->deletePaperKeywords($paperId);
00352 
00353       $paperEventLogDao =& DAORegistry::getDAO('PaperEventLogDAO');
00354       $paperEventLogDao->deletePaperLogEntries($paperId);
00355 
00356       $paperEmailLogDao =& DAORegistry::getDAO('PaperEmailLogDAO');
00357       $paperEmailLogDao->deletePaperLogEntries($paperId);
00358 
00359       $paperEventLogDao =& DAORegistry::getDAO('PaperEventLogDAO');
00360       $paperEventLogDao->deletePaperLogEntries($paperId);
00361 
00362       $suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
00363       $suppFileDao->deleteSuppFilesByPaper($paperId);
00364 
00365       // Delete paper files -- first from the filesystem, then from the database
00366       import('file.PaperFileManager');
00367       $paperFileDao =& DAORegistry::getDAO('PaperFileDAO');
00368       $paperFiles =& $paperFileDao->getPaperFilesByPaper($paperId);
00369 
00370       $paperFileManager = new PaperFileManager($paperId);
00371       foreach ($paperFiles as $paperFile) {
00372          $paperFileManager->deleteFile($paperFile->getFileId());
00373       }
00374 
00375       $paperFileDao->deletePaperFiles($paperId);
00376 
00377       $this->update('DELETE FROM paper_settings WHERE paper_id = ?', $paperId);
00378       $this->update('DELETE FROM papers WHERE paper_id = ?', $paperId);
00379    }
00380 
00387    function &getPapersBySchedConfId($schedConfId, $trackId = null) {
00388       $primaryLocale = AppLocale::getPrimaryLocale();
00389       $locale = AppLocale::getLocale();
00390 
00391       $params = array(
00392          'title',
00393          $primaryLocale,
00394          'title',
00395          $locale,
00396          'abbrev',
00397          $primaryLocale,
00398          'abbrev',
00399          $locale,
00400          $schedConfId
00401       );
00402 
00403       if ($trackId) $params[] = $trackId;
00404 
00405       $papers = array();
00406       $result =& $this->retrieve(
00407          'SELECT  p.*,
00408             COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
00409             COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
00410          FROM  papers p
00411             LEFT JOIN tracks t ON t.track_id = p.track_id
00412             LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
00413             LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
00414             LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
00415             LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
00416             WHERE p.sched_conf_id = ?' .
00417             ($trackId ? ' AND p.track_id = ?' : ''),
00418          $params
00419       );
00420 
00421       $returner = new DAOResultFactory($result, $this, '_returnPaperFromRow');
00422       return $returner;
00423    }
00424 
00429    function deletePapersBySchedConfId($schedConfId) {
00430       $papers = $this->getPapersBySchedConfId($schedConfId);
00431 
00432       while (!$papers->eof()) {
00433          $paper =& $papers->next();
00434          $this->deletePaperById($paper->getId());
00435       }
00436    }
00437 
00444    function &getPapersByUserId($userId, $schedConfId = null) {
00445       $primaryLocale = AppLocale::getPrimaryLocale();
00446       $locale = AppLocale::getLocale();
00447 
00448       $params = array(
00449          'title',
00450          $primaryLocale,
00451          'title',
00452          $locale,
00453          'abbrev',
00454          $primaryLocale,
00455          'abbrev',
00456          $locale,
00457          $userId
00458       );
00459 
00460       if ($schedConfId) $params[] = $schedConfId;
00461 
00462       $papers = array();
00463 
00464       $result =& $this->retrieve(
00465          'SELECT p.*,
00466             COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
00467             COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
00468          FROM papers p
00469             LEFT JOIN tracks t ON t.track_id = p.track_id
00470             LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
00471             LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
00472             LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
00473             LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
00474          WHERE p.user_id = ?' . (isset($schedConfId)?' AND p.sched_conf_id = ?':''),
00475          $params
00476       );
00477 
00478       while (!$result->EOF) {
00479          $papers[] =& $this->_returnPaperFromRow($result->GetRowAssoc(false));
00480          $result->MoveNext();
00481       }
00482 
00483       $result->Close();
00484       unset($result);
00485 
00486       return $papers;
00487    }
00488 
00494    function getPaperSchedConfId($paperId) {
00495       $result =& $this->retrieve(
00496          'SELECT sched_conf_id FROM papers WHERE paper_id = ?', $paperId
00497       );
00498       $returner = isset($result->fields[0]) ? $result->fields[0] : false;
00499 
00500       $result->Close();
00501       unset($result);
00502 
00503       return $returner;
00504    }
00505 
00513    function incompleteSubmissionExists($paperId, $userId, $schedConfId) {
00514       $result =& $this->retrieve(
00515          'SELECT submission_progress FROM papers WHERE paper_id = ? AND user_id = ? AND sched_conf_id = ? AND date_submitted IS NULL',
00516          array($paperId, $userId, $schedConfId)
00517       );
00518       $returner = isset($result->fields[0]) ? $result->fields[0] : false;
00519 
00520       $result->Close();
00521       unset($result);
00522 
00523       return $returner;
00524    }
00525 
00531    function changePaperStatus($paperId, $status) {
00532       $this->update(
00533          'UPDATE papers SET status = ? WHERE paper_id = ?', array($status, $paperId)
00534       );
00535    }
00536 
00541    function removePapersFromTrack($trackId) {
00542       $this->update(
00543          'UPDATE papers SET track_id = null WHERE track_id = ?', $trackId
00544       );
00545    }
00546 
00551    function getInsertPaperId() {
00552       return $this->getInsertId('papers', 'paper_id');
00553    }
00554 }
00555 
00556 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7