Open Journal Systems  2.4.4
 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  unset($result);
47 
48  return $returner;
49  }
50 
55  function newDataObject() {
56  return new ReviewFormResponse();
57  }
58 
65  $responseValue = $this->convertFromDB($row['response_value'], $row['response_type']);
66  $reviewFormResponse = $this->newDataObject();
67 
68  $reviewFormResponse->setReviewId($row['review_id']);
69  $reviewFormResponse->setReviewFormElementId($row['review_form_element_id']);
70  $reviewFormResponse->setValue($responseValue);
71  $reviewFormResponse->setResponseType($row['response_type']);
72 
73  HookRegistry::call('ReviewFormResponseDAO::_returnReviewFormResponseFromRow', array(&$reviewFormResponse, &$row));
74 
75  return $reviewFormResponse;
76  }
77 
82  function insertObject(&$reviewFormResponse) {
83  $responseValue = $this->convertToDB($reviewFormResponse->getValue(), $reviewFormResponse->getResponseType());
84  $this->update(
85  'INSERT INTO review_form_responses
86  (review_form_element_id, review_id, response_type, response_value)
87  VALUES
88  (?, ?, ?, ?)',
89  array(
90  $reviewFormResponse->getReviewFormElementId(),
91  $reviewFormResponse->getReviewId(),
92  $reviewFormResponse->getResponseType(),
93  $responseValue
94  )
95  );
96  }
97 
102  function updateObject(&$reviewFormResponse) {
103  $responseValue = $this->convertToDB($reviewFormResponse->getValue(), $reviewFormResponse->getResponseType());
104  $returner = $this->update(
105  'UPDATE review_form_responses
106  SET
107  response_type = ?,
108  response_value = ?
109  WHERE review_form_element_id = ? AND review_id = ?',
110  array(
111  $reviewFormResponse->getResponseType(),
112  $responseValue,
113  $reviewFormResponse->getReviewFormElementId(),
114  $reviewFormResponse->getReviewId()
115  )
116  );
117 
118  return $returner;
119  }
120 
125  function deleteObject(&$reviewFormResponse) {
126  return $this->deleteById($reviewFormResponse->getReviewId(), $reviewFormResponse->getReviewFormElementId());
127  }
128 
134  function deleteById($reviewId, $reviewFormElementId) {
135  return $this->update(
136  'DELETE FROM review_form_responses WHERE review_id = ? AND review_form_element_id = ?',
137  array($reviewId, $reviewFormElementId)
138  );
139  }
140 
145  function deleteByReviewId($reviewId) {
146  return $this->update(
147  'DELETE FROM review_form_responses WHERE review_id = ?',
148  $reviewId
149  );
150  }
151 
156  function deleteByReviewFormElementId($reviewFormElementId) {
157  return $this->update(
158  'DELETE FROM review_form_responses WHERE review_form_element_id = ?',
159  $reviewFormElementId
160  );
161  }
162 
168  function &getReviewReviewFormResponseValues($reviewId) {
169  $returner = array();
170 
171  $result =& $this->retrieveRange(
172  'SELECT * FROM review_form_responses WHERE review_id = ?',
173  $reviewId
174  );
175 
176  while (!$result->EOF) {
177  $row = $result->GetRowAssoc(false);
178  $reviewFormResponse =& $this->_returnReviewFormResponseFromRow($row);
179  $returner[$reviewFormResponse->getReviewFormElementId()] = $reviewFormResponse->getValue();
180  $result->MoveNext();
181  }
182 
183  $result->Close();
184  unset($result);
185 
186  return $returner;
187  }
188 
195  function reviewFormResponseExists($reviewId, $reviewFormElementId = null) {
196  $sql = 'SELECT COUNT(*) FROM review_form_responses WHERE review_id = ?';
197  $params = array($reviewId);
198  if ($reviewFormElementId !== null) {
199  $sql .= ' AND review_form_element_id = ?';
200  $params[] = $reviewFormElementId;
201  }
202  $result =& $this->retrieve($sql, $params);
203 
204  $returner = isset($result->fields[0]) && $result->fields[0] > 0 ? true : false;
205 
206  $result->Close();
207  unset($result);
208 
209  return $returner;
210  }
211 
214  function insertReviewFormResponse(&$reviewFormResponse) {
215  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
216  $this->insertObject($reviewFormResponse);
217  }
218 
219  function updateReviewFormResponse(&$reviewFormResponse) {
220  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
221  $this->updateObject($reviewFormResponse);
222  }
223 
224  function deleteReviewFormResponse(&$reviewFormResponse) {
225  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
226  $this->deleteObject($reviewFormResponse);
227  }
228 
229  function deleteReviewFormResponseById($reviewId, $reviewFormElementId) {
230  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
231  return $this->deleteById($reviewId, $reviewFormElementId);
232  }
233 
234  function deleteReviewFormResponseByReviewId($reviewId) {
235  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
236  return $this->deleteByReviewId($reviewId);
237  }
238 
239  function deleteReviewFormResponseByReviewFormElementId($reviewFormElementId) {
240  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
241  return $this->deleteByReviewFormElementId($reviewFormElementId);
242  }
243 
244 
245 }
246 
247 ?>
updateObject(&$reviewFormResponse)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
Operations for retrieving and modifying ReviewFormResponse objects.
reviewFormResponseExists($reviewId, $reviewFormElementId=null)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
insertReviewFormResponse(&$reviewFormResponse)
deleteObject(&$reviewFormResponse)
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
convertFromDB($value, $type)
Definition: DAO.inc.php:338
Basic class describing a review form response.
deleteByReviewFormElementId($reviewFormElementId)
convertToDB($value, &$type)
Definition: DAO.inc.php:394
call($hookName, $args=null)
& getReviewFormResponse($reviewId, $reviewFormElementId)
deleteById($reviewId, $reviewFormElementId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
insertObject(&$reviewFormResponse)