2dc1f9d8afb1e126c430102a6adfeecfeef5ef93
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\data\paid\subscription\transaction\log;
3 use wcf\data\object\type\ObjectTypeCache;
4 use wcf\data\paid\subscription\PaidSubscription;
5 use wcf\data\user\User;
6 use wcf\data\DatabaseObject;
7 use wcf\system\WCF;
8
9 /**
10 * Represents a paid subscription transaction log entry.
11 *
12 * @author Marcel Werk
13 * @copyright 2001-2016 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package com.woltlab.wcf
16 * @subpackage data.paid.subscription.transaction.log
17 * @category Community Framework
18 *
19 * @property-read integer $logID
20 * @property-read integer|null $subscriptionUserID
21 * @property-read integer|null $userID
22 * @property-read integer $subscriptionID
23 * @property-read integer $paymentMethodObjectTypeID
24 * @property-read integer $logTime
25 * @property-read string $transactionID
26 * @property-read string $transactionDetails
27 * @property-read string $logMessage
28 */
29 class PaidSubscriptionTransactionLog extends DatabaseObject {
30 /**
31 * @see \wcf\data\DatabaseObject::$databaseTableName
32 */
33 protected static $databaseTableName = 'paid_subscription_transaction_log';
34
35 /**
36 * @see \wcf\data\DatabaseObject::$databaseIndexName
37 */
38 protected static $databaseTableIndexName = 'logID';
39
40 /**
41 * user object
42 * @var \wcf\data\user\User
43 */
44 protected $user = null;
45
46 /**
47 * paid subscription object
48 * @var \wcf\data\paid\subscription\PaidSubscription
49 */
50 protected $subscription = null;
51
52 /**
53 * Returns the payment method of this transaction.
54 *
55 * @return string
56 */
57 public function getPaymentMethodName() {
58 $objectType = ObjectTypeCache::getInstance()->getObjectType($this->paymentMethodObjectTypeID);
59 return $objectType->objectType;
60 }
61
62 /**
63 * Returns transaction details.
64 *
65 * @return array
66 */
67 public function getTransactionDetails() {
68 return unserialize($this->transactionDetails);
69 }
70
71 /**
72 * Returns the user of this transaction.
73 *
74 * @return \wcf\data\user\User
75 */
76 public function getUser() {
77 if ($this->user === null) {
78 $this->user = new User($this->userID);
79 }
80
81 return $this->user;
82 }
83
84 /**
85 * Returns the paid subscription of this transaction.
86 *
87 * @return \wcf\data\paid\subscription\PaidSubscription
88 */
89 public function getSubscription() {
90 if ($this->subscription === null) {
91 $this->subscription = new PaidSubscription($this->subscriptionID);
92 }
93
94 return $this->subscription;
95 }
96
97 /**
98 * Gets a transaction log entry by transaction id.
99 *
100 * @param integer $paymentMethodObjectTypeID
101 * @param string $transactionID
102 * @return \wcf\data\paid\subscription\transaction\log\PaidSubscriptionTransactionLog
103 */
104 public static function getLogByTransactionID($paymentMethodObjectTypeID, $transactionID) {
105 $sql = "SELECT *
106 FROM wcf".WCF_N."_paid_subscription_transaction_log
107 WHERE paymentMethodObjectTypeID = ?
108 AND transactionID = ?";
109 $statement = WCF::getDB()->prepareStatement($sql);
110 $statement->execute([$paymentMethodObjectTypeID, $transactionID]);
111 $row = $statement->fetchArray();
112 if ($row !== false) {
113 return new PaidSubscriptionTransactionLog(null, $row);
114 }
115
116 return null;
117 }
118 }