ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

CommentDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('comment.Comment');
19 
20 define ('PAPER_COMMENT_RECURSE_ALL', -1);
21 
22 class CommentDAO extends DAO {
28  function &getRootCommentsByPaperId($paperId, $childLevels = 0) {
29  $comments = array();
30 
31  $result =& $this->retrieve('SELECT * FROM comments WHERE paper_id = ? AND parent_comment_id IS NULL ORDER BY date_posted', $paperId);
32 
33  while (!$result->EOF) {
34  $comments[] =& $this->_returnCommentFromRow($result->GetRowAssoc(false), $childLevels);
35  $result->moveNext();
36  }
37 
38  $result->Close();
39  unset($result);
40 
41  return $comments;
42  }
43 
49  function &getCommentsByParentId($parentId, $childLevels = 0) {
50  $comments = array();
51 
52  $result =& $this->retrieve('SELECT * FROM comments WHERE parent_comment_id = ? ORDER BY date_posted', $parentId);
53 
54  while (!$result->EOF) {
55  $comments[] =& $this->_returnCommentFromRow($result->GetRowAssoc(false), $childLevels);
56  $result->moveNext();
57  }
58 
59  $result->Close();
60  unset($result);
61 
62  return $comments;
63  }
64 
70  function &getCommentsByUserId($userId) {
71  $comments = array();
72 
73  $result =& $this->retrieve('SELECT * FROM comments WHERE user_id = ?', $userId);
74 
75  while (!$result->EOF) {
76  $comments[] =& $this->_returnCommentFromRow($result->GetRowAssoc(false));
77  $result->moveNext();
78  }
79 
80  $result->Close();
81  unset($result);
82 
83  return $comments;
84  }
85 
91  function &getComment($commentId, $paperId, $childLevels = 0) {
92  $result =& $this->retrieve(
93  'SELECT * FROM comments WHERE comment_id = ? and paper_id = ?', array($commentId, $paperId)
94  );
95 
96  $comment = null;
97  if ($result->RecordCount() != 0) {
98  $comment =& $this->_returnCommentFromRow($result->GetRowAssoc(false), $childLevels);
99  }
100 
101  $result->Close();
102  unset($result);
103 
104  return $comment;
105  }
106 
112  function &_returnCommentFromRow($row, $childLevels = 0) {
113  $userDao =& DAORegistry::getDAO('UserDAO');
114 
115  $comment = new Comment();
116  $comment->setId($row['comment_id']);
117  $comment->setPaperId($row['paper_id']);
118  $comment->setUser($userDao->getUser($row['user_id']), true);
119  $comment->setPosterIP($row['poster_ip']);
120  $comment->setPosterName($row['poster_name']);
121  $comment->setPosterEmail($row['poster_email']);
122  $comment->setTitle($row['title']);
123  $comment->setBody($row['body']);
124  $comment->setDatePosted($this->datetimeFromDB($row['date_posted']));
125  $comment->setDateModified($this->datetimeFromDB($row['date_modified']));
126  $comment->setParentCommentId($row['parent_comment_id']);
127  $comment->setChildCommentCount($row['num_children']);
128 
129  if (!HookRegistry::call('CommentDAO::_returnCommentFromRow', array(&$comment, &$row, &$childLevels))) {
130  if ($childLevels>0) $comment->setChildren($this->getCommentsByParentId($row['comment_id'], $childLevels-1));
131  else if ($childLevels==SUBMISSION_COMMENT_RECURSE_ALL) $comment->setChildren($this->getCommentsByParentId($row['comment_id'], SUBMISSION_COMMENT_RECURSE_ALL));
132  }
133 
134  return $comment;
135  }
136 
142  function insertComment(&$comment) {
143  $comment->setDatePosted(Core::getCurrentDate());
144  $comment->setDateModified($comment->getDatePosted());
145  $user = $comment->getUser();
146  $this->update(
147  sprintf('INSERT INTO comments
148  (paper_id, num_children, parent_comment_id, user_id, poster_ip, date_posted, date_modified, title, body, poster_name, poster_email)
149  VALUES
150  (?, ?, ?, ?, ?, %s, %s, ?, ?, ?, ?)',
151  $this->datetimeToDB($comment->getDatePosted()), $this->datetimeToDB($comment->getDateModified())),
152  array(
153  $comment->getPaperId(),
154  $comment->getChildCommentCount(),
155  $comment->getParentCommentId(),
156  (isset($user)?$user->getId():null),
157  $comment->getPosterIP(),
158  String::substr($comment->getTitle(), 0, 255),
159  $comment->getBody(),
160  String::substr($comment->getPosterName(), 0, 90),
161  String::substr($comment->getPosterEmail(), 0, 90)
162  )
163  );
164 
165  $comment->setId($this->getInsertCommentId());
166 
167  if ($comment->getParentCommentId()) $this->incrementChildCount($comment->getParentCommentId());
168 
169  return $comment->getId();
170  }
171 
176  function getInsertCommentId() {
177  return $this->getInsertId('comments', 'comment_id');
178  }
179 
184  function incrementChildCount($commentId) {
185  $this->update('UPDATE comments SET num_children=num_children+1 WHERE comment_id = ?', $commentId);
186  }
187 
192  function decrementChildCount($commentId) {
193  $this->update('UPDATE comments SET num_children=num_children-1 WHERE comment_id = ?', $commentId);
194  }
195 
200  function deleteComment(&$comment, $isRecursing = false) {
201  $result = $this->update('DELETE FROM comments WHERE comment_id = ?', $comment->getId());
202  if (!$isRecursing) $this->decrementChildCount($comment->getParentCommentId());
203  foreach ($comment->getChildren() as $child) {
204  $this->deleteComment($child, true);
205  }
206  }
207 
212  function deleteCommentsByPaper($paperId) {
213  return $this->update('DELETE FROM comments WHERE paper_id = ?', $paperId);
214  }
215 
220  function updateComment(&$comment) {
221  $comment->setDateModified(Core::getCurrentDate());
222  $user = $comment->getUser();
223  $this->update(
224  sprintf('UPDATE paper_comments
225  SET
226  paper_id = ?,
227  num_children = ?,
228  parent_comment_id = ?,
229  user_id = ?,
230  poster_ip = ?,
231  date_posted = %s,
232  date_modified = %s,
233  title = ?,
234  body = ?,
235  poster_name = ?,
236  poster_email = ?
237  WHERE comment_id = ?',
238  $this->datetimeToDB($comment->getDatePosted()), $this->datetimeToDB($comment->getDateModified())),
239  array(
240  $comment->getPaperId(),
241  $comment->getChildCommentCount(),
242  $comment->getParentCommentId(),
243  (isset($user)?$user->getId():null),
244  $comment->getPosterIP(),
245  String::substr($comment->getTitle(), 0, 255),
246  $comment->getBody(),
247  String::substr($comment->getPosterName(), 0, 90),
248  String::substr($comment->getPosterEmail(), 0, 90),
249  $comment->getId()
250  )
251  );
252  }
253 }
254 
255 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
deleteComment(&$comment, $isRecursing=false)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
& getCommentsByParentId($parentId, $childLevels=0)
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
& getComment($commentId, $paperId, $childLevels=0)
getCurrentDate($ts=null)
Definition: Core.inc.php:90
Class for public Comment associated with paper.
Definition: Comment.inc.php:22
& getRootCommentsByPaperId($paperId, $childLevels=0)
datetimeFromDB($dt)
Definition: DAO.inc.php:276
updateComment(&$comment)
deleteCommentsByPaper($paperId)
substr($string, $start, $length=false)
Definition: String.inc.php:179
& _returnCommentFromRow($row, $childLevels=0)
& getDAO($name, $dbconn=null)
incrementChildCount($commentId)
Operations for retrieving and modifying Comment objects.
call($hookName, $args=null)
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
& getCommentsByUserId($userId)
insertComment(&$comment)
decrementChildCount($commentId)