Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
SubscriptionTypeDAO.inc.php
1 <?php
2 
17 import('classes.subscription.SubscriptionType');
18 
19 class SubscriptionTypeDAO extends DAO {
25  function &getSubscriptionType($typeId) {
26  $result =& $this->retrieve(
27  'SELECT * FROM subscription_types WHERE type_id = ?', $typeId
28  );
29 
30  $returner = null;
31  if ($result->RecordCount() != 0) {
32  $returner =& $this->_returnSubscriptionTypeFromRow($result->GetRowAssoc(false));
33  }
34 
35  $result->Close();
36  unset($result);
37 
38  return $returner;
39  }
40 
46  function getSubscriptionTypeJournalId($typeId) {
47  $result =& $this->retrieve(
48  'SELECT journal_id FROM subscription_types WHERE type_id = ?', $typeId
49  );
50 
51  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
52 
53  $result->Close();
54  unset($result);
55 
56  return $returner;
57  }
58 
64  function getSubscriptionTypeName($typeId) {
65  $result =& $this->retrieve(
66  'SELECT COALESCE(l.setting_value, p.setting_value) FROM subscription_type_settings l LEFT JOIN subscription_type_settings p ON (p.type_id = ? AND p.setting_name = ? AND p.locale = ?) WHERE l.type_id = ? AND l.setting_name = ? AND l.locale = ?',
67  array(
68  $typeId, 'name', AppLocale::getLocale(),
69  $typeId, 'name', AppLocale::getPrimaryLocale()
70  )
71  );
72 
73  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
74 
75  $result->Close();
76  unset($result);
77 
78  return $returner;
79  }
80 
87  $result =& $this->retrieve(
88  'SELECT institutional FROM subscription_types WHERE type_id = ?', $typeId
89  );
90 
91  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
92 
93  $result->Close();
94  unset($result);
95 
96  return $returner;
97  }
98 
104  function getSubscriptionTypeMembership($typeId) {
105  $result =& $this->retrieve(
106  'SELECT membership FROM subscription_types WHERE type_id = ?', $typeId
107  );
108 
109  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
110 
111  $result->Close();
112  unset($result);
113 
114  return $returner;
115  }
116 
122  function getSubscriptionTypeNonExpiring($typeId) {
123  $result =& $this->retrieve(
124  'SELECT non_expiring FROM subscription_types WHERE type_id = ?', $typeId
125  );
126 
127  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
128 
129  $result->Close();
130  unset($result);
131 
132  return $returner;
133  }
134 
141  $result =& $this->retrieve(
142  'SELECT disable_public_display FROM subscription_types WHERE type_id = ?', $typeId
143  );
144 
145  $returner = isset($result->fields[0]) ? $result->fields[0] : false;
146 
147  $result->Close();
148  unset($result);
149 
150  return $returner;
151  }
152 
159  function subscriptionTypeExistsByTypeId($typeId, $journalId) {
160  $result =& $this->retrieve(
161  'SELECT COUNT(*)
162  FROM subscription_types
163  WHERE type_id = ?
164  AND journal_id = ?',
165  array(
166  $typeId,
167  $journalId
168  )
169  );
170  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
171 
172  $result->Close();
173  unset($result);
174 
175  return $returner;
176  }
177 
184  $subscriptionType = new SubscriptionType();
185  $subscriptionType->setTypeId($row['type_id']);
186  $subscriptionType->setJournalId($row['journal_id']);
187  $subscriptionType->setCost($row['cost']);
188  $subscriptionType->setCurrencyCodeAlpha($row['currency_code_alpha']);
189  $subscriptionType->setNonExpiring($row['non_expiring']);
190  $subscriptionType->setDuration($row['duration']);
191  $subscriptionType->setFormat($row['format']);
192  $subscriptionType->setInstitutional($row['institutional']);
193  $subscriptionType->setMembership($row['membership']);
194  $subscriptionType->setDisablePublicDisplay($row['disable_public_display']);
195  $subscriptionType->setSequence($row['seq']);
196 
197  $this->getDataObjectSettings('subscription_type_settings', 'type_id', $row['type_id'], $subscriptionType);
198 
199  HookRegistry::call('SubscriptionTypeDAO::_returnSubscriptionTypeFromRow', array(&$subscriptionType, &$row));
200 
201  return $subscriptionType;
202  }
203 
208  function getLocaleFieldNames() {
209  return array('name', 'description');
210  }
211 
216  function updateLocaleFields(&$subscriptionType) {
217  $this->updateDataObjectSettings('subscription_type_settings', $subscriptionType, array(
218  'type_id' => $subscriptionType->getTypeId()
219  ));
220  }
221 
227  function insertSubscriptionType(&$subscriptionType) {
228  $this->update(
229  'INSERT INTO subscription_types
230  (journal_id, cost, currency_code_alpha, non_expiring, duration, format, institutional, membership, disable_public_display, seq)
231  VALUES
232  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
233  array(
234  $subscriptionType->getJournalId(),
235  $subscriptionType->getCost(),
236  $subscriptionType->getCurrencyCodeAlpha(),
237  $subscriptionType->getNonExpiring(),
238  $subscriptionType->getDuration(),
239  $subscriptionType->getFormat(),
240  $subscriptionType->getInstitutional(),
241  $subscriptionType->getMembership(),
242  $subscriptionType->getDisablePublicDisplay(),
243  $subscriptionType->getSequence()
244  )
245  );
246 
247  $subscriptionType->setTypeId($this->getInsertSubscriptionTypeId());
248  $this->updateLocaleFields($subscriptionType);
249  return $subscriptionType->getTypeId();
250  }
251 
257  function updateSubscriptionType(&$subscriptionType) {
258  $returner = $this->update(
259  'UPDATE subscription_types
260  SET
261  journal_id = ?,
262  cost = ?,
263  currency_code_alpha = ?,
264  non_expiring = ?,
265  duration = ?,
266  format = ?,
267  institutional = ?,
268  membership = ?,
269  disable_public_display = ?,
270  seq = ?
271  WHERE type_id = ?',
272  array(
273  $subscriptionType->getJournalId(),
274  $subscriptionType->getCost(),
275  $subscriptionType->getCurrencyCodeAlpha(),
276  $subscriptionType->getNonExpiring(),
277  $subscriptionType->getDuration(),
278  $subscriptionType->getFormat(),
279  $subscriptionType->getInstitutional(),
280  $subscriptionType->getMembership(),
281  $subscriptionType->getDisablePublicDisplay(),
282  $subscriptionType->getSequence(),
283  $subscriptionType->getTypeId()
284  )
285  );
286  $this->updateLocaleFields($subscriptionType);
287  return $returner;
288  }
289 
295  function deleteSubscriptionType(&$subscriptionType) {
296  return $this->deleteSubscriptionTypeById($subscriptionType->getTypeId());
297  }
298 
305  function deleteSubscriptionTypeById($typeId) {
306  // Delete all subscriptions corresponding to this subscription type
307  $institutional = $this->getSubscriptionTypeInstitutional($typeId);
308 
309  if ($institutional) {
310  $subscriptionDao =& DAORegistry::getDAO('InstitutionalSubscriptionDAO');
311  } else {
312  $subscriptionDao =& DAORegistry::getDAO('IndividualSubscriptionDAO');
313  }
314  $returner = $subscriptionDao->deleteSubscriptionsByTypeId($typeId);
315 
316  // Delete subscription type
317  if ($returner) {
318  $returner = $this->update('DELETE FROM subscription_types WHERE type_id = ?', $typeId);
319  }
320 
321  // Delete all localization settings for this subscription type
322  if ($returner) {
323  $this->update('DELETE FROM subscription_type_settings WHERE type_id = ?', $typeId);
324  }
325 
326  return $returner;
327  }
328 
335  function deleteSubscriptionTypesByJournal($journalId) {
336  $result =& $this->retrieve(
337  'SELECT type_id
338  FROM subscription_types
339  WHERE journal_id = ?',
340  $journalId
341  );
342 
343  $returner = false;
344 
345  if ($result->RecordCount() != 0) {
346  $returner = true;
347  while (!$result->EOF && $returner) {
348  $typeId = $result->fields[0];
349  $returner = $this->deleteSubscriptionTypeById($typeId);
350  $result->moveNext();
351  }
352  }
353 
354  $result->Close();
355  unset($result);
356 
357  return $returner;
358  }
359 
365  function &getSubscriptionTypesByJournalId($journalId, $rangeInfo = null) {
366  $result =& $this->retrieveRange(
367  'SELECT * FROM subscription_types WHERE journal_id = ? ORDER BY seq',
368  $journalId, $rangeInfo
369  );
370 
371  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionTypeFromRow');
372  return $returner;
373  }
374 
382  function &getSubscriptionTypesByInstitutional($journalId, $institutional = false, $disablePublicDisplay = null, $rangeInfo = null) {
383  if ($institutional) $institutional = 1; else $institutional = 0;
384 
385  if ($disablePublicDisplay === null) {
386  $disablePublicDisplaySql = '';
387  } elseif ($disablePublicDisplay) {
388  $disablePublicDisplaySql = 'AND disable_public_display = 1';
389  } else {
390  $disablePublicDisplaySql = 'AND disable_public_display = 0';
391  }
392 
393  $result =& $this->retrieveRange(
394  'SELECT *
395  FROM
396  subscription_types
397  WHERE journal_id = ?
398  AND institutional = ? '
399  . $disablePublicDisplaySql .
400  ' ORDER BY seq',
401  array(
402  $journalId,
403  $institutional
404  ),
405  $rangeInfo
406  );
407 
408  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionTypeFromRow');
409  return $returner;
410  }
411 
418  function subscriptionTypesExistByInstitutional($journalId, $institutional = false) {
419  if ($institutional) $institutional = 1; else $institutional = 0;
420 
421  $result =& $this->retrieve(
422  'SELECT COUNT(*)
423  FROM
424  subscription_types st
425  WHERE st.journal_id = ?
426  AND st.institutional = ?',
427  array(
428  $journalId,
429  $institutional
430  )
431  );
432 
433  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
434 
435  $result->Close();
436  unset($result);
437 
438  return $returner;
439  }
440 
446  return $this->getInsertId('subscription_types', 'type_id');
447  }
448 
452  function resequenceSubscriptionTypes($journalId) {
453  $result =& $this->retrieve(
454  'SELECT type_id FROM subscription_types WHERE journal_id = ? ORDER BY seq',
455  $journalId
456  );
457 
458  for ($i=1; !$result->EOF; $i++) {
459  list($subscriptionTypeId) = $result->fields;
460  $this->update(
461  'UPDATE subscription_types SET seq = ? WHERE type_id = ?',
462  array(
463  $i,
464  $subscriptionTypeId
465  )
466  );
467 
468  $result->moveNext();
469  }
470 
471  $result->close();
472  unset($result);
473  }
474 }
475 
476 ?>
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
deleteSubscriptionTypesByJournal($journalId)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
subscriptionTypesExistByInstitutional($journalId, $institutional=false)
& getDAO($name, $dbconn=null)
& getSubscriptionTypesByJournalId($journalId, $rangeInfo=null)
call($hookName, $args=null)
insertSubscriptionType(&$subscriptionType)
deleteSubscriptionType(&$subscriptionType)
subscriptionTypeExistsByTypeId($typeId, $journalId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
Operations for retrieving and modifying SubscriptionType objects.
updateLocaleFields(&$subscriptionType)
getSubscriptionTypeDisablePublicDisplay($typeId)
& getSubscriptionTypesByInstitutional($journalId, $institutional=false, $disablePublicDisplay=null, $rangeInfo=null)
updateSubscriptionType(&$subscriptionType)