61483b4b7cdf54fd920f873aefade44ac994f223
[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 WoltLabSuite\Core\Data\Paid\Subscription\Transaction\Log
16 *
17 * @property-read integer $logID unique id of the paid subscription transaction log entry
18 * @property-read integer|null $subscriptionUserID id of the paid subscription-user-association or `null` if no such association exists
19 * @property-read integer|null $userID id of the user who caused the paid subscription transaction log entry or `null` if the user does not exist anymore
20 * @property-read integer $subscriptionID id of the paid subscription
21 * @property-read integer $paymentMethodObjectTypeID id of the `com.woltlab.wcf.payment.method` object type
22 * @property-read integer $logTime timestamp at which the log has been created
23 * @property-read string $transactionID identifier of the paid subscription transaction
24 * @property-read string $transactionDetails serialized defailts of the paid subscription transaction
25 * @property-read string $logMessage log message describing the status of the paid subscription transaction
26 */
27 class PaidSubscriptionTransactionLog extends DatabaseObject {
28 /**
29 * user object
30 * @var \wcf\data\user\User
31 */
32 protected $user = null;
33
34 /**
35 * paid subscription object
36 * @var \wcf\data\paid\subscription\PaidSubscription
37 */
38 protected $subscription = null;
39
40 /**
41 * Returns the payment method of this transaction.
42 *
43 * @return string
44 */
45 public function getPaymentMethodName() {
46 $objectType = ObjectTypeCache::getInstance()->getObjectType($this->paymentMethodObjectTypeID);
47 return $objectType->objectType;
48 }
49
50 /**
51 * Returns transaction details.
52 *
53 * @return array
54 */
55 public function getTransactionDetails() {
56 return unserialize($this->transactionDetails);
57 }
58
59 /**
60 * Returns the user of this transaction.
61 *
62 * @return \wcf\data\user\User
63 */
64 public function getUser() {
65 if ($this->user === null) {
66 $this->user = new User($this->userID);
67 }
68
69 return $this->user;
70 }
71
72 /**
73 * Returns the paid subscription of this transaction.
74 *
75 * @return \wcf\data\paid\subscription\PaidSubscription
76 */
77 public function getSubscription() {
78 if ($this->subscription === null) {
79 $this->subscription = new PaidSubscription($this->subscriptionID);
80 }
81
82 return $this->subscription;
83 }
84
85 /**
86 * Returns the transaction log entry by transaction id or `null` if no such entry exists.
87 *
88 * @param integer $paymentMethodObjectTypeID
89 * @param string $transactionID
90 * @return PaidSubscriptionTransactionLog|null
91 */
92 public static function getLogByTransactionID($paymentMethodObjectTypeID, $transactionID) {
93 $sql = "SELECT *
94 FROM wcf".WCF_N."_paid_subscription_transaction_log
95 WHERE paymentMethodObjectTypeID = ?
96 AND transactionID = ?";
97 $statement = WCF::getDB()->prepareStatement($sql);
98 $statement->execute([$paymentMethodObjectTypeID, $transactionID]);
99 $row = $statement->fetchArray();
100 if ($row !== false) {
101 return new PaidSubscriptionTransactionLog(null, $row);
102 }
103
104 return null;
105 }
106 }