| @@ -1,10 +1,14 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Give\MultiFormGoals\ProgressBar; |
| 4 | 4 | |
| 5 | -use Give\ValueObjects\Money; | |
| 5 | +use Give\DonationForms\DonationQuery; | |
| 6 | 6 | |
| 7 | +/** | |
| 8 | + * @since 3.16.0 Add $statusList property | |
| 9 | + * @since 2.9.0 | |
| 10 | + */ | |
| 7 | 11 | class Model |
| 8 | 12 | { |
| 9 | 13 | |
| 10 | 14 | // Settings |
| @@ -18,11 +22,14 @@ | ||
| 18 | 22 | // Internal |
| 19 | 23 | protected $forms = []; |
| 20 | 24 | protected $donationRevenueResults; |
| 21 | 25 | |
| 26 | + protected $statusList = []; | |
| 27 | + | |
| 22 | 28 | /** |
| 23 | 29 | * Constructs and sets up setting variables for a new Progress Bar model |
| 24 | 30 | * |
| 31 | + * @since 3.16.0 Add statusList support for $args | |
| 25 | 32 | * @since 2.9.0 |
| 26 | 33 | **@param array $args Arguments for new Progress Bar, including 'ids' |
| 27 | 34 | */ |
| 28 | 35 | public function __construct(array $args) |
| @@ -32,13 +39,16 @@ | ||
| 32 | 39 | isset($args['categories']) ? $this->categories = $args['categories'] : $this->categories = []; |
| 33 | 40 | isset($args['goal']) ? $this->goal = $args['goal'] : $this->goal = '1000'; |
| 34 | 41 | isset($args['enddate']) ? $this->enddate = $args['enddate'] : $this->enddate = ''; |
| 35 | 42 | isset($args['color']) ? $this->color = $args['color'] : $this->color = '#28c77b'; |
| 43 | + isset($args['statusList']) ? $this->statusList = $args['statusList'] : $this->statusList = ['publish']; | |
| 36 | 44 | } |
| 37 | 45 | |
| 38 | 46 | /** |
| 39 | 47 | * Get forms associated with Progress Bar |
| 40 | 48 | * |
| 49 | + * @since 3.16.0 Use $statusList property | |
| 50 | + * @since 3.0.3 Return empty array instead of false | |
| 41 | 51 | * @since 2.9.0 |
| 42 | 52 | */ |
| 43 | 53 | public function getForms(): array |
| 44 | 54 | { |
| @@ -47,9 +57,9 @@ | ||
| 47 | 57 | } |
| 48 | 58 | |
| 49 | 59 | $query_args = [ |
| 50 | 60 | 'post_type' => 'give_forms', |
| 51 | - 'post_status' => 'publish', | |
| 61 | + 'post_status' => $this->statusList, | |
| 52 | 62 | 'post__in' => $this->ids, |
| 53 | 63 | 'posts_per_page' => -1, |
| 54 | 64 | 'fields' => 'ids', |
| 55 | 65 | 'tax_query' => [ |
| @@ -77,9 +87,9 @@ | ||
| 77 | 87 | $this->forms = $query->posts; |
| 78 | 88 | |
| 79 | 89 | return $query->posts; |
| 80 | 90 | } else { |
| 81 | - return false; | |
| 91 | + return []; | |
| 82 | 92 | } |
| 83 | 93 | } |
| 84 | 94 | |
| 85 | 95 | /** |
| @@ -130,16 +140,14 @@ | ||
| 130 | 140 | |
| 131 | 141 | /** |
| 132 | 142 | * Get raw earnings value for Progress Bar |
| 133 | 143 | * |
| 144 | + * @since 3.12.0 use DonationQuery | |
| 134 | 145 | * @since 2.9.0 |
| 135 | 146 | */ |
| 136 | 147 | public function getTotal(): string |
| 137 | 148 | { |
| 138 | - $query = new Query($this->getForms()); | |
| 139 | - $results = $query->getResults(); | |
| 140 | - | |
| 141 | - return Money::ofMinor($results->total, give_get_option('currency'))->getAmount(); | |
| 149 | + return (new DonationQuery())->forms($this->getForms())->sumIntendedAmount(); | |
| 142 | 150 | } |
| 143 | 151 | |
| 144 | 152 | /** |
| 145 | 153 | * Get number of donations for Progress Bar |
| @@ -150,8 +158,25 @@ | ||
| 150 | 158 | { |
| 151 | 159 | $results = $this->getDonationRevenueResults(); |
| 152 | 160 | |
| 153 | 161 | return $results->count; |
| 162 | + } | |
| 163 | + | |
| 164 | + /** | |
| 165 | + * Get formatted number of donations | |
| 166 | + * | |
| 167 | + * @since 3.19.1 | |
| 168 | + */ | |
| 169 | + public function getFormattedDonationCount(): string | |
| 170 | + { | |
| 171 | + return give_format_amount( | |
| 172 | + $this->getDonationCount(), | |
| 173 | + [ | |
| 174 | + 'sanitize' => false, | |
| 175 | + 'decimal' => false, | |
| 176 | + 'currency' => false, | |
| 177 | + ] | |
| 178 | + ); | |
| 154 | 179 | } |
| 155 | 180 | |
| 156 | 181 | /** |
| 157 | 182 | * Get formatted total remaining (ex: $75) |