Open Monograph Press  3.3.0
OMPCompletedPaymentDAO.inc.php
1 <?php
2 
18 import('classes.payment.omp.OMPPaymentManager'); // PAYMENT_TYPE_... consts
19 import('lib.pkp.classes.payment.CompletedPayment');
20 
21 class OMPCompletedPaymentDAO extends DAO {
28  function getById($completedPaymentId, $contextId = null) {
29  $params = array((int) $completedPaymentId);
30  if ($contextId) $params[] = (int) $contextId;
31 
32  $result = $this->retrieve(
33  'SELECT * FROM completed_payments WHERE completed_payment_id = ?' . ($contextId?' AND context_id = ?':''),
34  $params
35  );
36 
37  $returner = null;
38  if ($result->RecordCount() != 0) {
39  $returner = $this->_fromRow($result->GetRowAssoc(false));
40  }
41 
42  $result->Close();
43  return $returner;
44  }
45 
50  function insertCompletedPayment($completedPayment) {
51  $this->update(
52  sprintf('INSERT INTO completed_payments
53  (timestamp, payment_type, context_id, user_id, assoc_id, amount, currency_code_alpha, payment_method_plugin_name)
54  VALUES
55  (%s, ?, ?, ?, ?, ?, ?, ?)',
57  array(
58  (int) $completedPayment->getType(),
59  (int) $completedPayment->getContextId(),
60  (int) $completedPayment->getUserId(),
61  $completedPayment->getAssocId(), /* NOT int */
62  $completedPayment->getAmount(),
63  $completedPayment->getCurrencyCode(),
64  $completedPayment->getPayMethodPluginName()
65  )
66  );
67 
68  return $this->getInsertId();
69  }
70 
76  function updateObject($completedPayment) {
77  $returner = false;
78 
79  $returner = $this->update(
80  sprintf('UPDATE completed_payments
81  SET
82  timestamp = %s,
83  payment_type = ?,
84  context_id = ?,
85  user_id = ?,
86  assoc_id = ?,
87  amount = ?,
88  currency_code_alpha = ?,
89  payment_method_plugin_name = ?
90  WHERE completed_payment_id = ?',
91  $this->datetimeToDB($completedPayment->getTimestamp())),
92  array(
93  (int) $completedPayment->getType(),
94  (int) $completedPayment->getContextId(),
95  (int) $completedPayment->getUserId(),
96  (int) $completedPayment->getAssocId(),
97  $completedPayment->getAmount(),
98  $completedPayment->getCurrencyCode(),
99  $completedPayment->getPayMethodPluginName(),
100  (int) $completedPayment->getId()
101  )
102  );
103 
104  return $returner;
105  }
106 
111  function getInsertId() {
112  return $this->_getInsertId('completed_payments', 'completed_payment_id');
113  }
114 
120  function hasPaidPurchaseFile ($userId, $fileIdAndRevision) {
121  $result = $this->retrieve(
122  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
123  array(
124  PAYMENT_TYPE_PURCHASE_FILE,
125  (int) $userId,
126  $fileIdAndRevision
127  )
128  );
129 
130  $returner = false;
131  if (isset($result->fields[0]) && $result->fields[0] != 0) {
132  $returner = true;
133  }
134 
135  $result->Close();
136  return $returner;
137  }
138 
144  function getByContextId($contextId, $rangeInfo = null) {
145  $result = $this->retrieveRange(
146  'SELECT * FROM completed_payments WHERE context_id = ? ORDER BY timestamp DESC',
147  (int) $contextId,
148  $rangeInfo
149  );
150 
151  return new DAOResultFactory($result, $this, '_fromRow');
152  }
153 
159  function getByUserId($userId, $rangeInfo = null) {
160  $result =& $this->retrieveRange(
161  'SELECT * FROM completed_payments WHERE user_id = ? ORDER BY timestamp DESC',
162  (int) $userId,
163  $rangeInfo
164  );
165 
166  $returner = new DAOResultFactory($result, $this, '_returnPaymentFromRow');
167  return $returner;
168  }
169 
174  function newDataObject() {
175  return new CompletedPayment();
176  }
177 
183  function _fromRow($row) {
184  $payment = $this->newDataObject();
185  $payment->setTimestamp($this->datetimeFromDB($row['timestamp']));
186  $payment->setId($row['completed_payment_id']);
187  $payment->setType($row['payment_type']);
188  $payment->setContextId($row['context_id']);
189  $payment->setAmount($row['amount']);
190  $payment->setCurrencyCode($row['currency_code_alpha']);
191  $payment->setUserId($row['user_id']);
192  $payment->setAssocId($row['assoc_id']);
193  $payment->setPayMethodPluginName($row['payment_method_plugin_name']);
194 
195  return $payment;
196  }
197 }
198 
199 
OMPCompletedPaymentDAO\getById
getById($completedPaymentId, $contextId=null)
Definition: OMPCompletedPaymentDAO.inc.php:28
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
OMPCompletedPaymentDAO
Operations for retrieving and querying past payments.
Definition: OMPCompletedPaymentDAO.inc.php:21
OMPCompletedPaymentDAO\hasPaidPurchaseFile
hasPaidPurchaseFile($userId, $fileIdAndRevision)
Definition: OMPCompletedPaymentDAO.inc.php:120
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
OMPCompletedPaymentDAO\updateObject
updateObject($completedPayment)
Definition: OMPCompletedPaymentDAO.inc.php:76
DAO\datetimeFromDB
datetimeFromDB($dt)
Definition: DAO.inc.php:319
CompletedPayment
Class describing a completed payment.
Definition: CompletedPayment.inc.php:19
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
DAO\datetimeToDB
datetimeToDB($dt)
Definition: DAO.inc.php:299
DAO\_getInsertId
_getInsertId($table='', $id='')
Definition: DAO.inc.php:255
OMPCompletedPaymentDAO\newDataObject
newDataObject()
Definition: OMPCompletedPaymentDAO.inc.php:174
Core\getCurrentDate
static getCurrentDate($ts=null)
Definition: Core.inc.php:63
OMPCompletedPaymentDAO\getByContextId
getByContextId($contextId, $rangeInfo=null)
Definition: OMPCompletedPaymentDAO.inc.php:144
OMPCompletedPaymentDAO\getByUserId
getByUserId($userId, $rangeInfo=null)
Definition: OMPCompletedPaymentDAO.inc.php:159
OMPCompletedPaymentDAO\getInsertId
getInsertId()
Definition: OMPCompletedPaymentDAO.inc.php:111
OMPCompletedPaymentDAO\insertCompletedPayment
insertCompletedPayment($completedPayment)
Definition: OMPCompletedPaymentDAO.inc.php:50
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31
OMPCompletedPaymentDAO\_fromRow
_fromRow($row)
Definition: OMPCompletedPaymentDAO.inc.php:183