Open Journal Systems  3.3.0
OJSCompletedPaymentDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.payment.CompletedPayment');
19 
20 class OJSCompletedPaymentDAO extends DAO {
27  function getById($completedPaymentId, $contextId = null) {
28  $params = array((int) $completedPaymentId);
29  if ($contextId) $params[] = (int) $contextId;
30 
31  $result = $this->retrieve(
32  'SELECT * FROM completed_payments WHERE completed_payment_id = ?' . ($contextId?' AND context_id = ?':''),
33  $params
34  );
35 
36  $returner = null;
37  if ($result->RecordCount() != 0) {
38  $returner = $this->_fromRow($result->GetRowAssoc(false));
39  }
40 
41  $result->Close();
42  return $returner;
43  }
44 
49  function insertObject($completedPayment) {
50  $this->update(
51  sprintf('INSERT INTO completed_payments
52  (timestamp, payment_type, context_id, user_id, assoc_id, amount, currency_code_alpha, payment_method_plugin_name)
53  VALUES
54  (%s, ?, ?, ?, ?, ?, ?, ?)',
56  array(
57  (int) $completedPayment->getType(),
58  (int) $completedPayment->getContextId(),
59  (int) $completedPayment->getUserId(),
60  (int) $completedPayment->getAssocId(),
61  $completedPayment->getAmount(),
62  $completedPayment->getCurrencyCode(),
63  $completedPayment->getPayMethodPluginName()
64  )
65  );
66 
67  return $this->getInsertId();
68  }
69 
75  function updateObject($completedPayment) {
76  $returner = false;
77 
78  $returner = $this->update(
79  sprintf('UPDATE completed_payments
80  SET
81  timestamp = %s,
82  payment_type = ?,
83  context_id = ?,
84  user_id = ?,
85  assoc_id = ?,
86  amount = ?,
87  currency_code_alpha = ?,
88  payment_method_plugin_name = ?
89  WHERE completed_payment_id = ?',
90  $this->datetimeToDB($completedPayment->getTimestamp())),
91  array(
92  (int) $completedPayment->getType(),
93  (int) $completedPayment->getContextId(),
94  (int) $completedPayment->getUserId(),
95  (int) $completedPayment->getAssocId(),
96  $completedPayment->getAmount(),
97  $completedPayment->getCurrencyCode(),
98  $completedPayment->getPayMethodPluginName(),
99  (int) $completedPayment->getId()
100  )
101  );
102 
103  return $returner;
104  }
105 
110  function getInsertId() {
111  return $this->_getInsertId('completed_payments', 'completed_payment_id');
112  }
113 
121  function getByAssoc($userId = null, $paymentType = null, $assocId = null) {
122  $params = array();
123  if ($userId) $params[] = (int) $userId;
124  if ($paymentType) $params[] = (int) $paymentType;
125  if ($assocId) $params[] = (int) $assocId;
126  $result = $this->retrieve(
127  'SELECT * FROM completed_payments WHERE 1=1' .
128  ($userId?' AND user_id = ?':'') .
129  ($paymentType?' AND payment_type = ?':'') .
130  ($assocId?' AND assoc_id = ?':''),
131  $params
132  );
133 
134  $returner = null;
135  if (isset($result->fields[0]) && $result->fields[0] != 0) {
136  $returner = $this->_fromRow($result->fields);
137  }
138 
139  $result->Close();
140  return $returner;
141  }
142 
148  function hasPaidPurchaseArticle($userId, $articleId) {
149  return $this->getByAssoc($userId, PAYMENT_TYPE_PURCHASE_ARTICLE, $articleId)?true:false;
150  }
151 
157  function hasPaidPurchaseIssue($userId, $issueId) {
158  return $this->getByAssoc($userId, PAYMENT_TYPE_PURCHASE_ISSUE, $issueId)?true:false;
159  }
160 
166  function hasPaidPublication($userId, $articleId) {
167  return $this->getByAssoc($userId, PAYMENT_TYPE_PUBLICATION, $articleId)?true:false;
168  }
169 
175  function getByContextId($contextId, $rangeInfo = null) {
176  $result = $this->retrieveRange(
177  'SELECT * FROM completed_payments WHERE context_id = ? ORDER BY timestamp DESC',
178  (int) $contextId,
179  $rangeInfo
180  );
181 
182  $returner = array();
183  while (!$result->EOF) {
184  $payment = $this->_fromRow($result->fields);
185  $returner[$payment->getId()] = $payment;
186  $result->MoveNext();
187  }
188  return $returner;
189  }
190 
197  function getByUserId($userId, $rangeInfo = null) {
198  $result = $this->retrieveRange(
199  'SELECT * FROM completed_payments WHERE user_id = ? ORDER BY timestamp DESC',
200  (int) $userId,
201  $rangeInfo
202  );
203 
204  return new DAOResultFactory($result, $this, '_fromRow');
205  }
206 
211  function newDataObject() {
212  return new CompletedPayment();
213  }
214 
220  function _fromRow($row) {
221  $payment = $this->newDataObject();
222  $payment->setTimestamp($this->datetimeFromDB($row['timestamp']));
223  $payment->setId($row['completed_payment_id']);
224  $payment->setType($row['payment_type']);
225  $payment->setContextId($row['context_id']);
226  $payment->setAmount($row['amount']);
227  $payment->setCurrencyCode($row['currency_code_alpha']);
228  $payment->setUserId($row['user_id']);
229  $payment->setAssocId($row['assoc_id']);
230  $payment->setPayMethodPluginName($row['payment_method_plugin_name']);
231 
232  return $payment;
233  }
234 }
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
OJSCompletedPaymentDAO\getInsertId
getInsertId()
Definition: OJSCompletedPaymentDAO.inc.php:110
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
OJSCompletedPaymentDAO\hasPaidPurchaseArticle
hasPaidPurchaseArticle($userId, $articleId)
Definition: OJSCompletedPaymentDAO.inc.php:148
OJSCompletedPaymentDAO\_fromRow
_fromRow($row)
Definition: OJSCompletedPaymentDAO.inc.php:220
OJSCompletedPaymentDAO\newDataObject
newDataObject()
Definition: OJSCompletedPaymentDAO.inc.php:211
OJSCompletedPaymentDAO\hasPaidPurchaseIssue
hasPaidPurchaseIssue($userId, $issueId)
Definition: OJSCompletedPaymentDAO.inc.php:157
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
OJSCompletedPaymentDAO\getByUserId
getByUserId($userId, $rangeInfo=null)
Definition: OJSCompletedPaymentDAO.inc.php:197
OJSCompletedPaymentDAO\insertObject
insertObject($completedPayment)
Definition: OJSCompletedPaymentDAO.inc.php:49
OJSCompletedPaymentDAO\getByContextId
getByContextId($contextId, $rangeInfo=null)
Definition: OJSCompletedPaymentDAO.inc.php:175
DAO\datetimeFromDB
datetimeFromDB($dt)
Definition: DAO.inc.php:319
OJSCompletedPaymentDAO\getByAssoc
getByAssoc($userId=null, $paymentType=null, $assocId=null)
Definition: OJSCompletedPaymentDAO.inc.php:121
CompletedPayment
Class describing a completed payment.
Definition: CompletedPayment.inc.php:19
OJSCompletedPaymentDAO\getById
getById($completedPaymentId, $contextId=null)
Definition: OJSCompletedPaymentDAO.inc.php:27
OJSCompletedPaymentDAO\updateObject
updateObject($completedPayment)
Definition: OJSCompletedPaymentDAO.inc.php:75
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
Core\getCurrentDate
static getCurrentDate($ts=null)
Definition: Core.inc.php:63
OJSCompletedPaymentDAO
Operations for retrieving and querying past payments.
Definition: OJSCompletedPaymentDAO.inc.php:20
OJSCompletedPaymentDAO\hasPaidPublication
hasPaidPublication($userId, $articleId)
Definition: OJSCompletedPaymentDAO.inc.php:166
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31