Open Journal Systems  2.4.8
 All Classes 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  unset($result);
43  return $returner;
44  }
45 
50  function insertCompletedPayment(&$completedPayment) {
51  $this->update(
52  sprintf('INSERT INTO completed_payments
53  (timestamp, payment_type, journal_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->getJournalId(),
60  (int) $completedPayment->getUserId(),
61  (int) $completedPayment->getAssocId(),
62  $completedPayment->getAmount(),
63  $completedPayment->getCurrencyCode(),
64  $completedPayment->getPayMethodPluginName()
65  )
66  );
67 
68  return $this->getInsertCompletedPaymentId();
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  journal_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->getJournalId(),
95  (int) $completedPayment->getUserId(),
96  (int) $completedPayment->getAssocId(),
97  $completedPayment->getAmount(),
98  $completedPayment->getCurrencyCode(),
99  $completedPayment->getPayMethodPluginName(),
100  (int) $completedPayment->getCompletedPaymentId()
101  )
102  );
103 
104  return $returner;
105  }
106 
112  return $this->getInsertId('completed_payments', 'completed_payment_id');
113  }
114 
120  function hasPaidPurchaseArticle ($userId, $articleId) {
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_ARTICLE,
125  (int) $userId,
126  (int) $articleId
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 hasPaidPurchaseIssue ($userId, $issueId) {
145  $result =& $this->retrieve(
146  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
147  array(
148  PAYMENT_TYPE_PURCHASE_ISSUE,
149  (int) $userId,
150  (int) $issueId
151  )
152  );
153 
154  $returner = false;
155  if (isset($result->fields[0]) && $result->fields[0] != 0) {
156  $returner = true;
157  }
158 
159  $result->Close();
160  return $returner;
161  }
162 
169  function hasPaidSubmission ( $journalId, $articleId ) {
170  $result =& $this->retrieve(
171  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
172  array(
173  (int) PAYMENT_TYPE_SUBMISSION,
174  (int) $journalId,
175  (int) $articleId
176  )
177  );
178 
179  $returner = false;
180  if (isset($result->fields[0]) && $result->fields[0] != 0) {
181  $returner = true;
182  }
183 
184  $result->Close();
185  return $returner;
186  }
187 
194  function &getSubmissionCompletedPayment ($journalId, $articleId) {
195  $result =& $this->retrieve(
196  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
197  array(
198  (int) PAYMENT_TYPE_SUBMISSION,
199  (int) $journalId,
200  (int) $articleId
201  )
202  );
203 
204  $returner = null;
205  if ($result->RecordCount() != 0) {
206  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
207  }
208 
209  $result->Close();
210  unset($result);
211  return $returner;
212  }
213 
220  function hasPaidFastTrack ( $journalId, $articleId ) {
221  $result =& $this->retrieve(
222  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
223  array(
224  (int) PAYMENT_TYPE_FASTTRACK,
225  (int) $journalId,
226  (int) $articleId
227  )
228  );
229 
230  $returner = false;
231  if (isset($result->fields[0]) && $result->fields[0] != 0)
232  $returner = true;
233 
234  $result->Close();
235  return $returner;
236  }
237 
244  function getFastTrackCompletedPayment ($journalId, $articleId) {
245  $result =& $this->retrieve(
246  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
247  array(
248  (int) PAYMENT_TYPE_FASTTRACK,
249  (int) $journalId,
250  (int) $articleId
251  )
252  );
253 
254  $returner = null;
255  if ($result->RecordCount() != 0) {
256  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
257  }
258 
259  $result->Close();
260  unset($result);
261  return $returner;
262  }
263 
269  function hasPaidPublication ($journalId, $articleId) {
270  $result =& $this->retrieve(
271  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
272  array(
273  (int) PAYMENT_TYPE_PUBLICATION,
274  (int) $journalId,
275  (int) $articleId
276  )
277  );
278 
279  $returner = (isset($result->fields[0]) && $result->fields[0] != 0) ;
280  $result->Close();
281  return $returner;
282  }
283 
290  function getPublicationCompletedPayment ($journalId, $articleId) {
291  $result =& $this->retrieve(
292  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
293  array(
294  (int) PAYMENT_TYPE_PUBLICATION,
295  (int) $journalId,
296  (int) $articleId
297  )
298  );
299 
300  $returner = null;
301  if ($result->RecordCount() != 0) {
302  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
303  }
304 
305  $result->Close();
306  unset($result);
307  return $returner;
308  }
309 
315  function &getPaymentsByJournalId($journalId, $rangeInfo = null) {
316  $result =& $this->retrieveRange(
317  'SELECT * FROM completed_payments WHERE journal_id = ? ORDER BY timestamp DESC',
318  (int) $journalId,
319  $rangeInfo
320  );
321 
322  $returner = new DAOResultFactory($result, $this, '_returnPaymentFromRow');
323  return $returner;
324  }
325 
331  function &getByUserId($userId, $rangeInfo = null) {
332  $result =& $this->retrieveRange(
333  'SELECT * FROM completed_payments WHERE user_id = ? ORDER BY timestamp DESC',
334  (int) $userId,
335  $rangeInfo
336  );
337 
338  $returner = new DAOResultFactory($result, $this, '_returnPaymentFromRow');
339  return $returner;
340  }
341 
346  function newDataObject() {
347  return new OJSCompletedPayment();
348  }
349 
355  function &_returnPaymentFromRow(&$row) {
356  $payment = $this->newDataObject();
357  $payment->setTimestamp($this->datetimeFromDB($row['timestamp']));
358  $payment->setPaymentId($row['completed_payment_id']);
359  $payment->setType($row['payment_type']);
360  $payment->setJournalId($row['journal_id']);
361  $payment->setAmount($row['amount']);
362  $payment->setCurrencyCode($row['currency_code_alpha']);
363  $payment->setUserId($row['user_id']);
364  $payment->setAssocId($row['assoc_id']);
365  $payment->setPayMethodPluginName($row['payment_method_plugin_name']);
366 
367  return $payment;
368  }
369 }
370 
371 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
Class describing a payment ready to be in the database.
& getCompletedPayment($completedPaymentId, $journalId=null)
& getSubmissionCompletedPayment($journalId, $articleId)
getCurrentDate($ts=null)
Definition: Core.inc.php:94
hasPaidPurchaseArticle($userId, $articleId)
getFastTrackCompletedPayment($journalId, $articleId)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
hasPaidSubmission($journalId, $articleId)
getPublicationCompletedPayment($journalId, $articleId)
datetimeFromDB($dt)
Definition: DAO.inc.php:316
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
hasPaidPublication($journalId, $articleId)
& getPaymentsByJournalId($journalId, $rangeInfo=null)
Operations for retrieving and querying past payments.
datetimeToDB($dt)
Definition: DAO.inc.php:296
insertCompletedPayment(&$completedPayment)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
hasPaidFastTrack($journalId, $articleId)
& getByUserId($userId, $rangeInfo=null)