classes/submission/author/AuthorSubmissionDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('submission.author.AuthorSubmission');
00019 
00020 class AuthorSubmissionDAO extends DAO {
00021 
00022    var $paperDao;
00023    var $authorDao;
00024    var $userDao;
00025    var $reviewAssignmentDao;
00026    var $paperFileDao;
00027    var $suppFileDao;
00028    var $paperCommentDao;
00029    var $galleyDao;
00030 
00034    function AuthorSubmissionDAO() {
00035       parent::DAO();
00036       $this->paperDao =& DAORegistry::getDAO('PaperDAO');
00037       $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
00038       $this->userDao =& DAORegistry::getDAO('UserDAO');
00039       $this->reviewAssignmentDao =& DAORegistry::getDAO('ReviewAssignmentDAO');
00040       $this->editAssignmentDao =& DAORegistry::getDAO('EditAssignmentDAO');
00041       $this->paperFileDao =& DAORegistry::getDAO('PaperFileDAO');
00042       $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
00043       $this->paperCommentDao =& DAORegistry::getDAO('PaperCommentDAO');
00044       $this->galleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00045    }
00046 
00052    function &getAuthorSubmission($paperId) {
00053       $primaryLocale = AppLocale::getPrimaryLocale();
00054       $locale = AppLocale::getLocale();
00055       $result =& $this->retrieve(
00056          'SELECT
00057             p.*,
00058             COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
00059             COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
00060          FROM  papers p
00061             LEFT JOIN tracks t ON (t.track_id = p.track_id)
00062             LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
00063             LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
00064             LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
00065             LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
00066          WHERE p.paper_id = ?',
00067          array(
00068             'title',
00069             $primaryLocale,
00070             'title',
00071             $locale,
00072             'abbrev',
00073             $primaryLocale,
00074             'abbrev',
00075             $locale,
00076             $paperId
00077          )
00078       );
00079 
00080       $returner = null;
00081       if ($result->RecordCount() != 0) {
00082          $returner =& $this->_returnAuthorSubmissionFromRow($result->GetRowAssoc(false));
00083       }
00084 
00085       $result->Close();
00086       unset($result);
00087 
00088       return $returner;
00089    }
00090 
00096    function &_returnAuthorSubmissionFromRow(&$row) {
00097       $authorSubmission = new AuthorSubmission();
00098 
00099       // Paper attributes
00100       $this->paperDao->_paperFromRow($authorSubmission, $row);
00101 
00102       // Director Assignment
00103       $editAssignments =& $this->editAssignmentDao->getEditAssignmentsByPaperId($row['paper_id']);
00104       $authorSubmission->setEditAssignments($editAssignments->toArray());
00105 
00106       // Director Decisions
00107       for ($i = 1; $i <= $row['current_stage']; $i++) {
00108          $authorSubmission->setDecisions($this->getDirectorDecisions($row['paper_id'], $i), $i);
00109       }
00110 
00111       // Review Assignments
00112       for ($i = 1; $i <= $row['current_stage']; $i++)
00113          $authorSubmission->setReviewAssignments($this->reviewAssignmentDao->getReviewAssignmentsByPaperId($row['paper_id'], $i), $i);
00114 
00115       // Comments
00116       $authorSubmission->setMostRecentDirectorDecisionComment($this->paperCommentDao->getMostRecentPaperComment($row['paper_id'], COMMENT_TYPE_DIRECTOR_DECISION, $row['paper_id']));
00117 
00118       // Files
00119       $authorSubmission->setSubmissionFile($this->paperFileDao->getPaperFile($row['submission_file_id']));
00120       $authorSubmission->setRevisedFile($this->paperFileDao->getPaperFile($row['revised_file_id']));
00121       $authorSubmission->setSuppFiles($this->suppFileDao->getSuppFilesByPaper($row['paper_id']));
00122       for ($i = 1; $i <= $row['current_stage']; $i++) {
00123          $authorSubmission->setAuthorFileRevisions($this->paperFileDao->getPaperFileRevisions($row['revised_file_id'], $i), $i);
00124       }
00125       for ($i = 1; $i <= $row['current_stage']; $i++) {
00126          $authorSubmission->setDirectorFileRevisions($this->paperFileDao->getPaperFileRevisions($row['director_file_id'], $i), $i);
00127       }
00128       $authorSubmission->setLayoutFile($this->paperFileDao->getPaperFile($row['layout_file_id']));
00129       $authorSubmission->setGalleys($this->galleyDao->getGalleysByPaper($row['paper_id']));
00130 
00131       HookRegistry::call('AuthorSubmissionDAO::_returnAuthorSubmissionFromRow', array(&$authorSubmission, &$row));
00132 
00133       return $authorSubmission;
00134    }
00135 
00140    function updateAuthorSubmission(&$authorSubmission) {
00141       // Update paper
00142       if ($authorSubmission->getPaperId()) {
00143          $paper =& $this->paperDao->getPaper($authorSubmission->getPaperId());
00144 
00145          // Only update fields that an author can actually edit.
00146          $paper->setRevisedFileId($authorSubmission->getRevisedFileId());
00147          $paper->setDateStatusModified($authorSubmission->getDateStatusModified());
00148          $paper->setLastModified($authorSubmission->getLastModified());
00149          // FIXME: These two are necessary for designating the
00150          // original as the review version, but they are probably
00151          // best not exposed like this.
00152          $paper->setReviewFileId($authorSubmission->getReviewFileId());
00153          $paper->setDirectorFileId($authorSubmission->getDirectorFileId());
00154 
00155          $this->paperDao->updatePaper($paper);
00156       }
00157    }
00158 
00163    function &getIncompleteSubmissions() {
00164       $primaryLocale = AppLocale::getPrimaryLocale();
00165       $locale = AppLocale::getLocale();
00166       $incompleteSubmissions = array();
00167       $result =& $this->retrieve(
00168          'SELECT  p.*,
00169             COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
00170             COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
00171          FROM  papers p
00172             LEFT JOIN tracks t ON (t.track_id = p.track_id)
00173             LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
00174             LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
00175             LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
00176             LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
00177          WHERE p.submission_progress != 0 AND
00178             p.status = ' . (int)STATUS_QUEUED,
00179          array(
00180             'title',
00181             $primaryLocale,
00182             'title',
00183             $locale,
00184             'abbrev',
00185             $primaryLocale,
00186             'abbrev',
00187             $locale
00188          )
00189       );
00190 
00191       while(!$result->EOF) {
00192          $incompleteSubmissions[] =& $this->_returnAuthorSubmissionFromRow($result->getRowAssoc(false));
00193          $result->moveNext();
00194       }
00195       return $incompleteSubmissions;
00196    }
00197 
00203    function &getAuthorSubmissions($authorId, $schedConfId, $active = true, $rangeInfo = null, $sortBy = null, $sortDirection = SORT_DIRECTION_ASC) {
00204       $primaryLocale = AppLocale::getPrimaryLocale();
00205       $locale = AppLocale::getLocale();
00206       $result =& $this->retrieveRange(
00207          'SELECT  p.*,
00208             COALESCE(ptl.setting_value, pptl.setting_value) AS submission_title,
00209             pa.last_name AS author_name,
00210             (SELECT SUM(g.views) FROM paper_galleys g WHERE (g.paper_id = p.paper_id AND g.locale = ?)) AS galley_views,
00211             COALESCE(ttl.setting_value, ttpl.setting_value) AS track_title,
00212             COALESCE(tal.setting_value, tapl.setting_value) AS track_abbrev
00213          FROM  papers p
00214             LEFT JOIN paper_authors pa ON (pa.paper_id = p.paper_id AND pa.primary_contact = 1)
00215             LEFT JOIN paper_settings pptl ON (p.paper_id = pptl.paper_id AND pptl.setting_name = ? AND pptl.locale = ?)
00216             LEFT JOIN paper_settings ptl ON (p.paper_id = ptl.paper_id AND ptl.setting_name = ? AND ptl.locale = ?)
00217             LEFT JOIN tracks t ON (t.track_id = p.track_id)
00218             LEFT JOIN track_settings ttpl ON (t.track_id = ttpl.track_id AND ttpl.setting_name = ? AND ttpl.locale = ?)
00219             LEFT JOIN track_settings ttl ON (t.track_id = ttl.track_id AND ttl.setting_name = ? AND ttl.locale = ?)
00220             LEFT JOIN track_settings tapl ON (t.track_id = tapl.track_id AND tapl.setting_name = ? AND tapl.locale = ?)
00221             LEFT JOIN track_settings tal ON (t.track_id = tal.track_id AND tal.setting_name = ? AND tal.locale = ?)
00222          WHERE p.sched_conf_id = ?
00223             AND p.user_id = ?' .
00224             ($active?(' AND p.status = ' . (int) STATUS_QUEUED):(
00225                ' AND ((p.status <> ' . (int) STATUS_QUEUED . ' AND p.submission_progress = 0) OR (p.status = ' . (int) STATUS_ARCHIVED . '))'
00226             )) .
00227             ($sortBy?(' ORDER BY ' . $this->getSortMapping($sortBy) . ' ' . $this->getDirectionMapping($sortDirection)) : ''),
00228          array(
00229             $locale,
00230             'cleanTitle',
00231             $primaryLocale,
00232             'cleanTitle',
00233             $locale,
00234             'title',
00235             $primaryLocale,
00236             'title',
00237             $locale,
00238             'abbrev',
00239             $primaryLocale,
00240             'abbrev',
00241             $locale,
00242             $schedConfId,
00243             $authorId
00244          ),
00245          $rangeInfo
00246       );
00247 
00248       $returner = new DAOResultFactory($result, $this, '_returnAuthorSubmissionFromRow');
00249       return $returner;
00250    }
00251 
00252    //
00253    // Miscellaneous
00254    //
00255 
00261    function getDirectorDecisions($paperId, $stage = null) {
00262       $decisions = array();
00263       $args = array($paperId);
00264       if($stage) {
00265          $args[] = $stage;
00266       }
00267 
00268       $result =& $this->retrieve(
00269          'SELECT edit_decision_id, director_id, decision, date_decided
00270          FROM edit_decisions
00271          WHERE paper_id = ? ' .
00272          ($stage?' AND stage = ?':'') .
00273          ' ORDER BY date_decided ASC',
00274          (count($args)==1?shift($args):$args)
00275       );
00276 
00277       while (!$result->EOF) {
00278          $decisions[] = array(
00279             'editDecisionId' => $result->fields['edit_decision_id'],
00280             'directorId' => $result->fields['director_id'],
00281             'decision' => $result->fields['decision'],
00282             'dateDecided' => $this->datetimeFromDB($result->fields['date_decided'])
00283          );
00284          $result->moveNext();
00285       }
00286 
00287       $result->Close();
00288       unset($result);
00289 
00290       return $decisions;
00291    }
00292 
00298    function getSubmissionsCount($authorId, $schedConfId) {
00299       $submissionsCount = array();
00300       $submissionsCount[0] = 0;
00301       $submissionsCount[1] = 0;
00302 
00303       $sql = '
00304          SELECT   count(*), status
00305          FROM  papers p 
00306          WHERE p.sched_conf_id = ? AND
00307             p.user_id = ?
00308          GROUP BY p.status';
00309 
00310       $result =& $this->retrieve($sql, array($schedConfId, $authorId));
00311 
00312       while (!$result->EOF) {
00313          if ($result->fields['status'] != 1) {
00314             $submissionsCount[1] += $result->fields[0];
00315          } else {
00316             $submissionsCount[0] += $result->fields[0];
00317          }
00318          $result->moveNext();
00319       }
00320 
00321       $result->Close();
00322       unset($result);
00323 
00324       return $submissionsCount;
00325    }
00326    
00332    function getSortMapping($heading) {
00333       switch ($heading) {
00334          case 'id': return 'p.paper_id';
00335          case 'submitDate': return 'p.date_submitted';
00336          case 'track': return 'track_abbrev';
00337          case 'authors': return 'author_name';
00338          case 'title': return 'submission_title';
00339          case 'active': return 'p.submission_progress';
00340          case 'views': return 'galley_views';
00341          case 'status': return 'p.status';
00342          default: return null;
00343       }
00344    }
00345 }
00346 
00347 ?>

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