PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 2.17.0
GiveWP – Donation Plugin and Fundraising Platform v2.17.0
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 in GiveWP – Donation Plugin and Fundraising Platform 2.17.0, at src/MultiFormGoals/ProgressBar/Query.php

66 lines 1.3 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 /** @var array */
11 protected $formIDs;
12
13 /**
14 * @var array $formIDs
15 */
16 public function __construct( $formIDs ) {
17 global $wpdb;
18 $this->wpdb = $wpdb;
19 $this->formIDs = $formIDs;
20 }
21
22 /**
23 * @return string
24 */
25 public function getSQL() {
26 global $wpdb;
27
28 $sql = "
29 SELECT
30 sum( revenue.amount ) as total,
31 count( payment.ID ) as count
32 FROM {$wpdb->posts} as payment
33 JOIN {$wpdb->give_revenue} as revenue
34 ON revenue.donation_id = payment.ID
35 WHERE
36 payment.post_type = 'give_payment'
37 AND
38 payment.post_status IN ( 'publish', 'give_subscription' )
39 ";
40
41 if ( ! empty( $this->formIDs ) ) {
42 $sql .= '
43 AND
44 revenue.form_id IN ( ' . $this->getFormsString() . ' )
45 ';
46 }
47
48 return $sql;
49 }
50
51 /**
52 * @return string
53 */
54 protected function getFormsString() {
55 return implode( ',', $this->formIDs );
56 }
57
58 /**
59 * @return stdClass
60 */
61 public function getResults() {
62 $sql = $this->getSQL();
63 return $this->wpdb->get_row( $sql );
64 }
65 }
66