Open Journal Systems  3.0.0
 All Data Structures 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  $params = array((int) $submissionId);
36  if ($commentType) $params[] = (int) $commentType;
37  if ($assocId) $params[] = (int) $assocId;
38  $result = $this->retrieve(
39  'SELECT a.*
40  FROM submission_comments a
41  WHERE submission_id = ?'
42  . ($commentType?' AND comment_type = ?':'')
43  . ($assocId?' AND assoc_id = ?':'')
44  . ' ORDER BY date_posted',
45  $params
46  );
47 
48  return new DAOResultFactory($result, $this, '_fromRow');
49  }
50 
56  function getByUserId($userId) {
57  $result = $this->retrieve(
58  'SELECT a.* FROM submission_comments a WHERE author_id = ? ORDER BY date_posted', (int) $userId
59  );
60 
61  return new DAOResultFactory($result, $this, '_fromRow');
62  }
63 
72  function getReviewerCommentsByReviewerId($reviewerId, $submissionId, $reviewId = null, $viewable = null) {
73  $params = array((int) $reviewerId, (int) $submissionId);
74  if ($reviewId) $params[] = (int) $reviewId;
75  return new DAOResultFactory(
76  $this->retrieve(
77  'SELECT a.*
78  FROM submission_comments a
79  WHERE author_id = ?
80  AND submission_id = ?
81  ' . ($reviewId?' AND assoc_id = ?':'') . '
82  ' . ($viewable === true?' AND viewable = 1':'') . '
83  ' . ($viewable === false?' AND viewable = 0':'') . '
84  ORDER BY date_posted DESC',
85  $params
86  ),
87  $this,
88  '_fromRow'
89  );
90  }
91 
98  function getMostRecentSubmissionComment($submissionId, $commentType = null, $assocId = null) {
99  $params = array((int) $submissionId);
100  if ($commentType) $params[] = (int) $commentType;
101  if ($assocId) $params[] = (int) $assocId;
102 
103  $result = $this->retrieveLimit(
104  'SELECT a.* FROM submission_comments a WHERE submission_id = ?'
105  . ($commentType?' AND comment_type = ?':'')
106  . ($assocId?' AND assoc_id = ?':'')
107  . ' ORDER BY date_posted DESC',
108  $params,
109  1
110  );
111 
112  $returner = null;
113  if (isset($result) && $result->RecordCount() != 0) {
114  $returner = $this->_fromRow($result->GetRowAssoc(false));
115  }
116 
117  $result->Close();
118  return $returner;
119  }
120 
126  function getById($commentId) {
127  $result = $this->retrieve(
128  'SELECT * FROM submission_comments WHERE comment_id = ?', (int) $commentId
129  );
130 
131  $submissionComment = $this->_fromRow($result->GetRowAssoc(false));
132 
133  $result->Close();
134  return $submissionComment;
135  }
136 
141  function newDataObject() {
142  return new SubmissionComment();
143  }
144 
150  function _fromRow($row) {
151  $submissionComment = $this->newDataObject();
152  $submissionComment->setId($row['comment_id']);
153  $submissionComment->setCommentType($row['comment_type']);
154  $submissionComment->setRoleId($row['role_id']);
155  $submissionComment->setSubmissionId($row['submission_id']);
156  $submissionComment->setAssocId($row['assoc_id']);
157  $submissionComment->setAuthorId($row['author_id']);
158  $submissionComment->setCommentTitle($row['comment_title']);
159  $submissionComment->setComments($row['comments']);
160  $submissionComment->setDatePosted($this->datetimeFromDB($row['date_posted']));
161  $submissionComment->setDateModified($this->datetimeFromDB($row['date_modified']));
162  $submissionComment->setViewable($row['viewable']);
163 
164  HookRegistry::call('SubmissionCommentDAO::_fromRow', array(&$submissionComment, &$row));
165 
166  return $submissionComment;
167  }
168 
174  function insertObject($submissionComment) {
175  $this->update(
176  sprintf('INSERT INTO submission_comments
177  (comment_type, role_id, submission_id, assoc_id, author_id, date_posted, date_modified, comment_title, comments, viewable)
178  VALUES
179  (?, ?, ?, ?, ?, %s, %s, ?, ?, ?)',
180  $this->datetimeToDB($submissionComment->getDatePosted()), $this->datetimeToDB($submissionComment->getDateModified())),
181  array(
182  (int) $submissionComment->getCommentType(),
183  (int) $submissionComment->getRoleId(),
184  (int) $submissionComment->getSubmissionId(),
185  (int) $submissionComment->getAssocId(),
186  (int) $submissionComment->getAuthorId(),
187  $submissionComment->getCommentTitle(),
188  $submissionComment->getComments(),
189  (int) $submissionComment->getViewable()
190  )
191  );
192 
193  $submissionComment->setId($this->getInsertId());
194  return $submissionComment->getId();
195  }
196 
201  function getInsertId() {
202  return $this->_getInsertId('submission_comments', 'comment_id');
203  }
204 
209  function deleteObject($submissionComment) {
210  $this->deleteById($submissionComment->getId());
211  }
212 
217  function deleteById($commentId) {
218  $this->update(
219  'DELETE FROM submission_comments WHERE comment_id = ?',
220  (int) $commentId
221  );
222  }
223 
228  function deleteBySubmissionId($submissionId) {
229  return $this->update(
230  'DELETE FROM submission_comments WHERE submission_id = ?',
231  (int) $submissionId
232  );
233  }
234 
239  function updateObject($submissionComment) {
240  $this->update(
241  sprintf('UPDATE submission_comments
242  SET
243  comment_type = ?,
244  role_id = ?,
245  submission_id = ?,
246  assoc_id = ?,
247  author_id = ?,
248  date_posted = %s,
249  date_modified = %s,
250  comment_title = ?,
251  comments = ?,
252  viewable = ?
253  WHERE comment_id = ?',
254  $this->datetimeToDB($submissionComment->getDatePosted()), $this->datetimeToDB($submissionComment->getDateModified())),
255  array(
256  (int) $submissionComment->getCommentType(),
257  (int) $submissionComment->getRoleId(),
258  (int) $submissionComment->getSubmissionId(),
259  (int) $submissionComment->getAssocId(),
260  (int) $submissionComment->getAuthorId(),
261  $submissionComment->getCommentTitle(),
262  $submissionComment->getComments(),
263  $submissionComment->getViewable() === null ? 1 : (int) $submissionComment->getViewable(),
264  (int) $submissionComment->getId()
265  )
266  );
267  }
268 }
269 
270 ?>
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
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getReviewerCommentsByReviewerId($reviewerId, $submissionId, $reviewId=null, $viewable=null)
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)