Open Journal Systems  3.0.0
 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  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 
74  function getInsertId() {
75  return $this->_getInsertId('completed_payments', 'completed_payment_id');
76  }
77 
83  function hasPaidPurchaseArticle ($userId, $articleId) {
84  $result = $this->retrieve(
85  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
86  array(
87  PAYMENT_TYPE_PURCHASE_ARTICLE,
88  (int) $userId,
89  (int) $articleId
90  )
91  );
92 
93  $returner = false;
94  if (isset($result->fields[0]) && $result->fields[0] != 0) {
95  $returner = true;
96  }
97 
98  $result->Close();
99  return $returner;
100  }
101 
107  function hasPaidPurchaseIssue ($userId, $issueId) {
108  $result = $this->retrieve(
109  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
110  array(
111  PAYMENT_TYPE_PURCHASE_ISSUE,
112  (int) $userId,
113  (int) $issueId
114  )
115  );
116 
117  $returner = false;
118  if (isset($result->fields[0]) && $result->fields[0] != 0) {
119  $returner = true;
120  }
121 
122  $result->Close();
123  return $returner;
124  }
125 
132  function hasPaidSubmission ( $journalId, $articleId ) {
133  $result = $this->retrieve(
134  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
135  array(
136  (int) PAYMENT_TYPE_SUBMISSION,
137  (int) $journalId,
138  (int) $articleId
139  )
140  );
141 
142  $returner = false;
143  if (isset($result->fields[0]) && $result->fields[0] != 0) {
144  $returner = true;
145  }
146 
147  $result->Close();
148  return $returner;
149  }
150 
157  function &getSubmissionCompletedPayment ($journalId, $articleId) {
158  $result = $this->retrieve(
159  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
160  array(
161  (int) PAYMENT_TYPE_SUBMISSION,
162  (int) $journalId,
163  (int) $articleId
164  )
165  );
166 
167  $returner = null;
168  if ($result->RecordCount() != 0) {
169  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
170  }
171 
172  $result->Close();
173  return $returner;
174  }
175 
182  function hasPaidFastTrack ( $journalId, $articleId ) {
183  $result = $this->retrieve(
184  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
185  array(
186  (int) PAYMENT_TYPE_FASTTRACK,
187  (int) $journalId,
188  (int) $articleId
189  )
190  );
191 
192  $returner = false;
193  if (isset($result->fields[0]) && $result->fields[0] != 0)
194  $returner = true;
195 
196  $result->Close();
197  return $returner;
198  }
199 
206  function getFastTrackCompletedPayment ($journalId, $articleId) {
207  $result = $this->retrieve(
208  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
209  array(
210  (int) PAYMENT_TYPE_FASTTRACK,
211  (int) $journalId,
212  (int) $articleId
213  )
214  );
215 
216  $returner = null;
217  if ($result->RecordCount() != 0) {
218  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
219  }
220 
221  $result->Close();
222  return $returner;
223  }
224 
230  function hasPaidPublication ($journalId, $articleId) {
231  $result = $this->retrieve(
232  'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
233  array(
234  (int) PAYMENT_TYPE_PUBLICATION,
235  (int) $journalId,
236  (int) $articleId
237  )
238  );
239 
240  $returner = (isset($result->fields[0]) && $result->fields[0] != 0) ;
241  $result->Close();
242  return $returner;
243  }
244 
251  function getPublicationCompletedPayment ($journalId, $articleId) {
252  $result = $this->retrieve(
253  'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
254  array(
255  (int) PAYMENT_TYPE_PUBLICATION,
256  (int) $journalId,
257  (int) $articleId
258  )
259  );
260 
261  $returner = null;
262  if ($result->RecordCount() != 0) {
263  $returner =& $this->_returnPaymentFromRow($result->GetRowAssoc(false));
264  }
265 
266  $result->Close();
267  return $returner;
268  }
269 
275  function getPaymentsByJournalId($journalId, $rangeInfo = null) {
276  $result = $this->retrieveRange(
277  'SELECT * FROM completed_payments WHERE journal_id = ? ORDER BY timestamp DESC',
278  (int) $journalId,
279  $rangeInfo
280  );
281 
282  return new DAOResultFactory($result, $this, '_returnPaymentFromRow');
283  }
284 
289  function newDataObject() {
290  return new OJSCompletedPayment();
291  }
292 
298  function &_returnPaymentFromRow($row) {
299  $payment = $this->newDataObject();
300  $payment->setTimestamp($this->datetimeFromDB($row['timestamp']));
301  $payment->setId($row['completed_payment_id']);
302  $payment->setType($row['payment_type']);
303  $payment->setJournalId($row['journal_id']);
304  $payment->setAmount($row['amount']);
305  $payment->setCurrencyCode($row['currency_code_alpha']);
306  $payment->setUserId($row['user_id']);
307  $payment->setAssocId($row['assoc_id']);
308  $payment->setPayMethodPluginName($row['payment_method_plugin_name']);
309 
310  return $payment;
311  }
312 }
313 
314 ?>
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)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95