Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
InstitutionalSubscriptionDAO.inc.php
1 <?php
2 
17 import('classes.subscription.SubscriptionDAO');
18 import('classes.subscription.InstitutionalSubscription');
19 
20 define('SUBSCRIPTION_INSTITUTION_NAME', 0x20);
21 define('SUBSCRIPTION_DOMAIN', 0x21);
22 define('SUBSCRIPTION_IP_RANGE', 0x22);
23 
30  function &getSubscription($subscriptionId) {
31  $result = $this->retrieve(
32  'SELECT s.*, iss.*
33  FROM
34  subscriptions s,
35  subscription_types st,
36  institutional_subscriptions iss
37  WHERE s.type_id = st.type_id
38  AND st.institutional = 1
39  AND s.subscription_id = iss.subscription_id
40  AND s.subscription_id = ?',
41  $subscriptionId
42  );
43 
44  $returner = null;
45  if ($result->RecordCount() != 0) {
46  $returner =& $this->_returnSubscriptionFromRow($result->GetRowAssoc(false));
47  }
48 
49  $result->Close();
50  return $returner;
51  }
52 
58  function &getSubscriptionsByUser($userId, $rangeInfo = null) {
59  $result = $this->retrieveRange(
60  'SELECT s.*, iss.*
61  FROM
62  subscriptions s,
63  subscription_types st,
64  institutional_subscriptions iss
65  WHERE s.type_id = st.type_id
66  AND st.institutional = 1
67  AND s.subscription_id = iss.subscription_id
68  AND s.user_id = ?',
69  $userId,
70  $rangeInfo
71  );
72 
73  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
74 
75  return $returner;
76  }
77 
84  function &getSubscriptionsByUserForJournal($userId, $journalId, $rangeInfo = null) {
85  $result = $this->retrieveRange(
86  'SELECT s.*, iss.*
87  FROM
88  subscriptions s,
89  subscription_types st,
90  institutional_subscriptions iss
91  WHERE s.type_id = st.type_id
92  AND st.institutional = 1
93  AND s.subscription_id = iss.subscription_id
94  AND s.user_id = ?
95  AND s.journal_id = ?',
96  array(
97  $userId,
98  $journalId
99  ),
100  $rangeInfo
101  );
102 
103  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
104 
105  return $returner;
106  }
107 
115  function &getSubscriptionsByInstitutionName($institutionName, $journalId, $exactMatch = true, $rangeInfo = null) {
116  $sql = 'SELECT s.*, iss.*
117  FROM
118  subscriptions s,
119  subscription_types st,
120  institutional_subscriptions iss
121  WHERE s.type_id = st.type_id
122  AND st.institutional = 1
123  AND s.subscription_id = iss.subscription_id' .
124  $exactMatch ? ' AND LOWER(iss.institution_name) = LOWER(?)'
125  : ' AND LOWER(iss.institution_name) LIKE LOWER(?)'
126  . ' AND s.journal_id = ?';
127 
128  $result = $this->retrieveRange(
129  $sql,
130  array(
131  $institutionName,
132  $journalId
133  ),
134  $rangeInfo
135  );
136 
137  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
138 
139  return $returner;
140  }
141 
147  function getStatusCount($journalId, $status = null) {
148  $params = array((int) $journalId);
149  if ($status !== null) $params[] = (int) $status;
150 
151  $result = $this->retrieve(
152  'SELECT COUNT(*)
153  FROM subscriptions s,
154  subscription_types st
155  WHERE s.type_id = st.type_id AND
156  st.institutional = 1 AND
157  s.journal_id = ?
158  ' . ($status !== null?' AND s.status = ?':''),
159  $params
160  );
161 
162  $returner = isset($result->fields[0]) ? $result->fields[0] : 0;
163 
164  $result->Close();
165  return $returner;
166  }
167 
173  function getSubscribedUserCount($journalId) {
174  return $this->getStatusCount($journalId);
175  }
176 
182  function subscriptionExists($subscriptionId) {
183  $result = $this->retrieve(
184  'SELECT COUNT(*)
185  FROM
186  subscriptions s,
187  subscription_types st
188  WHERE s.type_id = st.type_id
189  AND st.institutional = 1
190  AND s.subscription_id = ?',
191  $subscriptionId
192  );
193 
194  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
195 
196  $result->Close();
197  return $returner;
198  }
199 
206  function subscriptionExistsByUser($subscriptionId, $userId){
207  $result = $this->retrieve(
208  'SELECT COUNT(*)
209  FROM
210  subscriptions s,
211  subscription_types st
212  WHERE s.type_id = st.type_id
213  AND st.institutional = 1
214  AND s.subscription_id = ?
215  AND s.user_id = ?',
216  array(
217  $subscriptionId,
218  $userId
219  )
220  );
221 
222  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
223 
224  $result->Close();
225  return $returner;
226  }
227 
234  function subscriptionExistsByUserForJournal($userId, $journalId) {
235  $result = $this->retrieve(
236  'SELECT COUNT(*)
237  FROM
238  subscriptions s,
239  subscription_types st
240  WHERE s.type_id = st.type_id
241  AND st.institutional = 1
242  AND s.user_id = ?
243  AND s.journal_id = ?',
244  array(
245  $userId,
246  $journalId
247  )
248  );
249 
250  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
251 
252  $result->Close();
253  return $returner;
254  }
255 
263  function subscriptionExistsByInstitutionName($institutionName, $journalId, $exactMatch = true) {
264  $sql = 'SELECT COUNT(*)
265  FROM
266  subscriptions s,
267  subscription_types st,
268  institutional_subscriptions iss
269  WHERE s.type_id = st.type_id
270  AND st.institutional = 1' .
271  $exactMatch ? ' AND LOWER(iss.institution_name) = LOWER(?)'
272  : ' AND LOWER(iss.institution_name) LIKE LOWER(?)'
273  . ' AND s.journal_id = ?';
274 
275  $result = $this->retrieve(
276  $sql,
277  array(
278  $institutionName,
279  $journalId
280  )
281  );
282 
283  $returner = isset($result->fields[0]) && $result->fields[0] != 0 ? true : false;
284 
285  $result->Close();
286  return $returner;
287  }
288 
294  function insertSubscription(&$institutionalSubscription) {
295  $subscriptionId = null;
296  if ($this->_insertSubscription($institutionalSubscription)) {
297  $subscriptionId = $institutionalSubscription->getId();
298 
299  $this->update(
300  'INSERT INTO institutional_subscriptions
301  (subscription_id, institution_name, mailing_address, domain)
302  VALUES
303  (?, ?, ?, ?)',
304  array(
305  $subscriptionId,
306  $institutionalSubscription->getInstitutionName(),
307  $institutionalSubscription->getInstitutionMailingAddress(),
308  $institutionalSubscription->getDomain()
309  )
310  );
311 
312  $this->_insertSubscriptionIPRanges($subscriptionId, $institutionalSubscription->getIPRanges());
313  }
314 
315  return $subscriptionId;
316  }
317 
323  function updateSubscription(&$institutionalSubscription) {
324  $returner = false;
325  if ($this->_updateSubscription($institutionalSubscription)) {
326 
327  $returner = $this->update(
328  'UPDATE institutional_subscriptions
329  SET
330  institution_name = ?,
331  mailing_address = ?,
332  domain = ?
333  WHERE subscription_id = ?',
334  array(
335  $institutionalSubscription->getInstitutionName(),
336  $institutionalSubscription->getInstitutionMailingAddress(),
337  $institutionalSubscription->getDomain(),
338  $institutionalSubscription->getId()
339  )
340  );
341 
342  $this->_deleteSubscriptionIPRanges($institutionalSubscription->getId());
343  $this->_insertSubscriptionIPRanges($institutionalSubscription->getId(), $institutionalSubscription->getIPRanges());
344  }
345 
346  return $returner;
347  }
348 
354  function deleteSubscriptionById($subscriptionId) {
355  $returner = false;
356  if ($this->subscriptionExists($subscriptionId)) {
357  $returner = $this->update(
358  'DELETE
359  FROM
360  subscriptions
361  WHERE subscription_id = ?',
362  $subscriptionId
363  );
364 
365  $returner = $this->update(
366  'DELETE
367  FROM
368  institutional_subscriptions
369  WHERE subscription_id = ?',
370  $subscriptionId
371  );
372 
373  $this->_deleteSubscriptionIPRanges($subscriptionId);
374  }
375  return $returner;
376  }
377 
383  function deleteSubscriptionsByJournal($journalId) {
384  $result = $this->retrieve(
385  'SELECT s.subscription_id
386  FROM
387  subscriptions s
388  WHERE s.journal_id = ?',
389  $journalId
390  );
391 
392  $returner = true;
393  if ($result->RecordCount() != 0) {
394  while (!$result->EOF) {
395  $subscriptionId = $result->fields[0];
396  $returner = $this->deleteSubscriptionById($subscriptionId);
397  if (!$returner) {
398  break;
399  }
400  $result->MoveNext();
401  }
402  }
403 
404  $result->Close();
405  return $returner;
406  }
407 
413  function deleteSubscriptionsByUserId($userId) {
414  $result = $this->retrieve(
415  'SELECT s.subscription_id
416  FROM
417  subscriptions s
418  WHERE s.user_id = ?',
419  $userId
420  );
421 
422  $returner = true;
423  if ($result->RecordCount() != 0) {
424  while (!$result->EOF) {
425  $subscriptionId = $result->fields[0];
426  $returner = $this->deleteSubscriptionById($subscriptionId);
427  if (!$returner) {
428  break;
429  }
430  $result->MoveNext();
431  }
432  }
433 
434  $result->Close();
435  return $returner;
436  }
437 
444  function deleteSubscriptionsByUserIdForJournal($userId, $journalId) {
445  $result = $this->retrieve(
446  'SELECT s.subscription_id
447  FROM
448  subscriptions s
449  WHERE s.user_id = ?
450  AND s.journal_id = ?',
451  array (
452  $userId,
453  $journalId
454  )
455  );
456 
457  $returner = true;
458  if ($result->RecordCount() != 0) {
459  while (!$result->EOF) {
460  $subscriptionId = $result->fields[0];
461  $returner = $this->deleteSubscriptionById($subscriptionId);
462  if (!$returner) {
463  break;
464  }
465  $result->MoveNext();
466  }
467  }
468 
469  $result->Close();
470  return $returner;
471  }
472 
478  function deleteSubscriptionsByTypeId($subscriptionTypeId) {
479  $result = $this->retrieve(
480  'SELECT s.subscription_id
481  FROM
482  subscriptions s
483  WHERE s.type_id = ?',
484  $subscriptionTypeId
485  );
486 
487  $returner = true;
488  if ($result->RecordCount() != 0) {
489  while (!$result->EOF) {
490  $subscriptionId = $result->fields[0];
491  $returner = $this->deleteSubscriptionById($subscriptionId);
492  if (!$returner) {
493  break;
494  }
495  $result->MoveNext();
496  }
497  }
498 
499  $result->Close();
500  return $returner;
501  }
502 
507  function &getSubscriptions($rangeInfo = null) {
508  $result = $this->retrieveRange(
509  'SELECT s.*, iss.*
510  FROM
511  subscriptions s,
512  subscription_types st,
513  institutional_subscriptions iss
514  WHERE s.type_id = st.type_id
515  AND st.institutional = 1
516  AND s.subscription_id = iss.subscription_id
517  ORDER BY
518  iss.institution_name ASC,
519  s.subscription_id',
520  false,
521  $rangeInfo
522  );
523 
524  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
525 
526  return $returner;
527  }
528 
533  function &getSubscribedUsers($journalId, $rangeInfo = null) {
534  $result = $this->retrieveRange(
535  'SELECT u.*
536  FROM subscriptions s,
537  subscription_types st,
538  users u
539  WHERE s.type_id = st.type_id AND
540  st.institutional = 1 AND
541  s.user_id = u.user_id AND
542  s.journal_id = ?
543  ORDER BY u.last_name ASC, s.subscription_id',
544  array((int) $journalId),
545  $rangeInfo
546  );
547 
548  $userDao = DAORegistry::getDAO('UserDAO');
549  $returner = new DAOResultFactory($result, $userDao, '_returnUserFromRow');
550 
551  return $returner;
552  }
553 
566  function &getSubscriptionsByJournalId($journalId, $status = null, $searchField = null, $searchMatch = null, $search = null, $dateField = null, $dateFrom = null, $dateTo = null, $rangeInfo = null) {
567 
568  $params = array($journalId);
569  $ipRangeSql1 = $ipRangeSql2 = '';
570  $searchSql = $this->_generateSearchSQL($status, $searchField, $searchMatch, $search, $dateField, $dateFrom, $dateTo, $params);
571 
572  if (!empty($search)) switch ($searchField) {
573  case SUBSCRIPTION_INSTITUTION_NAME:
574  if ($searchMatch === 'is') {
575  $searchSql = ' AND LOWER(iss.institution_name) = LOWER(?)';
576  } elseif ($searchMatch === 'contains') {
577  $searchSql = ' AND LOWER(iss.institution_name) LIKE LOWER(?)';
578  $search = '%' . $search . '%';
579  } else { // $searchMatch === 'startsWith'
580  $searchSql = ' AND LOWER(iss.institution_name) LIKE LOWER(?)';
581  $search = $search . '%';
582  }
583  $params[] = $search;
584  break;
585  case SUBSCRIPTION_DOMAIN:
586  if ($searchMatch === 'is') {
587  $searchSql = ' AND LOWER(iss.domain) = LOWER(?)';
588  } elseif ($searchMatch === 'contains') {
589  $searchSql = ' AND LOWER(iss.domain) LIKE LOWER(?)';
590  $search = '%' . $search . '%';
591  } else { // $searchMatch === 'startsWith'
592  $searchSql = ' AND LOWER(iss.domain) LIKE LOWER(?)';
593  $search = $search . '%';
594  }
595  $params[] = $search;
596  break;
597  case SUBSCRIPTION_IP_RANGE:
598  if ($searchMatch === 'is') {
599  $searchSql = ' AND LOWER(isip.ip_string) = LOWER(?)';
600  } elseif ($searchMatch === 'contains') {
601  $searchSql = ' AND LOWER(isip.ip_string) LIKE LOWER(?)';
602  $search = '%' . $search . '%';
603  } else { // $searchMatch === 'startsWith'
604  $searchSql = ' AND LOWER(isip.ip_string) LIKE LOWER(?)';
605  $search = $search . '%';
606  }
607  $params[] = $search;
608  $ipRangeSql1 = ', institutional_subscription_ip isip' ;
609  $ipRangeSql2 = ' AND s.subscription_id = isip.subscription_id';
610  break;
611  }
612 
613  $sql = 'SELECT DISTINCT
614  s.*, iss.*
615  FROM
616  subscriptions s,
617  subscription_types st,
618  users u,
619  institutional_subscriptions iss'
620  . $ipRangeSql1 .
621  ' WHERE s.type_id = st.type_id
622  AND s.user_id = u.user_id
623  AND st.institutional = 1
624  AND s.subscription_id = iss.subscription_id'
625  . $ipRangeSql2 .
626  ' AND s.journal_id = ?';
627 
628  $result = $this->retrieveRange(
629  $sql . ' ' . $searchSql . ' ORDER BY iss.institution_name ASC, s.subscription_id',
630  count($params)===1?array_shift($params):$params,
631  $rangeInfo
632  );
633 
634  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
635 
636  return $returner;
637  }
638 
648  function isValidInstitutionalSubscription($domain, $IP, $journalId, $check = SUBSCRIPTION_DATE_BOTH, $checkDate = null) {
649  if (empty($journalId) || (empty($domain) && empty($IP))) {
650  return false;
651  }
652  $returner = false;
653 
654  $today = $this->dateToDB(Core::getCurrentDate());
655 
656  if ($checkDate == null) {
657  $checkDate = $today;
658  } else {
659  $checkDate = $this->dateToDB($checkDate);
660  }
661 
662  switch($check) {
663  case SUBSCRIPTION_DATE_START:
664  $dateSql = sprintf('%s >= s.date_start AND %s >= s.date_start', $checkDate, $today);
665  break;
666  case SUBSCRIPTION_DATE_END:
667  $dateSql = sprintf('%s <= s.date_end AND %s >= s.date_start', $checkDate, $today);
668  break;
669  default:
670  $dateSql = sprintf('%s >= s.date_start AND %s <= s.date_end', $checkDate, $checkDate);
671  }
672 
673  $nonExpiringSql = "AND ((st.non_expiring = 1) OR (st.non_expiring = 0 AND ($dateSql)))";
674 
675  // Check if domain match
676  if (!empty($domain)) {
677  $result = $this->retrieve('
678  SELECT iss.subscription_id
679  FROM
680  institutional_subscriptions iss,
681  subscriptions s,
682  subscription_types st
683  WHERE POSITION(UPPER(LPAD(iss.domain, LENGTH(iss.domain)+1, \'.\')) IN UPPER(LPAD(?, LENGTH(?)+1, \'.\'))) != 0
684  AND iss.domain != \'\'
685  AND iss.subscription_id = s.subscription_id
686  AND s.journal_id = ?
687  AND s.status = ' . SUBSCRIPTION_STATUS_ACTIVE . '
688  AND s.type_id = st.type_id
689  AND st.institutional = 1 '
690  . $nonExpiringSql .
691  ' AND (st.format = ' . SUBSCRIPTION_TYPE_FORMAT_ONLINE . '
692  OR st.format = ' . SUBSCRIPTION_TYPE_FORMAT_PRINT_ONLINE . ')',
693  array(
694  $domain,
695  $domain,
696  $journalId
697  )
698  );
699 
700  if ($result->RecordCount() != 0) {
701  $returner = $result->fields[0];
702  }
703 
704  $result->Close();
705 
706  if ($returner) {
707  return $returner;
708  }
709  }
710 
711  // Check for IP match
712  if (!empty($IP)) {
713  $IP = sprintf('%u', ip2long($IP));
714 
715  $result = $this->retrieve('
716  SELECT isip.subscription_id
717  FROM
718  institutional_subscription_ip isip,
719  subscriptions s,
720  subscription_types st
721  WHERE ((isip.ip_end IS NOT NULL
722  AND ? >= isip.ip_start AND ? <= isip.ip_end
723  AND isip.subscription_id = s.subscription_id
724  AND s.journal_id = ?
725  AND s.status = ' . SUBSCRIPTION_STATUS_ACTIVE . '
726  AND s.type_id = st.type_id
727  AND st.institutional = 1 '
728  . $nonExpiringSql .
729  ' AND (st.format = ' . SUBSCRIPTION_TYPE_FORMAT_ONLINE . '
730  OR st.format = ' . SUBSCRIPTION_TYPE_FORMAT_PRINT_ONLINE . '))
731  OR (isip.ip_end IS NULL
732  AND ? = isip.ip_start
733  AND isip.subscription_id = s.subscription_id
734  AND s.journal_id = ?
735  AND s.status = ' . SUBSCRIPTION_STATUS_ACTIVE . '
736  AND s.type_id = st.type_id
737  AND st.institutional = 1 '
738  . $nonExpiringSql .
739  ' AND (st.format = ' . SUBSCRIPTION_TYPE_FORMAT_ONLINE . '
740  OR st.format = ' . SUBSCRIPTION_TYPE_FORMAT_PRINT_ONLINE . ')))',
741  array (
742  $IP,
743  $IP,
744  $journalId,
745  $IP,
746  $journalId
747  )
748  );
749 
750  if ($result->RecordCount() != 0) {
751  $returner = $result->fields[0];
752  }
753 
754  $result->Close();
755  }
756 
757  return $returner;
758  }
759 
766  function &getSubscriptionsByDateEnd($dateEnd, $journalId, $rangeInfo = null) {
767  $dateEnd = explode('-', $dateEnd);
768 
769  $result = $this->retrieveRange(
770  'SELECT s.*, iss.*
771  FROM
772  subscriptions s,
773  subscription_types st,
774  institutional_subscriptions iss
775  WHERE s.type_id = st.type_id
776  AND s.status = ' . SUBSCRIPTION_STATUS_ACTIVE . ' ' .
777  'AND st.institutional = 1
778  AND s.subscription_id = iss.subscription_id AND
779  EXTRACT(YEAR FROM s.date_end) = ? AND
780  EXTRACT(MONTH FROM s.date_end) = ? AND
781  EXTRACT(DAY FROM s.date_end) = ? AND
782  s.journal_id = ?
783  ORDER BY iss.institution_name ASC, s.subscription_id',
784  array(
785  $dateEnd[0],
786  $dateEnd[1],
787  $dateEnd[2],
788  $journalId
789  ), $rangeInfo
790  );
791 
792  $returner = new DAOResultFactory($result, $this, '_returnSubscriptionFromRow');
793 
794  return $returner;
795  }
796 
803  function renewSubscription(&$institutionalSubscription) {
804  return $this->_renewSubscription($institutionalSubscription);
805  }
806 
811  function createObject() {
812  return new InstitutionalSubscription();
813  }
814 
820  function &_returnSubscriptionFromRow($row) {
821  $institutionalSubscription = parent::_returnSubscriptionFromRow($row);
822 
823  $institutionalSubscription->setInstitutionName($row['institution_name']);
824  $institutionalSubscription->setInstitutionMailingAddress($row['mailing_address']);
825  $institutionalSubscription->setDomain($row['domain']);
826 
827  $ipResult =& $this->retrieve(
828  'SELECT ip_string
829  FROM
830  institutional_subscription_ip
831  WHERE subscription_id = ?
832  ORDER BY institutional_subscription_ip_id ASC',
833  $institutionalSubscription->getId()
834  );
835 
836  $ipRanges = array();
837  while (!$ipResult->EOF) {
838  $ipRow = $ipResult->GetRowAssoc(false);
839  $ipRanges[] = $ipRow['ip_string'];
840  $ipResult->MoveNext();
841  }
842 
843  $institutionalSubscription->setIPRanges($ipRanges);
844  $ipResult->Close();
845 
846  HookRegistry::call('InstitutionalSubscriptionDAO::_returnSubscriptionFromRow', array(&$institutionalSubscription, &$row));
847 
848  return $institutionalSubscription;
849  }
850 
857  function _insertSubscriptionIPRanges($subscriptionId, $ipRanges) {
858  if (empty($ipRanges)) {
859  return true;
860  }
861 
862  if (empty($subscriptionId)) {
863  return false;
864  }
865 
866  $returner = true;
867 
868  while (list(, $curIPString) = each($ipRanges)) {
869  $ipStart = null;
870  $ipEnd = null;
871 
872  // Parse and check single IP string
873  if (strpos($curIPString, SUBSCRIPTION_IP_RANGE_RANGE) === false) {
874 
875  // Check for wildcards in IP
876  if (strpos($curIPString, SUBSCRIPTION_IP_RANGE_WILDCARD) === false) {
877 
878  // Get non-CIDR IP
879  if (strpos($curIPString, '/') === false) {
880  $ipStart = sprintf("%u", ip2long(trim($curIPString)));
881 
882  // Convert CIDR IP to IP range
883  } else {
884  list($cidrIPString, $cidrBits) = explode('/', trim($curIPString));
885 
886  if ($cidrBits == 0) {
887  $cidrMask = 0;
888  } else {
889  $cidrMask = (0xffffffff << (32 - $cidrBits));
890  }
891 
892  $ipStart = sprintf('%u', ip2long($cidrIPString) & $cidrMask);
893 
894  if ($cidrBits != 32) {
895  $ipEnd = sprintf('%u', ip2long($cidrIPString) | (~$cidrMask & 0xffffffff));
896  }
897  }
898 
899  // Convert wildcard IP to IP range
900  } else {
901  $ipStart = sprintf('%u', ip2long(str_replace(SUBSCRIPTION_IP_RANGE_WILDCARD, '0', trim($curIPString))));
902  $ipEnd = sprintf('%u', ip2long(str_replace(SUBSCRIPTION_IP_RANGE_WILDCARD, '255', trim($curIPString))));
903  }
904 
905  // Convert wildcard IP range to IP range
906  } else {
907  list($ipStart, $ipEnd) = explode(SUBSCRIPTION_IP_RANGE_RANGE, $curIPString);
908 
909  // Replace wildcards in start and end of range
910  $ipStart = sprintf('%u', ip2long(str_replace(SUBSCRIPTION_IP_RANGE_WILDCARD, '0', trim($ipStart))));
911  $ipEnd = sprintf('%u', ip2long(str_replace(SUBSCRIPTION_IP_RANGE_WILDCARD, '255', trim($ipEnd))));
912  }
913 
914  // Insert IP or IP range
915  if (($ipStart != null) && ($returner)) {
916  $returner = $this->update(
917  'INSERT INTO institutional_subscription_ip
918  (subscription_id, ip_string, ip_start, ip_end)
919  VALUES
920  (?, ?, ?, ?)',
921  array(
922  $subscriptionId,
923  $curIPString,
924  $ipStart,
925  $ipEnd
926  )
927  );
928  } else {
929  $returner = false;
930  break;
931  }
932 
933  }
934 
935  return $returner;
936  }
937 
943  function _deleteSubscriptionIPRanges($subscriptionId) {
944  return $this->update(
945  'DELETE FROM institutional_subscription_ip WHERE subscription_id = ?', $subscriptionId
946  );
947  }
948 }
949 
950 ?>
_renewSubscription(&$subscription)
static & getDAO($name, $dbconn=null)
_updateSubscription(&$subscription)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
Basic class describing an institutional subscription.
dateToDB($d)
Definition: DAO.inc.php:303
Abstract class for retrieving and modifying subscriptions.
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
static call($hookName, $args=null)
_insertSubscription(&$subscription)
subscriptionExistsByInstitutionName($institutionName, $journalId, $exactMatch=true)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
_insertSubscriptionIPRanges($subscriptionId, $ipRanges)
Operations for retrieving and modifying InstitutionalSubscription objects.
insertSubscription(&$institutionalSubscription)
updateSubscription(&$institutionalSubscription)
isValidInstitutionalSubscription($domain, $IP, $journalId, $check=SUBSCRIPTION_DATE_BOTH, $checkDate=null)
& getSubscriptionsByJournalId($journalId, $status=null, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, $rangeInfo=null)
_generateSearchSQL($status=null, $searchField=null, $searchMatch=null, $search=null, $dateField=null, $dateFrom=null, $dateTo=null, &$params)
& getSubscriptionsByInstitutionName($institutionName, $journalId, $exactMatch=true, $rangeInfo=null)
& getSubscribedUsers($journalId, $rangeInfo=null)
subscriptionExistsByUser($subscriptionId, $userId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
renewSubscription(&$institutionalSubscription)
& getSubscriptionsByUserForJournal($userId, $journalId, $rangeInfo=null)
& getSubscriptionsByUser($userId, $rangeInfo=null)
& getSubscriptionsByDateEnd($dateEnd, $journalId, $rangeInfo=null)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95