Open Monograph Press  1.1
 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  return $returner;
45  }
46 
51  function newDataObject() {
52  return new ReviewFormElement();
53  }
54 
61  $reviewFormElement = $this->newDataObject();
62  $reviewFormElement->setId($row['review_form_element_id']);
63  $reviewFormElement->setReviewFormId($row['review_form_id']);
64  $reviewFormElement->setSequence($row['seq']);
65  $reviewFormElement->setElementType($row['element_type']);
66  $reviewFormElement->setRequired($row['required']);
67  $reviewFormElement->setIncluded($row['included']);
68 
69  $this->getDataObjectSettings('review_form_element_settings', 'review_form_element_id', $row['review_form_element_id'], $reviewFormElement);
70 
71  HookRegistry::call('ReviewFormElementDAO::_returnReviewFormElementFromRow', array(&$reviewFormElement, &$row));
72 
73  return $reviewFormElement;
74  }
75 
80  function getLocaleFieldNames() {
81  return array('question', 'possibleResponses');
82  }
83 
88  function updateLocaleFields($reviewFormElement) {
89  $this->updateDataObjectSettings('review_form_element_settings', $reviewFormElement, array(
90  'review_form_element_id' => (int) $reviewFormElement->getId()
91  ));
92  }
93 
98  function insertObject($reviewFormElement) {
99  $this->update(
100  'INSERT INTO review_form_elements
101  (review_form_id, seq, element_type, required, included)
102  VALUES
103  (?, ?, ?, ?, ?)',
104  array(
105  (int) $reviewFormElement->getReviewFormId(),
106  $reviewFormElement->getSequence() == null ? 0 : $reviewFormElement->getSequence(),
107  $reviewFormElement->getElementType(),
108  (int) $reviewFormElement->getRequired(),
109  (int) $reviewFormElement->getIncluded(),
110  )
111  );
112 
113  $reviewFormElement->setId($this->getInsertId());
114  $this->updateLocaleFields($reviewFormElement);
115  return $reviewFormElement->getId();
116  }
117 
122  function updateObject($reviewFormElement) {
123  $returner = $this->update(
124  'UPDATE review_form_elements
125  SET
126  review_form_id = ?,
127  seq = ?,
128  element_type = ?,
129  required = ?,
130  included = ?
131  WHERE review_form_element_id = ?',
132  array(
133  (int) $reviewFormElement->getReviewFormId(),
134  $reviewFormElement->getSequence(),
135  $reviewFormElement->getElementType(),
136  (int) $reviewFormElement->getRequired(),
137  (int) $reviewFormElement->getIncluded(),
138  (int) $reviewFormElement->getId()
139  )
140  );
141  $this->updateLocaleFields($reviewFormElement);
142  return $returner;
143  }
144 
149  function deleteObject($reviewFormElement) {
150  return $this->deleteById($reviewFormElement->getId());
151  }
152 
157  function deleteById($reviewFormElementId) {
158  $reviewFormResponseDao = DAORegistry::getDAO('ReviewFormResponseDAO');
159  $reviewFormResponseDao->deleteByReviewFormElementId($reviewFormElementId);
160 
161  $this->update('DELETE FROM review_form_element_settings WHERE review_form_element_id = ?', (int) $reviewFormElementId);
162  return $this->update('DELETE FROM review_form_elements WHERE review_form_element_id = ?', (int) $reviewFormElementId);
163  }
164 
170  function deleteByReviewFormId($reviewFormId) {
171  $reviewFormElements = $this->getReviewFormElements($reviewFormId);
172  foreach ($reviewFormElements as $reviewFormElementId => $reviewFormElement) {
173  $this->deleteById($reviewFormElementId);
174  }
175  }
176 
183  function deleteSetting($reviewFormElementId, $name, $locale = null) {
184  $params = array($reviewFormElementId, $name);
185  $sql = 'DELETE FROM review_form_element_settings WHERE review_form_element_id = ? AND setting_name = ?';
186  if ($locale !== null) {
187  $params[] = $locale;
188  $sql .= ' AND locale = ?';
189  }
190 
191  return $this->update($sql, $params);
192  }
193 
199  function &getReviewFormElements($reviewFormId) {
200  $reviewFormElements = array();
201 
202  $result = $this->retrieve(
203  'SELECT * FROM review_form_elements WHERE review_form_id = ? ORDER BY seq',
204  $reviewFormId
205  );
206 
207  while (!$result->EOF) {
208  $reviewFormElement =& $this->_returnReviewFormElementFromRow($result->GetRowAssoc(false));
209  $reviewFormElements[$reviewFormElement->getId()] = $reviewFormElement;
210  $result->MoveNext();
211  }
212 
213  $result->Close();
214  return $reviewFormElements;
215  }
216 
223  function getReviewFormElementsByReviewForm($reviewFormId, $rangeInfo = null) {
224  $result = $this->retrieveRange(
225  'SELECT * FROM review_form_elements WHERE review_form_id = ? ORDER BY seq',
226  (int) $reviewFormId, $rangeInfo
227  );
228 
229  return new DAOResultFactory($result, $this, '_returnReviewFormElementFromRow');
230  }
231 
237  function getRequiredReviewFormElementIds($reviewFormId) {
238  $result = $this->retrieve(
239  'SELECT review_form_element_id FROM review_form_elements WHERE review_form_id = ? AND required = 1 ORDER BY seq',
240  $reviewFormId
241  );
242 
243  $requiredReviewFormElementIds = array();
244 
245  while (!$result->EOF) {
246  $requiredReviewFormElementIds[] = $result->fields[0];
247  $result->MoveNext();
248  }
249 
250  $result->Close();
251  return $requiredReviewFormElementIds;
252  }
253 
260  function reviewFormElementExists($reviewFormElementId, $reviewFormId = null) {
261  $sql = 'SELECT COUNT(*) FROM review_form_elements WHERE review_form_element_id = ?';
262  $params = array($reviewFormElementId);
263  if ($reviewFormId !== null) {
264  $sql .= ' AND review_form_id = ?';
265  $params[] = $reviewFormId;
266  }
267  $result = $this->retrieve($sql, $params);
268 
269  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
270 
271  $result->Close();
272  return $returner;
273  }
274 
279  function resequenceReviewFormElements($reviewFormId) {
280  $result = $this->retrieve(
281  'SELECT review_form_element_id FROM review_form_elements WHERE review_form_id = ? ORDER BY seq', $reviewFormId
282  );
283 
284  for ($i=1; !$result->EOF; $i++) {
285  list($reviewFormElementId) = $result->fields;
286  $this->update(
287  'UPDATE review_form_elements SET seq = ? WHERE review_form_element_id = ?',
288  array(
289  $i,
290  $reviewFormElementId
291  )
292  );
293 
294  $result->MoveNext();
295  }
296  $result->Close();
297  }
298 
303  function getInsertId() {
304  return $this->_getInsertId('review_form_elements', 'review_form_element_id');
305  }
306 }
307 
308 ?>
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)
getReviewFormElementsByReviewForm($reviewFormId, $rangeInfo=null)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
deleteObject($reviewFormElement)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
& getReviewFormElements($reviewFormId)
getRequiredReviewFormElementIds($reviewFormId)
static call($hookName, $args=null)
getReviewFormElement($reviewFormElementId)
resequenceReviewFormElements($reviewFormId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
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)