PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.9.1
GiveWP – Donation Plugin and Fundraising Platform v2.9.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
272 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
21 /**
22 * Constructs and sets up setting variables for a new Progress Bar model
23 *
24 * @param array $args Arguments for new Progress Bar, including 'ids'
25 * @since 2.9.0
26 **/
27 public function __construct( array $args ) {
28 isset( $args['ids'] ) ? $this->ids = $args['ids'] : $this->ids = [];
29 isset( $args['tags'] ) ? $this->tags = $args['tags'] : $this->tags = [];
30 isset( $args['categories'] ) ? $this->categories = $args['categories'] : $this->categories = [];
31 isset( $args['goal'] ) ? $this->goal = $args['goal'] : $this->goal = '1000';
32 isset( $args['enddate'] ) ? $this->enddate = $args['enddate'] : $this->enddate = '';
33 isset( $args['color'] ) ? $this->color = $args['color'] : $this->color = '#28c77b';
34 }
35
36 /**
37 * Get forms associated with Progress Bar
38 *
39 * @return array
40 * @since 2.9.0
41 **/
42 protected function getForms() {
43
44 if ( ! empty( $this->forms ) ) {
45 return $this->forms;
46 }
47
48 $query_args = [
49 'post_type' => 'give_forms',
50 'post_status' => 'publish',
51 'post__in' => $this->ids,
52 'posts_per_page' => - 1,
53 'fields' => 'ids',
54 'tax_query' => [
55 'relation' => 'AND',
56 ],
57 ];
58
59 if ( ! empty( $this->tags ) ) {
60 $query_args['tax_query'][] = [
61 'taxonomy' => 'give_forms_tag',
62 'terms' => $this->tags,
63 ];
64 }
65
66 if ( ! empty( $this->categories ) ) {
67 $query_args['tax_query'][] = [
68 'taxonomy' => 'give_forms_category',
69 'terms' => $this->categories,
70 ];
71 }
72
73 $query = new \WP_Query( $query_args );
74
75 if ( $query->posts ) {
76 $this->forms = $query->posts;
77 return $query->posts;
78 } else {
79 return false;
80 }
81 }
82
83 protected function getDonations() {
84 $query_args = [
85 'post_status' => [
86 'publish',
87 'give_subscription',
88 ],
89 'number' => -1,
90 'give_forms' => $this->getForms(),
91 ];
92 $query = new \Give_Payments_Query( $query_args );
93 return $query->get_payments();
94 }
95
96 /**
97 * Get output markup for Progress Bar
98 *
99 * @return string
100 * @since 2.9.0
101 **/
102 public function getOutput() {
103 ob_start();
104 $output = '';
105 require $this->getTemplatePath();
106 $output = ob_get_contents();
107 ob_end_clean();
108 return $output;
109 }
110
111 /**
112 * Get raw earnings value for Progress Bar
113 *
114 * @return string
115 * @since 2.9.0
116 **/
117 protected function getTotal() {
118 $query = new Query( $this->getForms() );
119 $results = $query->getResults();
120 return Money::ofMinor( $results->total, give_get_option( 'currency' ) )->getAmount();
121 }
122
123 /**
124 * Get number of donations for Progress Bar
125 *
126 * @return int
127 * @since 2.9.0
128 **/
129 protected function getDonationCount() {
130 $query = new Query( $this->getForms() );
131 $results = $query->getResults();
132 return $results->count;
133 }
134
135 /**
136 * Get formatted total remaining (ex: $75)
137 *
138 * @since 2.9.0
139 */
140 protected function getFormattedTotalRemaining() {
141 $total_remaining = ( $this->getGoal() - $this->getTotal() ) > 0 ? ( $this->getGoal() - $this->getTotal() ) : 0;
142 return give_currency_filter(
143 give_format_amount(
144 $total_remaining,
145 [
146 'sanitize' => false,
147 'decimal' => false,
148 ]
149 )
150 );
151 }
152
153 /**
154 * Get goal for Progress Bar
155 *
156 * @return string
157 * @since 2.9.0
158 **/
159 protected function getGoal() {
160 return $this->goal;
161 }
162
163 /**
164 * Get goal color for Progress Bar
165 *
166 * @return string
167 * @since 2.9.0
168 **/
169 protected function getColor() {
170 return $this->color;
171 }
172 /**
173 * Get template path for Progress Bar component template
174 * @since 2.9.0
175 **/
176 public function getTemplatePath() {
177 return GIVE_PLUGIN_DIR . '/src/MultiFormGoals/resources/views/progressbar.php';
178 }
179
180 protected function getFormattedTotal() {
181 return give_currency_filter(
182 give_format_amount(
183 $this->getTotal(),
184 [
185 'sanitize' => false,
186 'decimal' => false,
187 ]
188 )
189 );
190 }
191
192 protected function getFormattedGoal() {
193 return give_currency_filter(
194 give_format_amount(
195 $this->getGoal(),
196 [
197 'sanitize' => false,
198 'decimal' => false,
199 ]
200 )
201 );
202 }
203
204 /**
205 * Get end date for Progress Bar
206 *
207 * @return string
208 * @since 2.9.0
209 **/
210 protected function getEndDate() {
211 return $this->enddate;
212 }
213
214 /**
215 * Get minutes remaining before Progress Bar end date
216 *
217 * @return string
218 * @since 2.9.0
219 **/
220 protected function getMinutesRemaining() {
221 $enddate = strtotime( $this->getEndDate() );
222 if ( $enddate ) {
223 $now = current_time( 'timestamp', false );
224 return $now < $enddate ? ( $enddate - $now ) / 60 : 0;
225 } else {
226 return false;
227 }
228 }
229
230 /**
231 * Get time remaining before Progress Bar end date
232 *
233 * @return string
234 * @since 2.9.0
235 **/
236 protected function getTimeToGo() {
237 $minutes = $this->getMinutesRemaining();
238 switch ( $minutes ) {
239 case $minutes > 1440: {
240 return round( $minutes / 1440 );
241 }
242 case $minutes < 1440 && $minutes > 60: {
243 return round( $minutes / 60 );
244 }
245 case $minutes < 60: {
246 return round( $minutes );
247 }
248 }
249 }
250
251 /**
252 * Get time remaining before Progress Bar end date
253 *
254 * @return string
255 * @since 2.9.0
256 **/
257 protected function getTimeToGoLabel() {
258 $minutes = $this->getMinutesRemaining();
259 switch ( $minutes ) {
260 case $minutes > 1440: {
261 return _n( 'day to go', 'days to go', $this->getTimeToGo(), 'give' );
262 }
263 case $minutes < 1440 && $minutes > 60: {
264 return _n( 'hour to go', 'hours to go', $this->getTimeToGo(), 'give' );
265 }
266 case $minutes < 60: {
267 return _n( 'minute to go', 'minutes to go', $this->getTimeToGo(), 'give' );
268 }
269 }
270 }
271 }
272