Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
OMPCompletedPaymentDAO.inc.php
1 <?php
2 
18 import('classes.payment.omp.OMPPaymentManager'); // PAYMENT_TYPE_... consts
19 import('classes.payment.omp.OMPCompletedPayment');
20 
21 class OMPCompletedPaymentDAO extends DAO {
28  function &getCompletedPayment($completedPaymentId, $pressId = null) {
29  $params = array((int) $completedPaymentId);
30  if ($pressId) $params[] = (int) $pressId;
31 
32  $result = $this->retrieve(
33  'SELECT * FROM completed_payments WHERE completed_payment_id = ?' . ($pressId?' AND press_id = ?':''),
34  $params
35  );
36 
37  $returner = null;
38  if ($result->RecordCount() != 0) {
39  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
40  }
41 
42  $result->Close();
43  unset($result);
44  return $returner;
45  }
46 
51  function insertCompletedPayment(&$completedPayment) {
52  $this->update(
53  sprintf('INSERT INTO completed_payments
54  (timestamp, payment_type, press_id, user_id, assoc_id, amount, currency_code_alpha, payment_method_plugin_name)
55  VALUES
56  (%s, ?, ?, ?, ?, ?, ?, ?)',
58  array(
59  (int) $completedPayment->getType(),
60  (int) $completedPayment->getPressId(),
61  (int) $completedPayment->getUserId(),
62  $completedPayment->getAssocId(), /* NOT int */
63  $completedPayment->getAmount(),
64  $completedPayment->getCurrencyCode(),
65  $completedPayment->getPayMethodPluginName()
66  )
67  );
68 
69  return $this->getInsertId();
70  }
71 
76  function getInsertId() {
77  return $this->_getInsertId('completed_payments', 'completed_payment_id');
78  }
79 
85  function hasPaidPurchaseFile ($userId, $fileIdAndRevision) {
86  $result = $this->retrieve(
87  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
88  array(
89  PAYMENT_TYPE_PURCHASE_FILE,
90  (int) $userId,
91  $fileIdAndRevision
92  )
93  );
94 
95  $returner = false;
96  if (isset($result->fields[0]) && $result->fields[0] != 0) {
97  $returner = true;
98  }
99 
100  $result->Close();
101  return $returner;
102  }
103 
109  function &getPaymentsByPressId($pressId, $rangeInfo = null) {
110  $result = $this->retrieveRange(
111  'SELECT * FROM completed_payments WHERE press_id = ? ORDER BY timestamp DESC',
112  (int) $pressId,
113  $rangeInfo
114  );
115 
116  $returner = new DAOResultFactory($result, $this, '_returnPaymentFromRow');
117  return $returner;
118  }
119 
124  function newDataObject() {
125  return new OMPCompletedPayment();
126  }
127 
133  function &_returnPaymentFromRow(&$row) {
134  $payment = $this->newDataObject();
135  $payment->setTimestamp($this->datetimeFromDB($row['timestamp']));
136  $payment->setId($row['completed_payment_id']);
137  $payment->setType($row['payment_type']);
138  $payment->setPressId($row['press_id']);
139  $payment->setAmount($row['amount']);
140  $payment->setCurrencyCode($row['currency_code_alpha']);
141  $payment->setUserId($row['user_id']);
142  $payment->setAssocId($row['assoc_id']);
143  $payment->setPayMethodPluginName($row['payment_method_plugin_name']);
144 
145  return $payment;
146  }
147 }
148 
149 ?>
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
Class describing a payment ready to be in the database.
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
datetimeFromDB($dt)
Definition: DAO.inc.php:313
Operations for retrieving and querying past payments.
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
& getPaymentsByPressId($pressId, $rangeInfo=null)
& getCompletedPayment($completedPaymentId, $pressId=null)
insertCompletedPayment(&$completedPayment)
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
hasPaidPurchaseFile($userId, $fileIdAndRevision)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95