00001 <?php
00002
00016 import('classes.monograph.MonographComment');
00017
00018 class MonographCommentDAO extends DAO {
00022 function MonographCommentDAO() {
00023 parent::DAO();
00024 }
00025
00032 function &getMonographComments($monographId, $commentType = null, $assocId = null) {
00033 if ($commentType == null) {
00034 $result =& $this->retrieve(
00035 'SELECT a.* FROM monograph_comments a WHERE monograph_id = ? ORDER BY date_posted', $monographId
00036 );
00037 } else {
00038 if ($assocId == null) {
00039 $result =& $this->retrieve(
00040 'SELECT a.* FROM monograph_comments a WHERE monograph_id = ? AND comment_type = ? ORDER BY date_posted',
00041 array($monographId, $commentType)
00042 );
00043 } else {
00044 $result =& $this->retrieve(
00045 'SELECT a.* FROM monograph_comments a WHERE monograph_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted',
00046 array($monographId, $commentType, $assocId)
00047 );
00048 }
00049 }
00050
00051 $returner = new DAOResultFactory($result, $this, '_returnMonographCommentFromRow');
00052 return $returner;
00053 }
00054
00060 function &getByUserId($userId) {
00061 $result =& $this->retrieve(
00062 'SELECT a.* FROM monograph_comments a WHERE author_id = ? ORDER BY date_posted', $userId
00063 );
00064
00065 $returner = new DAOResultFactory($result, $this, '_returnMonographCommentFromRow');
00066 return $returner;
00067 }
00068
00076 function &getReviewerCommentsByReviewerId($reviewerId, $monographId, $reviewId = null) {
00077 $params = array($reviewerId, $monographId);
00078 if (isset($reviewId)) {
00079 $params[] = $reviewId;
00080 }
00081 $result =& $this->retrieve(
00082 'SELECT a.* FROM monograph_comments a WHERE author_id = ? AND monograph_id = ?' . (isset($reviewId) ? ' AND assoc_id = ?' : '') . ' ORDER BY date_posted DESC',
00083 $params
00084 );
00085
00086 $returner = new DAOResultFactory($result, $this, '_returnMonographCommentFromRow');
00087 return $returner;
00088 }
00089
00096 function getMostRecentMonographComment($monographId, $commentType = null, $assocId = null) {
00097 if ($commentType == null) {
00098 $result =& $this->retrieveLimit(
00099 'SELECT a.* FROM monograph_comments a WHERE monograph_id = ? ORDER BY date_posted DESC',
00100 $monographId,
00101 1
00102 );
00103 } else {
00104 if ($assocId == null) {
00105 $result =& $this->retrieveLimit(
00106 'SELECT a.* FROM monograph_comments a WHERE monograph_id = ? AND comment_type = ? ORDER BY date_posted DESC',
00107 array($monographId, $commentType),
00108 1
00109 );
00110 } else {
00111 $result =& $this->retrieveLimit(
00112 'SELECT a.* FROM monograph_comments a WHERE monograph_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted DESC',
00113 array($monographId, $commentType, $assocId),
00114 1
00115 );
00116 }
00117 }
00118
00119 $returner = null;
00120 if (isset($result) && $result->RecordCount() != 0) {
00121 $returner =& $this->_returnMonographCommentFromRow($result->GetRowAssoc(false));
00122 }
00123
00124 $result->Close();
00125 unset($result);
00126
00127 return $returner;
00128 }
00129
00135 function &getById($commentId) {
00136 $result =& $this->retrieve(
00137 'SELECT a.* FROM monograph_comments a WHERE comment_id = ?', $commentId
00138 );
00139
00140 $monographComment =& $this->_returnMonographCommentFromRow($result->GetRowAssoc(false));
00141
00142 $result->Close();
00143 unset($result);
00144
00145 return $monographComment;
00146 }
00147
00153 function &_returnMonographCommentFromRow($row) {
00154 $monographComment = new MonographComment();
00155 $monographComment->setCommentId($row['comment_id']);
00156 $monographComment->setCommentType($row['comment_type']);
00157 $monographComment->setRoleId($row['role_id']);
00158 $monographComment->setMonographId($row['monograph_id']);
00159 $monographComment->setAssocId($row['assoc_id']);
00160 $monographComment->setAuthorId($row['author_id']);
00161 $monographComment->setCommentTitle($row['comment_title']);
00162 $monographComment->setComments($row['comments']);
00163 $monographComment->setDatePosted($this->datetimeFromDB($row['date_posted']));
00164 $monographComment->setDateModified($this->datetimeFromDB($row['date_modified']));
00165 $monographComment->setViewable($row['viewable']);
00166
00167 HookRegistry::call('MonographCommentDAO::_returnMonographCommentFromRow', array(&$monographComment, &$row));
00168
00169 return $monographComment;
00170 }
00171
00177 function insertMonographComment(&$monographComment) {
00178 $this->update(
00179 sprintf('INSERT INTO monograph_comments
00180 (comment_type, role_id, monograph_id, assoc_id, author_id, date_posted, date_modified, comment_title, comments, viewable)
00181 VALUES
00182 (?, ?, ?, ?, ?, %s, %s, ?, ?, ?)',
00183 $this->datetimeToDB($monographComment->getDatePosted()), $this->datetimeToDB($monographComment->getDateModified())),
00184 array(
00185 $monographComment->getCommentType(),
00186 $monographComment->getRoleId(),
00187 $monographComment->getMonographId(),
00188 $monographComment->getAssocId(),
00189 $monographComment->getAuthorId(),
00190 $monographComment->getCommentTitle(),
00191 $monographComment->getComments(),
00192 $monographComment->getViewable() === null ? 0 : $monographComment->getViewable()
00193 )
00194 );
00195
00196 $monographComment->setCommentId($this->getInsertMonographCommentId());
00197 return $monographComment->getCommentId();
00198 }
00199
00204 function getInsertMonographCommentId() {
00205 return $this->getInsertId('monograph_comments', 'comment_id');
00206 }
00207
00212 function deleteObject($monographComment) {
00213 $this->deleteById($monographComment->getCommentId());
00214 }
00215
00220 function deleteById($commentId) {
00221 $this->update(
00222 'DELETE FROM monograph_comments WHERE comment_id = ?', $commentId
00223 );
00224 }
00225
00230 function deleteByMonographId($monographId) {
00231 return $this->update(
00232 'DELETE FROM monograph_comments WHERE monograph_id = ?', $monographId
00233 );
00234 }
00235
00240 function updateObject($monographComment) {
00241 $this->update(
00242 sprintf('UPDATE monograph_comments
00243 SET
00244 comment_type = ?,
00245 role_id = ?,
00246 monograph_id = ?,
00247 assoc_id = ?,
00248 author_id = ?,
00249 date_posted = %s,
00250 date_modified = %s,
00251 comment_title = ?,
00252 comments = ?,
00253 viewable = ?
00254 WHERE comment_id = ?',
00255 $this->datetimeToDB($monographComment->getDatePosted()), $this->datetimeToDB($monographComment->getDateModified())),
00256 array(
00257 $monographComment->getCommentType(),
00258 $monographComment->getRoleId(),
00259 $monographComment->getMonographId(),
00260 $monographComment->getAssocId(),
00261 $monographComment->getAuthorId(),
00262 $monographComment->getCommentTitle(),
00263 $monographComment->getComments(),
00264 $monographComment->getViewable() === null ? 1 : $monographComment->getViewable(),
00265 $monographComment->getCommentId()
00266 )
00267 );
00268 }
00269 }
00270
00271 ?>