Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
ReviewFormResponseDAO.inc.php
1 <?php
2 
18 import ('lib.pkp.classes.reviewForm.ReviewFormResponse');
19 
20 class ReviewFormResponseDAO extends DAO {
21 
25  function ReviewFormResponseDAO() {
26  parent::DAO();
27  }
28 
35  function &getReviewFormResponse($reviewId, $reviewFormElementId) {
36  $sql = 'SELECT * FROM review_form_responses WHERE review_id = ? AND review_form_element_id = ?';
37  $params = array($reviewId, $reviewFormElementId);
38  $result = $this->retrieve($sql, $params);
39 
40  $returner = null;
41  if ($result->RecordCount() != 0) {
42  $returner =& $this->_returnReviewFormResponseFromRow($result->GetRowAssoc(false));
43  }
44 
45  $result->Close();
46  return $returner;
47  }
48 
53  function newDataObject() {
54  return new ReviewFormResponse();
55  }
56 
63  $responseValue = $this->convertFromDB($row['response_value'], $row['response_type']);
64  $reviewFormResponse = $this->newDataObject();
65 
66  $reviewFormResponse->setReviewId($row['review_id']);
67  $reviewFormResponse->setReviewFormElementId($row['review_form_element_id']);
68  $reviewFormResponse->setValue($responseValue);
69  $reviewFormResponse->setResponseType($row['response_type']);
70 
71  HookRegistry::call('ReviewFormResponseDAO::_returnReviewFormResponseFromRow', array(&$reviewFormResponse, &$row));
72 
73  return $reviewFormResponse;
74  }
75 
80  function insertObject(&$reviewFormResponse) {
81  $responseValue = $this->convertToDB($reviewFormResponse->getValue(), $reviewFormResponse->getResponseType());
82  $this->update(
83  'INSERT INTO review_form_responses
84  (review_form_element_id, review_id, response_type, response_value)
85  VALUES
86  (?, ?, ?, ?)',
87  array(
88  $reviewFormResponse->getReviewFormElementId(),
89  $reviewFormResponse->getReviewId(),
90  $reviewFormResponse->getResponseType(),
91  $responseValue
92  )
93  );
94  }
95 
100  function updateObject(&$reviewFormResponse) {
101  $responseValue = $this->convertToDB($reviewFormResponse->getValue(), $reviewFormResponse->getResponseType());
102  $returner = $this->update(
103  'UPDATE review_form_responses
104  SET
105  response_type = ?,
106  response_value = ?
107  WHERE review_form_element_id = ? AND review_id = ?',
108  array(
109  $reviewFormResponse->getResponseType(),
110  $responseValue,
111  $reviewFormResponse->getReviewFormElementId(),
112  $reviewFormResponse->getReviewId()
113  )
114  );
115 
116  return $returner;
117  }
118 
123  function deleteObject(&$reviewFormResponse) {
124  return $this->deleteById($reviewFormResponse->getReviewId(), $reviewFormResponse->getReviewFormElementId());
125  }
126 
132  function deleteById($reviewId, $reviewFormElementId) {
133  return $this->update(
134  'DELETE FROM review_form_responses WHERE review_id = ? AND review_form_element_id = ?',
135  array($reviewId, $reviewFormElementId)
136  );
137  }
138 
143  function deleteByReviewId($reviewId) {
144  return $this->update(
145  'DELETE FROM review_form_responses WHERE review_id = ?',
146  $reviewId
147  );
148  }
149 
154  function deleteByReviewFormElementId($reviewFormElementId) {
155  return $this->update(
156  'DELETE FROM review_form_responses WHERE review_form_element_id = ?',
157  $reviewFormElementId
158  );
159  }
160 
166  function &getReviewReviewFormResponseValues($reviewId) {
167  $returner = array();
168 
169  $result = $this->retrieveRange(
170  'SELECT * FROM review_form_responses WHERE review_id = ?',
171  (int) $reviewId
172  );
173 
174  while (!$result->EOF) {
175  $row = $result->GetRowAssoc(false);
176  $reviewFormResponse =& $this->_returnReviewFormResponseFromRow($row);
177  $returner[$reviewFormResponse->getReviewFormElementId()] = $reviewFormResponse->getValue();
178  $result->MoveNext();
179  }
180 
181  $result->Close();
182  return $returner;
183  }
184 
191  function reviewFormResponseExists($reviewId, $reviewFormElementId = null) {
192  $sql = 'SELECT COUNT(*) FROM review_form_responses WHERE review_id = ?';
193  $params = array($reviewId);
194  if ($reviewFormElementId !== null) {
195  $sql .= ' AND review_form_element_id = ?';
196  $params[] = $reviewFormElementId;
197  }
198  $result = $this->retrieve($sql, $params);
199 
200  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
201 
202  $result->Close();
203  return $returner;
204  }
205 }
206 
207 ?>
updateObject(&$reviewFormResponse)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
Operations for retrieving and modifying ReviewFormResponse objects.
reviewFormResponseExists($reviewId, $reviewFormElementId=null)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
deleteObject(&$reviewFormResponse)
static call($hookName, $args=null)
convertFromDB($value, $type)
Definition: DAO.inc.php:335
Basic class describing a review form response.
deleteByReviewFormElementId($reviewFormElementId)
convertToDB($value, &$type)
Definition: DAO.inc.php:391
& getReviewFormResponse($reviewId, $reviewFormElementId)
deleteById($reviewId, $reviewFormElementId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
insertObject(&$reviewFormResponse)