Open Journal Systems  2.4.4
 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  return $this->getInsertId('completed_payments', 'completed_payment_id');
77  }
78 
84  function hasPaidPurchaseArticle ($userId, $articleId) {
85  $result =& $this->retrieve(
86  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
87  array(
88  PAYMENT_TYPE_PURCHASE_ARTICLE,
89  (int) $userId,
90  (int) $articleId
91  )
92  );
93 
94  $returner = false;
95  if (isset($result->fields[0]) && $result->fields[0] != 0) {
96  $returner = true;
97  }
98 
99  $result->Close();
100  return $returner;
101  }
102 
108  function hasPaidPurchaseIssue ($userId, $issueId) {
109  $result =& $this->retrieve(
110  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
111  array(
112  PAYMENT_TYPE_PURCHASE_ISSUE,
113  (int) $userId,
114  (int) $issueId
115  )
116  );
117 
118  $returner = false;
119  if (isset($result->fields[0]) && $result->fields[0] != 0) {
120  $returner = true;
121  }
122 
123  $result->Close();
124  return $returner;
125  }
126 
133  function hasPaidSubmission ( $journalId, $articleId ) {
134  $result =& $this->retrieve(
135  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
136  array(
137  (int) PAYMENT_TYPE_SUBMISSION,
138  (int) $journalId,
139  (int) $articleId
140  )
141  );
142 
143  $returner = false;
144  if (isset($result->fields[0]) && $result->fields[0] != 0) {
145  $returner = true;
146  }
147 
148  $result->Close();
149  return $returner;
150  }
151 
158  function &getSubmissionCompletedPayment ($journalId, $articleId) {
159  $result =& $this->retrieve(
160  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
161  array(
162  (int) PAYMENT_TYPE_SUBMISSION,
163  (int) $journalId,
164  (int) $articleId
165  )
166  );
167 
168  $returner = null;
169  if ($result->RecordCount() != 0) {
170  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
171  }
172 
173  $result->Close();
174  unset($result);
175  return $returner;
176  }
177 
184  function hasPaidFastTrack ( $journalId, $articleId ) {
185  $result =& $this->retrieve(
186  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
187  array(
188  (int) PAYMENT_TYPE_FASTTRACK,
189  (int) $journalId,
190  (int) $articleId
191  )
192  );
193 
194  $returner = false;
195  if (isset($result->fields[0]) && $result->fields[0] != 0)
196  $returner = true;
197 
198  $result->Close();
199  return $returner;
200  }
201 
208  function getFastTrackCompletedPayment ($journalId, $articleId) {
209  $result =& $this->retrieve(
210  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
211  array(
212  (int) PAYMENT_TYPE_FASTTRACK,
213  (int) $journalId,
214  (int) $articleId
215  )
216  );
217 
218  $returner = null;
219  if ($result->RecordCount() != 0) {
220  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
221  }
222 
223  $result->Close();
224  unset($result);
225  return $returner;
226  }
227 
233  function hasPaidPublication ($journalId, $articleId) {
234  $result =& $this->retrieve(
235  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
236  array(
237  (int) PAYMENT_TYPE_PUBLICATION,
238  (int) $journalId,
239  (int) $articleId
240  )
241  );
242 
243  $returner = (isset($result->fields[0]) && $result->fields[0] != 0) ;
244  $result->Close();
245  return $returner;
246  }
247 
254  function getPublicationCompletedPayment ($journalId, $articleId) {
255  $result =& $this->retrieve(
256  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
257  array(
258  (int) PAYMENT_TYPE_PUBLICATION,
259  (int) $journalId,
260  (int) $articleId
261  )
262  );
263 
264  $returner = null;
265  if ($result->RecordCount() != 0) {
266  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
267  }
268 
269  $result->Close();
270  unset($result);
271  return $returner;
272  }
273 
279  function &getPaymentsByJournalId($journalId, $rangeInfo = null) {
280  $result =& $this->retrieveRange(
281  'SELECT * FROM completed_payments WHERE journal_id = ? ORDER BY timestamp DESC',
282  (int) $journalId,
283  $rangeInfo
284  );
285 
286  $returner = new DAOResultFactory($result, $this, '_returnPaymentFromRow');
287  return $returner;
288  }
289 
294  function newDataObject() {
295  return new OJSCompletedPayment();
296  }
297 
303  function &_returnPaymentFromRow(&$row) {
304  $payment = $this->newDataObject();
305  $payment->setTimestamp($this->datetimeFromDB($row['timestamp']));
306  $payment->setPaymentId($row['completed_payment_id']);
307  $payment->setType($row['payment_type']);
308  $payment->setJournalId($row['journal_id']);
309  $payment->setAmount($row['amount']);
310  $payment->setCurrencyCode($row['currency_code_alpha']);
311  $payment->setUserId($row['user_id']);
312  $payment->setAssocId($row['assoc_id']);
313  $payment->setPayMethodPluginName($row['payment_method_plugin_name']);
314 
315  return $payment;
316  }
317 }
318 
319 ?>
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)