PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.13.1
GiveWP – Donation Plugin and Fundraising Platform v2.13.1
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Tracking / TrackingData / DonationData.php
DonationData.php
110 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Give\Tracking\TrackingData;
3
4 use Give\Framework\Database\DB;
5 use Give\Tracking\Contracts\TrackData;
6 use Give\Tracking\Helpers\DonationStatuses;
7
8 /**
9 * Class DonationData
10 *
11 * Represents donation data.
12 *
13 * @package Give\Tracking\TrackingData
14 *
15 * @since 2.10.0
16 */
17 class DonationData implements TrackData {
18 private $donationStatuses;
19
20 /**
21 * DonationData constructor.
22 */
23 public function __construct() {
24 $this->donationStatuses = DonationStatuses::getCompletedDonationsStatues( true );
25 }
26
27 /**
28 * @inheritdoc
29 * @return array|void
30 */
31 public function get() {
32 return [
33 'first_donation_date' => $this->getFirstDonationDate(),
34 'last_donation_date' => $this->getLastDonationDate(),
35 'revenue' => $this->getRevenueTillNow(),
36 ];
37 }
38
39 /**
40 * Get first donation date.
41 *
42 * @since 2.10.0
43 * @return string
44 */
45 private function getFirstDonationDate() {
46 global $wpdb;
47
48 $date = DB::get_var(
49 "
50 SELECT post_date_gmt
51 FROM {$wpdb->posts} as p
52 INNER JOIN {$wpdb->donationmeta} as dm ON p.id=dm.donation_id
53 WHERE post_status IN ({$this->donationStatuses})
54 AND dm.meta_key='_give_payment_mode'
55 AND dm.meta_value='live'
56 ORDER BY post_date_gmt ASC
57 LIMIT 1
58 "
59 );
60
61 return $date ? strtotime( $date ) : '';
62 }
63
64 /**
65 * Get last donation date.
66 *
67 * @since 2.10.0
68 * @return string
69 */
70 private function getLastDonationDate() {
71 global $wpdb;
72
73 $date = DB::get_var(
74 "
75 SELECT post_date_gmt
76 FROM {$wpdb->posts} as p
77 INNER JOIN {$wpdb->donationmeta} as dm ON p.id=dm.donation_id
78 WHERE post_status IN ({$this->donationStatuses})
79 AND dm.meta_key='_give_payment_mode'
80 AND dm.meta_value='live'
81 ORDER BY post_date_gmt DESC
82 LIMIT 1
83 "
84 );
85
86 return $date ? strtotime( $date ) : '';
87 }
88
89 /**
90 * Returns revenue till current date.
91 *
92 * @since 2.10.0
93 * @return int
94 */
95 public function getRevenueTillNow() {
96 global $wpdb;
97
98 $result = (int) DB::get_var(
99 "
100 SELECT SUM(r.amount)
101 FROM {$wpdb->give_revenue} as r
102 INNER JOIN {$wpdb->donationmeta} as dm ON r.donation_id=dm.donation_id
103 WHERE dm.meta_key='_give_payment_mode'
104 AND dm.meta_value='live'
105 "
106 );
107 return $result ?: 0;
108 }
109 }
110