classes/paper/PaperCommentDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('paper.PaperComment');
00019 
00020 class PaperCommentDAO extends DAO {
00027    function &getPaperComments($paperId, $commentType = null, $assocId = null) {
00028       $paperComments = array();
00029 
00030       if ($commentType == null) {
00031          $result =& $this->retrieve(
00032             'SELECT a.* FROM paper_comments a WHERE paper_id = ? ORDER BY date_posted',   $paperId
00033          );
00034       } else {
00035          if ($assocId == null) {
00036             $result =& $this->retrieve(
00037                'SELECT a.* FROM paper_comments a WHERE paper_id = ? AND comment_type = ? ORDER BY date_posted',   array($paperId, $commentType)
00038             );
00039          } else {
00040             $result =& $this->retrieve(
00041                'SELECT a.* FROM paper_comments a WHERE paper_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted',
00042                array($paperId, $commentType, $assocId)
00043             );
00044          }           
00045       }
00046 
00047       while (!$result->EOF) {
00048          $paperComments[] =& $this->_returnPaperCommentFromRow($result->GetRowAssoc(false));
00049          $result->moveNext();
00050       }
00051 
00052       $result->Close();
00053       unset($result);
00054 
00055       return $paperComments;
00056    }
00057 
00063    function &getPaperCommentsByUserId($userId) {
00064       $paperComments = array();
00065 
00066       $result =& $this->retrieve(
00067          'SELECT a.* FROM paper_comments a WHERE author_id = ? ORDER BY date_posted',  $userId
00068       );
00069 
00070       while (!$result->EOF) {
00071          $paperComments[] =& $this->_returnPaperCommentFromRow($result->GetRowAssoc(false));
00072          $result->moveNext();
00073       }
00074 
00075       $result->Close();
00076       unset($result);
00077 
00078       return $paperComments;
00079    }
00080 
00087    function getMostRecentPaperComment($paperId, $commentType = null, $assocId = null) {
00088       if ($commentType == null) {
00089          $result =& $this->retrieveLimit(
00090             'SELECT a.* FROM paper_comments a WHERE paper_id = ? ORDER BY date_posted DESC',
00091             $paperId,
00092             1
00093          );
00094       } else {
00095          if ($assocId == null) {
00096             $result =& $this->retrieveLimit(
00097                'SELECT a.* FROM paper_comments a WHERE paper_id = ? AND comment_type = ? ORDER BY date_posted DESC',
00098                array($paperId, $commentType),
00099                1
00100             );
00101          } else {
00102             $result =& $this->retrieveLimit(
00103                'SELECT a.* FROM paper_comments a WHERE paper_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted DESC',
00104                array($paperId, $commentType, $assocId),
00105                1
00106             );
00107          }           
00108       }
00109 
00110       $returner = null;
00111       if (isset($result) && $result->RecordCount() != 0) {
00112          $returner =& $this->_returnPaperCommentFromRow($result->GetRowAssoc(false));
00113       }
00114 
00115       $result->Close();
00116       unset($result);
00117 
00118       return $returner;
00119    }
00120 
00126    function &getPaperCommentById($commentId) {
00127       $result =& $this->retrieve(
00128          'SELECT a.* FROM paper_comments a WHERE comment_id = ?', $commentId
00129       );
00130 
00131       $paperComment =& $this->_returnPaperCommentFromRow($result->GetRowAssoc(false));
00132 
00133       $result->Close();
00134       unset($result);
00135 
00136       return $paperComment;
00137    }  
00138 
00144    function &_returnPaperCommentFromRow($row) {
00145       $paperComment = new PaperComment();
00146       $paperComment->setId($row['comment_id']);
00147       $paperComment->setCommentType($row['comment_type']);
00148       $paperComment->setRoleId($row['role_id']);
00149       $paperComment->setPaperId($row['paper_id']);
00150       $paperComment->setAssocId($row['assoc_id']);
00151       $paperComment->setAuthorId($row['author_id']);
00152       $paperComment->setCommentTitle($row['comment_title']);
00153       $paperComment->setComments($row['comments']);
00154       $paperComment->setDatePosted($this->datetimeFromDB($row['date_posted']));
00155       $paperComment->setDateModified($this->datetimeFromDB($row['date_modified']));
00156       $paperComment->setViewable($row['viewable']);
00157 
00158       HookRegistry::call('PaperCommentDAO::_returnPaperCommentFromRow', array(&$paperComment, &$row));
00159 
00160       return $paperComment;
00161    }
00162 
00168    function insertPaperComment(&$paperComment) {
00169       $this->update(
00170          sprintf('INSERT INTO paper_comments
00171             (comment_type, role_id, paper_id, assoc_id, author_id, date_posted, date_modified, comment_title, comments, viewable)
00172             VALUES
00173             (?, ?, ?, ?, ?, %s, %s, ?, ?, ?)',
00174             $this->datetimeToDB($paperComment->getDatePosted()), $this->datetimeToDB($paperComment->getDateModified())),
00175          array(
00176             $paperComment->getCommentType(),
00177             $paperComment->getRoleId(),
00178             $paperComment->getPaperId(),
00179             $paperComment->getAssocId(),
00180             $paperComment->getAuthorId(),
00181             String::substr($paperComment->getCommentTitle(), 0, 255),
00182             $paperComment->getComments(),
00183             $paperComment->getViewable() === null ? 0 : $paperComment->getViewable()
00184          )
00185       );
00186 
00187       $paperComment->setId($this->getInsertPaperCommentId());
00188       return $paperComment->getId();      
00189    }
00190 
00195    function getInsertPaperCommentId() {
00196       return $this->getInsertId('paper_comments', 'comment_id');
00197    }  
00198 
00203    function deletePaperComment($paperComment) {
00204       $this->deletePaperCommentById($paperComment->getId());
00205    }
00206 
00211    function deletePaperCommentById($commentId) {
00212       $this->update(
00213          'DELETE FROM paper_comments WHERE comment_id = ?', $commentId
00214       );
00215    }
00216 
00221    function deletePaperComments($paperId) {
00222       return $this->update(
00223          'DELETE FROM paper_comments WHERE paper_id = ?', $paperId
00224       );
00225    }
00226 
00231    function updatePaperComment($paperComment) {
00232       $this->update(
00233          sprintf('UPDATE paper_comments
00234             SET
00235                comment_type = ?,
00236                role_id = ?,
00237                paper_id = ?,
00238                assoc_id = ?,
00239                author_id = ?,
00240                date_posted = %s,
00241                date_modified = %s,
00242                comment_title = ?,
00243                comments = ?,
00244                viewable = ?
00245             WHERE comment_id = ?',
00246             $this->datetimeToDB($paperComment->getDatePosted()), $this->datetimeToDB($paperComment->getDateModified())),
00247          array(
00248             $paperComment->getCommentType(),
00249             $paperComment->getRoleId(),
00250             $paperComment->getPaperId(),
00251             $paperComment->getAssocId(),
00252             $paperComment->getAuthorId(),
00253             String::substr($paperComment->getCommentTitle(), 0, 255),
00254             $paperComment->getComments(),
00255             $paperComment->getViewable() === null ? 1 : $paperComment->getViewable(),
00256             $paperComment->getId()
00257          )
00258       );
00259    }
00260 }
00261 
00262 ?>

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