@@ -13,1702 +13,1702 @@ |
||
13 | 13 | class EE_Transaction extends EE_Base_Class implements EEI_Transaction |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * The length of time in seconds that a lock is applied before being considered expired. |
|
18 | - * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
19 | - */ |
|
20 | - const LOCK_EXPIRATION = 2; |
|
21 | - |
|
22 | - /** |
|
23 | - * txn status upon initial construction. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_old_txn_status; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param array $props_n_values incoming values |
|
32 | - * @param string $timezone incoming timezone |
|
33 | - * (if not set the timezone set for the website will be used.) |
|
34 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
35 | - * date_format and the second value is the time format |
|
36 | - * @return EE_Transaction |
|
37 | - * @throws EE_Error |
|
38 | - * @throws InvalidArgumentException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidInterfaceException |
|
41 | - * @throws ReflectionException |
|
42 | - */ |
|
43 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
44 | - { |
|
45 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
46 | - $txn = $has_object |
|
47 | - ? $has_object |
|
48 | - : new self($props_n_values, false, $timezone, $date_formats); |
|
49 | - if (! $has_object) { |
|
50 | - $txn->set_old_txn_status($txn->status_ID()); |
|
51 | - } |
|
52 | - return $txn; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param array $props_n_values incoming values from the database |
|
58 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
59 | - * the website will be used. |
|
60 | - * @return EE_Transaction |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - * @throws ReflectionException |
|
66 | - */ |
|
67 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
68 | - { |
|
69 | - $txn = new self($props_n_values, true, $timezone); |
|
70 | - $txn->set_old_txn_status($txn->status_ID()); |
|
71 | - return $txn; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
77 | - * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
78 | - * If that also fails, then an exception is thrown. |
|
79 | - * |
|
80 | - * @throws EE_Error |
|
81 | - * @throws InvalidArgumentException |
|
82 | - * @throws InvalidDataTypeException |
|
83 | - * @throws InvalidInterfaceException |
|
84 | - * @throws ReflectionException |
|
85 | - */ |
|
86 | - public function lock() |
|
87 | - { |
|
88 | - // attempt to set lock, but if that fails... |
|
89 | - if (! $this->add_extra_meta('lock', time(), true)) { |
|
90 | - // then attempt to remove the lock in case it is expired |
|
91 | - if ($this->_remove_expired_lock()) { |
|
92 | - // if removal was successful, then try setting lock again |
|
93 | - $this->lock(); |
|
94 | - } else { |
|
95 | - // but if the lock can not be removed, then throw an exception |
|
96 | - throw new EE_Error( |
|
97 | - sprintf( |
|
98 | - __( |
|
99 | - 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
100 | - 'event_espresso' |
|
101 | - ), |
|
102 | - $this->ID() |
|
103 | - ) |
|
104 | - ); |
|
105 | - } |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * removes transaction lock applied in EE_Transaction::lock() |
|
112 | - * |
|
113 | - * @return int |
|
114 | - * @throws EE_Error |
|
115 | - * @throws InvalidArgumentException |
|
116 | - * @throws InvalidDataTypeException |
|
117 | - * @throws InvalidInterfaceException |
|
118 | - * @throws ReflectionException |
|
119 | - */ |
|
120 | - public function unlock() |
|
121 | - { |
|
122 | - return $this->delete_extra_meta('lock'); |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * Decides whether or not now is the right time to update the transaction. |
|
128 | - * This is useful because we don't always know if it is safe to update the transaction |
|
129 | - * and its related data. why? |
|
130 | - * because it's possible that the transaction is being used in another |
|
131 | - * request and could overwrite anything we save. |
|
132 | - * So we want to only update the txn once we know that won't happen. |
|
133 | - * We also check that the lock isn't expired, and remove it if it is |
|
134 | - * |
|
135 | - * @return boolean |
|
136 | - * @throws EE_Error |
|
137 | - * @throws InvalidArgumentException |
|
138 | - * @throws InvalidDataTypeException |
|
139 | - * @throws InvalidInterfaceException |
|
140 | - * @throws ReflectionException |
|
141 | - */ |
|
142 | - public function is_locked() |
|
143 | - { |
|
144 | - // if TXN is not locked, then return false immediately |
|
145 | - if (! $this->_get_lock()) { |
|
146 | - return false; |
|
147 | - } |
|
148 | - // if not, then let's try and remove the lock in case it's expired... |
|
149 | - // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
150 | - // and a positive number if the lock was removed (ie: number of locks deleted), |
|
151 | - // so we need to return the opposite |
|
152 | - return ! $this->_remove_expired_lock() ? true : false; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Gets the meta field indicating that this TXN is locked |
|
158 | - * |
|
159 | - * @return int |
|
160 | - * @throws EE_Error |
|
161 | - * @throws InvalidArgumentException |
|
162 | - * @throws InvalidDataTypeException |
|
163 | - * @throws InvalidInterfaceException |
|
164 | - * @throws ReflectionException |
|
165 | - */ |
|
166 | - protected function _get_lock() |
|
167 | - { |
|
168 | - return (int) $this->get_extra_meta('lock', true, 0); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
174 | - * |
|
175 | - * @return int |
|
176 | - * @throws EE_Error |
|
177 | - * @throws InvalidArgumentException |
|
178 | - * @throws InvalidDataTypeException |
|
179 | - * @throws InvalidInterfaceException |
|
180 | - * @throws ReflectionException |
|
181 | - */ |
|
182 | - protected function _remove_expired_lock() |
|
183 | - { |
|
184 | - $locked = $this->_get_lock(); |
|
185 | - if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
186 | - return $this->unlock(); |
|
187 | - } |
|
188 | - return 0; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * Set transaction total |
|
194 | - * |
|
195 | - * @param float $total total value of transaction |
|
196 | - * @throws EE_Error |
|
197 | - * @throws InvalidArgumentException |
|
198 | - * @throws InvalidDataTypeException |
|
199 | - * @throws InvalidInterfaceException |
|
200 | - * @throws ReflectionException |
|
201 | - */ |
|
202 | - public function set_total($total = 0.00) |
|
203 | - { |
|
204 | - $this->set('TXN_total', (float) $total); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Set Total Amount Paid to Date |
|
210 | - * |
|
211 | - * @param float $total_paid total amount paid to date (sum of all payments) |
|
212 | - * @throws EE_Error |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws InvalidDataTypeException |
|
215 | - * @throws InvalidInterfaceException |
|
216 | - * @throws ReflectionException |
|
217 | - */ |
|
218 | - public function set_paid($total_paid = 0.00) |
|
219 | - { |
|
220 | - $this->set('TXN_paid', (float) $total_paid); |
|
221 | - } |
|
222 | - |
|
223 | - |
|
224 | - /** |
|
225 | - * Set transaction status |
|
226 | - * |
|
227 | - * @param string $status whether the transaction is open, declined, accepted, |
|
228 | - * or any number of custom values that can be set |
|
229 | - * @throws EE_Error |
|
230 | - * @throws InvalidArgumentException |
|
231 | - * @throws InvalidDataTypeException |
|
232 | - * @throws InvalidInterfaceException |
|
233 | - * @throws ReflectionException |
|
234 | - */ |
|
235 | - public function set_status($status = '') |
|
236 | - { |
|
237 | - $this->set('STS_ID', $status); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * Set hash salt |
|
243 | - * |
|
244 | - * @param string $hash_salt required for some payment gateways |
|
245 | - * @throws EE_Error |
|
246 | - * @throws InvalidArgumentException |
|
247 | - * @throws InvalidDataTypeException |
|
248 | - * @throws InvalidInterfaceException |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - public function set_hash_salt($hash_salt = '') |
|
252 | - { |
|
253 | - $this->set('TXN_hash_salt', $hash_salt); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Sets TXN_reg_steps array |
|
259 | - * |
|
260 | - * @param array $txn_reg_steps |
|
261 | - * @throws EE_Error |
|
262 | - * @throws InvalidArgumentException |
|
263 | - * @throws InvalidDataTypeException |
|
264 | - * @throws InvalidInterfaceException |
|
265 | - * @throws ReflectionException |
|
266 | - */ |
|
267 | - public function set_reg_steps(array $txn_reg_steps) |
|
268 | - { |
|
269 | - $this->set('TXN_reg_steps', $txn_reg_steps); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Gets TXN_reg_steps |
|
275 | - * |
|
276 | - * @return array |
|
277 | - * @throws EE_Error |
|
278 | - * @throws InvalidArgumentException |
|
279 | - * @throws InvalidDataTypeException |
|
280 | - * @throws InvalidInterfaceException |
|
281 | - * @throws ReflectionException |
|
282 | - */ |
|
283 | - public function reg_steps() |
|
284 | - { |
|
285 | - $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
286 | - return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @return string of transaction's total cost, with currency symbol and decimal |
|
292 | - * @throws EE_Error |
|
293 | - * @throws InvalidArgumentException |
|
294 | - * @throws InvalidDataTypeException |
|
295 | - * @throws InvalidInterfaceException |
|
296 | - * @throws ReflectionException |
|
297 | - */ |
|
298 | - public function pretty_total() |
|
299 | - { |
|
300 | - return $this->get_pretty('TXN_total'); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
306 | - * |
|
307 | - * @return string |
|
308 | - * @throws EE_Error |
|
309 | - * @throws InvalidArgumentException |
|
310 | - * @throws InvalidDataTypeException |
|
311 | - * @throws InvalidInterfaceException |
|
312 | - * @throws ReflectionException |
|
313 | - */ |
|
314 | - public function pretty_paid() |
|
315 | - { |
|
316 | - return $this->get_pretty('TXN_paid'); |
|
317 | - } |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * calculate the amount remaining for this transaction and return; |
|
322 | - * |
|
323 | - * @return float amount remaining |
|
324 | - * @throws EE_Error |
|
325 | - * @throws InvalidArgumentException |
|
326 | - * @throws InvalidDataTypeException |
|
327 | - * @throws InvalidInterfaceException |
|
328 | - * @throws ReflectionException |
|
329 | - */ |
|
330 | - public function remaining() |
|
331 | - { |
|
332 | - return $this->total() - $this->paid(); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * get Transaction Total |
|
338 | - * |
|
339 | - * @return float |
|
340 | - * @throws EE_Error |
|
341 | - * @throws InvalidArgumentException |
|
342 | - * @throws InvalidDataTypeException |
|
343 | - * @throws InvalidInterfaceException |
|
344 | - * @throws ReflectionException |
|
345 | - */ |
|
346 | - public function total() |
|
347 | - { |
|
348 | - return (float) $this->get('TXN_total'); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * get Total Amount Paid to Date |
|
354 | - * |
|
355 | - * @return float |
|
356 | - * @throws EE_Error |
|
357 | - * @throws InvalidArgumentException |
|
358 | - * @throws InvalidDataTypeException |
|
359 | - * @throws InvalidInterfaceException |
|
360 | - * @throws ReflectionException |
|
361 | - */ |
|
362 | - public function paid() |
|
363 | - { |
|
364 | - return (float) $this->get('TXN_paid'); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @return mixed|null |
|
370 | - * @throws EE_Error |
|
371 | - * @throws InvalidArgumentException |
|
372 | - * @throws InvalidDataTypeException |
|
373 | - * @throws InvalidInterfaceException |
|
374 | - * @throws ReflectionException |
|
375 | - */ |
|
376 | - public function get_cart_session() |
|
377 | - { |
|
378 | - $session_data = (array) $this->get('TXN_session_data'); |
|
379 | - return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
380 | - ? $session_data['cart'] |
|
381 | - : null; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * get Transaction session data |
|
387 | - * |
|
388 | - * @return array|mixed |
|
389 | - * @throws EE_Error |
|
390 | - * @throws InvalidArgumentException |
|
391 | - * @throws InvalidDataTypeException |
|
392 | - * @throws InvalidInterfaceException |
|
393 | - * @throws ReflectionException |
|
394 | - */ |
|
395 | - public function session_data() |
|
396 | - { |
|
397 | - $session_data = $this->get('TXN_session_data'); |
|
398 | - if (empty($session_data)) { |
|
399 | - $session_data = array( |
|
400 | - 'id' => null, |
|
401 | - 'user_id' => null, |
|
402 | - 'ip_address' => null, |
|
403 | - 'user_agent' => null, |
|
404 | - 'init_access' => null, |
|
405 | - 'last_access' => null, |
|
406 | - 'pages_visited' => array(), |
|
407 | - ); |
|
408 | - } |
|
409 | - return $session_data; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - /** |
|
414 | - * Set session data within the TXN object |
|
415 | - * |
|
416 | - * @param EE_Session|array $session_data |
|
417 | - * @throws EE_Error |
|
418 | - * @throws InvalidArgumentException |
|
419 | - * @throws InvalidDataTypeException |
|
420 | - * @throws InvalidInterfaceException |
|
421 | - * @throws ReflectionException |
|
422 | - */ |
|
423 | - public function set_txn_session_data($session_data) |
|
424 | - { |
|
425 | - if ($session_data instanceof EE_Session) { |
|
426 | - $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
427 | - } else { |
|
428 | - $this->set('TXN_session_data', $session_data); |
|
429 | - } |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * get Transaction hash salt |
|
435 | - * |
|
436 | - * @return mixed |
|
437 | - * @throws EE_Error |
|
438 | - * @throws InvalidArgumentException |
|
439 | - * @throws InvalidDataTypeException |
|
440 | - * @throws InvalidInterfaceException |
|
441 | - * @throws ReflectionException |
|
442 | - */ |
|
443 | - public function hash_salt_() |
|
444 | - { |
|
445 | - return $this->get('TXN_hash_salt'); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * Returns the transaction datetime as either: |
|
451 | - * - unix timestamp format ($format = false, $gmt = true) |
|
452 | - * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
453 | - * has no affect with this option)), this also may include a timezone abbreviation if the |
|
454 | - * set timezone in this class differs from what the timezone is on the blog. |
|
455 | - * - formatted date string including the UTC (timezone) offset (default). |
|
456 | - * |
|
457 | - * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
458 | - * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
459 | - * or no UTC offset applied |
|
460 | - * @return string | int |
|
461 | - * @throws EE_Error |
|
462 | - * @throws InvalidArgumentException |
|
463 | - * @throws InvalidDataTypeException |
|
464 | - * @throws InvalidInterfaceException |
|
465 | - * @throws ReflectionException |
|
466 | - */ |
|
467 | - public function datetime($format = false, $gmt = false) |
|
468 | - { |
|
469 | - if ($format) { |
|
470 | - return $this->get_pretty('TXN_timestamp'); |
|
471 | - } |
|
472 | - if ($gmt) { |
|
473 | - return $this->get_raw('TXN_timestamp'); |
|
474 | - } |
|
475 | - return $this->get('TXN_timestamp'); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * Gets registrations on this transaction |
|
481 | - * |
|
482 | - * @param array $query_params array of query parameters |
|
483 | - * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
484 | - * @return EE_Base_Class[]|EE_Registration[] |
|
485 | - * @throws EE_Error |
|
486 | - * @throws InvalidArgumentException |
|
487 | - * @throws InvalidDataTypeException |
|
488 | - * @throws InvalidInterfaceException |
|
489 | - * @throws ReflectionException |
|
490 | - */ |
|
491 | - public function registrations($query_params = array(), $get_cached = false) |
|
492 | - { |
|
493 | - $query_params = (empty($query_params) || ! is_array($query_params)) |
|
494 | - ? array( |
|
495 | - 'order_by' => array( |
|
496 | - 'Event.EVT_name' => 'ASC', |
|
497 | - 'Attendee.ATT_lname' => 'ASC', |
|
498 | - 'Attendee.ATT_fname' => 'ASC', |
|
499 | - ), |
|
500 | - ) |
|
501 | - : $query_params; |
|
502 | - $query_params = $get_cached ? array() : $query_params; |
|
503 | - return $this->get_many_related('Registration', $query_params); |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
509 | - * function for getting attendees and how many registrations they each have for an event) |
|
510 | - * |
|
511 | - * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
512 | - * @throws EE_Error |
|
513 | - * @throws InvalidArgumentException |
|
514 | - * @throws InvalidDataTypeException |
|
515 | - * @throws InvalidInterfaceException |
|
516 | - * @throws ReflectionException |
|
517 | - */ |
|
518 | - public function attendees() |
|
519 | - { |
|
520 | - return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
526 | - * |
|
527 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
528 | - * @return EE_Base_Class[]|EE_Payment[] |
|
529 | - * @throws EE_Error |
|
530 | - * @throws InvalidArgumentException |
|
531 | - * @throws InvalidDataTypeException |
|
532 | - * @throws InvalidInterfaceException |
|
533 | - * @throws ReflectionException |
|
534 | - */ |
|
535 | - public function payments($query_params = array()) |
|
536 | - { |
|
537 | - return $this->get_many_related('Payment', $query_params); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * gets only approved payments for this transaction |
|
543 | - * |
|
544 | - * @return EE_Base_Class[]|EE_Payment[] |
|
545 | - * @throws EE_Error |
|
546 | - * @throws InvalidArgumentException |
|
547 | - * @throws ReflectionException |
|
548 | - * @throws InvalidDataTypeException |
|
549 | - * @throws InvalidInterfaceException |
|
550 | - */ |
|
551 | - public function approved_payments() |
|
552 | - { |
|
553 | - EE_Registry::instance()->load_model('Payment'); |
|
554 | - return $this->get_many_related( |
|
555 | - 'Payment', |
|
556 | - array( |
|
557 | - array('STS_ID' => EEM_Payment::status_id_approved), |
|
558 | - 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
559 | - ) |
|
560 | - ); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * Gets all payments which have not been approved |
|
566 | - * |
|
567 | - * @return EE_Base_Class[]|EEI_Payment[] |
|
568 | - * @throws EE_Error if a model is misconfigured somehow |
|
569 | - * @throws InvalidArgumentException |
|
570 | - * @throws InvalidDataTypeException |
|
571 | - * @throws InvalidInterfaceException |
|
572 | - * @throws ReflectionException |
|
573 | - */ |
|
574 | - public function pending_payments() |
|
575 | - { |
|
576 | - return $this->get_many_related( |
|
577 | - 'Payment', |
|
578 | - array( |
|
579 | - array( |
|
580 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
581 | - ), |
|
582 | - 'order_by' => array( |
|
583 | - 'PAY_timestamp' => 'DESC', |
|
584 | - ), |
|
585 | - ) |
|
586 | - ); |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * echoes $this->pretty_status() |
|
592 | - * |
|
593 | - * @param bool $show_icons |
|
594 | - * @throws EE_Error |
|
595 | - * @throws InvalidArgumentException |
|
596 | - * @throws InvalidDataTypeException |
|
597 | - * @throws InvalidInterfaceException |
|
598 | - * @throws ReflectionException |
|
599 | - */ |
|
600 | - public function e_pretty_status($show_icons = false) |
|
601 | - { |
|
602 | - echo $this->pretty_status($show_icons); |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * returns a pretty version of the status, good for displaying to users |
|
608 | - * |
|
609 | - * @param bool $show_icons |
|
610 | - * @return string |
|
611 | - * @throws EE_Error |
|
612 | - * @throws InvalidArgumentException |
|
613 | - * @throws InvalidDataTypeException |
|
614 | - * @throws InvalidInterfaceException |
|
615 | - * @throws ReflectionException |
|
616 | - */ |
|
617 | - public function pretty_status($show_icons = false) |
|
618 | - { |
|
619 | - $status = EEM_Status::instance()->localized_status( |
|
620 | - array($this->status_ID() => __('unknown', 'event_espresso')), |
|
621 | - false, |
|
622 | - 'sentence' |
|
623 | - ); |
|
624 | - $icon = ''; |
|
625 | - switch ($this->status_ID()) { |
|
626 | - case EEM_Transaction::complete_status_code: |
|
627 | - $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
628 | - break; |
|
629 | - case EEM_Transaction::incomplete_status_code: |
|
630 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
631 | - : ''; |
|
632 | - break; |
|
633 | - case EEM_Transaction::abandoned_status_code: |
|
634 | - $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
635 | - break; |
|
636 | - case EEM_Transaction::failed_status_code: |
|
637 | - $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
638 | - break; |
|
639 | - case EEM_Transaction::overpaid_status_code: |
|
640 | - $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
641 | - break; |
|
642 | - } |
|
643 | - return $icon . $status[ $this->status_ID() ]; |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - /** |
|
648 | - * get Transaction Status |
|
649 | - * |
|
650 | - * @return mixed |
|
651 | - * @throws EE_Error |
|
652 | - * @throws InvalidArgumentException |
|
653 | - * @throws InvalidDataTypeException |
|
654 | - * @throws InvalidInterfaceException |
|
655 | - * @throws ReflectionException |
|
656 | - */ |
|
657 | - public function status_ID() |
|
658 | - { |
|
659 | - return $this->get('STS_ID'); |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - /** |
|
664 | - * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
665 | - * |
|
666 | - * @return boolean |
|
667 | - * @throws EE_Error |
|
668 | - * @throws InvalidArgumentException |
|
669 | - * @throws InvalidDataTypeException |
|
670 | - * @throws InvalidInterfaceException |
|
671 | - * @throws ReflectionException |
|
672 | - */ |
|
673 | - public function is_free() |
|
674 | - { |
|
675 | - return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
676 | - } |
|
677 | - |
|
678 | - |
|
679 | - /** |
|
680 | - * Returns whether this transaction is complete |
|
681 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
682 | - * |
|
683 | - * @return boolean |
|
684 | - * @throws EE_Error |
|
685 | - * @throws InvalidArgumentException |
|
686 | - * @throws InvalidDataTypeException |
|
687 | - * @throws InvalidInterfaceException |
|
688 | - * @throws ReflectionException |
|
689 | - */ |
|
690 | - public function is_completed() |
|
691 | - { |
|
692 | - return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * Returns whether this transaction is incomplete |
|
698 | - * Useful in templates and other logic for deciding if we should ask for another payment... |
|
699 | - * |
|
700 | - * @return boolean |
|
701 | - * @throws EE_Error |
|
702 | - * @throws InvalidArgumentException |
|
703 | - * @throws InvalidDataTypeException |
|
704 | - * @throws InvalidInterfaceException |
|
705 | - * @throws ReflectionException |
|
706 | - */ |
|
707 | - public function is_incomplete() |
|
708 | - { |
|
709 | - return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
710 | - } |
|
711 | - |
|
712 | - |
|
713 | - /** |
|
714 | - * Returns whether this transaction is overpaid |
|
715 | - * Useful in templates and other logic for deciding if monies need to be refunded |
|
716 | - * |
|
717 | - * @return boolean |
|
718 | - * @throws EE_Error |
|
719 | - * @throws InvalidArgumentException |
|
720 | - * @throws InvalidDataTypeException |
|
721 | - * @throws InvalidInterfaceException |
|
722 | - * @throws ReflectionException |
|
723 | - */ |
|
724 | - public function is_overpaid() |
|
725 | - { |
|
726 | - return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
727 | - } |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * Returns whether this transaction was abandoned |
|
732 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
733 | - * but that contact information exists for at least one registrant |
|
734 | - * |
|
735 | - * @return boolean |
|
736 | - * @throws EE_Error |
|
737 | - * @throws InvalidArgumentException |
|
738 | - * @throws InvalidDataTypeException |
|
739 | - * @throws InvalidInterfaceException |
|
740 | - * @throws ReflectionException |
|
741 | - */ |
|
742 | - public function is_abandoned() |
|
743 | - { |
|
744 | - return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * Returns whether this transaction failed |
|
750 | - * meaning that the transaction/registration process was somehow interrupted and never completed |
|
751 | - * and that NO contact information exists for any registrants |
|
752 | - * |
|
753 | - * @return boolean |
|
754 | - * @throws EE_Error |
|
755 | - * @throws InvalidArgumentException |
|
756 | - * @throws InvalidDataTypeException |
|
757 | - * @throws InvalidInterfaceException |
|
758 | - * @throws ReflectionException |
|
759 | - */ |
|
760 | - public function failed() |
|
761 | - { |
|
762 | - return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * This returns the url for the invoice of this transaction |
|
768 | - * |
|
769 | - * @param string $type 'html' or 'pdf' (default is pdf) |
|
770 | - * @return string |
|
771 | - * @throws EE_Error |
|
772 | - * @throws InvalidArgumentException |
|
773 | - * @throws InvalidDataTypeException |
|
774 | - * @throws InvalidInterfaceException |
|
775 | - * @throws ReflectionException |
|
776 | - */ |
|
777 | - public function invoice_url($type = 'html') |
|
778 | - { |
|
779 | - $REG = $this->primary_registration(); |
|
780 | - if (! $REG instanceof EE_Registration) { |
|
781 | - return ''; |
|
782 | - } |
|
783 | - return $REG->invoice_url($type); |
|
784 | - } |
|
785 | - |
|
786 | - |
|
787 | - /** |
|
788 | - * Gets the primary registration only |
|
789 | - * |
|
790 | - * @return EE_Base_Class|EE_Registration |
|
791 | - * @throws EE_Error |
|
792 | - * @throws InvalidArgumentException |
|
793 | - * @throws InvalidDataTypeException |
|
794 | - * @throws InvalidInterfaceException |
|
795 | - * @throws ReflectionException |
|
796 | - */ |
|
797 | - public function primary_registration() |
|
798 | - { |
|
799 | - $registrations = (array) $this->get_many_related( |
|
800 | - 'Registration', |
|
801 | - array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
802 | - ); |
|
803 | - foreach ($registrations as $registration) { |
|
804 | - // valid registration that is NOT cancelled or declined ? |
|
805 | - if ($registration instanceof EE_Registration |
|
806 | - && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
807 | - ) { |
|
808 | - return $registration; |
|
809 | - } |
|
810 | - } |
|
811 | - // nothing valid found, so just return first thing from array of results |
|
812 | - return reset($registrations); |
|
813 | - } |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * Gets the URL for viewing the receipt |
|
818 | - * |
|
819 | - * @param string $type 'pdf' or 'html' (default is 'html') |
|
820 | - * @return string |
|
821 | - * @throws EE_Error |
|
822 | - * @throws InvalidArgumentException |
|
823 | - * @throws InvalidDataTypeException |
|
824 | - * @throws InvalidInterfaceException |
|
825 | - * @throws ReflectionException |
|
826 | - */ |
|
827 | - public function receipt_url($type = 'html') |
|
828 | - { |
|
829 | - $REG = $this->primary_registration(); |
|
830 | - if (! $REG instanceof EE_Registration) { |
|
831 | - return ''; |
|
832 | - } |
|
833 | - return $REG->receipt_url($type); |
|
834 | - } |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
839 | - * a query parameter |
|
840 | - * |
|
841 | - * @return string |
|
842 | - * @throws EE_Error |
|
843 | - * @throws InvalidArgumentException |
|
844 | - * @throws InvalidDataTypeException |
|
845 | - * @throws InvalidInterfaceException |
|
846 | - * @throws ReflectionException |
|
847 | - */ |
|
848 | - public function payment_overview_url() |
|
849 | - { |
|
850 | - $primary_registration = $this->primary_registration(); |
|
851 | - return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
852 | - } |
|
853 | - |
|
854 | - |
|
855 | - /** |
|
856 | - * @return string |
|
857 | - * @throws EE_Error |
|
858 | - * @throws InvalidArgumentException |
|
859 | - * @throws InvalidDataTypeException |
|
860 | - * @throws InvalidInterfaceException |
|
861 | - * @throws ReflectionException |
|
862 | - */ |
|
863 | - public function gateway_response_on_transaction() |
|
864 | - { |
|
865 | - $payment = $this->get_first_related('Payment'); |
|
866 | - return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
867 | - } |
|
868 | - |
|
869 | - |
|
870 | - /** |
|
871 | - * Get the status object of this object |
|
872 | - * |
|
873 | - * @return EE_Base_Class|EE_Status |
|
874 | - * @throws EE_Error |
|
875 | - * @throws InvalidArgumentException |
|
876 | - * @throws InvalidDataTypeException |
|
877 | - * @throws InvalidInterfaceException |
|
878 | - * @throws ReflectionException |
|
879 | - */ |
|
880 | - public function status_obj() |
|
881 | - { |
|
882 | - return $this->get_first_related('Status'); |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - /** |
|
887 | - * Gets all the extra meta info on this payment |
|
888 | - * |
|
889 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
890 | - * @return EE_Base_Class[]|EE_Extra_Meta |
|
891 | - * @throws EE_Error |
|
892 | - * @throws InvalidArgumentException |
|
893 | - * @throws InvalidDataTypeException |
|
894 | - * @throws InvalidInterfaceException |
|
895 | - * @throws ReflectionException |
|
896 | - */ |
|
897 | - public function extra_meta($query_params = array()) |
|
898 | - { |
|
899 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
900 | - } |
|
901 | - |
|
902 | - |
|
903 | - /** |
|
904 | - * Wrapper for _add_relation_to |
|
905 | - * |
|
906 | - * @param EE_Registration $registration |
|
907 | - * @return EE_Base_Class the relation was added to |
|
908 | - * @throws EE_Error |
|
909 | - * @throws InvalidArgumentException |
|
910 | - * @throws InvalidDataTypeException |
|
911 | - * @throws InvalidInterfaceException |
|
912 | - * @throws ReflectionException |
|
913 | - */ |
|
914 | - public function add_registration(EE_Registration $registration) |
|
915 | - { |
|
916 | - return $this->_add_relation_to($registration, 'Registration'); |
|
917 | - } |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * Removes the given registration from being related (even before saving this transaction). |
|
922 | - * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
923 | - * |
|
924 | - * @param int $registration_or_id |
|
925 | - * @return EE_Base_Class that was removed from being related |
|
926 | - * @throws EE_Error |
|
927 | - * @throws InvalidArgumentException |
|
928 | - * @throws InvalidDataTypeException |
|
929 | - * @throws InvalidInterfaceException |
|
930 | - * @throws ReflectionException |
|
931 | - */ |
|
932 | - public function remove_registration_with_id($registration_or_id) |
|
933 | - { |
|
934 | - return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
935 | - } |
|
936 | - |
|
937 | - |
|
938 | - /** |
|
939 | - * Gets all the line items which are for ACTUAL items |
|
940 | - * |
|
941 | - * @return EE_Line_Item[] |
|
942 | - * @throws EE_Error |
|
943 | - * @throws InvalidArgumentException |
|
944 | - * @throws InvalidDataTypeException |
|
945 | - * @throws InvalidInterfaceException |
|
946 | - * @throws ReflectionException |
|
947 | - */ |
|
948 | - public function items_purchased() |
|
949 | - { |
|
950 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
951 | - } |
|
952 | - |
|
953 | - |
|
954 | - /** |
|
955 | - * Wrapper for _add_relation_to |
|
956 | - * |
|
957 | - * @param EE_Line_Item $line_item |
|
958 | - * @return EE_Base_Class the relation was added to |
|
959 | - * @throws EE_Error |
|
960 | - * @throws InvalidArgumentException |
|
961 | - * @throws InvalidDataTypeException |
|
962 | - * @throws InvalidInterfaceException |
|
963 | - * @throws ReflectionException |
|
964 | - */ |
|
965 | - public function add_line_item(EE_Line_Item $line_item) |
|
966 | - { |
|
967 | - return $this->_add_relation_to($line_item, 'Line_Item'); |
|
968 | - } |
|
969 | - |
|
970 | - |
|
971 | - /** |
|
972 | - * Gets ALL the line items related to this transaction (unstructured) |
|
973 | - * |
|
974 | - * @param array $query_params |
|
975 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
976 | - * @throws EE_Error |
|
977 | - * @throws InvalidArgumentException |
|
978 | - * @throws InvalidDataTypeException |
|
979 | - * @throws InvalidInterfaceException |
|
980 | - * @throws ReflectionException |
|
981 | - */ |
|
982 | - public function line_items($query_params = array()) |
|
983 | - { |
|
984 | - return $this->get_many_related('Line_Item', $query_params); |
|
985 | - } |
|
986 | - |
|
987 | - |
|
988 | - /** |
|
989 | - * Gets all the line items which are taxes on the total |
|
990 | - * |
|
991 | - * @return EE_Line_Item[] |
|
992 | - * @throws EE_Error |
|
993 | - * @throws InvalidArgumentException |
|
994 | - * @throws InvalidDataTypeException |
|
995 | - * @throws InvalidInterfaceException |
|
996 | - * @throws ReflectionException |
|
997 | - */ |
|
998 | - public function tax_items() |
|
999 | - { |
|
1000 | - return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
1001 | - } |
|
1002 | - |
|
1003 | - |
|
1004 | - /** |
|
1005 | - * Gets the total line item (which is a parent of all other related line items, |
|
1006 | - * meaning it takes them all into account on its total) |
|
1007 | - * |
|
1008 | - * @param bool $create_if_not_found |
|
1009 | - * @return \EE_Line_Item |
|
1010 | - * @throws EE_Error |
|
1011 | - * @throws InvalidArgumentException |
|
1012 | - * @throws InvalidDataTypeException |
|
1013 | - * @throws InvalidInterfaceException |
|
1014 | - * @throws ReflectionException |
|
1015 | - */ |
|
1016 | - public function total_line_item($create_if_not_found = true) |
|
1017 | - { |
|
1018 | - $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
1019 | - if (! $item && $create_if_not_found) { |
|
1020 | - $item = EEH_Line_Item::create_total_line_item($this); |
|
1021 | - } |
|
1022 | - return $item; |
|
1023 | - } |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * Returns the total amount of tax on this transaction |
|
1028 | - * (assumes there's only one tax subtotal line item) |
|
1029 | - * |
|
1030 | - * @return float |
|
1031 | - * @throws EE_Error |
|
1032 | - * @throws InvalidArgumentException |
|
1033 | - * @throws InvalidDataTypeException |
|
1034 | - * @throws InvalidInterfaceException |
|
1035 | - * @throws ReflectionException |
|
1036 | - */ |
|
1037 | - public function tax_total() |
|
1038 | - { |
|
1039 | - $tax_line_item = $this->tax_total_line_item(); |
|
1040 | - if ($tax_line_item) { |
|
1041 | - return (float) $tax_line_item->total(); |
|
1042 | - } |
|
1043 | - return (float) 0; |
|
1044 | - } |
|
1045 | - |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * Gets the tax subtotal line item (assumes there's only one) |
|
1049 | - * |
|
1050 | - * @return EE_Line_Item |
|
1051 | - * @throws EE_Error |
|
1052 | - * @throws InvalidArgumentException |
|
1053 | - * @throws InvalidDataTypeException |
|
1054 | - * @throws InvalidInterfaceException |
|
1055 | - * @throws ReflectionException |
|
1056 | - */ |
|
1057 | - public function tax_total_line_item() |
|
1058 | - { |
|
1059 | - return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
1060 | - } |
|
1061 | - |
|
1062 | - |
|
1063 | - /** |
|
1064 | - * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
1065 | - * |
|
1066 | - * @return EE_Form_Section_Proper |
|
1067 | - * @throws EE_Error |
|
1068 | - * @throws InvalidArgumentException |
|
1069 | - * @throws InvalidDataTypeException |
|
1070 | - * @throws InvalidInterfaceException |
|
1071 | - * @throws ReflectionException |
|
1072 | - */ |
|
1073 | - public function billing_info() |
|
1074 | - { |
|
1075 | - $payment_method = $this->payment_method(); |
|
1076 | - if (! $payment_method) { |
|
1077 | - EE_Error::add_error( |
|
1078 | - __( |
|
1079 | - 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
1080 | - 'event_espresso' |
|
1081 | - ), |
|
1082 | - __FILE__, |
|
1083 | - __FUNCTION__, |
|
1084 | - __LINE__ |
|
1085 | - ); |
|
1086 | - return null; |
|
1087 | - } |
|
1088 | - $primary_reg = $this->primary_registration(); |
|
1089 | - if (! $primary_reg) { |
|
1090 | - EE_Error::add_error( |
|
1091 | - __( |
|
1092 | - 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
1093 | - 'event_espresso' |
|
1094 | - ), |
|
1095 | - __FILE__, |
|
1096 | - __FUNCTION__, |
|
1097 | - __LINE__ |
|
1098 | - ); |
|
1099 | - return null; |
|
1100 | - } |
|
1101 | - $attendee = $primary_reg->attendee(); |
|
1102 | - if (! $attendee) { |
|
1103 | - EE_Error::add_error( |
|
1104 | - __( |
|
1105 | - 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
1106 | - 'event_espresso' |
|
1107 | - ), |
|
1108 | - __FILE__, |
|
1109 | - __FUNCTION__, |
|
1110 | - __LINE__ |
|
1111 | - ); |
|
1112 | - return null; |
|
1113 | - } |
|
1114 | - return $attendee->billing_info_for_payment_method($payment_method); |
|
1115 | - } |
|
1116 | - |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * Gets PMD_ID |
|
1120 | - * |
|
1121 | - * @return int |
|
1122 | - * @throws EE_Error |
|
1123 | - * @throws InvalidArgumentException |
|
1124 | - * @throws InvalidDataTypeException |
|
1125 | - * @throws InvalidInterfaceException |
|
1126 | - * @throws ReflectionException |
|
1127 | - */ |
|
1128 | - public function payment_method_ID() |
|
1129 | - { |
|
1130 | - return $this->get('PMD_ID'); |
|
1131 | - } |
|
1132 | - |
|
1133 | - |
|
1134 | - /** |
|
1135 | - * Sets PMD_ID |
|
1136 | - * |
|
1137 | - * @param int $PMD_ID |
|
1138 | - * @throws EE_Error |
|
1139 | - * @throws InvalidArgumentException |
|
1140 | - * @throws InvalidDataTypeException |
|
1141 | - * @throws InvalidInterfaceException |
|
1142 | - * @throws ReflectionException |
|
1143 | - */ |
|
1144 | - public function set_payment_method_ID($PMD_ID) |
|
1145 | - { |
|
1146 | - $this->set('PMD_ID', $PMD_ID); |
|
1147 | - } |
|
1148 | - |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * Gets the last-used payment method on this transaction |
|
1152 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
1153 | - * offline ones, dont' create payments) |
|
1154 | - * |
|
1155 | - * @return EE_Payment_Method |
|
1156 | - * @throws EE_Error |
|
1157 | - * @throws InvalidArgumentException |
|
1158 | - * @throws InvalidDataTypeException |
|
1159 | - * @throws InvalidInterfaceException |
|
1160 | - * @throws ReflectionException |
|
1161 | - */ |
|
1162 | - public function payment_method() |
|
1163 | - { |
|
1164 | - $pm = $this->get_first_related('Payment_Method'); |
|
1165 | - if ($pm instanceof EE_Payment_Method) { |
|
1166 | - return $pm; |
|
1167 | - } |
|
1168 | - $last_payment = $this->last_payment(); |
|
1169 | - if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
1170 | - return $last_payment->payment_method(); |
|
1171 | - } |
|
1172 | - return null; |
|
1173 | - } |
|
1174 | - |
|
1175 | - |
|
1176 | - /** |
|
1177 | - * Gets the last payment made |
|
1178 | - * |
|
1179 | - * @return EE_Base_Class|EE_Payment |
|
1180 | - * @throws EE_Error |
|
1181 | - * @throws InvalidArgumentException |
|
1182 | - * @throws InvalidDataTypeException |
|
1183 | - * @throws InvalidInterfaceException |
|
1184 | - * @throws ReflectionException |
|
1185 | - */ |
|
1186 | - public function last_payment() |
|
1187 | - { |
|
1188 | - return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
1189 | - } |
|
1190 | - |
|
1191 | - |
|
1192 | - /** |
|
1193 | - * Gets all the line items which are unrelated to tickets on this transaction |
|
1194 | - * |
|
1195 | - * @return EE_Line_Item[] |
|
1196 | - * @throws EE_Error |
|
1197 | - * @throws InvalidArgumentException |
|
1198 | - * @throws InvalidDataTypeException |
|
1199 | - * @throws InvalidInterfaceException |
|
1200 | - * @throws ReflectionException |
|
1201 | - */ |
|
1202 | - public function non_ticket_line_items() |
|
1203 | - { |
|
1204 | - return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
1205 | - } |
|
1206 | - |
|
1207 | - |
|
1208 | - /** |
|
1209 | - * possibly toggles TXN status |
|
1210 | - * |
|
1211 | - * @param boolean $update whether to save the TXN |
|
1212 | - * @return bool whether the TXN was saved |
|
1213 | - * @throws EE_Error |
|
1214 | - * @throws InvalidArgumentException |
|
1215 | - * @throws InvalidDataTypeException |
|
1216 | - * @throws InvalidInterfaceException |
|
1217 | - * @throws ReflectionException |
|
1218 | - * @throws RuntimeException |
|
1219 | - */ |
|
1220 | - public function update_status_based_on_total_paid($update = true) |
|
1221 | - { |
|
1222 | - // set transaction status based on comparison of TXN_paid vs TXN_total |
|
1223 | - if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
1224 | - $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
1225 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
1226 | - $new_txn_status = EEM_Transaction::complete_status_code; |
|
1227 | - } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
1228 | - $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
1229 | - } else { |
|
1230 | - throw new RuntimeException( |
|
1231 | - __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
1232 | - ); |
|
1233 | - } |
|
1234 | - if ($new_txn_status !== $this->status_ID()) { |
|
1235 | - $this->set_status($new_txn_status); |
|
1236 | - if ($update) { |
|
1237 | - return $this->save() ? true : false; |
|
1238 | - } |
|
1239 | - } |
|
1240 | - return false; |
|
1241 | - } |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * Updates the transaction's status and total_paid based on all the payments |
|
1246 | - * that apply to it |
|
1247 | - * |
|
1248 | - * @deprecated |
|
1249 | - * @return array|bool |
|
1250 | - * @throws EE_Error |
|
1251 | - * @throws InvalidArgumentException |
|
1252 | - * @throws ReflectionException |
|
1253 | - * @throws InvalidDataTypeException |
|
1254 | - * @throws InvalidInterfaceException |
|
1255 | - */ |
|
1256 | - public function update_based_on_payments() |
|
1257 | - { |
|
1258 | - EE_Error::doing_it_wrong( |
|
1259 | - __CLASS__ . '::' . __FUNCTION__, |
|
1260 | - sprintf( |
|
1261 | - __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
1262 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
1263 | - ), |
|
1264 | - '4.6.0' |
|
1265 | - ); |
|
1266 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
1267 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1268 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
1269 | - } |
|
1270 | - |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * @return string |
|
1274 | - */ |
|
1275 | - public function old_txn_status() |
|
1276 | - { |
|
1277 | - return $this->_old_txn_status; |
|
1278 | - } |
|
1279 | - |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * @param string $old_txn_status |
|
1283 | - */ |
|
1284 | - public function set_old_txn_status($old_txn_status) |
|
1285 | - { |
|
1286 | - // only set the first time |
|
1287 | - if ($this->_old_txn_status === null) { |
|
1288 | - $this->_old_txn_status = $old_txn_status; |
|
1289 | - } |
|
1290 | - } |
|
1291 | - |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * reg_status_updated |
|
1295 | - * |
|
1296 | - * @return bool |
|
1297 | - * @throws EE_Error |
|
1298 | - * @throws InvalidArgumentException |
|
1299 | - * @throws InvalidDataTypeException |
|
1300 | - * @throws InvalidInterfaceException |
|
1301 | - * @throws ReflectionException |
|
1302 | - */ |
|
1303 | - public function txn_status_updated() |
|
1304 | - { |
|
1305 | - return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
1306 | - } |
|
1307 | - |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * _reg_steps_completed |
|
1311 | - * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
1312 | - * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
1313 | - * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
1314 | - * |
|
1315 | - * @param string $reg_step_slug |
|
1316 | - * @param bool $check_all |
|
1317 | - * @return bool|int |
|
1318 | - * @throws EE_Error |
|
1319 | - * @throws InvalidArgumentException |
|
1320 | - * @throws InvalidDataTypeException |
|
1321 | - * @throws InvalidInterfaceException |
|
1322 | - * @throws ReflectionException |
|
1323 | - */ |
|
1324 | - private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
1325 | - { |
|
1326 | - $reg_steps = $this->reg_steps(); |
|
1327 | - if (! is_array($reg_steps) || empty($reg_steps)) { |
|
1328 | - return false; |
|
1329 | - } |
|
1330 | - // loop thru reg steps array) |
|
1331 | - foreach ($reg_steps as $slug => $reg_step_completed) { |
|
1332 | - // if NOT checking ALL steps (only checking one step) |
|
1333 | - if (! $check_all) { |
|
1334 | - // and this is the one |
|
1335 | - if ($slug === $reg_step_slug) { |
|
1336 | - return $reg_step_completed; |
|
1337 | - } |
|
1338 | - // skip to next reg step in loop |
|
1339 | - continue; |
|
1340 | - } |
|
1341 | - // $check_all must be true, else we would never have gotten to this point |
|
1342 | - if ($slug === $reg_step_slug) { |
|
1343 | - // if we reach this point, then we are testing either: |
|
1344 | - // all_reg_steps_completed_except() or |
|
1345 | - // all_reg_steps_completed_except_final_step(), |
|
1346 | - // and since this is the reg step EXCEPTION being tested |
|
1347 | - // we want to return true (yes true) if this reg step is NOT completed |
|
1348 | - // ie: "is everything completed except the final step?" |
|
1349 | - // "that is correct... the final step is not completed, but all others are." |
|
1350 | - return $reg_step_completed !== true; |
|
1351 | - } |
|
1352 | - if ($reg_step_completed !== true) { |
|
1353 | - // if any reg step is NOT completed, then ALL steps are not completed |
|
1354 | - return false; |
|
1355 | - } |
|
1356 | - } |
|
1357 | - return true; |
|
1358 | - } |
|
1359 | - |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * all_reg_steps_completed |
|
1363 | - * returns: |
|
1364 | - * true if ALL reg steps have been marked as completed |
|
1365 | - * or false if any step is not completed |
|
1366 | - * |
|
1367 | - * @return bool |
|
1368 | - * @throws EE_Error |
|
1369 | - * @throws InvalidArgumentException |
|
1370 | - * @throws InvalidDataTypeException |
|
1371 | - * @throws InvalidInterfaceException |
|
1372 | - * @throws ReflectionException |
|
1373 | - */ |
|
1374 | - public function all_reg_steps_completed() |
|
1375 | - { |
|
1376 | - return $this->_reg_steps_completed(); |
|
1377 | - } |
|
1378 | - |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * all_reg_steps_completed_except |
|
1382 | - * returns: |
|
1383 | - * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
1384 | - * or false if any other step is not completed |
|
1385 | - * or false if ALL steps are completed including the exception you are testing !!! |
|
1386 | - * |
|
1387 | - * @param string $exception |
|
1388 | - * @return bool |
|
1389 | - * @throws EE_Error |
|
1390 | - * @throws InvalidArgumentException |
|
1391 | - * @throws InvalidDataTypeException |
|
1392 | - * @throws InvalidInterfaceException |
|
1393 | - * @throws ReflectionException |
|
1394 | - */ |
|
1395 | - public function all_reg_steps_completed_except($exception = '') |
|
1396 | - { |
|
1397 | - return $this->_reg_steps_completed($exception); |
|
1398 | - } |
|
1399 | - |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * all_reg_steps_completed_except |
|
1403 | - * returns: |
|
1404 | - * true if ALL reg steps, except the final step, have been marked as completed |
|
1405 | - * or false if any step is not completed |
|
1406 | - * or false if ALL steps are completed including the final step !!! |
|
1407 | - * |
|
1408 | - * @return bool |
|
1409 | - * @throws EE_Error |
|
1410 | - * @throws InvalidArgumentException |
|
1411 | - * @throws InvalidDataTypeException |
|
1412 | - * @throws InvalidInterfaceException |
|
1413 | - * @throws ReflectionException |
|
1414 | - */ |
|
1415 | - public function all_reg_steps_completed_except_final_step() |
|
1416 | - { |
|
1417 | - return $this->_reg_steps_completed('finalize_registration'); |
|
1418 | - } |
|
1419 | - |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * reg_step_completed |
|
1423 | - * returns: |
|
1424 | - * true if a specific reg step has been marked as completed |
|
1425 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
1426 | - * or false if it has not yet been initialized |
|
1427 | - * |
|
1428 | - * @param string $reg_step_slug |
|
1429 | - * @return bool|int |
|
1430 | - * @throws EE_Error |
|
1431 | - * @throws InvalidArgumentException |
|
1432 | - * @throws InvalidDataTypeException |
|
1433 | - * @throws InvalidInterfaceException |
|
1434 | - * @throws ReflectionException |
|
1435 | - */ |
|
1436 | - public function reg_step_completed($reg_step_slug) |
|
1437 | - { |
|
1438 | - return $this->_reg_steps_completed($reg_step_slug, false); |
|
1439 | - } |
|
1440 | - |
|
1441 | - |
|
1442 | - /** |
|
1443 | - * completed_final_reg_step |
|
1444 | - * returns: |
|
1445 | - * true if the finalize_registration reg step has been marked as completed |
|
1446 | - * a Unix timestamp if it has been initialized but not yet completed, |
|
1447 | - * or false if it has not yet been initialized |
|
1448 | - * |
|
1449 | - * @return bool|int |
|
1450 | - * @throws EE_Error |
|
1451 | - * @throws InvalidArgumentException |
|
1452 | - * @throws InvalidDataTypeException |
|
1453 | - * @throws InvalidInterfaceException |
|
1454 | - * @throws ReflectionException |
|
1455 | - */ |
|
1456 | - public function final_reg_step_completed() |
|
1457 | - { |
|
1458 | - return $this->_reg_steps_completed('finalize_registration', false); |
|
1459 | - } |
|
1460 | - |
|
1461 | - |
|
1462 | - /** |
|
1463 | - * set_reg_step_initiated |
|
1464 | - * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
1465 | - * |
|
1466 | - * @param string $reg_step_slug |
|
1467 | - * @return boolean |
|
1468 | - * @throws EE_Error |
|
1469 | - * @throws InvalidArgumentException |
|
1470 | - * @throws InvalidDataTypeException |
|
1471 | - * @throws InvalidInterfaceException |
|
1472 | - * @throws ReflectionException |
|
1473 | - */ |
|
1474 | - public function set_reg_step_initiated($reg_step_slug) |
|
1475 | - { |
|
1476 | - return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
1477 | - } |
|
1478 | - |
|
1479 | - |
|
1480 | - /** |
|
1481 | - * set_reg_step_completed |
|
1482 | - * given a valid TXN_reg_step, this sets the step as completed |
|
1483 | - * |
|
1484 | - * @param string $reg_step_slug |
|
1485 | - * @return boolean |
|
1486 | - * @throws EE_Error |
|
1487 | - * @throws InvalidArgumentException |
|
1488 | - * @throws InvalidDataTypeException |
|
1489 | - * @throws InvalidInterfaceException |
|
1490 | - * @throws ReflectionException |
|
1491 | - */ |
|
1492 | - public function set_reg_step_completed($reg_step_slug) |
|
1493 | - { |
|
1494 | - return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
1495 | - } |
|
1496 | - |
|
1497 | - |
|
1498 | - /** |
|
1499 | - * set_reg_step_completed |
|
1500 | - * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
1501 | - * |
|
1502 | - * @param string $reg_step_slug |
|
1503 | - * @return boolean |
|
1504 | - * @throws EE_Error |
|
1505 | - * @throws InvalidArgumentException |
|
1506 | - * @throws InvalidDataTypeException |
|
1507 | - * @throws InvalidInterfaceException |
|
1508 | - * @throws ReflectionException |
|
1509 | - */ |
|
1510 | - public function set_reg_step_not_completed($reg_step_slug) |
|
1511 | - { |
|
1512 | - return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
1513 | - } |
|
1514 | - |
|
1515 | - |
|
1516 | - /** |
|
1517 | - * set_reg_step_completed |
|
1518 | - * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
1519 | - * |
|
1520 | - * @param string $reg_step_slug |
|
1521 | - * @param boolean|int $status |
|
1522 | - * @return boolean |
|
1523 | - * @throws EE_Error |
|
1524 | - * @throws InvalidArgumentException |
|
1525 | - * @throws InvalidDataTypeException |
|
1526 | - * @throws InvalidInterfaceException |
|
1527 | - * @throws ReflectionException |
|
1528 | - */ |
|
1529 | - private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
1530 | - { |
|
1531 | - // validate status |
|
1532 | - $status = is_bool($status) || is_int($status) ? $status : false; |
|
1533 | - // get reg steps array |
|
1534 | - $txn_reg_steps = $this->reg_steps(); |
|
1535 | - // if reg step does NOT exist |
|
1536 | - if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
1537 | - return false; |
|
1538 | - } |
|
1539 | - // if we're trying to complete a step that is already completed |
|
1540 | - if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
1541 | - return true; |
|
1542 | - } |
|
1543 | - // if we're trying to complete a step that hasn't even started |
|
1544 | - if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
1545 | - return false; |
|
1546 | - } |
|
1547 | - // if current status value matches the incoming value (no change) |
|
1548 | - // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
1549 | - if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
1550 | - // this will happen in cases where multiple AJAX requests occur during the same step |
|
1551 | - return true; |
|
1552 | - } |
|
1553 | - // if we're trying to set a start time, but it has already been set... |
|
1554 | - if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
1555 | - // skip the update below, but don't return FALSE so that errors won't be displayed |
|
1556 | - return true; |
|
1557 | - } |
|
1558 | - // update completed status |
|
1559 | - $txn_reg_steps[ $reg_step_slug ] = $status; |
|
1560 | - $this->set_reg_steps($txn_reg_steps); |
|
1561 | - $this->save(); |
|
1562 | - return true; |
|
1563 | - } |
|
1564 | - |
|
1565 | - |
|
1566 | - /** |
|
1567 | - * remove_reg_step |
|
1568 | - * given a valid TXN_reg_step slug, this will remove (unset) |
|
1569 | - * the reg step from the TXN reg step array |
|
1570 | - * |
|
1571 | - * @param string $reg_step_slug |
|
1572 | - * @return void |
|
1573 | - * @throws EE_Error |
|
1574 | - * @throws InvalidArgumentException |
|
1575 | - * @throws InvalidDataTypeException |
|
1576 | - * @throws InvalidInterfaceException |
|
1577 | - * @throws ReflectionException |
|
1578 | - */ |
|
1579 | - public function remove_reg_step($reg_step_slug) |
|
1580 | - { |
|
1581 | - // get reg steps array |
|
1582 | - $txn_reg_steps = $this->reg_steps(); |
|
1583 | - unset($txn_reg_steps[ $reg_step_slug ]); |
|
1584 | - $this->set_reg_steps($txn_reg_steps); |
|
1585 | - } |
|
1586 | - |
|
1587 | - |
|
1588 | - /** |
|
1589 | - * toggle_failed_transaction_status |
|
1590 | - * upgrades a TXNs status from failed to abandoned, |
|
1591 | - * meaning that contact information has been captured for at least one registrant |
|
1592 | - * |
|
1593 | - * @param bool $save |
|
1594 | - * @return bool |
|
1595 | - * @throws EE_Error |
|
1596 | - * @throws InvalidArgumentException |
|
1597 | - * @throws InvalidDataTypeException |
|
1598 | - * @throws InvalidInterfaceException |
|
1599 | - * @throws ReflectionException |
|
1600 | - */ |
|
1601 | - public function toggle_failed_transaction_status($save = true) |
|
1602 | - { |
|
1603 | - // if TXN status is still set as "failed"... |
|
1604 | - if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
1605 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1606 | - if ($save) { |
|
1607 | - $this->save(); |
|
1608 | - } |
|
1609 | - return true; |
|
1610 | - } |
|
1611 | - return false; |
|
1612 | - } |
|
1613 | - |
|
1614 | - |
|
1615 | - /** |
|
1616 | - * toggle_abandoned_transaction_status |
|
1617 | - * upgrades a TXNs status from failed or abandoned to incomplete |
|
1618 | - * |
|
1619 | - * @return bool |
|
1620 | - * @throws EE_Error |
|
1621 | - * @throws InvalidArgumentException |
|
1622 | - * @throws InvalidDataTypeException |
|
1623 | - * @throws InvalidInterfaceException |
|
1624 | - * @throws ReflectionException |
|
1625 | - */ |
|
1626 | - public function toggle_abandoned_transaction_status() |
|
1627 | - { |
|
1628 | - // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
1629 | - $txn_status = $this->status_ID(); |
|
1630 | - if ($txn_status === EEM_Transaction::failed_status_code |
|
1631 | - || $txn_status === EEM_Transaction::abandoned_status_code |
|
1632 | - ) { |
|
1633 | - // if a contact record for the primary registrant has been created |
|
1634 | - if ($this->primary_registration() instanceof EE_Registration |
|
1635 | - && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
1636 | - ) { |
|
1637 | - $this->set_status(EEM_Transaction::incomplete_status_code); |
|
1638 | - } else { |
|
1639 | - // no contact record? yer abandoned! |
|
1640 | - $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1641 | - } |
|
1642 | - return true; |
|
1643 | - } |
|
1644 | - return false; |
|
1645 | - } |
|
1646 | - |
|
1647 | - |
|
1648 | - /** |
|
1649 | - * checks if an Abandoned TXN has any related payments, and if so, |
|
1650 | - * updates the TXN status based on the amount paid |
|
1651 | - * |
|
1652 | - * @throws EE_Error |
|
1653 | - * @throws InvalidDataTypeException |
|
1654 | - * @throws InvalidInterfaceException |
|
1655 | - * @throws InvalidArgumentException |
|
1656 | - * @throws RuntimeException |
|
1657 | - * @throws ReflectionException |
|
1658 | - */ |
|
1659 | - public function verify_abandoned_transaction_status() |
|
1660 | - { |
|
1661 | - if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
1662 | - return; |
|
1663 | - } |
|
1664 | - $payments = $this->get_many_related('Payment'); |
|
1665 | - if (! empty($payments)) { |
|
1666 | - foreach ($payments as $payment) { |
|
1667 | - if ($payment instanceof EE_Payment) { |
|
1668 | - // kk this TXN should NOT be abandoned |
|
1669 | - $this->update_status_based_on_total_paid(); |
|
1670 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1671 | - EE_Error::add_attention( |
|
1672 | - sprintf( |
|
1673 | - esc_html__( |
|
1674 | - 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
1675 | - 'event_espresso' |
|
1676 | - ), |
|
1677 | - $this->ID(), |
|
1678 | - $this->pretty_status() |
|
1679 | - ) |
|
1680 | - ); |
|
1681 | - } |
|
1682 | - // get final reg step status |
|
1683 | - $finalized = $this->final_reg_step_completed(); |
|
1684 | - // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
1685 | - // but has not yet been fully completed (TRUE) |
|
1686 | - if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
1687 | - $this->set_reg_step_completed('finalize_registration'); |
|
1688 | - $this->save(); |
|
1689 | - } |
|
1690 | - } |
|
1691 | - } |
|
1692 | - } |
|
1693 | - } |
|
1694 | - |
|
1695 | - |
|
1696 | - /** |
|
1697 | - * @since 4.10.4.p |
|
1698 | - * @throws EE_Error |
|
1699 | - * @throws InvalidArgumentException |
|
1700 | - * @throws InvalidDataTypeException |
|
1701 | - * @throws InvalidInterfaceException |
|
1702 | - * @throws ReflectionException |
|
1703 | - * @throws RuntimeException |
|
1704 | - */ |
|
1705 | - public function recalculateLineItems() |
|
1706 | - { |
|
1707 | - $total_line_item = $this->total_line_item(false); |
|
1708 | - if ($total_line_item instanceof EE_Line_Item) { |
|
1709 | - EEH_Line_Item::resetIsTaxableForTickets($total_line_item); |
|
1710 | - return EEH_Line_Item::apply_taxes($total_line_item, true); |
|
1711 | - } |
|
1712 | - return false; |
|
1713 | - } |
|
16 | + /** |
|
17 | + * The length of time in seconds that a lock is applied before being considered expired. |
|
18 | + * It is not long because a transaction should only be locked for the duration of the request that locked it |
|
19 | + */ |
|
20 | + const LOCK_EXPIRATION = 2; |
|
21 | + |
|
22 | + /** |
|
23 | + * txn status upon initial construction. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_old_txn_status; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param array $props_n_values incoming values |
|
32 | + * @param string $timezone incoming timezone |
|
33 | + * (if not set the timezone set for the website will be used.) |
|
34 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
35 | + * date_format and the second value is the time format |
|
36 | + * @return EE_Transaction |
|
37 | + * @throws EE_Error |
|
38 | + * @throws InvalidArgumentException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidInterfaceException |
|
41 | + * @throws ReflectionException |
|
42 | + */ |
|
43 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
44 | + { |
|
45 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
46 | + $txn = $has_object |
|
47 | + ? $has_object |
|
48 | + : new self($props_n_values, false, $timezone, $date_formats); |
|
49 | + if (! $has_object) { |
|
50 | + $txn->set_old_txn_status($txn->status_ID()); |
|
51 | + } |
|
52 | + return $txn; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param array $props_n_values incoming values from the database |
|
58 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
59 | + * the website will be used. |
|
60 | + * @return EE_Transaction |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + * @throws ReflectionException |
|
66 | + */ |
|
67 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
68 | + { |
|
69 | + $txn = new self($props_n_values, true, $timezone); |
|
70 | + $txn->set_old_txn_status($txn->status_ID()); |
|
71 | + return $txn; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * Sets a meta field indicating that this TXN is locked and should not be updated in the db. |
|
77 | + * If a lock has already been set, then we will attempt to remove it in case it has expired. |
|
78 | + * If that also fails, then an exception is thrown. |
|
79 | + * |
|
80 | + * @throws EE_Error |
|
81 | + * @throws InvalidArgumentException |
|
82 | + * @throws InvalidDataTypeException |
|
83 | + * @throws InvalidInterfaceException |
|
84 | + * @throws ReflectionException |
|
85 | + */ |
|
86 | + public function lock() |
|
87 | + { |
|
88 | + // attempt to set lock, but if that fails... |
|
89 | + if (! $this->add_extra_meta('lock', time(), true)) { |
|
90 | + // then attempt to remove the lock in case it is expired |
|
91 | + if ($this->_remove_expired_lock()) { |
|
92 | + // if removal was successful, then try setting lock again |
|
93 | + $this->lock(); |
|
94 | + } else { |
|
95 | + // but if the lock can not be removed, then throw an exception |
|
96 | + throw new EE_Error( |
|
97 | + sprintf( |
|
98 | + __( |
|
99 | + 'Could not lock Transaction %1$d because it is already locked, meaning another part of the system is currently editing it. It should already be unlocked by the time you read this, so please refresh the page and try again.', |
|
100 | + 'event_espresso' |
|
101 | + ), |
|
102 | + $this->ID() |
|
103 | + ) |
|
104 | + ); |
|
105 | + } |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * removes transaction lock applied in EE_Transaction::lock() |
|
112 | + * |
|
113 | + * @return int |
|
114 | + * @throws EE_Error |
|
115 | + * @throws InvalidArgumentException |
|
116 | + * @throws InvalidDataTypeException |
|
117 | + * @throws InvalidInterfaceException |
|
118 | + * @throws ReflectionException |
|
119 | + */ |
|
120 | + public function unlock() |
|
121 | + { |
|
122 | + return $this->delete_extra_meta('lock'); |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * Decides whether or not now is the right time to update the transaction. |
|
128 | + * This is useful because we don't always know if it is safe to update the transaction |
|
129 | + * and its related data. why? |
|
130 | + * because it's possible that the transaction is being used in another |
|
131 | + * request and could overwrite anything we save. |
|
132 | + * So we want to only update the txn once we know that won't happen. |
|
133 | + * We also check that the lock isn't expired, and remove it if it is |
|
134 | + * |
|
135 | + * @return boolean |
|
136 | + * @throws EE_Error |
|
137 | + * @throws InvalidArgumentException |
|
138 | + * @throws InvalidDataTypeException |
|
139 | + * @throws InvalidInterfaceException |
|
140 | + * @throws ReflectionException |
|
141 | + */ |
|
142 | + public function is_locked() |
|
143 | + { |
|
144 | + // if TXN is not locked, then return false immediately |
|
145 | + if (! $this->_get_lock()) { |
|
146 | + return false; |
|
147 | + } |
|
148 | + // if not, then let's try and remove the lock in case it's expired... |
|
149 | + // _remove_expired_lock() returns 0 when lock is valid (ie: removed = false) |
|
150 | + // and a positive number if the lock was removed (ie: number of locks deleted), |
|
151 | + // so we need to return the opposite |
|
152 | + return ! $this->_remove_expired_lock() ? true : false; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Gets the meta field indicating that this TXN is locked |
|
158 | + * |
|
159 | + * @return int |
|
160 | + * @throws EE_Error |
|
161 | + * @throws InvalidArgumentException |
|
162 | + * @throws InvalidDataTypeException |
|
163 | + * @throws InvalidInterfaceException |
|
164 | + * @throws ReflectionException |
|
165 | + */ |
|
166 | + protected function _get_lock() |
|
167 | + { |
|
168 | + return (int) $this->get_extra_meta('lock', true, 0); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * If the lock on this transaction is expired, then we want to remove it so that the transaction can be updated |
|
174 | + * |
|
175 | + * @return int |
|
176 | + * @throws EE_Error |
|
177 | + * @throws InvalidArgumentException |
|
178 | + * @throws InvalidDataTypeException |
|
179 | + * @throws InvalidInterfaceException |
|
180 | + * @throws ReflectionException |
|
181 | + */ |
|
182 | + protected function _remove_expired_lock() |
|
183 | + { |
|
184 | + $locked = $this->_get_lock(); |
|
185 | + if ($locked && time() - EE_Transaction::LOCK_EXPIRATION > $locked) { |
|
186 | + return $this->unlock(); |
|
187 | + } |
|
188 | + return 0; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * Set transaction total |
|
194 | + * |
|
195 | + * @param float $total total value of transaction |
|
196 | + * @throws EE_Error |
|
197 | + * @throws InvalidArgumentException |
|
198 | + * @throws InvalidDataTypeException |
|
199 | + * @throws InvalidInterfaceException |
|
200 | + * @throws ReflectionException |
|
201 | + */ |
|
202 | + public function set_total($total = 0.00) |
|
203 | + { |
|
204 | + $this->set('TXN_total', (float) $total); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Set Total Amount Paid to Date |
|
210 | + * |
|
211 | + * @param float $total_paid total amount paid to date (sum of all payments) |
|
212 | + * @throws EE_Error |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws InvalidDataTypeException |
|
215 | + * @throws InvalidInterfaceException |
|
216 | + * @throws ReflectionException |
|
217 | + */ |
|
218 | + public function set_paid($total_paid = 0.00) |
|
219 | + { |
|
220 | + $this->set('TXN_paid', (float) $total_paid); |
|
221 | + } |
|
222 | + |
|
223 | + |
|
224 | + /** |
|
225 | + * Set transaction status |
|
226 | + * |
|
227 | + * @param string $status whether the transaction is open, declined, accepted, |
|
228 | + * or any number of custom values that can be set |
|
229 | + * @throws EE_Error |
|
230 | + * @throws InvalidArgumentException |
|
231 | + * @throws InvalidDataTypeException |
|
232 | + * @throws InvalidInterfaceException |
|
233 | + * @throws ReflectionException |
|
234 | + */ |
|
235 | + public function set_status($status = '') |
|
236 | + { |
|
237 | + $this->set('STS_ID', $status); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * Set hash salt |
|
243 | + * |
|
244 | + * @param string $hash_salt required for some payment gateways |
|
245 | + * @throws EE_Error |
|
246 | + * @throws InvalidArgumentException |
|
247 | + * @throws InvalidDataTypeException |
|
248 | + * @throws InvalidInterfaceException |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + public function set_hash_salt($hash_salt = '') |
|
252 | + { |
|
253 | + $this->set('TXN_hash_salt', $hash_salt); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Sets TXN_reg_steps array |
|
259 | + * |
|
260 | + * @param array $txn_reg_steps |
|
261 | + * @throws EE_Error |
|
262 | + * @throws InvalidArgumentException |
|
263 | + * @throws InvalidDataTypeException |
|
264 | + * @throws InvalidInterfaceException |
|
265 | + * @throws ReflectionException |
|
266 | + */ |
|
267 | + public function set_reg_steps(array $txn_reg_steps) |
|
268 | + { |
|
269 | + $this->set('TXN_reg_steps', $txn_reg_steps); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Gets TXN_reg_steps |
|
275 | + * |
|
276 | + * @return array |
|
277 | + * @throws EE_Error |
|
278 | + * @throws InvalidArgumentException |
|
279 | + * @throws InvalidDataTypeException |
|
280 | + * @throws InvalidInterfaceException |
|
281 | + * @throws ReflectionException |
|
282 | + */ |
|
283 | + public function reg_steps() |
|
284 | + { |
|
285 | + $TXN_reg_steps = $this->get('TXN_reg_steps'); |
|
286 | + return is_array($TXN_reg_steps) ? (array) $TXN_reg_steps : array(); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @return string of transaction's total cost, with currency symbol and decimal |
|
292 | + * @throws EE_Error |
|
293 | + * @throws InvalidArgumentException |
|
294 | + * @throws InvalidDataTypeException |
|
295 | + * @throws InvalidInterfaceException |
|
296 | + * @throws ReflectionException |
|
297 | + */ |
|
298 | + public function pretty_total() |
|
299 | + { |
|
300 | + return $this->get_pretty('TXN_total'); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Gets the amount paid in a pretty string (formatted and with currency symbol) |
|
306 | + * |
|
307 | + * @return string |
|
308 | + * @throws EE_Error |
|
309 | + * @throws InvalidArgumentException |
|
310 | + * @throws InvalidDataTypeException |
|
311 | + * @throws InvalidInterfaceException |
|
312 | + * @throws ReflectionException |
|
313 | + */ |
|
314 | + public function pretty_paid() |
|
315 | + { |
|
316 | + return $this->get_pretty('TXN_paid'); |
|
317 | + } |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * calculate the amount remaining for this transaction and return; |
|
322 | + * |
|
323 | + * @return float amount remaining |
|
324 | + * @throws EE_Error |
|
325 | + * @throws InvalidArgumentException |
|
326 | + * @throws InvalidDataTypeException |
|
327 | + * @throws InvalidInterfaceException |
|
328 | + * @throws ReflectionException |
|
329 | + */ |
|
330 | + public function remaining() |
|
331 | + { |
|
332 | + return $this->total() - $this->paid(); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * get Transaction Total |
|
338 | + * |
|
339 | + * @return float |
|
340 | + * @throws EE_Error |
|
341 | + * @throws InvalidArgumentException |
|
342 | + * @throws InvalidDataTypeException |
|
343 | + * @throws InvalidInterfaceException |
|
344 | + * @throws ReflectionException |
|
345 | + */ |
|
346 | + public function total() |
|
347 | + { |
|
348 | + return (float) $this->get('TXN_total'); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * get Total Amount Paid to Date |
|
354 | + * |
|
355 | + * @return float |
|
356 | + * @throws EE_Error |
|
357 | + * @throws InvalidArgumentException |
|
358 | + * @throws InvalidDataTypeException |
|
359 | + * @throws InvalidInterfaceException |
|
360 | + * @throws ReflectionException |
|
361 | + */ |
|
362 | + public function paid() |
|
363 | + { |
|
364 | + return (float) $this->get('TXN_paid'); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @return mixed|null |
|
370 | + * @throws EE_Error |
|
371 | + * @throws InvalidArgumentException |
|
372 | + * @throws InvalidDataTypeException |
|
373 | + * @throws InvalidInterfaceException |
|
374 | + * @throws ReflectionException |
|
375 | + */ |
|
376 | + public function get_cart_session() |
|
377 | + { |
|
378 | + $session_data = (array) $this->get('TXN_session_data'); |
|
379 | + return isset($session_data['cart']) && $session_data['cart'] instanceof EE_Cart |
|
380 | + ? $session_data['cart'] |
|
381 | + : null; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * get Transaction session data |
|
387 | + * |
|
388 | + * @return array|mixed |
|
389 | + * @throws EE_Error |
|
390 | + * @throws InvalidArgumentException |
|
391 | + * @throws InvalidDataTypeException |
|
392 | + * @throws InvalidInterfaceException |
|
393 | + * @throws ReflectionException |
|
394 | + */ |
|
395 | + public function session_data() |
|
396 | + { |
|
397 | + $session_data = $this->get('TXN_session_data'); |
|
398 | + if (empty($session_data)) { |
|
399 | + $session_data = array( |
|
400 | + 'id' => null, |
|
401 | + 'user_id' => null, |
|
402 | + 'ip_address' => null, |
|
403 | + 'user_agent' => null, |
|
404 | + 'init_access' => null, |
|
405 | + 'last_access' => null, |
|
406 | + 'pages_visited' => array(), |
|
407 | + ); |
|
408 | + } |
|
409 | + return $session_data; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + /** |
|
414 | + * Set session data within the TXN object |
|
415 | + * |
|
416 | + * @param EE_Session|array $session_data |
|
417 | + * @throws EE_Error |
|
418 | + * @throws InvalidArgumentException |
|
419 | + * @throws InvalidDataTypeException |
|
420 | + * @throws InvalidInterfaceException |
|
421 | + * @throws ReflectionException |
|
422 | + */ |
|
423 | + public function set_txn_session_data($session_data) |
|
424 | + { |
|
425 | + if ($session_data instanceof EE_Session) { |
|
426 | + $this->set('TXN_session_data', $session_data->get_session_data(null, true)); |
|
427 | + } else { |
|
428 | + $this->set('TXN_session_data', $session_data); |
|
429 | + } |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * get Transaction hash salt |
|
435 | + * |
|
436 | + * @return mixed |
|
437 | + * @throws EE_Error |
|
438 | + * @throws InvalidArgumentException |
|
439 | + * @throws InvalidDataTypeException |
|
440 | + * @throws InvalidInterfaceException |
|
441 | + * @throws ReflectionException |
|
442 | + */ |
|
443 | + public function hash_salt_() |
|
444 | + { |
|
445 | + return $this->get('TXN_hash_salt'); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * Returns the transaction datetime as either: |
|
451 | + * - unix timestamp format ($format = false, $gmt = true) |
|
452 | + * - formatted date string including the UTC (timezone) offset ($format = true ($gmt |
|
453 | + * has no affect with this option)), this also may include a timezone abbreviation if the |
|
454 | + * set timezone in this class differs from what the timezone is on the blog. |
|
455 | + * - formatted date string including the UTC (timezone) offset (default). |
|
456 | + * |
|
457 | + * @param boolean $format - whether to return a unix timestamp (default) or formatted date string |
|
458 | + * @param boolean $gmt - whether to return a unix timestamp with UTC offset applied (default) |
|
459 | + * or no UTC offset applied |
|
460 | + * @return string | int |
|
461 | + * @throws EE_Error |
|
462 | + * @throws InvalidArgumentException |
|
463 | + * @throws InvalidDataTypeException |
|
464 | + * @throws InvalidInterfaceException |
|
465 | + * @throws ReflectionException |
|
466 | + */ |
|
467 | + public function datetime($format = false, $gmt = false) |
|
468 | + { |
|
469 | + if ($format) { |
|
470 | + return $this->get_pretty('TXN_timestamp'); |
|
471 | + } |
|
472 | + if ($gmt) { |
|
473 | + return $this->get_raw('TXN_timestamp'); |
|
474 | + } |
|
475 | + return $this->get('TXN_timestamp'); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * Gets registrations on this transaction |
|
481 | + * |
|
482 | + * @param array $query_params array of query parameters |
|
483 | + * @param boolean $get_cached TRUE to retrieve cached registrations or FALSE to pull from the db |
|
484 | + * @return EE_Base_Class[]|EE_Registration[] |
|
485 | + * @throws EE_Error |
|
486 | + * @throws InvalidArgumentException |
|
487 | + * @throws InvalidDataTypeException |
|
488 | + * @throws InvalidInterfaceException |
|
489 | + * @throws ReflectionException |
|
490 | + */ |
|
491 | + public function registrations($query_params = array(), $get_cached = false) |
|
492 | + { |
|
493 | + $query_params = (empty($query_params) || ! is_array($query_params)) |
|
494 | + ? array( |
|
495 | + 'order_by' => array( |
|
496 | + 'Event.EVT_name' => 'ASC', |
|
497 | + 'Attendee.ATT_lname' => 'ASC', |
|
498 | + 'Attendee.ATT_fname' => 'ASC', |
|
499 | + ), |
|
500 | + ) |
|
501 | + : $query_params; |
|
502 | + $query_params = $get_cached ? array() : $query_params; |
|
503 | + return $this->get_many_related('Registration', $query_params); |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * Gets all the attendees for this transaction (handy for use with EE_Attendee's get_registrations_for_event |
|
509 | + * function for getting attendees and how many registrations they each have for an event) |
|
510 | + * |
|
511 | + * @return mixed EE_Attendee[] by default, int if $output is set to 'COUNT' |
|
512 | + * @throws EE_Error |
|
513 | + * @throws InvalidArgumentException |
|
514 | + * @throws InvalidDataTypeException |
|
515 | + * @throws InvalidInterfaceException |
|
516 | + * @throws ReflectionException |
|
517 | + */ |
|
518 | + public function attendees() |
|
519 | + { |
|
520 | + return $this->get_many_related('Attendee', array(array('Registration.Transaction.TXN_ID' => $this->ID()))); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * Gets payments for this transaction. Unlike other such functions, order by 'DESC' by default |
|
526 | + * |
|
527 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
528 | + * @return EE_Base_Class[]|EE_Payment[] |
|
529 | + * @throws EE_Error |
|
530 | + * @throws InvalidArgumentException |
|
531 | + * @throws InvalidDataTypeException |
|
532 | + * @throws InvalidInterfaceException |
|
533 | + * @throws ReflectionException |
|
534 | + */ |
|
535 | + public function payments($query_params = array()) |
|
536 | + { |
|
537 | + return $this->get_many_related('Payment', $query_params); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * gets only approved payments for this transaction |
|
543 | + * |
|
544 | + * @return EE_Base_Class[]|EE_Payment[] |
|
545 | + * @throws EE_Error |
|
546 | + * @throws InvalidArgumentException |
|
547 | + * @throws ReflectionException |
|
548 | + * @throws InvalidDataTypeException |
|
549 | + * @throws InvalidInterfaceException |
|
550 | + */ |
|
551 | + public function approved_payments() |
|
552 | + { |
|
553 | + EE_Registry::instance()->load_model('Payment'); |
|
554 | + return $this->get_many_related( |
|
555 | + 'Payment', |
|
556 | + array( |
|
557 | + array('STS_ID' => EEM_Payment::status_id_approved), |
|
558 | + 'order_by' => array('PAY_timestamp' => 'DESC'), |
|
559 | + ) |
|
560 | + ); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * Gets all payments which have not been approved |
|
566 | + * |
|
567 | + * @return EE_Base_Class[]|EEI_Payment[] |
|
568 | + * @throws EE_Error if a model is misconfigured somehow |
|
569 | + * @throws InvalidArgumentException |
|
570 | + * @throws InvalidDataTypeException |
|
571 | + * @throws InvalidInterfaceException |
|
572 | + * @throws ReflectionException |
|
573 | + */ |
|
574 | + public function pending_payments() |
|
575 | + { |
|
576 | + return $this->get_many_related( |
|
577 | + 'Payment', |
|
578 | + array( |
|
579 | + array( |
|
580 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
581 | + ), |
|
582 | + 'order_by' => array( |
|
583 | + 'PAY_timestamp' => 'DESC', |
|
584 | + ), |
|
585 | + ) |
|
586 | + ); |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * echoes $this->pretty_status() |
|
592 | + * |
|
593 | + * @param bool $show_icons |
|
594 | + * @throws EE_Error |
|
595 | + * @throws InvalidArgumentException |
|
596 | + * @throws InvalidDataTypeException |
|
597 | + * @throws InvalidInterfaceException |
|
598 | + * @throws ReflectionException |
|
599 | + */ |
|
600 | + public function e_pretty_status($show_icons = false) |
|
601 | + { |
|
602 | + echo $this->pretty_status($show_icons); |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * returns a pretty version of the status, good for displaying to users |
|
608 | + * |
|
609 | + * @param bool $show_icons |
|
610 | + * @return string |
|
611 | + * @throws EE_Error |
|
612 | + * @throws InvalidArgumentException |
|
613 | + * @throws InvalidDataTypeException |
|
614 | + * @throws InvalidInterfaceException |
|
615 | + * @throws ReflectionException |
|
616 | + */ |
|
617 | + public function pretty_status($show_icons = false) |
|
618 | + { |
|
619 | + $status = EEM_Status::instance()->localized_status( |
|
620 | + array($this->status_ID() => __('unknown', 'event_espresso')), |
|
621 | + false, |
|
622 | + 'sentence' |
|
623 | + ); |
|
624 | + $icon = ''; |
|
625 | + switch ($this->status_ID()) { |
|
626 | + case EEM_Transaction::complete_status_code: |
|
627 | + $icon = $show_icons ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' : ''; |
|
628 | + break; |
|
629 | + case EEM_Transaction::incomplete_status_code: |
|
630 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 lt-blue-text"></span>' |
|
631 | + : ''; |
|
632 | + break; |
|
633 | + case EEM_Transaction::abandoned_status_code: |
|
634 | + $icon = $show_icons ? '<span class="dashicons dashicons-marker ee-icon-size-16 red-text"></span>' : ''; |
|
635 | + break; |
|
636 | + case EEM_Transaction::failed_status_code: |
|
637 | + $icon = $show_icons ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' : ''; |
|
638 | + break; |
|
639 | + case EEM_Transaction::overpaid_status_code: |
|
640 | + $icon = $show_icons ? '<span class="dashicons dashicons-plus ee-icon-size-16 orange-text"></span>' : ''; |
|
641 | + break; |
|
642 | + } |
|
643 | + return $icon . $status[ $this->status_ID() ]; |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + /** |
|
648 | + * get Transaction Status |
|
649 | + * |
|
650 | + * @return mixed |
|
651 | + * @throws EE_Error |
|
652 | + * @throws InvalidArgumentException |
|
653 | + * @throws InvalidDataTypeException |
|
654 | + * @throws InvalidInterfaceException |
|
655 | + * @throws ReflectionException |
|
656 | + */ |
|
657 | + public function status_ID() |
|
658 | + { |
|
659 | + return $this->get('STS_ID'); |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + /** |
|
664 | + * Returns TRUE or FALSE for whether or not this transaction cost any money |
|
665 | + * |
|
666 | + * @return boolean |
|
667 | + * @throws EE_Error |
|
668 | + * @throws InvalidArgumentException |
|
669 | + * @throws InvalidDataTypeException |
|
670 | + * @throws InvalidInterfaceException |
|
671 | + * @throws ReflectionException |
|
672 | + */ |
|
673 | + public function is_free() |
|
674 | + { |
|
675 | + return EEH_Money::compare_floats($this->get('TXN_total'), 0, '=='); |
|
676 | + } |
|
677 | + |
|
678 | + |
|
679 | + /** |
|
680 | + * Returns whether this transaction is complete |
|
681 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
682 | + * |
|
683 | + * @return boolean |
|
684 | + * @throws EE_Error |
|
685 | + * @throws InvalidArgumentException |
|
686 | + * @throws InvalidDataTypeException |
|
687 | + * @throws InvalidInterfaceException |
|
688 | + * @throws ReflectionException |
|
689 | + */ |
|
690 | + public function is_completed() |
|
691 | + { |
|
692 | + return $this->status_ID() === EEM_Transaction::complete_status_code; |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * Returns whether this transaction is incomplete |
|
698 | + * Useful in templates and other logic for deciding if we should ask for another payment... |
|
699 | + * |
|
700 | + * @return boolean |
|
701 | + * @throws EE_Error |
|
702 | + * @throws InvalidArgumentException |
|
703 | + * @throws InvalidDataTypeException |
|
704 | + * @throws InvalidInterfaceException |
|
705 | + * @throws ReflectionException |
|
706 | + */ |
|
707 | + public function is_incomplete() |
|
708 | + { |
|
709 | + return $this->status_ID() === EEM_Transaction::incomplete_status_code; |
|
710 | + } |
|
711 | + |
|
712 | + |
|
713 | + /** |
|
714 | + * Returns whether this transaction is overpaid |
|
715 | + * Useful in templates and other logic for deciding if monies need to be refunded |
|
716 | + * |
|
717 | + * @return boolean |
|
718 | + * @throws EE_Error |
|
719 | + * @throws InvalidArgumentException |
|
720 | + * @throws InvalidDataTypeException |
|
721 | + * @throws InvalidInterfaceException |
|
722 | + * @throws ReflectionException |
|
723 | + */ |
|
724 | + public function is_overpaid() |
|
725 | + { |
|
726 | + return $this->status_ID() === EEM_Transaction::overpaid_status_code; |
|
727 | + } |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * Returns whether this transaction was abandoned |
|
732 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
733 | + * but that contact information exists for at least one registrant |
|
734 | + * |
|
735 | + * @return boolean |
|
736 | + * @throws EE_Error |
|
737 | + * @throws InvalidArgumentException |
|
738 | + * @throws InvalidDataTypeException |
|
739 | + * @throws InvalidInterfaceException |
|
740 | + * @throws ReflectionException |
|
741 | + */ |
|
742 | + public function is_abandoned() |
|
743 | + { |
|
744 | + return $this->status_ID() === EEM_Transaction::abandoned_status_code; |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * Returns whether this transaction failed |
|
750 | + * meaning that the transaction/registration process was somehow interrupted and never completed |
|
751 | + * and that NO contact information exists for any registrants |
|
752 | + * |
|
753 | + * @return boolean |
|
754 | + * @throws EE_Error |
|
755 | + * @throws InvalidArgumentException |
|
756 | + * @throws InvalidDataTypeException |
|
757 | + * @throws InvalidInterfaceException |
|
758 | + * @throws ReflectionException |
|
759 | + */ |
|
760 | + public function failed() |
|
761 | + { |
|
762 | + return $this->status_ID() === EEM_Transaction::failed_status_code; |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * This returns the url for the invoice of this transaction |
|
768 | + * |
|
769 | + * @param string $type 'html' or 'pdf' (default is pdf) |
|
770 | + * @return string |
|
771 | + * @throws EE_Error |
|
772 | + * @throws InvalidArgumentException |
|
773 | + * @throws InvalidDataTypeException |
|
774 | + * @throws InvalidInterfaceException |
|
775 | + * @throws ReflectionException |
|
776 | + */ |
|
777 | + public function invoice_url($type = 'html') |
|
778 | + { |
|
779 | + $REG = $this->primary_registration(); |
|
780 | + if (! $REG instanceof EE_Registration) { |
|
781 | + return ''; |
|
782 | + } |
|
783 | + return $REG->invoice_url($type); |
|
784 | + } |
|
785 | + |
|
786 | + |
|
787 | + /** |
|
788 | + * Gets the primary registration only |
|
789 | + * |
|
790 | + * @return EE_Base_Class|EE_Registration |
|
791 | + * @throws EE_Error |
|
792 | + * @throws InvalidArgumentException |
|
793 | + * @throws InvalidDataTypeException |
|
794 | + * @throws InvalidInterfaceException |
|
795 | + * @throws ReflectionException |
|
796 | + */ |
|
797 | + public function primary_registration() |
|
798 | + { |
|
799 | + $registrations = (array) $this->get_many_related( |
|
800 | + 'Registration', |
|
801 | + array(array('REG_count' => EEM_Registration::PRIMARY_REGISTRANT_COUNT)) |
|
802 | + ); |
|
803 | + foreach ($registrations as $registration) { |
|
804 | + // valid registration that is NOT cancelled or declined ? |
|
805 | + if ($registration instanceof EE_Registration |
|
806 | + && ! in_array($registration->status_ID(), EEM_Registration::closed_reg_statuses(), true) |
|
807 | + ) { |
|
808 | + return $registration; |
|
809 | + } |
|
810 | + } |
|
811 | + // nothing valid found, so just return first thing from array of results |
|
812 | + return reset($registrations); |
|
813 | + } |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * Gets the URL for viewing the receipt |
|
818 | + * |
|
819 | + * @param string $type 'pdf' or 'html' (default is 'html') |
|
820 | + * @return string |
|
821 | + * @throws EE_Error |
|
822 | + * @throws InvalidArgumentException |
|
823 | + * @throws InvalidDataTypeException |
|
824 | + * @throws InvalidInterfaceException |
|
825 | + * @throws ReflectionException |
|
826 | + */ |
|
827 | + public function receipt_url($type = 'html') |
|
828 | + { |
|
829 | + $REG = $this->primary_registration(); |
|
830 | + if (! $REG instanceof EE_Registration) { |
|
831 | + return ''; |
|
832 | + } |
|
833 | + return $REG->receipt_url($type); |
|
834 | + } |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
839 | + * a query parameter |
|
840 | + * |
|
841 | + * @return string |
|
842 | + * @throws EE_Error |
|
843 | + * @throws InvalidArgumentException |
|
844 | + * @throws InvalidDataTypeException |
|
845 | + * @throws InvalidInterfaceException |
|
846 | + * @throws ReflectionException |
|
847 | + */ |
|
848 | + public function payment_overview_url() |
|
849 | + { |
|
850 | + $primary_registration = $this->primary_registration(); |
|
851 | + return $primary_registration instanceof EE_Registration ? $primary_registration->payment_overview_url() : false; |
|
852 | + } |
|
853 | + |
|
854 | + |
|
855 | + /** |
|
856 | + * @return string |
|
857 | + * @throws EE_Error |
|
858 | + * @throws InvalidArgumentException |
|
859 | + * @throws InvalidDataTypeException |
|
860 | + * @throws InvalidInterfaceException |
|
861 | + * @throws ReflectionException |
|
862 | + */ |
|
863 | + public function gateway_response_on_transaction() |
|
864 | + { |
|
865 | + $payment = $this->get_first_related('Payment'); |
|
866 | + return $payment instanceof EE_Payment ? $payment->gateway_response() : ''; |
|
867 | + } |
|
868 | + |
|
869 | + |
|
870 | + /** |
|
871 | + * Get the status object of this object |
|
872 | + * |
|
873 | + * @return EE_Base_Class|EE_Status |
|
874 | + * @throws EE_Error |
|
875 | + * @throws InvalidArgumentException |
|
876 | + * @throws InvalidDataTypeException |
|
877 | + * @throws InvalidInterfaceException |
|
878 | + * @throws ReflectionException |
|
879 | + */ |
|
880 | + public function status_obj() |
|
881 | + { |
|
882 | + return $this->get_first_related('Status'); |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + /** |
|
887 | + * Gets all the extra meta info on this payment |
|
888 | + * |
|
889 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
890 | + * @return EE_Base_Class[]|EE_Extra_Meta |
|
891 | + * @throws EE_Error |
|
892 | + * @throws InvalidArgumentException |
|
893 | + * @throws InvalidDataTypeException |
|
894 | + * @throws InvalidInterfaceException |
|
895 | + * @throws ReflectionException |
|
896 | + */ |
|
897 | + public function extra_meta($query_params = array()) |
|
898 | + { |
|
899 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
900 | + } |
|
901 | + |
|
902 | + |
|
903 | + /** |
|
904 | + * Wrapper for _add_relation_to |
|
905 | + * |
|
906 | + * @param EE_Registration $registration |
|
907 | + * @return EE_Base_Class the relation was added to |
|
908 | + * @throws EE_Error |
|
909 | + * @throws InvalidArgumentException |
|
910 | + * @throws InvalidDataTypeException |
|
911 | + * @throws InvalidInterfaceException |
|
912 | + * @throws ReflectionException |
|
913 | + */ |
|
914 | + public function add_registration(EE_Registration $registration) |
|
915 | + { |
|
916 | + return $this->_add_relation_to($registration, 'Registration'); |
|
917 | + } |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * Removes the given registration from being related (even before saving this transaction). |
|
922 | + * If an ID/index is provided and this transaction isn't saved yet, removes it from list of cached relations |
|
923 | + * |
|
924 | + * @param int $registration_or_id |
|
925 | + * @return EE_Base_Class that was removed from being related |
|
926 | + * @throws EE_Error |
|
927 | + * @throws InvalidArgumentException |
|
928 | + * @throws InvalidDataTypeException |
|
929 | + * @throws InvalidInterfaceException |
|
930 | + * @throws ReflectionException |
|
931 | + */ |
|
932 | + public function remove_registration_with_id($registration_or_id) |
|
933 | + { |
|
934 | + return $this->_remove_relation_to($registration_or_id, 'Registration'); |
|
935 | + } |
|
936 | + |
|
937 | + |
|
938 | + /** |
|
939 | + * Gets all the line items which are for ACTUAL items |
|
940 | + * |
|
941 | + * @return EE_Line_Item[] |
|
942 | + * @throws EE_Error |
|
943 | + * @throws InvalidArgumentException |
|
944 | + * @throws InvalidDataTypeException |
|
945 | + * @throws InvalidInterfaceException |
|
946 | + * @throws ReflectionException |
|
947 | + */ |
|
948 | + public function items_purchased() |
|
949 | + { |
|
950 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_line_item))); |
|
951 | + } |
|
952 | + |
|
953 | + |
|
954 | + /** |
|
955 | + * Wrapper for _add_relation_to |
|
956 | + * |
|
957 | + * @param EE_Line_Item $line_item |
|
958 | + * @return EE_Base_Class the relation was added to |
|
959 | + * @throws EE_Error |
|
960 | + * @throws InvalidArgumentException |
|
961 | + * @throws InvalidDataTypeException |
|
962 | + * @throws InvalidInterfaceException |
|
963 | + * @throws ReflectionException |
|
964 | + */ |
|
965 | + public function add_line_item(EE_Line_Item $line_item) |
|
966 | + { |
|
967 | + return $this->_add_relation_to($line_item, 'Line_Item'); |
|
968 | + } |
|
969 | + |
|
970 | + |
|
971 | + /** |
|
972 | + * Gets ALL the line items related to this transaction (unstructured) |
|
973 | + * |
|
974 | + * @param array $query_params |
|
975 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
976 | + * @throws EE_Error |
|
977 | + * @throws InvalidArgumentException |
|
978 | + * @throws InvalidDataTypeException |
|
979 | + * @throws InvalidInterfaceException |
|
980 | + * @throws ReflectionException |
|
981 | + */ |
|
982 | + public function line_items($query_params = array()) |
|
983 | + { |
|
984 | + return $this->get_many_related('Line_Item', $query_params); |
|
985 | + } |
|
986 | + |
|
987 | + |
|
988 | + /** |
|
989 | + * Gets all the line items which are taxes on the total |
|
990 | + * |
|
991 | + * @return EE_Line_Item[] |
|
992 | + * @throws EE_Error |
|
993 | + * @throws InvalidArgumentException |
|
994 | + * @throws InvalidDataTypeException |
|
995 | + * @throws InvalidInterfaceException |
|
996 | + * @throws ReflectionException |
|
997 | + */ |
|
998 | + public function tax_items() |
|
999 | + { |
|
1000 | + return $this->line_items(array(array('LIN_type' => EEM_Line_Item::type_tax))); |
|
1001 | + } |
|
1002 | + |
|
1003 | + |
|
1004 | + /** |
|
1005 | + * Gets the total line item (which is a parent of all other related line items, |
|
1006 | + * meaning it takes them all into account on its total) |
|
1007 | + * |
|
1008 | + * @param bool $create_if_not_found |
|
1009 | + * @return \EE_Line_Item |
|
1010 | + * @throws EE_Error |
|
1011 | + * @throws InvalidArgumentException |
|
1012 | + * @throws InvalidDataTypeException |
|
1013 | + * @throws InvalidInterfaceException |
|
1014 | + * @throws ReflectionException |
|
1015 | + */ |
|
1016 | + public function total_line_item($create_if_not_found = true) |
|
1017 | + { |
|
1018 | + $item = $this->get_first_related('Line_Item', array(array('LIN_type' => EEM_Line_Item::type_total))); |
|
1019 | + if (! $item && $create_if_not_found) { |
|
1020 | + $item = EEH_Line_Item::create_total_line_item($this); |
|
1021 | + } |
|
1022 | + return $item; |
|
1023 | + } |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * Returns the total amount of tax on this transaction |
|
1028 | + * (assumes there's only one tax subtotal line item) |
|
1029 | + * |
|
1030 | + * @return float |
|
1031 | + * @throws EE_Error |
|
1032 | + * @throws InvalidArgumentException |
|
1033 | + * @throws InvalidDataTypeException |
|
1034 | + * @throws InvalidInterfaceException |
|
1035 | + * @throws ReflectionException |
|
1036 | + */ |
|
1037 | + public function tax_total() |
|
1038 | + { |
|
1039 | + $tax_line_item = $this->tax_total_line_item(); |
|
1040 | + if ($tax_line_item) { |
|
1041 | + return (float) $tax_line_item->total(); |
|
1042 | + } |
|
1043 | + return (float) 0; |
|
1044 | + } |
|
1045 | + |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * Gets the tax subtotal line item (assumes there's only one) |
|
1049 | + * |
|
1050 | + * @return EE_Line_Item |
|
1051 | + * @throws EE_Error |
|
1052 | + * @throws InvalidArgumentException |
|
1053 | + * @throws InvalidDataTypeException |
|
1054 | + * @throws InvalidInterfaceException |
|
1055 | + * @throws ReflectionException |
|
1056 | + */ |
|
1057 | + public function tax_total_line_item() |
|
1058 | + { |
|
1059 | + return EEH_Line_Item::get_taxes_subtotal($this->total_line_item()); |
|
1060 | + } |
|
1061 | + |
|
1062 | + |
|
1063 | + /** |
|
1064 | + * Gets the array of billing info for the gateway and for this transaction's primary registration's attendee. |
|
1065 | + * |
|
1066 | + * @return EE_Form_Section_Proper |
|
1067 | + * @throws EE_Error |
|
1068 | + * @throws InvalidArgumentException |
|
1069 | + * @throws InvalidDataTypeException |
|
1070 | + * @throws InvalidInterfaceException |
|
1071 | + * @throws ReflectionException |
|
1072 | + */ |
|
1073 | + public function billing_info() |
|
1074 | + { |
|
1075 | + $payment_method = $this->payment_method(); |
|
1076 | + if (! $payment_method) { |
|
1077 | + EE_Error::add_error( |
|
1078 | + __( |
|
1079 | + 'Could not find billing info for transaction because no gateway has been used for it yet', |
|
1080 | + 'event_espresso' |
|
1081 | + ), |
|
1082 | + __FILE__, |
|
1083 | + __FUNCTION__, |
|
1084 | + __LINE__ |
|
1085 | + ); |
|
1086 | + return null; |
|
1087 | + } |
|
1088 | + $primary_reg = $this->primary_registration(); |
|
1089 | + if (! $primary_reg) { |
|
1090 | + EE_Error::add_error( |
|
1091 | + __( |
|
1092 | + 'Cannot get billing info for gateway %s on transaction because no primary registration exists', |
|
1093 | + 'event_espresso' |
|
1094 | + ), |
|
1095 | + __FILE__, |
|
1096 | + __FUNCTION__, |
|
1097 | + __LINE__ |
|
1098 | + ); |
|
1099 | + return null; |
|
1100 | + } |
|
1101 | + $attendee = $primary_reg->attendee(); |
|
1102 | + if (! $attendee) { |
|
1103 | + EE_Error::add_error( |
|
1104 | + __( |
|
1105 | + 'Cannot get billing info for gateway %s on transaction because the primary registration has no attendee exists', |
|
1106 | + 'event_espresso' |
|
1107 | + ), |
|
1108 | + __FILE__, |
|
1109 | + __FUNCTION__, |
|
1110 | + __LINE__ |
|
1111 | + ); |
|
1112 | + return null; |
|
1113 | + } |
|
1114 | + return $attendee->billing_info_for_payment_method($payment_method); |
|
1115 | + } |
|
1116 | + |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * Gets PMD_ID |
|
1120 | + * |
|
1121 | + * @return int |
|
1122 | + * @throws EE_Error |
|
1123 | + * @throws InvalidArgumentException |
|
1124 | + * @throws InvalidDataTypeException |
|
1125 | + * @throws InvalidInterfaceException |
|
1126 | + * @throws ReflectionException |
|
1127 | + */ |
|
1128 | + public function payment_method_ID() |
|
1129 | + { |
|
1130 | + return $this->get('PMD_ID'); |
|
1131 | + } |
|
1132 | + |
|
1133 | + |
|
1134 | + /** |
|
1135 | + * Sets PMD_ID |
|
1136 | + * |
|
1137 | + * @param int $PMD_ID |
|
1138 | + * @throws EE_Error |
|
1139 | + * @throws InvalidArgumentException |
|
1140 | + * @throws InvalidDataTypeException |
|
1141 | + * @throws InvalidInterfaceException |
|
1142 | + * @throws ReflectionException |
|
1143 | + */ |
|
1144 | + public function set_payment_method_ID($PMD_ID) |
|
1145 | + { |
|
1146 | + $this->set('PMD_ID', $PMD_ID); |
|
1147 | + } |
|
1148 | + |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * Gets the last-used payment method on this transaction |
|
1152 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
1153 | + * offline ones, dont' create payments) |
|
1154 | + * |
|
1155 | + * @return EE_Payment_Method |
|
1156 | + * @throws EE_Error |
|
1157 | + * @throws InvalidArgumentException |
|
1158 | + * @throws InvalidDataTypeException |
|
1159 | + * @throws InvalidInterfaceException |
|
1160 | + * @throws ReflectionException |
|
1161 | + */ |
|
1162 | + public function payment_method() |
|
1163 | + { |
|
1164 | + $pm = $this->get_first_related('Payment_Method'); |
|
1165 | + if ($pm instanceof EE_Payment_Method) { |
|
1166 | + return $pm; |
|
1167 | + } |
|
1168 | + $last_payment = $this->last_payment(); |
|
1169 | + if ($last_payment instanceof EE_Payment && $last_payment->payment_method()) { |
|
1170 | + return $last_payment->payment_method(); |
|
1171 | + } |
|
1172 | + return null; |
|
1173 | + } |
|
1174 | + |
|
1175 | + |
|
1176 | + /** |
|
1177 | + * Gets the last payment made |
|
1178 | + * |
|
1179 | + * @return EE_Base_Class|EE_Payment |
|
1180 | + * @throws EE_Error |
|
1181 | + * @throws InvalidArgumentException |
|
1182 | + * @throws InvalidDataTypeException |
|
1183 | + * @throws InvalidInterfaceException |
|
1184 | + * @throws ReflectionException |
|
1185 | + */ |
|
1186 | + public function last_payment() |
|
1187 | + { |
|
1188 | + return $this->get_first_related('Payment', array('order_by' => array('PAY_ID' => 'desc'))); |
|
1189 | + } |
|
1190 | + |
|
1191 | + |
|
1192 | + /** |
|
1193 | + * Gets all the line items which are unrelated to tickets on this transaction |
|
1194 | + * |
|
1195 | + * @return EE_Line_Item[] |
|
1196 | + * @throws EE_Error |
|
1197 | + * @throws InvalidArgumentException |
|
1198 | + * @throws InvalidDataTypeException |
|
1199 | + * @throws InvalidInterfaceException |
|
1200 | + * @throws ReflectionException |
|
1201 | + */ |
|
1202 | + public function non_ticket_line_items() |
|
1203 | + { |
|
1204 | + return EEM_Line_Item::instance()->get_all_non_ticket_line_items_for_transaction($this->ID()); |
|
1205 | + } |
|
1206 | + |
|
1207 | + |
|
1208 | + /** |
|
1209 | + * possibly toggles TXN status |
|
1210 | + * |
|
1211 | + * @param boolean $update whether to save the TXN |
|
1212 | + * @return bool whether the TXN was saved |
|
1213 | + * @throws EE_Error |
|
1214 | + * @throws InvalidArgumentException |
|
1215 | + * @throws InvalidDataTypeException |
|
1216 | + * @throws InvalidInterfaceException |
|
1217 | + * @throws ReflectionException |
|
1218 | + * @throws RuntimeException |
|
1219 | + */ |
|
1220 | + public function update_status_based_on_total_paid($update = true) |
|
1221 | + { |
|
1222 | + // set transaction status based on comparison of TXN_paid vs TXN_total |
|
1223 | + if (EEH_Money::compare_floats($this->paid(), $this->total(), '>')) { |
|
1224 | + $new_txn_status = EEM_Transaction::overpaid_status_code; |
|
1225 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total())) { |
|
1226 | + $new_txn_status = EEM_Transaction::complete_status_code; |
|
1227 | + } elseif (EEH_Money::compare_floats($this->paid(), $this->total(), '<')) { |
|
1228 | + $new_txn_status = EEM_Transaction::incomplete_status_code; |
|
1229 | + } else { |
|
1230 | + throw new RuntimeException( |
|
1231 | + __('The total paid calculation for this transaction is inaccurate.', 'event_espresso') |
|
1232 | + ); |
|
1233 | + } |
|
1234 | + if ($new_txn_status !== $this->status_ID()) { |
|
1235 | + $this->set_status($new_txn_status); |
|
1236 | + if ($update) { |
|
1237 | + return $this->save() ? true : false; |
|
1238 | + } |
|
1239 | + } |
|
1240 | + return false; |
|
1241 | + } |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * Updates the transaction's status and total_paid based on all the payments |
|
1246 | + * that apply to it |
|
1247 | + * |
|
1248 | + * @deprecated |
|
1249 | + * @return array|bool |
|
1250 | + * @throws EE_Error |
|
1251 | + * @throws InvalidArgumentException |
|
1252 | + * @throws ReflectionException |
|
1253 | + * @throws InvalidDataTypeException |
|
1254 | + * @throws InvalidInterfaceException |
|
1255 | + */ |
|
1256 | + public function update_based_on_payments() |
|
1257 | + { |
|
1258 | + EE_Error::doing_it_wrong( |
|
1259 | + __CLASS__ . '::' . __FUNCTION__, |
|
1260 | + sprintf( |
|
1261 | + __('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
1262 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
1263 | + ), |
|
1264 | + '4.6.0' |
|
1265 | + ); |
|
1266 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
1267 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
1268 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($this); |
|
1269 | + } |
|
1270 | + |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * @return string |
|
1274 | + */ |
|
1275 | + public function old_txn_status() |
|
1276 | + { |
|
1277 | + return $this->_old_txn_status; |
|
1278 | + } |
|
1279 | + |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * @param string $old_txn_status |
|
1283 | + */ |
|
1284 | + public function set_old_txn_status($old_txn_status) |
|
1285 | + { |
|
1286 | + // only set the first time |
|
1287 | + if ($this->_old_txn_status === null) { |
|
1288 | + $this->_old_txn_status = $old_txn_status; |
|
1289 | + } |
|
1290 | + } |
|
1291 | + |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * reg_status_updated |
|
1295 | + * |
|
1296 | + * @return bool |
|
1297 | + * @throws EE_Error |
|
1298 | + * @throws InvalidArgumentException |
|
1299 | + * @throws InvalidDataTypeException |
|
1300 | + * @throws InvalidInterfaceException |
|
1301 | + * @throws ReflectionException |
|
1302 | + */ |
|
1303 | + public function txn_status_updated() |
|
1304 | + { |
|
1305 | + return $this->status_ID() !== $this->_old_txn_status && $this->_old_txn_status !== null; |
|
1306 | + } |
|
1307 | + |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * _reg_steps_completed |
|
1311 | + * if $check_all is TRUE, then returns TRUE if ALL reg steps have been marked as completed, |
|
1312 | + * if a $reg_step_slug is provided, then this step will be skipped when testing for completion |
|
1313 | + * if $check_all is FALSE and a $reg_step_slug is provided, then ONLY that reg step will be tested for completion |
|
1314 | + * |
|
1315 | + * @param string $reg_step_slug |
|
1316 | + * @param bool $check_all |
|
1317 | + * @return bool|int |
|
1318 | + * @throws EE_Error |
|
1319 | + * @throws InvalidArgumentException |
|
1320 | + * @throws InvalidDataTypeException |
|
1321 | + * @throws InvalidInterfaceException |
|
1322 | + * @throws ReflectionException |
|
1323 | + */ |
|
1324 | + private function _reg_steps_completed($reg_step_slug = '', $check_all = true) |
|
1325 | + { |
|
1326 | + $reg_steps = $this->reg_steps(); |
|
1327 | + if (! is_array($reg_steps) || empty($reg_steps)) { |
|
1328 | + return false; |
|
1329 | + } |
|
1330 | + // loop thru reg steps array) |
|
1331 | + foreach ($reg_steps as $slug => $reg_step_completed) { |
|
1332 | + // if NOT checking ALL steps (only checking one step) |
|
1333 | + if (! $check_all) { |
|
1334 | + // and this is the one |
|
1335 | + if ($slug === $reg_step_slug) { |
|
1336 | + return $reg_step_completed; |
|
1337 | + } |
|
1338 | + // skip to next reg step in loop |
|
1339 | + continue; |
|
1340 | + } |
|
1341 | + // $check_all must be true, else we would never have gotten to this point |
|
1342 | + if ($slug === $reg_step_slug) { |
|
1343 | + // if we reach this point, then we are testing either: |
|
1344 | + // all_reg_steps_completed_except() or |
|
1345 | + // all_reg_steps_completed_except_final_step(), |
|
1346 | + // and since this is the reg step EXCEPTION being tested |
|
1347 | + // we want to return true (yes true) if this reg step is NOT completed |
|
1348 | + // ie: "is everything completed except the final step?" |
|
1349 | + // "that is correct... the final step is not completed, but all others are." |
|
1350 | + return $reg_step_completed !== true; |
|
1351 | + } |
|
1352 | + if ($reg_step_completed !== true) { |
|
1353 | + // if any reg step is NOT completed, then ALL steps are not completed |
|
1354 | + return false; |
|
1355 | + } |
|
1356 | + } |
|
1357 | + return true; |
|
1358 | + } |
|
1359 | + |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * all_reg_steps_completed |
|
1363 | + * returns: |
|
1364 | + * true if ALL reg steps have been marked as completed |
|
1365 | + * or false if any step is not completed |
|
1366 | + * |
|
1367 | + * @return bool |
|
1368 | + * @throws EE_Error |
|
1369 | + * @throws InvalidArgumentException |
|
1370 | + * @throws InvalidDataTypeException |
|
1371 | + * @throws InvalidInterfaceException |
|
1372 | + * @throws ReflectionException |
|
1373 | + */ |
|
1374 | + public function all_reg_steps_completed() |
|
1375 | + { |
|
1376 | + return $this->_reg_steps_completed(); |
|
1377 | + } |
|
1378 | + |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * all_reg_steps_completed_except |
|
1382 | + * returns: |
|
1383 | + * true if ALL reg steps, except a particular step that you wish to skip over, have been marked as completed |
|
1384 | + * or false if any other step is not completed |
|
1385 | + * or false if ALL steps are completed including the exception you are testing !!! |
|
1386 | + * |
|
1387 | + * @param string $exception |
|
1388 | + * @return bool |
|
1389 | + * @throws EE_Error |
|
1390 | + * @throws InvalidArgumentException |
|
1391 | + * @throws InvalidDataTypeException |
|
1392 | + * @throws InvalidInterfaceException |
|
1393 | + * @throws ReflectionException |
|
1394 | + */ |
|
1395 | + public function all_reg_steps_completed_except($exception = '') |
|
1396 | + { |
|
1397 | + return $this->_reg_steps_completed($exception); |
|
1398 | + } |
|
1399 | + |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * all_reg_steps_completed_except |
|
1403 | + * returns: |
|
1404 | + * true if ALL reg steps, except the final step, have been marked as completed |
|
1405 | + * or false if any step is not completed |
|
1406 | + * or false if ALL steps are completed including the final step !!! |
|
1407 | + * |
|
1408 | + * @return bool |
|
1409 | + * @throws EE_Error |
|
1410 | + * @throws InvalidArgumentException |
|
1411 | + * @throws InvalidDataTypeException |
|
1412 | + * @throws InvalidInterfaceException |
|
1413 | + * @throws ReflectionException |
|
1414 | + */ |
|
1415 | + public function all_reg_steps_completed_except_final_step() |
|
1416 | + { |
|
1417 | + return $this->_reg_steps_completed('finalize_registration'); |
|
1418 | + } |
|
1419 | + |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * reg_step_completed |
|
1423 | + * returns: |
|
1424 | + * true if a specific reg step has been marked as completed |
|
1425 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
1426 | + * or false if it has not yet been initialized |
|
1427 | + * |
|
1428 | + * @param string $reg_step_slug |
|
1429 | + * @return bool|int |
|
1430 | + * @throws EE_Error |
|
1431 | + * @throws InvalidArgumentException |
|
1432 | + * @throws InvalidDataTypeException |
|
1433 | + * @throws InvalidInterfaceException |
|
1434 | + * @throws ReflectionException |
|
1435 | + */ |
|
1436 | + public function reg_step_completed($reg_step_slug) |
|
1437 | + { |
|
1438 | + return $this->_reg_steps_completed($reg_step_slug, false); |
|
1439 | + } |
|
1440 | + |
|
1441 | + |
|
1442 | + /** |
|
1443 | + * completed_final_reg_step |
|
1444 | + * returns: |
|
1445 | + * true if the finalize_registration reg step has been marked as completed |
|
1446 | + * a Unix timestamp if it has been initialized but not yet completed, |
|
1447 | + * or false if it has not yet been initialized |
|
1448 | + * |
|
1449 | + * @return bool|int |
|
1450 | + * @throws EE_Error |
|
1451 | + * @throws InvalidArgumentException |
|
1452 | + * @throws InvalidDataTypeException |
|
1453 | + * @throws InvalidInterfaceException |
|
1454 | + * @throws ReflectionException |
|
1455 | + */ |
|
1456 | + public function final_reg_step_completed() |
|
1457 | + { |
|
1458 | + return $this->_reg_steps_completed('finalize_registration', false); |
|
1459 | + } |
|
1460 | + |
|
1461 | + |
|
1462 | + /** |
|
1463 | + * set_reg_step_initiated |
|
1464 | + * given a valid TXN_reg_step, this sets it's value to a unix timestamp |
|
1465 | + * |
|
1466 | + * @param string $reg_step_slug |
|
1467 | + * @return boolean |
|
1468 | + * @throws EE_Error |
|
1469 | + * @throws InvalidArgumentException |
|
1470 | + * @throws InvalidDataTypeException |
|
1471 | + * @throws InvalidInterfaceException |
|
1472 | + * @throws ReflectionException |
|
1473 | + */ |
|
1474 | + public function set_reg_step_initiated($reg_step_slug) |
|
1475 | + { |
|
1476 | + return $this->_set_reg_step_completed_status($reg_step_slug, time()); |
|
1477 | + } |
|
1478 | + |
|
1479 | + |
|
1480 | + /** |
|
1481 | + * set_reg_step_completed |
|
1482 | + * given a valid TXN_reg_step, this sets the step as completed |
|
1483 | + * |
|
1484 | + * @param string $reg_step_slug |
|
1485 | + * @return boolean |
|
1486 | + * @throws EE_Error |
|
1487 | + * @throws InvalidArgumentException |
|
1488 | + * @throws InvalidDataTypeException |
|
1489 | + * @throws InvalidInterfaceException |
|
1490 | + * @throws ReflectionException |
|
1491 | + */ |
|
1492 | + public function set_reg_step_completed($reg_step_slug) |
|
1493 | + { |
|
1494 | + return $this->_set_reg_step_completed_status($reg_step_slug, true); |
|
1495 | + } |
|
1496 | + |
|
1497 | + |
|
1498 | + /** |
|
1499 | + * set_reg_step_completed |
|
1500 | + * given a valid TXN_reg_step slug, this sets the step as NOT completed |
|
1501 | + * |
|
1502 | + * @param string $reg_step_slug |
|
1503 | + * @return boolean |
|
1504 | + * @throws EE_Error |
|
1505 | + * @throws InvalidArgumentException |
|
1506 | + * @throws InvalidDataTypeException |
|
1507 | + * @throws InvalidInterfaceException |
|
1508 | + * @throws ReflectionException |
|
1509 | + */ |
|
1510 | + public function set_reg_step_not_completed($reg_step_slug) |
|
1511 | + { |
|
1512 | + return $this->_set_reg_step_completed_status($reg_step_slug, false); |
|
1513 | + } |
|
1514 | + |
|
1515 | + |
|
1516 | + /** |
|
1517 | + * set_reg_step_completed |
|
1518 | + * given a valid reg step slug, this sets the TXN_reg_step completed status which is either: |
|
1519 | + * |
|
1520 | + * @param string $reg_step_slug |
|
1521 | + * @param boolean|int $status |
|
1522 | + * @return boolean |
|
1523 | + * @throws EE_Error |
|
1524 | + * @throws InvalidArgumentException |
|
1525 | + * @throws InvalidDataTypeException |
|
1526 | + * @throws InvalidInterfaceException |
|
1527 | + * @throws ReflectionException |
|
1528 | + */ |
|
1529 | + private function _set_reg_step_completed_status($reg_step_slug, $status) |
|
1530 | + { |
|
1531 | + // validate status |
|
1532 | + $status = is_bool($status) || is_int($status) ? $status : false; |
|
1533 | + // get reg steps array |
|
1534 | + $txn_reg_steps = $this->reg_steps(); |
|
1535 | + // if reg step does NOT exist |
|
1536 | + if (! isset($txn_reg_steps[ $reg_step_slug ])) { |
|
1537 | + return false; |
|
1538 | + } |
|
1539 | + // if we're trying to complete a step that is already completed |
|
1540 | + if ($txn_reg_steps[ $reg_step_slug ] === true) { |
|
1541 | + return true; |
|
1542 | + } |
|
1543 | + // if we're trying to complete a step that hasn't even started |
|
1544 | + if ($status === true && $txn_reg_steps[ $reg_step_slug ] === false) { |
|
1545 | + return false; |
|
1546 | + } |
|
1547 | + // if current status value matches the incoming value (no change) |
|
1548 | + // type casting as int means values should collapse to either 0, 1, or a timestamp like 1234567890 |
|
1549 | + if ((int) $txn_reg_steps[ $reg_step_slug ] === (int) $status) { |
|
1550 | + // this will happen in cases where multiple AJAX requests occur during the same step |
|
1551 | + return true; |
|
1552 | + } |
|
1553 | + // if we're trying to set a start time, but it has already been set... |
|
1554 | + if (is_numeric($status) && is_numeric($txn_reg_steps[ $reg_step_slug ])) { |
|
1555 | + // skip the update below, but don't return FALSE so that errors won't be displayed |
|
1556 | + return true; |
|
1557 | + } |
|
1558 | + // update completed status |
|
1559 | + $txn_reg_steps[ $reg_step_slug ] = $status; |
|
1560 | + $this->set_reg_steps($txn_reg_steps); |
|
1561 | + $this->save(); |
|
1562 | + return true; |
|
1563 | + } |
|
1564 | + |
|
1565 | + |
|
1566 | + /** |
|
1567 | + * remove_reg_step |
|
1568 | + * given a valid TXN_reg_step slug, this will remove (unset) |
|
1569 | + * the reg step from the TXN reg step array |
|
1570 | + * |
|
1571 | + * @param string $reg_step_slug |
|
1572 | + * @return void |
|
1573 | + * @throws EE_Error |
|
1574 | + * @throws InvalidArgumentException |
|
1575 | + * @throws InvalidDataTypeException |
|
1576 | + * @throws InvalidInterfaceException |
|
1577 | + * @throws ReflectionException |
|
1578 | + */ |
|
1579 | + public function remove_reg_step($reg_step_slug) |
|
1580 | + { |
|
1581 | + // get reg steps array |
|
1582 | + $txn_reg_steps = $this->reg_steps(); |
|
1583 | + unset($txn_reg_steps[ $reg_step_slug ]); |
|
1584 | + $this->set_reg_steps($txn_reg_steps); |
|
1585 | + } |
|
1586 | + |
|
1587 | + |
|
1588 | + /** |
|
1589 | + * toggle_failed_transaction_status |
|
1590 | + * upgrades a TXNs status from failed to abandoned, |
|
1591 | + * meaning that contact information has been captured for at least one registrant |
|
1592 | + * |
|
1593 | + * @param bool $save |
|
1594 | + * @return bool |
|
1595 | + * @throws EE_Error |
|
1596 | + * @throws InvalidArgumentException |
|
1597 | + * @throws InvalidDataTypeException |
|
1598 | + * @throws InvalidInterfaceException |
|
1599 | + * @throws ReflectionException |
|
1600 | + */ |
|
1601 | + public function toggle_failed_transaction_status($save = true) |
|
1602 | + { |
|
1603 | + // if TXN status is still set as "failed"... |
|
1604 | + if ($this->status_ID() === EEM_Transaction::failed_status_code) { |
|
1605 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1606 | + if ($save) { |
|
1607 | + $this->save(); |
|
1608 | + } |
|
1609 | + return true; |
|
1610 | + } |
|
1611 | + return false; |
|
1612 | + } |
|
1613 | + |
|
1614 | + |
|
1615 | + /** |
|
1616 | + * toggle_abandoned_transaction_status |
|
1617 | + * upgrades a TXNs status from failed or abandoned to incomplete |
|
1618 | + * |
|
1619 | + * @return bool |
|
1620 | + * @throws EE_Error |
|
1621 | + * @throws InvalidArgumentException |
|
1622 | + * @throws InvalidDataTypeException |
|
1623 | + * @throws InvalidInterfaceException |
|
1624 | + * @throws ReflectionException |
|
1625 | + */ |
|
1626 | + public function toggle_abandoned_transaction_status() |
|
1627 | + { |
|
1628 | + // if TXN status has not been updated already due to a payment, and is still set as "failed" or "abandoned"... |
|
1629 | + $txn_status = $this->status_ID(); |
|
1630 | + if ($txn_status === EEM_Transaction::failed_status_code |
|
1631 | + || $txn_status === EEM_Transaction::abandoned_status_code |
|
1632 | + ) { |
|
1633 | + // if a contact record for the primary registrant has been created |
|
1634 | + if ($this->primary_registration() instanceof EE_Registration |
|
1635 | + && $this->primary_registration()->attendee() instanceof EE_Attendee |
|
1636 | + ) { |
|
1637 | + $this->set_status(EEM_Transaction::incomplete_status_code); |
|
1638 | + } else { |
|
1639 | + // no contact record? yer abandoned! |
|
1640 | + $this->set_status(EEM_Transaction::abandoned_status_code); |
|
1641 | + } |
|
1642 | + return true; |
|
1643 | + } |
|
1644 | + return false; |
|
1645 | + } |
|
1646 | + |
|
1647 | + |
|
1648 | + /** |
|
1649 | + * checks if an Abandoned TXN has any related payments, and if so, |
|
1650 | + * updates the TXN status based on the amount paid |
|
1651 | + * |
|
1652 | + * @throws EE_Error |
|
1653 | + * @throws InvalidDataTypeException |
|
1654 | + * @throws InvalidInterfaceException |
|
1655 | + * @throws InvalidArgumentException |
|
1656 | + * @throws RuntimeException |
|
1657 | + * @throws ReflectionException |
|
1658 | + */ |
|
1659 | + public function verify_abandoned_transaction_status() |
|
1660 | + { |
|
1661 | + if ($this->status_ID() !== EEM_Transaction::abandoned_status_code) { |
|
1662 | + return; |
|
1663 | + } |
|
1664 | + $payments = $this->get_many_related('Payment'); |
|
1665 | + if (! empty($payments)) { |
|
1666 | + foreach ($payments as $payment) { |
|
1667 | + if ($payment instanceof EE_Payment) { |
|
1668 | + // kk this TXN should NOT be abandoned |
|
1669 | + $this->update_status_based_on_total_paid(); |
|
1670 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1671 | + EE_Error::add_attention( |
|
1672 | + sprintf( |
|
1673 | + esc_html__( |
|
1674 | + 'The status for Transaction #%1$d has been updated from "Abandoned" to "%2$s", because at least one payment has been made towards it. If the payment appears in the "Payment Details" table below, you may need to edit its status and/or other details as well.', |
|
1675 | + 'event_espresso' |
|
1676 | + ), |
|
1677 | + $this->ID(), |
|
1678 | + $this->pretty_status() |
|
1679 | + ) |
|
1680 | + ); |
|
1681 | + } |
|
1682 | + // get final reg step status |
|
1683 | + $finalized = $this->final_reg_step_completed(); |
|
1684 | + // if the 'finalize_registration' step has been initiated (has a timestamp) |
|
1685 | + // but has not yet been fully completed (TRUE) |
|
1686 | + if (is_int($finalized) && $finalized !== false && $finalized !== true) { |
|
1687 | + $this->set_reg_step_completed('finalize_registration'); |
|
1688 | + $this->save(); |
|
1689 | + } |
|
1690 | + } |
|
1691 | + } |
|
1692 | + } |
|
1693 | + } |
|
1694 | + |
|
1695 | + |
|
1696 | + /** |
|
1697 | + * @since 4.10.4.p |
|
1698 | + * @throws EE_Error |
|
1699 | + * @throws InvalidArgumentException |
|
1700 | + * @throws InvalidDataTypeException |
|
1701 | + * @throws InvalidInterfaceException |
|
1702 | + * @throws ReflectionException |
|
1703 | + * @throws RuntimeException |
|
1704 | + */ |
|
1705 | + public function recalculateLineItems() |
|
1706 | + { |
|
1707 | + $total_line_item = $this->total_line_item(false); |
|
1708 | + if ($total_line_item instanceof EE_Line_Item) { |
|
1709 | + EEH_Line_Item::resetIsTaxableForTickets($total_line_item); |
|
1710 | + return EEH_Line_Item::apply_taxes($total_line_item, true); |
|
1711 | + } |
|
1712 | + return false; |
|
1713 | + } |
|
1714 | 1714 | } |
@@ -15,2848 +15,2848 @@ |
||
15 | 15 | class Events_Admin_Page extends EE_Admin_Page_CPT |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This will hold the event object for event_details screen. |
|
20 | - * |
|
21 | - * @access protected |
|
22 | - * @var EE_Event $_event |
|
23 | - */ |
|
24 | - protected $_event; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * This will hold the category object for category_details screen. |
|
29 | - * |
|
30 | - * @var stdClass $_category |
|
31 | - */ |
|
32 | - protected $_category; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * This will hold the event model instance |
|
37 | - * |
|
38 | - * @var EEM_Event $_event_model |
|
39 | - */ |
|
40 | - protected $_event_model; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EE_Event |
|
45 | - */ |
|
46 | - protected $_cpt_model_obj = false; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Initialize page props for this admin page group. |
|
51 | - */ |
|
52 | - protected function _init_page_props() |
|
53 | - { |
|
54 | - $this->page_slug = EVENTS_PG_SLUG; |
|
55 | - $this->page_label = EVENTS_LABEL; |
|
56 | - $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
57 | - $this->_admin_base_path = EVENTS_ADMIN; |
|
58 | - $this->_cpt_model_names = array( |
|
59 | - 'create_new' => 'EEM_Event', |
|
60 | - 'edit' => 'EEM_Event', |
|
61 | - ); |
|
62 | - $this->_cpt_edit_routes = array( |
|
63 | - 'espresso_events' => 'edit', |
|
64 | - ); |
|
65 | - add_action( |
|
66 | - 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
67 | - array($this, 'verify_event_edit'), |
|
68 | - 10, |
|
69 | - 2 |
|
70 | - ); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * Sets the ajax hooks used for this admin page group. |
|
76 | - */ |
|
77 | - protected function _ajax_hooks() |
|
78 | - { |
|
79 | - add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting')); |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Sets the page properties for this admin page group. |
|
85 | - */ |
|
86 | - protected function _define_page_props() |
|
87 | - { |
|
88 | - $this->_admin_page_title = EVENTS_LABEL; |
|
89 | - $this->_labels = array( |
|
90 | - 'buttons' => array( |
|
91 | - 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
92 | - 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
93 | - 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
94 | - 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
95 | - 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
96 | - 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
97 | - ), |
|
98 | - 'editor_title' => array( |
|
99 | - 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
100 | - ), |
|
101 | - 'publishbox' => array( |
|
102 | - 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
103 | - 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
104 | - 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
105 | - 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
106 | - 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
107 | - ), |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Sets the page routes property for this admin page group. |
|
114 | - */ |
|
115 | - protected function _set_page_routes() |
|
116 | - { |
|
117 | - // load formatter helper |
|
118 | - // load field generator helper |
|
119 | - // is there a evt_id in the request? |
|
120 | - $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
121 | - ? $this->_req_data['EVT_ID'] |
|
122 | - : 0; |
|
123 | - $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
124 | - $this->_page_routes = array( |
|
125 | - 'default' => array( |
|
126 | - 'func' => '_events_overview_list_table', |
|
127 | - 'capability' => 'ee_read_events', |
|
128 | - ), |
|
129 | - 'create_new' => array( |
|
130 | - 'func' => '_create_new_cpt_item', |
|
131 | - 'capability' => 'ee_edit_events', |
|
132 | - ), |
|
133 | - 'edit' => array( |
|
134 | - 'func' => '_edit_cpt_item', |
|
135 | - 'capability' => 'ee_edit_event', |
|
136 | - 'obj_id' => $evt_id, |
|
137 | - ), |
|
138 | - 'copy_event' => array( |
|
139 | - 'func' => '_copy_events', |
|
140 | - 'capability' => 'ee_edit_event', |
|
141 | - 'obj_id' => $evt_id, |
|
142 | - 'noheader' => true, |
|
143 | - ), |
|
144 | - 'trash_event' => array( |
|
145 | - 'func' => '_trash_or_restore_event', |
|
146 | - 'args' => array('event_status' => 'trash'), |
|
147 | - 'capability' => 'ee_delete_event', |
|
148 | - 'obj_id' => $evt_id, |
|
149 | - 'noheader' => true, |
|
150 | - ), |
|
151 | - 'trash_events' => array( |
|
152 | - 'func' => '_trash_or_restore_events', |
|
153 | - 'args' => array('event_status' => 'trash'), |
|
154 | - 'capability' => 'ee_delete_events', |
|
155 | - 'noheader' => true, |
|
156 | - ), |
|
157 | - 'restore_event' => array( |
|
158 | - 'func' => '_trash_or_restore_event', |
|
159 | - 'args' => array('event_status' => 'draft'), |
|
160 | - 'capability' => 'ee_delete_event', |
|
161 | - 'obj_id' => $evt_id, |
|
162 | - 'noheader' => true, |
|
163 | - ), |
|
164 | - 'restore_events' => array( |
|
165 | - 'func' => '_trash_or_restore_events', |
|
166 | - 'args' => array('event_status' => 'draft'), |
|
167 | - 'capability' => 'ee_delete_events', |
|
168 | - 'noheader' => true, |
|
169 | - ), |
|
170 | - 'delete_event' => array( |
|
171 | - 'func' => '_delete_event', |
|
172 | - 'capability' => 'ee_delete_event', |
|
173 | - 'obj_id' => $evt_id, |
|
174 | - 'noheader' => true, |
|
175 | - ), |
|
176 | - 'delete_events' => array( |
|
177 | - 'func' => '_delete_events', |
|
178 | - 'capability' => 'ee_delete_events', |
|
179 | - 'noheader' => true, |
|
180 | - ), |
|
181 | - 'view_report' => array( |
|
182 | - 'func' => '_view_report', |
|
183 | - 'capability' => 'ee_edit_events', |
|
184 | - ), |
|
185 | - 'default_event_settings' => array( |
|
186 | - 'func' => '_default_event_settings', |
|
187 | - 'capability' => 'manage_options', |
|
188 | - ), |
|
189 | - 'update_default_event_settings' => array( |
|
190 | - 'func' => '_update_default_event_settings', |
|
191 | - 'capability' => 'manage_options', |
|
192 | - 'noheader' => true, |
|
193 | - ), |
|
194 | - 'template_settings' => array( |
|
195 | - 'func' => '_template_settings', |
|
196 | - 'capability' => 'manage_options', |
|
197 | - ), |
|
198 | - // event category tab related |
|
199 | - 'add_category' => array( |
|
200 | - 'func' => '_category_details', |
|
201 | - 'capability' => 'ee_edit_event_category', |
|
202 | - 'args' => array('add'), |
|
203 | - ), |
|
204 | - 'edit_category' => array( |
|
205 | - 'func' => '_category_details', |
|
206 | - 'capability' => 'ee_edit_event_category', |
|
207 | - 'args' => array('edit'), |
|
208 | - ), |
|
209 | - 'delete_categories' => array( |
|
210 | - 'func' => '_delete_categories', |
|
211 | - 'capability' => 'ee_delete_event_category', |
|
212 | - 'noheader' => true, |
|
213 | - ), |
|
214 | - 'delete_category' => array( |
|
215 | - 'func' => '_delete_categories', |
|
216 | - 'capability' => 'ee_delete_event_category', |
|
217 | - 'noheader' => true, |
|
218 | - ), |
|
219 | - 'insert_category' => array( |
|
220 | - 'func' => '_insert_or_update_category', |
|
221 | - 'args' => array('new_category' => true), |
|
222 | - 'capability' => 'ee_edit_event_category', |
|
223 | - 'noheader' => true, |
|
224 | - ), |
|
225 | - 'update_category' => array( |
|
226 | - 'func' => '_insert_or_update_category', |
|
227 | - 'args' => array('new_category' => false), |
|
228 | - 'capability' => 'ee_edit_event_category', |
|
229 | - 'noheader' => true, |
|
230 | - ), |
|
231 | - 'category_list' => array( |
|
232 | - 'func' => '_category_list_table', |
|
233 | - 'capability' => 'ee_manage_event_categories', |
|
234 | - ), |
|
235 | - ); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Set the _page_config property for this admin page group. |
|
241 | - */ |
|
242 | - protected function _set_page_config() |
|
243 | - { |
|
244 | - $this->_page_config = array( |
|
245 | - 'default' => array( |
|
246 | - 'nav' => array( |
|
247 | - 'label' => esc_html__('Overview', 'event_espresso'), |
|
248 | - 'order' => 10, |
|
249 | - ), |
|
250 | - 'list_table' => 'Events_Admin_List_Table', |
|
251 | - 'help_tabs' => array( |
|
252 | - 'events_overview_help_tab' => array( |
|
253 | - 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
254 | - 'filename' => 'events_overview', |
|
255 | - ), |
|
256 | - 'events_overview_table_column_headings_help_tab' => array( |
|
257 | - 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
258 | - 'filename' => 'events_overview_table_column_headings', |
|
259 | - ), |
|
260 | - 'events_overview_filters_help_tab' => array( |
|
261 | - 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
262 | - 'filename' => 'events_overview_filters', |
|
263 | - ), |
|
264 | - 'events_overview_view_help_tab' => array( |
|
265 | - 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
266 | - 'filename' => 'events_overview_views', |
|
267 | - ), |
|
268 | - 'events_overview_other_help_tab' => array( |
|
269 | - 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
270 | - 'filename' => 'events_overview_other', |
|
271 | - ), |
|
272 | - ), |
|
273 | - 'help_tour' => array( |
|
274 | - 'Event_Overview_Help_Tour', |
|
275 | - // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
276 | - ), |
|
277 | - 'qtips' => array( |
|
278 | - 'EE_Event_List_Table_Tips', |
|
279 | - ), |
|
280 | - 'require_nonce' => false, |
|
281 | - ), |
|
282 | - 'create_new' => array( |
|
283 | - 'nav' => array( |
|
284 | - 'label' => esc_html__('Add Event', 'event_espresso'), |
|
285 | - 'order' => 5, |
|
286 | - 'persistent' => false, |
|
287 | - ), |
|
288 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
289 | - 'help_tabs' => array( |
|
290 | - 'event_editor_help_tab' => array( |
|
291 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
292 | - 'filename' => 'event_editor', |
|
293 | - ), |
|
294 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
295 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
296 | - 'filename' => 'event_editor_title_richtexteditor', |
|
297 | - ), |
|
298 | - 'event_editor_venue_details_help_tab' => array( |
|
299 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
300 | - 'filename' => 'event_editor_venue_details', |
|
301 | - ), |
|
302 | - 'event_editor_event_datetimes_help_tab' => array( |
|
303 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
304 | - 'filename' => 'event_editor_event_datetimes', |
|
305 | - ), |
|
306 | - 'event_editor_event_tickets_help_tab' => array( |
|
307 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
308 | - 'filename' => 'event_editor_event_tickets', |
|
309 | - ), |
|
310 | - 'event_editor_event_registration_options_help_tab' => array( |
|
311 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
312 | - 'filename' => 'event_editor_event_registration_options', |
|
313 | - ), |
|
314 | - 'event_editor_tags_categories_help_tab' => array( |
|
315 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
316 | - 'filename' => 'event_editor_tags_categories', |
|
317 | - ), |
|
318 | - 'event_editor_questions_registrants_help_tab' => array( |
|
319 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
320 | - 'filename' => 'event_editor_questions_registrants', |
|
321 | - ), |
|
322 | - 'event_editor_save_new_event_help_tab' => array( |
|
323 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
324 | - 'filename' => 'event_editor_save_new_event', |
|
325 | - ), |
|
326 | - 'event_editor_other_help_tab' => array( |
|
327 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
328 | - 'filename' => 'event_editor_other', |
|
329 | - ), |
|
330 | - ), |
|
331 | - 'help_tour' => array( |
|
332 | - 'Event_Editor_Help_Tour', |
|
333 | - ), |
|
334 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
335 | - 'require_nonce' => false, |
|
336 | - ), |
|
337 | - 'edit' => array( |
|
338 | - 'nav' => array( |
|
339 | - 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
340 | - 'order' => 5, |
|
341 | - 'persistent' => false, |
|
342 | - 'url' => isset($this->_req_data['post']) |
|
343 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
344 | - array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
345 | - $this->_current_page_view_url |
|
346 | - ) |
|
347 | - : $this->_admin_base_url, |
|
348 | - ), |
|
349 | - 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
350 | - 'help_tabs' => array( |
|
351 | - 'event_editor_help_tab' => array( |
|
352 | - 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
353 | - 'filename' => 'event_editor', |
|
354 | - ), |
|
355 | - 'event_editor_title_richtexteditor_help_tab' => array( |
|
356 | - 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
357 | - 'filename' => 'event_editor_title_richtexteditor', |
|
358 | - ), |
|
359 | - 'event_editor_venue_details_help_tab' => array( |
|
360 | - 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
361 | - 'filename' => 'event_editor_venue_details', |
|
362 | - ), |
|
363 | - 'event_editor_event_datetimes_help_tab' => array( |
|
364 | - 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
365 | - 'filename' => 'event_editor_event_datetimes', |
|
366 | - ), |
|
367 | - 'event_editor_event_tickets_help_tab' => array( |
|
368 | - 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
369 | - 'filename' => 'event_editor_event_tickets', |
|
370 | - ), |
|
371 | - 'event_editor_event_registration_options_help_tab' => array( |
|
372 | - 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
373 | - 'filename' => 'event_editor_event_registration_options', |
|
374 | - ), |
|
375 | - 'event_editor_tags_categories_help_tab' => array( |
|
376 | - 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
377 | - 'filename' => 'event_editor_tags_categories', |
|
378 | - ), |
|
379 | - 'event_editor_questions_registrants_help_tab' => array( |
|
380 | - 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
381 | - 'filename' => 'event_editor_questions_registrants', |
|
382 | - ), |
|
383 | - 'event_editor_save_new_event_help_tab' => array( |
|
384 | - 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
385 | - 'filename' => 'event_editor_save_new_event', |
|
386 | - ), |
|
387 | - 'event_editor_other_help_tab' => array( |
|
388 | - 'title' => esc_html__('Event Other', 'event_espresso'), |
|
389 | - 'filename' => 'event_editor_other', |
|
390 | - ), |
|
391 | - ), |
|
392 | - 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
393 | - 'require_nonce' => false, |
|
394 | - ), |
|
395 | - 'default_event_settings' => array( |
|
396 | - 'nav' => array( |
|
397 | - 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
398 | - 'order' => 40, |
|
399 | - ), |
|
400 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
401 | - 'labels' => array( |
|
402 | - 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
403 | - ), |
|
404 | - 'help_tabs' => array( |
|
405 | - 'default_settings_help_tab' => array( |
|
406 | - 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
407 | - 'filename' => 'events_default_settings', |
|
408 | - ), |
|
409 | - 'default_settings_status_help_tab' => array( |
|
410 | - 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
411 | - 'filename' => 'events_default_settings_status', |
|
412 | - ), |
|
413 | - 'default_maximum_tickets_help_tab' => array( |
|
414 | - 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
415 | - 'filename' => 'events_default_settings_max_tickets', |
|
416 | - ), |
|
417 | - ), |
|
418 | - 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
419 | - 'require_nonce' => false, |
|
420 | - ), |
|
421 | - // template settings |
|
422 | - 'template_settings' => array( |
|
423 | - 'nav' => array( |
|
424 | - 'label' => esc_html__('Templates', 'event_espresso'), |
|
425 | - 'order' => 30, |
|
426 | - ), |
|
427 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
428 | - 'help_tabs' => array( |
|
429 | - 'general_settings_templates_help_tab' => array( |
|
430 | - 'title' => esc_html__('Templates', 'event_espresso'), |
|
431 | - 'filename' => 'general_settings_templates', |
|
432 | - ), |
|
433 | - ), |
|
434 | - 'help_tour' => array('Templates_Help_Tour'), |
|
435 | - 'require_nonce' => false, |
|
436 | - ), |
|
437 | - // event category stuff |
|
438 | - 'add_category' => array( |
|
439 | - 'nav' => array( |
|
440 | - 'label' => esc_html__('Add Category', 'event_espresso'), |
|
441 | - 'order' => 15, |
|
442 | - 'persistent' => false, |
|
443 | - ), |
|
444 | - 'help_tabs' => array( |
|
445 | - 'add_category_help_tab' => array( |
|
446 | - 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
447 | - 'filename' => 'events_add_category', |
|
448 | - ), |
|
449 | - ), |
|
450 | - 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
451 | - 'metaboxes' => array('_publish_post_box'), |
|
452 | - 'require_nonce' => false, |
|
453 | - ), |
|
454 | - 'edit_category' => array( |
|
455 | - 'nav' => array( |
|
456 | - 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
457 | - 'order' => 15, |
|
458 | - 'persistent' => false, |
|
459 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
460 | - ? add_query_arg( |
|
461 | - array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
462 | - $this->_current_page_view_url |
|
463 | - ) |
|
464 | - : $this->_admin_base_url, |
|
465 | - ), |
|
466 | - 'help_tabs' => array( |
|
467 | - 'edit_category_help_tab' => array( |
|
468 | - 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
469 | - 'filename' => 'events_edit_category', |
|
470 | - ), |
|
471 | - ), |
|
472 | - /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
473 | - 'metaboxes' => array('_publish_post_box'), |
|
474 | - 'require_nonce' => false, |
|
475 | - ), |
|
476 | - 'category_list' => array( |
|
477 | - 'nav' => array( |
|
478 | - 'label' => esc_html__('Categories', 'event_espresso'), |
|
479 | - 'order' => 20, |
|
480 | - ), |
|
481 | - 'list_table' => 'Event_Categories_Admin_List_Table', |
|
482 | - 'help_tabs' => array( |
|
483 | - 'events_categories_help_tab' => array( |
|
484 | - 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
485 | - 'filename' => 'events_categories', |
|
486 | - ), |
|
487 | - 'events_categories_table_column_headings_help_tab' => array( |
|
488 | - 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
489 | - 'filename' => 'events_categories_table_column_headings', |
|
490 | - ), |
|
491 | - 'events_categories_view_help_tab' => array( |
|
492 | - 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
493 | - 'filename' => 'events_categories_views', |
|
494 | - ), |
|
495 | - 'events_categories_other_help_tab' => array( |
|
496 | - 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
497 | - 'filename' => 'events_categories_other', |
|
498 | - ), |
|
499 | - ), |
|
500 | - 'help_tour' => array( |
|
501 | - 'Event_Categories_Help_Tour', |
|
502 | - ), |
|
503 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
504 | - 'require_nonce' => false, |
|
505 | - ), |
|
506 | - ); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * Used to register any global screen options if necessary for every route in this admin page group. |
|
512 | - */ |
|
513 | - protected function _add_screen_options() |
|
514 | - { |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * Implementing the screen options for the 'default' route. |
|
520 | - * |
|
521 | - * @throws InvalidArgumentException |
|
522 | - * @throws InvalidDataTypeException |
|
523 | - * @throws InvalidInterfaceException |
|
524 | - */ |
|
525 | - protected function _add_screen_options_default() |
|
526 | - { |
|
527 | - $this->_per_page_screen_option(); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * Implementing screen options for the category list route. |
|
533 | - * |
|
534 | - * @throws InvalidArgumentException |
|
535 | - * @throws InvalidDataTypeException |
|
536 | - * @throws InvalidInterfaceException |
|
537 | - */ |
|
538 | - protected function _add_screen_options_category_list() |
|
539 | - { |
|
540 | - $page_title = $this->_admin_page_title; |
|
541 | - $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
542 | - $this->_per_page_screen_option(); |
|
543 | - $this->_admin_page_title = $page_title; |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * Used to register any global feature pointers for the admin page group. |
|
549 | - */ |
|
550 | - protected function _add_feature_pointers() |
|
551 | - { |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
557 | - */ |
|
558 | - public function load_scripts_styles() |
|
559 | - { |
|
560 | - wp_register_style( |
|
561 | - 'events-admin-css', |
|
562 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
563 | - array(), |
|
564 | - EVENT_ESPRESSO_VERSION |
|
565 | - ); |
|
566 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
567 | - wp_enqueue_style('events-admin-css'); |
|
568 | - wp_enqueue_style('ee-cat-admin'); |
|
569 | - // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
570 | - // registers for all views |
|
571 | - // scripts |
|
572 | - wp_register_script( |
|
573 | - 'event_editor_js', |
|
574 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
575 | - array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
576 | - EVENT_ESPRESSO_VERSION, |
|
577 | - true |
|
578 | - ); |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Enqueuing scripts and styles specific to this view |
|
584 | - */ |
|
585 | - public function load_scripts_styles_create_new() |
|
586 | - { |
|
587 | - $this->load_scripts_styles_edit(); |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - /** |
|
592 | - * Enqueuing scripts and styles specific to this view |
|
593 | - */ |
|
594 | - public function load_scripts_styles_edit() |
|
595 | - { |
|
596 | - // styles |
|
597 | - wp_enqueue_style('espresso-ui-theme'); |
|
598 | - wp_register_style( |
|
599 | - 'event-editor-css', |
|
600 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
601 | - array('ee-admin-css'), |
|
602 | - EVENT_ESPRESSO_VERSION |
|
603 | - ); |
|
604 | - wp_enqueue_style('event-editor-css'); |
|
605 | - // scripts |
|
606 | - wp_register_script( |
|
607 | - 'event-datetime-metabox', |
|
608 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
609 | - array('event_editor_js', 'ee-datepicker'), |
|
610 | - EVENT_ESPRESSO_VERSION |
|
611 | - ); |
|
612 | - wp_enqueue_script('event-datetime-metabox'); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Populating the _views property for the category list table view. |
|
618 | - */ |
|
619 | - protected function _set_list_table_views_category_list() |
|
620 | - { |
|
621 | - $this->_views = array( |
|
622 | - 'all' => array( |
|
623 | - 'slug' => 'all', |
|
624 | - 'label' => esc_html__('All', 'event_espresso'), |
|
625 | - 'count' => 0, |
|
626 | - 'bulk_action' => array( |
|
627 | - 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
628 | - ), |
|
629 | - ), |
|
630 | - ); |
|
631 | - } |
|
632 | - |
|
633 | - |
|
634 | - /** |
|
635 | - * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
636 | - */ |
|
637 | - public function admin_init() |
|
638 | - { |
|
639 | - EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
640 | - 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
641 | - 'event_espresso' |
|
642 | - ); |
|
643 | - } |
|
644 | - |
|
645 | - |
|
646 | - /** |
|
647 | - * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
648 | - * group. |
|
649 | - */ |
|
650 | - public function admin_notices() |
|
651 | - { |
|
652 | - } |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
657 | - * this admin page group. |
|
658 | - */ |
|
659 | - public function admin_footer_scripts() |
|
660 | - { |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
666 | - * warning (via EE_Error::add_error()); |
|
667 | - * |
|
668 | - * @param EE_Event $event Event object |
|
669 | - * @param string $req_type |
|
670 | - * @return void |
|
671 | - * @throws EE_Error |
|
672 | - * @access public |
|
673 | - */ |
|
674 | - public function verify_event_edit($event = null, $req_type = '') |
|
675 | - { |
|
676 | - // don't need to do this when processing |
|
677 | - if (! empty($req_type)) { |
|
678 | - return; |
|
679 | - } |
|
680 | - // no event? |
|
681 | - if (! $event instanceof EE_Event) { |
|
682 | - $event = $this->_cpt_model_obj; |
|
683 | - } |
|
684 | - // STILL no event? |
|
685 | - if (! $event instanceof EE_Event) { |
|
686 | - return; |
|
687 | - } |
|
688 | - $orig_status = $event->status(); |
|
689 | - // first check if event is active. |
|
690 | - if ($orig_status === EEM_Event::cancelled |
|
691 | - || $orig_status === EEM_Event::postponed |
|
692 | - || $event->is_expired() |
|
693 | - || $event->is_inactive() |
|
694 | - ) { |
|
695 | - return; |
|
696 | - } |
|
697 | - // made it here so it IS active... next check that any of the tickets are sold. |
|
698 | - if ($event->is_sold_out(true)) { |
|
699 | - if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
700 | - EE_Error::add_attention( |
|
701 | - sprintf( |
|
702 | - esc_html__( |
|
703 | - 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
704 | - 'event_espresso' |
|
705 | - ), |
|
706 | - EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
707 | - ) |
|
708 | - ); |
|
709 | - } |
|
710 | - return; |
|
711 | - } |
|
712 | - if ($orig_status === EEM_Event::sold_out) { |
|
713 | - EE_Error::add_attention( |
|
714 | - sprintf( |
|
715 | - esc_html__( |
|
716 | - 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
717 | - 'event_espresso' |
|
718 | - ), |
|
719 | - EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
720 | - ) |
|
721 | - ); |
|
722 | - } |
|
723 | - // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
724 | - if (! $event->tickets_on_sale()) { |
|
725 | - return; |
|
726 | - } |
|
727 | - // made it here so show warning |
|
728 | - $this->_edit_event_warning(); |
|
729 | - } |
|
730 | - |
|
731 | - |
|
732 | - /** |
|
733 | - * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
734 | - * When needed, hook this into a EE_Error::add_error() notice. |
|
735 | - * |
|
736 | - * @access protected |
|
737 | - * @return void |
|
738 | - */ |
|
739 | - protected function _edit_event_warning() |
|
740 | - { |
|
741 | - // we don't want to add warnings during these requests |
|
742 | - if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
743 | - return; |
|
744 | - } |
|
745 | - EE_Error::add_attention( |
|
746 | - sprintf( |
|
747 | - esc_html__( |
|
748 | - 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
749 | - 'event_espresso' |
|
750 | - ), |
|
751 | - '<a class="espresso-help-tab-lnk">', |
|
752 | - '</a>' |
|
753 | - ) |
|
754 | - ); |
|
755 | - } |
|
756 | - |
|
757 | - |
|
758 | - /** |
|
759 | - * When a user is creating a new event, notify them if they haven't set their timezone. |
|
760 | - * Otherwise, do the normal logic |
|
761 | - * |
|
762 | - * @return string |
|
763 | - * @throws EE_Error |
|
764 | - * @throws InvalidArgumentException |
|
765 | - * @throws InvalidDataTypeException |
|
766 | - * @throws InvalidInterfaceException |
|
767 | - */ |
|
768 | - protected function _create_new_cpt_item() |
|
769 | - { |
|
770 | - $has_timezone_string = get_option('timezone_string'); |
|
771 | - // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
772 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
773 | - EE_Error::add_attention( |
|
774 | - sprintf( |
|
775 | - __( |
|
776 | - 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
777 | - 'event_espresso' |
|
778 | - ), |
|
779 | - '<br>', |
|
780 | - '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
781 | - . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
782 | - . '</select>', |
|
783 | - '<button class="button button-secondary timezone-submit">', |
|
784 | - '</button><span class="spinner"></span>' |
|
785 | - ), |
|
786 | - __FILE__, |
|
787 | - __FUNCTION__, |
|
788 | - __LINE__ |
|
789 | - ); |
|
790 | - } |
|
791 | - parent::_create_new_cpt_item(); |
|
792 | - } |
|
793 | - |
|
794 | - |
|
795 | - /** |
|
796 | - * Sets the _views property for the default route in this admin page group. |
|
797 | - */ |
|
798 | - protected function _set_list_table_views_default() |
|
799 | - { |
|
800 | - $this->_views = array( |
|
801 | - 'all' => array( |
|
802 | - 'slug' => 'all', |
|
803 | - 'label' => esc_html__('View All Events', 'event_espresso'), |
|
804 | - 'count' => 0, |
|
805 | - 'bulk_action' => array( |
|
806 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
807 | - ), |
|
808 | - ), |
|
809 | - 'draft' => array( |
|
810 | - 'slug' => 'draft', |
|
811 | - 'label' => esc_html__('Draft', 'event_espresso'), |
|
812 | - 'count' => 0, |
|
813 | - 'bulk_action' => array( |
|
814 | - 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
815 | - ), |
|
816 | - ), |
|
817 | - ); |
|
818 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
819 | - $this->_views['trash'] = array( |
|
820 | - 'slug' => 'trash', |
|
821 | - 'label' => esc_html__('Trash', 'event_espresso'), |
|
822 | - 'count' => 0, |
|
823 | - 'bulk_action' => array( |
|
824 | - 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
825 | - 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
826 | - ), |
|
827 | - ); |
|
828 | - } |
|
829 | - } |
|
830 | - |
|
831 | - |
|
832 | - /** |
|
833 | - * Provides the legend item array for the default list table view. |
|
834 | - * |
|
835 | - * @return array |
|
836 | - */ |
|
837 | - protected function _event_legend_items() |
|
838 | - { |
|
839 | - $items = array( |
|
840 | - 'view_details' => array( |
|
841 | - 'class' => 'dashicons dashicons-search', |
|
842 | - 'desc' => esc_html__('View Event', 'event_espresso'), |
|
843 | - ), |
|
844 | - 'edit_event' => array( |
|
845 | - 'class' => 'ee-icon ee-icon-calendar-edit', |
|
846 | - 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
847 | - ), |
|
848 | - 'view_attendees' => array( |
|
849 | - 'class' => 'dashicons dashicons-groups', |
|
850 | - 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
851 | - ), |
|
852 | - ); |
|
853 | - $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
854 | - $statuses = array( |
|
855 | - 'sold_out_status' => array( |
|
856 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
857 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
858 | - ), |
|
859 | - 'active_status' => array( |
|
860 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
861 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
862 | - ), |
|
863 | - 'upcoming_status' => array( |
|
864 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
865 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
866 | - ), |
|
867 | - 'postponed_status' => array( |
|
868 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
869 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
870 | - ), |
|
871 | - 'cancelled_status' => array( |
|
872 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
873 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
874 | - ), |
|
875 | - 'expired_status' => array( |
|
876 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
877 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
878 | - ), |
|
879 | - 'inactive_status' => array( |
|
880 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
881 | - 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
882 | - ), |
|
883 | - ); |
|
884 | - $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
885 | - return array_merge($items, $statuses); |
|
886 | - } |
|
887 | - |
|
888 | - |
|
889 | - /** |
|
890 | - * @return EEM_Event |
|
891 | - * @throws EE_Error |
|
892 | - * @throws InvalidArgumentException |
|
893 | - * @throws InvalidDataTypeException |
|
894 | - * @throws InvalidInterfaceException |
|
895 | - * @throws ReflectionException |
|
896 | - */ |
|
897 | - private function _event_model() |
|
898 | - { |
|
899 | - if (! $this->_event_model instanceof EEM_Event) { |
|
900 | - $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
901 | - } |
|
902 | - return $this->_event_model; |
|
903 | - } |
|
904 | - |
|
905 | - |
|
906 | - /** |
|
907 | - * Adds extra buttons to the WP CPT permalink field row. |
|
908 | - * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
909 | - * |
|
910 | - * @param string $return the current html |
|
911 | - * @param int $id the post id for the page |
|
912 | - * @param string $new_title What the title is |
|
913 | - * @param string $new_slug what the slug is |
|
914 | - * @return string The new html string for the permalink area |
|
915 | - */ |
|
916 | - public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
917 | - { |
|
918 | - // make sure this is only when editing |
|
919 | - if (! empty($id)) { |
|
920 | - $post = get_post($id); |
|
921 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
922 | - . esc_html__('Shortcode', 'event_espresso') |
|
923 | - . '</a> '; |
|
924 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
925 | - . $post->ID |
|
926 | - . ']">'; |
|
927 | - } |
|
928 | - return $return; |
|
929 | - } |
|
930 | - |
|
931 | - |
|
932 | - /** |
|
933 | - * _events_overview_list_table |
|
934 | - * This contains the logic for showing the events_overview list |
|
935 | - * |
|
936 | - * @access protected |
|
937 | - * @return void |
|
938 | - * @throws DomainException |
|
939 | - * @throws EE_Error |
|
940 | - * @throws InvalidArgumentException |
|
941 | - * @throws InvalidDataTypeException |
|
942 | - * @throws InvalidInterfaceException |
|
943 | - */ |
|
944 | - protected function _events_overview_list_table() |
|
945 | - { |
|
946 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
947 | - $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
948 | - ? (array) $this->_template_args['after_list_table'] |
|
949 | - : array(); |
|
950 | - $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
951 | - . EEH_Template::get_button_or_link( |
|
952 | - get_post_type_archive_link('espresso_events'), |
|
953 | - esc_html__('View Event Archive Page', 'event_espresso'), |
|
954 | - 'button' |
|
955 | - ); |
|
956 | - $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
957 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
958 | - 'create_new', |
|
959 | - 'add', |
|
960 | - array(), |
|
961 | - 'add-new-h2' |
|
962 | - ); |
|
963 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
964 | - } |
|
965 | - |
|
966 | - |
|
967 | - /** |
|
968 | - * this allows for extra misc actions in the default WP publish box |
|
969 | - * |
|
970 | - * @return void |
|
971 | - * @throws DomainException |
|
972 | - * @throws EE_Error |
|
973 | - * @throws InvalidArgumentException |
|
974 | - * @throws InvalidDataTypeException |
|
975 | - * @throws InvalidInterfaceException |
|
976 | - * @throws ReflectionException |
|
977 | - */ |
|
978 | - public function extra_misc_actions_publish_box() |
|
979 | - { |
|
980 | - $this->_generate_publish_box_extra_content(); |
|
981 | - } |
|
982 | - |
|
983 | - |
|
984 | - /** |
|
985 | - * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
986 | - * saved. |
|
987 | - * Typically you would use this to save any additional data. |
|
988 | - * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
989 | - * ALSO very important. When a post transitions from scheduled to published, |
|
990 | - * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
991 | - * other meta saves. So MAKE sure that you handle this accordingly. |
|
992 | - * |
|
993 | - * @access protected |
|
994 | - * @abstract |
|
995 | - * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
996 | - * @param object $post The post object of the cpt that was saved. |
|
997 | - * @return void |
|
998 | - * @throws EE_Error |
|
999 | - * @throws InvalidArgumentException |
|
1000 | - * @throws InvalidDataTypeException |
|
1001 | - * @throws InvalidInterfaceException |
|
1002 | - * @throws ReflectionException |
|
1003 | - */ |
|
1004 | - protected function _insert_update_cpt_item($post_id, $post) |
|
1005 | - { |
|
1006 | - if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
1007 | - // get out we're not processing an event save. |
|
1008 | - return; |
|
1009 | - } |
|
1010 | - $event_values = array( |
|
1011 | - 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
1012 | - 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
1013 | - 'EVT_additional_limit' => min( |
|
1014 | - apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
1015 | - ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
1016 | - ), |
|
1017 | - 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
1018 | - ? $this->_req_data['EVT_default_registration_status'] |
|
1019 | - : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
1020 | - 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
1021 | - 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
1022 | - 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
1023 | - ? $this->_req_data['timezone_string'] : null, |
|
1024 | - 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
1025 | - ? $this->_req_data['externalURL'] : null, |
|
1026 | - 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
1027 | - ? $this->_req_data['event_phone'] : null, |
|
1028 | - ); |
|
1029 | - // update event |
|
1030 | - $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
1031 | - // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
1032 | - $get_one_where = array( |
|
1033 | - $this->_event_model()->primary_key_name() => $post_id, |
|
1034 | - 'OR' => array( |
|
1035 | - 'status' => $post->post_status, |
|
1036 | - // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
1037 | - // but the returned object here has a status of "publish", so use the original post status as well |
|
1038 | - 'status*1' => $this->_req_data['original_post_status'], |
|
1039 | - ), |
|
1040 | - ); |
|
1041 | - $event = $this->_event_model()->get_one(array($get_one_where)); |
|
1042 | - // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
1043 | - $event_update_callbacks = apply_filters( |
|
1044 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
1045 | - array( |
|
1046 | - array($this, '_default_venue_update'), |
|
1047 | - array($this, '_default_tickets_update'), |
|
1048 | - ) |
|
1049 | - ); |
|
1050 | - $att_success = true; |
|
1051 | - foreach ($event_update_callbacks as $e_callback) { |
|
1052 | - $_success = is_callable($e_callback) |
|
1053 | - ? $e_callback($event, $this->_req_data) |
|
1054 | - : false; |
|
1055 | - // if ANY of these updates fail then we want the appropriate global error message |
|
1056 | - $att_success = ! $att_success ? $att_success : $_success; |
|
1057 | - } |
|
1058 | - // any errors? |
|
1059 | - if ($success && false === $att_success) { |
|
1060 | - EE_Error::add_error( |
|
1061 | - esc_html__( |
|
1062 | - 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1063 | - 'event_espresso' |
|
1064 | - ), |
|
1065 | - __FILE__, |
|
1066 | - __FUNCTION__, |
|
1067 | - __LINE__ |
|
1068 | - ); |
|
1069 | - } elseif ($success === false) { |
|
1070 | - EE_Error::add_error( |
|
1071 | - esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1072 | - __FILE__, |
|
1073 | - __FUNCTION__, |
|
1074 | - __LINE__ |
|
1075 | - ); |
|
1076 | - } |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * @param int $post_id |
|
1082 | - * @param int $revision_id |
|
1083 | - * @throws EE_Error |
|
1084 | - * @throws InvalidArgumentException |
|
1085 | - * @throws InvalidDataTypeException |
|
1086 | - * @throws InvalidInterfaceException |
|
1087 | - * @throws ReflectionException |
|
1088 | - * @see parent::restore_item() |
|
1089 | - */ |
|
1090 | - protected function _restore_cpt_item($post_id, $revision_id) |
|
1091 | - { |
|
1092 | - // copy existing event meta to new post |
|
1093 | - $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1094 | - if ($post_evt instanceof EE_Event) { |
|
1095 | - // meta revision restore |
|
1096 | - $post_evt->restore_revision($revision_id); |
|
1097 | - // related objs restore |
|
1098 | - $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
1099 | - } |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * Attach the venue to the Event |
|
1105 | - * |
|
1106 | - * @param EE_Event $evtobj Event Object to add the venue to |
|
1107 | - * @param array $data The request data from the form |
|
1108 | - * @return bool Success or fail. |
|
1109 | - * @throws EE_Error |
|
1110 | - * @throws InvalidArgumentException |
|
1111 | - * @throws InvalidDataTypeException |
|
1112 | - * @throws InvalidInterfaceException |
|
1113 | - * @throws ReflectionException |
|
1114 | - */ |
|
1115 | - protected function _default_venue_update(EE_Event $evtobj, $data) |
|
1116 | - { |
|
1117 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1118 | - $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1119 | - $rows_affected = null; |
|
1120 | - $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1121 | - // very important. If we don't have a venue name... |
|
1122 | - // then we'll get out because not necessary to create empty venue |
|
1123 | - if (empty($data['venue_title'])) { |
|
1124 | - return false; |
|
1125 | - } |
|
1126 | - $venue_array = array( |
|
1127 | - 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
1128 | - 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
1129 | - 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1130 | - 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1131 | - 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
1132 | - : null, |
|
1133 | - 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1134 | - 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1135 | - 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1136 | - 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1137 | - 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1138 | - 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1139 | - 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1140 | - 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1141 | - 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1142 | - 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1143 | - 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1144 | - 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1145 | - 'status' => 'publish', |
|
1146 | - ); |
|
1147 | - // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1148 | - if (! empty($venue_id)) { |
|
1149 | - $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
1150 | - $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
1151 | - // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
1152 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1153 | - return $rows_affected > 0; |
|
1154 | - } |
|
1155 | - // we insert the venue |
|
1156 | - $venue_id = $venue_model->insert($venue_array); |
|
1157 | - $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1158 | - return ! empty($venue_id) ? true : false; |
|
1159 | - // when we have the ancestor come in it's already been handled by the revision save. |
|
1160 | - } |
|
1161 | - |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1165 | - * |
|
1166 | - * @param EE_Event $evtobj The Event object we're attaching data to |
|
1167 | - * @param array $data The request data from the form |
|
1168 | - * @return array |
|
1169 | - * @throws EE_Error |
|
1170 | - * @throws InvalidArgumentException |
|
1171 | - * @throws InvalidDataTypeException |
|
1172 | - * @throws InvalidInterfaceException |
|
1173 | - * @throws ReflectionException |
|
1174 | - * @throws Exception |
|
1175 | - */ |
|
1176 | - protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
1177 | - { |
|
1178 | - $success = true; |
|
1179 | - $saved_dtt = null; |
|
1180 | - $saved_tickets = array(); |
|
1181 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1182 | - foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
1183 | - // trim all values to ensure any excess whitespace is removed. |
|
1184 | - $dtt = array_map('trim', $dtt); |
|
1185 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
1186 | - : $dtt['DTT_EVT_start']; |
|
1187 | - $datetime_values = array( |
|
1188 | - 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
1189 | - 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
1190 | - 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
1191 | - 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
1192 | - 'DTT_order' => $row, |
|
1193 | - ); |
|
1194 | - // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
1195 | - if (! empty($dtt['DTT_ID'])) { |
|
1196 | - $DTM = EE_Registry::instance() |
|
1197 | - ->load_model('Datetime', array($evtobj->get_timezone())) |
|
1198 | - ->get_one_by_ID($dtt['DTT_ID']); |
|
1199 | - $DTM->set_date_format($incoming_date_formats[0]); |
|
1200 | - $DTM->set_time_format($incoming_date_formats[1]); |
|
1201 | - foreach ($datetime_values as $field => $value) { |
|
1202 | - $DTM->set($field, $value); |
|
1203 | - } |
|
1204 | - // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
1205 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
1206 | - } else { |
|
1207 | - $DTM = EE_Registry::instance()->load_class( |
|
1208 | - 'Datetime', |
|
1209 | - array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
1210 | - false, |
|
1211 | - false |
|
1212 | - ); |
|
1213 | - foreach ($datetime_values as $field => $value) { |
|
1214 | - $DTM->set($field, $value); |
|
1215 | - } |
|
1216 | - } |
|
1217 | - $DTM->save(); |
|
1218 | - $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
1219 | - // load DTT helper |
|
1220 | - // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
1221 | - if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
1222 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
1223 | - $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
1224 | - $DTT->save(); |
|
1225 | - } |
|
1226 | - // now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
1227 | - $saved_dtt = $DTT; |
|
1228 | - $success = ! $success ? $success : $DTT; |
|
1229 | - // if ANY of these updates fail then we want the appropriate global error message. |
|
1230 | - // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
1231 | - } |
|
1232 | - // no dtts get deleted so we don't do any of that logic here. |
|
1233 | - // update tickets next |
|
1234 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
1235 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
1236 | - $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1237 | - $update_prices = false; |
|
1238 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
1239 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
1240 | - // trim inputs to ensure any excess whitespace is removed. |
|
1241 | - $tkt = array_map('trim', $tkt); |
|
1242 | - if (empty($tkt['TKT_start_date'])) { |
|
1243 | - // let's use now in the set timezone. |
|
1244 | - $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
1245 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1246 | - } |
|
1247 | - if (empty($tkt['TKT_end_date'])) { |
|
1248 | - // use the start date of the first datetime |
|
1249 | - $dtt = $evtobj->first_datetime(); |
|
1250 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
1251 | - $incoming_date_formats[0], |
|
1252 | - $incoming_date_formats[1] |
|
1253 | - ); |
|
1254 | - } |
|
1255 | - $TKT_values = array( |
|
1256 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
1257 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
1258 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
1259 | - 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
1260 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
1261 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
1262 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
1263 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
1264 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
1265 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
1266 | - 'TKT_row' => $row, |
|
1267 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
1268 | - 'TKT_price' => $ticket_price, |
|
1269 | - ); |
|
1270 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
1271 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
1272 | - $TKT_values['TKT_ID'] = 0; |
|
1273 | - $TKT_values['TKT_is_default'] = 0; |
|
1274 | - $TKT_values['TKT_price'] = $ticket_price; |
|
1275 | - $update_prices = true; |
|
1276 | - } |
|
1277 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1278 | - // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
1279 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
1280 | - if (! empty($tkt['TKT_ID'])) { |
|
1281 | - $TKT = EE_Registry::instance() |
|
1282 | - ->load_model('Ticket', array($evtobj->get_timezone())) |
|
1283 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
1284 | - if ($TKT instanceof EE_Ticket) { |
|
1285 | - $ticket_sold = $TKT->count_related( |
|
1286 | - 'Registration', |
|
1287 | - array( |
|
1288 | - array( |
|
1289 | - 'STS_ID' => array( |
|
1290 | - 'NOT IN', |
|
1291 | - array(EEM_Registration::status_id_incomplete), |
|
1292 | - ), |
|
1293 | - ), |
|
1294 | - ) |
|
1295 | - ) > 0; |
|
1296 | - // let's just check the total price for the existing ticket and determine if it matches the new |
|
1297 | - // total price. if they are different then we create a new ticket (if tickets sold) |
|
1298 | - // if they aren't different then we go ahead and modify existing ticket. |
|
1299 | - $create_new_TKT = $ticket_sold && ! $TKT->deleted() && EEH_Money::compare_floats( |
|
1300 | - $ticket_price, |
|
1301 | - $TKT->get('TKT_price'), |
|
1302 | - '!==' |
|
1303 | - ); |
|
1304 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
1305 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
1306 | - // set new values |
|
1307 | - foreach ($TKT_values as $field => $value) { |
|
1308 | - if ($field === 'TKT_qty') { |
|
1309 | - $TKT->set_qty($value); |
|
1310 | - } else { |
|
1311 | - $TKT->set($field, $value); |
|
1312 | - } |
|
1313 | - } |
|
1314 | - // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
1315 | - if ($create_new_TKT) { |
|
1316 | - // archive the old ticket first |
|
1317 | - $TKT->set('TKT_deleted', 1); |
|
1318 | - $TKT->save(); |
|
1319 | - // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
1320 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1321 | - // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
1322 | - $TKT = clone $TKT; |
|
1323 | - $TKT->set('TKT_ID', 0); |
|
1324 | - $TKT->set('TKT_deleted', 0); |
|
1325 | - $TKT->set('TKT_price', $ticket_price); |
|
1326 | - $TKT->set('TKT_sold', 0); |
|
1327 | - // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1328 | - $update_prices = true; |
|
1329 | - } |
|
1330 | - // make sure price is set if it hasn't been already |
|
1331 | - $TKT->set('TKT_price', $ticket_price); |
|
1332 | - } |
|
1333 | - } else { |
|
1334 | - // no TKT_id so a new TKT |
|
1335 | - $TKT_values['TKT_price'] = $ticket_price; |
|
1336 | - $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
1337 | - if ($TKT instanceof EE_Ticket) { |
|
1338 | - // need to reset values to properly account for the date formats |
|
1339 | - $TKT->set_date_format($incoming_date_formats[0]); |
|
1340 | - $TKT->set_time_format($incoming_date_formats[1]); |
|
1341 | - $TKT->set_timezone($evtobj->get_timezone()); |
|
1342 | - // set new values |
|
1343 | - foreach ($TKT_values as $field => $value) { |
|
1344 | - if ($field === 'TKT_qty') { |
|
1345 | - $TKT->set_qty($value); |
|
1346 | - } else { |
|
1347 | - $TKT->set($field, $value); |
|
1348 | - } |
|
1349 | - } |
|
1350 | - $update_prices = true; |
|
1351 | - } |
|
1352 | - } |
|
1353 | - // cap ticket qty by datetime reg limits |
|
1354 | - $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
1355 | - // update ticket. |
|
1356 | - $TKT->save(); |
|
1357 | - // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
1358 | - if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
1359 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
1360 | - $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
1361 | - $TKT->save(); |
|
1362 | - } |
|
1363 | - // initially let's add the ticket to the dtt |
|
1364 | - $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
1365 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1366 | - // add prices to ticket |
|
1367 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
1368 | - } |
|
1369 | - // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
1370 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
1371 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1372 | - foreach ($tickets_removed as $id) { |
|
1373 | - $id = absint($id); |
|
1374 | - // get the ticket for this id |
|
1375 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
1376 | - // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
1377 | - $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
1378 | - foreach ($dtts as $dtt) { |
|
1379 | - $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
1380 | - } |
|
1381 | - // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
1382 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
1383 | - // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
1384 | - $tkt_to_remove->delete_permanently(); |
|
1385 | - } |
|
1386 | - return array($saved_dtt, $saved_tickets); |
|
1387 | - } |
|
1388 | - |
|
1389 | - |
|
1390 | - /** |
|
1391 | - * This attaches a list of given prices to a ticket. |
|
1392 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
1393 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
1394 | - * price info and prices are automatically "archived" via the ticket. |
|
1395 | - * |
|
1396 | - * @access private |
|
1397 | - * @param array $prices Array of prices from the form. |
|
1398 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1399 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1400 | - * @return void |
|
1401 | - * @throws EE_Error |
|
1402 | - * @throws InvalidArgumentException |
|
1403 | - * @throws InvalidDataTypeException |
|
1404 | - * @throws InvalidInterfaceException |
|
1405 | - * @throws ReflectionException |
|
1406 | - */ |
|
1407 | - private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
1408 | - { |
|
1409 | - foreach ($prices as $row => $prc) { |
|
1410 | - $PRC_values = array( |
|
1411 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
1412 | - 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
1413 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
1414 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
1415 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
1416 | - 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
1417 | - 'PRC_order' => $row, |
|
1418 | - ); |
|
1419 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
1420 | - $PRC_values['PRC_ID'] = 0; |
|
1421 | - $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
1422 | - } else { |
|
1423 | - $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
1424 | - // update this price with new values |
|
1425 | - foreach ($PRC_values as $field => $newprc) { |
|
1426 | - $PRC->set($field, $newprc); |
|
1427 | - } |
|
1428 | - $PRC->save(); |
|
1429 | - } |
|
1430 | - $ticket->_add_relation_to($PRC, 'Price'); |
|
1431 | - } |
|
1432 | - } |
|
1433 | - |
|
1434 | - |
|
1435 | - /** |
|
1436 | - * Add in our autosave ajax handlers |
|
1437 | - * |
|
1438 | - */ |
|
1439 | - protected function _ee_autosave_create_new() |
|
1440 | - { |
|
1441 | - } |
|
1442 | - |
|
1443 | - |
|
1444 | - /** |
|
1445 | - * More autosave handlers. |
|
1446 | - */ |
|
1447 | - protected function _ee_autosave_edit() |
|
1448 | - { |
|
1449 | - } |
|
1450 | - |
|
1451 | - |
|
1452 | - /** |
|
1453 | - * _generate_publish_box_extra_content |
|
1454 | - * |
|
1455 | - * @throws DomainException |
|
1456 | - * @throws EE_Error |
|
1457 | - * @throws InvalidArgumentException |
|
1458 | - * @throws InvalidDataTypeException |
|
1459 | - * @throws InvalidInterfaceException |
|
1460 | - * @throws ReflectionException |
|
1461 | - */ |
|
1462 | - private function _generate_publish_box_extra_content() |
|
1463 | - { |
|
1464 | - // load formatter helper |
|
1465 | - // args for getting related registrations |
|
1466 | - $approved_query_args = array( |
|
1467 | - array( |
|
1468 | - 'REG_deleted' => 0, |
|
1469 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
1470 | - ), |
|
1471 | - ); |
|
1472 | - $not_approved_query_args = array( |
|
1473 | - array( |
|
1474 | - 'REG_deleted' => 0, |
|
1475 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1476 | - ), |
|
1477 | - ); |
|
1478 | - $pending_payment_query_args = array( |
|
1479 | - array( |
|
1480 | - 'REG_deleted' => 0, |
|
1481 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1482 | - ), |
|
1483 | - ); |
|
1484 | - // publish box |
|
1485 | - $publish_box_extra_args = array( |
|
1486 | - 'view_approved_reg_url' => add_query_arg( |
|
1487 | - array( |
|
1488 | - 'action' => 'default', |
|
1489 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1490 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1491 | - ), |
|
1492 | - REG_ADMIN_URL |
|
1493 | - ), |
|
1494 | - 'view_not_approved_reg_url' => add_query_arg( |
|
1495 | - array( |
|
1496 | - 'action' => 'default', |
|
1497 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1498 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1499 | - ), |
|
1500 | - REG_ADMIN_URL |
|
1501 | - ), |
|
1502 | - 'view_pending_payment_reg_url' => add_query_arg( |
|
1503 | - array( |
|
1504 | - 'action' => 'default', |
|
1505 | - 'event_id' => $this->_cpt_model_obj->ID(), |
|
1506 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1507 | - ), |
|
1508 | - REG_ADMIN_URL |
|
1509 | - ), |
|
1510 | - 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1511 | - 'Registration', |
|
1512 | - $approved_query_args |
|
1513 | - ), |
|
1514 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1515 | - 'Registration', |
|
1516 | - $not_approved_query_args |
|
1517 | - ), |
|
1518 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1519 | - 'Registration', |
|
1520 | - $pending_payment_query_args |
|
1521 | - ), |
|
1522 | - 'misc_pub_section_class' => apply_filters( |
|
1523 | - 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1524 | - 'misc-pub-section' |
|
1525 | - ), |
|
1526 | - ); |
|
1527 | - ob_start(); |
|
1528 | - do_action( |
|
1529 | - 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1530 | - $this->_cpt_model_obj |
|
1531 | - ); |
|
1532 | - $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1533 | - // load template |
|
1534 | - EEH_Template::display_template( |
|
1535 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1536 | - $publish_box_extra_args |
|
1537 | - ); |
|
1538 | - } |
|
1539 | - |
|
1540 | - |
|
1541 | - /** |
|
1542 | - * @return EE_Event |
|
1543 | - */ |
|
1544 | - public function get_event_object() |
|
1545 | - { |
|
1546 | - return $this->_cpt_model_obj; |
|
1547 | - } |
|
1548 | - |
|
1549 | - |
|
1550 | - |
|
1551 | - |
|
1552 | - /** METABOXES * */ |
|
1553 | - /** |
|
1554 | - * _register_event_editor_meta_boxes |
|
1555 | - * add all metaboxes related to the event_editor |
|
1556 | - * |
|
1557 | - * @return void |
|
1558 | - * @throws EE_Error |
|
1559 | - * @throws InvalidArgumentException |
|
1560 | - * @throws InvalidDataTypeException |
|
1561 | - * @throws InvalidInterfaceException |
|
1562 | - * @throws ReflectionException |
|
1563 | - */ |
|
1564 | - protected function _register_event_editor_meta_boxes() |
|
1565 | - { |
|
1566 | - $this->verify_cpt_object(); |
|
1567 | - // add_meta_box( |
|
1568 | - // 'espresso_event_editor_tickets', |
|
1569 | - // esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1570 | - // array($this, 'ticket_metabox'), |
|
1571 | - // $this->page_slug, |
|
1572 | - // 'normal', |
|
1573 | - // 'high' |
|
1574 | - // ); |
|
1575 | - add_meta_box( |
|
1576 | - 'espresso_event_editor_event_options', |
|
1577 | - esc_html__('Event Registration Options', 'event_espresso'), |
|
1578 | - array($this, 'registration_options_meta_box'), |
|
1579 | - $this->page_slug, |
|
1580 | - 'side' |
|
1581 | - ); |
|
1582 | - // NOTE: if you're looking for other metaboxes in here, |
|
1583 | - // where a metabox has a related management page in the admin |
|
1584 | - // you will find it setup in the related management page's "_Hooks" file. |
|
1585 | - // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1586 | - } |
|
1587 | - |
|
1588 | - |
|
1589 | - /** |
|
1590 | - * @throws DomainException |
|
1591 | - * @throws EE_Error |
|
1592 | - * @throws InvalidArgumentException |
|
1593 | - * @throws InvalidDataTypeException |
|
1594 | - * @throws InvalidInterfaceException |
|
1595 | - * @throws ReflectionException |
|
1596 | - */ |
|
1597 | - public function ticket_metabox() |
|
1598 | - { |
|
1599 | - $existing_datetime_ids = $existing_ticket_ids = array(); |
|
1600 | - // defaults for template args |
|
1601 | - $template_args = array( |
|
1602 | - 'existing_datetime_ids' => '', |
|
1603 | - 'event_datetime_help_link' => '', |
|
1604 | - 'ticket_options_help_link' => '', |
|
1605 | - 'time' => null, |
|
1606 | - 'ticket_rows' => '', |
|
1607 | - 'existing_ticket_ids' => '', |
|
1608 | - 'total_ticket_rows' => 1, |
|
1609 | - 'ticket_js_structure' => '', |
|
1610 | - 'trash_icon' => 'ee-lock-icon', |
|
1611 | - 'disabled' => '', |
|
1612 | - ); |
|
1613 | - $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1614 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1615 | - /** |
|
1616 | - * 1. Start with retrieving Datetimes |
|
1617 | - * 2. Fore each datetime get related tickets |
|
1618 | - * 3. For each ticket get related prices |
|
1619 | - */ |
|
1620 | - $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
1621 | - /** @type EE_Datetime $first_datetime */ |
|
1622 | - $first_datetime = reset($times); |
|
1623 | - // do we get related tickets? |
|
1624 | - if ($first_datetime instanceof EE_Datetime |
|
1625 | - && $first_datetime->ID() !== 0 |
|
1626 | - ) { |
|
1627 | - $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1628 | - $template_args['time'] = $first_datetime; |
|
1629 | - $related_tickets = $first_datetime->tickets( |
|
1630 | - array( |
|
1631 | - array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
1632 | - 'default_where_conditions' => 'none', |
|
1633 | - ) |
|
1634 | - ); |
|
1635 | - if (! empty($related_tickets)) { |
|
1636 | - $template_args['total_ticket_rows'] = count($related_tickets); |
|
1637 | - $row = 0; |
|
1638 | - foreach ($related_tickets as $ticket) { |
|
1639 | - $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1640 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1641 | - $row++; |
|
1642 | - } |
|
1643 | - } else { |
|
1644 | - $template_args['total_ticket_rows'] = 1; |
|
1645 | - /** @type EE_Ticket $ticket */ |
|
1646 | - $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
1647 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1648 | - } |
|
1649 | - } else { |
|
1650 | - $template_args['time'] = $times[0]; |
|
1651 | - /** @type EE_Ticket $ticket */ |
|
1652 | - $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
1653 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
1654 | - // NOTE: we're just sending the first default row |
|
1655 | - // (decaf can't manage default tickets so this should be sufficient); |
|
1656 | - } |
|
1657 | - $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1658 | - 'event_editor_event_datetimes_help_tab' |
|
1659 | - ); |
|
1660 | - $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1661 | - $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1662 | - $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1663 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1664 | - EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
1665 | - true |
|
1666 | - ); |
|
1667 | - $template = apply_filters( |
|
1668 | - 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1669 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1670 | - ); |
|
1671 | - EEH_Template::display_template($template, $template_args); |
|
1672 | - } |
|
1673 | - |
|
1674 | - |
|
1675 | - /** |
|
1676 | - * Setup an individual ticket form for the decaf event editor page |
|
1677 | - * |
|
1678 | - * @access private |
|
1679 | - * @param EE_Ticket $ticket the ticket object |
|
1680 | - * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1681 | - * @param int $row |
|
1682 | - * @return string generated html for the ticket row. |
|
1683 | - * @throws DomainException |
|
1684 | - * @throws EE_Error |
|
1685 | - * @throws InvalidArgumentException |
|
1686 | - * @throws InvalidDataTypeException |
|
1687 | - * @throws InvalidInterfaceException |
|
1688 | - * @throws ReflectionException |
|
1689 | - */ |
|
1690 | - private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
1691 | - { |
|
1692 | - $template_args = array( |
|
1693 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1694 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1695 | - : '', |
|
1696 | - 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1697 | - 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1698 | - 'TKT_name' => $ticket->get('TKT_name'), |
|
1699 | - 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1700 | - 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1701 | - 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1702 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1703 | - 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1704 | - 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1705 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1706 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1707 | - ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1708 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1709 | - : ' disabled=disabled', |
|
1710 | - ); |
|
1711 | - $price = $ticket->ID() !== 0 |
|
1712 | - ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
1713 | - : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
1714 | - $price_args = array( |
|
1715 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1716 | - 'PRC_amount' => $price->get('PRC_amount'), |
|
1717 | - 'PRT_ID' => $price->get('PRT_ID'), |
|
1718 | - 'PRC_ID' => $price->get('PRC_ID'), |
|
1719 | - 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1720 | - ); |
|
1721 | - // make sure we have default start and end dates if skeleton |
|
1722 | - // handle rows that should NOT be empty |
|
1723 | - if (empty($template_args['TKT_start_date'])) { |
|
1724 | - // if empty then the start date will be now. |
|
1725 | - $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1726 | - } |
|
1727 | - if (empty($template_args['TKT_end_date'])) { |
|
1728 | - // get the earliest datetime (if present); |
|
1729 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
1730 | - ? $this->_cpt_model_obj->get_first_related( |
|
1731 | - 'Datetime', |
|
1732 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1733 | - ) |
|
1734 | - : null; |
|
1735 | - if (! empty($earliest_dtt)) { |
|
1736 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
1737 | - } else { |
|
1738 | - $template_args['TKT_end_date'] = date( |
|
1739 | - 'Y-m-d h:i a', |
|
1740 | - mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')) |
|
1741 | - ); |
|
1742 | - } |
|
1743 | - } |
|
1744 | - $template_args = array_merge($template_args, $price_args); |
|
1745 | - $template = apply_filters( |
|
1746 | - 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1747 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1748 | - $ticket |
|
1749 | - ); |
|
1750 | - return EEH_Template::display_template($template, $template_args, true); |
|
1751 | - } |
|
1752 | - |
|
1753 | - |
|
1754 | - /** |
|
1755 | - * @throws DomainException |
|
1756 | - * @throws EE_Error |
|
1757 | - */ |
|
1758 | - public function registration_options_meta_box() |
|
1759 | - { |
|
1760 | - $yes_no_values = array( |
|
1761 | - array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
1762 | - array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
1763 | - ); |
|
1764 | - $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1765 | - array( |
|
1766 | - EEM_Registration::status_id_cancelled, |
|
1767 | - EEM_Registration::status_id_declined, |
|
1768 | - EEM_Registration::status_id_incomplete, |
|
1769 | - ), |
|
1770 | - true |
|
1771 | - ); |
|
1772 | - // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1773 | - $template_args['_event'] = $this->_cpt_model_obj; |
|
1774 | - $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1775 | - $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1776 | - $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1777 | - 'default_reg_status', |
|
1778 | - $default_reg_status_values, |
|
1779 | - $this->_cpt_model_obj->default_registration_status() |
|
1780 | - ); |
|
1781 | - $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1782 | - 'display_desc', |
|
1783 | - $yes_no_values, |
|
1784 | - $this->_cpt_model_obj->display_description() |
|
1785 | - ); |
|
1786 | - $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1787 | - 'display_ticket_selector', |
|
1788 | - $yes_no_values, |
|
1789 | - $this->_cpt_model_obj->display_ticket_selector(), |
|
1790 | - '', |
|
1791 | - '', |
|
1792 | - false |
|
1793 | - ); |
|
1794 | - $template_args['additional_registration_options'] = apply_filters( |
|
1795 | - 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1796 | - '', |
|
1797 | - $template_args, |
|
1798 | - $yes_no_values, |
|
1799 | - $default_reg_status_values |
|
1800 | - ); |
|
1801 | - EEH_Template::display_template( |
|
1802 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1803 | - $template_args |
|
1804 | - ); |
|
1805 | - } |
|
1806 | - |
|
1807 | - |
|
1808 | - /** |
|
1809 | - * _get_events() |
|
1810 | - * This method simply returns all the events (for the given _view and paging) |
|
1811 | - * |
|
1812 | - * @access public |
|
1813 | - * @param int $per_page count of items per page (20 default); |
|
1814 | - * @param int $current_page what is the current page being viewed. |
|
1815 | - * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1816 | - * If FALSE then we return an array of event objects |
|
1817 | - * that match the given _view and paging parameters. |
|
1818 | - * @return array an array of event objects. |
|
1819 | - * @throws EE_Error |
|
1820 | - * @throws InvalidArgumentException |
|
1821 | - * @throws InvalidDataTypeException |
|
1822 | - * @throws InvalidInterfaceException |
|
1823 | - * @throws ReflectionException |
|
1824 | - * @throws Exception |
|
1825 | - * @throws Exception |
|
1826 | - * @throws Exception |
|
1827 | - */ |
|
1828 | - public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
1829 | - { |
|
1830 | - $EEME = $this->_event_model(); |
|
1831 | - $offset = ($current_page - 1) * $per_page; |
|
1832 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
1833 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
1834 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
1835 | - if (isset($this->_req_data['month_range'])) { |
|
1836 | - $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
1837 | - // simulate the FIRST day of the month, that fixes issues for months like February |
|
1838 | - // where PHP doesn't know what to assume for date. |
|
1839 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1840 | - $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1841 | - $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1842 | - } |
|
1843 | - $where = array(); |
|
1844 | - $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
1845 | - // determine what post_status our condition will have for the query. |
|
1846 | - switch ($status) { |
|
1847 | - case 'month': |
|
1848 | - case 'today': |
|
1849 | - case null: |
|
1850 | - case 'all': |
|
1851 | - break; |
|
1852 | - case 'draft': |
|
1853 | - $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
1854 | - break; |
|
1855 | - default: |
|
1856 | - $where['status'] = $status; |
|
1857 | - } |
|
1858 | - // categories? |
|
1859 | - $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
1860 | - ? $this->_req_data['EVT_CAT'] : null; |
|
1861 | - if (! empty($category)) { |
|
1862 | - $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
1863 | - $where['Term_Taxonomy.term_id'] = $category; |
|
1864 | - } |
|
1865 | - // date where conditions |
|
1866 | - $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1867 | - if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
|
1868 | - $DateTime = new DateTime( |
|
1869 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
1870 | - new DateTimeZone('UTC') |
|
1871 | - ); |
|
1872 | - $start = $DateTime->getTimestamp(); |
|
1873 | - // set the datetime to be the end of the month |
|
1874 | - $DateTime->setDate( |
|
1875 | - $year_r, |
|
1876 | - $month_r, |
|
1877 | - $DateTime->format('t') |
|
1878 | - )->setTime(23, 59, 59); |
|
1879 | - $end = $DateTime->getTimestamp(); |
|
1880 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1881 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') { |
|
1882 | - $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1883 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1884 | - $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1885 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1886 | - } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') { |
|
1887 | - $now = date('Y-m-01'); |
|
1888 | - $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1889 | - $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1890 | - $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1891 | - ->setTime(23, 59, 59) |
|
1892 | - ->format(implode(' ', $start_formats)); |
|
1893 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1894 | - } |
|
1895 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1896 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
1897 | - } elseif (! isset($where['status']) |
|
1898 | - && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events') |
|
1899 | - ) { |
|
1900 | - $where['OR'] = array( |
|
1901 | - 'status*restrict_private' => array('!=', 'private'), |
|
1902 | - 'AND' => array( |
|
1903 | - 'status*inclusive' => array('=', 'private'), |
|
1904 | - 'EVT_wp_user' => get_current_user_id(), |
|
1905 | - ), |
|
1906 | - ); |
|
1907 | - } |
|
1908 | - |
|
1909 | - if (isset($this->_req_data['EVT_wp_user']) |
|
1910 | - && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id() |
|
1911 | - && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
1912 | - ) { |
|
1913 | - $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
1914 | - } |
|
1915 | - // search query handling |
|
1916 | - if (isset($this->_req_data['s'])) { |
|
1917 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1918 | - $where['OR'] = array( |
|
1919 | - 'EVT_name' => array('LIKE', $search_string), |
|
1920 | - 'EVT_desc' => array('LIKE', $search_string), |
|
1921 | - 'EVT_short_desc' => array('LIKE', $search_string), |
|
1922 | - ); |
|
1923 | - } |
|
1924 | - // filter events by venue. |
|
1925 | - if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
1926 | - $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
1927 | - } |
|
1928 | - $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
1929 | - $query_params = apply_filters( |
|
1930 | - 'FHEE__Events_Admin_Page__get_events__query_params', |
|
1931 | - array( |
|
1932 | - $where, |
|
1933 | - 'limit' => $limit, |
|
1934 | - 'order_by' => $orderby, |
|
1935 | - 'order' => $order, |
|
1936 | - 'group_by' => 'EVT_ID', |
|
1937 | - ), |
|
1938 | - $this->_req_data |
|
1939 | - ); |
|
1940 | - |
|
1941 | - // let's first check if we have special requests coming in. |
|
1942 | - if (isset($this->_req_data['active_status'])) { |
|
1943 | - switch ($this->_req_data['active_status']) { |
|
1944 | - case 'upcoming': |
|
1945 | - return $EEME->get_upcoming_events($query_params, $count); |
|
1946 | - break; |
|
1947 | - case 'expired': |
|
1948 | - return $EEME->get_expired_events($query_params, $count); |
|
1949 | - break; |
|
1950 | - case 'active': |
|
1951 | - return $EEME->get_active_events($query_params, $count); |
|
1952 | - break; |
|
1953 | - case 'inactive': |
|
1954 | - return $EEME->get_inactive_events($query_params, $count); |
|
1955 | - break; |
|
1956 | - } |
|
1957 | - } |
|
1958 | - |
|
1959 | - $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
1960 | - return $events; |
|
1961 | - } |
|
1962 | - |
|
1963 | - |
|
1964 | - /** |
|
1965 | - * handling for WordPress CPT actions (trash, restore, delete) |
|
1966 | - * |
|
1967 | - * @param string $post_id |
|
1968 | - * @throws EE_Error |
|
1969 | - * @throws InvalidArgumentException |
|
1970 | - * @throws InvalidDataTypeException |
|
1971 | - * @throws InvalidInterfaceException |
|
1972 | - * @throws ReflectionException |
|
1973 | - */ |
|
1974 | - public function trash_cpt_item($post_id) |
|
1975 | - { |
|
1976 | - $this->_req_data['EVT_ID'] = $post_id; |
|
1977 | - $this->_trash_or_restore_event('trash', false); |
|
1978 | - } |
|
1979 | - |
|
1980 | - |
|
1981 | - /** |
|
1982 | - * @param string $post_id |
|
1983 | - * @throws EE_Error |
|
1984 | - * @throws InvalidArgumentException |
|
1985 | - * @throws InvalidDataTypeException |
|
1986 | - * @throws InvalidInterfaceException |
|
1987 | - * @throws ReflectionException |
|
1988 | - */ |
|
1989 | - public function restore_cpt_item($post_id) |
|
1990 | - { |
|
1991 | - $this->_req_data['EVT_ID'] = $post_id; |
|
1992 | - $this->_trash_or_restore_event('draft', false); |
|
1993 | - } |
|
1994 | - |
|
1995 | - |
|
1996 | - /** |
|
1997 | - * @param string $post_id |
|
1998 | - * @throws EE_Error |
|
1999 | - * @throws InvalidArgumentException |
|
2000 | - * @throws InvalidDataTypeException |
|
2001 | - * @throws InvalidInterfaceException |
|
2002 | - * @throws ReflectionException |
|
2003 | - */ |
|
2004 | - public function delete_cpt_item($post_id) |
|
2005 | - { |
|
2006 | - $this->_req_data['EVT_ID'] = $post_id; |
|
2007 | - $this->_delete_event(false); |
|
2008 | - } |
|
2009 | - |
|
2010 | - |
|
2011 | - /** |
|
2012 | - * _trash_or_restore_event |
|
2013 | - * |
|
2014 | - * @access protected |
|
2015 | - * @param string $event_status |
|
2016 | - * @param bool $redirect_after |
|
2017 | - * @throws EE_Error |
|
2018 | - * @throws InvalidArgumentException |
|
2019 | - * @throws InvalidDataTypeException |
|
2020 | - * @throws InvalidInterfaceException |
|
2021 | - * @throws ReflectionException |
|
2022 | - */ |
|
2023 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
2024 | - { |
|
2025 | - // determine the event id and set to array. |
|
2026 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
2027 | - // loop thru events |
|
2028 | - if ($EVT_ID) { |
|
2029 | - // clean status |
|
2030 | - $event_status = sanitize_key($event_status); |
|
2031 | - // grab status |
|
2032 | - if (! empty($event_status)) { |
|
2033 | - $success = $this->_change_event_status($EVT_ID, $event_status); |
|
2034 | - } else { |
|
2035 | - $success = false; |
|
2036 | - $msg = esc_html__( |
|
2037 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2038 | - 'event_espresso' |
|
2039 | - ); |
|
2040 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2041 | - } |
|
2042 | - } else { |
|
2043 | - $success = false; |
|
2044 | - $msg = esc_html__( |
|
2045 | - 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
2046 | - 'event_espresso' |
|
2047 | - ); |
|
2048 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2049 | - } |
|
2050 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2051 | - if ($redirect_after) { |
|
2052 | - $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
2053 | - } |
|
2054 | - } |
|
2055 | - |
|
2056 | - |
|
2057 | - /** |
|
2058 | - * _trash_or_restore_events |
|
2059 | - * |
|
2060 | - * @access protected |
|
2061 | - * @param string $event_status |
|
2062 | - * @return void |
|
2063 | - * @throws EE_Error |
|
2064 | - * @throws InvalidArgumentException |
|
2065 | - * @throws InvalidDataTypeException |
|
2066 | - * @throws InvalidInterfaceException |
|
2067 | - * @throws ReflectionException |
|
2068 | - */ |
|
2069 | - protected function _trash_or_restore_events($event_status = 'trash') |
|
2070 | - { |
|
2071 | - // clean status |
|
2072 | - $event_status = sanitize_key($event_status); |
|
2073 | - // grab status |
|
2074 | - if (! empty($event_status)) { |
|
2075 | - $success = true; |
|
2076 | - // determine the event id and set to array. |
|
2077 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
2078 | - // loop thru events |
|
2079 | - foreach ($EVT_IDs as $EVT_ID) { |
|
2080 | - if ($EVT_ID = absint($EVT_ID)) { |
|
2081 | - $results = $this->_change_event_status($EVT_ID, $event_status); |
|
2082 | - $success = $results !== false ? $success : false; |
|
2083 | - } else { |
|
2084 | - $msg = sprintf( |
|
2085 | - esc_html__( |
|
2086 | - 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
2087 | - 'event_espresso' |
|
2088 | - ), |
|
2089 | - $EVT_ID |
|
2090 | - ); |
|
2091 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2092 | - $success = false; |
|
2093 | - } |
|
2094 | - } |
|
2095 | - } else { |
|
2096 | - $success = false; |
|
2097 | - $msg = esc_html__( |
|
2098 | - 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2099 | - 'event_espresso' |
|
2100 | - ); |
|
2101 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2102 | - } |
|
2103 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2104 | - $success = $success ? 2 : false; |
|
2105 | - $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2106 | - $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
2107 | - } |
|
2108 | - |
|
2109 | - |
|
2110 | - /** |
|
2111 | - * _trash_or_restore_events |
|
2112 | - * |
|
2113 | - * @access private |
|
2114 | - * @param int $EVT_ID |
|
2115 | - * @param string $event_status |
|
2116 | - * @return bool |
|
2117 | - * @throws EE_Error |
|
2118 | - * @throws InvalidArgumentException |
|
2119 | - * @throws InvalidDataTypeException |
|
2120 | - * @throws InvalidInterfaceException |
|
2121 | - * @throws ReflectionException |
|
2122 | - */ |
|
2123 | - private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
2124 | - { |
|
2125 | - // grab event id |
|
2126 | - if (! $EVT_ID) { |
|
2127 | - $msg = esc_html__( |
|
2128 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2129 | - 'event_espresso' |
|
2130 | - ); |
|
2131 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2132 | - return false; |
|
2133 | - } |
|
2134 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2135 | - // clean status |
|
2136 | - $event_status = sanitize_key($event_status); |
|
2137 | - // grab status |
|
2138 | - if (empty($event_status)) { |
|
2139 | - $msg = esc_html__( |
|
2140 | - 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2141 | - 'event_espresso' |
|
2142 | - ); |
|
2143 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2144 | - return false; |
|
2145 | - } |
|
2146 | - // was event trashed or restored ? |
|
2147 | - switch ($event_status) { |
|
2148 | - case 'draft': |
|
2149 | - $action = 'restored from the trash'; |
|
2150 | - $hook = 'AHEE_event_restored_from_trash'; |
|
2151 | - break; |
|
2152 | - case 'trash': |
|
2153 | - $action = 'moved to the trash'; |
|
2154 | - $hook = 'AHEE_event_moved_to_trash'; |
|
2155 | - break; |
|
2156 | - default: |
|
2157 | - $action = 'updated'; |
|
2158 | - $hook = false; |
|
2159 | - } |
|
2160 | - // use class to change status |
|
2161 | - $this->_cpt_model_obj->set_status($event_status); |
|
2162 | - $success = $this->_cpt_model_obj->save(); |
|
2163 | - if ($success === false) { |
|
2164 | - $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2165 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2166 | - return false; |
|
2167 | - } |
|
2168 | - if ($hook) { |
|
2169 | - do_action($hook); |
|
2170 | - } |
|
2171 | - return true; |
|
2172 | - } |
|
2173 | - |
|
2174 | - |
|
2175 | - /** |
|
2176 | - * _delete_event |
|
2177 | - * |
|
2178 | - * @access protected |
|
2179 | - * @param bool $redirect_after |
|
2180 | - * @throws EE_Error |
|
2181 | - * @throws InvalidArgumentException |
|
2182 | - * @throws InvalidDataTypeException |
|
2183 | - * @throws InvalidInterfaceException |
|
2184 | - * @throws ReflectionException |
|
2185 | - */ |
|
2186 | - protected function _delete_event($redirect_after = true) |
|
2187 | - { |
|
2188 | - // determine the event id and set to array. |
|
2189 | - $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
2190 | - $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
2191 | - // loop thru events |
|
2192 | - if ($EVT_ID) { |
|
2193 | - $success = $this->_permanently_delete_event($EVT_ID); |
|
2194 | - // get list of events with no prices |
|
2195 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
2196 | - // remove this event from the list of events with no prices |
|
2197 | - if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
2198 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
2199 | - } |
|
2200 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
2201 | - } else { |
|
2202 | - $success = false; |
|
2203 | - $msg = esc_html__( |
|
2204 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
2205 | - 'event_espresso' |
|
2206 | - ); |
|
2207 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2208 | - } |
|
2209 | - if ($redirect_after) { |
|
2210 | - $this->_redirect_after_action( |
|
2211 | - $success, |
|
2212 | - 'Event', |
|
2213 | - 'deleted', |
|
2214 | - array('action' => 'default', 'status' => 'trash') |
|
2215 | - ); |
|
2216 | - } |
|
2217 | - } |
|
2218 | - |
|
2219 | - |
|
2220 | - /** |
|
2221 | - * _delete_events |
|
2222 | - * |
|
2223 | - * @access protected |
|
2224 | - * @return void |
|
2225 | - * @throws EE_Error |
|
2226 | - * @throws InvalidArgumentException |
|
2227 | - * @throws InvalidDataTypeException |
|
2228 | - * @throws InvalidInterfaceException |
|
2229 | - * @throws ReflectionException |
|
2230 | - */ |
|
2231 | - protected function _delete_events() |
|
2232 | - { |
|
2233 | - $success = true; |
|
2234 | - // get list of events with no prices |
|
2235 | - $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
2236 | - // determine the event id and set to array. |
|
2237 | - $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
2238 | - // loop thru events |
|
2239 | - foreach ($EVT_IDs as $EVT_ID) { |
|
2240 | - $EVT_ID = absint($EVT_ID); |
|
2241 | - if ($EVT_ID) { |
|
2242 | - $results = $this->_permanently_delete_event($EVT_ID); |
|
2243 | - $success = $results !== false ? $success : false; |
|
2244 | - // remove this event from the list of events with no prices |
|
2245 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
2246 | - } else { |
|
2247 | - $success = false; |
|
2248 | - $msg = esc_html__( |
|
2249 | - 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
2250 | - 'event_espresso' |
|
2251 | - ); |
|
2252 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2253 | - } |
|
2254 | - } |
|
2255 | - update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
2256 | - // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2257 | - $success = $success ? 2 : false; |
|
2258 | - $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
2259 | - } |
|
2260 | - |
|
2261 | - |
|
2262 | - /** |
|
2263 | - * _permanently_delete_event |
|
2264 | - * |
|
2265 | - * @access private |
|
2266 | - * @param int $EVT_ID |
|
2267 | - * @return bool |
|
2268 | - * @throws EE_Error |
|
2269 | - * @throws InvalidArgumentException |
|
2270 | - * @throws InvalidDataTypeException |
|
2271 | - * @throws InvalidInterfaceException |
|
2272 | - * @throws ReflectionException |
|
2273 | - */ |
|
2274 | - private function _permanently_delete_event($EVT_ID = 0) |
|
2275 | - { |
|
2276 | - // grab event id |
|
2277 | - if (! $EVT_ID) { |
|
2278 | - $msg = esc_html__( |
|
2279 | - 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2280 | - 'event_espresso' |
|
2281 | - ); |
|
2282 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2283 | - return false; |
|
2284 | - } |
|
2285 | - if (! $this->_cpt_model_obj instanceof EE_Event |
|
2286 | - || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
2287 | - ) { |
|
2288 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2289 | - } |
|
2290 | - if (! $this->_cpt_model_obj instanceof EE_Event) { |
|
2291 | - return false; |
|
2292 | - } |
|
2293 | - // need to delete related tickets and prices first. |
|
2294 | - $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
2295 | - foreach ($datetimes as $datetime) { |
|
2296 | - $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
2297 | - $tickets = $datetime->get_many_related('Ticket'); |
|
2298 | - foreach ($tickets as $ticket) { |
|
2299 | - $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
2300 | - $ticket->delete_related_permanently('Price'); |
|
2301 | - $ticket->delete_permanently(); |
|
2302 | - } |
|
2303 | - $datetime->delete(); |
|
2304 | - } |
|
2305 | - // what about related venues or terms? |
|
2306 | - $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
2307 | - foreach ($venues as $venue) { |
|
2308 | - $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
2309 | - } |
|
2310 | - // any attached question groups? |
|
2311 | - $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
2312 | - if (! empty($question_groups)) { |
|
2313 | - foreach ($question_groups as $question_group) { |
|
2314 | - $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
2315 | - } |
|
2316 | - } |
|
2317 | - // Message Template Groups |
|
2318 | - $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
2319 | - /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
2320 | - $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
2321 | - foreach ($term_taxonomies as $term_taxonomy) { |
|
2322 | - $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
2323 | - } |
|
2324 | - $success = $this->_cpt_model_obj->delete_permanently(); |
|
2325 | - // did it all go as planned ? |
|
2326 | - if ($success) { |
|
2327 | - $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
2328 | - EE_Error::add_success($msg); |
|
2329 | - } else { |
|
2330 | - $msg = sprintf( |
|
2331 | - esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
2332 | - $EVT_ID |
|
2333 | - ); |
|
2334 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2335 | - return false; |
|
2336 | - } |
|
2337 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
2338 | - return true; |
|
2339 | - } |
|
2340 | - |
|
2341 | - |
|
2342 | - /** |
|
2343 | - * get total number of events |
|
2344 | - * |
|
2345 | - * @access public |
|
2346 | - * @return int |
|
2347 | - * @throws EE_Error |
|
2348 | - * @throws InvalidArgumentException |
|
2349 | - * @throws InvalidDataTypeException |
|
2350 | - * @throws InvalidInterfaceException |
|
2351 | - */ |
|
2352 | - public function total_events() |
|
2353 | - { |
|
2354 | - $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
2355 | - return $count; |
|
2356 | - } |
|
2357 | - |
|
2358 | - |
|
2359 | - /** |
|
2360 | - * get total number of draft events |
|
2361 | - * |
|
2362 | - * @access public |
|
2363 | - * @return int |
|
2364 | - * @throws EE_Error |
|
2365 | - * @throws InvalidArgumentException |
|
2366 | - * @throws InvalidDataTypeException |
|
2367 | - * @throws InvalidInterfaceException |
|
2368 | - */ |
|
2369 | - public function total_events_draft() |
|
2370 | - { |
|
2371 | - $where = array( |
|
2372 | - 'status' => array('IN', array('draft', 'auto-draft')), |
|
2373 | - ); |
|
2374 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2375 | - return $count; |
|
2376 | - } |
|
2377 | - |
|
2378 | - |
|
2379 | - /** |
|
2380 | - * get total number of trashed events |
|
2381 | - * |
|
2382 | - * @access public |
|
2383 | - * @return int |
|
2384 | - * @throws EE_Error |
|
2385 | - * @throws InvalidArgumentException |
|
2386 | - * @throws InvalidDataTypeException |
|
2387 | - * @throws InvalidInterfaceException |
|
2388 | - */ |
|
2389 | - public function total_trashed_events() |
|
2390 | - { |
|
2391 | - $where = array( |
|
2392 | - 'status' => 'trash', |
|
2393 | - ); |
|
2394 | - $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2395 | - return $count; |
|
2396 | - } |
|
2397 | - |
|
2398 | - |
|
2399 | - /** |
|
2400 | - * _default_event_settings |
|
2401 | - * This generates the Default Settings Tab |
|
2402 | - * |
|
2403 | - * @return void |
|
2404 | - * @throws DomainException |
|
2405 | - * @throws EE_Error |
|
2406 | - * @throws InvalidArgumentException |
|
2407 | - * @throws InvalidDataTypeException |
|
2408 | - * @throws InvalidInterfaceException |
|
2409 | - */ |
|
2410 | - protected function _default_event_settings() |
|
2411 | - { |
|
2412 | - $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2413 | - $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
2414 | - $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
2415 | - $this->display_admin_page_with_sidebar(); |
|
2416 | - } |
|
2417 | - |
|
2418 | - |
|
2419 | - /** |
|
2420 | - * Return the form for event settings. |
|
2421 | - * |
|
2422 | - * @return EE_Form_Section_Proper |
|
2423 | - * @throws EE_Error |
|
2424 | - */ |
|
2425 | - protected function _default_event_settings_form() |
|
2426 | - { |
|
2427 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2428 | - $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2429 | - // exclude |
|
2430 | - array( |
|
2431 | - EEM_Registration::status_id_cancelled, |
|
2432 | - EEM_Registration::status_id_declined, |
|
2433 | - EEM_Registration::status_id_incomplete, |
|
2434 | - EEM_Registration::status_id_wait_list, |
|
2435 | - ), |
|
2436 | - true |
|
2437 | - ); |
|
2438 | - return new EE_Form_Section_Proper( |
|
2439 | - array( |
|
2440 | - 'name' => 'update_default_event_settings', |
|
2441 | - 'html_id' => 'update_default_event_settings', |
|
2442 | - 'html_class' => 'form-table', |
|
2443 | - 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2444 | - 'subsections' => apply_filters( |
|
2445 | - 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2446 | - array( |
|
2447 | - 'default_reg_status' => new EE_Select_Input( |
|
2448 | - $registration_stati_for_selection, |
|
2449 | - array( |
|
2450 | - 'default' => isset($registration_config->default_STS_ID) |
|
2451 | - && array_key_exists( |
|
2452 | - $registration_config->default_STS_ID, |
|
2453 | - $registration_stati_for_selection |
|
2454 | - ) |
|
2455 | - ? sanitize_text_field($registration_config->default_STS_ID) |
|
2456 | - : EEM_Registration::status_id_pending_payment, |
|
2457 | - 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2458 | - . EEH_Template::get_help_tab_link( |
|
2459 | - 'default_settings_status_help_tab' |
|
2460 | - ), |
|
2461 | - 'html_help_text' => esc_html__( |
|
2462 | - 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
2463 | - 'event_espresso' |
|
2464 | - ), |
|
2465 | - ) |
|
2466 | - ), |
|
2467 | - 'default_max_tickets' => new EE_Integer_Input( |
|
2468 | - array( |
|
2469 | - 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
2470 | - ? $registration_config->default_maximum_number_of_tickets |
|
2471 | - : EEM_Event::get_default_additional_limit(), |
|
2472 | - 'html_label_text' => esc_html__( |
|
2473 | - 'Default Maximum Tickets Allowed Per Order:', |
|
2474 | - 'event_espresso' |
|
2475 | - ) |
|
2476 | - . EEH_Template::get_help_tab_link( |
|
2477 | - 'default_maximum_tickets_help_tab"' |
|
2478 | - ), |
|
2479 | - 'html_help_text' => esc_html__( |
|
2480 | - 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2481 | - 'event_espresso' |
|
2482 | - ), |
|
2483 | - ) |
|
2484 | - ), |
|
2485 | - ) |
|
2486 | - ), |
|
2487 | - ) |
|
2488 | - ); |
|
2489 | - } |
|
2490 | - |
|
2491 | - |
|
2492 | - /** |
|
2493 | - * @return void |
|
2494 | - * @throws EE_Error |
|
2495 | - * @throws InvalidArgumentException |
|
2496 | - * @throws InvalidDataTypeException |
|
2497 | - * @throws InvalidInterfaceException |
|
2498 | - */ |
|
2499 | - protected function _update_default_event_settings() |
|
2500 | - { |
|
2501 | - $form = $this->_default_event_settings_form(); |
|
2502 | - if ($form->was_submitted()) { |
|
2503 | - $form->receive_form_submission(); |
|
2504 | - if ($form->is_valid()) { |
|
2505 | - $registration_config = EE_Registry::instance()->CFG->registration; |
|
2506 | - $valid_data = $form->valid_data(); |
|
2507 | - if (isset($valid_data['default_reg_status'])) { |
|
2508 | - $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2509 | - } |
|
2510 | - if (isset($valid_data['default_max_tickets'])) { |
|
2511 | - $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2512 | - } |
|
2513 | - do_action( |
|
2514 | - 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
2515 | - $valid_data, |
|
2516 | - EE_Registry::instance()->CFG, |
|
2517 | - $this |
|
2518 | - ); |
|
2519 | - // update because data was valid! |
|
2520 | - EE_Registry::instance()->CFG->update_espresso_config(); |
|
2521 | - EE_Error::overwrite_success(); |
|
2522 | - EE_Error::add_success( |
|
2523 | - __('Default Event Settings were updated', 'event_espresso') |
|
2524 | - ); |
|
2525 | - } |
|
2526 | - } |
|
2527 | - $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
2528 | - } |
|
2529 | - |
|
2530 | - |
|
2531 | - /************* Templates *************/ |
|
2532 | - protected function _template_settings() |
|
2533 | - { |
|
2534 | - $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2535 | - $this->_template_args['preview_img'] = '<img src="' |
|
2536 | - . EVENTS_ASSETS_URL |
|
2537 | - . '/images/' |
|
2538 | - . 'caffeinated_template_features.jpg" alt="' |
|
2539 | - . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2540 | - . '" />'; |
|
2541 | - $this->_template_args['preview_text'] = '<strong>' |
|
2542 | - . esc_html__( |
|
2543 | - 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
2544 | - 'event_espresso' |
|
2545 | - ) . '</strong>'; |
|
2546 | - $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2547 | - } |
|
2548 | - |
|
2549 | - |
|
2550 | - /** Event Category Stuff **/ |
|
2551 | - /** |
|
2552 | - * set the _category property with the category object for the loaded page. |
|
2553 | - * |
|
2554 | - * @access private |
|
2555 | - * @return void |
|
2556 | - */ |
|
2557 | - private function _set_category_object() |
|
2558 | - { |
|
2559 | - if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2560 | - return; |
|
2561 | - } //already have the category object so get out. |
|
2562 | - // set default category object |
|
2563 | - $this->_set_empty_category_object(); |
|
2564 | - // only set if we've got an id |
|
2565 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2566 | - return; |
|
2567 | - } |
|
2568 | - $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
2569 | - $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2570 | - if (! empty($term)) { |
|
2571 | - $this->_category->category_name = $term->name; |
|
2572 | - $this->_category->category_identifier = $term->slug; |
|
2573 | - $this->_category->category_desc = $term->description; |
|
2574 | - $this->_category->id = $term->term_id; |
|
2575 | - $this->_category->parent = $term->parent; |
|
2576 | - } |
|
2577 | - } |
|
2578 | - |
|
2579 | - |
|
2580 | - /** |
|
2581 | - * Clears out category properties. |
|
2582 | - */ |
|
2583 | - private function _set_empty_category_object() |
|
2584 | - { |
|
2585 | - $this->_category = new stdClass(); |
|
2586 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2587 | - $this->_category->id = $this->_category->parent = 0; |
|
2588 | - } |
|
2589 | - |
|
2590 | - |
|
2591 | - /** |
|
2592 | - * @throws DomainException |
|
2593 | - * @throws EE_Error |
|
2594 | - * @throws InvalidArgumentException |
|
2595 | - * @throws InvalidDataTypeException |
|
2596 | - * @throws InvalidInterfaceException |
|
2597 | - */ |
|
2598 | - protected function _category_list_table() |
|
2599 | - { |
|
2600 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2601 | - $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2602 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2603 | - 'add_category', |
|
2604 | - 'add_category', |
|
2605 | - array(), |
|
2606 | - 'add-new-h2' |
|
2607 | - ); |
|
2608 | - $this->display_admin_list_table_page_with_sidebar(); |
|
2609 | - } |
|
2610 | - |
|
2611 | - |
|
2612 | - /** |
|
2613 | - * Output category details view. |
|
2614 | - * |
|
2615 | - * @param string $view |
|
2616 | - * @throws DomainException |
|
2617 | - * @throws EE_Error |
|
2618 | - * @throws InvalidArgumentException |
|
2619 | - * @throws InvalidDataTypeException |
|
2620 | - * @throws InvalidInterfaceException |
|
2621 | - */ |
|
2622 | - protected function _category_details($view) |
|
2623 | - { |
|
2624 | - // load formatter helper |
|
2625 | - // load field generator helper |
|
2626 | - $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
2627 | - $this->_set_add_edit_form_tags($route); |
|
2628 | - $this->_set_category_object(); |
|
2629 | - $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2630 | - $delete_action = 'delete_category'; |
|
2631 | - // custom redirect |
|
2632 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2633 | - array('action' => 'category_list'), |
|
2634 | - $this->_admin_base_url |
|
2635 | - ); |
|
2636 | - $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2637 | - // take care of contents |
|
2638 | - $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2639 | - $this->display_admin_page_with_sidebar(); |
|
2640 | - } |
|
2641 | - |
|
2642 | - |
|
2643 | - /** |
|
2644 | - * Output category details content. |
|
2645 | - * |
|
2646 | - * @throws DomainException |
|
2647 | - */ |
|
2648 | - protected function _category_details_content() |
|
2649 | - { |
|
2650 | - $editor_args['category_desc'] = array( |
|
2651 | - 'type' => 'wp_editor', |
|
2652 | - 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2653 | - 'class' => 'my_editor_custom', |
|
2654 | - 'wpeditor_args' => array('media_buttons' => false), |
|
2655 | - ); |
|
2656 | - $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2657 | - $all_terms = get_terms( |
|
2658 | - array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY), |
|
2659 | - array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
2660 | - ); |
|
2661 | - // setup category select for term parents. |
|
2662 | - $category_select_values[] = array( |
|
2663 | - 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2664 | - 'id' => 0, |
|
2665 | - ); |
|
2666 | - foreach ($all_terms as $term) { |
|
2667 | - $category_select_values[] = array( |
|
2668 | - 'text' => $term->name, |
|
2669 | - 'id' => $term->term_id, |
|
2670 | - ); |
|
2671 | - } |
|
2672 | - $category_select = EEH_Form_Fields::select_input( |
|
2673 | - 'category_parent', |
|
2674 | - $category_select_values, |
|
2675 | - $this->_category->parent |
|
2676 | - ); |
|
2677 | - $template_args = array( |
|
2678 | - 'category' => $this->_category, |
|
2679 | - 'category_select' => $category_select, |
|
2680 | - 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2681 | - 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2682 | - 'disable' => '', |
|
2683 | - 'disabled_message' => false, |
|
2684 | - ); |
|
2685 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2686 | - return EEH_Template::display_template($template, $template_args, true); |
|
2687 | - } |
|
2688 | - |
|
2689 | - |
|
2690 | - /** |
|
2691 | - * Handles deleting categories. |
|
2692 | - */ |
|
2693 | - protected function _delete_categories() |
|
2694 | - { |
|
2695 | - $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
2696 | - : (array) $this->_req_data['category_id']; |
|
2697 | - foreach ($cat_ids as $cat_id) { |
|
2698 | - $this->_delete_category($cat_id); |
|
2699 | - } |
|
2700 | - // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2701 | - $query_args = array( |
|
2702 | - 'action' => 'category_list', |
|
2703 | - ); |
|
2704 | - $this->_redirect_after_action(0, '', '', $query_args); |
|
2705 | - } |
|
2706 | - |
|
2707 | - |
|
2708 | - /** |
|
2709 | - * Handles deleting specific category. |
|
2710 | - * |
|
2711 | - * @param int $cat_id |
|
2712 | - */ |
|
2713 | - protected function _delete_category($cat_id) |
|
2714 | - { |
|
2715 | - $cat_id = absint($cat_id); |
|
2716 | - wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2717 | - } |
|
2718 | - |
|
2719 | - |
|
2720 | - /** |
|
2721 | - * Handles triggering the update or insertion of a new category. |
|
2722 | - * |
|
2723 | - * @param bool $new_category true means we're triggering the insert of a new category. |
|
2724 | - * @throws EE_Error |
|
2725 | - * @throws InvalidArgumentException |
|
2726 | - * @throws InvalidDataTypeException |
|
2727 | - * @throws InvalidInterfaceException |
|
2728 | - */ |
|
2729 | - protected function _insert_or_update_category($new_category) |
|
2730 | - { |
|
2731 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
2732 | - $success = 0; // we already have a success message so lets not send another. |
|
2733 | - if ($cat_id) { |
|
2734 | - $query_args = array( |
|
2735 | - 'action' => 'edit_category', |
|
2736 | - 'EVT_CAT_ID' => $cat_id, |
|
2737 | - ); |
|
2738 | - } else { |
|
2739 | - $query_args = array('action' => 'add_category'); |
|
2740 | - } |
|
2741 | - $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2742 | - } |
|
2743 | - |
|
2744 | - |
|
2745 | - /** |
|
2746 | - * Inserts or updates category |
|
2747 | - * |
|
2748 | - * @param bool $update (true indicates we're updating a category). |
|
2749 | - * @return bool|mixed|string |
|
2750 | - */ |
|
2751 | - private function _insert_category($update = false) |
|
2752 | - { |
|
2753 | - $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
2754 | - $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
2755 | - $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
2756 | - $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
2757 | - if (empty($category_name)) { |
|
2758 | - $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2759 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2760 | - return false; |
|
2761 | - } |
|
2762 | - $term_args = array( |
|
2763 | - 'name' => $category_name, |
|
2764 | - 'description' => $category_desc, |
|
2765 | - 'parent' => $category_parent, |
|
2766 | - ); |
|
2767 | - // was the category_identifier input disabled? |
|
2768 | - if (isset($this->_req_data['category_identifier'])) { |
|
2769 | - $term_args['slug'] = $this->_req_data['category_identifier']; |
|
2770 | - } |
|
2771 | - $insert_ids = $update |
|
2772 | - ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
2773 | - : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
2774 | - if (! is_array($insert_ids)) { |
|
2775 | - $msg = esc_html__( |
|
2776 | - 'An error occurred and the category has not been saved to the database.', |
|
2777 | - 'event_espresso' |
|
2778 | - ); |
|
2779 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2780 | - } else { |
|
2781 | - $cat_id = $insert_ids['term_id']; |
|
2782 | - $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
2783 | - EE_Error::add_success($msg); |
|
2784 | - } |
|
2785 | - return $cat_id; |
|
2786 | - } |
|
2787 | - |
|
2788 | - |
|
2789 | - /** |
|
2790 | - * Gets categories or count of categories matching the arguments in the request. |
|
2791 | - * |
|
2792 | - * @param int $per_page |
|
2793 | - * @param int $current_page |
|
2794 | - * @param bool $count |
|
2795 | - * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
2796 | - * @throws EE_Error |
|
2797 | - * @throws InvalidArgumentException |
|
2798 | - * @throws InvalidDataTypeException |
|
2799 | - * @throws InvalidInterfaceException |
|
2800 | - */ |
|
2801 | - public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
2802 | - { |
|
2803 | - // testing term stuff |
|
2804 | - $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2805 | - $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2806 | - $limit = ($current_page - 1) * $per_page; |
|
2807 | - $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2808 | - if (isset($this->_req_data['s'])) { |
|
2809 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2810 | - $where['OR'] = array( |
|
2811 | - 'Term.name' => array('LIKE', $sstr), |
|
2812 | - 'description' => array('LIKE', $sstr), |
|
2813 | - ); |
|
2814 | - } |
|
2815 | - $query_params = array( |
|
2816 | - $where, |
|
2817 | - 'order_by' => array($orderby => $order), |
|
2818 | - 'limit' => $limit . ',' . $per_page, |
|
2819 | - 'force_join' => array('Term'), |
|
2820 | - ); |
|
2821 | - $categories = $count |
|
2822 | - ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2823 | - : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2824 | - return $categories; |
|
2825 | - } |
|
2826 | - |
|
2827 | - /* end category stuff */ |
|
2828 | - /**************/ |
|
2829 | - |
|
2830 | - |
|
2831 | - /** |
|
2832 | - * Callback for the `ee_save_timezone_setting` ajax action. |
|
2833 | - * |
|
2834 | - * @throws EE_Error |
|
2835 | - * @throws InvalidArgumentException |
|
2836 | - * @throws InvalidDataTypeException |
|
2837 | - * @throws InvalidInterfaceException |
|
2838 | - */ |
|
2839 | - public function save_timezonestring_setting() |
|
2840 | - { |
|
2841 | - $timezone_string = isset($this->_req_data['timezone_selected']) |
|
2842 | - ? $this->_req_data['timezone_selected'] |
|
2843 | - : ''; |
|
2844 | - if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
2845 | - EE_Error::add_error( |
|
2846 | - esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
2847 | - __FILE__, |
|
2848 | - __FUNCTION__, |
|
2849 | - __LINE__ |
|
2850 | - ); |
|
2851 | - $this->_template_args['error'] = true; |
|
2852 | - $this->_return_json(); |
|
2853 | - } |
|
2854 | - |
|
2855 | - update_option('timezone_string', $timezone_string); |
|
2856 | - EE_Error::add_success( |
|
2857 | - esc_html__('Your timezone string was updated.', 'event_espresso') |
|
2858 | - ); |
|
2859 | - $this->_template_args['success'] = true; |
|
2860 | - $this->_return_json(true, array('action' => 'create_new')); |
|
2861 | - } |
|
18 | + /** |
|
19 | + * This will hold the event object for event_details screen. |
|
20 | + * |
|
21 | + * @access protected |
|
22 | + * @var EE_Event $_event |
|
23 | + */ |
|
24 | + protected $_event; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * This will hold the category object for category_details screen. |
|
29 | + * |
|
30 | + * @var stdClass $_category |
|
31 | + */ |
|
32 | + protected $_category; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * This will hold the event model instance |
|
37 | + * |
|
38 | + * @var EEM_Event $_event_model |
|
39 | + */ |
|
40 | + protected $_event_model; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EE_Event |
|
45 | + */ |
|
46 | + protected $_cpt_model_obj = false; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Initialize page props for this admin page group. |
|
51 | + */ |
|
52 | + protected function _init_page_props() |
|
53 | + { |
|
54 | + $this->page_slug = EVENTS_PG_SLUG; |
|
55 | + $this->page_label = EVENTS_LABEL; |
|
56 | + $this->_admin_base_url = EVENTS_ADMIN_URL; |
|
57 | + $this->_admin_base_path = EVENTS_ADMIN; |
|
58 | + $this->_cpt_model_names = array( |
|
59 | + 'create_new' => 'EEM_Event', |
|
60 | + 'edit' => 'EEM_Event', |
|
61 | + ); |
|
62 | + $this->_cpt_edit_routes = array( |
|
63 | + 'espresso_events' => 'edit', |
|
64 | + ); |
|
65 | + add_action( |
|
66 | + 'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', |
|
67 | + array($this, 'verify_event_edit'), |
|
68 | + 10, |
|
69 | + 2 |
|
70 | + ); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * Sets the ajax hooks used for this admin page group. |
|
76 | + */ |
|
77 | + protected function _ajax_hooks() |
|
78 | + { |
|
79 | + add_action('wp_ajax_ee_save_timezone_setting', array($this, 'save_timezonestring_setting')); |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Sets the page properties for this admin page group. |
|
85 | + */ |
|
86 | + protected function _define_page_props() |
|
87 | + { |
|
88 | + $this->_admin_page_title = EVENTS_LABEL; |
|
89 | + $this->_labels = array( |
|
90 | + 'buttons' => array( |
|
91 | + 'add' => esc_html__('Add New Event', 'event_espresso'), |
|
92 | + 'edit' => esc_html__('Edit Event', 'event_espresso'), |
|
93 | + 'delete' => esc_html__('Delete Event', 'event_espresso'), |
|
94 | + 'add_category' => esc_html__('Add New Category', 'event_espresso'), |
|
95 | + 'edit_category' => esc_html__('Edit Category', 'event_espresso'), |
|
96 | + 'delete_category' => esc_html__('Delete Category', 'event_espresso'), |
|
97 | + ), |
|
98 | + 'editor_title' => array( |
|
99 | + 'espresso_events' => esc_html__('Enter event title here', 'event_espresso'), |
|
100 | + ), |
|
101 | + 'publishbox' => array( |
|
102 | + 'create_new' => esc_html__('Save New Event', 'event_espresso'), |
|
103 | + 'edit' => esc_html__('Update Event', 'event_espresso'), |
|
104 | + 'add_category' => esc_html__('Save New Category', 'event_espresso'), |
|
105 | + 'edit_category' => esc_html__('Update Category', 'event_espresso'), |
|
106 | + 'template_settings' => esc_html__('Update Settings', 'event_espresso'), |
|
107 | + ), |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Sets the page routes property for this admin page group. |
|
114 | + */ |
|
115 | + protected function _set_page_routes() |
|
116 | + { |
|
117 | + // load formatter helper |
|
118 | + // load field generator helper |
|
119 | + // is there a evt_id in the request? |
|
120 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) |
|
121 | + ? $this->_req_data['EVT_ID'] |
|
122 | + : 0; |
|
123 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
124 | + $this->_page_routes = array( |
|
125 | + 'default' => array( |
|
126 | + 'func' => '_events_overview_list_table', |
|
127 | + 'capability' => 'ee_read_events', |
|
128 | + ), |
|
129 | + 'create_new' => array( |
|
130 | + 'func' => '_create_new_cpt_item', |
|
131 | + 'capability' => 'ee_edit_events', |
|
132 | + ), |
|
133 | + 'edit' => array( |
|
134 | + 'func' => '_edit_cpt_item', |
|
135 | + 'capability' => 'ee_edit_event', |
|
136 | + 'obj_id' => $evt_id, |
|
137 | + ), |
|
138 | + 'copy_event' => array( |
|
139 | + 'func' => '_copy_events', |
|
140 | + 'capability' => 'ee_edit_event', |
|
141 | + 'obj_id' => $evt_id, |
|
142 | + 'noheader' => true, |
|
143 | + ), |
|
144 | + 'trash_event' => array( |
|
145 | + 'func' => '_trash_or_restore_event', |
|
146 | + 'args' => array('event_status' => 'trash'), |
|
147 | + 'capability' => 'ee_delete_event', |
|
148 | + 'obj_id' => $evt_id, |
|
149 | + 'noheader' => true, |
|
150 | + ), |
|
151 | + 'trash_events' => array( |
|
152 | + 'func' => '_trash_or_restore_events', |
|
153 | + 'args' => array('event_status' => 'trash'), |
|
154 | + 'capability' => 'ee_delete_events', |
|
155 | + 'noheader' => true, |
|
156 | + ), |
|
157 | + 'restore_event' => array( |
|
158 | + 'func' => '_trash_or_restore_event', |
|
159 | + 'args' => array('event_status' => 'draft'), |
|
160 | + 'capability' => 'ee_delete_event', |
|
161 | + 'obj_id' => $evt_id, |
|
162 | + 'noheader' => true, |
|
163 | + ), |
|
164 | + 'restore_events' => array( |
|
165 | + 'func' => '_trash_or_restore_events', |
|
166 | + 'args' => array('event_status' => 'draft'), |
|
167 | + 'capability' => 'ee_delete_events', |
|
168 | + 'noheader' => true, |
|
169 | + ), |
|
170 | + 'delete_event' => array( |
|
171 | + 'func' => '_delete_event', |
|
172 | + 'capability' => 'ee_delete_event', |
|
173 | + 'obj_id' => $evt_id, |
|
174 | + 'noheader' => true, |
|
175 | + ), |
|
176 | + 'delete_events' => array( |
|
177 | + 'func' => '_delete_events', |
|
178 | + 'capability' => 'ee_delete_events', |
|
179 | + 'noheader' => true, |
|
180 | + ), |
|
181 | + 'view_report' => array( |
|
182 | + 'func' => '_view_report', |
|
183 | + 'capability' => 'ee_edit_events', |
|
184 | + ), |
|
185 | + 'default_event_settings' => array( |
|
186 | + 'func' => '_default_event_settings', |
|
187 | + 'capability' => 'manage_options', |
|
188 | + ), |
|
189 | + 'update_default_event_settings' => array( |
|
190 | + 'func' => '_update_default_event_settings', |
|
191 | + 'capability' => 'manage_options', |
|
192 | + 'noheader' => true, |
|
193 | + ), |
|
194 | + 'template_settings' => array( |
|
195 | + 'func' => '_template_settings', |
|
196 | + 'capability' => 'manage_options', |
|
197 | + ), |
|
198 | + // event category tab related |
|
199 | + 'add_category' => array( |
|
200 | + 'func' => '_category_details', |
|
201 | + 'capability' => 'ee_edit_event_category', |
|
202 | + 'args' => array('add'), |
|
203 | + ), |
|
204 | + 'edit_category' => array( |
|
205 | + 'func' => '_category_details', |
|
206 | + 'capability' => 'ee_edit_event_category', |
|
207 | + 'args' => array('edit'), |
|
208 | + ), |
|
209 | + 'delete_categories' => array( |
|
210 | + 'func' => '_delete_categories', |
|
211 | + 'capability' => 'ee_delete_event_category', |
|
212 | + 'noheader' => true, |
|
213 | + ), |
|
214 | + 'delete_category' => array( |
|
215 | + 'func' => '_delete_categories', |
|
216 | + 'capability' => 'ee_delete_event_category', |
|
217 | + 'noheader' => true, |
|
218 | + ), |
|
219 | + 'insert_category' => array( |
|
220 | + 'func' => '_insert_or_update_category', |
|
221 | + 'args' => array('new_category' => true), |
|
222 | + 'capability' => 'ee_edit_event_category', |
|
223 | + 'noheader' => true, |
|
224 | + ), |
|
225 | + 'update_category' => array( |
|
226 | + 'func' => '_insert_or_update_category', |
|
227 | + 'args' => array('new_category' => false), |
|
228 | + 'capability' => 'ee_edit_event_category', |
|
229 | + 'noheader' => true, |
|
230 | + ), |
|
231 | + 'category_list' => array( |
|
232 | + 'func' => '_category_list_table', |
|
233 | + 'capability' => 'ee_manage_event_categories', |
|
234 | + ), |
|
235 | + ); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Set the _page_config property for this admin page group. |
|
241 | + */ |
|
242 | + protected function _set_page_config() |
|
243 | + { |
|
244 | + $this->_page_config = array( |
|
245 | + 'default' => array( |
|
246 | + 'nav' => array( |
|
247 | + 'label' => esc_html__('Overview', 'event_espresso'), |
|
248 | + 'order' => 10, |
|
249 | + ), |
|
250 | + 'list_table' => 'Events_Admin_List_Table', |
|
251 | + 'help_tabs' => array( |
|
252 | + 'events_overview_help_tab' => array( |
|
253 | + 'title' => esc_html__('Events Overview', 'event_espresso'), |
|
254 | + 'filename' => 'events_overview', |
|
255 | + ), |
|
256 | + 'events_overview_table_column_headings_help_tab' => array( |
|
257 | + 'title' => esc_html__('Events Overview Table Column Headings', 'event_espresso'), |
|
258 | + 'filename' => 'events_overview_table_column_headings', |
|
259 | + ), |
|
260 | + 'events_overview_filters_help_tab' => array( |
|
261 | + 'title' => esc_html__('Events Overview Filters', 'event_espresso'), |
|
262 | + 'filename' => 'events_overview_filters', |
|
263 | + ), |
|
264 | + 'events_overview_view_help_tab' => array( |
|
265 | + 'title' => esc_html__('Events Overview Views', 'event_espresso'), |
|
266 | + 'filename' => 'events_overview_views', |
|
267 | + ), |
|
268 | + 'events_overview_other_help_tab' => array( |
|
269 | + 'title' => esc_html__('Events Overview Other', 'event_espresso'), |
|
270 | + 'filename' => 'events_overview_other', |
|
271 | + ), |
|
272 | + ), |
|
273 | + 'help_tour' => array( |
|
274 | + 'Event_Overview_Help_Tour', |
|
275 | + // 'New_Features_Test_Help_Tour' for testing multiple help tour |
|
276 | + ), |
|
277 | + 'qtips' => array( |
|
278 | + 'EE_Event_List_Table_Tips', |
|
279 | + ), |
|
280 | + 'require_nonce' => false, |
|
281 | + ), |
|
282 | + 'create_new' => array( |
|
283 | + 'nav' => array( |
|
284 | + 'label' => esc_html__('Add Event', 'event_espresso'), |
|
285 | + 'order' => 5, |
|
286 | + 'persistent' => false, |
|
287 | + ), |
|
288 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
289 | + 'help_tabs' => array( |
|
290 | + 'event_editor_help_tab' => array( |
|
291 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
292 | + 'filename' => 'event_editor', |
|
293 | + ), |
|
294 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
295 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
296 | + 'filename' => 'event_editor_title_richtexteditor', |
|
297 | + ), |
|
298 | + 'event_editor_venue_details_help_tab' => array( |
|
299 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
300 | + 'filename' => 'event_editor_venue_details', |
|
301 | + ), |
|
302 | + 'event_editor_event_datetimes_help_tab' => array( |
|
303 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
304 | + 'filename' => 'event_editor_event_datetimes', |
|
305 | + ), |
|
306 | + 'event_editor_event_tickets_help_tab' => array( |
|
307 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
308 | + 'filename' => 'event_editor_event_tickets', |
|
309 | + ), |
|
310 | + 'event_editor_event_registration_options_help_tab' => array( |
|
311 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
312 | + 'filename' => 'event_editor_event_registration_options', |
|
313 | + ), |
|
314 | + 'event_editor_tags_categories_help_tab' => array( |
|
315 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
316 | + 'filename' => 'event_editor_tags_categories', |
|
317 | + ), |
|
318 | + 'event_editor_questions_registrants_help_tab' => array( |
|
319 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
320 | + 'filename' => 'event_editor_questions_registrants', |
|
321 | + ), |
|
322 | + 'event_editor_save_new_event_help_tab' => array( |
|
323 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
324 | + 'filename' => 'event_editor_save_new_event', |
|
325 | + ), |
|
326 | + 'event_editor_other_help_tab' => array( |
|
327 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
328 | + 'filename' => 'event_editor_other', |
|
329 | + ), |
|
330 | + ), |
|
331 | + 'help_tour' => array( |
|
332 | + 'Event_Editor_Help_Tour', |
|
333 | + ), |
|
334 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
335 | + 'require_nonce' => false, |
|
336 | + ), |
|
337 | + 'edit' => array( |
|
338 | + 'nav' => array( |
|
339 | + 'label' => esc_html__('Edit Event', 'event_espresso'), |
|
340 | + 'order' => 5, |
|
341 | + 'persistent' => false, |
|
342 | + 'url' => isset($this->_req_data['post']) |
|
343 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
344 | + array('post' => $this->_req_data['post'], 'action' => 'edit'), |
|
345 | + $this->_current_page_view_url |
|
346 | + ) |
|
347 | + : $this->_admin_base_url, |
|
348 | + ), |
|
349 | + 'metaboxes' => array('_register_event_editor_meta_boxes'), |
|
350 | + 'help_tabs' => array( |
|
351 | + 'event_editor_help_tab' => array( |
|
352 | + 'title' => esc_html__('Event Editor', 'event_espresso'), |
|
353 | + 'filename' => 'event_editor', |
|
354 | + ), |
|
355 | + 'event_editor_title_richtexteditor_help_tab' => array( |
|
356 | + 'title' => esc_html__('Event Title & Rich Text Editor', 'event_espresso'), |
|
357 | + 'filename' => 'event_editor_title_richtexteditor', |
|
358 | + ), |
|
359 | + 'event_editor_venue_details_help_tab' => array( |
|
360 | + 'title' => esc_html__('Event Venue Details', 'event_espresso'), |
|
361 | + 'filename' => 'event_editor_venue_details', |
|
362 | + ), |
|
363 | + 'event_editor_event_datetimes_help_tab' => array( |
|
364 | + 'title' => esc_html__('Event Datetimes', 'event_espresso'), |
|
365 | + 'filename' => 'event_editor_event_datetimes', |
|
366 | + ), |
|
367 | + 'event_editor_event_tickets_help_tab' => array( |
|
368 | + 'title' => esc_html__('Event Tickets', 'event_espresso'), |
|
369 | + 'filename' => 'event_editor_event_tickets', |
|
370 | + ), |
|
371 | + 'event_editor_event_registration_options_help_tab' => array( |
|
372 | + 'title' => esc_html__('Event Registration Options', 'event_espresso'), |
|
373 | + 'filename' => 'event_editor_event_registration_options', |
|
374 | + ), |
|
375 | + 'event_editor_tags_categories_help_tab' => array( |
|
376 | + 'title' => esc_html__('Event Tags & Categories', 'event_espresso'), |
|
377 | + 'filename' => 'event_editor_tags_categories', |
|
378 | + ), |
|
379 | + 'event_editor_questions_registrants_help_tab' => array( |
|
380 | + 'title' => esc_html__('Questions for Registrants', 'event_espresso'), |
|
381 | + 'filename' => 'event_editor_questions_registrants', |
|
382 | + ), |
|
383 | + 'event_editor_save_new_event_help_tab' => array( |
|
384 | + 'title' => esc_html__('Save New Event', 'event_espresso'), |
|
385 | + 'filename' => 'event_editor_save_new_event', |
|
386 | + ), |
|
387 | + 'event_editor_other_help_tab' => array( |
|
388 | + 'title' => esc_html__('Event Other', 'event_espresso'), |
|
389 | + 'filename' => 'event_editor_other', |
|
390 | + ), |
|
391 | + ), |
|
392 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
393 | + 'require_nonce' => false, |
|
394 | + ), |
|
395 | + 'default_event_settings' => array( |
|
396 | + 'nav' => array( |
|
397 | + 'label' => esc_html__('Default Settings', 'event_espresso'), |
|
398 | + 'order' => 40, |
|
399 | + ), |
|
400 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
401 | + 'labels' => array( |
|
402 | + 'publishbox' => esc_html__('Update Settings', 'event_espresso'), |
|
403 | + ), |
|
404 | + 'help_tabs' => array( |
|
405 | + 'default_settings_help_tab' => array( |
|
406 | + 'title' => esc_html__('Default Event Settings', 'event_espresso'), |
|
407 | + 'filename' => 'events_default_settings', |
|
408 | + ), |
|
409 | + 'default_settings_status_help_tab' => array( |
|
410 | + 'title' => esc_html__('Default Registration Status', 'event_espresso'), |
|
411 | + 'filename' => 'events_default_settings_status', |
|
412 | + ), |
|
413 | + 'default_maximum_tickets_help_tab' => array( |
|
414 | + 'title' => esc_html__('Default Maximum Tickets Per Order', 'event_espresso'), |
|
415 | + 'filename' => 'events_default_settings_max_tickets', |
|
416 | + ), |
|
417 | + ), |
|
418 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
419 | + 'require_nonce' => false, |
|
420 | + ), |
|
421 | + // template settings |
|
422 | + 'template_settings' => array( |
|
423 | + 'nav' => array( |
|
424 | + 'label' => esc_html__('Templates', 'event_espresso'), |
|
425 | + 'order' => 30, |
|
426 | + ), |
|
427 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
428 | + 'help_tabs' => array( |
|
429 | + 'general_settings_templates_help_tab' => array( |
|
430 | + 'title' => esc_html__('Templates', 'event_espresso'), |
|
431 | + 'filename' => 'general_settings_templates', |
|
432 | + ), |
|
433 | + ), |
|
434 | + 'help_tour' => array('Templates_Help_Tour'), |
|
435 | + 'require_nonce' => false, |
|
436 | + ), |
|
437 | + // event category stuff |
|
438 | + 'add_category' => array( |
|
439 | + 'nav' => array( |
|
440 | + 'label' => esc_html__('Add Category', 'event_espresso'), |
|
441 | + 'order' => 15, |
|
442 | + 'persistent' => false, |
|
443 | + ), |
|
444 | + 'help_tabs' => array( |
|
445 | + 'add_category_help_tab' => array( |
|
446 | + 'title' => esc_html__('Add New Event Category', 'event_espresso'), |
|
447 | + 'filename' => 'events_add_category', |
|
448 | + ), |
|
449 | + ), |
|
450 | + 'help_tour' => array('Event_Add_Category_Help_Tour'), |
|
451 | + 'metaboxes' => array('_publish_post_box'), |
|
452 | + 'require_nonce' => false, |
|
453 | + ), |
|
454 | + 'edit_category' => array( |
|
455 | + 'nav' => array( |
|
456 | + 'label' => esc_html__('Edit Category', 'event_espresso'), |
|
457 | + 'order' => 15, |
|
458 | + 'persistent' => false, |
|
459 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) |
|
460 | + ? add_query_arg( |
|
461 | + array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), |
|
462 | + $this->_current_page_view_url |
|
463 | + ) |
|
464 | + : $this->_admin_base_url, |
|
465 | + ), |
|
466 | + 'help_tabs' => array( |
|
467 | + 'edit_category_help_tab' => array( |
|
468 | + 'title' => esc_html__('Edit Event Category', 'event_espresso'), |
|
469 | + 'filename' => 'events_edit_category', |
|
470 | + ), |
|
471 | + ), |
|
472 | + /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/ |
|
473 | + 'metaboxes' => array('_publish_post_box'), |
|
474 | + 'require_nonce' => false, |
|
475 | + ), |
|
476 | + 'category_list' => array( |
|
477 | + 'nav' => array( |
|
478 | + 'label' => esc_html__('Categories', 'event_espresso'), |
|
479 | + 'order' => 20, |
|
480 | + ), |
|
481 | + 'list_table' => 'Event_Categories_Admin_List_Table', |
|
482 | + 'help_tabs' => array( |
|
483 | + 'events_categories_help_tab' => array( |
|
484 | + 'title' => esc_html__('Event Categories', 'event_espresso'), |
|
485 | + 'filename' => 'events_categories', |
|
486 | + ), |
|
487 | + 'events_categories_table_column_headings_help_tab' => array( |
|
488 | + 'title' => esc_html__('Event Categories Table Column Headings', 'event_espresso'), |
|
489 | + 'filename' => 'events_categories_table_column_headings', |
|
490 | + ), |
|
491 | + 'events_categories_view_help_tab' => array( |
|
492 | + 'title' => esc_html__('Event Categories Views', 'event_espresso'), |
|
493 | + 'filename' => 'events_categories_views', |
|
494 | + ), |
|
495 | + 'events_categories_other_help_tab' => array( |
|
496 | + 'title' => esc_html__('Event Categories Other', 'event_espresso'), |
|
497 | + 'filename' => 'events_categories_other', |
|
498 | + ), |
|
499 | + ), |
|
500 | + 'help_tour' => array( |
|
501 | + 'Event_Categories_Help_Tour', |
|
502 | + ), |
|
503 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
504 | + 'require_nonce' => false, |
|
505 | + ), |
|
506 | + ); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * Used to register any global screen options if necessary for every route in this admin page group. |
|
512 | + */ |
|
513 | + protected function _add_screen_options() |
|
514 | + { |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * Implementing the screen options for the 'default' route. |
|
520 | + * |
|
521 | + * @throws InvalidArgumentException |
|
522 | + * @throws InvalidDataTypeException |
|
523 | + * @throws InvalidInterfaceException |
|
524 | + */ |
|
525 | + protected function _add_screen_options_default() |
|
526 | + { |
|
527 | + $this->_per_page_screen_option(); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * Implementing screen options for the category list route. |
|
533 | + * |
|
534 | + * @throws InvalidArgumentException |
|
535 | + * @throws InvalidDataTypeException |
|
536 | + * @throws InvalidInterfaceException |
|
537 | + */ |
|
538 | + protected function _add_screen_options_category_list() |
|
539 | + { |
|
540 | + $page_title = $this->_admin_page_title; |
|
541 | + $this->_admin_page_title = esc_html__('Categories', 'event_espresso'); |
|
542 | + $this->_per_page_screen_option(); |
|
543 | + $this->_admin_page_title = $page_title; |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * Used to register any global feature pointers for the admin page group. |
|
549 | + */ |
|
550 | + protected function _add_feature_pointers() |
|
551 | + { |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * Registers and enqueues any global scripts and styles for the entire admin page group. |
|
557 | + */ |
|
558 | + public function load_scripts_styles() |
|
559 | + { |
|
560 | + wp_register_style( |
|
561 | + 'events-admin-css', |
|
562 | + EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
563 | + array(), |
|
564 | + EVENT_ESPRESSO_VERSION |
|
565 | + ); |
|
566 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
567 | + wp_enqueue_style('events-admin-css'); |
|
568 | + wp_enqueue_style('ee-cat-admin'); |
|
569 | + // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
|
570 | + // registers for all views |
|
571 | + // scripts |
|
572 | + wp_register_script( |
|
573 | + 'event_editor_js', |
|
574 | + EVENTS_ASSETS_URL . 'event_editor.js', |
|
575 | + array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
|
576 | + EVENT_ESPRESSO_VERSION, |
|
577 | + true |
|
578 | + ); |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Enqueuing scripts and styles specific to this view |
|
584 | + */ |
|
585 | + public function load_scripts_styles_create_new() |
|
586 | + { |
|
587 | + $this->load_scripts_styles_edit(); |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + /** |
|
592 | + * Enqueuing scripts and styles specific to this view |
|
593 | + */ |
|
594 | + public function load_scripts_styles_edit() |
|
595 | + { |
|
596 | + // styles |
|
597 | + wp_enqueue_style('espresso-ui-theme'); |
|
598 | + wp_register_style( |
|
599 | + 'event-editor-css', |
|
600 | + EVENTS_ASSETS_URL . 'event-editor.css', |
|
601 | + array('ee-admin-css'), |
|
602 | + EVENT_ESPRESSO_VERSION |
|
603 | + ); |
|
604 | + wp_enqueue_style('event-editor-css'); |
|
605 | + // scripts |
|
606 | + wp_register_script( |
|
607 | + 'event-datetime-metabox', |
|
608 | + EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
609 | + array('event_editor_js', 'ee-datepicker'), |
|
610 | + EVENT_ESPRESSO_VERSION |
|
611 | + ); |
|
612 | + wp_enqueue_script('event-datetime-metabox'); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Populating the _views property for the category list table view. |
|
618 | + */ |
|
619 | + protected function _set_list_table_views_category_list() |
|
620 | + { |
|
621 | + $this->_views = array( |
|
622 | + 'all' => array( |
|
623 | + 'slug' => 'all', |
|
624 | + 'label' => esc_html__('All', 'event_espresso'), |
|
625 | + 'count' => 0, |
|
626 | + 'bulk_action' => array( |
|
627 | + 'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'), |
|
628 | + ), |
|
629 | + ), |
|
630 | + ); |
|
631 | + } |
|
632 | + |
|
633 | + |
|
634 | + /** |
|
635 | + * For adding anything that fires on the admin_init hook for any route within this admin page group. |
|
636 | + */ |
|
637 | + public function admin_init() |
|
638 | + { |
|
639 | + EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__( |
|
640 | + 'Do you really want to delete this image? Please remember to update your event to complete the removal.', |
|
641 | + 'event_espresso' |
|
642 | + ); |
|
643 | + } |
|
644 | + |
|
645 | + |
|
646 | + /** |
|
647 | + * For adding anything that should be triggered on the admin_notices hook for any route within this admin page |
|
648 | + * group. |
|
649 | + */ |
|
650 | + public function admin_notices() |
|
651 | + { |
|
652 | + } |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * For adding anything that should be triggered on the `admin_print_footer_scripts` hook for any route within |
|
657 | + * this admin page group. |
|
658 | + */ |
|
659 | + public function admin_footer_scripts() |
|
660 | + { |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * Call this function to verify if an event is public and has tickets for sale. If it does, then we need to show a |
|
666 | + * warning (via EE_Error::add_error()); |
|
667 | + * |
|
668 | + * @param EE_Event $event Event object |
|
669 | + * @param string $req_type |
|
670 | + * @return void |
|
671 | + * @throws EE_Error |
|
672 | + * @access public |
|
673 | + */ |
|
674 | + public function verify_event_edit($event = null, $req_type = '') |
|
675 | + { |
|
676 | + // don't need to do this when processing |
|
677 | + if (! empty($req_type)) { |
|
678 | + return; |
|
679 | + } |
|
680 | + // no event? |
|
681 | + if (! $event instanceof EE_Event) { |
|
682 | + $event = $this->_cpt_model_obj; |
|
683 | + } |
|
684 | + // STILL no event? |
|
685 | + if (! $event instanceof EE_Event) { |
|
686 | + return; |
|
687 | + } |
|
688 | + $orig_status = $event->status(); |
|
689 | + // first check if event is active. |
|
690 | + if ($orig_status === EEM_Event::cancelled |
|
691 | + || $orig_status === EEM_Event::postponed |
|
692 | + || $event->is_expired() |
|
693 | + || $event->is_inactive() |
|
694 | + ) { |
|
695 | + return; |
|
696 | + } |
|
697 | + // made it here so it IS active... next check that any of the tickets are sold. |
|
698 | + if ($event->is_sold_out(true)) { |
|
699 | + if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) { |
|
700 | + EE_Error::add_attention( |
|
701 | + sprintf( |
|
702 | + esc_html__( |
|
703 | + 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', |
|
704 | + 'event_espresso' |
|
705 | + ), |
|
706 | + EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence') |
|
707 | + ) |
|
708 | + ); |
|
709 | + } |
|
710 | + return; |
|
711 | + } |
|
712 | + if ($orig_status === EEM_Event::sold_out) { |
|
713 | + EE_Error::add_attention( |
|
714 | + sprintf( |
|
715 | + esc_html__( |
|
716 | + 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
717 | + 'event_espresso' |
|
718 | + ), |
|
719 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
720 | + ) |
|
721 | + ); |
|
722 | + } |
|
723 | + // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
|
724 | + if (! $event->tickets_on_sale()) { |
|
725 | + return; |
|
726 | + } |
|
727 | + // made it here so show warning |
|
728 | + $this->_edit_event_warning(); |
|
729 | + } |
|
730 | + |
|
731 | + |
|
732 | + /** |
|
733 | + * This is the text used for when an event is being edited that is public and has tickets for sale. |
|
734 | + * When needed, hook this into a EE_Error::add_error() notice. |
|
735 | + * |
|
736 | + * @access protected |
|
737 | + * @return void |
|
738 | + */ |
|
739 | + protected function _edit_event_warning() |
|
740 | + { |
|
741 | + // we don't want to add warnings during these requests |
|
742 | + if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') { |
|
743 | + return; |
|
744 | + } |
|
745 | + EE_Error::add_attention( |
|
746 | + sprintf( |
|
747 | + esc_html__( |
|
748 | + 'Your event is open for registration. Making changes may disrupt any transactions in progress. %sLearn more%s', |
|
749 | + 'event_espresso' |
|
750 | + ), |
|
751 | + '<a class="espresso-help-tab-lnk">', |
|
752 | + '</a>' |
|
753 | + ) |
|
754 | + ); |
|
755 | + } |
|
756 | + |
|
757 | + |
|
758 | + /** |
|
759 | + * When a user is creating a new event, notify them if they haven't set their timezone. |
|
760 | + * Otherwise, do the normal logic |
|
761 | + * |
|
762 | + * @return string |
|
763 | + * @throws EE_Error |
|
764 | + * @throws InvalidArgumentException |
|
765 | + * @throws InvalidDataTypeException |
|
766 | + * @throws InvalidInterfaceException |
|
767 | + */ |
|
768 | + protected function _create_new_cpt_item() |
|
769 | + { |
|
770 | + $has_timezone_string = get_option('timezone_string'); |
|
771 | + // only nag them about setting their timezone if it's their first event, and they haven't already done it |
|
772 | + if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
773 | + EE_Error::add_attention( |
|
774 | + sprintf( |
|
775 | + __( |
|
776 | + 'Your website\'s timezone is currently set to a UTC offset. We recommend updating your timezone to a city or region near you before you create an event. Change your timezone now:%1$s%2$s%3$sChange Timezone%4$s', |
|
777 | + 'event_espresso' |
|
778 | + ), |
|
779 | + '<br>', |
|
780 | + '<select id="timezone_string" name="timezone_string" aria-describedby="timezone-description">' |
|
781 | + . EEH_DTT_Helper::wp_timezone_choice('', EEH_DTT_Helper::get_user_locale()) |
|
782 | + . '</select>', |
|
783 | + '<button class="button button-secondary timezone-submit">', |
|
784 | + '</button><span class="spinner"></span>' |
|
785 | + ), |
|
786 | + __FILE__, |
|
787 | + __FUNCTION__, |
|
788 | + __LINE__ |
|
789 | + ); |
|
790 | + } |
|
791 | + parent::_create_new_cpt_item(); |
|
792 | + } |
|
793 | + |
|
794 | + |
|
795 | + /** |
|
796 | + * Sets the _views property for the default route in this admin page group. |
|
797 | + */ |
|
798 | + protected function _set_list_table_views_default() |
|
799 | + { |
|
800 | + $this->_views = array( |
|
801 | + 'all' => array( |
|
802 | + 'slug' => 'all', |
|
803 | + 'label' => esc_html__('View All Events', 'event_espresso'), |
|
804 | + 'count' => 0, |
|
805 | + 'bulk_action' => array( |
|
806 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
807 | + ), |
|
808 | + ), |
|
809 | + 'draft' => array( |
|
810 | + 'slug' => 'draft', |
|
811 | + 'label' => esc_html__('Draft', 'event_espresso'), |
|
812 | + 'count' => 0, |
|
813 | + 'bulk_action' => array( |
|
814 | + 'trash_events' => esc_html__('Move to Trash', 'event_espresso'), |
|
815 | + ), |
|
816 | + ), |
|
817 | + ); |
|
818 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
819 | + $this->_views['trash'] = array( |
|
820 | + 'slug' => 'trash', |
|
821 | + 'label' => esc_html__('Trash', 'event_espresso'), |
|
822 | + 'count' => 0, |
|
823 | + 'bulk_action' => array( |
|
824 | + 'restore_events' => esc_html__('Restore From Trash', 'event_espresso'), |
|
825 | + 'delete_events' => esc_html__('Delete Permanently', 'event_espresso'), |
|
826 | + ), |
|
827 | + ); |
|
828 | + } |
|
829 | + } |
|
830 | + |
|
831 | + |
|
832 | + /** |
|
833 | + * Provides the legend item array for the default list table view. |
|
834 | + * |
|
835 | + * @return array |
|
836 | + */ |
|
837 | + protected function _event_legend_items() |
|
838 | + { |
|
839 | + $items = array( |
|
840 | + 'view_details' => array( |
|
841 | + 'class' => 'dashicons dashicons-search', |
|
842 | + 'desc' => esc_html__('View Event', 'event_espresso'), |
|
843 | + ), |
|
844 | + 'edit_event' => array( |
|
845 | + 'class' => 'ee-icon ee-icon-calendar-edit', |
|
846 | + 'desc' => esc_html__('Edit Event Details', 'event_espresso'), |
|
847 | + ), |
|
848 | + 'view_attendees' => array( |
|
849 | + 'class' => 'dashicons dashicons-groups', |
|
850 | + 'desc' => esc_html__('View Registrations for Event', 'event_espresso'), |
|
851 | + ), |
|
852 | + ); |
|
853 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
854 | + $statuses = array( |
|
855 | + 'sold_out_status' => array( |
|
856 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
857 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
|
858 | + ), |
|
859 | + 'active_status' => array( |
|
860 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
861 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
|
862 | + ), |
|
863 | + 'upcoming_status' => array( |
|
864 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
865 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
|
866 | + ), |
|
867 | + 'postponed_status' => array( |
|
868 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
869 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
|
870 | + ), |
|
871 | + 'cancelled_status' => array( |
|
872 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
873 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
|
874 | + ), |
|
875 | + 'expired_status' => array( |
|
876 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
877 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
|
878 | + ), |
|
879 | + 'inactive_status' => array( |
|
880 | + 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
881 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
|
882 | + ), |
|
883 | + ); |
|
884 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
885 | + return array_merge($items, $statuses); |
|
886 | + } |
|
887 | + |
|
888 | + |
|
889 | + /** |
|
890 | + * @return EEM_Event |
|
891 | + * @throws EE_Error |
|
892 | + * @throws InvalidArgumentException |
|
893 | + * @throws InvalidDataTypeException |
|
894 | + * @throws InvalidInterfaceException |
|
895 | + * @throws ReflectionException |
|
896 | + */ |
|
897 | + private function _event_model() |
|
898 | + { |
|
899 | + if (! $this->_event_model instanceof EEM_Event) { |
|
900 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
901 | + } |
|
902 | + return $this->_event_model; |
|
903 | + } |
|
904 | + |
|
905 | + |
|
906 | + /** |
|
907 | + * Adds extra buttons to the WP CPT permalink field row. |
|
908 | + * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter. |
|
909 | + * |
|
910 | + * @param string $return the current html |
|
911 | + * @param int $id the post id for the page |
|
912 | + * @param string $new_title What the title is |
|
913 | + * @param string $new_slug what the slug is |
|
914 | + * @return string The new html string for the permalink area |
|
915 | + */ |
|
916 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
|
917 | + { |
|
918 | + // make sure this is only when editing |
|
919 | + if (! empty($id)) { |
|
920 | + $post = get_post($id); |
|
921 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
|
922 | + . esc_html__('Shortcode', 'event_espresso') |
|
923 | + . '</a> '; |
|
924 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=' |
|
925 | + . $post->ID |
|
926 | + . ']">'; |
|
927 | + } |
|
928 | + return $return; |
|
929 | + } |
|
930 | + |
|
931 | + |
|
932 | + /** |
|
933 | + * _events_overview_list_table |
|
934 | + * This contains the logic for showing the events_overview list |
|
935 | + * |
|
936 | + * @access protected |
|
937 | + * @return void |
|
938 | + * @throws DomainException |
|
939 | + * @throws EE_Error |
|
940 | + * @throws InvalidArgumentException |
|
941 | + * @throws InvalidDataTypeException |
|
942 | + * @throws InvalidInterfaceException |
|
943 | + */ |
|
944 | + protected function _events_overview_list_table() |
|
945 | + { |
|
946 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
947 | + $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table']) |
|
948 | + ? (array) $this->_template_args['after_list_table'] |
|
949 | + : array(); |
|
950 | + $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br() |
|
951 | + . EEH_Template::get_button_or_link( |
|
952 | + get_post_type_archive_link('espresso_events'), |
|
953 | + esc_html__('View Event Archive Page', 'event_espresso'), |
|
954 | + 'button' |
|
955 | + ); |
|
956 | + $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
|
957 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
958 | + 'create_new', |
|
959 | + 'add', |
|
960 | + array(), |
|
961 | + 'add-new-h2' |
|
962 | + ); |
|
963 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
964 | + } |
|
965 | + |
|
966 | + |
|
967 | + /** |
|
968 | + * this allows for extra misc actions in the default WP publish box |
|
969 | + * |
|
970 | + * @return void |
|
971 | + * @throws DomainException |
|
972 | + * @throws EE_Error |
|
973 | + * @throws InvalidArgumentException |
|
974 | + * @throws InvalidDataTypeException |
|
975 | + * @throws InvalidInterfaceException |
|
976 | + * @throws ReflectionException |
|
977 | + */ |
|
978 | + public function extra_misc_actions_publish_box() |
|
979 | + { |
|
980 | + $this->_generate_publish_box_extra_content(); |
|
981 | + } |
|
982 | + |
|
983 | + |
|
984 | + /** |
|
985 | + * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been |
|
986 | + * saved. |
|
987 | + * Typically you would use this to save any additional data. |
|
988 | + * Keep in mind also that "save_post" runs on EVERY post update to the database. |
|
989 | + * ALSO very important. When a post transitions from scheduled to published, |
|
990 | + * the save_post action is fired but you will NOT have any _POST data containing any extra info you may have from |
|
991 | + * other meta saves. So MAKE sure that you handle this accordingly. |
|
992 | + * |
|
993 | + * @access protected |
|
994 | + * @abstract |
|
995 | + * @param string $post_id The ID of the cpt that was saved (so you can link relationally) |
|
996 | + * @param object $post The post object of the cpt that was saved. |
|
997 | + * @return void |
|
998 | + * @throws EE_Error |
|
999 | + * @throws InvalidArgumentException |
|
1000 | + * @throws InvalidDataTypeException |
|
1001 | + * @throws InvalidInterfaceException |
|
1002 | + * @throws ReflectionException |
|
1003 | + */ |
|
1004 | + protected function _insert_update_cpt_item($post_id, $post) |
|
1005 | + { |
|
1006 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
1007 | + // get out we're not processing an event save. |
|
1008 | + return; |
|
1009 | + } |
|
1010 | + $event_values = array( |
|
1011 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
1012 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
1013 | + 'EVT_additional_limit' => min( |
|
1014 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
1015 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null |
|
1016 | + ), |
|
1017 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) |
|
1018 | + ? $this->_req_data['EVT_default_registration_status'] |
|
1019 | + : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
1020 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
1021 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
1022 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) |
|
1023 | + ? $this->_req_data['timezone_string'] : null, |
|
1024 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) |
|
1025 | + ? $this->_req_data['externalURL'] : null, |
|
1026 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) |
|
1027 | + ? $this->_req_data['event_phone'] : null, |
|
1028 | + ); |
|
1029 | + // update event |
|
1030 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
1031 | + // get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
|
1032 | + $get_one_where = array( |
|
1033 | + $this->_event_model()->primary_key_name() => $post_id, |
|
1034 | + 'OR' => array( |
|
1035 | + 'status' => $post->post_status, |
|
1036 | + // if trying to "Publish" a sold out event, it's status will get switched back to "sold_out" in the db, |
|
1037 | + // but the returned object here has a status of "publish", so use the original post status as well |
|
1038 | + 'status*1' => $this->_req_data['original_post_status'], |
|
1039 | + ), |
|
1040 | + ); |
|
1041 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
1042 | + // the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
|
1043 | + $event_update_callbacks = apply_filters( |
|
1044 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
1045 | + array( |
|
1046 | + array($this, '_default_venue_update'), |
|
1047 | + array($this, '_default_tickets_update'), |
|
1048 | + ) |
|
1049 | + ); |
|
1050 | + $att_success = true; |
|
1051 | + foreach ($event_update_callbacks as $e_callback) { |
|
1052 | + $_success = is_callable($e_callback) |
|
1053 | + ? $e_callback($event, $this->_req_data) |
|
1054 | + : false; |
|
1055 | + // if ANY of these updates fail then we want the appropriate global error message |
|
1056 | + $att_success = ! $att_success ? $att_success : $_success; |
|
1057 | + } |
|
1058 | + // any errors? |
|
1059 | + if ($success && false === $att_success) { |
|
1060 | + EE_Error::add_error( |
|
1061 | + esc_html__( |
|
1062 | + 'Event Details saved successfully but something went wrong with saving attachments.', |
|
1063 | + 'event_espresso' |
|
1064 | + ), |
|
1065 | + __FILE__, |
|
1066 | + __FUNCTION__, |
|
1067 | + __LINE__ |
|
1068 | + ); |
|
1069 | + } elseif ($success === false) { |
|
1070 | + EE_Error::add_error( |
|
1071 | + esc_html__('Event Details did not save successfully.', 'event_espresso'), |
|
1072 | + __FILE__, |
|
1073 | + __FUNCTION__, |
|
1074 | + __LINE__ |
|
1075 | + ); |
|
1076 | + } |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * @param int $post_id |
|
1082 | + * @param int $revision_id |
|
1083 | + * @throws EE_Error |
|
1084 | + * @throws InvalidArgumentException |
|
1085 | + * @throws InvalidDataTypeException |
|
1086 | + * @throws InvalidInterfaceException |
|
1087 | + * @throws ReflectionException |
|
1088 | + * @see parent::restore_item() |
|
1089 | + */ |
|
1090 | + protected function _restore_cpt_item($post_id, $revision_id) |
|
1091 | + { |
|
1092 | + // copy existing event meta to new post |
|
1093 | + $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
|
1094 | + if ($post_evt instanceof EE_Event) { |
|
1095 | + // meta revision restore |
|
1096 | + $post_evt->restore_revision($revision_id); |
|
1097 | + // related objs restore |
|
1098 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
1099 | + } |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * Attach the venue to the Event |
|
1105 | + * |
|
1106 | + * @param EE_Event $evtobj Event Object to add the venue to |
|
1107 | + * @param array $data The request data from the form |
|
1108 | + * @return bool Success or fail. |
|
1109 | + * @throws EE_Error |
|
1110 | + * @throws InvalidArgumentException |
|
1111 | + * @throws InvalidDataTypeException |
|
1112 | + * @throws InvalidInterfaceException |
|
1113 | + * @throws ReflectionException |
|
1114 | + */ |
|
1115 | + protected function _default_venue_update(EE_Event $evtobj, $data) |
|
1116 | + { |
|
1117 | + require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1118 | + $venue_model = EE_Registry::instance()->load_model('Venue'); |
|
1119 | + $rows_affected = null; |
|
1120 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
|
1121 | + // very important. If we don't have a venue name... |
|
1122 | + // then we'll get out because not necessary to create empty venue |
|
1123 | + if (empty($data['venue_title'])) { |
|
1124 | + return false; |
|
1125 | + } |
|
1126 | + $venue_array = array( |
|
1127 | + 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
|
1128 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : null, |
|
1129 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : null, |
|
1130 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null, |
|
1131 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] |
|
1132 | + : null, |
|
1133 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : null, |
|
1134 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : null, |
|
1135 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : null, |
|
1136 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : null, |
|
1137 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : null, |
|
1138 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : null, |
|
1139 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : null, |
|
1140 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null, |
|
1141 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : null, |
|
1142 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null, |
|
1143 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : null, |
|
1144 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
1145 | + 'status' => 'publish', |
|
1146 | + ); |
|
1147 | + // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
|
1148 | + if (! empty($venue_id)) { |
|
1149 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
1150 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
1151 | + // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
|
1152 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1153 | + return $rows_affected > 0; |
|
1154 | + } |
|
1155 | + // we insert the venue |
|
1156 | + $venue_id = $venue_model->insert($venue_array); |
|
1157 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
1158 | + return ! empty($venue_id) ? true : false; |
|
1159 | + // when we have the ancestor come in it's already been handled by the revision save. |
|
1160 | + } |
|
1161 | + |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
1165 | + * |
|
1166 | + * @param EE_Event $evtobj The Event object we're attaching data to |
|
1167 | + * @param array $data The request data from the form |
|
1168 | + * @return array |
|
1169 | + * @throws EE_Error |
|
1170 | + * @throws InvalidArgumentException |
|
1171 | + * @throws InvalidDataTypeException |
|
1172 | + * @throws InvalidInterfaceException |
|
1173 | + * @throws ReflectionException |
|
1174 | + * @throws Exception |
|
1175 | + */ |
|
1176 | + protected function _default_tickets_update(EE_Event $evtobj, $data) |
|
1177 | + { |
|
1178 | + $success = true; |
|
1179 | + $saved_dtt = null; |
|
1180 | + $saved_tickets = array(); |
|
1181 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1182 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
1183 | + // trim all values to ensure any excess whitespace is removed. |
|
1184 | + $dtt = array_map('trim', $dtt); |
|
1185 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] |
|
1186 | + : $dtt['DTT_EVT_start']; |
|
1187 | + $datetime_values = array( |
|
1188 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null, |
|
1189 | + 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
|
1190 | + 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
|
1191 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
1192 | + 'DTT_order' => $row, |
|
1193 | + ); |
|
1194 | + // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
|
1195 | + if (! empty($dtt['DTT_ID'])) { |
|
1196 | + $DTM = EE_Registry::instance() |
|
1197 | + ->load_model('Datetime', array($evtobj->get_timezone())) |
|
1198 | + ->get_one_by_ID($dtt['DTT_ID']); |
|
1199 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
1200 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
1201 | + foreach ($datetime_values as $field => $value) { |
|
1202 | + $DTM->set($field, $value); |
|
1203 | + } |
|
1204 | + // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
|
1205 | + $saved_dtts[ $DTM->ID() ] = $DTM; |
|
1206 | + } else { |
|
1207 | + $DTM = EE_Registry::instance()->load_class( |
|
1208 | + 'Datetime', |
|
1209 | + array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats), |
|
1210 | + false, |
|
1211 | + false |
|
1212 | + ); |
|
1213 | + foreach ($datetime_values as $field => $value) { |
|
1214 | + $DTM->set($field, $value); |
|
1215 | + } |
|
1216 | + } |
|
1217 | + $DTM->save(); |
|
1218 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
1219 | + // load DTT helper |
|
1220 | + // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
1221 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
1222 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
1223 | + $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
|
1224 | + $DTT->save(); |
|
1225 | + } |
|
1226 | + // now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
|
1227 | + $saved_dtt = $DTT; |
|
1228 | + $success = ! $success ? $success : $DTT; |
|
1229 | + // if ANY of these updates fail then we want the appropriate global error message. |
|
1230 | + // //todo this is actually sucky we need a better error message but this is what it is for now. |
|
1231 | + } |
|
1232 | + // no dtts get deleted so we don't do any of that logic here. |
|
1233 | + // update tickets next |
|
1234 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
1235 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
1236 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1237 | + $update_prices = false; |
|
1238 | + $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
1239 | + ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
1240 | + // trim inputs to ensure any excess whitespace is removed. |
|
1241 | + $tkt = array_map('trim', $tkt); |
|
1242 | + if (empty($tkt['TKT_start_date'])) { |
|
1243 | + // let's use now in the set timezone. |
|
1244 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
1245 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1246 | + } |
|
1247 | + if (empty($tkt['TKT_end_date'])) { |
|
1248 | + // use the start date of the first datetime |
|
1249 | + $dtt = $evtobj->first_datetime(); |
|
1250 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time( |
|
1251 | + $incoming_date_formats[0], |
|
1252 | + $incoming_date_formats[1] |
|
1253 | + ); |
|
1254 | + } |
|
1255 | + $TKT_values = array( |
|
1256 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
1257 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
1258 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
1259 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
1260 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
1261 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
1262 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
1263 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
1264 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
1265 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
1266 | + 'TKT_row' => $row, |
|
1267 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
1268 | + 'TKT_price' => $ticket_price, |
|
1269 | + ); |
|
1270 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
|
1271 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
1272 | + $TKT_values['TKT_ID'] = 0; |
|
1273 | + $TKT_values['TKT_is_default'] = 0; |
|
1274 | + $TKT_values['TKT_price'] = $ticket_price; |
|
1275 | + $update_prices = true; |
|
1276 | + } |
|
1277 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
1278 | + // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
|
1279 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
1280 | + if (! empty($tkt['TKT_ID'])) { |
|
1281 | + $TKT = EE_Registry::instance() |
|
1282 | + ->load_model('Ticket', array($evtobj->get_timezone())) |
|
1283 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
1284 | + if ($TKT instanceof EE_Ticket) { |
|
1285 | + $ticket_sold = $TKT->count_related( |
|
1286 | + 'Registration', |
|
1287 | + array( |
|
1288 | + array( |
|
1289 | + 'STS_ID' => array( |
|
1290 | + 'NOT IN', |
|
1291 | + array(EEM_Registration::status_id_incomplete), |
|
1292 | + ), |
|
1293 | + ), |
|
1294 | + ) |
|
1295 | + ) > 0; |
|
1296 | + // let's just check the total price for the existing ticket and determine if it matches the new |
|
1297 | + // total price. if they are different then we create a new ticket (if tickets sold) |
|
1298 | + // if they aren't different then we go ahead and modify existing ticket. |
|
1299 | + $create_new_TKT = $ticket_sold && ! $TKT->deleted() && EEH_Money::compare_floats( |
|
1300 | + $ticket_price, |
|
1301 | + $TKT->get('TKT_price'), |
|
1302 | + '!==' |
|
1303 | + ); |
|
1304 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
1305 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
1306 | + // set new values |
|
1307 | + foreach ($TKT_values as $field => $value) { |
|
1308 | + if ($field === 'TKT_qty') { |
|
1309 | + $TKT->set_qty($value); |
|
1310 | + } else { |
|
1311 | + $TKT->set($field, $value); |
|
1312 | + } |
|
1313 | + } |
|
1314 | + // if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
|
1315 | + if ($create_new_TKT) { |
|
1316 | + // archive the old ticket first |
|
1317 | + $TKT->set('TKT_deleted', 1); |
|
1318 | + $TKT->save(); |
|
1319 | + // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
|
1320 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1321 | + // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
|
1322 | + $TKT = clone $TKT; |
|
1323 | + $TKT->set('TKT_ID', 0); |
|
1324 | + $TKT->set('TKT_deleted', 0); |
|
1325 | + $TKT->set('TKT_price', $ticket_price); |
|
1326 | + $TKT->set('TKT_sold', 0); |
|
1327 | + // now we need to make sure that $new prices are created as well and attached to new ticket. |
|
1328 | + $update_prices = true; |
|
1329 | + } |
|
1330 | + // make sure price is set if it hasn't been already |
|
1331 | + $TKT->set('TKT_price', $ticket_price); |
|
1332 | + } |
|
1333 | + } else { |
|
1334 | + // no TKT_id so a new TKT |
|
1335 | + $TKT_values['TKT_price'] = $ticket_price; |
|
1336 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false); |
|
1337 | + if ($TKT instanceof EE_Ticket) { |
|
1338 | + // need to reset values to properly account for the date formats |
|
1339 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
1340 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
1341 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
1342 | + // set new values |
|
1343 | + foreach ($TKT_values as $field => $value) { |
|
1344 | + if ($field === 'TKT_qty') { |
|
1345 | + $TKT->set_qty($value); |
|
1346 | + } else { |
|
1347 | + $TKT->set($field, $value); |
|
1348 | + } |
|
1349 | + } |
|
1350 | + $update_prices = true; |
|
1351 | + } |
|
1352 | + } |
|
1353 | + // cap ticket qty by datetime reg limits |
|
1354 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
1355 | + // update ticket. |
|
1356 | + $TKT->save(); |
|
1357 | + // before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
|
1358 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
1359 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
1360 | + $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
|
1361 | + $TKT->save(); |
|
1362 | + } |
|
1363 | + // initially let's add the ticket to the dtt |
|
1364 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
1365 | + $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1366 | + // add prices to ticket |
|
1367 | + $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
1368 | + } |
|
1369 | + // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
|
1370 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
1371 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1372 | + foreach ($tickets_removed as $id) { |
|
1373 | + $id = absint($id); |
|
1374 | + // get the ticket for this id |
|
1375 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
1376 | + // need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
|
1377 | + $dtts = $tkt_to_remove->get_many_related('Datetime'); |
|
1378 | + foreach ($dtts as $dtt) { |
|
1379 | + $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
|
1380 | + } |
|
1381 | + // need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
1382 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
1383 | + // finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
|
1384 | + $tkt_to_remove->delete_permanently(); |
|
1385 | + } |
|
1386 | + return array($saved_dtt, $saved_tickets); |
|
1387 | + } |
|
1388 | + |
|
1389 | + |
|
1390 | + /** |
|
1391 | + * This attaches a list of given prices to a ticket. |
|
1392 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
1393 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
1394 | + * price info and prices are automatically "archived" via the ticket. |
|
1395 | + * |
|
1396 | + * @access private |
|
1397 | + * @param array $prices Array of prices from the form. |
|
1398 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
1399 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
1400 | + * @return void |
|
1401 | + * @throws EE_Error |
|
1402 | + * @throws InvalidArgumentException |
|
1403 | + * @throws InvalidDataTypeException |
|
1404 | + * @throws InvalidInterfaceException |
|
1405 | + * @throws ReflectionException |
|
1406 | + */ |
|
1407 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false) |
|
1408 | + { |
|
1409 | + foreach ($prices as $row => $prc) { |
|
1410 | + $PRC_values = array( |
|
1411 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
1412 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null, |
|
1413 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
1414 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
1415 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
1416 | + 'PRC_is_default' => 0, // make sure prices are NOT set as default from this context |
|
1417 | + 'PRC_order' => $row, |
|
1418 | + ); |
|
1419 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
1420 | + $PRC_values['PRC_ID'] = 0; |
|
1421 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false); |
|
1422 | + } else { |
|
1423 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
1424 | + // update this price with new values |
|
1425 | + foreach ($PRC_values as $field => $newprc) { |
|
1426 | + $PRC->set($field, $newprc); |
|
1427 | + } |
|
1428 | + $PRC->save(); |
|
1429 | + } |
|
1430 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
1431 | + } |
|
1432 | + } |
|
1433 | + |
|
1434 | + |
|
1435 | + /** |
|
1436 | + * Add in our autosave ajax handlers |
|
1437 | + * |
|
1438 | + */ |
|
1439 | + protected function _ee_autosave_create_new() |
|
1440 | + { |
|
1441 | + } |
|
1442 | + |
|
1443 | + |
|
1444 | + /** |
|
1445 | + * More autosave handlers. |
|
1446 | + */ |
|
1447 | + protected function _ee_autosave_edit() |
|
1448 | + { |
|
1449 | + } |
|
1450 | + |
|
1451 | + |
|
1452 | + /** |
|
1453 | + * _generate_publish_box_extra_content |
|
1454 | + * |
|
1455 | + * @throws DomainException |
|
1456 | + * @throws EE_Error |
|
1457 | + * @throws InvalidArgumentException |
|
1458 | + * @throws InvalidDataTypeException |
|
1459 | + * @throws InvalidInterfaceException |
|
1460 | + * @throws ReflectionException |
|
1461 | + */ |
|
1462 | + private function _generate_publish_box_extra_content() |
|
1463 | + { |
|
1464 | + // load formatter helper |
|
1465 | + // args for getting related registrations |
|
1466 | + $approved_query_args = array( |
|
1467 | + array( |
|
1468 | + 'REG_deleted' => 0, |
|
1469 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
1470 | + ), |
|
1471 | + ); |
|
1472 | + $not_approved_query_args = array( |
|
1473 | + array( |
|
1474 | + 'REG_deleted' => 0, |
|
1475 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
1476 | + ), |
|
1477 | + ); |
|
1478 | + $pending_payment_query_args = array( |
|
1479 | + array( |
|
1480 | + 'REG_deleted' => 0, |
|
1481 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
1482 | + ), |
|
1483 | + ); |
|
1484 | + // publish box |
|
1485 | + $publish_box_extra_args = array( |
|
1486 | + 'view_approved_reg_url' => add_query_arg( |
|
1487 | + array( |
|
1488 | + 'action' => 'default', |
|
1489 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1490 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1491 | + ), |
|
1492 | + REG_ADMIN_URL |
|
1493 | + ), |
|
1494 | + 'view_not_approved_reg_url' => add_query_arg( |
|
1495 | + array( |
|
1496 | + 'action' => 'default', |
|
1497 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1498 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1499 | + ), |
|
1500 | + REG_ADMIN_URL |
|
1501 | + ), |
|
1502 | + 'view_pending_payment_reg_url' => add_query_arg( |
|
1503 | + array( |
|
1504 | + 'action' => 'default', |
|
1505 | + 'event_id' => $this->_cpt_model_obj->ID(), |
|
1506 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1507 | + ), |
|
1508 | + REG_ADMIN_URL |
|
1509 | + ), |
|
1510 | + 'approved_regs' => $this->_cpt_model_obj->count_related( |
|
1511 | + 'Registration', |
|
1512 | + $approved_query_args |
|
1513 | + ), |
|
1514 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related( |
|
1515 | + 'Registration', |
|
1516 | + $not_approved_query_args |
|
1517 | + ), |
|
1518 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related( |
|
1519 | + 'Registration', |
|
1520 | + $pending_payment_query_args |
|
1521 | + ), |
|
1522 | + 'misc_pub_section_class' => apply_filters( |
|
1523 | + 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
|
1524 | + 'misc-pub-section' |
|
1525 | + ), |
|
1526 | + ); |
|
1527 | + ob_start(); |
|
1528 | + do_action( |
|
1529 | + 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
|
1530 | + $this->_cpt_model_obj |
|
1531 | + ); |
|
1532 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1533 | + // load template |
|
1534 | + EEH_Template::display_template( |
|
1535 | + EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1536 | + $publish_box_extra_args |
|
1537 | + ); |
|
1538 | + } |
|
1539 | + |
|
1540 | + |
|
1541 | + /** |
|
1542 | + * @return EE_Event |
|
1543 | + */ |
|
1544 | + public function get_event_object() |
|
1545 | + { |
|
1546 | + return $this->_cpt_model_obj; |
|
1547 | + } |
|
1548 | + |
|
1549 | + |
|
1550 | + |
|
1551 | + |
|
1552 | + /** METABOXES * */ |
|
1553 | + /** |
|
1554 | + * _register_event_editor_meta_boxes |
|
1555 | + * add all metaboxes related to the event_editor |
|
1556 | + * |
|
1557 | + * @return void |
|
1558 | + * @throws EE_Error |
|
1559 | + * @throws InvalidArgumentException |
|
1560 | + * @throws InvalidDataTypeException |
|
1561 | + * @throws InvalidInterfaceException |
|
1562 | + * @throws ReflectionException |
|
1563 | + */ |
|
1564 | + protected function _register_event_editor_meta_boxes() |
|
1565 | + { |
|
1566 | + $this->verify_cpt_object(); |
|
1567 | + // add_meta_box( |
|
1568 | + // 'espresso_event_editor_tickets', |
|
1569 | + // esc_html__('Event Datetime & Ticket', 'event_espresso'), |
|
1570 | + // array($this, 'ticket_metabox'), |
|
1571 | + // $this->page_slug, |
|
1572 | + // 'normal', |
|
1573 | + // 'high' |
|
1574 | + // ); |
|
1575 | + add_meta_box( |
|
1576 | + 'espresso_event_editor_event_options', |
|
1577 | + esc_html__('Event Registration Options', 'event_espresso'), |
|
1578 | + array($this, 'registration_options_meta_box'), |
|
1579 | + $this->page_slug, |
|
1580 | + 'side' |
|
1581 | + ); |
|
1582 | + // NOTE: if you're looking for other metaboxes in here, |
|
1583 | + // where a metabox has a related management page in the admin |
|
1584 | + // you will find it setup in the related management page's "_Hooks" file. |
|
1585 | + // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php". |
|
1586 | + } |
|
1587 | + |
|
1588 | + |
|
1589 | + /** |
|
1590 | + * @throws DomainException |
|
1591 | + * @throws EE_Error |
|
1592 | + * @throws InvalidArgumentException |
|
1593 | + * @throws InvalidDataTypeException |
|
1594 | + * @throws InvalidInterfaceException |
|
1595 | + * @throws ReflectionException |
|
1596 | + */ |
|
1597 | + public function ticket_metabox() |
|
1598 | + { |
|
1599 | + $existing_datetime_ids = $existing_ticket_ids = array(); |
|
1600 | + // defaults for template args |
|
1601 | + $template_args = array( |
|
1602 | + 'existing_datetime_ids' => '', |
|
1603 | + 'event_datetime_help_link' => '', |
|
1604 | + 'ticket_options_help_link' => '', |
|
1605 | + 'time' => null, |
|
1606 | + 'ticket_rows' => '', |
|
1607 | + 'existing_ticket_ids' => '', |
|
1608 | + 'total_ticket_rows' => 1, |
|
1609 | + 'ticket_js_structure' => '', |
|
1610 | + 'trash_icon' => 'ee-lock-icon', |
|
1611 | + 'disabled' => '', |
|
1612 | + ); |
|
1613 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null; |
|
1614 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1615 | + /** |
|
1616 | + * 1. Start with retrieving Datetimes |
|
1617 | + * 2. Fore each datetime get related tickets |
|
1618 | + * 3. For each ticket get related prices |
|
1619 | + */ |
|
1620 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
1621 | + /** @type EE_Datetime $first_datetime */ |
|
1622 | + $first_datetime = reset($times); |
|
1623 | + // do we get related tickets? |
|
1624 | + if ($first_datetime instanceof EE_Datetime |
|
1625 | + && $first_datetime->ID() !== 0 |
|
1626 | + ) { |
|
1627 | + $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
|
1628 | + $template_args['time'] = $first_datetime; |
|
1629 | + $related_tickets = $first_datetime->tickets( |
|
1630 | + array( |
|
1631 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
1632 | + 'default_where_conditions' => 'none', |
|
1633 | + ) |
|
1634 | + ); |
|
1635 | + if (! empty($related_tickets)) { |
|
1636 | + $template_args['total_ticket_rows'] = count($related_tickets); |
|
1637 | + $row = 0; |
|
1638 | + foreach ($related_tickets as $ticket) { |
|
1639 | + $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
|
1640 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row); |
|
1641 | + $row++; |
|
1642 | + } |
|
1643 | + } else { |
|
1644 | + $template_args['total_ticket_rows'] = 1; |
|
1645 | + /** @type EE_Ticket $ticket */ |
|
1646 | + $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
|
1647 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1648 | + } |
|
1649 | + } else { |
|
1650 | + $template_args['time'] = $times[0]; |
|
1651 | + /** @type EE_Ticket $ticket */ |
|
1652 | + $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
|
1653 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
1654 | + // NOTE: we're just sending the first default row |
|
1655 | + // (decaf can't manage default tickets so this should be sufficient); |
|
1656 | + } |
|
1657 | + $template_args['event_datetime_help_link'] = $this->_get_help_tab_link( |
|
1658 | + 'event_editor_event_datetimes_help_tab' |
|
1659 | + ); |
|
1660 | + $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
|
1661 | + $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1662 | + $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1663 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row( |
|
1664 | + EE_Registry::instance()->load_model('Ticket')->create_default_object(), |
|
1665 | + true |
|
1666 | + ); |
|
1667 | + $template = apply_filters( |
|
1668 | + 'FHEE__Events_Admin_Page__ticket_metabox__template', |
|
1669 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1670 | + ); |
|
1671 | + EEH_Template::display_template($template, $template_args); |
|
1672 | + } |
|
1673 | + |
|
1674 | + |
|
1675 | + /** |
|
1676 | + * Setup an individual ticket form for the decaf event editor page |
|
1677 | + * |
|
1678 | + * @access private |
|
1679 | + * @param EE_Ticket $ticket the ticket object |
|
1680 | + * @param boolean $skeleton whether we're generating a skeleton for js manipulation |
|
1681 | + * @param int $row |
|
1682 | + * @return string generated html for the ticket row. |
|
1683 | + * @throws DomainException |
|
1684 | + * @throws EE_Error |
|
1685 | + * @throws InvalidArgumentException |
|
1686 | + * @throws InvalidDataTypeException |
|
1687 | + * @throws InvalidInterfaceException |
|
1688 | + * @throws ReflectionException |
|
1689 | + */ |
|
1690 | + private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
|
1691 | + { |
|
1692 | + $template_args = array( |
|
1693 | + 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1694 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
|
1695 | + : '', |
|
1696 | + 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
|
1697 | + 'TKT_ID' => $ticket->get('TKT_ID'), |
|
1698 | + 'TKT_name' => $ticket->get('TKT_name'), |
|
1699 | + 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
|
1700 | + 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
|
1701 | + 'TKT_is_default' => $ticket->get('TKT_is_default'), |
|
1702 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1703 | + 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1704 | + 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
|
1705 | + 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1706 | + && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1707 | + ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1708 | + 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1709 | + : ' disabled=disabled', |
|
1710 | + ); |
|
1711 | + $price = $ticket->ID() !== 0 |
|
1712 | + ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) |
|
1713 | + : EE_Registry::instance()->load_model('Price')->create_default_object(); |
|
1714 | + $price_args = array( |
|
1715 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1716 | + 'PRC_amount' => $price->get('PRC_amount'), |
|
1717 | + 'PRT_ID' => $price->get('PRT_ID'), |
|
1718 | + 'PRC_ID' => $price->get('PRC_ID'), |
|
1719 | + 'PRC_is_default' => $price->get('PRC_is_default'), |
|
1720 | + ); |
|
1721 | + // make sure we have default start and end dates if skeleton |
|
1722 | + // handle rows that should NOT be empty |
|
1723 | + if (empty($template_args['TKT_start_date'])) { |
|
1724 | + // if empty then the start date will be now. |
|
1725 | + $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
|
1726 | + } |
|
1727 | + if (empty($template_args['TKT_end_date'])) { |
|
1728 | + // get the earliest datetime (if present); |
|
1729 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 |
|
1730 | + ? $this->_cpt_model_obj->get_first_related( |
|
1731 | + 'Datetime', |
|
1732 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1733 | + ) |
|
1734 | + : null; |
|
1735 | + if (! empty($earliest_dtt)) { |
|
1736 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
|
1737 | + } else { |
|
1738 | + $template_args['TKT_end_date'] = date( |
|
1739 | + 'Y-m-d h:i a', |
|
1740 | + mktime(0, 0, 0, date('m'), date('d') + 7, date('Y')) |
|
1741 | + ); |
|
1742 | + } |
|
1743 | + } |
|
1744 | + $template_args = array_merge($template_args, $price_args); |
|
1745 | + $template = apply_filters( |
|
1746 | + 'FHEE__Events_Admin_Page__get_ticket_row__template', |
|
1747 | + EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1748 | + $ticket |
|
1749 | + ); |
|
1750 | + return EEH_Template::display_template($template, $template_args, true); |
|
1751 | + } |
|
1752 | + |
|
1753 | + |
|
1754 | + /** |
|
1755 | + * @throws DomainException |
|
1756 | + * @throws EE_Error |
|
1757 | + */ |
|
1758 | + public function registration_options_meta_box() |
|
1759 | + { |
|
1760 | + $yes_no_values = array( |
|
1761 | + array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')), |
|
1762 | + array('id' => false, 'text' => esc_html__('No', 'event_espresso')), |
|
1763 | + ); |
|
1764 | + $default_reg_status_values = EEM_Registration::reg_status_array( |
|
1765 | + array( |
|
1766 | + EEM_Registration::status_id_cancelled, |
|
1767 | + EEM_Registration::status_id_declined, |
|
1768 | + EEM_Registration::status_id_incomplete, |
|
1769 | + ), |
|
1770 | + true |
|
1771 | + ); |
|
1772 | + // $template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active()); |
|
1773 | + $template_args['_event'] = $this->_cpt_model_obj; |
|
1774 | + $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false); |
|
1775 | + $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit(); |
|
1776 | + $template_args['default_registration_status'] = EEH_Form_Fields::select_input( |
|
1777 | + 'default_reg_status', |
|
1778 | + $default_reg_status_values, |
|
1779 | + $this->_cpt_model_obj->default_registration_status() |
|
1780 | + ); |
|
1781 | + $template_args['display_description'] = EEH_Form_Fields::select_input( |
|
1782 | + 'display_desc', |
|
1783 | + $yes_no_values, |
|
1784 | + $this->_cpt_model_obj->display_description() |
|
1785 | + ); |
|
1786 | + $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input( |
|
1787 | + 'display_ticket_selector', |
|
1788 | + $yes_no_values, |
|
1789 | + $this->_cpt_model_obj->display_ticket_selector(), |
|
1790 | + '', |
|
1791 | + '', |
|
1792 | + false |
|
1793 | + ); |
|
1794 | + $template_args['additional_registration_options'] = apply_filters( |
|
1795 | + 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', |
|
1796 | + '', |
|
1797 | + $template_args, |
|
1798 | + $yes_no_values, |
|
1799 | + $default_reg_status_values |
|
1800 | + ); |
|
1801 | + EEH_Template::display_template( |
|
1802 | + EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1803 | + $template_args |
|
1804 | + ); |
|
1805 | + } |
|
1806 | + |
|
1807 | + |
|
1808 | + /** |
|
1809 | + * _get_events() |
|
1810 | + * This method simply returns all the events (for the given _view and paging) |
|
1811 | + * |
|
1812 | + * @access public |
|
1813 | + * @param int $per_page count of items per page (20 default); |
|
1814 | + * @param int $current_page what is the current page being viewed. |
|
1815 | + * @param bool $count if TRUE then we just return a count of ALL events matching the given _view. |
|
1816 | + * If FALSE then we return an array of event objects |
|
1817 | + * that match the given _view and paging parameters. |
|
1818 | + * @return array an array of event objects. |
|
1819 | + * @throws EE_Error |
|
1820 | + * @throws InvalidArgumentException |
|
1821 | + * @throws InvalidDataTypeException |
|
1822 | + * @throws InvalidInterfaceException |
|
1823 | + * @throws ReflectionException |
|
1824 | + * @throws Exception |
|
1825 | + * @throws Exception |
|
1826 | + * @throws Exception |
|
1827 | + */ |
|
1828 | + public function get_events($per_page = 10, $current_page = 1, $count = false) |
|
1829 | + { |
|
1830 | + $EEME = $this->_event_model(); |
|
1831 | + $offset = ($current_page - 1) * $per_page; |
|
1832 | + $limit = $count ? null : $offset . ',' . $per_page; |
|
1833 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
|
1834 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
1835 | + if (isset($this->_req_data['month_range'])) { |
|
1836 | + $pieces = explode(' ', $this->_req_data['month_range'], 3); |
|
1837 | + // simulate the FIRST day of the month, that fixes issues for months like February |
|
1838 | + // where PHP doesn't know what to assume for date. |
|
1839 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/10437 |
|
1840 | + $month_r = ! empty($pieces[0]) ? date('m', EEH_DTT_Helper::first_of_month_timestamp($pieces[0])) : ''; |
|
1841 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1842 | + } |
|
1843 | + $where = array(); |
|
1844 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null; |
|
1845 | + // determine what post_status our condition will have for the query. |
|
1846 | + switch ($status) { |
|
1847 | + case 'month': |
|
1848 | + case 'today': |
|
1849 | + case null: |
|
1850 | + case 'all': |
|
1851 | + break; |
|
1852 | + case 'draft': |
|
1853 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
1854 | + break; |
|
1855 | + default: |
|
1856 | + $where['status'] = $status; |
|
1857 | + } |
|
1858 | + // categories? |
|
1859 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
|
1860 | + ? $this->_req_data['EVT_CAT'] : null; |
|
1861 | + if (! empty($category)) { |
|
1862 | + $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
|
1863 | + $where['Term_Taxonomy.term_id'] = $category; |
|
1864 | + } |
|
1865 | + // date where conditions |
|
1866 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1867 | + if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
|
1868 | + $DateTime = new DateTime( |
|
1869 | + $year_r . '-' . $month_r . '-01 00:00:00', |
|
1870 | + new DateTimeZone('UTC') |
|
1871 | + ); |
|
1872 | + $start = $DateTime->getTimestamp(); |
|
1873 | + // set the datetime to be the end of the month |
|
1874 | + $DateTime->setDate( |
|
1875 | + $year_r, |
|
1876 | + $month_r, |
|
1877 | + $DateTime->format('t') |
|
1878 | + )->setTime(23, 59, 59); |
|
1879 | + $end = $DateTime->getTimestamp(); |
|
1880 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1881 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'today') { |
|
1882 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1883 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1884 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1885 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1886 | + } elseif (isset($this->_req_data['status']) && $this->_req_data['status'] === 'month') { |
|
1887 | + $now = date('Y-m-01'); |
|
1888 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1889 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1890 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t')) |
|
1891 | + ->setTime(23, 59, 59) |
|
1892 | + ->format(implode(' ', $start_formats)); |
|
1893 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1894 | + } |
|
1895 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1896 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
1897 | + } elseif (! isset($where['status']) |
|
1898 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events') |
|
1899 | + ) { |
|
1900 | + $where['OR'] = array( |
|
1901 | + 'status*restrict_private' => array('!=', 'private'), |
|
1902 | + 'AND' => array( |
|
1903 | + 'status*inclusive' => array('=', 'private'), |
|
1904 | + 'EVT_wp_user' => get_current_user_id(), |
|
1905 | + ), |
|
1906 | + ); |
|
1907 | + } |
|
1908 | + |
|
1909 | + if (isset($this->_req_data['EVT_wp_user']) |
|
1910 | + && (int) $this->_req_data['EVT_wp_user'] !== (int) get_current_user_id() |
|
1911 | + && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events') |
|
1912 | + ) { |
|
1913 | + $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
|
1914 | + } |
|
1915 | + // search query handling |
|
1916 | + if (isset($this->_req_data['s'])) { |
|
1917 | + $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1918 | + $where['OR'] = array( |
|
1919 | + 'EVT_name' => array('LIKE', $search_string), |
|
1920 | + 'EVT_desc' => array('LIKE', $search_string), |
|
1921 | + 'EVT_short_desc' => array('LIKE', $search_string), |
|
1922 | + ); |
|
1923 | + } |
|
1924 | + // filter events by venue. |
|
1925 | + if (isset($this->_req_data['venue']) && ! empty($this->_req_data['venue'])) { |
|
1926 | + $where['Venue.VNU_ID'] = absint($this->_req_data['venue']); |
|
1927 | + } |
|
1928 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
1929 | + $query_params = apply_filters( |
|
1930 | + 'FHEE__Events_Admin_Page__get_events__query_params', |
|
1931 | + array( |
|
1932 | + $where, |
|
1933 | + 'limit' => $limit, |
|
1934 | + 'order_by' => $orderby, |
|
1935 | + 'order' => $order, |
|
1936 | + 'group_by' => 'EVT_ID', |
|
1937 | + ), |
|
1938 | + $this->_req_data |
|
1939 | + ); |
|
1940 | + |
|
1941 | + // let's first check if we have special requests coming in. |
|
1942 | + if (isset($this->_req_data['active_status'])) { |
|
1943 | + switch ($this->_req_data['active_status']) { |
|
1944 | + case 'upcoming': |
|
1945 | + return $EEME->get_upcoming_events($query_params, $count); |
|
1946 | + break; |
|
1947 | + case 'expired': |
|
1948 | + return $EEME->get_expired_events($query_params, $count); |
|
1949 | + break; |
|
1950 | + case 'active': |
|
1951 | + return $EEME->get_active_events($query_params, $count); |
|
1952 | + break; |
|
1953 | + case 'inactive': |
|
1954 | + return $EEME->get_inactive_events($query_params, $count); |
|
1955 | + break; |
|
1956 | + } |
|
1957 | + } |
|
1958 | + |
|
1959 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
1960 | + return $events; |
|
1961 | + } |
|
1962 | + |
|
1963 | + |
|
1964 | + /** |
|
1965 | + * handling for WordPress CPT actions (trash, restore, delete) |
|
1966 | + * |
|
1967 | + * @param string $post_id |
|
1968 | + * @throws EE_Error |
|
1969 | + * @throws InvalidArgumentException |
|
1970 | + * @throws InvalidDataTypeException |
|
1971 | + * @throws InvalidInterfaceException |
|
1972 | + * @throws ReflectionException |
|
1973 | + */ |
|
1974 | + public function trash_cpt_item($post_id) |
|
1975 | + { |
|
1976 | + $this->_req_data['EVT_ID'] = $post_id; |
|
1977 | + $this->_trash_or_restore_event('trash', false); |
|
1978 | + } |
|
1979 | + |
|
1980 | + |
|
1981 | + /** |
|
1982 | + * @param string $post_id |
|
1983 | + * @throws EE_Error |
|
1984 | + * @throws InvalidArgumentException |
|
1985 | + * @throws InvalidDataTypeException |
|
1986 | + * @throws InvalidInterfaceException |
|
1987 | + * @throws ReflectionException |
|
1988 | + */ |
|
1989 | + public function restore_cpt_item($post_id) |
|
1990 | + { |
|
1991 | + $this->_req_data['EVT_ID'] = $post_id; |
|
1992 | + $this->_trash_or_restore_event('draft', false); |
|
1993 | + } |
|
1994 | + |
|
1995 | + |
|
1996 | + /** |
|
1997 | + * @param string $post_id |
|
1998 | + * @throws EE_Error |
|
1999 | + * @throws InvalidArgumentException |
|
2000 | + * @throws InvalidDataTypeException |
|
2001 | + * @throws InvalidInterfaceException |
|
2002 | + * @throws ReflectionException |
|
2003 | + */ |
|
2004 | + public function delete_cpt_item($post_id) |
|
2005 | + { |
|
2006 | + $this->_req_data['EVT_ID'] = $post_id; |
|
2007 | + $this->_delete_event(false); |
|
2008 | + } |
|
2009 | + |
|
2010 | + |
|
2011 | + /** |
|
2012 | + * _trash_or_restore_event |
|
2013 | + * |
|
2014 | + * @access protected |
|
2015 | + * @param string $event_status |
|
2016 | + * @param bool $redirect_after |
|
2017 | + * @throws EE_Error |
|
2018 | + * @throws InvalidArgumentException |
|
2019 | + * @throws InvalidDataTypeException |
|
2020 | + * @throws InvalidInterfaceException |
|
2021 | + * @throws ReflectionException |
|
2022 | + */ |
|
2023 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true) |
|
2024 | + { |
|
2025 | + // determine the event id and set to array. |
|
2026 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false; |
|
2027 | + // loop thru events |
|
2028 | + if ($EVT_ID) { |
|
2029 | + // clean status |
|
2030 | + $event_status = sanitize_key($event_status); |
|
2031 | + // grab status |
|
2032 | + if (! empty($event_status)) { |
|
2033 | + $success = $this->_change_event_status($EVT_ID, $event_status); |
|
2034 | + } else { |
|
2035 | + $success = false; |
|
2036 | + $msg = esc_html__( |
|
2037 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2038 | + 'event_espresso' |
|
2039 | + ); |
|
2040 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2041 | + } |
|
2042 | + } else { |
|
2043 | + $success = false; |
|
2044 | + $msg = esc_html__( |
|
2045 | + 'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.', |
|
2046 | + 'event_espresso' |
|
2047 | + ); |
|
2048 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2049 | + } |
|
2050 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2051 | + if ($redirect_after) { |
|
2052 | + $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
|
2053 | + } |
|
2054 | + } |
|
2055 | + |
|
2056 | + |
|
2057 | + /** |
|
2058 | + * _trash_or_restore_events |
|
2059 | + * |
|
2060 | + * @access protected |
|
2061 | + * @param string $event_status |
|
2062 | + * @return void |
|
2063 | + * @throws EE_Error |
|
2064 | + * @throws InvalidArgumentException |
|
2065 | + * @throws InvalidDataTypeException |
|
2066 | + * @throws InvalidInterfaceException |
|
2067 | + * @throws ReflectionException |
|
2068 | + */ |
|
2069 | + protected function _trash_or_restore_events($event_status = 'trash') |
|
2070 | + { |
|
2071 | + // clean status |
|
2072 | + $event_status = sanitize_key($event_status); |
|
2073 | + // grab status |
|
2074 | + if (! empty($event_status)) { |
|
2075 | + $success = true; |
|
2076 | + // determine the event id and set to array. |
|
2077 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
2078 | + // loop thru events |
|
2079 | + foreach ($EVT_IDs as $EVT_ID) { |
|
2080 | + if ($EVT_ID = absint($EVT_ID)) { |
|
2081 | + $results = $this->_change_event_status($EVT_ID, $event_status); |
|
2082 | + $success = $results !== false ? $success : false; |
|
2083 | + } else { |
|
2084 | + $msg = sprintf( |
|
2085 | + esc_html__( |
|
2086 | + 'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.', |
|
2087 | + 'event_espresso' |
|
2088 | + ), |
|
2089 | + $EVT_ID |
|
2090 | + ); |
|
2091 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2092 | + $success = false; |
|
2093 | + } |
|
2094 | + } |
|
2095 | + } else { |
|
2096 | + $success = false; |
|
2097 | + $msg = esc_html__( |
|
2098 | + 'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.', |
|
2099 | + 'event_espresso' |
|
2100 | + ); |
|
2101 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2102 | + } |
|
2103 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2104 | + $success = $success ? 2 : false; |
|
2105 | + $action = $event_status === 'trash' ? 'moved to the trash' : 'restored from the trash'; |
|
2106 | + $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default')); |
|
2107 | + } |
|
2108 | + |
|
2109 | + |
|
2110 | + /** |
|
2111 | + * _trash_or_restore_events |
|
2112 | + * |
|
2113 | + * @access private |
|
2114 | + * @param int $EVT_ID |
|
2115 | + * @param string $event_status |
|
2116 | + * @return bool |
|
2117 | + * @throws EE_Error |
|
2118 | + * @throws InvalidArgumentException |
|
2119 | + * @throws InvalidDataTypeException |
|
2120 | + * @throws InvalidInterfaceException |
|
2121 | + * @throws ReflectionException |
|
2122 | + */ |
|
2123 | + private function _change_event_status($EVT_ID = 0, $event_status = '') |
|
2124 | + { |
|
2125 | + // grab event id |
|
2126 | + if (! $EVT_ID) { |
|
2127 | + $msg = esc_html__( |
|
2128 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2129 | + 'event_espresso' |
|
2130 | + ); |
|
2131 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2132 | + return false; |
|
2133 | + } |
|
2134 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2135 | + // clean status |
|
2136 | + $event_status = sanitize_key($event_status); |
|
2137 | + // grab status |
|
2138 | + if (empty($event_status)) { |
|
2139 | + $msg = esc_html__( |
|
2140 | + 'An error occurred. No Event Status or an invalid Event Status was received.', |
|
2141 | + 'event_espresso' |
|
2142 | + ); |
|
2143 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2144 | + return false; |
|
2145 | + } |
|
2146 | + // was event trashed or restored ? |
|
2147 | + switch ($event_status) { |
|
2148 | + case 'draft': |
|
2149 | + $action = 'restored from the trash'; |
|
2150 | + $hook = 'AHEE_event_restored_from_trash'; |
|
2151 | + break; |
|
2152 | + case 'trash': |
|
2153 | + $action = 'moved to the trash'; |
|
2154 | + $hook = 'AHEE_event_moved_to_trash'; |
|
2155 | + break; |
|
2156 | + default: |
|
2157 | + $action = 'updated'; |
|
2158 | + $hook = false; |
|
2159 | + } |
|
2160 | + // use class to change status |
|
2161 | + $this->_cpt_model_obj->set_status($event_status); |
|
2162 | + $success = $this->_cpt_model_obj->save(); |
|
2163 | + if ($success === false) { |
|
2164 | + $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action); |
|
2165 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2166 | + return false; |
|
2167 | + } |
|
2168 | + if ($hook) { |
|
2169 | + do_action($hook); |
|
2170 | + } |
|
2171 | + return true; |
|
2172 | + } |
|
2173 | + |
|
2174 | + |
|
2175 | + /** |
|
2176 | + * _delete_event |
|
2177 | + * |
|
2178 | + * @access protected |
|
2179 | + * @param bool $redirect_after |
|
2180 | + * @throws EE_Error |
|
2181 | + * @throws InvalidArgumentException |
|
2182 | + * @throws InvalidDataTypeException |
|
2183 | + * @throws InvalidInterfaceException |
|
2184 | + * @throws ReflectionException |
|
2185 | + */ |
|
2186 | + protected function _delete_event($redirect_after = true) |
|
2187 | + { |
|
2188 | + // determine the event id and set to array. |
|
2189 | + $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null; |
|
2190 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
2191 | + // loop thru events |
|
2192 | + if ($EVT_ID) { |
|
2193 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
2194 | + // get list of events with no prices |
|
2195 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
2196 | + // remove this event from the list of events with no prices |
|
2197 | + if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
2198 | + unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
2199 | + } |
|
2200 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
2201 | + } else { |
|
2202 | + $success = false; |
|
2203 | + $msg = esc_html__( |
|
2204 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
2205 | + 'event_espresso' |
|
2206 | + ); |
|
2207 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2208 | + } |
|
2209 | + if ($redirect_after) { |
|
2210 | + $this->_redirect_after_action( |
|
2211 | + $success, |
|
2212 | + 'Event', |
|
2213 | + 'deleted', |
|
2214 | + array('action' => 'default', 'status' => 'trash') |
|
2215 | + ); |
|
2216 | + } |
|
2217 | + } |
|
2218 | + |
|
2219 | + |
|
2220 | + /** |
|
2221 | + * _delete_events |
|
2222 | + * |
|
2223 | + * @access protected |
|
2224 | + * @return void |
|
2225 | + * @throws EE_Error |
|
2226 | + * @throws InvalidArgumentException |
|
2227 | + * @throws InvalidDataTypeException |
|
2228 | + * @throws InvalidInterfaceException |
|
2229 | + * @throws ReflectionException |
|
2230 | + */ |
|
2231 | + protected function _delete_events() |
|
2232 | + { |
|
2233 | + $success = true; |
|
2234 | + // get list of events with no prices |
|
2235 | + $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
|
2236 | + // determine the event id and set to array. |
|
2237 | + $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
|
2238 | + // loop thru events |
|
2239 | + foreach ($EVT_IDs as $EVT_ID) { |
|
2240 | + $EVT_ID = absint($EVT_ID); |
|
2241 | + if ($EVT_ID) { |
|
2242 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
2243 | + $success = $results !== false ? $success : false; |
|
2244 | + // remove this event from the list of events with no prices |
|
2245 | + unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
2246 | + } else { |
|
2247 | + $success = false; |
|
2248 | + $msg = esc_html__( |
|
2249 | + 'An error occurred. An event could not be deleted because a valid event ID was not not supplied.', |
|
2250 | + 'event_espresso' |
|
2251 | + ); |
|
2252 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2253 | + } |
|
2254 | + } |
|
2255 | + update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
|
2256 | + // in order to force a pluralized result message we need to send back a success status greater than 1 |
|
2257 | + $success = $success ? 2 : false; |
|
2258 | + $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default')); |
|
2259 | + } |
|
2260 | + |
|
2261 | + |
|
2262 | + /** |
|
2263 | + * _permanently_delete_event |
|
2264 | + * |
|
2265 | + * @access private |
|
2266 | + * @param int $EVT_ID |
|
2267 | + * @return bool |
|
2268 | + * @throws EE_Error |
|
2269 | + * @throws InvalidArgumentException |
|
2270 | + * @throws InvalidDataTypeException |
|
2271 | + * @throws InvalidInterfaceException |
|
2272 | + * @throws ReflectionException |
|
2273 | + */ |
|
2274 | + private function _permanently_delete_event($EVT_ID = 0) |
|
2275 | + { |
|
2276 | + // grab event id |
|
2277 | + if (! $EVT_ID) { |
|
2278 | + $msg = esc_html__( |
|
2279 | + 'An error occurred. No Event ID or an invalid Event ID was received.', |
|
2280 | + 'event_espresso' |
|
2281 | + ); |
|
2282 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2283 | + return false; |
|
2284 | + } |
|
2285 | + if (! $this->_cpt_model_obj instanceof EE_Event |
|
2286 | + || $this->_cpt_model_obj->ID() !== $EVT_ID |
|
2287 | + ) { |
|
2288 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
2289 | + } |
|
2290 | + if (! $this->_cpt_model_obj instanceof EE_Event) { |
|
2291 | + return false; |
|
2292 | + } |
|
2293 | + // need to delete related tickets and prices first. |
|
2294 | + $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
|
2295 | + foreach ($datetimes as $datetime) { |
|
2296 | + $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
|
2297 | + $tickets = $datetime->get_many_related('Ticket'); |
|
2298 | + foreach ($tickets as $ticket) { |
|
2299 | + $ticket->_remove_relation_to($datetime, 'Datetime'); |
|
2300 | + $ticket->delete_related_permanently('Price'); |
|
2301 | + $ticket->delete_permanently(); |
|
2302 | + } |
|
2303 | + $datetime->delete(); |
|
2304 | + } |
|
2305 | + // what about related venues or terms? |
|
2306 | + $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
|
2307 | + foreach ($venues as $venue) { |
|
2308 | + $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
|
2309 | + } |
|
2310 | + // any attached question groups? |
|
2311 | + $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
|
2312 | + if (! empty($question_groups)) { |
|
2313 | + foreach ($question_groups as $question_group) { |
|
2314 | + $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
|
2315 | + } |
|
2316 | + } |
|
2317 | + // Message Template Groups |
|
2318 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
2319 | + /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
|
2320 | + $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
|
2321 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
2322 | + $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
|
2323 | + } |
|
2324 | + $success = $this->_cpt_model_obj->delete_permanently(); |
|
2325 | + // did it all go as planned ? |
|
2326 | + if ($success) { |
|
2327 | + $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID); |
|
2328 | + EE_Error::add_success($msg); |
|
2329 | + } else { |
|
2330 | + $msg = sprintf( |
|
2331 | + esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'), |
|
2332 | + $EVT_ID |
|
2333 | + ); |
|
2334 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2335 | + return false; |
|
2336 | + } |
|
2337 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
2338 | + return true; |
|
2339 | + } |
|
2340 | + |
|
2341 | + |
|
2342 | + /** |
|
2343 | + * get total number of events |
|
2344 | + * |
|
2345 | + * @access public |
|
2346 | + * @return int |
|
2347 | + * @throws EE_Error |
|
2348 | + * @throws InvalidArgumentException |
|
2349 | + * @throws InvalidDataTypeException |
|
2350 | + * @throws InvalidInterfaceException |
|
2351 | + */ |
|
2352 | + public function total_events() |
|
2353 | + { |
|
2354 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
2355 | + return $count; |
|
2356 | + } |
|
2357 | + |
|
2358 | + |
|
2359 | + /** |
|
2360 | + * get total number of draft events |
|
2361 | + * |
|
2362 | + * @access public |
|
2363 | + * @return int |
|
2364 | + * @throws EE_Error |
|
2365 | + * @throws InvalidArgumentException |
|
2366 | + * @throws InvalidDataTypeException |
|
2367 | + * @throws InvalidInterfaceException |
|
2368 | + */ |
|
2369 | + public function total_events_draft() |
|
2370 | + { |
|
2371 | + $where = array( |
|
2372 | + 'status' => array('IN', array('draft', 'auto-draft')), |
|
2373 | + ); |
|
2374 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2375 | + return $count; |
|
2376 | + } |
|
2377 | + |
|
2378 | + |
|
2379 | + /** |
|
2380 | + * get total number of trashed events |
|
2381 | + * |
|
2382 | + * @access public |
|
2383 | + * @return int |
|
2384 | + * @throws EE_Error |
|
2385 | + * @throws InvalidArgumentException |
|
2386 | + * @throws InvalidDataTypeException |
|
2387 | + * @throws InvalidInterfaceException |
|
2388 | + */ |
|
2389 | + public function total_trashed_events() |
|
2390 | + { |
|
2391 | + $where = array( |
|
2392 | + 'status' => 'trash', |
|
2393 | + ); |
|
2394 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2395 | + return $count; |
|
2396 | + } |
|
2397 | + |
|
2398 | + |
|
2399 | + /** |
|
2400 | + * _default_event_settings |
|
2401 | + * This generates the Default Settings Tab |
|
2402 | + * |
|
2403 | + * @return void |
|
2404 | + * @throws DomainException |
|
2405 | + * @throws EE_Error |
|
2406 | + * @throws InvalidArgumentException |
|
2407 | + * @throws InvalidDataTypeException |
|
2408 | + * @throws InvalidInterfaceException |
|
2409 | + */ |
|
2410 | + protected function _default_event_settings() |
|
2411 | + { |
|
2412 | + $this->_set_add_edit_form_tags('update_default_event_settings'); |
|
2413 | + $this->_set_publish_post_box_vars(null, false, false, null, false); |
|
2414 | + $this->_template_args['admin_page_content'] = $this->_default_event_settings_form()->get_html(); |
|
2415 | + $this->display_admin_page_with_sidebar(); |
|
2416 | + } |
|
2417 | + |
|
2418 | + |
|
2419 | + /** |
|
2420 | + * Return the form for event settings. |
|
2421 | + * |
|
2422 | + * @return EE_Form_Section_Proper |
|
2423 | + * @throws EE_Error |
|
2424 | + */ |
|
2425 | + protected function _default_event_settings_form() |
|
2426 | + { |
|
2427 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2428 | + $registration_stati_for_selection = EEM_Registration::reg_status_array( |
|
2429 | + // exclude |
|
2430 | + array( |
|
2431 | + EEM_Registration::status_id_cancelled, |
|
2432 | + EEM_Registration::status_id_declined, |
|
2433 | + EEM_Registration::status_id_incomplete, |
|
2434 | + EEM_Registration::status_id_wait_list, |
|
2435 | + ), |
|
2436 | + true |
|
2437 | + ); |
|
2438 | + return new EE_Form_Section_Proper( |
|
2439 | + array( |
|
2440 | + 'name' => 'update_default_event_settings', |
|
2441 | + 'html_id' => 'update_default_event_settings', |
|
2442 | + 'html_class' => 'form-table', |
|
2443 | + 'layout_strategy' => new EE_Admin_Two_Column_Layout(), |
|
2444 | + 'subsections' => apply_filters( |
|
2445 | + 'FHEE__Events_Admin_Page___default_event_settings_form__form_subsections', |
|
2446 | + array( |
|
2447 | + 'default_reg_status' => new EE_Select_Input( |
|
2448 | + $registration_stati_for_selection, |
|
2449 | + array( |
|
2450 | + 'default' => isset($registration_config->default_STS_ID) |
|
2451 | + && array_key_exists( |
|
2452 | + $registration_config->default_STS_ID, |
|
2453 | + $registration_stati_for_selection |
|
2454 | + ) |
|
2455 | + ? sanitize_text_field($registration_config->default_STS_ID) |
|
2456 | + : EEM_Registration::status_id_pending_payment, |
|
2457 | + 'html_label_text' => esc_html__('Default Registration Status', 'event_espresso') |
|
2458 | + . EEH_Template::get_help_tab_link( |
|
2459 | + 'default_settings_status_help_tab' |
|
2460 | + ), |
|
2461 | + 'html_help_text' => esc_html__( |
|
2462 | + 'This setting allows you to preselect what the default registration status setting is when creating an event. Note that changing this setting does NOT retroactively apply it to existing events.', |
|
2463 | + 'event_espresso' |
|
2464 | + ), |
|
2465 | + ) |
|
2466 | + ), |
|
2467 | + 'default_max_tickets' => new EE_Integer_Input( |
|
2468 | + array( |
|
2469 | + 'default' => isset($registration_config->default_maximum_number_of_tickets) |
|
2470 | + ? $registration_config->default_maximum_number_of_tickets |
|
2471 | + : EEM_Event::get_default_additional_limit(), |
|
2472 | + 'html_label_text' => esc_html__( |
|
2473 | + 'Default Maximum Tickets Allowed Per Order:', |
|
2474 | + 'event_espresso' |
|
2475 | + ) |
|
2476 | + . EEH_Template::get_help_tab_link( |
|
2477 | + 'default_maximum_tickets_help_tab"' |
|
2478 | + ), |
|
2479 | + 'html_help_text' => esc_html__( |
|
2480 | + 'This setting allows you to indicate what will be the default for the maximum number of tickets per order when creating new events.', |
|
2481 | + 'event_espresso' |
|
2482 | + ), |
|
2483 | + ) |
|
2484 | + ), |
|
2485 | + ) |
|
2486 | + ), |
|
2487 | + ) |
|
2488 | + ); |
|
2489 | + } |
|
2490 | + |
|
2491 | + |
|
2492 | + /** |
|
2493 | + * @return void |
|
2494 | + * @throws EE_Error |
|
2495 | + * @throws InvalidArgumentException |
|
2496 | + * @throws InvalidDataTypeException |
|
2497 | + * @throws InvalidInterfaceException |
|
2498 | + */ |
|
2499 | + protected function _update_default_event_settings() |
|
2500 | + { |
|
2501 | + $form = $this->_default_event_settings_form(); |
|
2502 | + if ($form->was_submitted()) { |
|
2503 | + $form->receive_form_submission(); |
|
2504 | + if ($form->is_valid()) { |
|
2505 | + $registration_config = EE_Registry::instance()->CFG->registration; |
|
2506 | + $valid_data = $form->valid_data(); |
|
2507 | + if (isset($valid_data['default_reg_status'])) { |
|
2508 | + $registration_config->default_STS_ID = $valid_data['default_reg_status']; |
|
2509 | + } |
|
2510 | + if (isset($valid_data['default_max_tickets'])) { |
|
2511 | + $registration_config->default_maximum_number_of_tickets = $valid_data['default_max_tickets']; |
|
2512 | + } |
|
2513 | + do_action( |
|
2514 | + 'AHEE__Events_Admin_Page___update_default_event_settings', |
|
2515 | + $valid_data, |
|
2516 | + EE_Registry::instance()->CFG, |
|
2517 | + $this |
|
2518 | + ); |
|
2519 | + // update because data was valid! |
|
2520 | + EE_Registry::instance()->CFG->update_espresso_config(); |
|
2521 | + EE_Error::overwrite_success(); |
|
2522 | + EE_Error::add_success( |
|
2523 | + __('Default Event Settings were updated', 'event_espresso') |
|
2524 | + ); |
|
2525 | + } |
|
2526 | + } |
|
2527 | + $this->_redirect_after_action(0, '', '', array('action' => 'default_event_settings'), true); |
|
2528 | + } |
|
2529 | + |
|
2530 | + |
|
2531 | + /************* Templates *************/ |
|
2532 | + protected function _template_settings() |
|
2533 | + { |
|
2534 | + $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso'); |
|
2535 | + $this->_template_args['preview_img'] = '<img src="' |
|
2536 | + . EVENTS_ASSETS_URL |
|
2537 | + . '/images/' |
|
2538 | + . 'caffeinated_template_features.jpg" alt="' |
|
2539 | + . esc_attr__('Template Settings Preview screenshot', 'event_espresso') |
|
2540 | + . '" />'; |
|
2541 | + $this->_template_args['preview_text'] = '<strong>' |
|
2542 | + . esc_html__( |
|
2543 | + 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
|
2544 | + 'event_espresso' |
|
2545 | + ) . '</strong>'; |
|
2546 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2547 | + } |
|
2548 | + |
|
2549 | + |
|
2550 | + /** Event Category Stuff **/ |
|
2551 | + /** |
|
2552 | + * set the _category property with the category object for the loaded page. |
|
2553 | + * |
|
2554 | + * @access private |
|
2555 | + * @return void |
|
2556 | + */ |
|
2557 | + private function _set_category_object() |
|
2558 | + { |
|
2559 | + if (isset($this->_category->id) && ! empty($this->_category->id)) { |
|
2560 | + return; |
|
2561 | + } //already have the category object so get out. |
|
2562 | + // set default category object |
|
2563 | + $this->_set_empty_category_object(); |
|
2564 | + // only set if we've got an id |
|
2565 | + if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2566 | + return; |
|
2567 | + } |
|
2568 | + $category_id = absint($this->_req_data['EVT_CAT_ID']); |
|
2569 | + $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2570 | + if (! empty($term)) { |
|
2571 | + $this->_category->category_name = $term->name; |
|
2572 | + $this->_category->category_identifier = $term->slug; |
|
2573 | + $this->_category->category_desc = $term->description; |
|
2574 | + $this->_category->id = $term->term_id; |
|
2575 | + $this->_category->parent = $term->parent; |
|
2576 | + } |
|
2577 | + } |
|
2578 | + |
|
2579 | + |
|
2580 | + /** |
|
2581 | + * Clears out category properties. |
|
2582 | + */ |
|
2583 | + private function _set_empty_category_object() |
|
2584 | + { |
|
2585 | + $this->_category = new stdClass(); |
|
2586 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2587 | + $this->_category->id = $this->_category->parent = 0; |
|
2588 | + } |
|
2589 | + |
|
2590 | + |
|
2591 | + /** |
|
2592 | + * @throws DomainException |
|
2593 | + * @throws EE_Error |
|
2594 | + * @throws InvalidArgumentException |
|
2595 | + * @throws InvalidDataTypeException |
|
2596 | + * @throws InvalidInterfaceException |
|
2597 | + */ |
|
2598 | + protected function _category_list_table() |
|
2599 | + { |
|
2600 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2601 | + $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
|
2602 | + $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2603 | + 'add_category', |
|
2604 | + 'add_category', |
|
2605 | + array(), |
|
2606 | + 'add-new-h2' |
|
2607 | + ); |
|
2608 | + $this->display_admin_list_table_page_with_sidebar(); |
|
2609 | + } |
|
2610 | + |
|
2611 | + |
|
2612 | + /** |
|
2613 | + * Output category details view. |
|
2614 | + * |
|
2615 | + * @param string $view |
|
2616 | + * @throws DomainException |
|
2617 | + * @throws EE_Error |
|
2618 | + * @throws InvalidArgumentException |
|
2619 | + * @throws InvalidDataTypeException |
|
2620 | + * @throws InvalidInterfaceException |
|
2621 | + */ |
|
2622 | + protected function _category_details($view) |
|
2623 | + { |
|
2624 | + // load formatter helper |
|
2625 | + // load field generator helper |
|
2626 | + $route = $view === 'edit' ? 'update_category' : 'insert_category'; |
|
2627 | + $this->_set_add_edit_form_tags($route); |
|
2628 | + $this->_set_category_object(); |
|
2629 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2630 | + $delete_action = 'delete_category'; |
|
2631 | + // custom redirect |
|
2632 | + $redirect = EE_Admin_Page::add_query_args_and_nonce( |
|
2633 | + array('action' => 'category_list'), |
|
2634 | + $this->_admin_base_url |
|
2635 | + ); |
|
2636 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2637 | + // take care of contents |
|
2638 | + $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
|
2639 | + $this->display_admin_page_with_sidebar(); |
|
2640 | + } |
|
2641 | + |
|
2642 | + |
|
2643 | + /** |
|
2644 | + * Output category details content. |
|
2645 | + * |
|
2646 | + * @throws DomainException |
|
2647 | + */ |
|
2648 | + protected function _category_details_content() |
|
2649 | + { |
|
2650 | + $editor_args['category_desc'] = array( |
|
2651 | + 'type' => 'wp_editor', |
|
2652 | + 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
|
2653 | + 'class' => 'my_editor_custom', |
|
2654 | + 'wpeditor_args' => array('media_buttons' => false), |
|
2655 | + ); |
|
2656 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2657 | + $all_terms = get_terms( |
|
2658 | + array(EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY), |
|
2659 | + array('hide_empty' => 0, 'exclude' => array($this->_category->id)) |
|
2660 | + ); |
|
2661 | + // setup category select for term parents. |
|
2662 | + $category_select_values[] = array( |
|
2663 | + 'text' => esc_html__('No Parent', 'event_espresso'), |
|
2664 | + 'id' => 0, |
|
2665 | + ); |
|
2666 | + foreach ($all_terms as $term) { |
|
2667 | + $category_select_values[] = array( |
|
2668 | + 'text' => $term->name, |
|
2669 | + 'id' => $term->term_id, |
|
2670 | + ); |
|
2671 | + } |
|
2672 | + $category_select = EEH_Form_Fields::select_input( |
|
2673 | + 'category_parent', |
|
2674 | + $category_select_values, |
|
2675 | + $this->_category->parent |
|
2676 | + ); |
|
2677 | + $template_args = array( |
|
2678 | + 'category' => $this->_category, |
|
2679 | + 'category_select' => $category_select, |
|
2680 | + 'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'), |
|
2681 | + 'category_desc_editor' => $_wp_editor['category_desc']['field'], |
|
2682 | + 'disable' => '', |
|
2683 | + 'disabled_message' => false, |
|
2684 | + ); |
|
2685 | + $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2686 | + return EEH_Template::display_template($template, $template_args, true); |
|
2687 | + } |
|
2688 | + |
|
2689 | + |
|
2690 | + /** |
|
2691 | + * Handles deleting categories. |
|
2692 | + */ |
|
2693 | + protected function _delete_categories() |
|
2694 | + { |
|
2695 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] |
|
2696 | + : (array) $this->_req_data['category_id']; |
|
2697 | + foreach ($cat_ids as $cat_id) { |
|
2698 | + $this->_delete_category($cat_id); |
|
2699 | + } |
|
2700 | + // doesn't matter what page we're coming from... we're going to the same place after delete. |
|
2701 | + $query_args = array( |
|
2702 | + 'action' => 'category_list', |
|
2703 | + ); |
|
2704 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
2705 | + } |
|
2706 | + |
|
2707 | + |
|
2708 | + /** |
|
2709 | + * Handles deleting specific category. |
|
2710 | + * |
|
2711 | + * @param int $cat_id |
|
2712 | + */ |
|
2713 | + protected function _delete_category($cat_id) |
|
2714 | + { |
|
2715 | + $cat_id = absint($cat_id); |
|
2716 | + wp_delete_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2717 | + } |
|
2718 | + |
|
2719 | + |
|
2720 | + /** |
|
2721 | + * Handles triggering the update or insertion of a new category. |
|
2722 | + * |
|
2723 | + * @param bool $new_category true means we're triggering the insert of a new category. |
|
2724 | + * @throws EE_Error |
|
2725 | + * @throws InvalidArgumentException |
|
2726 | + * @throws InvalidDataTypeException |
|
2727 | + * @throws InvalidInterfaceException |
|
2728 | + */ |
|
2729 | + protected function _insert_or_update_category($new_category) |
|
2730 | + { |
|
2731 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true); |
|
2732 | + $success = 0; // we already have a success message so lets not send another. |
|
2733 | + if ($cat_id) { |
|
2734 | + $query_args = array( |
|
2735 | + 'action' => 'edit_category', |
|
2736 | + 'EVT_CAT_ID' => $cat_id, |
|
2737 | + ); |
|
2738 | + } else { |
|
2739 | + $query_args = array('action' => 'add_category'); |
|
2740 | + } |
|
2741 | + $this->_redirect_after_action($success, '', '', $query_args, true); |
|
2742 | + } |
|
2743 | + |
|
2744 | + |
|
2745 | + /** |
|
2746 | + * Inserts or updates category |
|
2747 | + * |
|
2748 | + * @param bool $update (true indicates we're updating a category). |
|
2749 | + * @return bool|mixed|string |
|
2750 | + */ |
|
2751 | + private function _insert_category($update = false) |
|
2752 | + { |
|
2753 | + $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
|
2754 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
2755 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
2756 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
2757 | + if (empty($category_name)) { |
|
2758 | + $msg = esc_html__('You must add a name for the category.', 'event_espresso'); |
|
2759 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2760 | + return false; |
|
2761 | + } |
|
2762 | + $term_args = array( |
|
2763 | + 'name' => $category_name, |
|
2764 | + 'description' => $category_desc, |
|
2765 | + 'parent' => $category_parent, |
|
2766 | + ); |
|
2767 | + // was the category_identifier input disabled? |
|
2768 | + if (isset($this->_req_data['category_identifier'])) { |
|
2769 | + $term_args['slug'] = $this->_req_data['category_identifier']; |
|
2770 | + } |
|
2771 | + $insert_ids = $update |
|
2772 | + ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
|
2773 | + : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
|
2774 | + if (! is_array($insert_ids)) { |
|
2775 | + $msg = esc_html__( |
|
2776 | + 'An error occurred and the category has not been saved to the database.', |
|
2777 | + 'event_espresso' |
|
2778 | + ); |
|
2779 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2780 | + } else { |
|
2781 | + $cat_id = $insert_ids['term_id']; |
|
2782 | + $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name); |
|
2783 | + EE_Error::add_success($msg); |
|
2784 | + } |
|
2785 | + return $cat_id; |
|
2786 | + } |
|
2787 | + |
|
2788 | + |
|
2789 | + /** |
|
2790 | + * Gets categories or count of categories matching the arguments in the request. |
|
2791 | + * |
|
2792 | + * @param int $per_page |
|
2793 | + * @param int $current_page |
|
2794 | + * @param bool $count |
|
2795 | + * @return EE_Base_Class[]|EE_Term_Taxonomy[]|int |
|
2796 | + * @throws EE_Error |
|
2797 | + * @throws InvalidArgumentException |
|
2798 | + * @throws InvalidDataTypeException |
|
2799 | + * @throws InvalidInterfaceException |
|
2800 | + */ |
|
2801 | + public function get_categories($per_page = 10, $current_page = 1, $count = false) |
|
2802 | + { |
|
2803 | + // testing term stuff |
|
2804 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2805 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2806 | + $limit = ($current_page - 1) * $per_page; |
|
2807 | + $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
|
2808 | + if (isset($this->_req_data['s'])) { |
|
2809 | + $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2810 | + $where['OR'] = array( |
|
2811 | + 'Term.name' => array('LIKE', $sstr), |
|
2812 | + 'description' => array('LIKE', $sstr), |
|
2813 | + ); |
|
2814 | + } |
|
2815 | + $query_params = array( |
|
2816 | + $where, |
|
2817 | + 'order_by' => array($orderby => $order), |
|
2818 | + 'limit' => $limit . ',' . $per_page, |
|
2819 | + 'force_join' => array('Term'), |
|
2820 | + ); |
|
2821 | + $categories = $count |
|
2822 | + ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') |
|
2823 | + : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2824 | + return $categories; |
|
2825 | + } |
|
2826 | + |
|
2827 | + /* end category stuff */ |
|
2828 | + /**************/ |
|
2829 | + |
|
2830 | + |
|
2831 | + /** |
|
2832 | + * Callback for the `ee_save_timezone_setting` ajax action. |
|
2833 | + * |
|
2834 | + * @throws EE_Error |
|
2835 | + * @throws InvalidArgumentException |
|
2836 | + * @throws InvalidDataTypeException |
|
2837 | + * @throws InvalidInterfaceException |
|
2838 | + */ |
|
2839 | + public function save_timezonestring_setting() |
|
2840 | + { |
|
2841 | + $timezone_string = isset($this->_req_data['timezone_selected']) |
|
2842 | + ? $this->_req_data['timezone_selected'] |
|
2843 | + : ''; |
|
2844 | + if (empty($timezone_string) || ! EEH_DTT_Helper::validate_timezone($timezone_string, false)) { |
|
2845 | + EE_Error::add_error( |
|
2846 | + esc_html__('An invalid timezone string submitted.', 'event_espresso'), |
|
2847 | + __FILE__, |
|
2848 | + __FUNCTION__, |
|
2849 | + __LINE__ |
|
2850 | + ); |
|
2851 | + $this->_template_args['error'] = true; |
|
2852 | + $this->_return_json(); |
|
2853 | + } |
|
2854 | + |
|
2855 | + update_option('timezone_string', $timezone_string); |
|
2856 | + EE_Error::add_success( |
|
2857 | + esc_html__('Your timezone string was updated.', 'event_espresso') |
|
2858 | + ); |
|
2859 | + $this->_template_args['success'] = true; |
|
2860 | + $this->_return_json(true, array('action' => 'create_new')); |
|
2861 | + } |
|
2862 | 2862 | } |
@@ -559,11 +559,11 @@ discard block |
||
559 | 559 | { |
560 | 560 | wp_register_style( |
561 | 561 | 'events-admin-css', |
562 | - EVENTS_ASSETS_URL . 'events-admin-page.css', |
|
562 | + EVENTS_ASSETS_URL.'events-admin-page.css', |
|
563 | 563 | array(), |
564 | 564 | EVENT_ESPRESSO_VERSION |
565 | 565 | ); |
566 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
566 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
567 | 567 | wp_enqueue_style('events-admin-css'); |
568 | 568 | wp_enqueue_style('ee-cat-admin'); |
569 | 569 | // todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
@@ -571,7 +571,7 @@ discard block |
||
571 | 571 | // scripts |
572 | 572 | wp_register_script( |
573 | 573 | 'event_editor_js', |
574 | - EVENTS_ASSETS_URL . 'event_editor.js', |
|
574 | + EVENTS_ASSETS_URL.'event_editor.js', |
|
575 | 575 | array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), |
576 | 576 | EVENT_ESPRESSO_VERSION, |
577 | 577 | true |
@@ -597,7 +597,7 @@ discard block |
||
597 | 597 | wp_enqueue_style('espresso-ui-theme'); |
598 | 598 | wp_register_style( |
599 | 599 | 'event-editor-css', |
600 | - EVENTS_ASSETS_URL . 'event-editor.css', |
|
600 | + EVENTS_ASSETS_URL.'event-editor.css', |
|
601 | 601 | array('ee-admin-css'), |
602 | 602 | EVENT_ESPRESSO_VERSION |
603 | 603 | ); |
@@ -605,7 +605,7 @@ discard block |
||
605 | 605 | // scripts |
606 | 606 | wp_register_script( |
607 | 607 | 'event-datetime-metabox', |
608 | - EVENTS_ASSETS_URL . 'event-datetime-metabox.js', |
|
608 | + EVENTS_ASSETS_URL.'event-datetime-metabox.js', |
|
609 | 609 | array('event_editor_js', 'ee-datepicker'), |
610 | 610 | EVENT_ESPRESSO_VERSION |
611 | 611 | ); |
@@ -674,15 +674,15 @@ discard block |
||
674 | 674 | public function verify_event_edit($event = null, $req_type = '') |
675 | 675 | { |
676 | 676 | // don't need to do this when processing |
677 | - if (! empty($req_type)) { |
|
677 | + if ( ! empty($req_type)) { |
|
678 | 678 | return; |
679 | 679 | } |
680 | 680 | // no event? |
681 | - if (! $event instanceof EE_Event) { |
|
681 | + if ( ! $event instanceof EE_Event) { |
|
682 | 682 | $event = $this->_cpt_model_obj; |
683 | 683 | } |
684 | 684 | // STILL no event? |
685 | - if (! $event instanceof EE_Event) { |
|
685 | + if ( ! $event instanceof EE_Event) { |
|
686 | 686 | return; |
687 | 687 | } |
688 | 688 | $orig_status = $event->status(); |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | ); |
722 | 722 | } |
723 | 723 | // now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
724 | - if (! $event->tickets_on_sale()) { |
|
724 | + if ( ! $event->tickets_on_sale()) { |
|
725 | 725 | return; |
726 | 726 | } |
727 | 727 | // made it here so show warning |
@@ -769,7 +769,7 @@ discard block |
||
769 | 769 | { |
770 | 770 | $has_timezone_string = get_option('timezone_string'); |
771 | 771 | // only nag them about setting their timezone if it's their first event, and they haven't already done it |
772 | - if (! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
772 | + if ( ! $has_timezone_string && ! EEM_Event::instance()->exists(array())) { |
|
773 | 773 | EE_Error::add_attention( |
774 | 774 | sprintf( |
775 | 775 | __( |
@@ -853,31 +853,31 @@ discard block |
||
853 | 853 | $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
854 | 854 | $statuses = array( |
855 | 855 | 'sold_out_status' => array( |
856 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
856 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
857 | 857 | 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'), |
858 | 858 | ), |
859 | 859 | 'active_status' => array( |
860 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
860 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
861 | 861 | 'desc' => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'), |
862 | 862 | ), |
863 | 863 | 'upcoming_status' => array( |
864 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
864 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
865 | 865 | 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'), |
866 | 866 | ), |
867 | 867 | 'postponed_status' => array( |
868 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
868 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
869 | 869 | 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'), |
870 | 870 | ), |
871 | 871 | 'cancelled_status' => array( |
872 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
872 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
873 | 873 | 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'), |
874 | 874 | ), |
875 | 875 | 'expired_status' => array( |
876 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
876 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
877 | 877 | 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'), |
878 | 878 | ), |
879 | 879 | 'inactive_status' => array( |
880 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
880 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
881 | 881 | 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'), |
882 | 882 | ), |
883 | 883 | ); |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | */ |
897 | 897 | private function _event_model() |
898 | 898 | { |
899 | - if (! $this->_event_model instanceof EEM_Event) { |
|
899 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
900 | 900 | $this->_event_model = EE_Registry::instance()->load_model('Event'); |
901 | 901 | } |
902 | 902 | return $this->_event_model; |
@@ -916,7 +916,7 @@ discard block |
||
916 | 916 | public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) |
917 | 917 | { |
918 | 918 | // make sure this is only when editing |
919 | - if (! empty($id)) { |
|
919 | + if ( ! empty($id)) { |
|
920 | 920 | $post = get_post($id); |
921 | 921 | $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' |
922 | 922 | . esc_html__('Shortcode', 'event_espresso') |
@@ -954,7 +954,7 @@ discard block |
||
954 | 954 | 'button' |
955 | 955 | ); |
956 | 956 | $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items()); |
957 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
957 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
958 | 958 | 'create_new', |
959 | 959 | 'add', |
960 | 960 | array(), |
@@ -1114,7 +1114,7 @@ discard block |
||
1114 | 1114 | */ |
1115 | 1115 | protected function _default_venue_update(EE_Event $evtobj, $data) |
1116 | 1116 | { |
1117 | - require_once(EE_MODELS . 'EEM_Venue.model.php'); |
|
1117 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
1118 | 1118 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
1119 | 1119 | $rows_affected = null; |
1120 | 1120 | $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null; |
@@ -1145,7 +1145,7 @@ discard block |
||
1145 | 1145 | 'status' => 'publish', |
1146 | 1146 | ); |
1147 | 1147 | // if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
1148 | - if (! empty($venue_id)) { |
|
1148 | + if ( ! empty($venue_id)) { |
|
1149 | 1149 | $update_where = array($venue_model->primary_key_name() => $venue_id); |
1150 | 1150 | $rows_affected = $venue_model->update($venue_array, array($update_where)); |
1151 | 1151 | // we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
@@ -1192,7 +1192,7 @@ discard block |
||
1192 | 1192 | 'DTT_order' => $row, |
1193 | 1193 | ); |
1194 | 1194 | // if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
1195 | - if (! empty($dtt['DTT_ID'])) { |
|
1195 | + if ( ! empty($dtt['DTT_ID'])) { |
|
1196 | 1196 | $DTM = EE_Registry::instance() |
1197 | 1197 | ->load_model('Datetime', array($evtobj->get_timezone())) |
1198 | 1198 | ->get_one_by_ID($dtt['DTT_ID']); |
@@ -1202,7 +1202,7 @@ discard block |
||
1202 | 1202 | $DTM->set($field, $value); |
1203 | 1203 | } |
1204 | 1204 | // make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
1205 | - $saved_dtts[ $DTM->ID() ] = $DTM; |
|
1205 | + $saved_dtts[$DTM->ID()] = $DTM; |
|
1206 | 1206 | } else { |
1207 | 1207 | $DTM = EE_Registry::instance()->load_class( |
1208 | 1208 | 'Datetime', |
@@ -1235,14 +1235,14 @@ discard block |
||
1235 | 1235 | foreach ($data['edit_tickets'] as $row => $tkt) { |
1236 | 1236 | $incoming_date_formats = array('Y-m-d', 'h:i a'); |
1237 | 1237 | $update_prices = false; |
1238 | - $ticket_price = isset($data['edit_prices'][ $row ][1]['PRC_amount']) |
|
1239 | - ? $data['edit_prices'][ $row ][1]['PRC_amount'] : 0; |
|
1238 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) |
|
1239 | + ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
1240 | 1240 | // trim inputs to ensure any excess whitespace is removed. |
1241 | 1241 | $tkt = array_map('trim', $tkt); |
1242 | 1242 | if (empty($tkt['TKT_start_date'])) { |
1243 | 1243 | // let's use now in the set timezone. |
1244 | 1244 | $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
1245 | - $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]); |
|
1245 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
1246 | 1246 | } |
1247 | 1247 | if (empty($tkt['TKT_end_date'])) { |
1248 | 1248 | // use the start date of the first datetime |
@@ -1277,7 +1277,7 @@ discard block |
||
1277 | 1277 | // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
1278 | 1278 | // we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
1279 | 1279 | // keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
1280 | - if (! empty($tkt['TKT_ID'])) { |
|
1280 | + if ( ! empty($tkt['TKT_ID'])) { |
|
1281 | 1281 | $TKT = EE_Registry::instance() |
1282 | 1282 | ->load_model('Ticket', array($evtobj->get_timezone())) |
1283 | 1283 | ->get_one_by_ID($tkt['TKT_ID']); |
@@ -1317,7 +1317,7 @@ discard block |
||
1317 | 1317 | $TKT->set('TKT_deleted', 1); |
1318 | 1318 | $TKT->save(); |
1319 | 1319 | // make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
1320 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1320 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
1321 | 1321 | // create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
1322 | 1322 | $TKT = clone $TKT; |
1323 | 1323 | $TKT->set('TKT_ID', 0); |
@@ -1362,9 +1362,9 @@ discard block |
||
1362 | 1362 | } |
1363 | 1363 | // initially let's add the ticket to the dtt |
1364 | 1364 | $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
1365 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1365 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
1366 | 1366 | // add prices to ticket |
1367 | - $this->_add_prices_to_ticket($data['edit_prices'][ $row ], $TKT, $update_prices); |
|
1367 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
1368 | 1368 | } |
1369 | 1369 | // however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
1370 | 1370 | $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
@@ -1532,7 +1532,7 @@ discard block |
||
1532 | 1532 | $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
1533 | 1533 | // load template |
1534 | 1534 | EEH_Template::display_template( |
1535 | - EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', |
|
1535 | + EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', |
|
1536 | 1536 | $publish_box_extra_args |
1537 | 1537 | ); |
1538 | 1538 | } |
@@ -1632,7 +1632,7 @@ discard block |
||
1632 | 1632 | 'default_where_conditions' => 'none', |
1633 | 1633 | ) |
1634 | 1634 | ); |
1635 | - if (! empty($related_tickets)) { |
|
1635 | + if ( ! empty($related_tickets)) { |
|
1636 | 1636 | $template_args['total_ticket_rows'] = count($related_tickets); |
1637 | 1637 | $row = 0; |
1638 | 1638 | foreach ($related_tickets as $ticket) { |
@@ -1666,7 +1666,7 @@ discard block |
||
1666 | 1666 | ); |
1667 | 1667 | $template = apply_filters( |
1668 | 1668 | 'FHEE__Events_Admin_Page__ticket_metabox__template', |
1669 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' |
|
1669 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php' |
|
1670 | 1670 | ); |
1671 | 1671 | EEH_Template::display_template($template, $template_args); |
1672 | 1672 | } |
@@ -1690,7 +1690,7 @@ discard block |
||
1690 | 1690 | private function _get_ticket_row($ticket, $skeleton = false, $row = 0) |
1691 | 1691 | { |
1692 | 1692 | $template_args = array( |
1693 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1693 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
1694 | 1694 | 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' |
1695 | 1695 | : '', |
1696 | 1696 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
@@ -1702,10 +1702,10 @@ discard block |
||
1702 | 1702 | 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
1703 | 1703 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
1704 | 1704 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
1705 | - 'trash_icon' => ($skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1706 | - && (! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1705 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) |
|
1706 | + && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) |
|
1707 | 1707 | ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
1708 | - 'disabled' => $skeleton || (! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1708 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' |
|
1709 | 1709 | : ' disabled=disabled', |
1710 | 1710 | ); |
1711 | 1711 | $price = $ticket->ID() !== 0 |
@@ -1732,7 +1732,7 @@ discard block |
||
1732 | 1732 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
1733 | 1733 | ) |
1734 | 1734 | : null; |
1735 | - if (! empty($earliest_dtt)) { |
|
1735 | + if ( ! empty($earliest_dtt)) { |
|
1736 | 1736 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
1737 | 1737 | } else { |
1738 | 1738 | $template_args['TKT_end_date'] = date( |
@@ -1744,7 +1744,7 @@ discard block |
||
1744 | 1744 | $template_args = array_merge($template_args, $price_args); |
1745 | 1745 | $template = apply_filters( |
1746 | 1746 | 'FHEE__Events_Admin_Page__get_ticket_row__template', |
1747 | - EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', |
|
1747 | + EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', |
|
1748 | 1748 | $ticket |
1749 | 1749 | ); |
1750 | 1750 | return EEH_Template::display_template($template, $template_args, true); |
@@ -1799,7 +1799,7 @@ discard block |
||
1799 | 1799 | $default_reg_status_values |
1800 | 1800 | ); |
1801 | 1801 | EEH_Template::display_template( |
1802 | - EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php', |
|
1802 | + EVENTS_TEMPLATE_PATH.'event_registration_options.template.php', |
|
1803 | 1803 | $template_args |
1804 | 1804 | ); |
1805 | 1805 | } |
@@ -1829,7 +1829,7 @@ discard block |
||
1829 | 1829 | { |
1830 | 1830 | $EEME = $this->_event_model(); |
1831 | 1831 | $offset = ($current_page - 1) * $per_page; |
1832 | - $limit = $count ? null : $offset . ',' . $per_page; |
|
1832 | + $limit = $count ? null : $offset.','.$per_page; |
|
1833 | 1833 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
1834 | 1834 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
1835 | 1835 | if (isset($this->_req_data['month_range'])) { |
@@ -1858,7 +1858,7 @@ discard block |
||
1858 | 1858 | // categories? |
1859 | 1859 | $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 |
1860 | 1860 | ? $this->_req_data['EVT_CAT'] : null; |
1861 | - if (! empty($category)) { |
|
1861 | + if ( ! empty($category)) { |
|
1862 | 1862 | $where['Term_Taxonomy.taxonomy'] = EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY; |
1863 | 1863 | $where['Term_Taxonomy.term_id'] = $category; |
1864 | 1864 | } |
@@ -1866,7 +1866,7 @@ discard block |
||
1866 | 1866 | $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
1867 | 1867 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] !== '') { |
1868 | 1868 | $DateTime = new DateTime( |
1869 | - $year_r . '-' . $month_r . '-01 00:00:00', |
|
1869 | + $year_r.'-'.$month_r.'-01 00:00:00', |
|
1870 | 1870 | new DateTimeZone('UTC') |
1871 | 1871 | ); |
1872 | 1872 | $start = $DateTime->getTimestamp(); |
@@ -1892,9 +1892,9 @@ discard block |
||
1892 | 1892 | ->format(implode(' ', $start_formats)); |
1893 | 1893 | $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
1894 | 1894 | } |
1895 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1895 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1896 | 1896 | $where['EVT_wp_user'] = get_current_user_id(); |
1897 | - } elseif (! isset($where['status']) |
|
1897 | + } elseif ( ! isset($where['status']) |
|
1898 | 1898 | && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events') |
1899 | 1899 | ) { |
1900 | 1900 | $where['OR'] = array( |
@@ -1914,7 +1914,7 @@ discard block |
||
1914 | 1914 | } |
1915 | 1915 | // search query handling |
1916 | 1916 | if (isset($this->_req_data['s'])) { |
1917 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1917 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
1918 | 1918 | $where['OR'] = array( |
1919 | 1919 | 'EVT_name' => array('LIKE', $search_string), |
1920 | 1920 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -2029,7 +2029,7 @@ discard block |
||
2029 | 2029 | // clean status |
2030 | 2030 | $event_status = sanitize_key($event_status); |
2031 | 2031 | // grab status |
2032 | - if (! empty($event_status)) { |
|
2032 | + if ( ! empty($event_status)) { |
|
2033 | 2033 | $success = $this->_change_event_status($EVT_ID, $event_status); |
2034 | 2034 | } else { |
2035 | 2035 | $success = false; |
@@ -2071,7 +2071,7 @@ discard block |
||
2071 | 2071 | // clean status |
2072 | 2072 | $event_status = sanitize_key($event_status); |
2073 | 2073 | // grab status |
2074 | - if (! empty($event_status)) { |
|
2074 | + if ( ! empty($event_status)) { |
|
2075 | 2075 | $success = true; |
2076 | 2076 | // determine the event id and set to array. |
2077 | 2077 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
@@ -2123,7 +2123,7 @@ discard block |
||
2123 | 2123 | private function _change_event_status($EVT_ID = 0, $event_status = '') |
2124 | 2124 | { |
2125 | 2125 | // grab event id |
2126 | - if (! $EVT_ID) { |
|
2126 | + if ( ! $EVT_ID) { |
|
2127 | 2127 | $msg = esc_html__( |
2128 | 2128 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
2129 | 2129 | 'event_espresso' |
@@ -2194,8 +2194,8 @@ discard block |
||
2194 | 2194 | // get list of events with no prices |
2195 | 2195 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
2196 | 2196 | // remove this event from the list of events with no prices |
2197 | - if (isset($espresso_no_ticket_prices[ $EVT_ID ])) { |
|
2198 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
2197 | + if (isset($espresso_no_ticket_prices[$EVT_ID])) { |
|
2198 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
2199 | 2199 | } |
2200 | 2200 | update_option('ee_no_ticket_prices', $espresso_no_ticket_prices); |
2201 | 2201 | } else { |
@@ -2242,7 +2242,7 @@ discard block |
||
2242 | 2242 | $results = $this->_permanently_delete_event($EVT_ID); |
2243 | 2243 | $success = $results !== false ? $success : false; |
2244 | 2244 | // remove this event from the list of events with no prices |
2245 | - unset($espresso_no_ticket_prices[ $EVT_ID ]); |
|
2245 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
2246 | 2246 | } else { |
2247 | 2247 | $success = false; |
2248 | 2248 | $msg = esc_html__( |
@@ -2274,7 +2274,7 @@ discard block |
||
2274 | 2274 | private function _permanently_delete_event($EVT_ID = 0) |
2275 | 2275 | { |
2276 | 2276 | // grab event id |
2277 | - if (! $EVT_ID) { |
|
2277 | + if ( ! $EVT_ID) { |
|
2278 | 2278 | $msg = esc_html__( |
2279 | 2279 | 'An error occurred. No Event ID or an invalid Event ID was received.', |
2280 | 2280 | 'event_espresso' |
@@ -2282,12 +2282,12 @@ discard block |
||
2282 | 2282 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
2283 | 2283 | return false; |
2284 | 2284 | } |
2285 | - if (! $this->_cpt_model_obj instanceof EE_Event |
|
2285 | + if ( ! $this->_cpt_model_obj instanceof EE_Event |
|
2286 | 2286 | || $this->_cpt_model_obj->ID() !== $EVT_ID |
2287 | 2287 | ) { |
2288 | 2288 | $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
2289 | 2289 | } |
2290 | - if (! $this->_cpt_model_obj instanceof EE_Event) { |
|
2290 | + if ( ! $this->_cpt_model_obj instanceof EE_Event) { |
|
2291 | 2291 | return false; |
2292 | 2292 | } |
2293 | 2293 | // need to delete related tickets and prices first. |
@@ -2309,7 +2309,7 @@ discard block |
||
2309 | 2309 | } |
2310 | 2310 | // any attached question groups? |
2311 | 2311 | $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
2312 | - if (! empty($question_groups)) { |
|
2312 | + if ( ! empty($question_groups)) { |
|
2313 | 2313 | foreach ($question_groups as $question_group) { |
2314 | 2314 | $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
2315 | 2315 | } |
@@ -2542,7 +2542,7 @@ discard block |
||
2542 | 2542 | . esc_html__( |
2543 | 2543 | 'Template Settings is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', |
2544 | 2544 | 'event_espresso' |
2545 | - ) . '</strong>'; |
|
2545 | + ).'</strong>'; |
|
2546 | 2546 | $this->display_admin_caf_preview_page('template_settings_tab'); |
2547 | 2547 | } |
2548 | 2548 | |
@@ -2562,12 +2562,12 @@ discard block |
||
2562 | 2562 | // set default category object |
2563 | 2563 | $this->_set_empty_category_object(); |
2564 | 2564 | // only set if we've got an id |
2565 | - if (! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2565 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2566 | 2566 | return; |
2567 | 2567 | } |
2568 | 2568 | $category_id = absint($this->_req_data['EVT_CAT_ID']); |
2569 | 2569 | $term = get_term($category_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
2570 | - if (! empty($term)) { |
|
2570 | + if ( ! empty($term)) { |
|
2571 | 2571 | $this->_category->category_name = $term->name; |
2572 | 2572 | $this->_category->category_identifier = $term->slug; |
2573 | 2573 | $this->_category->category_desc = $term->description; |
@@ -2599,7 +2599,7 @@ discard block |
||
2599 | 2599 | { |
2600 | 2600 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
2601 | 2601 | $this->_search_btn_label = esc_html__('Categories', 'event_espresso'); |
2602 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
2602 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
2603 | 2603 | 'add_category', |
2604 | 2604 | 'add_category', |
2605 | 2605 | array(), |
@@ -2682,7 +2682,7 @@ discard block |
||
2682 | 2682 | 'disable' => '', |
2683 | 2683 | 'disabled_message' => false, |
2684 | 2684 | ); |
2685 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2685 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
2686 | 2686 | return EEH_Template::display_template($template, $template_args, true); |
2687 | 2687 | } |
2688 | 2688 | |
@@ -2771,7 +2771,7 @@ discard block |
||
2771 | 2771 | $insert_ids = $update |
2772 | 2772 | ? wp_update_term($cat_id, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args) |
2773 | 2773 | : wp_insert_term($category_name, EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY, $term_args); |
2774 | - if (! is_array($insert_ids)) { |
|
2774 | + if ( ! is_array($insert_ids)) { |
|
2775 | 2775 | $msg = esc_html__( |
2776 | 2776 | 'An error occurred and the category has not been saved to the database.', |
2777 | 2777 | 'event_espresso' |
@@ -2806,7 +2806,7 @@ discard block |
||
2806 | 2806 | $limit = ($current_page - 1) * $per_page; |
2807 | 2807 | $where = array('taxonomy' => EEM_CPT_Base::EVENT_CATEGORY_TAXONOMY); |
2808 | 2808 | if (isset($this->_req_data['s'])) { |
2809 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2809 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
2810 | 2810 | $where['OR'] = array( |
2811 | 2811 | 'Term.name' => array('LIKE', $sstr), |
2812 | 2812 | 'description' => array('LIKE', $sstr), |
@@ -2815,7 +2815,7 @@ discard block |
||
2815 | 2815 | $query_params = array( |
2816 | 2816 | $where, |
2817 | 2817 | 'order_by' => array($orderby => $order), |
2818 | - 'limit' => $limit . ',' . $per_page, |
|
2818 | + 'limit' => $limit.','.$per_page, |
|
2819 | 2819 | 'force_join' => array('Term'), |
2820 | 2820 | ); |
2821 | 2821 | $categories = $count |