Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SubmissionCommentDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.submission.SubmissionComment');
18 
19 class SubmissionCommentDAO extends DAO {
23  function SubmissionCommentDAO() {
24  parent::DAO();
25  }
26 
34  function getSubmissionComments($submissionId, $commentType = null, $assocId = null) {
35  if ($commentType == null) {
36  $result = $this->retrieve(
37  'SELECT a.* FROM submission_comments a WHERE submission_id = ? ORDER BY date_posted', (int) $submissionId
38  );
39  } else {
40  if ($assocId == null) {
41  $result = $this->retrieve(
42  'SELECT a.* FROM submission_comments a WHERE submission_id = ? AND comment_type = ? ORDER BY date_posted',
43  array((int) $submissionId, (int) $commentType)
44  );
45  } else {
46  $result = $this->retrieve(
47  'SELECT a.* FROM submission_comments a WHERE submission_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted',
48  array((int) $submissionId, (int) $commentType, (int) $assocId)
49  );
50  }
51  }
52 
53  return new DAOResultFactory($result, $this, '_fromRow');
54  }
55 
61  function getByUserId($userId) {
62  $result = $this->retrieve(
63  'SELECT a.* FROM submission_comments a WHERE author_id = ? ORDER BY date_posted', (int) $userId
64  );
65 
66  return new DAOResultFactory($result, $this, '_fromRow');
67  }
68 
76  function getReviewerCommentsByReviewerId($reviewerId, $submissionId, $reviewId = null) {
77  $params = array((int) $reviewerId, (int) $submissionId);
78  if (isset($reviewId)) {
79  $params[] = (int) $reviewId;
80  }
81  $result = $this->retrieve(
82  'SELECT a.* FROM submission_comments a WHERE author_id = ? AND submission_id = ?' . (isset($reviewId) ? ' AND assoc_id = ?' : '') . ' ORDER BY date_posted DESC',
83  $params
84  );
85 
86  return new DAOResultFactory($result, $this, '_fromRow');
87  }
88 
95  function getMostRecentSubmissionComment($submissionId, $commentType = null, $assocId = null) {
96  if ($commentType == null) {
97  $result = $this->retrieveLimit(
98  'SELECT a.* FROM submission_comments a WHERE submission_id = ? ORDER BY date_posted DESC',
99  (int) $submissionId,
100  1
101  );
102  } else {
103  if ($assocId == null) {
104  $result = $this->retrieveLimit(
105  'SELECT a.* FROM submission_comments a WHERE submission_id = ? AND comment_type = ? ORDER BY date_posted DESC',
106  array((int) $submissionId, (int) $commentType),
107  1
108  );
109  } else {
110  $result = $this->retrieveLimit(
111  'SELECT a.* FROM submission_comments a WHERE submission_id = ? AND comment_type = ? AND assoc_id = ? ORDER BY date_posted DESC',
112  array((int) $submissionId, (int) $commentType, (int) $assocId),
113  1
114  );
115  }
116  }
117 
118  $returner = null;
119  if (isset($result) && $result->RecordCount() != 0) {
120  $returner = $this->_fromRow($result->GetRowAssoc(false));
121  }
122 
123  $result->Close();
124  return $returner;
125  }
126 
132  function getById($commentId) {
133  $result = $this->retrieve(
134  'SELECT * FROM submission_comments WHERE comment_id = ?', (int) $commentId
135  );
136 
137  $submissionComment = $this->_fromRow($result->GetRowAssoc(false));
138 
139  $result->Close();
140  return $submissionComment;
141  }
142 
147  function newDataObject() {
148  return new SubmissionComment();
149  }
150 
156  function _fromRow($row) {
157  $submissionComment = $this->newDataObject();
158  $submissionComment->setId($row['comment_id']);
159  $submissionComment->setCommentType($row['comment_type']);
160  $submissionComment->setRoleId($row['role_id']);
161  $submissionComment->setSubmissionId($row['submission_id']);
162  $submissionComment->setAssocId($row['assoc_id']);
163  $submissionComment->setAuthorId($row['author_id']);
164  $submissionComment->setCommentTitle($row['comment_title']);
165  $submissionComment->setComments($row['comments']);
166  $submissionComment->setDatePosted($this->datetimeFromDB($row['date_posted']));
167  $submissionComment->setDateModified($this->datetimeFromDB($row['date_modified']));
168  $submissionComment->setViewable($row['viewable']);
169 
170  HookRegistry::call('SubmissionCommentDAO::_fromRow', array(&$submissionComment, &$row));
171 
172  return $submissionComment;
173  }
174 
180  function insertObject($submissionComment) {
181  $this->update(
182  sprintf('INSERT INTO submission_comments
183  (comment_type, role_id, submission_id, assoc_id, author_id, date_posted, date_modified, comment_title, comments, viewable)
184  VALUES
185  (?, ?, ?, ?, ?, %s, %s, ?, ?, ?)',
186  $this->datetimeToDB($submissionComment->getDatePosted()), $this->datetimeToDB($submissionComment->getDateModified())),
187  array(
188  (int) $submissionComment->getCommentType(),
189  (int) $submissionComment->getRoleId(),
190  (int) $submissionComment->getSubmissionId(),
191  (int) $submissionComment->getAssocId(),
192  (int) $submissionComment->getAuthorId(),
193  $submissionComment->getCommentTitle(),
194  $submissionComment->getComments(),
195  (int) $submissionComment->getViewable()
196  )
197  );
198 
199  $submissionComment->setId($this->getInsertId());
200  return $submissionComment->getId();
201  }
202 
207  function getInsertId() {
208  return $this->_getInsertId('submission_comments', 'comment_id');
209  }
210 
215  function deleteObject($submissionComment) {
216  $this->deleteById($submissionComment->getId());
217  }
218 
223  function deleteById($commentId) {
224  $this->update(
225  'DELETE FROM submission_comments WHERE comment_id = ?',
226  (int) $commentId
227  );
228  }
229 
234  function deleteBySubmissionId($submissionId) {
235  return $this->update(
236  'DELETE FROM submission_comments WHERE submission_id = ?',
237  (int) $submissionId
238  );
239  }
240 
245  function updateObject($submissionComment) {
246  $this->update(
247  sprintf('UPDATE submission_comments
248  SET
249  comment_type = ?,
250  role_id = ?,
251  submission_id = ?,
252  assoc_id = ?,
253  author_id = ?,
254  date_posted = %s,
255  date_modified = %s,
256  comment_title = ?,
257  comments = ?,
258  viewable = ?
259  WHERE comment_id = ?',
260  $this->datetimeToDB($submissionComment->getDatePosted()), $this->datetimeToDB($submissionComment->getDateModified())),
261  array(
262  (int) $submissionComment->getCommentType(),
263  (int) $submissionComment->getRoleId(),
264  (int) $submissionComment->getSubmissionId(),
265  (int) $submissionComment->getAssocId(),
266  (int) $submissionComment->getAuthorId(),
267  $submissionComment->getCommentTitle(),
268  $submissionComment->getComments(),
269  $submissionComment->getViewable() === null ? 1 : (int) $submissionComment->getViewable(),
270  (int) $submissionComment->getId()
271  )
272  );
273  }
274 }
275 
276 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieveLimit($sql, $params=false, $numRows=false, $offset=false, $callHooks=true)
Definition: DAO.inc.php:146
getReviewerCommentsByReviewerId($reviewerId, $submissionId, $reviewId=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getSubmissionComments($submissionId, $commentType=null, $assocId=null)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
datetimeFromDB($dt)
Definition: DAO.inc.php:313
static call($hookName, $args=null)
deleteObject($submissionComment)
Operations for retrieving and modifying SubmissionComment objects.
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
updateObject($submissionComment)
Class for SubmissionComment.
insertObject($submissionComment)
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
getMostRecentSubmissionComment($submissionId, $commentType=null, $assocId=null)