00001 <?php
00002
00017 class OJSCompletedPaymentDAO extends DAO {
00023 function &getCompletedPayment($completedPaymentId) {
00024 $result = &$this->retrieve(
00025 'SELECT * FROM completed_payments WHERE completed_payment_id = ?', $completedPaymentId
00026 );
00027
00028 $returner = null;
00029 if ($result->RecordCount() != 0) {
00030 $returner = &$this->_returnPaymentFromRow($result->GetRowAssoc(false));
00031 }
00032
00033 $result->Close();
00034 unset($result);
00035 return $returner;
00036 }
00037
00042 function insertCompletedPayment(&$completedPayment) {
00043 $this->update(
00044 sprintf('INSERT INTO completed_payments
00045 (timestamp, payment_type, journal_id, user_id, assoc_id, amount, currency_code_alpha, payment_method_plugin_name)
00046 VALUES
00047 (%s, ?, ?, ?, ?, ?, ?, ?)',
00048 $this->datetimeToDB(Core::getCurrentDate())),
00049 array(
00050 $completedPayment->getType(),
00051 $completedPayment->getJournalId(),
00052 $completedPayment->getUserId(),
00053 $completedPayment->getAssocId(),
00054 $completedPayment->getAmount(),
00055 $completedPayment->getCurrencyCode(),
00056 $completedPayment->getPayMethodPluginName()
00057 )
00058 );
00059
00060 return $this->getInsertCompletedPaymentId();
00061 }
00062
00067 function getInsertCompletedPaymentId() {
00068 return $this->getInsertId('completed_payments', 'completed_payment_id');
00069 }
00070
00076 function hasPaidPerViewArticle ( $userId, $articleId ) {
00077 $result =& $this->retrieve(
00078 'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND user_id = ? AND assoc_id = ?',
00079 array(PAYMENT_TYPE_PURCHASE_ARTICLE,
00080 $userId,
00081 $articleId )
00082 );
00083
00084 $returner = false;
00085 if (isset($result->fields[0]) && $result->fields[0] != 0) {
00086 $returner = true;
00087 }
00088
00089 $result->Close();
00090 return $returner;
00091 }
00092
00099 function hasPaidSubmission ( $journalId, $articleId ) {
00100 $result =& $this->retrieve(
00101 'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
00102 array(
00103 PAYMENT_TYPE_SUBMISSION,
00104 $journalId,
00105 $articleId
00106 )
00107 );
00108
00109 $returner = false;
00110 if (isset($result->fields[0]) && $result->fields[0] != 0) {
00111 $returner = true;
00112 }
00113
00114 $result->Close();
00115 return $returner;
00116 }
00117
00124 function &getSubmissionCompletedPayment ( $journalId, $articleId ) {
00125 $result =& $this->retrieve(
00126 'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
00127 array(
00128 PAYMENT_TYPE_SUBMISSION,
00129 $journalId,
00130 $articleId
00131 )
00132 );
00133
00134 $returner = null;
00135 if ($result->RecordCount() != 0) {
00136 $returner = &$this->_returnPaymentFromRow($result->GetRowAssoc(false));
00137 }
00138
00139 $result->Close();
00140 unset($result);
00141 return $returner;
00142 }
00143
00150 function hasPaidFastTrack ( $journalId, $articleId ) {
00151 $result =& $this->retrieve(
00152 'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
00153 array(
00154 PAYMENT_TYPE_FASTTRACK,
00155 $journalId,
00156 $articleId
00157 )
00158 );
00159
00160 $returner = false;
00161 if (isset($result->fields[0]) && $result->fields[0] != 0)
00162 $returner = true;
00163
00164 $result->Close();
00165 return $returner;
00166 }
00167
00174 function getFastTrackCompletedPayment ( $journalId, $articleId ) {
00175 $result =& $this->retrieve(
00176 'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
00177 array(
00178 PAYMENT_TYPE_FASTTRACK,
00179 $journalId,
00180 $articleId
00181 )
00182 );
00183
00184 $returner = null;
00185 if ($result->RecordCount() != 0) {
00186 $returner = &$this->_returnPaymentFromRow($result->GetRowAssoc(false));
00187 }
00188
00189 $result->Close();
00190 unset($result);
00191 return $returner;
00192 }
00193
00199 function hasPaidPublication ( $journalId, $articleId ) {
00200 $result =& $this->retrieve(
00201 'SELECT count(*) FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
00202 array(
00203 PAYMENT_TYPE_PUBLICATION,
00204 $journalId,
00205 $articleId
00206 )
00207 );
00208
00209 $returner = (isset($result->fields[0]) && $result->fields[0] != 0) ;
00210 $result->Close();
00211 return $returner;
00212 }
00213
00220 function getPublicationCompletedPayment ( $journalId, $articleId ) {
00221 $result =& $this->retrieve(
00222 'SELECT * FROM completed_payments WHERE payment_type = ? AND journal_id = ? AND assoc_id = ?',
00223 array(
00224 PAYMENT_TYPE_PUBLICATION,
00225 $journalId,
00226 $articleId
00227 )
00228 );
00229
00230 $returner = null;
00231 if ($result->RecordCount() != 0) {
00232 $returner = &$this->_returnPaymentFromRow($result->GetRowAssoc(false));
00233 }
00234
00235 $result->Close();
00236 unset($result);
00237 return $returner;
00238 }
00239
00245 function &getPaymentsByJournalId($journalId, $rangeInfo = null) {
00246 $result = &$this->retrieveRange(
00247 'SELECT * FROM completed_payments WHERE journal_id = ? ORDER BY timestamp DESC', $journalId, $rangeInfo
00248 );
00249
00250 $returner = &new DAOResultFactory($result, $this, '_returnPaymentFromRow');
00251 return $returner;
00252 }
00253
00259 function &_returnPaymentFromRow(&$row) {
00260 import('payment.ojs.OJSCompletedPayment');
00261
00262 $payment = &new OJSCompletedPayment();
00263 $payment->setTimestamp($this->datetimeFromDB($row['timestamp']));
00264 $payment->setPaymentId($row['completed_payment_id']);
00265 $payment->setType($row['payment_type']);
00266 $payment->setJournalId($row['journal_id']);
00267 $payment->setAmount($row['amount']);
00268 $payment->setCurrencyCode($row['currency_code_alpha']);
00269 $payment->setUserId($row['user_id']);
00270 $payment->setAssocId($row['assoc_id']);
00271 $payment->setPayMethodPluginName($row['payment_method_plugin_name']);
00272
00273 return $payment;
00274 }
00275
00276 }
00277
00278 ?>