Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
OJSCompletedPaymentDAO.inc.php
1 <?php
2 
18 import('classes.payment.ojs.OJSCompletedPayment');
19 
20 class OJSCompletedPaymentDAO extends DAO {
27  function getCompletedPayment($completedPaymentId, $journalId = null) {
28  $params = array((int) $completedPaymentId);
29  if ($journalId) $params[] = (int) $journalId;
30 
31  $result = $this->retrieve(
32  'SELECT * FROM completed_payments WHERE completed_payment_id = ?' . ($journalId?' AND journal_id = ?':''),
33  $params
34  );
35 
36  $returner = null;
37  if ($result->RecordCount() != 0) {
38  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
39  }
40 
41  $result->Close();
42  return $returner;
43  }
44 
49  function insertCompletedPayment(&$completedPayment) {
50  $this->update(
51  sprintf('INSERT INTO completed_payments
52  (timestamp, payment_type, journal_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->getJournalId(),
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  journal_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->getJournalId(),
94  (int) $completedPayment->getUserId(),
95  (int) $completedPayment->getAssocId(),
96  $completedPayment->getAmount(),
97  $completedPayment->getCurrencyCode(),
98  $completedPayment->getPayMethodPluginName(),
99  (int) $completedPayment->getCompletedPaymentId()
100  )
101  );
102 
103  return $returner;
104  }
105 
110  function getInsertId() {
111  return $this->_getInsertId('completed_payments', 'completed_payment_id');
112  }
113 
119  function hasPaidPurchaseArticle ($userId, $articleId) {
120  $result = $this->retrieve(
121  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
122  array(
123  PAYMENT_TYPE_PURCHASE_ARTICLE,
124  (int) $userId,
125  (int) $articleId
126  )
127  );
128 
129  $returner = false;
130  if (isset($result->fields[0]) && $result->fields[0] != 0) {
131  $returner = true;
132  }
133 
134  $result->Close();
135  return $returner;
136  }
137 
143  function hasPaidPurchaseIssue ($userId, $issueId) {
144  $result = $this->retrieve(
145  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
146  array(
147  PAYMENT_TYPE_PURCHASE_ISSUE,
148  (int) $userId,
149  (int) $issueId
150  )
151  );
152 
153  $returner = false;
154  if (isset($result->fields[0]) && $result->fields[0] != 0) {
155  $returner = true;
156  }
157 
158  $result->Close();
159  return $returner;
160  }
161 
168  function hasPaidSubmission ( $journalId, $articleId ) {
169  $result = $this->retrieve(
170  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
171  array(
172  (int) PAYMENT_TYPE_SUBMISSION,
173  (int) $journalId,
174  (int) $articleId
175  )
176  );
177 
178  $returner = false;
179  if (isset($result->fields[0]) && $result->fields[0] != 0) {
180  $returner = true;
181  }
182 
183  $result->Close();
184  return $returner;
185  }
186 
193  function &getSubmissionCompletedPayment ($journalId, $articleId) {
194  $result = $this->retrieve(
195  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
196  array(
197  (int) PAYMENT_TYPE_SUBMISSION,
198  (int) $journalId,
199  (int) $articleId
200  )
201  );
202 
203  $returner = null;
204  if ($result->RecordCount() != 0) {
205  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
206  }
207 
208  $result->Close();
209  return $returner;
210  }
211 
218  function hasPaidFastTrack ( $journalId, $articleId ) {
219  $result = $this->retrieve(
220  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
221  array(
222  (int) PAYMENT_TYPE_FASTTRACK,
223  (int) $journalId,
224  (int) $articleId
225  )
226  );
227 
228  $returner = false;
229  if (isset($result->fields[0]) && $result->fields[0] != 0)
230  $returner = true;
231 
232  $result->Close();
233  return $returner;
234  }
235 
242  function getFastTrackCompletedPayment ($journalId, $articleId) {
243  $result = $this->retrieve(
244  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
245  array(
246  (int) PAYMENT_TYPE_FASTTRACK,
247  (int) $journalId,
248  (int) $articleId
249  )
250  );
251 
252  $returner = null;
253  if ($result->RecordCount() != 0) {
254  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
255  }
256 
257  $result->Close();
258  return $returner;
259  }
260 
266  function hasPaidPublication ($journalId, $articleId) {
267  $result = $this->retrieve(
268  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
269  array(
270  (int) PAYMENT_TYPE_PUBLICATION,
271  (int) $journalId,
272  (int) $articleId
273  )
274  );
275 
276  $returner = (isset($result->fields[0]) && $result->fields[0] != 0) ;
277  $result->Close();
278  return $returner;
279  }
280 
287  function getPublicationCompletedPayment ($journalId, $articleId) {
288  $result = $this->retrieve(
289  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
290  array(
291  (int) PAYMENT_TYPE_PUBLICATION,
292  (int) $journalId,
293  (int) $articleId
294  )
295  );
296 
297  $returner = null;
298  if ($result->RecordCount() != 0) {
299  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
300  }
301 
302  $result->Close();
303  return $returner;
304  }
305 
311  function getPaymentsByJournalId($journalId, $rangeInfo = null) {
312  $result = $this->retrieveRange(
313  'SELECT * FROM completed_payments WHERE journal_id = ? ORDER BY timestamp DESC',
314  (int) $journalId,
315  $rangeInfo
316  );
317 
318  return new DAOResultFactory($result, $this, '_returnPaymentFromRow');
319  }
320 
326  function &getByUserId($userId, $rangeInfo = null) {
327  $result =& $this->retrieveRange(
328  'SELECT * FROM completed_payments WHERE user_id = ? ORDER BY timestamp DESC',
329  (int) $userId,
330  $rangeInfo
331  );
332 
333  $returner = new DAOResultFactory($result, $this, '_returnPaymentFromRow');
334  return $returner;
335  }
336 
341  function newDataObject() {
342  return new OJSCompletedPayment();
343  }
344 
350  function &_returnPaymentFromRow($row) {
351  $payment = $this->newDataObject();
352  $payment->setTimestamp($this->datetimeFromDB($row['timestamp']));
353  $payment->setId($row['completed_payment_id']);
354  $payment->setType($row['payment_type']);
355  $payment->setJournalId($row['journal_id']);
356  $payment->setAmount($row['amount']);
357  $payment->setCurrencyCode($row['currency_code_alpha']);
358  $payment->setUserId($row['user_id']);
359  $payment->setAssocId($row['assoc_id']);
360  $payment->setPayMethodPluginName($row['payment_method_plugin_name']);
361 
362  return $payment;
363  }
364 }
365 
366 ?>
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
getCompletedPayment($completedPaymentId, $journalId=null)
getPaymentsByJournalId($journalId, $rangeInfo=null)
Class describing a payment ready to be in the database.
& getSubmissionCompletedPayment($journalId, $articleId)
hasPaidPurchaseArticle($userId, $articleId)
getFastTrackCompletedPayment($journalId, $articleId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
hasPaidSubmission($journalId, $articleId)
getPublicationCompletedPayment($journalId, $articleId)
datetimeFromDB($dt)
Definition: DAO.inc.php:313
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
hasPaidPublication($journalId, $articleId)
Operations for retrieving and querying past payments.
datetimeToDB($dt)
Definition: DAO.inc.php:293
insertCompletedPayment(&$completedPayment)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
hasPaidFastTrack($journalId, $articleId)
& getByUserId($userId, $rangeInfo=null)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95