Open Journal Systems  3.0.0
 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 
34  function getById($reviewFormElementId, $reviewFormId = null) {
35  $params = array((int) $reviewFormElementId);
36  if ($reviewFormId) {
37  $params[] = (int) $reviewFormId;
38  }
39  $result = $this->retrieve(
40  'SELECT *
41  FROM review_form_elements
42  WHERE review_form_element_id = ?
43  ' . ($reviewFormId?' AND review_form_id = ?':''),
44  $params
45  );
46 
47  $returner = null;
48  if ($result->RecordCount() != 0) {
49  $returner = $this->_fromRow($result->GetRowAssoc(false));
50  }
51 
52  $result->Close();
53  return $returner;
54  }
55 
60  function newDataObject() {
61  return new ReviewFormElement();
62  }
63 
69  function _fromRow($row) {
70  $reviewFormElement = $this->newDataObject();
71  $reviewFormElement->setId($row['review_form_element_id']);
72  $reviewFormElement->setReviewFormId($row['review_form_id']);
73  $reviewFormElement->setSequence($row['seq']);
74  $reviewFormElement->setElementType($row['element_type']);
75  $reviewFormElement->setRequired($row['required']);
76  $reviewFormElement->setIncluded($row['included']);
77 
78  $this->getDataObjectSettings('review_form_element_settings', 'review_form_element_id', $row['review_form_element_id'], $reviewFormElement);
79 
80  HookRegistry::call('ReviewFormElementDAO::_fromRow', array(&$reviewFormElement, &$row));
81 
82  return $reviewFormElement;
83  }
84 
89  function getLocaleFieldNames() {
90  return array('question', 'possibleResponses');
91  }
92 
97  function updateLocaleFields($reviewFormElement) {
98  $this->updateDataObjectSettings('review_form_element_settings', $reviewFormElement, array(
99  'review_form_element_id' => (int) $reviewFormElement->getId()
100  ));
101  }
102 
108  function insertObject($reviewFormElement) {
109  $this->update(
110  'INSERT INTO review_form_elements
111  (review_form_id, seq, element_type, required, included)
112  VALUES
113  (?, ?, ?, ?, ?)',
114  array(
115  (int) $reviewFormElement->getReviewFormId(),
116  $reviewFormElement->getSequence() == null ? 0 : (float) $reviewFormElement->getSequence(),
117  (int) $reviewFormElement->getElementType(),
118  (int) $reviewFormElement->getRequired(),
119  (int) $reviewFormElement->getIncluded(),
120  )
121  );
122 
123  $reviewFormElement->setId($this->getInsertId());
124  $this->updateLocaleFields($reviewFormElement);
125  return $reviewFormElement->getId();
126  }
127 
132  function updateObject($reviewFormElement) {
133  $returner = $this->update(
134  'UPDATE review_form_elements
135  SET review_form_id = ?,
136  seq = ?,
137  element_type = ?,
138  required = ?,
139  included = ?
140  WHERE review_form_element_id = ?',
141  array(
142  (int) $reviewFormElement->getReviewFormId(),
143  (float) $reviewFormElement->getSequence(),
144  (int) $reviewFormElement->getElementType(),
145  (int) $reviewFormElement->getRequired(),
146  (int) $reviewFormElement->getIncluded(),
147  (int) $reviewFormElement->getId()
148  )
149  );
150  $this->updateLocaleFields($reviewFormElement);
151  return $returner;
152  }
153 
158  function deleteObject($reviewFormElement) {
159  return $this->deleteById($reviewFormElement->getId());
160  }
161 
166  function deleteById($reviewFormElementId) {
167  $reviewFormResponseDao = DAORegistry::getDAO('ReviewFormResponseDAO');
168  $reviewFormResponseDao->deleteByReviewFormElementId($reviewFormElementId);
169 
170  $this->update('DELETE FROM review_form_element_settings WHERE review_form_element_id = ?', (int) $reviewFormElementId);
171  return $this->update('DELETE FROM review_form_elements WHERE review_form_element_id = ?', (int) $reviewFormElementId);
172  }
173 
179  function deleteByReviewFormId($reviewFormId) {
180  $reviewFormElements = $this->getByReviewFormId($reviewFormId);
181  foreach ($reviewFormElements as $reviewFormElementId => $reviewFormElement) {
182  $this->deleteById($reviewFormElementId);
183  }
184  }
185 
192  function deleteSetting($reviewFormElementId, $name, $locale = null) {
193  $params = array((int) $reviewFormElementId, $name);
194  if ($locale) $params[] = $locale;
195 
196  $this->update(
197  'DELETE FROM review_form_element_settings
198  WHERE review_form_element_id = ? AND setting_name = ?
199  ' . ($locale?' AND locale = ?':''),
200  $params
201  );
202  }
203 
210  function getByReviewFormId($reviewFormId, $rangeInfo = null) {
211  $result = $this->retrieveRange(
212  'SELECT * FROM review_form_elements WHERE review_form_id = ? ORDER BY seq',
213  (int) $reviewFormId, $rangeInfo
214  );
215 
216  return new DAOResultFactory($result, $this, '_fromRow');
217  }
218 
224  function getRequiredReviewFormElementIds($reviewFormId) {
225  $result = $this->retrieve(
226  'SELECT review_form_element_id FROM review_form_elements WHERE review_form_id = ? AND required = 1 ORDER BY seq',
227  $reviewFormId
228  );
229 
230  $requiredReviewFormElementIds = array();
231  while (!$result->EOF) {
232  $requiredReviewFormElementIds[] = $result->fields[0];
233  $result->MoveNext();
234  }
235 
236  $result->Close();
237  return $requiredReviewFormElementIds;
238  }
239 
246  function reviewFormElementExists($reviewFormElementId, $reviewFormId = null) {
247  $params = array((int) $reviewFormElementId);
248  if ($reviewFormId) $params[] = (int) $reviewFormId;
249 
250  $result = $this->retrieve(
251  'SELECT COUNT(*)
252  FROM review_form_elements
253  WHERE review_form_element_id = ?
254  ' . ($reviewFormId?' AND review_form_id = ?':''),
255  $params
256  );
257 
258  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
259 
260  $result->Close();
261  return $returner;
262  }
263 
268  function resequenceReviewFormElements($reviewFormId) {
269  $result = $this->retrieve(
270  'SELECT review_form_element_id FROM review_form_elements WHERE review_form_id = ? ORDER BY seq',
271  (int) $reviewFormId
272  );
273 
274  for ($i=1; !$result->EOF; $i++) {
275  list($reviewFormElementId) = $result->fields;
276  $this->update(
277  'UPDATE review_form_elements SET seq = ? WHERE review_form_element_id = ?',
278  array(
279  $i,
280  $reviewFormElementId
281  )
282  );
283 
284  $result->MoveNext();
285  }
286  $result->Close();
287  }
288 
293  function getInsertId() {
294  return $this->_getInsertId('review_form_elements', 'review_form_element_id');
295  }
296 }
297 
298 ?>
static & getDAO($name, $dbconn=null)
updateObject($reviewFormElement)
Operations for retrieving and modifying ReviewFormElement objects.
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
updateLocaleFields($reviewFormElement)
insertObject($reviewFormElement)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:457
deleteById($reviewFormElementId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
deleteObject($reviewFormElement)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
getRequiredReviewFormElementIds($reviewFormId)
static call($hookName, $args=null)
resequenceReviewFormElements($reviewFormId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getByReviewFormId($reviewFormId, $rangeInfo=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
Basic class describing a review form element.
deleteSetting($reviewFormElementId, $name, $locale=null)
reviewFormElementExists($reviewFormElementId, $reviewFormId=null)
getById($reviewFormElementId, $reviewFormId=null)