00001 <?php
00002
00016
00017
00018
00019 import('article.ArticleComment');
00020
00021 class ArticleCommentDAO extends DAO {
00028 function &getArticleComments($articleId, $commentType = null, $assocId = null) {
00029 $articleComments = array();
00030
00031 if ($commentType == null) {
00032 $result = &$this->retrieve(
00033 'SELECT a.* FROM article_comments a WHERE article_id = ? ORDER BY date_posted', $articleId
00034 );
00035 } else {
00036 if ($assocId == null) {
00037 $result = &$this->retrieve(
00038 'SELECT a.* FROM article_comments a WHERE article_id = ? AND comment_type = ? ORDER BY date_posted', array($articleId, $commentType)
00039 );
00040 } else {
00041 $result = &$this->retrieve(
00042 'SELECT a.* FROM article_comments a WHERE article_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted',
00043 array($articleId, $commentType, $assocId)
00044 );
00045 }
00046 }
00047
00048 while (!$result->EOF) {
00049 $articleComments[] = &$this->_returnArticleCommentFromRow($result->GetRowAssoc(false));
00050 $result->moveNext();
00051 }
00052
00053 $result->Close();
00054 unset($result);
00055
00056 return $articleComments;
00057 }
00058
00064 function &getArticleCommentsByUserId($userId) {
00065 $articleComments = array();
00066
00067 $result = &$this->retrieve(
00068 'SELECT a.* FROM article_comments a WHERE author_id = ? ORDER BY date_posted', $userId
00069 );
00070
00071 while (!$result->EOF) {
00072 $articleComments[] = &$this->_returnArticleCommentFromRow($result->GetRowAssoc(false));
00073 $result->moveNext();
00074 }
00075
00076 $result->Close();
00077 unset($result);
00078
00079 return $articleComments;
00080 }
00081
00088 function getMostRecentArticleComment($articleId, $commentType = null, $assocId = null) {
00089 if ($commentType == null) {
00090 $result = &$this->retrieveLimit(
00091 'SELECT a.* FROM article_comments a WHERE article_id = ? ORDER BY date_posted DESC',
00092 $articleId,
00093 1
00094 );
00095 } else {
00096 if ($assocId == null) {
00097 $result = &$this->retrieveLimit(
00098 'SELECT a.* FROM article_comments a WHERE article_id = ? AND comment_type = ? ORDER BY date_posted DESC',
00099 array($articleId, $commentType),
00100 1
00101 );
00102 } else {
00103 $result = &$this->retrieveLimit(
00104 'SELECT a.* FROM article_comments a WHERE article_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted DESC',
00105 array($articleId, $commentType, $assocId),
00106 1
00107 );
00108 }
00109 }
00110
00111 $returner = null;
00112 if (isset($result) && $result->RecordCount() != 0) {
00113 $returner = &$this->_returnArticleCommentFromRow($result->GetRowAssoc(false));
00114 }
00115
00116 $result->Close();
00117 unset($result);
00118
00119 return $returner;
00120 }
00121
00127 function &getArticleCommentById($commentId) {
00128 $result = &$this->retrieve(
00129 'SELECT a.* FROM article_comments a WHERE comment_id = ?', $commentId
00130 );
00131
00132 $articleComment = &$this->_returnArticleCommentFromRow($result->GetRowAssoc(false));
00133
00134 $result->Close();
00135 unset($result);
00136
00137 return $articleComment;
00138 }
00139
00145 function &_returnArticleCommentFromRow($row) {
00146 $articleComment = &new ArticleComment();
00147 $articleComment->setCommentId($row['comment_id']);
00148 $articleComment->setCommentType($row['comment_type']);
00149 $articleComment->setRoleId($row['role_id']);
00150 $articleComment->setArticleId($row['article_id']);
00151 $articleComment->setAssocId($row['assoc_id']);
00152 $articleComment->setAuthorId($row['author_id']);
00153 $articleComment->setCommentTitle($row['comment_title']);
00154 $articleComment->setComments($row['comments']);
00155 $articleComment->setDatePosted($this->datetimeFromDB($row['date_posted']));
00156 $articleComment->setDateModified($this->datetimeFromDB($row['date_modified']));
00157 $articleComment->setViewable($row['viewable']);
00158
00159 HookRegistry::call('ArticleCommentDAO::_returnArticleCommentFromRow', array(&$articleComment, &$row));
00160
00161 return $articleComment;
00162 }
00163
00169 function insertArticleComment(&$articleComment) {
00170 $this->update(
00171 sprintf('INSERT INTO article_comments
00172 (comment_type, role_id, article_id, assoc_id, author_id, date_posted, date_modified, comment_title, comments, viewable)
00173 VALUES
00174 (?, ?, ?, ?, ?, %s, %s, ?, ?, ?)',
00175 $this->datetimeToDB($articleComment->getDatePosted()), $this->datetimeToDB($articleComment->getDateModified())),
00176 array(
00177 $articleComment->getCommentType(),
00178 $articleComment->getRoleId(),
00179 $articleComment->getArticleId(),
00180 $articleComment->getAssocId(),
00181 $articleComment->getAuthorId(),
00182 $articleComment->getCommentTitle(),
00183 $articleComment->getComments(),
00184 $articleComment->getViewable() === null ? 0 : $articleComment->getViewable()
00185 )
00186 );
00187
00188 $articleComment->setCommentId($this->getInsertArticleCommentId());
00189 return $articleComment->getCommentId();
00190 }
00191
00196 function getInsertArticleCommentId() {
00197 return $this->getInsertId('article_comments', 'comment_id');
00198 }
00199
00204 function deleteArticleComment($articleComment) {
00205 $this->deleteArticleCommentById($articleComment->getCommentId());
00206 }
00207
00212 function deleteArticleCommentById($commentId) {
00213 $this->update(
00214 'DELETE FROM article_comments WHERE comment_id = ?', $commentId
00215 );
00216 }
00217
00222 function deleteArticleComments($articleId) {
00223 return $this->update(
00224 'DELETE FROM article_comments WHERE article_id = ?', $articleId
00225 );
00226 }
00227
00232 function updateArticleComment($articleComment) {
00233 $this->update(
00234 sprintf('UPDATE article_comments
00235 SET
00236 comment_type = ?,
00237 role_id = ?,
00238 article_id = ?,
00239 assoc_id = ?,
00240 author_id = ?,
00241 date_posted = %s,
00242 date_modified = %s,
00243 comment_title = ?,
00244 comments = ?,
00245 viewable = ?
00246 WHERE comment_id = ?',
00247 $this->datetimeToDB($articleComment->getDatePosted()), $this->datetimeToDB($articleComment->getDateModified())),
00248 array(
00249 $articleComment->getCommentType(),
00250 $articleComment->getRoleId(),
00251 $articleComment->getArticleId(),
00252 $articleComment->getAssocId(),
00253 $articleComment->getAuthorId(),
00254 $articleComment->getCommentTitle(),
00255 $articleComment->getComments(),
00256 $articleComment->getViewable() === null ? 1 : $articleComment->getViewable(),
00257 $articleComment->getCommentId()
00258 )
00259 );
00260 }
00261 }
00262
00263 ?>