PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.11.1
GiveWP – Donation Plugin and Fundraising Platform v2.11.1
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 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / MultiFormGoals / ProgressBar / Model.php
give / src / MultiFormGoals / ProgressBar Last commit date
Block.php 5 years ago Model.php 5 years ago Query.php 5 years ago
Model.php
285 lines
1 <?php
2
3 namespace Give\MultiFormGoals\ProgressBar;
4
5
6 use Give\ValueObjects\Money;
7
8 class Model {
9
10 // Settings
11 protected $ids;
12 protected $tags;
13 protected $categories;
14 protected $goal;
15 protected $enddate;
16 protected $color;
17
18 // Internal
19 protected $forms = [];
20 protected $donationRevenueResults;
21
22 /**
23 * Constructs and sets up setting variables for a new Progress Bar model
24 *
25 * @param array $args Arguments for new Progress Bar, including 'ids'
26 * @since 2.9.0
27 **/
28 public function __construct( array $args ) {
29 isset( $args['ids'] ) ? $this->ids = $args['ids'] : $this->ids = [];
30 isset( $args['tags'] ) ? $this->tags = $args['tags'] : $this->tags = [];
31 isset( $args['categories'] ) ? $this->categories = $args['categories'] : $this->categories = [];
32 isset( $args['goal'] ) ? $this->goal = $args['goal'] : $this->goal = '1000';
33 isset( $args['enddate'] ) ? $this->enddate = $args['enddate'] : $this->enddate = '';
34 isset( $args['color'] ) ? $this->color = $args['color'] : $this->color = '#28c77b';
35 }
36
37 /**
38 * Get forms associated with Progress Bar
39 *
40 * @return array
41 * @since 2.9.0
42 **/
43 protected function getForms() {
44
45 if ( ! empty( $this->forms ) ) {
46 return $this->forms;
47 }
48
49 $query_args = [
50 'post_type' => 'give_forms',
51 'post_status' => 'publish',
52 'post__in' => $this->ids,
53 'posts_per_page' => - 1,
54 'fields' => 'ids',
55 'tax_query' => [
56 'relation' => 'AND',
57 ],
58 ];
59
60 if ( ! empty( $this->tags ) ) {
61 $query_args['tax_query'][] = [
62 'taxonomy' => 'give_forms_tag',
63 'terms' => $this->tags,
64 ];
65 }
66
67 if ( ! empty( $this->categories ) ) {
68 $query_args['tax_query'][] = [
69 'taxonomy' => 'give_forms_category',
70 'terms' => $this->categories,
71 ];
72 }
73
74 $query = new \WP_Query( $query_args );
75
76 if ( $query->posts ) {
77 $this->forms = $query->posts;
78 return $query->posts;
79 } else {
80 return false;
81 }
82 }
83
84 protected function getDonations() {
85 $query_args = [
86 'post_status' => [
87 'publish',
88 'give_subscription',
89 ],
90 'number' => -1,
91 'give_forms' => $this->getForms(),
92 ];
93 $query = new \Give_Payments_Query( $query_args );
94 return $query->get_payments();
95 }
96
97 /**
98 * Get output markup for Progress Bar
99 *
100 * @return string
101 * @since 2.9.0
102 **/
103 public function getOutput() {
104 ob_start();
105 $output = '';
106 require $this->getTemplatePath();
107 $output = ob_get_contents();
108 ob_end_clean();
109 return $output;
110 }
111
112 /**
113 * Returns query results for Donation Revenue.
114 * @since 2.9.0
115 * @return stdClass seem MultiFormGoals/ProgressBar/Query.php
116 */
117 protected function getDonationRevenueResults() {
118 if ( ! $this->donationRevenueResults ) {
119 $query = new Query( $this->getForms() );
120 $this->donationRevenueResults = $query->getResults();
121 }
122 return $this->donationRevenueResults;
123 }
124
125 /**
126 * Get raw earnings value for Progress Bar
127 *
128 * @return string
129 * @since 2.9.0
130 **/
131 protected function getTotal() {
132 $query = new Query( $this->getForms() );
133 $results = $query->getResults();
134 return Money::ofMinor( $results->total, give_get_option( 'currency' ) )->getAmount();
135 }
136
137 /**
138 * Get number of donations for Progress Bar
139 *
140 * @return int
141 * @since 2.9.0
142 **/
143 protected function getDonationCount() {
144 $results = $this->getDonationRevenueResults();
145 return $results->count;
146 }
147
148 /**
149 * Get formatted total remaining (ex: $75)
150 *
151 * @since 2.9.0
152 */
153 protected function getFormattedTotalRemaining() {
154 $total_remaining = ( $this->getGoal() - $this->getTotal() ) > 0 ? ( $this->getGoal() - $this->getTotal() ) : 0;
155 return give_currency_filter(
156 give_format_amount(
157 $total_remaining,
158 [
159 'sanitize' => false,
160 'decimal' => false,
161 ]
162 )
163 );
164 }
165
166 /**
167 * Get goal for Progress Bar
168 *
169 * @return string
170 * @since 2.9.0
171 **/
172 protected function getGoal() {
173 return $this->goal;
174 }
175
176 /**
177 * Get goal color for Progress Bar
178 *
179 * @return string
180 * @since 2.9.0
181 **/
182 protected function getColor() {
183 return $this->color;
184 }
185 /**
186 * Get template path for Progress Bar component template
187 * @since 2.9.0
188 **/
189 public function getTemplatePath() {
190 return GIVE_PLUGIN_DIR . '/src/MultiFormGoals/resources/views/progressbar.php';
191 }
192
193 protected function getFormattedTotal() {
194 return give_currency_filter(
195 give_format_amount(
196 $this->getTotal(),
197 [
198 'sanitize' => false,
199 'decimal' => false,
200 ]
201 )
202 );
203 }
204
205 protected function getFormattedGoal() {
206 return give_currency_filter(
207 give_format_amount(
208 $this->getGoal(),
209 [
210 'sanitize' => false,
211 'decimal' => false,
212 ]
213 )
214 );
215 }
216
217 /**
218 * Get end date for Progress Bar
219 *
220 * @return string
221 * @since 2.9.0
222 **/
223 protected function getEndDate() {
224 return $this->enddate;
225 }
226
227 /**
228 * Get minutes remaining before Progress Bar end date
229 *
230 * @return string
231 * @since 2.9.0
232 **/
233 protected function getMinutesRemaining() {
234 $enddate = strtotime( $this->getEndDate() );
235 if ( $enddate ) {
236 $now = current_time( 'timestamp', false );
237 return $now < $enddate ? ( $enddate - $now ) / 60 : 0;
238 } else {
239 return false;
240 }
241 }
242
243 /**
244 * Get time remaining before Progress Bar end date
245 *
246 * @return string
247 * @since 2.9.0
248 **/
249 protected function getTimeToGo() {
250 $minutes = $this->getMinutesRemaining();
251 switch ( $minutes ) {
252 case $minutes > 1440: {
253 return round( $minutes / 1440 );
254 }
255 case $minutes < 1440 && $minutes > 60: {
256 return round( $minutes / 60 );
257 }
258 case $minutes < 60: {
259 return round( $minutes );
260 }
261 }
262 }
263
264 /**
265 * Get time remaining before Progress Bar end date
266 *
267 * @return string
268 * @since 2.9.0
269 **/
270 protected function getTimeToGoLabel() {
271 $minutes = $this->getMinutesRemaining();
272 switch ( $minutes ) {
273 case $minutes > 1440: {
274 return _n( 'day to go', 'days to go', $this->getTimeToGo(), 'give' );
275 }
276 case $minutes < 1440 && $minutes > 60: {
277 return _n( 'hour to go', 'hours to go', $this->getTimeToGo(), 'give' );
278 }
279 case $minutes < 60: {
280 return _n( 'minute to go', 'minutes to go', $this->getTimeToGo(), 'give' );
281 }
282 }
283 }
284 }
285