PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.19.6
GiveWP – Donation Plugin and Fundraising Platform v2.19.6
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 / MultiFormGoals / ProgressBar / Query.php
Query.php
72 lines 1.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\MultiFormGoals\ProgressBar;
4
5 /**
6 * Get the Total, Count, and Average of the payment totals for published donations of a given set of forms.
7 */
8 class Query
9 {
10
11 /** @var array */
12 protected $formIDs;
13
14 /**
15 * @var array $formIDs
16 */
17 public function __construct($formIDs)
18 {
19 global $wpdb;
20 $this->wpdb = $wpdb;
21 $this->formIDs = $formIDs;
22 }
23
24 /**
25 * @return string
26 */
27 public function getSQL()
28 {
29 global $wpdb;
30
31 $sql = "
32 SELECT
33 sum( revenue.amount ) as total,
34 count( payment.ID ) as count
35 FROM {$wpdb->posts} as payment
36 JOIN {$wpdb->give_revenue} as revenue
37 ON revenue.donation_id = payment.ID
38 WHERE
39 payment.post_type = 'give_payment'
40 AND
41 payment.post_status IN ( 'publish', 'give_subscription' )
42 ";
43
44 if ( ! empty($this->formIDs)) {
45 $sql .= '
46 AND
47 revenue.form_id IN ( ' . $this->getFormsString() . ' )
48 ';
49 }
50
51 return $sql;
52 }
53
54 /**
55 * @return string
56 */
57 protected function getFormsString()
58 {
59 return implode(',', $this->formIDs);
60 }
61
62 /**
63 * @return stdClass
64 */
65 public function getResults()
66 {
67 $sql = $this->getSQL();
68
69 return $this->wpdb->get_row($sql);
70 }
71 }
72