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