Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
ReviewFormElementDAO.inc.php
1 <?php
2 
18 import ('lib.pkp.classes.reviewForm.ReviewFormElement');
19 
20 class ReviewFormElementDAO extends DAO {
24  function ReviewFormElementDAO() {
25  parent::DAO();
26  }
27 
33  function &getReviewFormElement($reviewFormElementId) {
34  $result =& $this->retrieve(
35  'SELECT * FROM review_form_elements WHERE review_form_element_id = ?', $reviewFormElementId
36  );
37 
38  $returner = null;
39  if ($result->RecordCount() != 0) {
40  $returner =& $this->_returnReviewFormElementFromRow($result->GetRowAssoc(false));
41  }
42 
43  $result->Close();
44  unset($result);
45 
46  return $returner;
47  }
48 
53  function newDataObject() {
54  return new ReviewFormElement();
55  }
56 
63  $reviewFormElement = $this->newDataObject();
64  $reviewFormElement->setId($row['review_form_element_id']);
65  $reviewFormElement->setReviewFormId($row['review_form_id']);
66  $reviewFormElement->setSequence($row['seq']);
67  $reviewFormElement->setElementType($row['element_type']);
68  $reviewFormElement->setRequired($row['required']);
69  $reviewFormElement->setIncluded($row['included']);
70 
71  $this->getDataObjectSettings('review_form_element_settings', 'review_form_element_id', $row['review_form_element_id'], $reviewFormElement);
72 
73  HookRegistry::call('ReviewFormElementDAO::_returnReviewFormElementFromRow', array(&$reviewFormElement, &$row));
74 
75  return $reviewFormElement;
76  }
77 
82  function getLocaleFieldNames() {
83  return array('question', 'possibleResponses');
84  }
85 
90  function updateLocaleFields(&$reviewFormElement) {
91  $this->updateDataObjectSettings('review_form_element_settings', $reviewFormElement, array(
92  'review_form_element_id' => $reviewFormElement->getId()
93  ));
94  }
95 
100  function insertObject(&$reviewFormElement) {
101  $this->update(
102  'INSERT INTO review_form_elements
103  (review_form_id, seq, element_type, required, included)
104  VALUES
105  (?, ?, ?, ?, ?)',
106  array(
107  $reviewFormElement->getReviewFormId(),
108  $reviewFormElement->getSequence() == null ? 0 : $reviewFormElement->getSequence(),
109  $reviewFormElement->getElementType(),
110  $reviewFormElement->getRequired() ? 1 : 0,
111  $reviewFormElement->getIncluded() ? 1 : 0
112  )
113  );
114 
115  $reviewFormElement->setId($this->getInsertReviewFormElementId());
116  $this->updateLocaleFields($reviewFormElement);
117  return $reviewFormElement->getId();
118  }
119 
124  function updateObject(&$reviewFormElement) {
125  $returner = $this->update(
126  'UPDATE review_form_elements
127  SET
128  review_form_id = ?,
129  seq = ?,
130  element_type = ?,
131  required = ?,
132  included = ?
133  WHERE review_form_element_id = ?',
134  array(
135  $reviewFormElement->getReviewFormId(),
136  $reviewFormElement->getSequence(),
137  $reviewFormElement->getElementType(),
138  $reviewFormElement->getRequired(),
139  $reviewFormElement->getIncluded(),
140  $reviewFormElement->getId()
141  )
142  );
143  $this->updateLocaleFields($reviewFormElement);
144  return $returner;
145  }
146 
151  function deleteObject(&$reviewFormElement) {
152  return $this->deleteById($reviewFormElement->getId());
153  }
154 
159  function deleteById($reviewFormElementId) {
160  $reviewFormResponseDao =& DAORegistry::getDAO('ReviewFormResponseDAO');
161  $reviewFormResponseDao->deleteByReviewFormElementId($reviewFormElementId);
162 
163  $this->update('DELETE FROM review_form_element_settings WHERE review_form_element_id = ?', array($reviewFormElementId));
164  return $this->update('DELETE FROM review_form_elements WHERE review_form_element_id = ?', array($reviewFormElementId));
165  }
166 
172  function deleteByReviewFormId($reviewFormId) {
173  $reviewFormElements =& $this->getReviewFormElements($reviewFormId);
174  foreach ($reviewFormElements as $reviewFormElementId => $reviewFormElement) {
175  $this->deleteById($reviewFormElementId);
176  }
177  }
178 
185  function deleteSetting($reviewFormElementId, $name, $locale = null) {
186  $params = array($reviewFormElementId, $name);
187  $sql = 'DELETE FROM review_form_element_settings WHERE review_form_element_id = ? AND setting_name = ?';
188  if ($locale !== null) {
189  $params[] = $locale;
190  $sql .= ' AND locale = ?';
191  }
192 
193  return $this->update($sql, $params);
194  }
195 
201  function &getReviewFormElements($reviewFormId) {
202  $reviewFormElements = array();
203 
204  $result =& $this->retrieve(
205  'SELECT * FROM review_form_elements WHERE review_form_id = ? ORDER BY seq',
206  $reviewFormId
207  );
208 
209  while (!$result->EOF) {
210  $reviewFormElement =& $this->_returnReviewFormElementFromRow($result->GetRowAssoc(false));
211  $reviewFormElements[$reviewFormElement->getId()] = $reviewFormElement;
212  $result->MoveNext();
213  }
214 
215  $result->Close();
216  unset($result);
217 
218  return $reviewFormElements;
219  }
220 
227  function &getReviewFormElementsByReviewForm($reviewFormId, $rangeInfo = null) {
228  $result =& $this->retrieveRange(
229  'SELECT * FROM review_form_elements WHERE review_form_id = ? ORDER BY seq',
230  $reviewFormId, $rangeInfo
231  );
232 
233  $returner = new DAOResultFactory($result, $this, '_returnReviewFormElementFromRow');
234  return $returner;
235  }
236 
242  function getRequiredReviewFormElementIds($reviewFormId) {
243  $result =& $this->retrieve(
244  'SELECT review_form_element_id FROM review_form_elements WHERE review_form_id = ? AND required = 1 ORDER BY seq',
245  $reviewFormId
246  );
247 
248  $requiredReviewFormElementIds = array();
249 
250  while (!$result->EOF) {
251  $requiredReviewFormElementIds[] = $result->fields[0];
252  $result->MoveNext();
253  }
254 
255  $result->Close();
256  unset($result);
257 
258  return $requiredReviewFormElementIds;
259  }
260 
267  function reviewFormElementExists($reviewFormElementId, $reviewFormId = null) {
268  $sql = 'SELECT COUNT(*) FROM review_form_elements WHERE review_form_element_id = ?';
269  $params = array($reviewFormElementId);
270  if ($reviewFormId !== null) {
271  $sql .= ' AND review_form_id = ?';
272  $params[] = $reviewFormId;
273  }
274  $result =& $this->retrieve($sql, $params);
275 
276  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
277 
278  $result->Close();
279  unset($result);
280 
281  return $returner;
282  }
283 
288  function resequenceReviewFormElements($reviewFormId) {
289  $result =& $this->retrieve(
290  'SELECT review_form_element_id FROM review_form_elements WHERE review_form_id = ? ORDER BY seq', $reviewFormId
291  );
292 
293  for ($i=1; !$result->EOF; $i++) {
294  list($reviewFormElementId) = $result->fields;
295  $this->update(
296  'UPDATE review_form_elements SET seq = ? WHERE review_form_element_id = ?',
297  array(
298  $i,
299  $reviewFormElementId
300  )
301  );
302 
303  $result->MoveNext();
304  }
305 
306  $result->Close();
307  unset($result);
308  }
309 
315  return $this->getInsertId('review_form_elements', 'review_form_element_id');
316  }
317 
320  function insertReviewFormElement(&$reviewFormElement) {
321  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
322  $this->insertObject($reviewFormElement);
323  }
324 
325  function updateReviewFormElement(&$reviewFormElement) {
326  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
327  $this->updateObject($reviewFormElement);
328  }
329 
330  function deleteReviewFormElement(&$reviewFormElement) {
331  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
332  return $this->deleteObject($reviewFormElement);
333  }
334 
335  function deleteReviewFormElementById($reviewFormElementId) {
336  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
337  return $this->deleteById($reviewFormElementId);
338  }
339 
340  function deleteReviewFormElementsByReviewForm($reviewFormId) {
341  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
342  return $this->deleteByReviewFormId($reviewFormId);
343  }
344 }
345 
346 ?>
updateObject(&$reviewFormElement)
Operations for retrieving and modifying ReviewFormElement objects.
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
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
& getReviewFormElementsByReviewForm($reviewFormId, $rangeInfo=null)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
deleteById($reviewFormElementId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
updateLocaleFields(&$reviewFormElement)
deleteObject(&$reviewFormElement)
& getReviewFormElements($reviewFormId)
getRequiredReviewFormElementIds($reviewFormId)
resequenceReviewFormElements($reviewFormId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
insertReviewFormElement(&$reviewFormElement)
& getDAO($name, $dbconn=null)
call($hookName, $args=null)
insertObject(&$reviewFormElement)
& getReviewFormElement($reviewFormElementId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
Basic class describing a review form element.
deleteSetting($reviewFormElementId, $name, $locale=null)
reviewFormElementExists($reviewFormElementId, $reviewFormId=null)