Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
ArticleCommentDAO.inc.php
1 <?php
2 
17 import('classes.article.ArticleComment');
18 
19 class ArticleCommentDAO extends DAO {
26  function &getArticleComments($articleId, $commentType = null, $assocId = null) {
27  $articleComments = array();
28 
29  if ($commentType == null) {
30  $result =& $this->retrieve(
31  'SELECT a.* FROM article_comments a WHERE article_id = ? ORDER BY date_posted', $articleId
32  );
33  } else {
34  if ($assocId == null) {
35  $result =& $this->retrieve(
36  'SELECT a.* FROM article_comments a WHERE article_id = ? AND comment_type = ? ORDER BY date_posted', array($articleId, $commentType)
37  );
38  } else {
39  $result =& $this->retrieve(
40  'SELECT a.* FROM article_comments a WHERE article_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted',
41  array($articleId, $commentType, $assocId)
42  );
43  }
44  }
45 
46  while (!$result->EOF) {
47  $articleComments[] =& $this->_returnArticleCommentFromRow($result->GetRowAssoc(false));
48  $result->moveNext();
49  }
50 
51  $result->Close();
52  unset($result);
53 
54  return $articleComments;
55  }
56 
62  function &getArticleCommentsByUserId($userId) {
63  $articleComments = array();
64 
65  $result =& $this->retrieve(
66  'SELECT a.* FROM article_comments a WHERE author_id = ? ORDER BY date_posted', $userId
67  );
68 
69  while (!$result->EOF) {
70  $articleComments[] =& $this->_returnArticleCommentFromRow($result->GetRowAssoc(false));
71  $result->moveNext();
72  }
73 
74  $result->Close();
75  unset($result);
76 
77  return $articleComments;
78  }
79 
86  function getMostRecentArticleComment($articleId, $commentType = null, $assocId = null) {
87  if ($commentType == null) {
88  $result =& $this->retrieveLimit(
89  'SELECT a.* FROM article_comments a WHERE article_id = ? ORDER BY date_posted DESC',
90  $articleId,
91  1
92  );
93  } else {
94  if ($assocId == null) {
95  $result =& $this->retrieveLimit(
96  'SELECT a.* FROM article_comments a WHERE article_id = ? AND comment_type = ? ORDER BY date_posted DESC',
97  array($articleId, $commentType),
98  1
99  );
100  } else {
101  $result =& $this->retrieveLimit(
102  'SELECT a.* FROM article_comments a WHERE article_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted DESC',
103  array($articleId, $commentType, $assocId),
104  1
105  );
106  }
107  }
108 
109  $returner = null;
110  if (isset($result) && $result->RecordCount() != 0) {
111  $returner =& $this->_returnArticleCommentFromRow($result->GetRowAssoc(false));
112  }
113 
114  $result->Close();
115  unset($result);
116 
117  return $returner;
118  }
119 
125  function &getArticleCommentById($commentId) {
126  $result =& $this->retrieve(
127  'SELECT a.* FROM article_comments a WHERE comment_id = ?', $commentId
128  );
129 
130  $articleComment =& $this->_returnArticleCommentFromRow($result->GetRowAssoc(false));
131 
132  $result->Close();
133  unset($result);
134 
135  return $articleComment;
136  }
137 
144  $articleComment = new ArticleComment();
145  $articleComment->setId($row['comment_id']);
146  $articleComment->setCommentType($row['comment_type']);
147  $articleComment->setRoleId($row['role_id']);
148  $articleComment->setArticleId($row['article_id']);
149  $articleComment->setAssocId($row['assoc_id']);
150  $articleComment->setAuthorId($row['author_id']);
151  $articleComment->setCommentTitle($row['comment_title']);
152  $articleComment->setComments($row['comments']);
153  $articleComment->setDatePosted($this->datetimeFromDB($row['date_posted']));
154  $articleComment->setDateModified($this->datetimeFromDB($row['date_modified']));
155  $articleComment->setViewable($row['viewable']);
156 
157  HookRegistry::call('ArticleCommentDAO::_returnArticleCommentFromRow', array(&$articleComment, &$row));
158 
159  return $articleComment;
160  }
161 
167  function insertArticleComment(&$articleComment) {
168  $this->update(
169  sprintf('INSERT INTO article_comments
170  (comment_type, role_id, article_id, assoc_id, author_id, date_posted, date_modified, comment_title, comments, viewable)
171  VALUES
172  (?, ?, ?, ?, ?, %s, %s, ?, ?, ?)',
173  $this->datetimeToDB($articleComment->getDatePosted()), $this->datetimeToDB($articleComment->getDateModified())),
174  array(
175  $articleComment->getCommentType(),
176  $articleComment->getRoleId(),
177  $articleComment->getArticleId(),
178  $articleComment->getAssocId(),
179  $articleComment->getAuthorId(),
180  String::substr($articleComment->getCommentTitle(), 0, 255),
181  $articleComment->getComments(),
182  $articleComment->getViewable() === null ? 0 : $articleComment->getViewable()
183  )
184  );
185 
186  $articleComment->setId($this->getInsertArticleCommentId());
187  return $articleComment->getId();
188  }
189 
195  return $this->getInsertId('article_comments', 'comment_id');
196  }
197 
202  function deleteArticleComment($articleComment) {
203  $this->deleteArticleCommentById($articleComment->getId());
204  }
205 
210  function deleteArticleCommentById($commentId) {
211  $this->update(
212  'DELETE FROM article_comments WHERE comment_id = ?', $commentId
213  );
214  }
215 
220  function deleteArticleComments($articleId) {
221  return $this->update(
222  'DELETE FROM article_comments WHERE article_id = ?', $articleId
223  );
224  }
225 
230  function updateArticleComment($articleComment) {
231  $this->update(
232  sprintf('UPDATE article_comments
233  SET
234  comment_type = ?,
235  role_id = ?,
236  article_id = ?,
237  assoc_id = ?,
238  author_id = ?,
239  date_posted = %s,
240  date_modified = %s,
241  comment_title = ?,
242  comments = ?,
243  viewable = ?
244  WHERE comment_id = ?',
245  $this->datetimeToDB($articleComment->getDatePosted()), $this->datetimeToDB($articleComment->getDateModified())),
246  array(
247  $articleComment->getCommentType(),
248  $articleComment->getRoleId(),
249  $articleComment->getArticleId(),
250  $articleComment->getAssocId(),
251  $articleComment->getAuthorId(),
252  String::substr($articleComment->getCommentTitle(), 0, 255),
253  $articleComment->getComments(),
254  $articleComment->getViewable() === null ? 1 : $articleComment->getViewable(),
255  $articleComment->getId()
256  )
257  );
258  }
259 }
260 
261 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieveLimit($sql, $params=false, $numRows=false, $offset=false, $callHooks=true)
Definition: DAO.inc.php:147
& getArticleCommentsByUserId($userId)
deleteArticleComment($articleComment)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
updateArticleComment($articleComment)
& getArticleCommentById($commentId)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
substr($string, $start, $length=false)
Definition: String.inc.php:179
deleteArticleCommentById($commentId)
getMostRecentArticleComment($articleId, $commentType=null, $assocId=null)
call($hookName, $args=null)
Operations for retrieving and modifying ArticleComment objects.
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getArticleComments($articleId, $commentType=null, $assocId=null)
insertArticleComment(&$articleComment)
Class for ArticleComment.