@@ -135,11 +135,11 @@ discard block |
||
135 | 135 | |
136 | 136 | |
137 | 137 | |
138 | - /** |
|
139 | - * _setup_data |
|
140 | - * |
|
141 | - * @throws EE_Error |
|
142 | - */ |
|
138 | + /** |
|
139 | + * _setup_data |
|
140 | + * |
|
141 | + * @throws EE_Error |
|
142 | + */ |
|
143 | 143 | protected function _setup_data() { |
144 | 144 | |
145 | 145 | $this->reg_info = array(); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $this->ip_address = isset( $session_data['ip_address'] ) ? $session_data['ip_address'] : ''; |
158 | 158 | $this->user_agent = isset( $session_data['user_agent'] ) ? $session_data['user_agent'] : ''; |
159 | 159 | $this->init_access = $this->last_access = ''; |
160 | - //get all non-trashed registrations |
|
160 | + //get all non-trashed registrations |
|
161 | 161 | $this->reg_objs = $this->txn->registrations(array(array('REG_deleted' => false))); |
162 | 162 | $this->_assemble_data(); |
163 | 163 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | |
6 | 6 | /** |
@@ -44,25 +44,25 @@ discard block |
||
44 | 44 | * @param array $data |
45 | 45 | * @throws EE_Error |
46 | 46 | */ |
47 | - public function __construct( $data ) { |
|
47 | + public function __construct($data) { |
|
48 | 48 | |
49 | 49 | //test for valid params |
50 | - if ( ! ( $data[0] instanceof EE_Transaction )) |
|
51 | - throw new EE_Error( __('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso') ); |
|
50 | + if ( ! ($data[0] instanceof EE_Transaction)) |
|
51 | + throw new EE_Error(__('Incoming data for the Gateways data handler must have an EE_Transaction object as the value for the first array index.', 'event_espresso')); |
|
52 | 52 | |
53 | - if ( empty( $data[1] ) || ! $data[1] instanceof EE_Payment ) |
|
54 | - $pmt_obj = $this->_get_empty_payment_obj( $data[0] ); |
|
53 | + if (empty($data[1]) || ! $data[1] instanceof EE_Payment) |
|
54 | + $pmt_obj = $this->_get_empty_payment_obj($data[0]); |
|
55 | 55 | |
56 | - if ( ! empty( $data[2] ) ) { |
|
56 | + if ( ! empty($data[2])) { |
|
57 | 57 | $filtered_reg_status = $data[2]; |
58 | 58 | } |
59 | 59 | |
60 | 60 | $data = array( |
61 | 61 | 'txn_obj' => $data[0], |
62 | 62 | 'pmt_obj' => isset($pmt_obj) ? $pmt_obj : $data[1], |
63 | - 'filtered_reg_status' => isset( $filtered_reg_status ) ? $filtered_reg_status : null |
|
63 | + 'filtered_reg_status' => isset($filtered_reg_status) ? $filtered_reg_status : null |
|
64 | 64 | ); |
65 | - parent::__construct( $data ); |
|
65 | + parent::__construct($data); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
@@ -76,18 +76,18 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return array The prepped data for db |
78 | 78 | */ |
79 | - static public function convert_data_for_persistent_storage( $data ) { |
|
79 | + static public function convert_data_for_persistent_storage($data) { |
|
80 | 80 | $prepped_data = array(); |
81 | 81 | |
82 | - if ( $data[0] instanceof EE_Transaction ) { |
|
82 | + if ($data[0] instanceof EE_Transaction) { |
|
83 | 83 | $prepped_data['Transaction'] = $data[0]->ID(); |
84 | 84 | } |
85 | 85 | |
86 | - if ( isset( $data[1] ) && $data[1] instanceof EE_Payment ) { |
|
86 | + if (isset($data[1]) && $data[1] instanceof EE_Payment) { |
|
87 | 87 | $prepped_data['Payment'] = $data[1]->ID(); |
88 | 88 | } |
89 | 89 | |
90 | - if ( ! empty( $data[2] ) ) { |
|
90 | + if ( ! empty($data[2])) { |
|
91 | 91 | $prepped_data['filter'] = $data[2]; |
92 | 92 | } |
93 | 93 | |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return array |
109 | 109 | */ |
110 | - static public function convert_data_from_persistent_storage( $data ) { |
|
110 | + static public function convert_data_from_persistent_storage($data) { |
|
111 | 111 | $prepped_data = array( |
112 | - 0 => isset( $data['Transaction'] ) ? EEM_Transaction::instance()->get_one_by_ID( $data['Transaction'] ) : null, |
|
113 | - 1 => isset( $data['Payment'] ) ? EEM_Payment::instance()->get_one_by_ID( $data['Payment'] ) : null, |
|
114 | - 2 => isset( $data['filter'] ) ? $data['filter'] : null |
|
112 | + 0 => isset($data['Transaction']) ? EEM_Transaction::instance()->get_one_by_ID($data['Transaction']) : null, |
|
113 | + 1 => isset($data['Payment']) ? EEM_Payment::instance()->get_one_by_ID($data['Payment']) : null, |
|
114 | + 2 => isset($data['filter']) ? $data['filter'] : null |
|
115 | 115 | ); |
116 | 116 | return $prepped_data; |
117 | 117 | } |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | * @param \EE_Transaction $txn |
123 | 123 | * @return \EE_Payment |
124 | 124 | */ |
125 | - private function _get_empty_payment_obj( EE_Transaction $txn ) { |
|
126 | - $PMT = EE_Payment::new_instance( array( |
|
125 | + private function _get_empty_payment_obj(EE_Transaction $txn) { |
|
126 | + $PMT = EE_Payment::new_instance(array( |
|
127 | 127 | 'STS_ID' => EEM_Payment::status_id_pending, |
128 | 128 | 'PAY_timestamp' => time(), |
129 | 129 | 'PMD_ID' => $txn->payment_method_ID(), |
@@ -153,9 +153,9 @@ discard block |
||
153 | 153 | |
154 | 154 | |
155 | 155 | //other data from the session (if possible) |
156 | - $this->user_id = isset( $session_data['user_id'] ) ? $session_data['user_id'] : ''; |
|
157 | - $this->ip_address = isset( $session_data['ip_address'] ) ? $session_data['ip_address'] : ''; |
|
158 | - $this->user_agent = isset( $session_data['user_agent'] ) ? $session_data['user_agent'] : ''; |
|
156 | + $this->user_id = isset($session_data['user_id']) ? $session_data['user_id'] : ''; |
|
157 | + $this->ip_address = isset($session_data['ip_address']) ? $session_data['ip_address'] : ''; |
|
158 | + $this->user_agent = isset($session_data['user_agent']) ? $session_data['user_agent'] : ''; |
|
159 | 159 | $this->init_access = $this->last_access = ''; |
160 | 160 | //get all non-trashed registrations |
161 | 161 | $this->reg_objs = $this->txn->registrations(array(array('REG_deleted' => false))); |
@@ -1164,7 +1164,7 @@ discard block |
||
1164 | 1164 | * Sets deleted |
1165 | 1165 | * |
1166 | 1166 | * @param boolean $deleted |
1167 | - * @return bool |
|
1167 | + * @return boolean|null |
|
1168 | 1168 | * @throws EE_Error |
1169 | 1169 | * @throws RuntimeException |
1170 | 1170 | */ |
@@ -1222,6 +1222,7 @@ discard block |
||
1222 | 1222 | * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
1223 | 1223 | * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
1224 | 1224 | * consider registration status as well as datetime access. |
1225 | + * @param integer $DTT_OR_ID |
|
1225 | 1226 | * @return bool |
1226 | 1227 | * @throws EE_Error |
1227 | 1228 | */ |
@@ -1392,7 +1393,7 @@ discard block |
||
1392 | 1393 | * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
1393 | 1394 | * "Latest" is defined by the `DTT_EVT_start` column. |
1394 | 1395 | * |
1395 | - * @return EE_Datetime|null |
|
1396 | + * @return null|EE_Base_Class |
|
1396 | 1397 | * @throws EE_Error |
1397 | 1398 | */ |
1398 | 1399 | public function get_latest_related_datetime() |
@@ -1688,7 +1689,7 @@ discard block |
||
1688 | 1689 | * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
1689 | 1690 | * Note: if there are no payments on the registration there will be no payment method returned. |
1690 | 1691 | * |
1691 | - * @return EE_Payment_Method|null |
|
1692 | + * @return null|EE_Base_Class |
|
1692 | 1693 | */ |
1693 | 1694 | public function payment_method() |
1694 | 1695 | { |
@@ -18,1985 +18,1985 @@ |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * Used to reference when a registration has never been checked in. |
|
23 | - * |
|
24 | - * @deprecated use \EE_Checkin::status_checked_never instead |
|
25 | - * @type int |
|
26 | - */ |
|
27 | - const checkin_status_never = 2; |
|
28 | - |
|
29 | - /** |
|
30 | - * Used to reference when a registration has been checked in. |
|
31 | - * |
|
32 | - * @deprecated use \EE_Checkin::status_checked_in instead |
|
33 | - * @type int |
|
34 | - */ |
|
35 | - const checkin_status_in = 1; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Used to reference when a registration has been checked out. |
|
40 | - * |
|
41 | - * @deprecated use \EE_Checkin::status_checked_out instead |
|
42 | - * @type int |
|
43 | - */ |
|
44 | - const checkin_status_out = 0; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * extra meta key for tracking reg status os trashed registrations |
|
49 | - * |
|
50 | - * @type string |
|
51 | - */ |
|
52 | - const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * extra meta key for tracking if registration has reserved ticket |
|
57 | - * |
|
58 | - * @type string |
|
59 | - */ |
|
60 | - const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @param array $props_n_values incoming values |
|
65 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
66 | - * used.) |
|
67 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
68 | - * date_format and the second value is the time format |
|
69 | - * @return EE_Registration |
|
70 | - * @throws EE_Error |
|
71 | - */ |
|
72 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
73 | - { |
|
74 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
75 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param array $props_n_values incoming values from the database |
|
81 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
82 | - * the website will be used. |
|
83 | - * @return EE_Registration |
|
84 | - */ |
|
85 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
86 | - { |
|
87 | - return new self($props_n_values, true, $timezone); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Set Event ID |
|
93 | - * |
|
94 | - * @param int $EVT_ID Event ID |
|
95 | - * @throws EE_Error |
|
96 | - * @throws RuntimeException |
|
97 | - */ |
|
98 | - public function set_event($EVT_ID = 0) |
|
99 | - { |
|
100 | - $this->set('EVT_ID', $EVT_ID); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
106 | - * be routed to internal methods |
|
107 | - * |
|
108 | - * @param string $field_name |
|
109 | - * @param mixed $field_value |
|
110 | - * @param bool $use_default |
|
111 | - * @throws EE_Error |
|
112 | - * @throws EntityNotFoundException |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidInterfaceException |
|
116 | - * @throws ReflectionException |
|
117 | - * @throws RuntimeException |
|
118 | - */ |
|
119 | - public function set($field_name, $field_value, $use_default = false) |
|
120 | - { |
|
121 | - switch ($field_name) { |
|
122 | - case 'REG_code': |
|
123 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
124 | - $this->set_reg_code($field_value, $use_default); |
|
125 | - } |
|
126 | - break; |
|
127 | - case 'STS_ID': |
|
128 | - $this->set_status($field_value, $use_default); |
|
129 | - break; |
|
130 | - default: |
|
131 | - parent::set($field_name, $field_value, $use_default); |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * Set Status ID |
|
138 | - * updates the registration status and ALSO... |
|
139 | - * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
140 | - * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
141 | - * |
|
142 | - * @param string $new_STS_ID |
|
143 | - * @param boolean $use_default |
|
144 | - * @param Context|null $context |
|
145 | - * @return bool |
|
146 | - * @throws EE_Error |
|
147 | - * @throws EntityNotFoundException |
|
148 | - * @throws InvalidArgumentException |
|
149 | - * @throws ReflectionException |
|
150 | - * @throws RuntimeException |
|
151 | - * @throws InvalidDataTypeException |
|
152 | - * @throws InvalidInterfaceException |
|
153 | - */ |
|
154 | - public function set_status($new_STS_ID = null, $use_default = false, Context $context = null) |
|
155 | - { |
|
156 | - // get current REG_Status |
|
157 | - $old_STS_ID = $this->status_ID(); |
|
158 | - // if status has changed |
|
159 | - if ($old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
160 | - && ! empty($old_STS_ID) // and that old status is actually set |
|
161 | - && ! empty($new_STS_ID) // as well as the new status |
|
162 | - && $this->ID() // ensure registration is in the db |
|
163 | - ) { |
|
164 | - // TO approved |
|
165 | - if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
166 | - // reserve a space by incrementing ticket and datetime sold values |
|
167 | - $this->_reserve_registration_space(); |
|
168 | - do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
169 | - // OR FROM approved |
|
170 | - } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
171 | - // release a space by decrementing ticket and datetime sold values |
|
172 | - $this->_release_registration_space(); |
|
173 | - do_action( |
|
174 | - 'AHEE__EE_Registration__set_status__from_approved', |
|
175 | - $this, |
|
176 | - $old_STS_ID, |
|
177 | - $new_STS_ID, |
|
178 | - $context |
|
179 | - ); |
|
180 | - } |
|
181 | - // update status |
|
182 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
183 | - $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
|
184 | - if($this->statusChangeUpdatesTransaction($context)) { |
|
185 | - $this->updateTransactionAfterStatusChange(); |
|
186 | - } |
|
187 | - do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
188 | - return true; |
|
189 | - } |
|
190 | - //even though the old value matches the new value, it's still good to |
|
191 | - //allow the parent set method to have a say |
|
192 | - parent::set('STS_ID', $new_STS_ID, $use_default); |
|
193 | - return true; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * update REGs and TXN when cancelled or declined registrations involved |
|
199 | - * |
|
200 | - * @param string $new_STS_ID |
|
201 | - * @param string $old_STS_ID |
|
202 | - * @param Context|null $context |
|
203 | - * @throws EE_Error |
|
204 | - * @throws InvalidArgumentException |
|
205 | - * @throws InvalidDataTypeException |
|
206 | - * @throws InvalidInterfaceException |
|
207 | - * @throws ReflectionException |
|
208 | - */ |
|
209 | - private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, Context $context = null) |
|
210 | - { |
|
211 | - // these reg statuses should not be considered in any calculations involving monies owing |
|
212 | - $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
213 | - // true if registration has been cancelled or declined |
|
214 | - $this->updateIfCanceled( |
|
215 | - $closed_reg_statuses, |
|
216 | - $new_STS_ID, |
|
217 | - $old_STS_ID, |
|
218 | - $context |
|
219 | - ); |
|
220 | - $this->updateIfDeclined( |
|
221 | - $closed_reg_statuses, |
|
222 | - $new_STS_ID, |
|
223 | - $old_STS_ID, |
|
224 | - $context |
|
225 | - ); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * update REGs and TXN when cancelled or declined registrations involved |
|
231 | - * |
|
232 | - * @param array $closed_reg_statuses |
|
233 | - * @param string $new_STS_ID |
|
234 | - * @param string $old_STS_ID |
|
235 | - * @param Context|null $context |
|
236 | - * @throws EE_Error |
|
237 | - * @throws InvalidArgumentException |
|
238 | - * @throws InvalidDataTypeException |
|
239 | - * @throws InvalidInterfaceException |
|
240 | - * @throws ReflectionException |
|
241 | - */ |
|
242 | - private function updateIfCanceled(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, Context $context = null) |
|
243 | - { |
|
244 | - // true if registration has been cancelled or declined |
|
245 | - if (in_array($new_STS_ID, $closed_reg_statuses, true) |
|
246 | - && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
247 | - ) { |
|
248 | - /** @type EE_Registration_Processor $registration_processor */ |
|
249 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
250 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
251 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
252 | - // cancelled or declined registration |
|
253 | - $registration_processor->update_registration_after_being_canceled_or_declined( |
|
254 | - $this, |
|
255 | - $closed_reg_statuses |
|
256 | - ); |
|
257 | - $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
258 | - $this, |
|
259 | - $closed_reg_statuses, |
|
260 | - false |
|
261 | - ); |
|
262 | - do_action( |
|
263 | - 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
264 | - $this, |
|
265 | - $old_STS_ID, |
|
266 | - $new_STS_ID, |
|
267 | - $context |
|
268 | - ); |
|
269 | - return; |
|
270 | - } |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * update REGs and TXN when cancelled or declined registrations involved |
|
276 | - * |
|
277 | - * @param array $closed_reg_statuses |
|
278 | - * @param string $new_STS_ID |
|
279 | - * @param string $old_STS_ID |
|
280 | - * @param Context|null $context |
|
281 | - * @throws EE_Error |
|
282 | - * @throws InvalidArgumentException |
|
283 | - * @throws InvalidDataTypeException |
|
284 | - * @throws InvalidInterfaceException |
|
285 | - * @throws ReflectionException |
|
286 | - */ |
|
287 | - private function updateIfDeclined(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, Context $context = null) |
|
288 | - { |
|
289 | - // true if reinstating cancelled or declined registration |
|
290 | - if (in_array($old_STS_ID, $closed_reg_statuses, true) |
|
291 | - && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
292 | - ) { |
|
293 | - /** @type EE_Registration_Processor $registration_processor */ |
|
294 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
295 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
296 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
297 | - // reinstating cancelled or declined registration |
|
298 | - $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
299 | - $this, |
|
300 | - $closed_reg_statuses |
|
301 | - ); |
|
302 | - $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
303 | - $this, |
|
304 | - $closed_reg_statuses, |
|
305 | - false |
|
306 | - ); |
|
307 | - do_action( |
|
308 | - 'AHEE__EE_Registration__set_status__after_reinstated', |
|
309 | - $this, |
|
310 | - $old_STS_ID, |
|
311 | - $new_STS_ID, |
|
312 | - $context |
|
313 | - ); |
|
314 | - } |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @param Context|null $context |
|
320 | - * @return bool |
|
321 | - */ |
|
322 | - private function statusChangeUpdatesTransaction(Context $context = null) |
|
323 | - { |
|
324 | - $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
325 | - 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
326 | - array('spco_reg_step_attendee_information_process_registrations'), |
|
327 | - $context, |
|
328 | - $this |
|
329 | - ); |
|
330 | - return ! ( |
|
331 | - $context instanceof Context |
|
332 | - && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
333 | - ); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * @throws EE_Error |
|
339 | - * @throws EntityNotFoundException |
|
340 | - * @throws InvalidArgumentException |
|
341 | - * @throws InvalidDataTypeException |
|
342 | - * @throws InvalidInterfaceException |
|
343 | - * @throws ReflectionException |
|
344 | - * @throws RuntimeException |
|
345 | - */ |
|
346 | - private function updateTransactionAfterStatusChange() |
|
347 | - { |
|
348 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
349 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
350 | - $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
351 | - $this->transaction()->update_status_based_on_total_paid(true); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * get Status ID |
|
357 | - */ |
|
358 | - public function status_ID() |
|
359 | - { |
|
360 | - return $this->get('STS_ID'); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * increments this registration's related ticket sold and corresponding datetime sold values |
|
366 | - * |
|
367 | - * @return void |
|
368 | - * @throws EE_Error |
|
369 | - * @throws EntityNotFoundException |
|
370 | - */ |
|
371 | - private function _reserve_registration_space() |
|
372 | - { |
|
373 | - // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
374 | - // so stop tracking that this reg has a ticket reserved |
|
375 | - $this->release_reserved_ticket(); |
|
376 | - $ticket = $this->ticket(); |
|
377 | - $ticket->increase_sold(); |
|
378 | - $ticket->save(); |
|
379 | - // possibly set event status to sold out |
|
380 | - $this->event()->perform_sold_out_status_check(); |
|
381 | - } |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * Gets the ticket this registration is for |
|
386 | - * |
|
387 | - * @param boolean $include_archived whether to include archived tickets or not. |
|
388 | - * |
|
389 | - * @return EE_Ticket|EE_Base_Class |
|
390 | - * @throws EE_Error |
|
391 | - */ |
|
392 | - public function ticket($include_archived = true) |
|
393 | - { |
|
394 | - $query_params = array(); |
|
395 | - if ($include_archived) { |
|
396 | - $query_params['default_where_conditions'] = 'none'; |
|
397 | - } |
|
398 | - return $this->get_first_related('Ticket', $query_params); |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * Gets the event this registration is for |
|
404 | - * |
|
405 | - * @return EE_Event |
|
406 | - * @throws EE_Error |
|
407 | - * @throws EntityNotFoundException |
|
408 | - */ |
|
409 | - public function event() |
|
410 | - { |
|
411 | - $event = $this->get_first_related('Event'); |
|
412 | - if (! $event instanceof \EE_Event) { |
|
413 | - throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
414 | - } |
|
415 | - return $event; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
421 | - * with the author of the event this registration is for. |
|
422 | - * |
|
423 | - * @since 4.5.0 |
|
424 | - * @return int |
|
425 | - * @throws EE_Error |
|
426 | - * @throws EntityNotFoundException |
|
427 | - */ |
|
428 | - public function wp_user() |
|
429 | - { |
|
430 | - $event = $this->event(); |
|
431 | - if ($event instanceof EE_Event) { |
|
432 | - return $event->wp_user(); |
|
433 | - } |
|
434 | - return 0; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
440 | - * |
|
441 | - * @return void |
|
442 | - * @throws EE_Error |
|
443 | - */ |
|
444 | - private function _release_registration_space() |
|
445 | - { |
|
446 | - $ticket = $this->ticket(); |
|
447 | - $ticket->decrease_sold(); |
|
448 | - $ticket->save(); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - /** |
|
453 | - * tracks this registration's ticket reservation in extra meta |
|
454 | - * and can increment related ticket reserved and corresponding datetime reserved values |
|
455 | - * |
|
456 | - * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
457 | - * |
|
458 | - * @return void |
|
459 | - * @throws EE_Error |
|
460 | - */ |
|
461 | - public function reserve_ticket($update_ticket = false) |
|
462 | - { |
|
463 | - if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) { |
|
464 | - // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
465 | - // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
466 | - if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) { |
|
467 | - $ticket = $this->ticket(); |
|
468 | - $ticket->increase_reserved(); |
|
469 | - $ticket->save(); |
|
470 | - } |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - /** |
|
476 | - * stops tracking this registration's ticket reservation in extra meta |
|
477 | - * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
478 | - * |
|
479 | - * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
480 | - * |
|
481 | - * @return void |
|
482 | - * @throws EE_Error |
|
483 | - */ |
|
484 | - public function release_reserved_ticket($update_ticket = false) |
|
485 | - { |
|
486 | - if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) { |
|
487 | - // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
488 | - // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first |
|
489 | - if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) { |
|
490 | - $ticket = $this->ticket(); |
|
491 | - $ticket->decrease_reserved(); |
|
492 | - $ticket->save(); |
|
493 | - } |
|
494 | - } |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * Set Attendee ID |
|
500 | - * |
|
501 | - * @param int $ATT_ID Attendee ID |
|
502 | - * @throws EE_Error |
|
503 | - * @throws RuntimeException |
|
504 | - */ |
|
505 | - public function set_attendee_id($ATT_ID = 0) |
|
506 | - { |
|
507 | - $this->set('ATT_ID', $ATT_ID); |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * Set Transaction ID |
|
513 | - * |
|
514 | - * @param int $TXN_ID Transaction ID |
|
515 | - * @throws EE_Error |
|
516 | - * @throws RuntimeException |
|
517 | - */ |
|
518 | - public function set_transaction_id($TXN_ID = 0) |
|
519 | - { |
|
520 | - $this->set('TXN_ID', $TXN_ID); |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - /** |
|
525 | - * Set Session |
|
526 | - * |
|
527 | - * @param string $REG_session PHP Session ID |
|
528 | - * @throws EE_Error |
|
529 | - * @throws RuntimeException |
|
530 | - */ |
|
531 | - public function set_session($REG_session = '') |
|
532 | - { |
|
533 | - $this->set('REG_session', $REG_session); |
|
534 | - } |
|
535 | - |
|
536 | - |
|
537 | - /** |
|
538 | - * Set Registration URL Link |
|
539 | - * |
|
540 | - * @param string $REG_url_link Registration URL Link |
|
541 | - * @throws EE_Error |
|
542 | - * @throws RuntimeException |
|
543 | - */ |
|
544 | - public function set_reg_url_link($REG_url_link = '') |
|
545 | - { |
|
546 | - $this->set('REG_url_link', $REG_url_link); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * Set Attendee Counter |
|
552 | - * |
|
553 | - * @param int $REG_count Primary Attendee |
|
554 | - * @throws EE_Error |
|
555 | - * @throws RuntimeException |
|
556 | - */ |
|
557 | - public function set_count($REG_count = 1) |
|
558 | - { |
|
559 | - $this->set('REG_count', $REG_count); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * Set Group Size |
|
565 | - * |
|
566 | - * @param boolean $REG_group_size Group Registration |
|
567 | - * @throws EE_Error |
|
568 | - * @throws RuntimeException |
|
569 | - */ |
|
570 | - public function set_group_size($REG_group_size = false) |
|
571 | - { |
|
572 | - $this->set('REG_group_size', $REG_group_size); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - /** |
|
577 | - * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
578 | - * EEM_Registration::status_id_not_approved |
|
579 | - * |
|
580 | - * @return boolean |
|
581 | - */ |
|
582 | - public function is_not_approved() |
|
583 | - { |
|
584 | - return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
585 | - } |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
590 | - * EEM_Registration::status_id_pending_payment |
|
591 | - * |
|
592 | - * @return boolean |
|
593 | - */ |
|
594 | - public function is_pending_payment() |
|
595 | - { |
|
596 | - return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
602 | - * |
|
603 | - * @return boolean |
|
604 | - */ |
|
605 | - public function is_approved() |
|
606 | - { |
|
607 | - return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
613 | - * |
|
614 | - * @return boolean |
|
615 | - */ |
|
616 | - public function is_cancelled() |
|
617 | - { |
|
618 | - return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
619 | - } |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
624 | - * |
|
625 | - * @return boolean |
|
626 | - */ |
|
627 | - public function is_declined() |
|
628 | - { |
|
629 | - return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - /** |
|
634 | - * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
635 | - * EEM_Registration::status_id_incomplete |
|
636 | - * |
|
637 | - * @return boolean |
|
638 | - */ |
|
639 | - public function is_incomplete() |
|
640 | - { |
|
641 | - return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
642 | - } |
|
643 | - |
|
644 | - |
|
645 | - /** |
|
646 | - * Set Registration Date |
|
647 | - * |
|
648 | - * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
649 | - * Date |
|
650 | - * @throws EE_Error |
|
651 | - * @throws RuntimeException |
|
652 | - */ |
|
653 | - public function set_reg_date($REG_date = false) |
|
654 | - { |
|
655 | - $this->set('REG_date', $REG_date); |
|
656 | - } |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * Set final price owing for this registration after all ticket/price modifications |
|
661 | - * |
|
662 | - * @access public |
|
663 | - * @param float $REG_final_price |
|
664 | - * @throws EE_Error |
|
665 | - * @throws RuntimeException |
|
666 | - */ |
|
667 | - public function set_final_price($REG_final_price = 0.00) |
|
668 | - { |
|
669 | - $this->set('REG_final_price', $REG_final_price); |
|
670 | - } |
|
671 | - |
|
672 | - |
|
673 | - /** |
|
674 | - * Set amount paid towards this registration's final price |
|
675 | - * |
|
676 | - * @access public |
|
677 | - * @param float $REG_paid |
|
678 | - * @throws EE_Error |
|
679 | - * @throws RuntimeException |
|
680 | - */ |
|
681 | - public function set_paid($REG_paid = 0.00) |
|
682 | - { |
|
683 | - $this->set('REG_paid', $REG_paid); |
|
684 | - } |
|
685 | - |
|
686 | - |
|
687 | - /** |
|
688 | - * Attendee Is Going |
|
689 | - * |
|
690 | - * @param boolean $REG_att_is_going Attendee Is Going |
|
691 | - * @throws EE_Error |
|
692 | - * @throws RuntimeException |
|
693 | - */ |
|
694 | - public function set_att_is_going($REG_att_is_going = false) |
|
695 | - { |
|
696 | - $this->set('REG_att_is_going', $REG_att_is_going); |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - /** |
|
701 | - * Gets the related attendee |
|
702 | - * |
|
703 | - * @return EE_Attendee |
|
704 | - * @throws EE_Error |
|
705 | - */ |
|
706 | - public function attendee() |
|
707 | - { |
|
708 | - return $this->get_first_related('Attendee'); |
|
709 | - } |
|
710 | - |
|
711 | - |
|
712 | - /** |
|
713 | - * get Event ID |
|
714 | - */ |
|
715 | - public function event_ID() |
|
716 | - { |
|
717 | - return $this->get('EVT_ID'); |
|
718 | - } |
|
719 | - |
|
720 | - |
|
721 | - /** |
|
722 | - * get Event ID |
|
723 | - */ |
|
724 | - public function event_name() |
|
725 | - { |
|
726 | - $event = $this->event_obj(); |
|
727 | - if ($event) { |
|
728 | - return $event->name(); |
|
729 | - } else { |
|
730 | - return null; |
|
731 | - } |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * Fetches the event this registration is for |
|
737 | - * |
|
738 | - * @return EE_Event |
|
739 | - * @throws EE_Error |
|
740 | - */ |
|
741 | - public function event_obj() |
|
742 | - { |
|
743 | - return $this->get_first_related('Event'); |
|
744 | - } |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * get Attendee ID |
|
749 | - */ |
|
750 | - public function attendee_ID() |
|
751 | - { |
|
752 | - return $this->get('ATT_ID'); |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - /** |
|
757 | - * get PHP Session ID |
|
758 | - */ |
|
759 | - public function session_ID() |
|
760 | - { |
|
761 | - return $this->get('REG_session'); |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - /** |
|
766 | - * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
767 | - * |
|
768 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
769 | - * @return string |
|
770 | - */ |
|
771 | - public function receipt_url($messenger = 'html') |
|
772 | - { |
|
773 | - |
|
774 | - /** |
|
775 | - * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
776 | - * already in use on old system. If there is then we just return the standard url for it. |
|
777 | - * |
|
778 | - * @since 4.5.0 |
|
779 | - */ |
|
780 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
781 | - $has_custom = EEH_Template::locate_template( |
|
782 | - $template_relative_path, |
|
783 | - array(), |
|
784 | - true, |
|
785 | - true, |
|
786 | - true |
|
787 | - ); |
|
788 | - |
|
789 | - if ($has_custom) { |
|
790 | - return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
791 | - } |
|
792 | - return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
793 | - } |
|
794 | - |
|
795 | - |
|
796 | - /** |
|
797 | - * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
798 | - * |
|
799 | - * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
800 | - * @return string |
|
801 | - * @throws EE_Error |
|
802 | - */ |
|
803 | - public function invoice_url($messenger = 'html') |
|
804 | - { |
|
805 | - /** |
|
806 | - * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
807 | - * already in use on old system. If there is then we just return the standard url for it. |
|
808 | - * |
|
809 | - * @since 4.5.0 |
|
810 | - */ |
|
811 | - $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
812 | - $has_custom = EEH_Template::locate_template( |
|
813 | - $template_relative_path, |
|
814 | - array(), |
|
815 | - true, |
|
816 | - true, |
|
817 | - true |
|
818 | - ); |
|
819 | - |
|
820 | - if ($has_custom) { |
|
821 | - if ($messenger == 'html') { |
|
822 | - return $this->invoice_url('launch'); |
|
823 | - } |
|
824 | - $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
825 | - |
|
826 | - $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
827 | - if ($messenger == 'html') { |
|
828 | - $query_args['html'] = true; |
|
829 | - } |
|
830 | - return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
831 | - } |
|
832 | - return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
833 | - } |
|
834 | - |
|
835 | - |
|
836 | - /** |
|
837 | - * get Registration URL Link |
|
838 | - * |
|
839 | - * @access public |
|
840 | - * @return string |
|
841 | - * @throws EE_Error |
|
842 | - */ |
|
843 | - public function reg_url_link() |
|
844 | - { |
|
845 | - return (string) $this->get('REG_url_link'); |
|
846 | - } |
|
847 | - |
|
848 | - |
|
849 | - /** |
|
850 | - * Echoes out invoice_url() |
|
851 | - * |
|
852 | - * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
853 | - * @return void |
|
854 | - * @throws EE_Error |
|
855 | - */ |
|
856 | - public function e_invoice_url($type = 'launch') |
|
857 | - { |
|
858 | - echo $this->invoice_url($type); |
|
859 | - } |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * Echoes out payment_overview_url |
|
864 | - */ |
|
865 | - public function e_payment_overview_url() |
|
866 | - { |
|
867 | - echo $this->payment_overview_url(); |
|
868 | - } |
|
869 | - |
|
870 | - |
|
871 | - /** |
|
872 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
873 | - * a query parameter |
|
874 | - * |
|
875 | - * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
876 | - * payment overview url. |
|
877 | - * @return string |
|
878 | - * @throws EE_Error |
|
879 | - */ |
|
880 | - public function payment_overview_url($clear_session = false) |
|
881 | - { |
|
882 | - return add_query_arg(array( |
|
883 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
884 | - 'step' => 'payment_options', |
|
885 | - 'revisit' => true, |
|
886 | - 'clear_session' => (bool) $clear_session |
|
887 | - ), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
888 | - } |
|
889 | - |
|
890 | - |
|
891 | - /** |
|
892 | - * Gets the URL of the thank you page with this registration REG_url_link added as |
|
893 | - * a query parameter |
|
894 | - * |
|
895 | - * @return string |
|
896 | - * @throws EE_Error |
|
897 | - */ |
|
898 | - public function edit_attendee_information_url() |
|
899 | - { |
|
900 | - return add_query_arg(array( |
|
901 | - 'e_reg_url_link' => $this->reg_url_link(), |
|
902 | - 'step' => 'attendee_information', |
|
903 | - 'revisit' => true, |
|
904 | - ), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - /** |
|
909 | - * Simply generates and returns the appropriate admin_url link to edit this registration |
|
910 | - * |
|
911 | - * @return string |
|
912 | - * @throws EE_Error |
|
913 | - */ |
|
914 | - public function get_admin_edit_url() |
|
915 | - { |
|
916 | - return EEH_URL::add_query_args_and_nonce(array( |
|
917 | - 'page' => 'espresso_registrations', |
|
918 | - 'action' => 'view_registration', |
|
919 | - '_REG_ID' => $this->ID(), |
|
920 | - ), admin_url('admin.php')); |
|
921 | - } |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * is_primary_registrant? |
|
926 | - */ |
|
927 | - public function is_primary_registrant() |
|
928 | - { |
|
929 | - return $this->get('REG_count') == 1 ? true : false; |
|
930 | - } |
|
931 | - |
|
932 | - |
|
933 | - /** |
|
934 | - * This returns the primary registration object for this registration group (which may be this object). |
|
935 | - * |
|
936 | - * @return EE_Registration |
|
937 | - * @throws EE_Error |
|
938 | - */ |
|
939 | - public function get_primary_registration() |
|
940 | - { |
|
941 | - if ($this->is_primary_registrant()) { |
|
942 | - return $this; |
|
943 | - } |
|
944 | - |
|
945 | - //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
946 | - /** @var EE_Registration $primary_registrant */ |
|
947 | - $primary_registrant = EEM_Registration::instance()->get_one(array( |
|
948 | - array( |
|
949 | - 'TXN_ID' => $this->transaction_ID(), |
|
950 | - 'REG_count' => 1, |
|
951 | - ), |
|
952 | - )); |
|
953 | - return $primary_registrant; |
|
954 | - } |
|
955 | - |
|
956 | - |
|
957 | - /** |
|
958 | - * get Attendee Number |
|
959 | - * |
|
960 | - * @access public |
|
961 | - */ |
|
962 | - public function count() |
|
963 | - { |
|
964 | - return $this->get('REG_count'); |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - /** |
|
969 | - * get Group Size |
|
970 | - */ |
|
971 | - public function group_size() |
|
972 | - { |
|
973 | - return $this->get('REG_group_size'); |
|
974 | - } |
|
975 | - |
|
976 | - |
|
977 | - /** |
|
978 | - * get Registration Date |
|
979 | - */ |
|
980 | - public function date() |
|
981 | - { |
|
982 | - return $this->get('REG_date'); |
|
983 | - } |
|
984 | - |
|
985 | - |
|
986 | - /** |
|
987 | - * gets a pretty date |
|
988 | - * |
|
989 | - * @param string $date_format |
|
990 | - * @param string $time_format |
|
991 | - * @return string |
|
992 | - * @throws EE_Error |
|
993 | - */ |
|
994 | - public function pretty_date($date_format = null, $time_format = null) |
|
995 | - { |
|
996 | - return $this->get_datetime('REG_date', $date_format, $time_format); |
|
997 | - } |
|
998 | - |
|
999 | - |
|
1000 | - /** |
|
1001 | - * final_price |
|
1002 | - * the registration's share of the transaction total, so that the |
|
1003 | - * sum of all the transaction's REG_final_prices equal the transaction's total |
|
1004 | - * |
|
1005 | - * @return float |
|
1006 | - * @throws EE_Error |
|
1007 | - */ |
|
1008 | - public function final_price() |
|
1009 | - { |
|
1010 | - return $this->get('REG_final_price'); |
|
1011 | - } |
|
1012 | - |
|
1013 | - |
|
1014 | - /** |
|
1015 | - * pretty_final_price |
|
1016 | - * final price as formatted string, with correct decimal places and currency symbol |
|
1017 | - * |
|
1018 | - * @return string |
|
1019 | - * @throws EE_Error |
|
1020 | - */ |
|
1021 | - public function pretty_final_price() |
|
1022 | - { |
|
1023 | - return $this->get_pretty('REG_final_price'); |
|
1024 | - } |
|
1025 | - |
|
1026 | - |
|
1027 | - /** |
|
1028 | - * get paid (yeah) |
|
1029 | - * |
|
1030 | - * @return float |
|
1031 | - * @throws EE_Error |
|
1032 | - */ |
|
1033 | - public function paid() |
|
1034 | - { |
|
1035 | - return $this->get('REG_paid'); |
|
1036 | - } |
|
1037 | - |
|
1038 | - |
|
1039 | - /** |
|
1040 | - * pretty_paid |
|
1041 | - * |
|
1042 | - * @return float |
|
1043 | - * @throws EE_Error |
|
1044 | - */ |
|
1045 | - public function pretty_paid() |
|
1046 | - { |
|
1047 | - return $this->get_pretty('REG_paid'); |
|
1048 | - } |
|
1049 | - |
|
1050 | - |
|
1051 | - /** |
|
1052 | - * owes_monies_and_can_pay |
|
1053 | - * whether or not this registration has monies owing and it's' status allows payment |
|
1054 | - * |
|
1055 | - * @param array $requires_payment |
|
1056 | - * @return bool |
|
1057 | - * @throws EE_Error |
|
1058 | - */ |
|
1059 | - public function owes_monies_and_can_pay($requires_payment = array()) |
|
1060 | - { |
|
1061 | - // these reg statuses require payment (if event is not free) |
|
1062 | - $requires_payment = ! empty($requires_payment) |
|
1063 | - ? $requires_payment |
|
1064 | - : EEM_Registration::reg_statuses_that_allow_payment(); |
|
1065 | - if (in_array($this->status_ID(), $requires_payment) && |
|
1066 | - $this->final_price() != 0 && |
|
1067 | - $this->final_price() != $this->paid() |
|
1068 | - ) { |
|
1069 | - return true; |
|
1070 | - } else { |
|
1071 | - return false; |
|
1072 | - } |
|
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - /** |
|
1077 | - * Prints out the return value of $this->pretty_status() |
|
1078 | - * |
|
1079 | - * @param bool $show_icons |
|
1080 | - * @return void |
|
1081 | - * @throws EE_Error |
|
1082 | - */ |
|
1083 | - public function e_pretty_status($show_icons = false) |
|
1084 | - { |
|
1085 | - echo $this->pretty_status($show_icons); |
|
1086 | - } |
|
1087 | - |
|
1088 | - |
|
1089 | - /** |
|
1090 | - * Returns a nice version of the status for displaying to customers |
|
1091 | - * |
|
1092 | - * @param bool $show_icons |
|
1093 | - * @return string |
|
1094 | - * @throws EE_Error |
|
1095 | - */ |
|
1096 | - public function pretty_status($show_icons = false) |
|
1097 | - { |
|
1098 | - $status = EEM_Status::instance()->localized_status( |
|
1099 | - array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
1100 | - false, |
|
1101 | - 'sentence' |
|
1102 | - ); |
|
1103 | - $icon = ''; |
|
1104 | - switch ($this->status_ID()) { |
|
1105 | - case EEM_Registration::status_id_approved: |
|
1106 | - $icon = $show_icons |
|
1107 | - ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
1108 | - : ''; |
|
1109 | - break; |
|
1110 | - case EEM_Registration::status_id_pending_payment: |
|
1111 | - $icon = $show_icons |
|
1112 | - ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
1113 | - : ''; |
|
1114 | - break; |
|
1115 | - case EEM_Registration::status_id_not_approved: |
|
1116 | - $icon = $show_icons |
|
1117 | - ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
1118 | - : ''; |
|
1119 | - break; |
|
1120 | - case EEM_Registration::status_id_cancelled: |
|
1121 | - $icon = $show_icons |
|
1122 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
1123 | - : ''; |
|
1124 | - break; |
|
1125 | - case EEM_Registration::status_id_incomplete: |
|
1126 | - $icon = $show_icons |
|
1127 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
1128 | - : ''; |
|
1129 | - break; |
|
1130 | - case EEM_Registration::status_id_declined: |
|
1131 | - $icon = $show_icons |
|
1132 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
1133 | - : ''; |
|
1134 | - break; |
|
1135 | - case EEM_Registration::status_id_wait_list: |
|
1136 | - $icon = $show_icons |
|
1137 | - ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
1138 | - : ''; |
|
1139 | - break; |
|
1140 | - } |
|
1141 | - return $icon . $status[$this->status_ID()]; |
|
1142 | - } |
|
1143 | - |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * get Attendee Is Going |
|
1147 | - */ |
|
1148 | - public function att_is_going() |
|
1149 | - { |
|
1150 | - return $this->get('REG_att_is_going'); |
|
1151 | - } |
|
1152 | - |
|
1153 | - |
|
1154 | - /** |
|
1155 | - * Gets related answers |
|
1156 | - * |
|
1157 | - * @param array $query_params like EEM_Base::get_all |
|
1158 | - * @return EE_Answer[] |
|
1159 | - * @throws EE_Error |
|
1160 | - */ |
|
1161 | - public function answers($query_params = null) |
|
1162 | - { |
|
1163 | - return $this->get_many_related('Answer', $query_params); |
|
1164 | - } |
|
1165 | - |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * Gets the registration's answer value to the specified question |
|
1169 | - * (either the question's ID or a question object) |
|
1170 | - * |
|
1171 | - * @param EE_Question|int $question |
|
1172 | - * @param bool $pretty_value |
|
1173 | - * @return array|string if pretty_value= true, the result will always be a string |
|
1174 | - * (because the answer might be an array of answer values, so passing pretty_value=true |
|
1175 | - * will convert it into some kind of string) |
|
1176 | - * @throws EE_Error |
|
1177 | - */ |
|
1178 | - public function answer_value_to_question($question, $pretty_value = true) |
|
1179 | - { |
|
1180 | - $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
1181 | - return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
1182 | - } |
|
1183 | - |
|
1184 | - |
|
1185 | - /** |
|
1186 | - * question_groups |
|
1187 | - * returns an array of EE_Question_Group objects for this registration |
|
1188 | - * |
|
1189 | - * @return EE_Question_Group[] |
|
1190 | - * @throws EE_Error |
|
1191 | - * @throws EntityNotFoundException |
|
1192 | - */ |
|
1193 | - public function question_groups() |
|
1194 | - { |
|
1195 | - $question_groups = array(); |
|
1196 | - if ($this->event() instanceof EE_Event) { |
|
1197 | - $question_groups = $this->event()->question_groups( |
|
1198 | - array( |
|
1199 | - array( |
|
1200 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
1201 | - ), |
|
1202 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
1203 | - ) |
|
1204 | - ); |
|
1205 | - } |
|
1206 | - return $question_groups; |
|
1207 | - } |
|
1208 | - |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * count_question_groups |
|
1212 | - * returns a count of the number of EE_Question_Group objects for this registration |
|
1213 | - * |
|
1214 | - * @return int |
|
1215 | - * @throws EE_Error |
|
1216 | - * @throws EntityNotFoundException |
|
1217 | - */ |
|
1218 | - public function count_question_groups() |
|
1219 | - { |
|
1220 | - $qg_count = 0; |
|
1221 | - if ($this->event() instanceof EE_Event) { |
|
1222 | - $qg_count = $this->event()->count_related( |
|
1223 | - 'Question_Group', |
|
1224 | - array( |
|
1225 | - array( |
|
1226 | - 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
1227 | - ), |
|
1228 | - ) |
|
1229 | - ); |
|
1230 | - } |
|
1231 | - return $qg_count; |
|
1232 | - } |
|
1233 | - |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * Returns the registration date in the 'standard' string format |
|
1237 | - * (function may be improved in the future to allow for different formats and timezones) |
|
1238 | - * |
|
1239 | - * @return string |
|
1240 | - * @throws EE_Error |
|
1241 | - */ |
|
1242 | - public function reg_date() |
|
1243 | - { |
|
1244 | - return $this->get_datetime('REG_date'); |
|
1245 | - } |
|
1246 | - |
|
1247 | - |
|
1248 | - /** |
|
1249 | - * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
1250 | - * the ticket this registration purchased, or the datetime they have registered |
|
1251 | - * to attend) |
|
1252 | - * |
|
1253 | - * @return EE_Datetime_Ticket |
|
1254 | - * @throws EE_Error |
|
1255 | - */ |
|
1256 | - public function datetime_ticket() |
|
1257 | - { |
|
1258 | - return $this->get_first_related('Datetime_Ticket'); |
|
1259 | - } |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * Sets the registration's datetime_ticket. |
|
1264 | - * |
|
1265 | - * @param EE_Datetime_Ticket $datetime_ticket |
|
1266 | - * @return EE_Datetime_Ticket |
|
1267 | - * @throws EE_Error |
|
1268 | - */ |
|
1269 | - public function set_datetime_ticket($datetime_ticket) |
|
1270 | - { |
|
1271 | - return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1272 | - } |
|
1273 | - |
|
1274 | - /** |
|
1275 | - * Gets deleted |
|
1276 | - * |
|
1277 | - * @return bool |
|
1278 | - * @throws EE_Error |
|
1279 | - */ |
|
1280 | - public function deleted() |
|
1281 | - { |
|
1282 | - return $this->get('REG_deleted'); |
|
1283 | - } |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * Sets deleted |
|
1287 | - * |
|
1288 | - * @param boolean $deleted |
|
1289 | - * @return bool |
|
1290 | - * @throws EE_Error |
|
1291 | - * @throws RuntimeException |
|
1292 | - */ |
|
1293 | - public function set_deleted($deleted) |
|
1294 | - { |
|
1295 | - if ($deleted) { |
|
1296 | - $this->delete(); |
|
1297 | - } else { |
|
1298 | - $this->restore(); |
|
1299 | - } |
|
1300 | - } |
|
1301 | - |
|
1302 | - |
|
1303 | - /** |
|
1304 | - * Get the status object of this object |
|
1305 | - * |
|
1306 | - * @return EE_Status |
|
1307 | - * @throws EE_Error |
|
1308 | - */ |
|
1309 | - public function status_obj() |
|
1310 | - { |
|
1311 | - return $this->get_first_related('Status'); |
|
1312 | - } |
|
1313 | - |
|
1314 | - |
|
1315 | - /** |
|
1316 | - * Returns the number of times this registration has checked into any of the datetimes |
|
1317 | - * its available for |
|
1318 | - * |
|
1319 | - * @return int |
|
1320 | - * @throws EE_Error |
|
1321 | - */ |
|
1322 | - public function count_checkins() |
|
1323 | - { |
|
1324 | - return $this->get_model()->count_related($this, 'Checkin'); |
|
1325 | - } |
|
1326 | - |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
1330 | - * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
1331 | - * |
|
1332 | - * @return int |
|
1333 | - * @throws EE_Error |
|
1334 | - */ |
|
1335 | - public function count_checkins_not_checkedout() |
|
1336 | - { |
|
1337 | - return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1338 | - } |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
1343 | - * |
|
1344 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1345 | - * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
1346 | - * consider registration status as well as datetime access. |
|
1347 | - * @return bool |
|
1348 | - * @throws EE_Error |
|
1349 | - */ |
|
1350 | - public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
1351 | - { |
|
1352 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1353 | - |
|
1354 | - //first check registration status |
|
1355 | - if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1356 | - return false; |
|
1357 | - } |
|
1358 | - //is there a datetime ticket that matches this dtt_ID? |
|
1359 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
1360 | - array( |
|
1361 | - 'TKT_ID' => $this->get('TKT_ID'), |
|
1362 | - 'DTT_ID' => $DTT_ID, |
|
1363 | - ), |
|
1364 | - ))) |
|
1365 | - ) { |
|
1366 | - return false; |
|
1367 | - } |
|
1368 | - |
|
1369 | - //final check is against TKT_uses |
|
1370 | - return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1371 | - } |
|
1372 | - |
|
1373 | - |
|
1374 | - /** |
|
1375 | - * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
1376 | - * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
1377 | - * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
1378 | - * then return false. Otherwise return true. |
|
1379 | - * |
|
1380 | - * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1381 | - * @return bool true means can checkin. false means cannot checkin. |
|
1382 | - * @throws EE_Error |
|
1383 | - */ |
|
1384 | - public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
1385 | - { |
|
1386 | - $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1387 | - |
|
1388 | - if (! $DTT_ID) { |
|
1389 | - return false; |
|
1390 | - } |
|
1391 | - |
|
1392 | - $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
1393 | - |
|
1394 | - // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
1395 | - // check-in or not. |
|
1396 | - if (! $max_uses || $max_uses === EE_INF) { |
|
1397 | - return true; |
|
1398 | - } |
|
1399 | - |
|
1400 | - //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
1401 | - //go ahead and toggle. |
|
1402 | - if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1403 | - return true; |
|
1404 | - } |
|
1405 | - |
|
1406 | - //made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
1407 | - //disallows further check-ins. |
|
1408 | - $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( |
|
1409 | - array( |
|
1410 | - 'REG_ID' => $this->ID(), |
|
1411 | - 'CHK_in' => true, |
|
1412 | - ), |
|
1413 | - ), 'DTT_ID', true); |
|
1414 | - // checkins have already reached their max number of uses |
|
1415 | - // so registrant can NOT checkin |
|
1416 | - if ($count_unique_dtt_checkins >= $max_uses) { |
|
1417 | - EE_Error::add_error( |
|
1418 | - esc_html__( |
|
1419 | - 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
1420 | - 'event_espresso' |
|
1421 | - ), |
|
1422 | - __FILE__, |
|
1423 | - __FUNCTION__, |
|
1424 | - __LINE__ |
|
1425 | - ); |
|
1426 | - return false; |
|
1427 | - } |
|
1428 | - return true; |
|
1429 | - } |
|
1430 | - |
|
1431 | - |
|
1432 | - /** |
|
1433 | - * toggle Check-in status for this registration |
|
1434 | - * Check-ins are toggled in the following order: |
|
1435 | - * never checked in -> checked in |
|
1436 | - * checked in -> checked out |
|
1437 | - * checked out -> checked in |
|
1438 | - * |
|
1439 | - * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1440 | - * If not included or null, then it is assumed latest datetime is being toggled. |
|
1441 | - * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1442 | - * can be checked in or not. Otherwise this forces change in checkin status. |
|
1443 | - * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1444 | - * @throws EE_Error |
|
1445 | - */ |
|
1446 | - public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
1447 | - { |
|
1448 | - if (empty($DTT_ID)) { |
|
1449 | - $datetime = $this->get_latest_related_datetime(); |
|
1450 | - $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
1451 | - // verify the registration can checkin for the given DTT_ID |
|
1452 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1453 | - EE_Error::add_error( |
|
1454 | - sprintf( |
|
1455 | - esc_html__( |
|
1456 | - 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
1457 | - 'event_espresso' |
|
1458 | - ), |
|
1459 | - $this->ID(), |
|
1460 | - $DTT_ID |
|
1461 | - ), |
|
1462 | - __FILE__, |
|
1463 | - __FUNCTION__, |
|
1464 | - __LINE__ |
|
1465 | - ); |
|
1466 | - return false; |
|
1467 | - } |
|
1468 | - $status_paths = array( |
|
1469 | - EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
1470 | - EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
1471 | - EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
1472 | - ); |
|
1473 | - //start by getting the current status so we know what status we'll be changing to. |
|
1474 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
1475 | - $status_to = $status_paths[$cur_status]; |
|
1476 | - // database only records true for checked IN or false for checked OUT |
|
1477 | - // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
1478 | - $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
1479 | - // add relation - note Check-ins are always creating new rows |
|
1480 | - // because we are keeping track of Check-ins over time. |
|
1481 | - // Eventually we'll probably want to show a list table |
|
1482 | - // for the individual Check-ins so that they can be managed. |
|
1483 | - $checkin = EE_Checkin::new_instance(array( |
|
1484 | - 'REG_ID' => $this->ID(), |
|
1485 | - 'DTT_ID' => $DTT_ID, |
|
1486 | - 'CHK_in' => $new_status, |
|
1487 | - )); |
|
1488 | - // if the record could not be saved then return false |
|
1489 | - if ($checkin->save() === 0) { |
|
1490 | - if (WP_DEBUG) { |
|
1491 | - global $wpdb; |
|
1492 | - $error = sprintf( |
|
1493 | - esc_html__( |
|
1494 | - 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
1495 | - 'event_espresso' |
|
1496 | - ), |
|
1497 | - '<br />', |
|
1498 | - $wpdb->last_error |
|
1499 | - ); |
|
1500 | - } else { |
|
1501 | - $error = esc_html__( |
|
1502 | - 'Registration check in update failed because of an unknown database error', |
|
1503 | - 'event_espresso' |
|
1504 | - ); |
|
1505 | - } |
|
1506 | - EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1507 | - return false; |
|
1508 | - } |
|
1509 | - return $status_to; |
|
1510 | - } |
|
1511 | - |
|
1512 | - |
|
1513 | - /** |
|
1514 | - * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1515 | - * "Latest" is defined by the `DTT_EVT_start` column. |
|
1516 | - * |
|
1517 | - * @return EE_Datetime|null |
|
1518 | - * @throws EE_Error |
|
1519 | - */ |
|
1520 | - public function get_latest_related_datetime() |
|
1521 | - { |
|
1522 | - return EEM_Datetime::instance()->get_one( |
|
1523 | - array( |
|
1524 | - array( |
|
1525 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1526 | - ), |
|
1527 | - 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
1528 | - ) |
|
1529 | - ); |
|
1530 | - } |
|
1531 | - |
|
1532 | - |
|
1533 | - /** |
|
1534 | - * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1535 | - * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1536 | - * |
|
1537 | - * @throws EE_Error |
|
1538 | - */ |
|
1539 | - public function get_earliest_related_datetime() |
|
1540 | - { |
|
1541 | - return EEM_Datetime::instance()->get_one( |
|
1542 | - array( |
|
1543 | - array( |
|
1544 | - 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1545 | - ), |
|
1546 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1547 | - ) |
|
1548 | - ); |
|
1549 | - } |
|
1550 | - |
|
1551 | - |
|
1552 | - /** |
|
1553 | - * This method simply returns the check-in status for this registration and the given datetime. |
|
1554 | - * If neither the datetime nor the checkin values are provided as arguments, |
|
1555 | - * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1556 | - * |
|
1557 | - * @param int $DTT_ID The ID of the datetime we're checking against |
|
1558 | - * (if empty we'll get the primary datetime for |
|
1559 | - * this registration (via event) and use it's ID); |
|
1560 | - * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1561 | - * |
|
1562 | - * @return int Integer representing Check-in status. |
|
1563 | - * @throws EE_Error |
|
1564 | - */ |
|
1565 | - public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
1566 | - { |
|
1567 | - $checkin_query_params = array( |
|
1568 | - 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
1569 | - ); |
|
1570 | - |
|
1571 | - if ($DTT_ID > 0) { |
|
1572 | - $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1573 | - } |
|
1574 | - |
|
1575 | - //get checkin object (if exists) |
|
1576 | - $checkin = $checkin instanceof EE_Checkin |
|
1577 | - ? $checkin |
|
1578 | - : $this->get_first_related('Checkin', $checkin_query_params); |
|
1579 | - if ($checkin instanceof EE_Checkin) { |
|
1580 | - if ($checkin->get('CHK_in')) { |
|
1581 | - return EE_Checkin::status_checked_in; //checked in |
|
1582 | - } |
|
1583 | - return EE_Checkin::status_checked_out; //had checked in but is now checked out. |
|
1584 | - } |
|
1585 | - return EE_Checkin::status_checked_never; //never been checked in |
|
1586 | - } |
|
1587 | - |
|
1588 | - |
|
1589 | - /** |
|
1590 | - * This method returns a localized message for the toggled Check-in message. |
|
1591 | - * |
|
1592 | - * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
1593 | - * then it is assumed Check-in for primary datetime was toggled. |
|
1594 | - * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
1595 | - * message can be customized with the attendee name. |
|
1596 | - * @return string internationalized message |
|
1597 | - * @throws EE_Error |
|
1598 | - */ |
|
1599 | - public function get_checkin_msg($DTT_ID, $error = false) |
|
1600 | - { |
|
1601 | - //let's get the attendee first so we can include the name of the attendee |
|
1602 | - $attendee = $this->get_first_related('Attendee'); |
|
1603 | - if ($attendee instanceof EE_Attendee) { |
|
1604 | - if ($error) { |
|
1605 | - return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1606 | - } |
|
1607 | - $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1608 | - //what is the status message going to be? |
|
1609 | - switch ($cur_status) { |
|
1610 | - case EE_Checkin::status_checked_never: |
|
1611 | - return sprintf(__("%s has been removed from Check-in records", "event_espresso"), |
|
1612 | - $attendee->full_name()); |
|
1613 | - break; |
|
1614 | - case EE_Checkin::status_checked_in: |
|
1615 | - return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1616 | - break; |
|
1617 | - case EE_Checkin::status_checked_out: |
|
1618 | - return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1619 | - break; |
|
1620 | - } |
|
1621 | - } |
|
1622 | - return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
1623 | - } |
|
1624 | - |
|
1625 | - |
|
1626 | - /** |
|
1627 | - * Returns the related EE_Transaction to this registration |
|
1628 | - * |
|
1629 | - * @return EE_Transaction |
|
1630 | - * @throws EE_Error |
|
1631 | - * @throws EntityNotFoundException |
|
1632 | - */ |
|
1633 | - public function transaction() |
|
1634 | - { |
|
1635 | - $transaction = $this->get_first_related('Transaction'); |
|
1636 | - if (! $transaction instanceof \EE_Transaction) { |
|
1637 | - throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
1638 | - } |
|
1639 | - return $transaction; |
|
1640 | - } |
|
1641 | - |
|
1642 | - |
|
1643 | - /** |
|
1644 | - * get Registration Code |
|
1645 | - */ |
|
1646 | - public function reg_code() |
|
1647 | - { |
|
1648 | - return $this->get('REG_code'); |
|
1649 | - } |
|
1650 | - |
|
1651 | - |
|
1652 | - /** |
|
1653 | - * get Transaction ID |
|
1654 | - */ |
|
1655 | - public function transaction_ID() |
|
1656 | - { |
|
1657 | - return $this->get('TXN_ID'); |
|
1658 | - } |
|
1659 | - |
|
1660 | - |
|
1661 | - /** |
|
1662 | - * @return int |
|
1663 | - * @throws EE_Error |
|
1664 | - */ |
|
1665 | - public function ticket_ID() |
|
1666 | - { |
|
1667 | - return $this->get('TKT_ID'); |
|
1668 | - } |
|
1669 | - |
|
1670 | - |
|
1671 | - /** |
|
1672 | - * Set Registration Code |
|
1673 | - * |
|
1674 | - * @access public |
|
1675 | - * @param string $REG_code Registration Code |
|
1676 | - * @param boolean $use_default |
|
1677 | - * @throws EE_Error |
|
1678 | - */ |
|
1679 | - public function set_reg_code($REG_code, $use_default = false) |
|
1680 | - { |
|
1681 | - if (empty($REG_code)) { |
|
1682 | - EE_Error::add_error( |
|
1683 | - esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
1684 | - __FILE__, |
|
1685 | - __FUNCTION__, |
|
1686 | - __LINE__ |
|
1687 | - ); |
|
1688 | - return; |
|
1689 | - } |
|
1690 | - if (! $this->reg_code()) { |
|
1691 | - parent::set('REG_code', $REG_code, $use_default); |
|
1692 | - } else { |
|
1693 | - EE_Error::doing_it_wrong( |
|
1694 | - __CLASS__ . '::' . __FUNCTION__, |
|
1695 | - esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1696 | - '4.6.0' |
|
1697 | - ); |
|
1698 | - } |
|
1699 | - } |
|
1700 | - |
|
1701 | - |
|
1702 | - /** |
|
1703 | - * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
1704 | - * Note, if you want to just get all registrations in the same transaction (group), use: |
|
1705 | - * $registration->transaction()->registrations(); |
|
1706 | - * |
|
1707 | - * @since 4.5.0 |
|
1708 | - * @return EE_Registration[] or empty array if this isn't a group registration. |
|
1709 | - * @throws EE_Error |
|
1710 | - */ |
|
1711 | - public function get_all_other_registrations_in_group() |
|
1712 | - { |
|
1713 | - if ($this->group_size() < 2) { |
|
1714 | - return array(); |
|
1715 | - } |
|
1716 | - |
|
1717 | - $query[0] = array( |
|
1718 | - 'TXN_ID' => $this->transaction_ID(), |
|
1719 | - 'REG_ID' => array('!=', $this->ID()), |
|
1720 | - 'TKT_ID' => $this->ticket_ID(), |
|
1721 | - ); |
|
1722 | - /** @var EE_Registration[] $registrations */ |
|
1723 | - $registrations = $this->get_model()->get_all($query); |
|
1724 | - return $registrations; |
|
1725 | - } |
|
1726 | - |
|
1727 | - /** |
|
1728 | - * Return the link to the admin details for the object. |
|
1729 | - * |
|
1730 | - * @return string |
|
1731 | - * @throws EE_Error |
|
1732 | - */ |
|
1733 | - public function get_admin_details_link() |
|
1734 | - { |
|
1735 | - EE_Registry::instance()->load_helper('URL'); |
|
1736 | - return EEH_URL::add_query_args_and_nonce( |
|
1737 | - array( |
|
1738 | - 'page' => 'espresso_registrations', |
|
1739 | - 'action' => 'view_registration', |
|
1740 | - '_REG_ID' => $this->ID(), |
|
1741 | - ), |
|
1742 | - admin_url('admin.php') |
|
1743 | - ); |
|
1744 | - } |
|
1745 | - |
|
1746 | - /** |
|
1747 | - * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
1748 | - * |
|
1749 | - * @return string |
|
1750 | - * @throws EE_Error |
|
1751 | - */ |
|
1752 | - public function get_admin_edit_link() |
|
1753 | - { |
|
1754 | - return $this->get_admin_details_link(); |
|
1755 | - } |
|
1756 | - |
|
1757 | - /** |
|
1758 | - * Returns the link to a settings page for the object. |
|
1759 | - * |
|
1760 | - * @return string |
|
1761 | - * @throws EE_Error |
|
1762 | - */ |
|
1763 | - public function get_admin_settings_link() |
|
1764 | - { |
|
1765 | - return $this->get_admin_details_link(); |
|
1766 | - } |
|
1767 | - |
|
1768 | - /** |
|
1769 | - * Returns the link to the "overview" for the object (typically the "list table" view). |
|
1770 | - * |
|
1771 | - * @return string |
|
1772 | - */ |
|
1773 | - public function get_admin_overview_link() |
|
1774 | - { |
|
1775 | - EE_Registry::instance()->load_helper('URL'); |
|
1776 | - return EEH_URL::add_query_args_and_nonce( |
|
1777 | - array( |
|
1778 | - 'page' => 'espresso_registrations', |
|
1779 | - ), |
|
1780 | - admin_url('admin.php') |
|
1781 | - ); |
|
1782 | - } |
|
1783 | - |
|
1784 | - |
|
1785 | - /** |
|
1786 | - * @param array $query_params |
|
1787 | - * |
|
1788 | - * @return \EE_Registration[] |
|
1789 | - * @throws EE_Error |
|
1790 | - */ |
|
1791 | - public function payments($query_params = array()) |
|
1792 | - { |
|
1793 | - return $this->get_many_related('Payment', $query_params); |
|
1794 | - } |
|
1795 | - |
|
1796 | - |
|
1797 | - /** |
|
1798 | - * @param array $query_params |
|
1799 | - * |
|
1800 | - * @return \EE_Registration_Payment[] |
|
1801 | - * @throws EE_Error |
|
1802 | - */ |
|
1803 | - public function registration_payments($query_params = array()) |
|
1804 | - { |
|
1805 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
1806 | - } |
|
1807 | - |
|
1808 | - |
|
1809 | - /** |
|
1810 | - * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
1811 | - * Note: if there are no payments on the registration there will be no payment method returned. |
|
1812 | - * |
|
1813 | - * @return EE_Payment_Method|null |
|
1814 | - */ |
|
1815 | - public function payment_method() |
|
1816 | - { |
|
1817 | - return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1818 | - } |
|
1819 | - |
|
1820 | - |
|
1821 | - /** |
|
1822 | - * @return \EE_Line_Item |
|
1823 | - * @throws EntityNotFoundException |
|
1824 | - * @throws EE_Error |
|
1825 | - */ |
|
1826 | - public function ticket_line_item() |
|
1827 | - { |
|
1828 | - $ticket = $this->ticket(); |
|
1829 | - $transaction = $this->transaction(); |
|
1830 | - $line_item = null; |
|
1831 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
1832 | - $transaction->total_line_item(), |
|
1833 | - 'Ticket', |
|
1834 | - array($ticket->ID()) |
|
1835 | - ); |
|
1836 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
1837 | - if ( |
|
1838 | - $ticket_line_item instanceof \EE_Line_Item |
|
1839 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
1840 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
1841 | - ) { |
|
1842 | - $line_item = $ticket_line_item; |
|
1843 | - break; |
|
1844 | - } |
|
1845 | - } |
|
1846 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1847 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
1848 | - } |
|
1849 | - return $line_item; |
|
1850 | - } |
|
1851 | - |
|
1852 | - |
|
1853 | - /** |
|
1854 | - * Soft Deletes this model object. |
|
1855 | - * |
|
1856 | - * @return boolean | int |
|
1857 | - * @throws RuntimeException |
|
1858 | - * @throws EE_Error |
|
1859 | - */ |
|
1860 | - public function delete() |
|
1861 | - { |
|
1862 | - if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1863 | - $this->set_status(EEM_Registration::status_id_cancelled); |
|
1864 | - } |
|
1865 | - return parent::delete(); |
|
1866 | - } |
|
1867 | - |
|
1868 | - |
|
1869 | - /** |
|
1870 | - * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1871 | - * |
|
1872 | - * @throws EE_Error |
|
1873 | - * @throws RuntimeException |
|
1874 | - */ |
|
1875 | - public function restore() |
|
1876 | - { |
|
1877 | - $previous_status = $this->get_extra_meta( |
|
1878 | - EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1879 | - true, |
|
1880 | - EEM_Registration::status_id_cancelled |
|
1881 | - ); |
|
1882 | - if ($previous_status) { |
|
1883 | - $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1884 | - $this->set_status($previous_status); |
|
1885 | - } |
|
1886 | - return parent::restore(); |
|
1887 | - } |
|
1888 | - |
|
1889 | - |
|
1890 | - /** |
|
1891 | - * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
1892 | - * |
|
1893 | - * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
1894 | - * depending on whether the reg status changes to or from "Approved" |
|
1895 | - * @return boolean whether the Registration status was updated |
|
1896 | - * @throws EE_Error |
|
1897 | - * @throws RuntimeException |
|
1898 | - */ |
|
1899 | - public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
1900 | - { |
|
1901 | - $paid = $this->paid(); |
|
1902 | - $price = $this->final_price(); |
|
1903 | - switch(true) { |
|
1904 | - // overpaid or paid |
|
1905 | - case EEH_Money::compare_floats($paid, $price, '>'): |
|
1906 | - case EEH_Money::compare_floats($paid, $price): |
|
1907 | - $new_status = EEM_Registration::status_id_approved; |
|
1908 | - break; |
|
1909 | - // underpaid |
|
1910 | - case EEH_Money::compare_floats($paid, $price, '<'): |
|
1911 | - $new_status = EEM_Registration::status_id_pending_payment; |
|
1912 | - break; |
|
1913 | - // uhhh Houston... |
|
1914 | - default: |
|
1915 | - throw new RuntimeException( |
|
1916 | - esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
1917 | - ); |
|
1918 | - } |
|
1919 | - if ($new_status !== $this->status_ID()) { |
|
1920 | - if ($trigger_set_status_logic) { |
|
1921 | - return $this->set_status($new_status); |
|
1922 | - } |
|
1923 | - parent::set('STS_ID', $new_status); |
|
1924 | - return true; |
|
1925 | - } |
|
1926 | - return false; |
|
1927 | - } |
|
1928 | - |
|
1929 | - |
|
1930 | - /*************************** DEPRECATED ***************************/ |
|
1931 | - |
|
1932 | - |
|
1933 | - /** |
|
1934 | - * @deprecated |
|
1935 | - * @since 4.7.0 |
|
1936 | - * @access public |
|
1937 | - */ |
|
1938 | - public function price_paid() |
|
1939 | - { |
|
1940 | - EE_Error::doing_it_wrong('EE_Registration::price_paid()', |
|
1941 | - esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), |
|
1942 | - '4.7.0'); |
|
1943 | - return $this->final_price(); |
|
1944 | - } |
|
1945 | - |
|
1946 | - |
|
1947 | - /** |
|
1948 | - * @deprecated |
|
1949 | - * @since 4.7.0 |
|
1950 | - * @access public |
|
1951 | - * @param float $REG_final_price |
|
1952 | - * @throws EE_Error |
|
1953 | - * @throws RuntimeException |
|
1954 | - */ |
|
1955 | - public function set_price_paid($REG_final_price = 0.00) |
|
1956 | - { |
|
1957 | - EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', |
|
1958 | - esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), |
|
1959 | - '4.7.0'); |
|
1960 | - $this->set_final_price($REG_final_price); |
|
1961 | - } |
|
1962 | - |
|
1963 | - |
|
1964 | - /** |
|
1965 | - * @deprecated |
|
1966 | - * @since 4.7.0 |
|
1967 | - * @return string |
|
1968 | - * @throws EE_Error |
|
1969 | - */ |
|
1970 | - public function pretty_price_paid() |
|
1971 | - { |
|
1972 | - EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', |
|
1973 | - esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
1974 | - 'event_espresso'), '4.7.0'); |
|
1975 | - return $this->pretty_final_price(); |
|
1976 | - } |
|
1977 | - |
|
1978 | - |
|
1979 | - /** |
|
1980 | - * Gets the primary datetime related to this registration via the related Event to this registration |
|
1981 | - * |
|
1982 | - * @deprecated 4.9.17 |
|
1983 | - * @return EE_Datetime |
|
1984 | - * @throws EE_Error |
|
1985 | - * @throws EntityNotFoundException |
|
1986 | - */ |
|
1987 | - public function get_related_primary_datetime() |
|
1988 | - { |
|
1989 | - EE_Error::doing_it_wrong( |
|
1990 | - __METHOD__, |
|
1991 | - esc_html__( |
|
1992 | - 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
1993 | - 'event_espresso' |
|
1994 | - ), |
|
1995 | - '4.9.17', |
|
1996 | - '5.0.0' |
|
1997 | - ); |
|
1998 | - return $this->event()->primary_datetime(); |
|
1999 | - } |
|
21 | + /** |
|
22 | + * Used to reference when a registration has never been checked in. |
|
23 | + * |
|
24 | + * @deprecated use \EE_Checkin::status_checked_never instead |
|
25 | + * @type int |
|
26 | + */ |
|
27 | + const checkin_status_never = 2; |
|
28 | + |
|
29 | + /** |
|
30 | + * Used to reference when a registration has been checked in. |
|
31 | + * |
|
32 | + * @deprecated use \EE_Checkin::status_checked_in instead |
|
33 | + * @type int |
|
34 | + */ |
|
35 | + const checkin_status_in = 1; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Used to reference when a registration has been checked out. |
|
40 | + * |
|
41 | + * @deprecated use \EE_Checkin::status_checked_out instead |
|
42 | + * @type int |
|
43 | + */ |
|
44 | + const checkin_status_out = 0; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * extra meta key for tracking reg status os trashed registrations |
|
49 | + * |
|
50 | + * @type string |
|
51 | + */ |
|
52 | + const PRE_TRASH_REG_STATUS_KEY = 'pre_trash_registration_status'; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * extra meta key for tracking if registration has reserved ticket |
|
57 | + * |
|
58 | + * @type string |
|
59 | + */ |
|
60 | + const HAS_RESERVED_TICKET_KEY = 'has_reserved_ticket'; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @param array $props_n_values incoming values |
|
65 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
66 | + * used.) |
|
67 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
68 | + * date_format and the second value is the time format |
|
69 | + * @return EE_Registration |
|
70 | + * @throws EE_Error |
|
71 | + */ |
|
72 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
73 | + { |
|
74 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
75 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param array $props_n_values incoming values from the database |
|
81 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
82 | + * the website will be used. |
|
83 | + * @return EE_Registration |
|
84 | + */ |
|
85 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
86 | + { |
|
87 | + return new self($props_n_values, true, $timezone); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Set Event ID |
|
93 | + * |
|
94 | + * @param int $EVT_ID Event ID |
|
95 | + * @throws EE_Error |
|
96 | + * @throws RuntimeException |
|
97 | + */ |
|
98 | + public function set_event($EVT_ID = 0) |
|
99 | + { |
|
100 | + $this->set('EVT_ID', $EVT_ID); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Overrides parent set() method so that all calls to set( 'REG_code', $REG_code ) OR set( 'STS_ID', $STS_ID ) can |
|
106 | + * be routed to internal methods |
|
107 | + * |
|
108 | + * @param string $field_name |
|
109 | + * @param mixed $field_value |
|
110 | + * @param bool $use_default |
|
111 | + * @throws EE_Error |
|
112 | + * @throws EntityNotFoundException |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + * @throws ReflectionException |
|
117 | + * @throws RuntimeException |
|
118 | + */ |
|
119 | + public function set($field_name, $field_value, $use_default = false) |
|
120 | + { |
|
121 | + switch ($field_name) { |
|
122 | + case 'REG_code': |
|
123 | + if (! empty($field_value) && $this->reg_code() === null) { |
|
124 | + $this->set_reg_code($field_value, $use_default); |
|
125 | + } |
|
126 | + break; |
|
127 | + case 'STS_ID': |
|
128 | + $this->set_status($field_value, $use_default); |
|
129 | + break; |
|
130 | + default: |
|
131 | + parent::set($field_name, $field_value, $use_default); |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * Set Status ID |
|
138 | + * updates the registration status and ALSO... |
|
139 | + * calls reserve_registration_space() if the reg status changes TO approved from any other reg status |
|
140 | + * calls release_registration_space() if the reg status changes FROM approved to any other reg status |
|
141 | + * |
|
142 | + * @param string $new_STS_ID |
|
143 | + * @param boolean $use_default |
|
144 | + * @param Context|null $context |
|
145 | + * @return bool |
|
146 | + * @throws EE_Error |
|
147 | + * @throws EntityNotFoundException |
|
148 | + * @throws InvalidArgumentException |
|
149 | + * @throws ReflectionException |
|
150 | + * @throws RuntimeException |
|
151 | + * @throws InvalidDataTypeException |
|
152 | + * @throws InvalidInterfaceException |
|
153 | + */ |
|
154 | + public function set_status($new_STS_ID = null, $use_default = false, Context $context = null) |
|
155 | + { |
|
156 | + // get current REG_Status |
|
157 | + $old_STS_ID = $this->status_ID(); |
|
158 | + // if status has changed |
|
159 | + if ($old_STS_ID !== $new_STS_ID // and that status has actually changed |
|
160 | + && ! empty($old_STS_ID) // and that old status is actually set |
|
161 | + && ! empty($new_STS_ID) // as well as the new status |
|
162 | + && $this->ID() // ensure registration is in the db |
|
163 | + ) { |
|
164 | + // TO approved |
|
165 | + if ($new_STS_ID === EEM_Registration::status_id_approved) { |
|
166 | + // reserve a space by incrementing ticket and datetime sold values |
|
167 | + $this->_reserve_registration_space(); |
|
168 | + do_action('AHEE__EE_Registration__set_status__to_approved', $this, $old_STS_ID, $new_STS_ID, $context); |
|
169 | + // OR FROM approved |
|
170 | + } elseif ($old_STS_ID === EEM_Registration::status_id_approved) { |
|
171 | + // release a space by decrementing ticket and datetime sold values |
|
172 | + $this->_release_registration_space(); |
|
173 | + do_action( |
|
174 | + 'AHEE__EE_Registration__set_status__from_approved', |
|
175 | + $this, |
|
176 | + $old_STS_ID, |
|
177 | + $new_STS_ID, |
|
178 | + $context |
|
179 | + ); |
|
180 | + } |
|
181 | + // update status |
|
182 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
183 | + $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
|
184 | + if($this->statusChangeUpdatesTransaction($context)) { |
|
185 | + $this->updateTransactionAfterStatusChange(); |
|
186 | + } |
|
187 | + do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
|
188 | + return true; |
|
189 | + } |
|
190 | + //even though the old value matches the new value, it's still good to |
|
191 | + //allow the parent set method to have a say |
|
192 | + parent::set('STS_ID', $new_STS_ID, $use_default); |
|
193 | + return true; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * update REGs and TXN when cancelled or declined registrations involved |
|
199 | + * |
|
200 | + * @param string $new_STS_ID |
|
201 | + * @param string $old_STS_ID |
|
202 | + * @param Context|null $context |
|
203 | + * @throws EE_Error |
|
204 | + * @throws InvalidArgumentException |
|
205 | + * @throws InvalidDataTypeException |
|
206 | + * @throws InvalidInterfaceException |
|
207 | + * @throws ReflectionException |
|
208 | + */ |
|
209 | + private function _update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, Context $context = null) |
|
210 | + { |
|
211 | + // these reg statuses should not be considered in any calculations involving monies owing |
|
212 | + $closed_reg_statuses = EEM_Registration::closed_reg_statuses(); |
|
213 | + // true if registration has been cancelled or declined |
|
214 | + $this->updateIfCanceled( |
|
215 | + $closed_reg_statuses, |
|
216 | + $new_STS_ID, |
|
217 | + $old_STS_ID, |
|
218 | + $context |
|
219 | + ); |
|
220 | + $this->updateIfDeclined( |
|
221 | + $closed_reg_statuses, |
|
222 | + $new_STS_ID, |
|
223 | + $old_STS_ID, |
|
224 | + $context |
|
225 | + ); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * update REGs and TXN when cancelled or declined registrations involved |
|
231 | + * |
|
232 | + * @param array $closed_reg_statuses |
|
233 | + * @param string $new_STS_ID |
|
234 | + * @param string $old_STS_ID |
|
235 | + * @param Context|null $context |
|
236 | + * @throws EE_Error |
|
237 | + * @throws InvalidArgumentException |
|
238 | + * @throws InvalidDataTypeException |
|
239 | + * @throws InvalidInterfaceException |
|
240 | + * @throws ReflectionException |
|
241 | + */ |
|
242 | + private function updateIfCanceled(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, Context $context = null) |
|
243 | + { |
|
244 | + // true if registration has been cancelled or declined |
|
245 | + if (in_array($new_STS_ID, $closed_reg_statuses, true) |
|
246 | + && ! in_array($old_STS_ID, $closed_reg_statuses, true) |
|
247 | + ) { |
|
248 | + /** @type EE_Registration_Processor $registration_processor */ |
|
249 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
250 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
251 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
252 | + // cancelled or declined registration |
|
253 | + $registration_processor->update_registration_after_being_canceled_or_declined( |
|
254 | + $this, |
|
255 | + $closed_reg_statuses |
|
256 | + ); |
|
257 | + $transaction_processor->update_transaction_after_canceled_or_declined_registration( |
|
258 | + $this, |
|
259 | + $closed_reg_statuses, |
|
260 | + false |
|
261 | + ); |
|
262 | + do_action( |
|
263 | + 'AHEE__EE_Registration__set_status__canceled_or_declined', |
|
264 | + $this, |
|
265 | + $old_STS_ID, |
|
266 | + $new_STS_ID, |
|
267 | + $context |
|
268 | + ); |
|
269 | + return; |
|
270 | + } |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * update REGs and TXN when cancelled or declined registrations involved |
|
276 | + * |
|
277 | + * @param array $closed_reg_statuses |
|
278 | + * @param string $new_STS_ID |
|
279 | + * @param string $old_STS_ID |
|
280 | + * @param Context|null $context |
|
281 | + * @throws EE_Error |
|
282 | + * @throws InvalidArgumentException |
|
283 | + * @throws InvalidDataTypeException |
|
284 | + * @throws InvalidInterfaceException |
|
285 | + * @throws ReflectionException |
|
286 | + */ |
|
287 | + private function updateIfDeclined(array $closed_reg_statuses, $new_STS_ID, $old_STS_ID, Context $context = null) |
|
288 | + { |
|
289 | + // true if reinstating cancelled or declined registration |
|
290 | + if (in_array($old_STS_ID, $closed_reg_statuses, true) |
|
291 | + && ! in_array($new_STS_ID, $closed_reg_statuses, true) |
|
292 | + ) { |
|
293 | + /** @type EE_Registration_Processor $registration_processor */ |
|
294 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
295 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
296 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
297 | + // reinstating cancelled or declined registration |
|
298 | + $registration_processor->update_canceled_or_declined_registration_after_being_reinstated( |
|
299 | + $this, |
|
300 | + $closed_reg_statuses |
|
301 | + ); |
|
302 | + $transaction_processor->update_transaction_after_reinstating_canceled_registration( |
|
303 | + $this, |
|
304 | + $closed_reg_statuses, |
|
305 | + false |
|
306 | + ); |
|
307 | + do_action( |
|
308 | + 'AHEE__EE_Registration__set_status__after_reinstated', |
|
309 | + $this, |
|
310 | + $old_STS_ID, |
|
311 | + $new_STS_ID, |
|
312 | + $context |
|
313 | + ); |
|
314 | + } |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @param Context|null $context |
|
320 | + * @return bool |
|
321 | + */ |
|
322 | + private function statusChangeUpdatesTransaction(Context $context = null) |
|
323 | + { |
|
324 | + $contexts_that_do_not_update_transaction = (array) apply_filters( |
|
325 | + 'AHEE__EE_Registration__statusChangeUpdatesTransaction__contexts_that_do_not_update_transaction', |
|
326 | + array('spco_reg_step_attendee_information_process_registrations'), |
|
327 | + $context, |
|
328 | + $this |
|
329 | + ); |
|
330 | + return ! ( |
|
331 | + $context instanceof Context |
|
332 | + && in_array($context->slug(), $contexts_that_do_not_update_transaction, true) |
|
333 | + ); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * @throws EE_Error |
|
339 | + * @throws EntityNotFoundException |
|
340 | + * @throws InvalidArgumentException |
|
341 | + * @throws InvalidDataTypeException |
|
342 | + * @throws InvalidInterfaceException |
|
343 | + * @throws ReflectionException |
|
344 | + * @throws RuntimeException |
|
345 | + */ |
|
346 | + private function updateTransactionAfterStatusChange() |
|
347 | + { |
|
348 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
349 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
350 | + $transaction_payments->recalculate_transaction_total($this->transaction(), false); |
|
351 | + $this->transaction()->update_status_based_on_total_paid(true); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * get Status ID |
|
357 | + */ |
|
358 | + public function status_ID() |
|
359 | + { |
|
360 | + return $this->get('STS_ID'); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * increments this registration's related ticket sold and corresponding datetime sold values |
|
366 | + * |
|
367 | + * @return void |
|
368 | + * @throws EE_Error |
|
369 | + * @throws EntityNotFoundException |
|
370 | + */ |
|
371 | + private function _reserve_registration_space() |
|
372 | + { |
|
373 | + // reserved ticket and datetime counts will be decremented as sold counts are incremented |
|
374 | + // so stop tracking that this reg has a ticket reserved |
|
375 | + $this->release_reserved_ticket(); |
|
376 | + $ticket = $this->ticket(); |
|
377 | + $ticket->increase_sold(); |
|
378 | + $ticket->save(); |
|
379 | + // possibly set event status to sold out |
|
380 | + $this->event()->perform_sold_out_status_check(); |
|
381 | + } |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * Gets the ticket this registration is for |
|
386 | + * |
|
387 | + * @param boolean $include_archived whether to include archived tickets or not. |
|
388 | + * |
|
389 | + * @return EE_Ticket|EE_Base_Class |
|
390 | + * @throws EE_Error |
|
391 | + */ |
|
392 | + public function ticket($include_archived = true) |
|
393 | + { |
|
394 | + $query_params = array(); |
|
395 | + if ($include_archived) { |
|
396 | + $query_params['default_where_conditions'] = 'none'; |
|
397 | + } |
|
398 | + return $this->get_first_related('Ticket', $query_params); |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * Gets the event this registration is for |
|
404 | + * |
|
405 | + * @return EE_Event |
|
406 | + * @throws EE_Error |
|
407 | + * @throws EntityNotFoundException |
|
408 | + */ |
|
409 | + public function event() |
|
410 | + { |
|
411 | + $event = $this->get_first_related('Event'); |
|
412 | + if (! $event instanceof \EE_Event) { |
|
413 | + throw new EntityNotFoundException('Event ID', $this->event_ID()); |
|
414 | + } |
|
415 | + return $event; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * Gets the "author" of the registration. Note that for the purposes of registrations, the author will correspond |
|
421 | + * with the author of the event this registration is for. |
|
422 | + * |
|
423 | + * @since 4.5.0 |
|
424 | + * @return int |
|
425 | + * @throws EE_Error |
|
426 | + * @throws EntityNotFoundException |
|
427 | + */ |
|
428 | + public function wp_user() |
|
429 | + { |
|
430 | + $event = $this->event(); |
|
431 | + if ($event instanceof EE_Event) { |
|
432 | + return $event->wp_user(); |
|
433 | + } |
|
434 | + return 0; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * decrements (subtracts) this registration's related ticket sold and corresponding datetime sold values |
|
440 | + * |
|
441 | + * @return void |
|
442 | + * @throws EE_Error |
|
443 | + */ |
|
444 | + private function _release_registration_space() |
|
445 | + { |
|
446 | + $ticket = $this->ticket(); |
|
447 | + $ticket->decrease_sold(); |
|
448 | + $ticket->save(); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + /** |
|
453 | + * tracks this registration's ticket reservation in extra meta |
|
454 | + * and can increment related ticket reserved and corresponding datetime reserved values |
|
455 | + * |
|
456 | + * @param bool $update_ticket if true, will increment ticket and datetime reserved count |
|
457 | + * |
|
458 | + * @return void |
|
459 | + * @throws EE_Error |
|
460 | + */ |
|
461 | + public function reserve_ticket($update_ticket = false) |
|
462 | + { |
|
463 | + if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) === false) { |
|
464 | + // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
465 | + // we NEED to ALWAYS call update_extra_meta(), which is why that is done first |
|
466 | + if ($this->update_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) && $update_ticket) { |
|
467 | + $ticket = $this->ticket(); |
|
468 | + $ticket->increase_reserved(); |
|
469 | + $ticket->save(); |
|
470 | + } |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + /** |
|
476 | + * stops tracking this registration's ticket reservation in extra meta |
|
477 | + * decrements (subtracts) related ticket reserved and corresponding datetime reserved values |
|
478 | + * |
|
479 | + * @param bool $update_ticket if true, will decrement ticket and datetime reserved count |
|
480 | + * |
|
481 | + * @return void |
|
482 | + * @throws EE_Error |
|
483 | + */ |
|
484 | + public function release_reserved_ticket($update_ticket = false) |
|
485 | + { |
|
486 | + if ($this->get_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY, true, false) !== false) { |
|
487 | + // PLZ NOTE: although checking $update_ticket first would be more efficient, |
|
488 | + // we NEED to ALWAYS call delete_extra_meta(), which is why that is done first |
|
489 | + if ($this->delete_extra_meta(EE_Registration::HAS_RESERVED_TICKET_KEY) && $update_ticket) { |
|
490 | + $ticket = $this->ticket(); |
|
491 | + $ticket->decrease_reserved(); |
|
492 | + $ticket->save(); |
|
493 | + } |
|
494 | + } |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * Set Attendee ID |
|
500 | + * |
|
501 | + * @param int $ATT_ID Attendee ID |
|
502 | + * @throws EE_Error |
|
503 | + * @throws RuntimeException |
|
504 | + */ |
|
505 | + public function set_attendee_id($ATT_ID = 0) |
|
506 | + { |
|
507 | + $this->set('ATT_ID', $ATT_ID); |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * Set Transaction ID |
|
513 | + * |
|
514 | + * @param int $TXN_ID Transaction ID |
|
515 | + * @throws EE_Error |
|
516 | + * @throws RuntimeException |
|
517 | + */ |
|
518 | + public function set_transaction_id($TXN_ID = 0) |
|
519 | + { |
|
520 | + $this->set('TXN_ID', $TXN_ID); |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + /** |
|
525 | + * Set Session |
|
526 | + * |
|
527 | + * @param string $REG_session PHP Session ID |
|
528 | + * @throws EE_Error |
|
529 | + * @throws RuntimeException |
|
530 | + */ |
|
531 | + public function set_session($REG_session = '') |
|
532 | + { |
|
533 | + $this->set('REG_session', $REG_session); |
|
534 | + } |
|
535 | + |
|
536 | + |
|
537 | + /** |
|
538 | + * Set Registration URL Link |
|
539 | + * |
|
540 | + * @param string $REG_url_link Registration URL Link |
|
541 | + * @throws EE_Error |
|
542 | + * @throws RuntimeException |
|
543 | + */ |
|
544 | + public function set_reg_url_link($REG_url_link = '') |
|
545 | + { |
|
546 | + $this->set('REG_url_link', $REG_url_link); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * Set Attendee Counter |
|
552 | + * |
|
553 | + * @param int $REG_count Primary Attendee |
|
554 | + * @throws EE_Error |
|
555 | + * @throws RuntimeException |
|
556 | + */ |
|
557 | + public function set_count($REG_count = 1) |
|
558 | + { |
|
559 | + $this->set('REG_count', $REG_count); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * Set Group Size |
|
565 | + * |
|
566 | + * @param boolean $REG_group_size Group Registration |
|
567 | + * @throws EE_Error |
|
568 | + * @throws RuntimeException |
|
569 | + */ |
|
570 | + public function set_group_size($REG_group_size = false) |
|
571 | + { |
|
572 | + $this->set('REG_group_size', $REG_group_size); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + /** |
|
577 | + * is_not_approved - convenience method that returns TRUE if REG status ID == |
|
578 | + * EEM_Registration::status_id_not_approved |
|
579 | + * |
|
580 | + * @return boolean |
|
581 | + */ |
|
582 | + public function is_not_approved() |
|
583 | + { |
|
584 | + return $this->status_ID() == EEM_Registration::status_id_not_approved ? true : false; |
|
585 | + } |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * is_pending_payment - convenience method that returns TRUE if REG status ID == |
|
590 | + * EEM_Registration::status_id_pending_payment |
|
591 | + * |
|
592 | + * @return boolean |
|
593 | + */ |
|
594 | + public function is_pending_payment() |
|
595 | + { |
|
596 | + return $this->status_ID() == EEM_Registration::status_id_pending_payment ? true : false; |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * is_approved - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_approved |
|
602 | + * |
|
603 | + * @return boolean |
|
604 | + */ |
|
605 | + public function is_approved() |
|
606 | + { |
|
607 | + return $this->status_ID() == EEM_Registration::status_id_approved ? true : false; |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * is_cancelled - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_cancelled |
|
613 | + * |
|
614 | + * @return boolean |
|
615 | + */ |
|
616 | + public function is_cancelled() |
|
617 | + { |
|
618 | + return $this->status_ID() == EEM_Registration::status_id_cancelled ? true : false; |
|
619 | + } |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * is_declined - convenience method that returns TRUE if REG status ID == EEM_Registration::status_id_declined |
|
624 | + * |
|
625 | + * @return boolean |
|
626 | + */ |
|
627 | + public function is_declined() |
|
628 | + { |
|
629 | + return $this->status_ID() == EEM_Registration::status_id_declined ? true : false; |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + /** |
|
634 | + * is_incomplete - convenience method that returns TRUE if REG status ID == |
|
635 | + * EEM_Registration::status_id_incomplete |
|
636 | + * |
|
637 | + * @return boolean |
|
638 | + */ |
|
639 | + public function is_incomplete() |
|
640 | + { |
|
641 | + return $this->status_ID() == EEM_Registration::status_id_incomplete ? true : false; |
|
642 | + } |
|
643 | + |
|
644 | + |
|
645 | + /** |
|
646 | + * Set Registration Date |
|
647 | + * |
|
648 | + * @param mixed ( int or string ) $REG_date Registration Date - Unix timestamp or string representation of |
|
649 | + * Date |
|
650 | + * @throws EE_Error |
|
651 | + * @throws RuntimeException |
|
652 | + */ |
|
653 | + public function set_reg_date($REG_date = false) |
|
654 | + { |
|
655 | + $this->set('REG_date', $REG_date); |
|
656 | + } |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * Set final price owing for this registration after all ticket/price modifications |
|
661 | + * |
|
662 | + * @access public |
|
663 | + * @param float $REG_final_price |
|
664 | + * @throws EE_Error |
|
665 | + * @throws RuntimeException |
|
666 | + */ |
|
667 | + public function set_final_price($REG_final_price = 0.00) |
|
668 | + { |
|
669 | + $this->set('REG_final_price', $REG_final_price); |
|
670 | + } |
|
671 | + |
|
672 | + |
|
673 | + /** |
|
674 | + * Set amount paid towards this registration's final price |
|
675 | + * |
|
676 | + * @access public |
|
677 | + * @param float $REG_paid |
|
678 | + * @throws EE_Error |
|
679 | + * @throws RuntimeException |
|
680 | + */ |
|
681 | + public function set_paid($REG_paid = 0.00) |
|
682 | + { |
|
683 | + $this->set('REG_paid', $REG_paid); |
|
684 | + } |
|
685 | + |
|
686 | + |
|
687 | + /** |
|
688 | + * Attendee Is Going |
|
689 | + * |
|
690 | + * @param boolean $REG_att_is_going Attendee Is Going |
|
691 | + * @throws EE_Error |
|
692 | + * @throws RuntimeException |
|
693 | + */ |
|
694 | + public function set_att_is_going($REG_att_is_going = false) |
|
695 | + { |
|
696 | + $this->set('REG_att_is_going', $REG_att_is_going); |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + /** |
|
701 | + * Gets the related attendee |
|
702 | + * |
|
703 | + * @return EE_Attendee |
|
704 | + * @throws EE_Error |
|
705 | + */ |
|
706 | + public function attendee() |
|
707 | + { |
|
708 | + return $this->get_first_related('Attendee'); |
|
709 | + } |
|
710 | + |
|
711 | + |
|
712 | + /** |
|
713 | + * get Event ID |
|
714 | + */ |
|
715 | + public function event_ID() |
|
716 | + { |
|
717 | + return $this->get('EVT_ID'); |
|
718 | + } |
|
719 | + |
|
720 | + |
|
721 | + /** |
|
722 | + * get Event ID |
|
723 | + */ |
|
724 | + public function event_name() |
|
725 | + { |
|
726 | + $event = $this->event_obj(); |
|
727 | + if ($event) { |
|
728 | + return $event->name(); |
|
729 | + } else { |
|
730 | + return null; |
|
731 | + } |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * Fetches the event this registration is for |
|
737 | + * |
|
738 | + * @return EE_Event |
|
739 | + * @throws EE_Error |
|
740 | + */ |
|
741 | + public function event_obj() |
|
742 | + { |
|
743 | + return $this->get_first_related('Event'); |
|
744 | + } |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * get Attendee ID |
|
749 | + */ |
|
750 | + public function attendee_ID() |
|
751 | + { |
|
752 | + return $this->get('ATT_ID'); |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + /** |
|
757 | + * get PHP Session ID |
|
758 | + */ |
|
759 | + public function session_ID() |
|
760 | + { |
|
761 | + return $this->get('REG_session'); |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + /** |
|
766 | + * Gets the string which represents the URL trigger for the receipt template in the message template system. |
|
767 | + * |
|
768 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
769 | + * @return string |
|
770 | + */ |
|
771 | + public function receipt_url($messenger = 'html') |
|
772 | + { |
|
773 | + |
|
774 | + /** |
|
775 | + * The below will be deprecated one version after this. We check first if there is a custom receipt template |
|
776 | + * already in use on old system. If there is then we just return the standard url for it. |
|
777 | + * |
|
778 | + * @since 4.5.0 |
|
779 | + */ |
|
780 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/receipt_body.template.php'; |
|
781 | + $has_custom = EEH_Template::locate_template( |
|
782 | + $template_relative_path, |
|
783 | + array(), |
|
784 | + true, |
|
785 | + true, |
|
786 | + true |
|
787 | + ); |
|
788 | + |
|
789 | + if ($has_custom) { |
|
790 | + return add_query_arg(array('receipt' => 'true'), $this->invoice_url('launch')); |
|
791 | + } |
|
792 | + return apply_filters('FHEE__EE_Registration__receipt_url__receipt_url', '', $this, $messenger, 'receipt'); |
|
793 | + } |
|
794 | + |
|
795 | + |
|
796 | + /** |
|
797 | + * Gets the string which represents the URL trigger for the invoice template in the message template system. |
|
798 | + * |
|
799 | + * @param string $messenger 'pdf' or 'html'. Default 'html'. |
|
800 | + * @return string |
|
801 | + * @throws EE_Error |
|
802 | + */ |
|
803 | + public function invoice_url($messenger = 'html') |
|
804 | + { |
|
805 | + /** |
|
806 | + * The below will be deprecated one version after this. We check first if there is a custom invoice template |
|
807 | + * already in use on old system. If there is then we just return the standard url for it. |
|
808 | + * |
|
809 | + * @since 4.5.0 |
|
810 | + */ |
|
811 | + $template_relative_path = 'modules/gateways/Invoice/lib/templates/invoice_body.template.php'; |
|
812 | + $has_custom = EEH_Template::locate_template( |
|
813 | + $template_relative_path, |
|
814 | + array(), |
|
815 | + true, |
|
816 | + true, |
|
817 | + true |
|
818 | + ); |
|
819 | + |
|
820 | + if ($has_custom) { |
|
821 | + if ($messenger == 'html') { |
|
822 | + return $this->invoice_url('launch'); |
|
823 | + } |
|
824 | + $route = $messenger == 'download' || $messenger == 'pdf' ? 'download_invoice' : 'launch_invoice'; |
|
825 | + |
|
826 | + $query_args = array('ee' => $route, 'id' => $this->reg_url_link()); |
|
827 | + if ($messenger == 'html') { |
|
828 | + $query_args['html'] = true; |
|
829 | + } |
|
830 | + return add_query_arg($query_args, get_permalink(EE_Registry::instance()->CFG->core->thank_you_page_id)); |
|
831 | + } |
|
832 | + return apply_filters('FHEE__EE_Registration__invoice_url__invoice_url', '', $this, $messenger, 'invoice'); |
|
833 | + } |
|
834 | + |
|
835 | + |
|
836 | + /** |
|
837 | + * get Registration URL Link |
|
838 | + * |
|
839 | + * @access public |
|
840 | + * @return string |
|
841 | + * @throws EE_Error |
|
842 | + */ |
|
843 | + public function reg_url_link() |
|
844 | + { |
|
845 | + return (string) $this->get('REG_url_link'); |
|
846 | + } |
|
847 | + |
|
848 | + |
|
849 | + /** |
|
850 | + * Echoes out invoice_url() |
|
851 | + * |
|
852 | + * @param string $type 'download','launch', or 'html' (default is 'launch') |
|
853 | + * @return void |
|
854 | + * @throws EE_Error |
|
855 | + */ |
|
856 | + public function e_invoice_url($type = 'launch') |
|
857 | + { |
|
858 | + echo $this->invoice_url($type); |
|
859 | + } |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * Echoes out payment_overview_url |
|
864 | + */ |
|
865 | + public function e_payment_overview_url() |
|
866 | + { |
|
867 | + echo $this->payment_overview_url(); |
|
868 | + } |
|
869 | + |
|
870 | + |
|
871 | + /** |
|
872 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
873 | + * a query parameter |
|
874 | + * |
|
875 | + * @param bool $clear_session Set to true when you want to clear the session on revisiting the |
|
876 | + * payment overview url. |
|
877 | + * @return string |
|
878 | + * @throws EE_Error |
|
879 | + */ |
|
880 | + public function payment_overview_url($clear_session = false) |
|
881 | + { |
|
882 | + return add_query_arg(array( |
|
883 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
884 | + 'step' => 'payment_options', |
|
885 | + 'revisit' => true, |
|
886 | + 'clear_session' => (bool) $clear_session |
|
887 | + ), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
888 | + } |
|
889 | + |
|
890 | + |
|
891 | + /** |
|
892 | + * Gets the URL of the thank you page with this registration REG_url_link added as |
|
893 | + * a query parameter |
|
894 | + * |
|
895 | + * @return string |
|
896 | + * @throws EE_Error |
|
897 | + */ |
|
898 | + public function edit_attendee_information_url() |
|
899 | + { |
|
900 | + return add_query_arg(array( |
|
901 | + 'e_reg_url_link' => $this->reg_url_link(), |
|
902 | + 'step' => 'attendee_information', |
|
903 | + 'revisit' => true, |
|
904 | + ), EE_Registry::instance()->CFG->core->reg_page_url()); |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + /** |
|
909 | + * Simply generates and returns the appropriate admin_url link to edit this registration |
|
910 | + * |
|
911 | + * @return string |
|
912 | + * @throws EE_Error |
|
913 | + */ |
|
914 | + public function get_admin_edit_url() |
|
915 | + { |
|
916 | + return EEH_URL::add_query_args_and_nonce(array( |
|
917 | + 'page' => 'espresso_registrations', |
|
918 | + 'action' => 'view_registration', |
|
919 | + '_REG_ID' => $this->ID(), |
|
920 | + ), admin_url('admin.php')); |
|
921 | + } |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * is_primary_registrant? |
|
926 | + */ |
|
927 | + public function is_primary_registrant() |
|
928 | + { |
|
929 | + return $this->get('REG_count') == 1 ? true : false; |
|
930 | + } |
|
931 | + |
|
932 | + |
|
933 | + /** |
|
934 | + * This returns the primary registration object for this registration group (which may be this object). |
|
935 | + * |
|
936 | + * @return EE_Registration |
|
937 | + * @throws EE_Error |
|
938 | + */ |
|
939 | + public function get_primary_registration() |
|
940 | + { |
|
941 | + if ($this->is_primary_registrant()) { |
|
942 | + return $this; |
|
943 | + } |
|
944 | + |
|
945 | + //k reg_count !== 1 so let's get the EE_Registration object matching this txn_id and reg_count == 1 |
|
946 | + /** @var EE_Registration $primary_registrant */ |
|
947 | + $primary_registrant = EEM_Registration::instance()->get_one(array( |
|
948 | + array( |
|
949 | + 'TXN_ID' => $this->transaction_ID(), |
|
950 | + 'REG_count' => 1, |
|
951 | + ), |
|
952 | + )); |
|
953 | + return $primary_registrant; |
|
954 | + } |
|
955 | + |
|
956 | + |
|
957 | + /** |
|
958 | + * get Attendee Number |
|
959 | + * |
|
960 | + * @access public |
|
961 | + */ |
|
962 | + public function count() |
|
963 | + { |
|
964 | + return $this->get('REG_count'); |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + /** |
|
969 | + * get Group Size |
|
970 | + */ |
|
971 | + public function group_size() |
|
972 | + { |
|
973 | + return $this->get('REG_group_size'); |
|
974 | + } |
|
975 | + |
|
976 | + |
|
977 | + /** |
|
978 | + * get Registration Date |
|
979 | + */ |
|
980 | + public function date() |
|
981 | + { |
|
982 | + return $this->get('REG_date'); |
|
983 | + } |
|
984 | + |
|
985 | + |
|
986 | + /** |
|
987 | + * gets a pretty date |
|
988 | + * |
|
989 | + * @param string $date_format |
|
990 | + * @param string $time_format |
|
991 | + * @return string |
|
992 | + * @throws EE_Error |
|
993 | + */ |
|
994 | + public function pretty_date($date_format = null, $time_format = null) |
|
995 | + { |
|
996 | + return $this->get_datetime('REG_date', $date_format, $time_format); |
|
997 | + } |
|
998 | + |
|
999 | + |
|
1000 | + /** |
|
1001 | + * final_price |
|
1002 | + * the registration's share of the transaction total, so that the |
|
1003 | + * sum of all the transaction's REG_final_prices equal the transaction's total |
|
1004 | + * |
|
1005 | + * @return float |
|
1006 | + * @throws EE_Error |
|
1007 | + */ |
|
1008 | + public function final_price() |
|
1009 | + { |
|
1010 | + return $this->get('REG_final_price'); |
|
1011 | + } |
|
1012 | + |
|
1013 | + |
|
1014 | + /** |
|
1015 | + * pretty_final_price |
|
1016 | + * final price as formatted string, with correct decimal places and currency symbol |
|
1017 | + * |
|
1018 | + * @return string |
|
1019 | + * @throws EE_Error |
|
1020 | + */ |
|
1021 | + public function pretty_final_price() |
|
1022 | + { |
|
1023 | + return $this->get_pretty('REG_final_price'); |
|
1024 | + } |
|
1025 | + |
|
1026 | + |
|
1027 | + /** |
|
1028 | + * get paid (yeah) |
|
1029 | + * |
|
1030 | + * @return float |
|
1031 | + * @throws EE_Error |
|
1032 | + */ |
|
1033 | + public function paid() |
|
1034 | + { |
|
1035 | + return $this->get('REG_paid'); |
|
1036 | + } |
|
1037 | + |
|
1038 | + |
|
1039 | + /** |
|
1040 | + * pretty_paid |
|
1041 | + * |
|
1042 | + * @return float |
|
1043 | + * @throws EE_Error |
|
1044 | + */ |
|
1045 | + public function pretty_paid() |
|
1046 | + { |
|
1047 | + return $this->get_pretty('REG_paid'); |
|
1048 | + } |
|
1049 | + |
|
1050 | + |
|
1051 | + /** |
|
1052 | + * owes_monies_and_can_pay |
|
1053 | + * whether or not this registration has monies owing and it's' status allows payment |
|
1054 | + * |
|
1055 | + * @param array $requires_payment |
|
1056 | + * @return bool |
|
1057 | + * @throws EE_Error |
|
1058 | + */ |
|
1059 | + public function owes_monies_and_can_pay($requires_payment = array()) |
|
1060 | + { |
|
1061 | + // these reg statuses require payment (if event is not free) |
|
1062 | + $requires_payment = ! empty($requires_payment) |
|
1063 | + ? $requires_payment |
|
1064 | + : EEM_Registration::reg_statuses_that_allow_payment(); |
|
1065 | + if (in_array($this->status_ID(), $requires_payment) && |
|
1066 | + $this->final_price() != 0 && |
|
1067 | + $this->final_price() != $this->paid() |
|
1068 | + ) { |
|
1069 | + return true; |
|
1070 | + } else { |
|
1071 | + return false; |
|
1072 | + } |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + /** |
|
1077 | + * Prints out the return value of $this->pretty_status() |
|
1078 | + * |
|
1079 | + * @param bool $show_icons |
|
1080 | + * @return void |
|
1081 | + * @throws EE_Error |
|
1082 | + */ |
|
1083 | + public function e_pretty_status($show_icons = false) |
|
1084 | + { |
|
1085 | + echo $this->pretty_status($show_icons); |
|
1086 | + } |
|
1087 | + |
|
1088 | + |
|
1089 | + /** |
|
1090 | + * Returns a nice version of the status for displaying to customers |
|
1091 | + * |
|
1092 | + * @param bool $show_icons |
|
1093 | + * @return string |
|
1094 | + * @throws EE_Error |
|
1095 | + */ |
|
1096 | + public function pretty_status($show_icons = false) |
|
1097 | + { |
|
1098 | + $status = EEM_Status::instance()->localized_status( |
|
1099 | + array($this->status_ID() => esc_html__('unknown', 'event_espresso')), |
|
1100 | + false, |
|
1101 | + 'sentence' |
|
1102 | + ); |
|
1103 | + $icon = ''; |
|
1104 | + switch ($this->status_ID()) { |
|
1105 | + case EEM_Registration::status_id_approved: |
|
1106 | + $icon = $show_icons |
|
1107 | + ? '<span class="dashicons dashicons-star-filled ee-icon-size-16 green-text"></span>' |
|
1108 | + : ''; |
|
1109 | + break; |
|
1110 | + case EEM_Registration::status_id_pending_payment: |
|
1111 | + $icon = $show_icons |
|
1112 | + ? '<span class="dashicons dashicons-star-half ee-icon-size-16 orange-text"></span>' |
|
1113 | + : ''; |
|
1114 | + break; |
|
1115 | + case EEM_Registration::status_id_not_approved: |
|
1116 | + $icon = $show_icons |
|
1117 | + ? '<span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>' |
|
1118 | + : ''; |
|
1119 | + break; |
|
1120 | + case EEM_Registration::status_id_cancelled: |
|
1121 | + $icon = $show_icons |
|
1122 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
1123 | + : ''; |
|
1124 | + break; |
|
1125 | + case EEM_Registration::status_id_incomplete: |
|
1126 | + $icon = $show_icons |
|
1127 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-orange-text"></span>' |
|
1128 | + : ''; |
|
1129 | + break; |
|
1130 | + case EEM_Registration::status_id_declined: |
|
1131 | + $icon = $show_icons |
|
1132 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
1133 | + : ''; |
|
1134 | + break; |
|
1135 | + case EEM_Registration::status_id_wait_list: |
|
1136 | + $icon = $show_icons |
|
1137 | + ? '<span class="dashicons dashicons-clipboard ee-icon-size-16 purple-text"></span>' |
|
1138 | + : ''; |
|
1139 | + break; |
|
1140 | + } |
|
1141 | + return $icon . $status[$this->status_ID()]; |
|
1142 | + } |
|
1143 | + |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * get Attendee Is Going |
|
1147 | + */ |
|
1148 | + public function att_is_going() |
|
1149 | + { |
|
1150 | + return $this->get('REG_att_is_going'); |
|
1151 | + } |
|
1152 | + |
|
1153 | + |
|
1154 | + /** |
|
1155 | + * Gets related answers |
|
1156 | + * |
|
1157 | + * @param array $query_params like EEM_Base::get_all |
|
1158 | + * @return EE_Answer[] |
|
1159 | + * @throws EE_Error |
|
1160 | + */ |
|
1161 | + public function answers($query_params = null) |
|
1162 | + { |
|
1163 | + return $this->get_many_related('Answer', $query_params); |
|
1164 | + } |
|
1165 | + |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * Gets the registration's answer value to the specified question |
|
1169 | + * (either the question's ID or a question object) |
|
1170 | + * |
|
1171 | + * @param EE_Question|int $question |
|
1172 | + * @param bool $pretty_value |
|
1173 | + * @return array|string if pretty_value= true, the result will always be a string |
|
1174 | + * (because the answer might be an array of answer values, so passing pretty_value=true |
|
1175 | + * will convert it into some kind of string) |
|
1176 | + * @throws EE_Error |
|
1177 | + */ |
|
1178 | + public function answer_value_to_question($question, $pretty_value = true) |
|
1179 | + { |
|
1180 | + $question_id = EEM_Question::instance()->ensure_is_ID($question); |
|
1181 | + return EEM_Answer::instance()->get_answer_value_to_question($this, $question_id, $pretty_value); |
|
1182 | + } |
|
1183 | + |
|
1184 | + |
|
1185 | + /** |
|
1186 | + * question_groups |
|
1187 | + * returns an array of EE_Question_Group objects for this registration |
|
1188 | + * |
|
1189 | + * @return EE_Question_Group[] |
|
1190 | + * @throws EE_Error |
|
1191 | + * @throws EntityNotFoundException |
|
1192 | + */ |
|
1193 | + public function question_groups() |
|
1194 | + { |
|
1195 | + $question_groups = array(); |
|
1196 | + if ($this->event() instanceof EE_Event) { |
|
1197 | + $question_groups = $this->event()->question_groups( |
|
1198 | + array( |
|
1199 | + array( |
|
1200 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
1201 | + ), |
|
1202 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
1203 | + ) |
|
1204 | + ); |
|
1205 | + } |
|
1206 | + return $question_groups; |
|
1207 | + } |
|
1208 | + |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * count_question_groups |
|
1212 | + * returns a count of the number of EE_Question_Group objects for this registration |
|
1213 | + * |
|
1214 | + * @return int |
|
1215 | + * @throws EE_Error |
|
1216 | + * @throws EntityNotFoundException |
|
1217 | + */ |
|
1218 | + public function count_question_groups() |
|
1219 | + { |
|
1220 | + $qg_count = 0; |
|
1221 | + if ($this->event() instanceof EE_Event) { |
|
1222 | + $qg_count = $this->event()->count_related( |
|
1223 | + 'Question_Group', |
|
1224 | + array( |
|
1225 | + array( |
|
1226 | + 'Event_Question_Group.EQG_primary' => $this->count() == 1 ? true : false, |
|
1227 | + ), |
|
1228 | + ) |
|
1229 | + ); |
|
1230 | + } |
|
1231 | + return $qg_count; |
|
1232 | + } |
|
1233 | + |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * Returns the registration date in the 'standard' string format |
|
1237 | + * (function may be improved in the future to allow for different formats and timezones) |
|
1238 | + * |
|
1239 | + * @return string |
|
1240 | + * @throws EE_Error |
|
1241 | + */ |
|
1242 | + public function reg_date() |
|
1243 | + { |
|
1244 | + return $this->get_datetime('REG_date'); |
|
1245 | + } |
|
1246 | + |
|
1247 | + |
|
1248 | + /** |
|
1249 | + * Gets the datetime-ticket for this registration (ie, it can be used to isolate |
|
1250 | + * the ticket this registration purchased, or the datetime they have registered |
|
1251 | + * to attend) |
|
1252 | + * |
|
1253 | + * @return EE_Datetime_Ticket |
|
1254 | + * @throws EE_Error |
|
1255 | + */ |
|
1256 | + public function datetime_ticket() |
|
1257 | + { |
|
1258 | + return $this->get_first_related('Datetime_Ticket'); |
|
1259 | + } |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * Sets the registration's datetime_ticket. |
|
1264 | + * |
|
1265 | + * @param EE_Datetime_Ticket $datetime_ticket |
|
1266 | + * @return EE_Datetime_Ticket |
|
1267 | + * @throws EE_Error |
|
1268 | + */ |
|
1269 | + public function set_datetime_ticket($datetime_ticket) |
|
1270 | + { |
|
1271 | + return $this->_add_relation_to($datetime_ticket, 'Datetime_Ticket'); |
|
1272 | + } |
|
1273 | + |
|
1274 | + /** |
|
1275 | + * Gets deleted |
|
1276 | + * |
|
1277 | + * @return bool |
|
1278 | + * @throws EE_Error |
|
1279 | + */ |
|
1280 | + public function deleted() |
|
1281 | + { |
|
1282 | + return $this->get('REG_deleted'); |
|
1283 | + } |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * Sets deleted |
|
1287 | + * |
|
1288 | + * @param boolean $deleted |
|
1289 | + * @return bool |
|
1290 | + * @throws EE_Error |
|
1291 | + * @throws RuntimeException |
|
1292 | + */ |
|
1293 | + public function set_deleted($deleted) |
|
1294 | + { |
|
1295 | + if ($deleted) { |
|
1296 | + $this->delete(); |
|
1297 | + } else { |
|
1298 | + $this->restore(); |
|
1299 | + } |
|
1300 | + } |
|
1301 | + |
|
1302 | + |
|
1303 | + /** |
|
1304 | + * Get the status object of this object |
|
1305 | + * |
|
1306 | + * @return EE_Status |
|
1307 | + * @throws EE_Error |
|
1308 | + */ |
|
1309 | + public function status_obj() |
|
1310 | + { |
|
1311 | + return $this->get_first_related('Status'); |
|
1312 | + } |
|
1313 | + |
|
1314 | + |
|
1315 | + /** |
|
1316 | + * Returns the number of times this registration has checked into any of the datetimes |
|
1317 | + * its available for |
|
1318 | + * |
|
1319 | + * @return int |
|
1320 | + * @throws EE_Error |
|
1321 | + */ |
|
1322 | + public function count_checkins() |
|
1323 | + { |
|
1324 | + return $this->get_model()->count_related($this, 'Checkin'); |
|
1325 | + } |
|
1326 | + |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * Returns the number of current Check-ins this registration is checked into for any of the datetimes the |
|
1330 | + * registration is for. Note, this is ONLY checked in (does not include checkedout) |
|
1331 | + * |
|
1332 | + * @return int |
|
1333 | + * @throws EE_Error |
|
1334 | + */ |
|
1335 | + public function count_checkins_not_checkedout() |
|
1336 | + { |
|
1337 | + return $this->get_model()->count_related($this, 'Checkin', array(array('CHK_in' => 1))); |
|
1338 | + } |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * The purpose of this method is simply to check whether this registration can checkin to the given datetime. |
|
1343 | + * |
|
1344 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1345 | + * @param bool $check_approved This is used to indicate whether the caller wants can_checkin to also |
|
1346 | + * consider registration status as well as datetime access. |
|
1347 | + * @return bool |
|
1348 | + * @throws EE_Error |
|
1349 | + */ |
|
1350 | + public function can_checkin($DTT_OR_ID, $check_approved = true) |
|
1351 | + { |
|
1352 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1353 | + |
|
1354 | + //first check registration status |
|
1355 | + if (($check_approved && ! $this->is_approved()) || ! $DTT_ID) { |
|
1356 | + return false; |
|
1357 | + } |
|
1358 | + //is there a datetime ticket that matches this dtt_ID? |
|
1359 | + if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
1360 | + array( |
|
1361 | + 'TKT_ID' => $this->get('TKT_ID'), |
|
1362 | + 'DTT_ID' => $DTT_ID, |
|
1363 | + ), |
|
1364 | + ))) |
|
1365 | + ) { |
|
1366 | + return false; |
|
1367 | + } |
|
1368 | + |
|
1369 | + //final check is against TKT_uses |
|
1370 | + return $this->verify_can_checkin_against_TKT_uses($DTT_ID); |
|
1371 | + } |
|
1372 | + |
|
1373 | + |
|
1374 | + /** |
|
1375 | + * This method verifies whether the user can checkin for the given datetime considering the max uses value set on |
|
1376 | + * the ticket. To do this, a query is done to get the count of the datetime records already checked into. If the |
|
1377 | + * datetime given does not have a check-in record and checking in for that datetime will exceed the allowed uses, |
|
1378 | + * then return false. Otherwise return true. |
|
1379 | + * |
|
1380 | + * @param int | EE_Datetime $DTT_OR_ID The datetime the registration is being checked against |
|
1381 | + * @return bool true means can checkin. false means cannot checkin. |
|
1382 | + * @throws EE_Error |
|
1383 | + */ |
|
1384 | + public function verify_can_checkin_against_TKT_uses($DTT_OR_ID) |
|
1385 | + { |
|
1386 | + $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
|
1387 | + |
|
1388 | + if (! $DTT_ID) { |
|
1389 | + return false; |
|
1390 | + } |
|
1391 | + |
|
1392 | + $max_uses = $this->ticket() instanceof EE_Ticket ? $this->ticket()->uses() : EE_INF; |
|
1393 | + |
|
1394 | + // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
|
1395 | + // check-in or not. |
|
1396 | + if (! $max_uses || $max_uses === EE_INF) { |
|
1397 | + return true; |
|
1398 | + } |
|
1399 | + |
|
1400 | + //does this datetime have a checkin record? If so, then the dtt count has already been verified so we can just |
|
1401 | + //go ahead and toggle. |
|
1402 | + if (EEM_Checkin::instance()->exists(array(array('REG_ID' => $this->ID(), 'DTT_ID' => $DTT_ID)))) { |
|
1403 | + return true; |
|
1404 | + } |
|
1405 | + |
|
1406 | + //made it here so the last check is whether the number of checkins per unique datetime on this registration |
|
1407 | + //disallows further check-ins. |
|
1408 | + $count_unique_dtt_checkins = EEM_Checkin::instance()->count(array( |
|
1409 | + array( |
|
1410 | + 'REG_ID' => $this->ID(), |
|
1411 | + 'CHK_in' => true, |
|
1412 | + ), |
|
1413 | + ), 'DTT_ID', true); |
|
1414 | + // checkins have already reached their max number of uses |
|
1415 | + // so registrant can NOT checkin |
|
1416 | + if ($count_unique_dtt_checkins >= $max_uses) { |
|
1417 | + EE_Error::add_error( |
|
1418 | + esc_html__( |
|
1419 | + 'Check-in denied because number of datetime uses for the ticket has been reached or exceeded.', |
|
1420 | + 'event_espresso' |
|
1421 | + ), |
|
1422 | + __FILE__, |
|
1423 | + __FUNCTION__, |
|
1424 | + __LINE__ |
|
1425 | + ); |
|
1426 | + return false; |
|
1427 | + } |
|
1428 | + return true; |
|
1429 | + } |
|
1430 | + |
|
1431 | + |
|
1432 | + /** |
|
1433 | + * toggle Check-in status for this registration |
|
1434 | + * Check-ins are toggled in the following order: |
|
1435 | + * never checked in -> checked in |
|
1436 | + * checked in -> checked out |
|
1437 | + * checked out -> checked in |
|
1438 | + * |
|
1439 | + * @param int $DTT_ID include specific datetime to toggle Check-in for. |
|
1440 | + * If not included or null, then it is assumed latest datetime is being toggled. |
|
1441 | + * @param bool $verify If true then can_checkin() is used to verify whether the person |
|
1442 | + * can be checked in or not. Otherwise this forces change in checkin status. |
|
1443 | + * @return bool|int the chk_in status toggled to OR false if nothing got changed. |
|
1444 | + * @throws EE_Error |
|
1445 | + */ |
|
1446 | + public function toggle_checkin_status($DTT_ID = null, $verify = false) |
|
1447 | + { |
|
1448 | + if (empty($DTT_ID)) { |
|
1449 | + $datetime = $this->get_latest_related_datetime(); |
|
1450 | + $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
|
1451 | + // verify the registration can checkin for the given DTT_ID |
|
1452 | + } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1453 | + EE_Error::add_error( |
|
1454 | + sprintf( |
|
1455 | + esc_html__( |
|
1456 | + 'The given registration (ID:%1$d) can not be checked in to the given DTT_ID (%2$d), because the registration does not have access', |
|
1457 | + 'event_espresso' |
|
1458 | + ), |
|
1459 | + $this->ID(), |
|
1460 | + $DTT_ID |
|
1461 | + ), |
|
1462 | + __FILE__, |
|
1463 | + __FUNCTION__, |
|
1464 | + __LINE__ |
|
1465 | + ); |
|
1466 | + return false; |
|
1467 | + } |
|
1468 | + $status_paths = array( |
|
1469 | + EE_Checkin::status_checked_never => EE_Checkin::status_checked_in, |
|
1470 | + EE_Checkin::status_checked_in => EE_Checkin::status_checked_out, |
|
1471 | + EE_Checkin::status_checked_out => EE_Checkin::status_checked_in, |
|
1472 | + ); |
|
1473 | + //start by getting the current status so we know what status we'll be changing to. |
|
1474 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID, null); |
|
1475 | + $status_to = $status_paths[$cur_status]; |
|
1476 | + // database only records true for checked IN or false for checked OUT |
|
1477 | + // no record ( null ) means checked in NEVER, but we obviously don't save that |
|
1478 | + $new_status = $status_to === EE_Checkin::status_checked_in ? true : false; |
|
1479 | + // add relation - note Check-ins are always creating new rows |
|
1480 | + // because we are keeping track of Check-ins over time. |
|
1481 | + // Eventually we'll probably want to show a list table |
|
1482 | + // for the individual Check-ins so that they can be managed. |
|
1483 | + $checkin = EE_Checkin::new_instance(array( |
|
1484 | + 'REG_ID' => $this->ID(), |
|
1485 | + 'DTT_ID' => $DTT_ID, |
|
1486 | + 'CHK_in' => $new_status, |
|
1487 | + )); |
|
1488 | + // if the record could not be saved then return false |
|
1489 | + if ($checkin->save() === 0) { |
|
1490 | + if (WP_DEBUG) { |
|
1491 | + global $wpdb; |
|
1492 | + $error = sprintf( |
|
1493 | + esc_html__( |
|
1494 | + 'Registration check in update failed because of the following database error: %1$s%2$s', |
|
1495 | + 'event_espresso' |
|
1496 | + ), |
|
1497 | + '<br />', |
|
1498 | + $wpdb->last_error |
|
1499 | + ); |
|
1500 | + } else { |
|
1501 | + $error = esc_html__( |
|
1502 | + 'Registration check in update failed because of an unknown database error', |
|
1503 | + 'event_espresso' |
|
1504 | + ); |
|
1505 | + } |
|
1506 | + EE_Error::add_error($error, __FILE__, __FUNCTION__, __LINE__); |
|
1507 | + return false; |
|
1508 | + } |
|
1509 | + return $status_to; |
|
1510 | + } |
|
1511 | + |
|
1512 | + |
|
1513 | + /** |
|
1514 | + * Returns the latest datetime related to this registration (via the ticket attached to the registration). |
|
1515 | + * "Latest" is defined by the `DTT_EVT_start` column. |
|
1516 | + * |
|
1517 | + * @return EE_Datetime|null |
|
1518 | + * @throws EE_Error |
|
1519 | + */ |
|
1520 | + public function get_latest_related_datetime() |
|
1521 | + { |
|
1522 | + return EEM_Datetime::instance()->get_one( |
|
1523 | + array( |
|
1524 | + array( |
|
1525 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1526 | + ), |
|
1527 | + 'order_by' => array('DTT_EVT_start' => 'DESC'), |
|
1528 | + ) |
|
1529 | + ); |
|
1530 | + } |
|
1531 | + |
|
1532 | + |
|
1533 | + /** |
|
1534 | + * Returns the earliest datetime related to this registration (via the ticket attached to the registration). |
|
1535 | + * "Earliest" is defined by the `DTT_EVT_start` column. |
|
1536 | + * |
|
1537 | + * @throws EE_Error |
|
1538 | + */ |
|
1539 | + public function get_earliest_related_datetime() |
|
1540 | + { |
|
1541 | + return EEM_Datetime::instance()->get_one( |
|
1542 | + array( |
|
1543 | + array( |
|
1544 | + 'Ticket.Registration.REG_ID' => $this->ID(), |
|
1545 | + ), |
|
1546 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
1547 | + ) |
|
1548 | + ); |
|
1549 | + } |
|
1550 | + |
|
1551 | + |
|
1552 | + /** |
|
1553 | + * This method simply returns the check-in status for this registration and the given datetime. |
|
1554 | + * If neither the datetime nor the checkin values are provided as arguments, |
|
1555 | + * then this will return the LATEST check-in status for the registration across all datetimes it belongs to. |
|
1556 | + * |
|
1557 | + * @param int $DTT_ID The ID of the datetime we're checking against |
|
1558 | + * (if empty we'll get the primary datetime for |
|
1559 | + * this registration (via event) and use it's ID); |
|
1560 | + * @param EE_Checkin $checkin If present, we use the given checkin object rather than the dtt_id. |
|
1561 | + * |
|
1562 | + * @return int Integer representing Check-in status. |
|
1563 | + * @throws EE_Error |
|
1564 | + */ |
|
1565 | + public function check_in_status_for_datetime($DTT_ID = 0, $checkin = null) |
|
1566 | + { |
|
1567 | + $checkin_query_params = array( |
|
1568 | + 'order_by' => array('CHK_timestamp' => 'DESC'), |
|
1569 | + ); |
|
1570 | + |
|
1571 | + if ($DTT_ID > 0) { |
|
1572 | + $checkin_query_params[0] = array('DTT_ID' => $DTT_ID); |
|
1573 | + } |
|
1574 | + |
|
1575 | + //get checkin object (if exists) |
|
1576 | + $checkin = $checkin instanceof EE_Checkin |
|
1577 | + ? $checkin |
|
1578 | + : $this->get_first_related('Checkin', $checkin_query_params); |
|
1579 | + if ($checkin instanceof EE_Checkin) { |
|
1580 | + if ($checkin->get('CHK_in')) { |
|
1581 | + return EE_Checkin::status_checked_in; //checked in |
|
1582 | + } |
|
1583 | + return EE_Checkin::status_checked_out; //had checked in but is now checked out. |
|
1584 | + } |
|
1585 | + return EE_Checkin::status_checked_never; //never been checked in |
|
1586 | + } |
|
1587 | + |
|
1588 | + |
|
1589 | + /** |
|
1590 | + * This method returns a localized message for the toggled Check-in message. |
|
1591 | + * |
|
1592 | + * @param int $DTT_ID include specific datetime to get the correct Check-in message. If not included or null, |
|
1593 | + * then it is assumed Check-in for primary datetime was toggled. |
|
1594 | + * @param bool $error This just flags that you want an error message returned. This is put in so that the error |
|
1595 | + * message can be customized with the attendee name. |
|
1596 | + * @return string internationalized message |
|
1597 | + * @throws EE_Error |
|
1598 | + */ |
|
1599 | + public function get_checkin_msg($DTT_ID, $error = false) |
|
1600 | + { |
|
1601 | + //let's get the attendee first so we can include the name of the attendee |
|
1602 | + $attendee = $this->get_first_related('Attendee'); |
|
1603 | + if ($attendee instanceof EE_Attendee) { |
|
1604 | + if ($error) { |
|
1605 | + return sprintf(__("%s's check-in status was not changed.", "event_espresso"), $attendee->full_name()); |
|
1606 | + } |
|
1607 | + $cur_status = $this->check_in_status_for_datetime($DTT_ID); |
|
1608 | + //what is the status message going to be? |
|
1609 | + switch ($cur_status) { |
|
1610 | + case EE_Checkin::status_checked_never: |
|
1611 | + return sprintf(__("%s has been removed from Check-in records", "event_espresso"), |
|
1612 | + $attendee->full_name()); |
|
1613 | + break; |
|
1614 | + case EE_Checkin::status_checked_in: |
|
1615 | + return sprintf(__('%s has been checked in', 'event_espresso'), $attendee->full_name()); |
|
1616 | + break; |
|
1617 | + case EE_Checkin::status_checked_out: |
|
1618 | + return sprintf(__('%s has been checked out', 'event_espresso'), $attendee->full_name()); |
|
1619 | + break; |
|
1620 | + } |
|
1621 | + } |
|
1622 | + return esc_html__("The check-in status could not be determined.", "event_espresso"); |
|
1623 | + } |
|
1624 | + |
|
1625 | + |
|
1626 | + /** |
|
1627 | + * Returns the related EE_Transaction to this registration |
|
1628 | + * |
|
1629 | + * @return EE_Transaction |
|
1630 | + * @throws EE_Error |
|
1631 | + * @throws EntityNotFoundException |
|
1632 | + */ |
|
1633 | + public function transaction() |
|
1634 | + { |
|
1635 | + $transaction = $this->get_first_related('Transaction'); |
|
1636 | + if (! $transaction instanceof \EE_Transaction) { |
|
1637 | + throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
|
1638 | + } |
|
1639 | + return $transaction; |
|
1640 | + } |
|
1641 | + |
|
1642 | + |
|
1643 | + /** |
|
1644 | + * get Registration Code |
|
1645 | + */ |
|
1646 | + public function reg_code() |
|
1647 | + { |
|
1648 | + return $this->get('REG_code'); |
|
1649 | + } |
|
1650 | + |
|
1651 | + |
|
1652 | + /** |
|
1653 | + * get Transaction ID |
|
1654 | + */ |
|
1655 | + public function transaction_ID() |
|
1656 | + { |
|
1657 | + return $this->get('TXN_ID'); |
|
1658 | + } |
|
1659 | + |
|
1660 | + |
|
1661 | + /** |
|
1662 | + * @return int |
|
1663 | + * @throws EE_Error |
|
1664 | + */ |
|
1665 | + public function ticket_ID() |
|
1666 | + { |
|
1667 | + return $this->get('TKT_ID'); |
|
1668 | + } |
|
1669 | + |
|
1670 | + |
|
1671 | + /** |
|
1672 | + * Set Registration Code |
|
1673 | + * |
|
1674 | + * @access public |
|
1675 | + * @param string $REG_code Registration Code |
|
1676 | + * @param boolean $use_default |
|
1677 | + * @throws EE_Error |
|
1678 | + */ |
|
1679 | + public function set_reg_code($REG_code, $use_default = false) |
|
1680 | + { |
|
1681 | + if (empty($REG_code)) { |
|
1682 | + EE_Error::add_error( |
|
1683 | + esc_html__('REG_code can not be empty.', 'event_espresso'), |
|
1684 | + __FILE__, |
|
1685 | + __FUNCTION__, |
|
1686 | + __LINE__ |
|
1687 | + ); |
|
1688 | + return; |
|
1689 | + } |
|
1690 | + if (! $this->reg_code()) { |
|
1691 | + parent::set('REG_code', $REG_code, $use_default); |
|
1692 | + } else { |
|
1693 | + EE_Error::doing_it_wrong( |
|
1694 | + __CLASS__ . '::' . __FUNCTION__, |
|
1695 | + esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
|
1696 | + '4.6.0' |
|
1697 | + ); |
|
1698 | + } |
|
1699 | + } |
|
1700 | + |
|
1701 | + |
|
1702 | + /** |
|
1703 | + * Returns all other registrations in the same group as this registrant who have the same ticket option. |
|
1704 | + * Note, if you want to just get all registrations in the same transaction (group), use: |
|
1705 | + * $registration->transaction()->registrations(); |
|
1706 | + * |
|
1707 | + * @since 4.5.0 |
|
1708 | + * @return EE_Registration[] or empty array if this isn't a group registration. |
|
1709 | + * @throws EE_Error |
|
1710 | + */ |
|
1711 | + public function get_all_other_registrations_in_group() |
|
1712 | + { |
|
1713 | + if ($this->group_size() < 2) { |
|
1714 | + return array(); |
|
1715 | + } |
|
1716 | + |
|
1717 | + $query[0] = array( |
|
1718 | + 'TXN_ID' => $this->transaction_ID(), |
|
1719 | + 'REG_ID' => array('!=', $this->ID()), |
|
1720 | + 'TKT_ID' => $this->ticket_ID(), |
|
1721 | + ); |
|
1722 | + /** @var EE_Registration[] $registrations */ |
|
1723 | + $registrations = $this->get_model()->get_all($query); |
|
1724 | + return $registrations; |
|
1725 | + } |
|
1726 | + |
|
1727 | + /** |
|
1728 | + * Return the link to the admin details for the object. |
|
1729 | + * |
|
1730 | + * @return string |
|
1731 | + * @throws EE_Error |
|
1732 | + */ |
|
1733 | + public function get_admin_details_link() |
|
1734 | + { |
|
1735 | + EE_Registry::instance()->load_helper('URL'); |
|
1736 | + return EEH_URL::add_query_args_and_nonce( |
|
1737 | + array( |
|
1738 | + 'page' => 'espresso_registrations', |
|
1739 | + 'action' => 'view_registration', |
|
1740 | + '_REG_ID' => $this->ID(), |
|
1741 | + ), |
|
1742 | + admin_url('admin.php') |
|
1743 | + ); |
|
1744 | + } |
|
1745 | + |
|
1746 | + /** |
|
1747 | + * Returns the link to the editor for the object. Sometimes this is the same as the details. |
|
1748 | + * |
|
1749 | + * @return string |
|
1750 | + * @throws EE_Error |
|
1751 | + */ |
|
1752 | + public function get_admin_edit_link() |
|
1753 | + { |
|
1754 | + return $this->get_admin_details_link(); |
|
1755 | + } |
|
1756 | + |
|
1757 | + /** |
|
1758 | + * Returns the link to a settings page for the object. |
|
1759 | + * |
|
1760 | + * @return string |
|
1761 | + * @throws EE_Error |
|
1762 | + */ |
|
1763 | + public function get_admin_settings_link() |
|
1764 | + { |
|
1765 | + return $this->get_admin_details_link(); |
|
1766 | + } |
|
1767 | + |
|
1768 | + /** |
|
1769 | + * Returns the link to the "overview" for the object (typically the "list table" view). |
|
1770 | + * |
|
1771 | + * @return string |
|
1772 | + */ |
|
1773 | + public function get_admin_overview_link() |
|
1774 | + { |
|
1775 | + EE_Registry::instance()->load_helper('URL'); |
|
1776 | + return EEH_URL::add_query_args_and_nonce( |
|
1777 | + array( |
|
1778 | + 'page' => 'espresso_registrations', |
|
1779 | + ), |
|
1780 | + admin_url('admin.php') |
|
1781 | + ); |
|
1782 | + } |
|
1783 | + |
|
1784 | + |
|
1785 | + /** |
|
1786 | + * @param array $query_params |
|
1787 | + * |
|
1788 | + * @return \EE_Registration[] |
|
1789 | + * @throws EE_Error |
|
1790 | + */ |
|
1791 | + public function payments($query_params = array()) |
|
1792 | + { |
|
1793 | + return $this->get_many_related('Payment', $query_params); |
|
1794 | + } |
|
1795 | + |
|
1796 | + |
|
1797 | + /** |
|
1798 | + * @param array $query_params |
|
1799 | + * |
|
1800 | + * @return \EE_Registration_Payment[] |
|
1801 | + * @throws EE_Error |
|
1802 | + */ |
|
1803 | + public function registration_payments($query_params = array()) |
|
1804 | + { |
|
1805 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
1806 | + } |
|
1807 | + |
|
1808 | + |
|
1809 | + /** |
|
1810 | + * This grabs the payment method corresponding to the last payment made for the amount owing on the registration. |
|
1811 | + * Note: if there are no payments on the registration there will be no payment method returned. |
|
1812 | + * |
|
1813 | + * @return EE_Payment_Method|null |
|
1814 | + */ |
|
1815 | + public function payment_method() |
|
1816 | + { |
|
1817 | + return EEM_Payment_Method::instance()->get_last_used_for_registration($this); |
|
1818 | + } |
|
1819 | + |
|
1820 | + |
|
1821 | + /** |
|
1822 | + * @return \EE_Line_Item |
|
1823 | + * @throws EntityNotFoundException |
|
1824 | + * @throws EE_Error |
|
1825 | + */ |
|
1826 | + public function ticket_line_item() |
|
1827 | + { |
|
1828 | + $ticket = $this->ticket(); |
|
1829 | + $transaction = $this->transaction(); |
|
1830 | + $line_item = null; |
|
1831 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
1832 | + $transaction->total_line_item(), |
|
1833 | + 'Ticket', |
|
1834 | + array($ticket->ID()) |
|
1835 | + ); |
|
1836 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
1837 | + if ( |
|
1838 | + $ticket_line_item instanceof \EE_Line_Item |
|
1839 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
1840 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
1841 | + ) { |
|
1842 | + $line_item = $ticket_line_item; |
|
1843 | + break; |
|
1844 | + } |
|
1845 | + } |
|
1846 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1847 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
1848 | + } |
|
1849 | + return $line_item; |
|
1850 | + } |
|
1851 | + |
|
1852 | + |
|
1853 | + /** |
|
1854 | + * Soft Deletes this model object. |
|
1855 | + * |
|
1856 | + * @return boolean | int |
|
1857 | + * @throws RuntimeException |
|
1858 | + * @throws EE_Error |
|
1859 | + */ |
|
1860 | + public function delete() |
|
1861 | + { |
|
1862 | + if ($this->update_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY, $this->status_ID()) === true) { |
|
1863 | + $this->set_status(EEM_Registration::status_id_cancelled); |
|
1864 | + } |
|
1865 | + return parent::delete(); |
|
1866 | + } |
|
1867 | + |
|
1868 | + |
|
1869 | + /** |
|
1870 | + * Restores whatever the previous status was on a registration before it was trashed (if possible) |
|
1871 | + * |
|
1872 | + * @throws EE_Error |
|
1873 | + * @throws RuntimeException |
|
1874 | + */ |
|
1875 | + public function restore() |
|
1876 | + { |
|
1877 | + $previous_status = $this->get_extra_meta( |
|
1878 | + EE_Registration::PRE_TRASH_REG_STATUS_KEY, |
|
1879 | + true, |
|
1880 | + EEM_Registration::status_id_cancelled |
|
1881 | + ); |
|
1882 | + if ($previous_status) { |
|
1883 | + $this->delete_extra_meta(EE_Registration::PRE_TRASH_REG_STATUS_KEY); |
|
1884 | + $this->set_status($previous_status); |
|
1885 | + } |
|
1886 | + return parent::restore(); |
|
1887 | + } |
|
1888 | + |
|
1889 | + |
|
1890 | + /** |
|
1891 | + * possibly toggle Registration status based on comparison of REG_paid vs REG_final_price |
|
1892 | + * |
|
1893 | + * @param boolean $trigger_set_status_logic EE_Registration::set_status() can trigger additional logic |
|
1894 | + * depending on whether the reg status changes to or from "Approved" |
|
1895 | + * @return boolean whether the Registration status was updated |
|
1896 | + * @throws EE_Error |
|
1897 | + * @throws RuntimeException |
|
1898 | + */ |
|
1899 | + public function updateStatusBasedOnTotalPaid($trigger_set_status_logic = true) |
|
1900 | + { |
|
1901 | + $paid = $this->paid(); |
|
1902 | + $price = $this->final_price(); |
|
1903 | + switch(true) { |
|
1904 | + // overpaid or paid |
|
1905 | + case EEH_Money::compare_floats($paid, $price, '>'): |
|
1906 | + case EEH_Money::compare_floats($paid, $price): |
|
1907 | + $new_status = EEM_Registration::status_id_approved; |
|
1908 | + break; |
|
1909 | + // underpaid |
|
1910 | + case EEH_Money::compare_floats($paid, $price, '<'): |
|
1911 | + $new_status = EEM_Registration::status_id_pending_payment; |
|
1912 | + break; |
|
1913 | + // uhhh Houston... |
|
1914 | + default: |
|
1915 | + throw new RuntimeException( |
|
1916 | + esc_html__('The total paid calculation for this registration is inaccurate.', 'event_espresso') |
|
1917 | + ); |
|
1918 | + } |
|
1919 | + if ($new_status !== $this->status_ID()) { |
|
1920 | + if ($trigger_set_status_logic) { |
|
1921 | + return $this->set_status($new_status); |
|
1922 | + } |
|
1923 | + parent::set('STS_ID', $new_status); |
|
1924 | + return true; |
|
1925 | + } |
|
1926 | + return false; |
|
1927 | + } |
|
1928 | + |
|
1929 | + |
|
1930 | + /*************************** DEPRECATED ***************************/ |
|
1931 | + |
|
1932 | + |
|
1933 | + /** |
|
1934 | + * @deprecated |
|
1935 | + * @since 4.7.0 |
|
1936 | + * @access public |
|
1937 | + */ |
|
1938 | + public function price_paid() |
|
1939 | + { |
|
1940 | + EE_Error::doing_it_wrong('EE_Registration::price_paid()', |
|
1941 | + esc_html__('This method is deprecated, please use EE_Registration::final_price() instead.', 'event_espresso'), |
|
1942 | + '4.7.0'); |
|
1943 | + return $this->final_price(); |
|
1944 | + } |
|
1945 | + |
|
1946 | + |
|
1947 | + /** |
|
1948 | + * @deprecated |
|
1949 | + * @since 4.7.0 |
|
1950 | + * @access public |
|
1951 | + * @param float $REG_final_price |
|
1952 | + * @throws EE_Error |
|
1953 | + * @throws RuntimeException |
|
1954 | + */ |
|
1955 | + public function set_price_paid($REG_final_price = 0.00) |
|
1956 | + { |
|
1957 | + EE_Error::doing_it_wrong('EE_Registration::set_price_paid()', |
|
1958 | + esc_html__('This method is deprecated, please use EE_Registration::set_final_price() instead.', 'event_espresso'), |
|
1959 | + '4.7.0'); |
|
1960 | + $this->set_final_price($REG_final_price); |
|
1961 | + } |
|
1962 | + |
|
1963 | + |
|
1964 | + /** |
|
1965 | + * @deprecated |
|
1966 | + * @since 4.7.0 |
|
1967 | + * @return string |
|
1968 | + * @throws EE_Error |
|
1969 | + */ |
|
1970 | + public function pretty_price_paid() |
|
1971 | + { |
|
1972 | + EE_Error::doing_it_wrong('EE_Registration::pretty_price_paid()', |
|
1973 | + esc_html__('This method is deprecated, please use EE_Registration::pretty_final_price() instead.', |
|
1974 | + 'event_espresso'), '4.7.0'); |
|
1975 | + return $this->pretty_final_price(); |
|
1976 | + } |
|
1977 | + |
|
1978 | + |
|
1979 | + /** |
|
1980 | + * Gets the primary datetime related to this registration via the related Event to this registration |
|
1981 | + * |
|
1982 | + * @deprecated 4.9.17 |
|
1983 | + * @return EE_Datetime |
|
1984 | + * @throws EE_Error |
|
1985 | + * @throws EntityNotFoundException |
|
1986 | + */ |
|
1987 | + public function get_related_primary_datetime() |
|
1988 | + { |
|
1989 | + EE_Error::doing_it_wrong( |
|
1990 | + __METHOD__, |
|
1991 | + esc_html__( |
|
1992 | + 'Use EE_Registration::get_latest_related_datetime() or EE_Registration::get_earliest_related_datetime()', |
|
1993 | + 'event_espresso' |
|
1994 | + ), |
|
1995 | + '4.9.17', |
|
1996 | + '5.0.0' |
|
1997 | + ); |
|
1998 | + return $this->event()->primary_datetime(); |
|
1999 | + } |
|
2000 | 2000 | |
2001 | 2001 | |
2002 | 2002 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | switch ($field_name) { |
122 | 122 | case 'REG_code': |
123 | - if (! empty($field_value) && $this->reg_code() === null) { |
|
123 | + if ( ! empty($field_value) && $this->reg_code() === null) { |
|
124 | 124 | $this->set_reg_code($field_value, $use_default); |
125 | 125 | } |
126 | 126 | break; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | // update status |
182 | 182 | parent::set('STS_ID', $new_STS_ID, $use_default); |
183 | 183 | $this->_update_if_canceled_or_declined($new_STS_ID, $old_STS_ID, $context); |
184 | - if($this->statusChangeUpdatesTransaction($context)) { |
|
184 | + if ($this->statusChangeUpdatesTransaction($context)) { |
|
185 | 185 | $this->updateTransactionAfterStatusChange(); |
186 | 186 | } |
187 | 187 | do_action('AHEE__EE_Registration__set_status__after_update', $this, $old_STS_ID, $new_STS_ID, $context); |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | public function event() |
410 | 410 | { |
411 | 411 | $event = $this->get_first_related('Event'); |
412 | - if (! $event instanceof \EE_Event) { |
|
412 | + if ( ! $event instanceof \EE_Event) { |
|
413 | 413 | throw new EntityNotFoundException('Event ID', $this->event_ID()); |
414 | 414 | } |
415 | 415 | return $event; |
@@ -1100,7 +1100,7 @@ discard block |
||
1100 | 1100 | false, |
1101 | 1101 | 'sentence' |
1102 | 1102 | ); |
1103 | - $icon = ''; |
|
1103 | + $icon = ''; |
|
1104 | 1104 | switch ($this->status_ID()) { |
1105 | 1105 | case EEM_Registration::status_id_approved: |
1106 | 1106 | $icon = $show_icons |
@@ -1138,7 +1138,7 @@ discard block |
||
1138 | 1138 | : ''; |
1139 | 1139 | break; |
1140 | 1140 | } |
1141 | - return $icon . $status[$this->status_ID()]; |
|
1141 | + return $icon.$status[$this->status_ID()]; |
|
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | |
@@ -1356,7 +1356,7 @@ discard block |
||
1356 | 1356 | return false; |
1357 | 1357 | } |
1358 | 1358 | //is there a datetime ticket that matches this dtt_ID? |
1359 | - if (! (EEM_Datetime_Ticket::instance()->exists(array( |
|
1359 | + if ( ! (EEM_Datetime_Ticket::instance()->exists(array( |
|
1360 | 1360 | array( |
1361 | 1361 | 'TKT_ID' => $this->get('TKT_ID'), |
1362 | 1362 | 'DTT_ID' => $DTT_ID, |
@@ -1385,7 +1385,7 @@ discard block |
||
1385 | 1385 | { |
1386 | 1386 | $DTT_ID = EEM_Datetime::instance()->ensure_is_ID($DTT_OR_ID); |
1387 | 1387 | |
1388 | - if (! $DTT_ID) { |
|
1388 | + if ( ! $DTT_ID) { |
|
1389 | 1389 | return false; |
1390 | 1390 | } |
1391 | 1391 | |
@@ -1393,7 +1393,7 @@ discard block |
||
1393 | 1393 | |
1394 | 1394 | // if max uses is not set or equals infinity then return true cause its not a factor for whether user can |
1395 | 1395 | // check-in or not. |
1396 | - if (! $max_uses || $max_uses === EE_INF) { |
|
1396 | + if ( ! $max_uses || $max_uses === EE_INF) { |
|
1397 | 1397 | return true; |
1398 | 1398 | } |
1399 | 1399 | |
@@ -1449,7 +1449,7 @@ discard block |
||
1449 | 1449 | $datetime = $this->get_latest_related_datetime(); |
1450 | 1450 | $DTT_ID = $datetime instanceof EE_Datetime ? $datetime->ID() : 0; |
1451 | 1451 | // verify the registration can checkin for the given DTT_ID |
1452 | - } elseif (! $this->can_checkin($DTT_ID, $verify)) { |
|
1452 | + } elseif ( ! $this->can_checkin($DTT_ID, $verify)) { |
|
1453 | 1453 | EE_Error::add_error( |
1454 | 1454 | sprintf( |
1455 | 1455 | esc_html__( |
@@ -1633,7 +1633,7 @@ discard block |
||
1633 | 1633 | public function transaction() |
1634 | 1634 | { |
1635 | 1635 | $transaction = $this->get_first_related('Transaction'); |
1636 | - if (! $transaction instanceof \EE_Transaction) { |
|
1636 | + if ( ! $transaction instanceof \EE_Transaction) { |
|
1637 | 1637 | throw new EntityNotFoundException('Transaction ID', $this->transaction_ID()); |
1638 | 1638 | } |
1639 | 1639 | return $transaction; |
@@ -1687,11 +1687,11 @@ discard block |
||
1687 | 1687 | ); |
1688 | 1688 | return; |
1689 | 1689 | } |
1690 | - if (! $this->reg_code()) { |
|
1690 | + if ( ! $this->reg_code()) { |
|
1691 | 1691 | parent::set('REG_code', $REG_code, $use_default); |
1692 | 1692 | } else { |
1693 | 1693 | EE_Error::doing_it_wrong( |
1694 | - __CLASS__ . '::' . __FUNCTION__, |
|
1694 | + __CLASS__.'::'.__FUNCTION__, |
|
1695 | 1695 | esc_html__('Can not change a registration REG_code once it has been set.', 'event_espresso'), |
1696 | 1696 | '4.6.0' |
1697 | 1697 | ); |
@@ -1843,7 +1843,7 @@ discard block |
||
1843 | 1843 | break; |
1844 | 1844 | } |
1845 | 1845 | } |
1846 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1846 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
1847 | 1847 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
1848 | 1848 | } |
1849 | 1849 | return $line_item; |
@@ -1900,7 +1900,7 @@ discard block |
||
1900 | 1900 | { |
1901 | 1901 | $paid = $this->paid(); |
1902 | 1902 | $price = $this->final_price(); |
1903 | - switch(true) { |
|
1903 | + switch (true) { |
|
1904 | 1904 | // overpaid or paid |
1905 | 1905 | case EEH_Money::compare_floats($paid, $price, '>'): |
1906 | 1906 | case EEH_Money::compare_floats($paid, $price): |
@@ -17,309 +17,309 @@ |
||
17 | 17 | class Benchmark |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * array containing the start time for the timers |
|
22 | - */ |
|
23 | - private static $start_times; |
|
24 | - |
|
25 | - /** |
|
26 | - * array containing all the timer'd times, which can be outputted via show_times() |
|
27 | - */ |
|
28 | - private static $times = array(); |
|
29 | - |
|
30 | - /** |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected static $memory_usage = array(); |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * whether to benchmark code or not |
|
39 | - */ |
|
40 | - public static function doNotRun() |
|
41 | - { |
|
42 | - return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * resetTimes |
|
49 | - */ |
|
50 | - public static function resetTimes() |
|
51 | - { |
|
52 | - Benchmark::$times = array(); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
59 | - * |
|
60 | - * @param null $timer_name |
|
61 | - */ |
|
62 | - public static function startTimer($timer_name = null) |
|
63 | - { |
|
64 | - if (Benchmark::doNotRun()) { |
|
65 | - return; |
|
66 | - } |
|
67 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
68 | - Benchmark::$start_times[$timer_name] = microtime(true); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
75 | - * |
|
76 | - * @param string $timer_name |
|
77 | - */ |
|
78 | - public static function stopTimer($timer_name = '') |
|
79 | - { |
|
80 | - if (Benchmark::doNotRun()) { |
|
81 | - return; |
|
82 | - } |
|
83 | - $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
84 | - if (isset(Benchmark::$start_times[$timer_name])) { |
|
85 | - $start_time = Benchmark::$start_times[$timer_name]; |
|
86 | - unset(Benchmark::$start_times[$timer_name]); |
|
87 | - } else { |
|
88 | - $start_time = array_pop(Benchmark::$start_times); |
|
89 | - } |
|
90 | - Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Measure the memory usage by PHP so far. |
|
97 | - * |
|
98 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
99 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
100 | - * @param bool $formatted |
|
101 | - * @return void |
|
102 | - */ |
|
103 | - public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
104 | - { |
|
105 | - if (Benchmark::doNotRun()) { |
|
106 | - return; |
|
107 | - } |
|
108 | - $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
109 | - Benchmark::$memory_usage[$label] = $memory_used; |
|
110 | - if ($output_now) { |
|
111 | - echo $formatted |
|
112 | - ? "<br>{$label} : {$memory_used}" |
|
113 | - : "\n {$label} : {$memory_used}"; |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * will display the benchmarking results at shutdown |
|
121 | - * |
|
122 | - * @param bool $formatted |
|
123 | - * @return void |
|
124 | - */ |
|
125 | - public static function displayResultsAtShutdown($formatted = true) |
|
126 | - { |
|
127 | - add_action( |
|
128 | - 'shutdown', |
|
129 | - function () use ($formatted) { |
|
130 | - Benchmark::displayResults(true, $formatted); |
|
131 | - } |
|
132 | - ); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * will display the benchmarking results at shutdown |
|
139 | - * |
|
140 | - * @param string $filepath |
|
141 | - * @param bool $formatted |
|
142 | - * @param bool $append |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
146 | - { |
|
147 | - add_action( |
|
148 | - 'shutdown', |
|
149 | - function () use ($filepath, $formatted, $append) { |
|
150 | - Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
151 | - } |
|
152 | - ); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @param bool $formatted |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - private static function generateResults($formatted = true) |
|
162 | - { |
|
163 | - if (Benchmark::doNotRun()) { |
|
164 | - return ''; |
|
165 | - } |
|
166 | - $output = ''; |
|
167 | - if (! empty(Benchmark::$times)) { |
|
168 | - $total = 0; |
|
169 | - $output .= $formatted |
|
170 | - ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
171 | - : ''; |
|
172 | - foreach (Benchmark::$times as $timer_name => $total_time) { |
|
173 | - $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
174 | - $output .= $formatted ? '<br />' : "\n"; |
|
175 | - $total += $total_time; |
|
176 | - } |
|
177 | - if($formatted) { |
|
178 | - $output .= '<br />'; |
|
179 | - $output .= '<h4>TOTAL TIME</h4>'; |
|
180 | - $output .= Benchmark::formatTime('', $total, $formatted); |
|
181 | - $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
182 | - $output .= '<br />'; |
|
183 | - $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
184 | - $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
185 | - $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
186 | - $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
187 | - $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
188 | - $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
189 | - $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
190 | - } |
|
191 | - } |
|
192 | - if (! empty(Benchmark::$memory_usage)) { |
|
193 | - $output .= $formatted |
|
194 | - ? '<h5>Memory</h5>' |
|
195 | - : "\nMemory"; |
|
196 | - foreach (Benchmark::$memory_usage as $label => $memory_usage) { |
|
197 | - $output .= $formatted |
|
198 | - ? '<br />' |
|
199 | - : "\n"; |
|
200 | - $output .= "{$memory_usage} : {$label}"; |
|
201 | - } |
|
202 | - } |
|
203 | - if (empty($output)) { |
|
204 | - return ''; |
|
205 | - } |
|
206 | - $output = $formatted |
|
207 | - ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
208 | - . (is_admin() |
|
209 | - ? ' margin:2em 2em 2em 180px;' |
|
210 | - : ' margin:2em;') |
|
211 | - . ' padding:2em;">' |
|
212 | - . '<h4>BENCHMARKING</h4>' |
|
213 | - . $output |
|
214 | - . '</div>' |
|
215 | - : $output; |
|
216 | - return $output; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * @param bool $echo |
|
223 | - * @param bool $formatted |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - public static function displayResults($echo = true, $formatted = true) |
|
227 | - { |
|
228 | - $results = Benchmark::generateResults($formatted); |
|
229 | - if ($echo) { |
|
230 | - echo $results; |
|
231 | - $results = ''; |
|
232 | - } |
|
233 | - return $results; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @param string $filepath |
|
240 | - * @param bool $formatted |
|
241 | - * @param bool $append |
|
242 | - */ |
|
243 | - public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
244 | - { |
|
245 | - $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
246 | - ? $filepath |
|
247 | - : ''; |
|
248 | - if( empty($filepath)) { |
|
249 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
250 | - } |
|
251 | - file_put_contents( |
|
252 | - $filepath, |
|
253 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
254 | - $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
255 | - ); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
262 | - * |
|
263 | - * @param int $size |
|
264 | - * @return string |
|
265 | - */ |
|
266 | - public static function convert($size) |
|
267 | - { |
|
268 | - $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
269 | - return round( |
|
270 | - $size / pow(1024, $i = floor(log($size, 1024))), |
|
271 | - 2 |
|
272 | - ) . ' ' . $unit[absint($i)]; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @param string $timer_name |
|
279 | - * @param float $total_time |
|
280 | - * @param bool $formatted |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - public static function formatTime($timer_name, $total_time, $formatted = true) |
|
284 | - { |
|
285 | - $total_time *= 1000; |
|
286 | - switch ($total_time) { |
|
287 | - case $total_time > 12500 : |
|
288 | - $color = 'red'; |
|
289 | - $bold = 'bold'; |
|
290 | - break; |
|
291 | - case $total_time > 2500 : |
|
292 | - $color = 'darkorange'; |
|
293 | - $bold = 'bold'; |
|
294 | - break; |
|
295 | - case $total_time > 500 : |
|
296 | - $color = 'gold'; |
|
297 | - $bold = 'bold'; |
|
298 | - break; |
|
299 | - case $total_time > 100 : |
|
300 | - $color = 'limegreen'; |
|
301 | - $bold = 'normal'; |
|
302 | - break; |
|
303 | - case $total_time > 20 : |
|
304 | - $color = 'deepskyblue'; |
|
305 | - $bold = 'normal'; |
|
306 | - break; |
|
307 | - default : |
|
308 | - $color = 'mediumpurple'; |
|
309 | - $bold = 'normal'; |
|
310 | - break; |
|
311 | - } |
|
312 | - return $formatted |
|
313 | - ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
314 | - . $color |
|
315 | - . '; font-weight:' |
|
316 | - . $bold |
|
317 | - . '; font-size:1.2em;">' |
|
318 | - . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
319 | - . '</span> ' |
|
320 | - . $timer_name |
|
321 | - : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
322 | - } |
|
20 | + /** |
|
21 | + * array containing the start time for the timers |
|
22 | + */ |
|
23 | + private static $start_times; |
|
24 | + |
|
25 | + /** |
|
26 | + * array containing all the timer'd times, which can be outputted via show_times() |
|
27 | + */ |
|
28 | + private static $times = array(); |
|
29 | + |
|
30 | + /** |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected static $memory_usage = array(); |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * whether to benchmark code or not |
|
39 | + */ |
|
40 | + public static function doNotRun() |
|
41 | + { |
|
42 | + return ! WP_DEBUG || (defined('DOING_AJAX') && DOING_AJAX); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * resetTimes |
|
49 | + */ |
|
50 | + public static function resetTimes() |
|
51 | + { |
|
52 | + Benchmark::$times = array(); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Add Benchmark::startTimer() before a block of code you want to measure the performance of |
|
59 | + * |
|
60 | + * @param null $timer_name |
|
61 | + */ |
|
62 | + public static function startTimer($timer_name = null) |
|
63 | + { |
|
64 | + if (Benchmark::doNotRun()) { |
|
65 | + return; |
|
66 | + } |
|
67 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
68 | + Benchmark::$start_times[$timer_name] = microtime(true); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Add Benchmark::stopTimer() after a block of code you want to measure the performance of |
|
75 | + * |
|
76 | + * @param string $timer_name |
|
77 | + */ |
|
78 | + public static function stopTimer($timer_name = '') |
|
79 | + { |
|
80 | + if (Benchmark::doNotRun()) { |
|
81 | + return; |
|
82 | + } |
|
83 | + $timer_name = $timer_name !== '' ? $timer_name : get_called_class(); |
|
84 | + if (isset(Benchmark::$start_times[$timer_name])) { |
|
85 | + $start_time = Benchmark::$start_times[$timer_name]; |
|
86 | + unset(Benchmark::$start_times[$timer_name]); |
|
87 | + } else { |
|
88 | + $start_time = array_pop(Benchmark::$start_times); |
|
89 | + } |
|
90 | + Benchmark::$times[$timer_name] = number_format(microtime(true) - $start_time, 8); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Measure the memory usage by PHP so far. |
|
97 | + * |
|
98 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
99 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
100 | + * @param bool $formatted |
|
101 | + * @return void |
|
102 | + */ |
|
103 | + public static function measureMemory($label = 'memory usage', $output_now = false, $formatted = true) |
|
104 | + { |
|
105 | + if (Benchmark::doNotRun()) { |
|
106 | + return; |
|
107 | + } |
|
108 | + $memory_used = Benchmark::convert(memory_get_usage(true)); |
|
109 | + Benchmark::$memory_usage[$label] = $memory_used; |
|
110 | + if ($output_now) { |
|
111 | + echo $formatted |
|
112 | + ? "<br>{$label} : {$memory_used}" |
|
113 | + : "\n {$label} : {$memory_used}"; |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * will display the benchmarking results at shutdown |
|
121 | + * |
|
122 | + * @param bool $formatted |
|
123 | + * @return void |
|
124 | + */ |
|
125 | + public static function displayResultsAtShutdown($formatted = true) |
|
126 | + { |
|
127 | + add_action( |
|
128 | + 'shutdown', |
|
129 | + function () use ($formatted) { |
|
130 | + Benchmark::displayResults(true, $formatted); |
|
131 | + } |
|
132 | + ); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * will display the benchmarking results at shutdown |
|
139 | + * |
|
140 | + * @param string $filepath |
|
141 | + * @param bool $formatted |
|
142 | + * @param bool $append |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public static function writeResultsAtShutdown($filepath = '', $formatted = true, $append = true) |
|
146 | + { |
|
147 | + add_action( |
|
148 | + 'shutdown', |
|
149 | + function () use ($filepath, $formatted, $append) { |
|
150 | + Benchmark::writeResultsToFile($filepath, $formatted, $append); |
|
151 | + } |
|
152 | + ); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @param bool $formatted |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + private static function generateResults($formatted = true) |
|
162 | + { |
|
163 | + if (Benchmark::doNotRun()) { |
|
164 | + return ''; |
|
165 | + } |
|
166 | + $output = ''; |
|
167 | + if (! empty(Benchmark::$times)) { |
|
168 | + $total = 0; |
|
169 | + $output .= $formatted |
|
170 | + ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
|
171 | + : ''; |
|
172 | + foreach (Benchmark::$times as $timer_name => $total_time) { |
|
173 | + $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
|
174 | + $output .= $formatted ? '<br />' : "\n"; |
|
175 | + $total += $total_time; |
|
176 | + } |
|
177 | + if($formatted) { |
|
178 | + $output .= '<br />'; |
|
179 | + $output .= '<h4>TOTAL TIME</h4>'; |
|
180 | + $output .= Benchmark::formatTime('', $total, $formatted); |
|
181 | + $output .= '<span style="color:#999999; font-size:.8em;"> milliseconds</span><br />'; |
|
182 | + $output .= '<br />'; |
|
183 | + $output .= '<h5>Performance scale (from best to worse)</h5>'; |
|
184 | + $output .= '<span style="color:mediumpurple">Like wow! How about a Scooby snack?</span><br />'; |
|
185 | + $output .= '<span style="color:deepskyblue">Like...no way man!</span><br />'; |
|
186 | + $output .= '<span style="color:limegreen">Like...groovy!</span><br />'; |
|
187 | + $output .= '<span style="color:gold">Ruh Oh</span><br />'; |
|
188 | + $output .= '<span style="color:darkorange">Zoinks!</span><br />'; |
|
189 | + $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
|
190 | + } |
|
191 | + } |
|
192 | + if (! empty(Benchmark::$memory_usage)) { |
|
193 | + $output .= $formatted |
|
194 | + ? '<h5>Memory</h5>' |
|
195 | + : "\nMemory"; |
|
196 | + foreach (Benchmark::$memory_usage as $label => $memory_usage) { |
|
197 | + $output .= $formatted |
|
198 | + ? '<br />' |
|
199 | + : "\n"; |
|
200 | + $output .= "{$memory_usage} : {$label}"; |
|
201 | + } |
|
202 | + } |
|
203 | + if (empty($output)) { |
|
204 | + return ''; |
|
205 | + } |
|
206 | + $output = $formatted |
|
207 | + ? '<div style="border:1px solid #dddddd; background-color:#ffffff;' |
|
208 | + . (is_admin() |
|
209 | + ? ' margin:2em 2em 2em 180px;' |
|
210 | + : ' margin:2em;') |
|
211 | + . ' padding:2em;">' |
|
212 | + . '<h4>BENCHMARKING</h4>' |
|
213 | + . $output |
|
214 | + . '</div>' |
|
215 | + : $output; |
|
216 | + return $output; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * @param bool $echo |
|
223 | + * @param bool $formatted |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + public static function displayResults($echo = true, $formatted = true) |
|
227 | + { |
|
228 | + $results = Benchmark::generateResults($formatted); |
|
229 | + if ($echo) { |
|
230 | + echo $results; |
|
231 | + $results = ''; |
|
232 | + } |
|
233 | + return $results; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @param string $filepath |
|
240 | + * @param bool $formatted |
|
241 | + * @param bool $append |
|
242 | + */ |
|
243 | + public static function writeResultsToFile($filepath = '', $formatted = true, $append = true) |
|
244 | + { |
|
245 | + $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
|
246 | + ? $filepath |
|
247 | + : ''; |
|
248 | + if( empty($filepath)) { |
|
249 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
250 | + } |
|
251 | + file_put_contents( |
|
252 | + $filepath, |
|
253 | + "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
254 | + $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
|
255 | + ); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Converts a measure of memory bytes into the most logical units (eg kb, mb, etc) |
|
262 | + * |
|
263 | + * @param int $size |
|
264 | + * @return string |
|
265 | + */ |
|
266 | + public static function convert($size) |
|
267 | + { |
|
268 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
269 | + return round( |
|
270 | + $size / pow(1024, $i = floor(log($size, 1024))), |
|
271 | + 2 |
|
272 | + ) . ' ' . $unit[absint($i)]; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @param string $timer_name |
|
279 | + * @param float $total_time |
|
280 | + * @param bool $formatted |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + public static function formatTime($timer_name, $total_time, $formatted = true) |
|
284 | + { |
|
285 | + $total_time *= 1000; |
|
286 | + switch ($total_time) { |
|
287 | + case $total_time > 12500 : |
|
288 | + $color = 'red'; |
|
289 | + $bold = 'bold'; |
|
290 | + break; |
|
291 | + case $total_time > 2500 : |
|
292 | + $color = 'darkorange'; |
|
293 | + $bold = 'bold'; |
|
294 | + break; |
|
295 | + case $total_time > 500 : |
|
296 | + $color = 'gold'; |
|
297 | + $bold = 'bold'; |
|
298 | + break; |
|
299 | + case $total_time > 100 : |
|
300 | + $color = 'limegreen'; |
|
301 | + $bold = 'normal'; |
|
302 | + break; |
|
303 | + case $total_time > 20 : |
|
304 | + $color = 'deepskyblue'; |
|
305 | + $bold = 'normal'; |
|
306 | + break; |
|
307 | + default : |
|
308 | + $color = 'mediumpurple'; |
|
309 | + $bold = 'normal'; |
|
310 | + break; |
|
311 | + } |
|
312 | + return $formatted |
|
313 | + ? '<span style="min-width: 10px; margin:0 1em; color:' |
|
314 | + . $color |
|
315 | + . '; font-weight:' |
|
316 | + . $bold |
|
317 | + . '; font-size:1.2em;">' |
|
318 | + . str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT) |
|
319 | + . '</span> ' |
|
320 | + . $timer_name |
|
321 | + : str_pad(number_format($total_time, 3), 9, '0', STR_PAD_LEFT); |
|
322 | + } |
|
323 | 323 | |
324 | 324 | |
325 | 325 |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | add_action( |
128 | 128 | 'shutdown', |
129 | - function () use ($formatted) { |
|
129 | + function() use ($formatted) { |
|
130 | 130 | Benchmark::displayResults(true, $formatted); |
131 | 131 | } |
132 | 132 | ); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | { |
147 | 147 | add_action( |
148 | 148 | 'shutdown', |
149 | - function () use ($filepath, $formatted, $append) { |
|
149 | + function() use ($filepath, $formatted, $append) { |
|
150 | 150 | Benchmark::writeResultsToFile($filepath, $formatted, $append); |
151 | 151 | } |
152 | 152 | ); |
@@ -164,17 +164,17 @@ discard block |
||
164 | 164 | return ''; |
165 | 165 | } |
166 | 166 | $output = ''; |
167 | - if (! empty(Benchmark::$times)) { |
|
167 | + if ( ! empty(Benchmark::$times)) { |
|
168 | 168 | $total = 0; |
169 | 169 | $output .= $formatted |
170 | 170 | ? '<span style="color:#999999; font-size:.8em;">( time in milliseconds )</span><br />' |
171 | 171 | : ''; |
172 | 172 | foreach (Benchmark::$times as $timer_name => $total_time) { |
173 | 173 | $output .= Benchmark::formatTime($timer_name, $total_time, $formatted); |
174 | - $output .= $formatted ? '<br />' : "\n"; |
|
174 | + $output .= $formatted ? '<br />' : "\n"; |
|
175 | 175 | $total += $total_time; |
176 | 176 | } |
177 | - if($formatted) { |
|
177 | + if ($formatted) { |
|
178 | 178 | $output .= '<br />'; |
179 | 179 | $output .= '<h4>TOTAL TIME</h4>'; |
180 | 180 | $output .= Benchmark::formatTime('', $total, $formatted); |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $output .= '<span style="color:red">Like...HEEELLLP</span><br />'; |
190 | 190 | } |
191 | 191 | } |
192 | - if (! empty(Benchmark::$memory_usage)) { |
|
192 | + if ( ! empty(Benchmark::$memory_usage)) { |
|
193 | 193 | $output .= $formatted |
194 | 194 | ? '<h5>Memory</h5>' |
195 | 195 | : "\nMemory"; |
@@ -245,12 +245,12 @@ discard block |
||
245 | 245 | $filepath = ! empty($filepath) && is_readable(dirname($filepath)) |
246 | 246 | ? $filepath |
247 | 247 | : ''; |
248 | - if( empty($filepath)) { |
|
249 | - $filepath = EVENT_ESPRESSO_UPLOAD_DIR . 'logs/benchmarking-' . date('Y-m-d') . '.html'; |
|
248 | + if (empty($filepath)) { |
|
249 | + $filepath = EVENT_ESPRESSO_UPLOAD_DIR.'logs/benchmarking-'.date('Y-m-d').'.html'; |
|
250 | 250 | } |
251 | 251 | file_put_contents( |
252 | 252 | $filepath, |
253 | - "\n" . date('Y-m-d H:i:s') . Benchmark::generateResults($formatted), |
|
253 | + "\n".date('Y-m-d H:i:s').Benchmark::generateResults($formatted), |
|
254 | 254 | $append ? FILE_APPEND | LOCK_EX : LOCK_EX |
255 | 255 | ); |
256 | 256 | } |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | return round( |
270 | 270 | $size / pow(1024, $i = floor(log($size, 1024))), |
271 | 271 | 2 |
272 | - ) . ' ' . $unit[absint($i)]; |
|
272 | + ).' '.$unit[absint($i)]; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use RuntimeException; |
13 | 13 | |
14 | 14 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
15 | - exit('No direct script access allowed'); |
|
15 | + exit('No direct script access allowed'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -30,145 +30,145 @@ discard block |
||
30 | 30 | { |
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @param EE_Registration $target_registration |
|
35 | - * @param EE_Registration $registration_to_copy |
|
36 | - * @return bool |
|
37 | - * @throws UnexpectedEntityException |
|
38 | - * @throws EntityNotFoundException |
|
39 | - * @throws RuntimeException |
|
40 | - * @throws EE_Error |
|
41 | - */ |
|
42 | - public function copyRegistrationDetails( |
|
43 | - EE_Registration $target_registration, |
|
44 | - EE_Registration $registration_to_copy |
|
45 | - ) { |
|
46 | - // copy attendee |
|
47 | - $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
48 | - $target_registration->updateStatusBasedOnTotalPaid(false); |
|
49 | - $target_registration->save(); |
|
50 | - // get answers to previous reg questions |
|
51 | - $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
52 | - // get questions to new event reg form |
|
53 | - $new_event = $target_registration->event(); |
|
54 | - $question_groups = $new_event->question_groups( |
|
55 | - array( |
|
56 | - array( |
|
57 | - 'Event.EVT_ID' => $new_event->ID(), |
|
58 | - 'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant(), |
|
59 | - ), |
|
60 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
61 | - ) |
|
62 | - ); |
|
63 | - foreach ($question_groups as $question_group) { |
|
64 | - if ($question_group instanceof \EE_Question_Group) { |
|
65 | - foreach ($question_group->questions() as $question) { |
|
66 | - if ($question instanceof EE_Question) { |
|
67 | - $this->generateNewAnswer( |
|
68 | - $question, |
|
69 | - $target_registration, |
|
70 | - $answers |
|
71 | - ); |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - } |
|
76 | - return true; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param EE_Answer[] $answers |
|
83 | - * @return array |
|
84 | - * @throws EE_Error |
|
85 | - */ |
|
86 | - protected function reindexAnswersByQuestionId(array $answers) |
|
87 | - { |
|
88 | - $reindexed_answers = array(); |
|
89 | - foreach ($answers as $answer) { |
|
90 | - if ($answer instanceof EE_Answer) { |
|
91 | - $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
92 | - } |
|
93 | - } |
|
94 | - return $reindexed_answers; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @param EE_Question $question |
|
101 | - * @param EE_Registration $registration |
|
102 | - * @param $previous_answers |
|
103 | - * @return EE_Answer |
|
104 | - * @throws UnexpectedEntityException |
|
105 | - * @throws EE_Error |
|
106 | - */ |
|
107 | - protected function generateNewAnswer( |
|
108 | - EE_Question $question, |
|
109 | - EE_Registration $registration, |
|
110 | - $previous_answers |
|
111 | - ) { |
|
112 | - $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
113 | - ? $previous_answers[ $question->ID() ] |
|
114 | - : ''; |
|
115 | - $new_answer = EE_Answer::new_instance( |
|
116 | - array( |
|
117 | - 'QST_ID' => $question->ID(), |
|
118 | - 'REG_ID' => $registration->ID(), |
|
119 | - 'ANS_value' => $old_answer_value, |
|
120 | - ) |
|
121 | - ); |
|
122 | - if ( ! $new_answer instanceof EE_Answer) { |
|
123 | - throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
124 | - } |
|
125 | - $new_answer->save(); |
|
126 | - return $new_answer; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @param EE_Registration $target_registration |
|
133 | - * @param EE_Registration $registration_to_copy |
|
134 | - * @return bool |
|
135 | - * @throws RuntimeException |
|
136 | - * @throws UnexpectedEntityException |
|
137 | - * @throws EE_Error |
|
138 | - */ |
|
139 | - public function copyPaymentDetails( |
|
140 | - EE_Registration $target_registration, |
|
141 | - EE_Registration $registration_to_copy |
|
142 | - ) { |
|
143 | - $previous_payments = $registration_to_copy->registration_payments(); |
|
144 | - foreach ($previous_payments as $previous_payment) { |
|
145 | - if ( |
|
146 | - $previous_payment instanceof \EE_Registration_Payment |
|
147 | - && $previous_payment->payment() instanceof \EE_Payment |
|
148 | - && $previous_payment->payment()->is_approved() |
|
149 | - ) { |
|
150 | - $new_registration_payment = \EE_Registration_Payment::new_instance( |
|
151 | - array( |
|
152 | - 'REG_ID' => $target_registration->ID(), |
|
153 | - 'PAY_ID' => $previous_payment->ID(), |
|
154 | - 'RPY_amount' => $previous_payment->amount(), |
|
155 | - ) |
|
156 | - ); |
|
157 | - if ( ! $new_registration_payment instanceof \EE_Registration_Payment) { |
|
158 | - throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
159 | - } |
|
160 | - $new_registration_payment->save(); |
|
161 | - $target_registration->set_paid($previous_payment->amount()); |
|
162 | - $target_registration->save(); |
|
163 | - // if new reg payment is good, then set old reg payment amount to zero |
|
164 | - $previous_payment->set_amount(0); |
|
165 | - $previous_payment->save(); |
|
166 | - $registration_to_copy->set_paid(0); |
|
167 | - $registration_to_copy->save(); |
|
168 | - } |
|
169 | - } |
|
170 | - return true; |
|
171 | - } |
|
33 | + /** |
|
34 | + * @param EE_Registration $target_registration |
|
35 | + * @param EE_Registration $registration_to_copy |
|
36 | + * @return bool |
|
37 | + * @throws UnexpectedEntityException |
|
38 | + * @throws EntityNotFoundException |
|
39 | + * @throws RuntimeException |
|
40 | + * @throws EE_Error |
|
41 | + */ |
|
42 | + public function copyRegistrationDetails( |
|
43 | + EE_Registration $target_registration, |
|
44 | + EE_Registration $registration_to_copy |
|
45 | + ) { |
|
46 | + // copy attendee |
|
47 | + $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
48 | + $target_registration->updateStatusBasedOnTotalPaid(false); |
|
49 | + $target_registration->save(); |
|
50 | + // get answers to previous reg questions |
|
51 | + $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
52 | + // get questions to new event reg form |
|
53 | + $new_event = $target_registration->event(); |
|
54 | + $question_groups = $new_event->question_groups( |
|
55 | + array( |
|
56 | + array( |
|
57 | + 'Event.EVT_ID' => $new_event->ID(), |
|
58 | + 'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant(), |
|
59 | + ), |
|
60 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
61 | + ) |
|
62 | + ); |
|
63 | + foreach ($question_groups as $question_group) { |
|
64 | + if ($question_group instanceof \EE_Question_Group) { |
|
65 | + foreach ($question_group->questions() as $question) { |
|
66 | + if ($question instanceof EE_Question) { |
|
67 | + $this->generateNewAnswer( |
|
68 | + $question, |
|
69 | + $target_registration, |
|
70 | + $answers |
|
71 | + ); |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + } |
|
76 | + return true; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param EE_Answer[] $answers |
|
83 | + * @return array |
|
84 | + * @throws EE_Error |
|
85 | + */ |
|
86 | + protected function reindexAnswersByQuestionId(array $answers) |
|
87 | + { |
|
88 | + $reindexed_answers = array(); |
|
89 | + foreach ($answers as $answer) { |
|
90 | + if ($answer instanceof EE_Answer) { |
|
91 | + $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
92 | + } |
|
93 | + } |
|
94 | + return $reindexed_answers; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @param EE_Question $question |
|
101 | + * @param EE_Registration $registration |
|
102 | + * @param $previous_answers |
|
103 | + * @return EE_Answer |
|
104 | + * @throws UnexpectedEntityException |
|
105 | + * @throws EE_Error |
|
106 | + */ |
|
107 | + protected function generateNewAnswer( |
|
108 | + EE_Question $question, |
|
109 | + EE_Registration $registration, |
|
110 | + $previous_answers |
|
111 | + ) { |
|
112 | + $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
113 | + ? $previous_answers[ $question->ID() ] |
|
114 | + : ''; |
|
115 | + $new_answer = EE_Answer::new_instance( |
|
116 | + array( |
|
117 | + 'QST_ID' => $question->ID(), |
|
118 | + 'REG_ID' => $registration->ID(), |
|
119 | + 'ANS_value' => $old_answer_value, |
|
120 | + ) |
|
121 | + ); |
|
122 | + if ( ! $new_answer instanceof EE_Answer) { |
|
123 | + throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
124 | + } |
|
125 | + $new_answer->save(); |
|
126 | + return $new_answer; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @param EE_Registration $target_registration |
|
133 | + * @param EE_Registration $registration_to_copy |
|
134 | + * @return bool |
|
135 | + * @throws RuntimeException |
|
136 | + * @throws UnexpectedEntityException |
|
137 | + * @throws EE_Error |
|
138 | + */ |
|
139 | + public function copyPaymentDetails( |
|
140 | + EE_Registration $target_registration, |
|
141 | + EE_Registration $registration_to_copy |
|
142 | + ) { |
|
143 | + $previous_payments = $registration_to_copy->registration_payments(); |
|
144 | + foreach ($previous_payments as $previous_payment) { |
|
145 | + if ( |
|
146 | + $previous_payment instanceof \EE_Registration_Payment |
|
147 | + && $previous_payment->payment() instanceof \EE_Payment |
|
148 | + && $previous_payment->payment()->is_approved() |
|
149 | + ) { |
|
150 | + $new_registration_payment = \EE_Registration_Payment::new_instance( |
|
151 | + array( |
|
152 | + 'REG_ID' => $target_registration->ID(), |
|
153 | + 'PAY_ID' => $previous_payment->ID(), |
|
154 | + 'RPY_amount' => $previous_payment->amount(), |
|
155 | + ) |
|
156 | + ); |
|
157 | + if ( ! $new_registration_payment instanceof \EE_Registration_Payment) { |
|
158 | + throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
159 | + } |
|
160 | + $new_registration_payment->save(); |
|
161 | + $target_registration->set_paid($previous_payment->amount()); |
|
162 | + $target_registration->save(); |
|
163 | + // if new reg payment is good, then set old reg payment amount to zero |
|
164 | + $previous_payment->set_amount(0); |
|
165 | + $previous_payment->save(); |
|
166 | + $registration_to_copy->set_paid(0); |
|
167 | + $registration_to_copy->save(); |
|
168 | + } |
|
169 | + } |
|
170 | + return true; |
|
171 | + } |
|
172 | 172 | |
173 | 173 | |
174 | 174 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | $reindexed_answers = array(); |
89 | 89 | foreach ($answers as $answer) { |
90 | 90 | if ($answer instanceof EE_Answer) { |
91 | - $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
91 | + $reindexed_answers[$answer->question_ID()] = $answer->value(); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | return $reindexed_answers; |
@@ -109,8 +109,8 @@ discard block |
||
109 | 109 | EE_Registration $registration, |
110 | 110 | $previous_answers |
111 | 111 | ) { |
112 | - $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
113 | - ? $previous_answers[ $question->ID() ] |
|
112 | + $old_answer_value = isset($previous_answers[$question->ID()]) |
|
113 | + ? $previous_answers[$question->ID()] |
|
114 | 114 | : ''; |
115 | 115 | $new_answer = EE_Answer::new_instance( |
116 | 116 | array( |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @return EED_Events_Archive_Filters |
30 | 30 | */ |
31 | 31 | public static function instance() { |
32 | - return parent::get_instance( __CLASS__ ); |
|
32 | + return parent::get_instance(__CLASS__); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @var $_types |
72 | 72 | * @access protected |
73 | 73 | */ |
74 | - protected static $_types = array( 'grid', 'text', 'dates' ); |
|
74 | + protected static $_types = array('grid', 'text', 'dates'); |
|
75 | 75 | |
76 | 76 | |
77 | 77 | // public static $espresso_event_list_ID = 0; |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * @access public |
126 | 126 | * @return void |
127 | 127 | */ |
128 | - public function run( $WP ) { |
|
128 | + public function run($WP) { |
|
129 | 129 | // do_action( 'AHEE__EED_Events_Archive_Filters__before_run' ); |
130 | 130 | // // set config |
131 | 131 | // if ( ! isset( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters ) || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters instanceof EE_Events_Archive_Config ) { |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | */ |
171 | 171 | private function _filter_query_parts() { |
172 | 172 | // build event list query |
173 | - add_filter( 'posts_join', array( $this, 'posts_join' ), 1, 2 ); |
|
174 | - add_filter( 'posts_where', array( $this, 'posts_where' ), 1, 2 ); |
|
175 | - add_filter( 'posts_orderby', array( $this, 'posts_orderby' ), 1, 2 ); |
|
173 | + add_filter('posts_join', array($this, 'posts_join'), 1, 2); |
|
174 | + add_filter('posts_where', array($this, 'posts_where'), 1, 2); |
|
175 | + add_filter('posts_orderby', array($this, 'posts_orderby'), 1, 2); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
@@ -182,13 +182,13 @@ discard block |
||
182 | 182 | * @return string |
183 | 183 | */ |
184 | 184 | public static function set_type() { |
185 | - do_action( 'AHEE__EED_Events_Archive_Filters__before_set_type' ); |
|
186 | - EED_Events_Archive_Filters::$_types = apply_filters( 'EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types ); |
|
187 | - $view = isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid'; |
|
188 | - $elf_type = EE_Registry::instance()->REQ->is_set( 'elf_type' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_type' )) : ''; |
|
189 | - $view = ! empty( $elf_type ) ? $elf_type : $view; |
|
190 | - $view = apply_filters( 'EED_Events_Archive_Filters__set_type__type', $view ); |
|
191 | - if ( ! empty( $view ) && in_array( $view, EED_Events_Archive_Filters::$_types )) { |
|
185 | + do_action('AHEE__EED_Events_Archive_Filters__before_set_type'); |
|
186 | + EED_Events_Archive_Filters::$_types = apply_filters('EED_Events_Archive_Filters__set_type__types', EED_Events_Archive_Filters::$_types); |
|
187 | + $view = isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['default_type'] : 'grid'; |
|
188 | + $elf_type = EE_Registry::instance()->REQ->is_set('elf_type') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_type')) : ''; |
|
189 | + $view = ! empty($elf_type) ? $elf_type : $view; |
|
190 | + $view = apply_filters('EED_Events_Archive_Filters__set_type__type', $view); |
|
191 | + if ( ! empty($view) && in_array($view, EED_Events_Archive_Filters::$_types)) { |
|
192 | 192 | self::$_type = $view; |
193 | 193 | } |
194 | 194 | } |
@@ -200,11 +200,11 @@ discard block |
||
200 | 200 | * @param boolean $req_only if TRUE, then ignore defaults and only return $_POST value |
201 | 201 | * @return boolean |
202 | 202 | */ |
203 | - private static function _show_expired( $req_only = FALSE ) { |
|
203 | + private static function _show_expired($req_only = FALSE) { |
|
204 | 204 | // get default value for "display_expired_events" as set in the EE General Settings > Templates > Event Listings |
205 | - $show_expired = ! $req_only && isset( EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] ) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE; |
|
205 | + $show_expired = ! $req_only && isset(EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events']) ? EE_Registry::instance()->CFG->EED_Events_Archive_Filters['display_expired_events'] : FALSE; |
|
206 | 206 | // override default expired option if set via filter |
207 | - $show_expired = EE_Registry::instance()->REQ->is_set( 'elf_expired_chk' ) ? absint( EE_Registry::instance()->REQ->get( 'elf_expired_chk' )) : $show_expired; |
|
207 | + $show_expired = EE_Registry::instance()->REQ->is_set('elf_expired_chk') ? absint(EE_Registry::instance()->REQ->get('elf_expired_chk')) : $show_expired; |
|
208 | 208 | return $show_expired ? TRUE : FALSE; |
209 | 209 | } |
210 | 210 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @return string |
216 | 216 | */ |
217 | 217 | private static function _event_category_slug() { |
218 | - return EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : ''; |
|
218 | + return EE_Registry::instance()->REQ->is_set('elf_category_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_category_dd')) : ''; |
|
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @return string |
226 | 226 | */ |
227 | 227 | private static function _display_month() { |
228 | - return EE_Registry::instance()->REQ->is_set( 'elf_month_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_month_dd' )) : ''; |
|
228 | + return EE_Registry::instance()->REQ->is_set('elf_month_dd') ? sanitize_text_field(EE_Registry::instance()->REQ->get('elf_month_dd')) : ''; |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | public function get_post_data() { |
240 | 240 | $this->_elf_month = EED_Events_Archive_Filters::_display_month(); |
241 | 241 | $this->_elf_category = EED_Events_Archive_Filters::_event_category_slug(); |
242 | - $this->_show_expired = EED_Events_Archive_Filters::_show_expired( TRUE ); |
|
242 | + $this->_show_expired = EED_Events_Archive_Filters::_show_expired(TRUE); |
|
243 | 243 | // EEH_Debug_Tools::printr( EE_Registry::instance()->REQ, 'EE_Registry::instance()->REQ <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
244 | 244 | // echo '<h4>$this->_elf_month : ' . $this->_elf_month . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
245 | 245 | // echo '<h4>$this->_elf_category : ' . $this->_elf_category . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h4>'; |
@@ -256,11 +256,11 @@ discard block |
||
256 | 256 | * @access public |
257 | 257 | * @return void |
258 | 258 | */ |
259 | - public function posts_join( $SQL, WP_Query $wp_query ) { |
|
260 | - if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) { |
|
259 | + public function posts_join($SQL, WP_Query $wp_query) { |
|
260 | + if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') { |
|
261 | 261 | // Category |
262 | 262 | // $elf_category = EE_Registry::instance()->REQ->is_set( 'elf_category_dd' ) ? sanitize_text_field( EE_Registry::instance()->REQ->get( 'elf_category_dd' )) : ''; |
263 | - $SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms( EED_Events_Archive_Filters::_event_category_slug() ); |
|
263 | + $SQL .= EED_Events_Archive_Filters::posts_join_sql_for_terms(EED_Events_Archive_Filters::_event_category_slug()); |
|
264 | 264 | } |
265 | 265 | return $SQL; |
266 | 266 | } |
@@ -273,9 +273,9 @@ discard block |
||
273 | 273 | * @param mixed boolean|string $join_terms pass TRUE or term string, doesn't really matter since this value doesn't really get used for anything yet |
274 | 274 | * @return string |
275 | 275 | */ |
276 | - public static function posts_join_sql_for_terms( $join_terms = NULL ) { |
|
277 | - $SQL= ''; |
|
278 | - if ( ! empty( $join_terms )) { |
|
276 | + public static function posts_join_sql_for_terms($join_terms = NULL) { |
|
277 | + $SQL = ''; |
|
278 | + if ( ! empty($join_terms)) { |
|
279 | 279 | global $wpdb; |
280 | 280 | $SQL .= " LEFT JOIN $wpdb->term_relationships ON ($wpdb->posts.ID = $wpdb->term_relationships.object_id)"; |
281 | 281 | $SQL .= " LEFT JOIN $wpdb->term_taxonomy ON ($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)"; |
@@ -293,28 +293,28 @@ discard block |
||
293 | 293 | * @param array $orderby_params |
294 | 294 | * @return string |
295 | 295 | */ |
296 | - public static function posts_join_for_orderby( $orderby_params = array() ) { |
|
296 | + public static function posts_join_for_orderby($orderby_params = array()) { |
|
297 | 297 | global $wpdb; |
298 | - $SQL= ''; |
|
299 | - $orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params ); |
|
300 | - foreach( $orderby_params as $orderby ) { |
|
301 | - switch ( $orderby ) { |
|
298 | + $SQL = ''; |
|
299 | + $orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params); |
|
300 | + foreach ($orderby_params as $orderby) { |
|
301 | + switch ($orderby) { |
|
302 | 302 | |
303 | 303 | case 'ticket_start' : |
304 | 304 | case 'ticket_end' : |
305 | - $SQL .= ' LEFT JOIN ' . EEM_Datetime_Ticket::instance()->table() . ' ON (' . EEM_Datetime::instance()->table() . '.DTT_ID = ' . EEM_Datetime_Ticket::instance()->table() . '.DTT_ID )'; |
|
306 | - $SQL .= ' LEFT JOIN ' . EEM_Ticket::instance()->table() . ' ON (' . EEM_Datetime_Ticket::instance()->table() . '.TKT_ID = ' . EEM_Ticket::instance()->table() . '.TKT_ID )'; |
|
305 | + $SQL .= ' LEFT JOIN '.EEM_Datetime_Ticket::instance()->table().' ON ('.EEM_Datetime::instance()->table().'.DTT_ID = '.EEM_Datetime_Ticket::instance()->table().'.DTT_ID )'; |
|
306 | + $SQL .= ' LEFT JOIN '.EEM_Ticket::instance()->table().' ON ('.EEM_Datetime_Ticket::instance()->table().'.TKT_ID = '.EEM_Ticket::instance()->table().'.TKT_ID )'; |
|
307 | 307 | break; |
308 | 308 | |
309 | 309 | case 'venue_title' : |
310 | 310 | case 'city' : |
311 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )'; |
|
312 | - $SQL .= ' LEFT JOIN ' . EEM_Venue::instance()->table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Venue::instance()->table() . '.VNU_ID )'; |
|
311 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )'; |
|
312 | + $SQL .= ' LEFT JOIN '.EEM_Venue::instance()->table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Venue::instance()->table().'.VNU_ID )'; |
|
313 | 313 | break; |
314 | 314 | |
315 | 315 | case 'state' : |
316 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->table() . ' ON (' . $wpdb->posts . '.ID = ' . EEM_Event_Venue::instance()->table() . '.EVT_ID )'; |
|
317 | - $SQL .= ' LEFT JOIN ' . EEM_Event_Venue::instance()->second_table() . ' ON (' . EEM_Event_Venue::instance()->table() . '.VNU_ID = ' . EEM_Event_Venue::instance()->second_table() . '.VNU_ID )'; |
|
316 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->table().' ON ('.$wpdb->posts.'.ID = '.EEM_Event_Venue::instance()->table().'.EVT_ID )'; |
|
317 | + $SQL .= ' LEFT JOIN '.EEM_Event_Venue::instance()->second_table().' ON ('.EEM_Event_Venue::instance()->table().'.VNU_ID = '.EEM_Event_Venue::instance()->second_table().'.VNU_ID )'; |
|
318 | 318 | break; |
319 | 319 | |
320 | 320 | break; |
@@ -331,16 +331,16 @@ discard block |
||
331 | 331 | * @access public |
332 | 332 | * @return void |
333 | 333 | */ |
334 | - public function posts_where( $SQL, WP_Query $wp_query ) { |
|
335 | - if ( isset( $wp_query->query_vars ) && isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'espresso_events' ) { |
|
334 | + public function posts_where($SQL, WP_Query $wp_query) { |
|
335 | + if (isset($wp_query->query_vars) && isset($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'espresso_events') { |
|
336 | 336 | // Show Expired ? |
337 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired( EED_Events_Archive_Filters::_show_expired() ); |
|
337 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_show_expired(EED_Events_Archive_Filters::_show_expired()); |
|
338 | 338 | // Category |
339 | 339 | //$elf_category = EED_Events_Archive_Filters::_event_category_slug(); |
340 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug( EED_Events_Archive_Filters::_event_category_slug() ); |
|
340 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_category_slug(EED_Events_Archive_Filters::_event_category_slug()); |
|
341 | 341 | // Start Date |
342 | 342 | //$elf_month = EED_Events_Archive_Filters::_display_month(); |
343 | - $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month( EED_Events_Archive_Filters::_display_month() ); |
|
343 | + $SQL .= EED_Events_Archive_Filters::posts_where_sql_for_event_list_month(EED_Events_Archive_Filters::_display_month()); |
|
344 | 344 | } |
345 | 345 | return $SQL; |
346 | 346 | } |
@@ -353,8 +353,8 @@ discard block |
||
353 | 353 | * @param boolean $show_expired if TRUE, then displayed past events |
354 | 354 | * @return string |
355 | 355 | */ |
356 | - public static function posts_where_sql_for_show_expired( $show_expired = FALSE ) { |
|
357 | - return ! $show_expired ? ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end > "' . date('Y-m-d H:s:i') . '" ' : ''; |
|
356 | + public static function posts_where_sql_for_show_expired($show_expired = FALSE) { |
|
357 | + return ! $show_expired ? ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end > "'.date('Y-m-d H:s:i').'" ' : ''; |
|
358 | 358 | } |
359 | 359 | |
360 | 360 | |
@@ -365,9 +365,9 @@ discard block |
||
365 | 365 | * @param boolean $event_category_slug |
366 | 366 | * @return string |
367 | 367 | */ |
368 | - public static function posts_where_sql_for_event_category_slug( $event_category_slug = NULL ) { |
|
368 | + public static function posts_where_sql_for_event_category_slug($event_category_slug = NULL) { |
|
369 | 369 | global $wpdb; |
370 | - return ! empty( $event_category_slug ) ? ' AND ' . $wpdb->terms . '.slug = "' . $event_category_slug . '" ' : ''; |
|
370 | + return ! empty($event_category_slug) ? ' AND '.$wpdb->terms.'.slug = "'.$event_category_slug.'" ' : ''; |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | /** |
@@ -377,15 +377,15 @@ discard block |
||
377 | 377 | * @param boolean $month |
378 | 378 | * @return string |
379 | 379 | */ |
380 | - public static function posts_where_sql_for_event_list_month( $month = NULL ) { |
|
381 | - $SQL= ''; |
|
382 | - if ( ! empty( $month )) { |
|
380 | + public static function posts_where_sql_for_event_list_month($month = NULL) { |
|
381 | + $SQL = ''; |
|
382 | + if ( ! empty($month)) { |
|
383 | 383 | // event start date is LESS than the end of the month ( so nothing that doesn't start until next month ) |
384 | - $SQL = ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start'; |
|
385 | - $SQL .= ' <= "' . date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '"'; |
|
384 | + $SQL = ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_start'; |
|
385 | + $SQL .= ' <= "'.date('Y-m-t 23:59:59', \EEH_DTT_Helper::first_of_month_timestamp($month)).'"'; |
|
386 | 386 | // event end date is GREATER than the start of the month ( so nothing that ended before this month ) |
387 | - $SQL .= ' AND ' . EEM_Datetime::instance()->table() . '.DTT_EVT_end'; |
|
388 | - $SQL .= ' >= "' . date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)) . '" '; |
|
387 | + $SQL .= ' AND '.EEM_Datetime::instance()->table().'.DTT_EVT_end'; |
|
388 | + $SQL .= ' >= "'.date('Y-m-d 0:0:00', \EEH_DTT_Helper::first_of_month_timestamp($month)).'" '; |
|
389 | 389 | } |
390 | 390 | return $SQL; |
391 | 391 | } |
@@ -397,9 +397,9 @@ discard block |
||
397 | 397 | * @access public |
398 | 398 | * @return void |
399 | 399 | */ |
400 | - public function posts_orderby( $SQL, WP_Query $wp_query ) { |
|
401 | - if ( isset( $wp_query->query ) && isset( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] == 'espresso_events' ) { |
|
402 | - $SQL = EED_Events_Archive_Filters::posts_orderby_sql( array( 'start_date' )); |
|
400 | + public function posts_orderby($SQL, WP_Query $wp_query) { |
|
401 | + if (isset($wp_query->query) && isset($wp_query->query['post_type']) && $wp_query->query['post_type'] == 'espresso_events') { |
|
402 | + $SQL = EED_Events_Archive_Filters::posts_orderby_sql(array('start_date')); |
|
403 | 403 | } |
404 | 404 | return $SQL; |
405 | 405 | } |
@@ -428,54 +428,54 @@ discard block |
||
428 | 428 | * @param boolean $orderby_params |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public static function posts_orderby_sql( $orderby_params = array(), $sort = 'ASC' ) { |
|
431 | + public static function posts_orderby_sql($orderby_params = array(), $sort = 'ASC') { |
|
432 | 432 | global $wpdb; |
433 | 433 | $SQL = ''; |
434 | 434 | $cntr = 1; |
435 | - $orderby_params = is_array( $orderby_params ) ? $orderby_params : array( $orderby_params ); |
|
436 | - foreach( $orderby_params as $orderby ) { |
|
437 | - $glue = $cntr == 1 || $cntr == count( $orderby_params ) ? ' ' : ', '; |
|
438 | - switch ( $orderby ) { |
|
435 | + $orderby_params = is_array($orderby_params) ? $orderby_params : array($orderby_params); |
|
436 | + foreach ($orderby_params as $orderby) { |
|
437 | + $glue = $cntr == 1 || $cntr == count($orderby_params) ? ' ' : ', '; |
|
438 | + switch ($orderby) { |
|
439 | 439 | |
440 | 440 | case 'id' : |
441 | 441 | case 'ID' : |
442 | - $SQL .= $glue . $wpdb->posts . '.ID ' . $sort; |
|
442 | + $SQL .= $glue.$wpdb->posts.'.ID '.$sort; |
|
443 | 443 | break; |
444 | 444 | |
445 | 445 | case 'start_date' : |
446 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_start ' . $sort; |
|
446 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_start '.$sort; |
|
447 | 447 | break; |
448 | 448 | |
449 | 449 | case 'end_date' : |
450 | - $SQL .= $glue . EEM_Datetime::instance()->table() . '.DTT_EVT_end ' . $sort; |
|
450 | + $SQL .= $glue.EEM_Datetime::instance()->table().'.DTT_EVT_end '.$sort; |
|
451 | 451 | break; |
452 | 452 | |
453 | 453 | case 'event_name' : |
454 | - $SQL .= $glue . $wpdb->posts . '.post_title ' . $sort; |
|
454 | + $SQL .= $glue.$wpdb->posts.'.post_title '.$sort; |
|
455 | 455 | break; |
456 | 456 | |
457 | 457 | case 'category_slug' : |
458 | - $SQL .= $glue . $wpdb->terms . '.slug ' . $sort; |
|
458 | + $SQL .= $glue.$wpdb->terms.'.slug '.$sort; |
|
459 | 459 | break; |
460 | 460 | |
461 | 461 | case 'ticket_start' : |
462 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_start_date ' . $sort; |
|
462 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_start_date '.$sort; |
|
463 | 463 | break; |
464 | 464 | |
465 | 465 | case 'ticket_end' : |
466 | - $SQL .= $glue . EEM_Ticket::instance()->table() . '.TKT_end_date ' . $sort; |
|
466 | + $SQL .= $glue.EEM_Ticket::instance()->table().'.TKT_end_date '.$sort; |
|
467 | 467 | break; |
468 | 468 | |
469 | 469 | case 'venue_title' : |
470 | - $SQL .= $glue . 'venue_title ' . $sort; |
|
470 | + $SQL .= $glue.'venue_title '.$sort; |
|
471 | 471 | break; |
472 | 472 | |
473 | 473 | case 'city' : |
474 | - $SQL .= $glue . EEM_Venue::instance()->second_table() . '.VNU_city ' . $sort; |
|
474 | + $SQL .= $glue.EEM_Venue::instance()->second_table().'.VNU_city '.$sort; |
|
475 | 475 | break; |
476 | 476 | |
477 | 477 | case 'state' : |
478 | - $SQL .= $glue . EEM_State::instance()->table() . '.STA_name ' . $sort; |
|
478 | + $SQL .= $glue.EEM_State::instance()->table().'.STA_name '.$sort; |
|
479 | 479 | break; |
480 | 480 | |
481 | 481 | } |
@@ -495,26 +495,26 @@ discard block |
||
495 | 495 | */ |
496 | 496 | public function template_redirect() { |
497 | 497 | // add event list filters |
498 | - add_action( 'loop_start', array( $this, 'event_list_template_filters' )); |
|
498 | + add_action('loop_start', array($this, 'event_list_template_filters')); |
|
499 | 499 | // and pagination |
500 | - add_action( 'loop_start', array( $this, 'event_list_pagination' )); |
|
501 | - add_action( 'loop_end', array( $this, 'event_list_pagination' )); |
|
500 | + add_action('loop_start', array($this, 'event_list_pagination')); |
|
501 | + add_action('loop_end', array($this, 'event_list_pagination')); |
|
502 | 502 | // if NOT a custom template |
503 | - if ( EE_Registry::instance()->load_core( 'Front_Controller', array(), false, true )->get_selected_template() != 'archive-espresso_events.php' ) { |
|
503 | + if (EE_Registry::instance()->load_core('Front_Controller', array(), false, true)->get_selected_template() != 'archive-espresso_events.php') { |
|
504 | 504 | // don't know if theme uses the_excerpt |
505 | - add_filter( 'the_excerpt', array( $this, 'event_details' ), 100 ); |
|
506 | - add_filter( 'the_excerpt', array( $this, 'event_tickets' ), 110 ); |
|
507 | - add_filter( 'the_excerpt', array( $this, 'event_datetimes' ), 120 ); |
|
508 | - add_filter( 'the_excerpt', array( $this, 'event_venues' ), 130 ); |
|
505 | + add_filter('the_excerpt', array($this, 'event_details'), 100); |
|
506 | + add_filter('the_excerpt', array($this, 'event_tickets'), 110); |
|
507 | + add_filter('the_excerpt', array($this, 'event_datetimes'), 120); |
|
508 | + add_filter('the_excerpt', array($this, 'event_venues'), 130); |
|
509 | 509 | // or the_content |
510 | - add_filter( 'the_content', array( $this, 'event_details' ), 100 ); |
|
511 | - add_filter( 'the_content', array( $this, 'event_tickets' ), 110 ); |
|
512 | - add_filter( 'the_content', array( $this, 'event_datetimes' ), 120 ); |
|
513 | - add_filter( 'the_content', array( $this, 'event_venues' ), 130 ); |
|
510 | + add_filter('the_content', array($this, 'event_details'), 100); |
|
511 | + add_filter('the_content', array($this, 'event_tickets'), 110); |
|
512 | + add_filter('the_content', array($this, 'event_datetimes'), 120); |
|
513 | + add_filter('the_content', array($this, 'event_venues'), 130); |
|
514 | 514 | } else { |
515 | - remove_all_filters( 'excerpt_length' ); |
|
516 | - add_filter( 'excerpt_length', array( $this, 'excerpt_length' ), 10 ); |
|
517 | - add_filter( 'excerpt_more', array( $this, 'excerpt_more' ), 10 ); |
|
515 | + remove_all_filters('excerpt_length'); |
|
516 | + add_filter('excerpt_length', array($this, 'excerpt_length'), 10); |
|
517 | + add_filter('excerpt_more', array($this, 'excerpt_more'), 10); |
|
518 | 518 | } |
519 | 519 | } |
520 | 520 | |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | * @return void |
528 | 528 | */ |
529 | 529 | public function event_list_pagination() { |
530 | - echo '<div class="ee-pagination-dv ee-clear-float">' . espresso_event_list_pagination() . '</div>'; |
|
530 | + echo '<div class="ee-pagination-dv ee-clear-float">'.espresso_event_list_pagination().'</div>'; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | |
@@ -538,8 +538,8 @@ discard block |
||
538 | 538 | * @param string $content |
539 | 539 | * @return void |
540 | 540 | */ |
541 | - public function event_details( $content ) { |
|
542 | - return EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-details.php', array( 'the_content' => $content ), TRUE ); |
|
541 | + public function event_details($content) { |
|
542 | + return EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-details.php', array('the_content' => $content), TRUE); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | |
@@ -550,8 +550,8 @@ discard block |
||
550 | 550 | * @param string $content |
551 | 551 | * @return void |
552 | 552 | */ |
553 | - public function event_tickets( $content ) { |
|
554 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-tickets.php', array(), TRUE ); |
|
553 | + public function event_tickets($content) { |
|
554 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-tickets.php', array(), TRUE); |
|
555 | 555 | } |
556 | 556 | |
557 | 557 | /** |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | * @param string $content |
562 | 562 | * @return void |
563 | 563 | */ |
564 | - public function event_datetimes( $content ) { |
|
565 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-datetimes.php', array(), TRUE ); |
|
564 | + public function event_datetimes($content) { |
|
565 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-datetimes.php', array(), TRUE); |
|
566 | 566 | } |
567 | 567 | |
568 | 568 | /** |
@@ -572,8 +572,8 @@ discard block |
||
572 | 572 | * @param string $content |
573 | 573 | * @return void |
574 | 574 | */ |
575 | - public function event_venues( $content ) { |
|
576 | - return $content . EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'content-espresso_events-venues.php', array(), TRUE ); |
|
575 | + public function event_venues($content) { |
|
576 | + return $content.EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'content-espresso_events-venues.php', array(), TRUE); |
|
577 | 577 | } |
578 | 578 | |
579 | 579 | |
@@ -588,13 +588,13 @@ discard block |
||
588 | 588 | * @return void |
589 | 589 | */ |
590 | 590 | private function _load_assests() { |
591 | - do_action( 'AHEE__EED_Events_Archive_Filters__before_load_assests' ); |
|
591 | + do_action('AHEE__EED_Events_Archive_Filters__before_load_assests'); |
|
592 | 592 | wp_enqueue_style('espresso_default'); |
593 | 593 | wp_enqueue_style('espresso_custom_css'); |
594 | - add_filter( 'FHEE_load_EE_Session', '__return_true' ); |
|
595 | - add_action('wp_enqueue_scripts', array( $this, 'wp_enqueue_scripts' ), 10 ); |
|
596 | - if ( EE_Registry::instance()->CFG->map_settings->use_google_maps ) { |
|
597 | - add_action('wp_enqueue_scripts', array( 'EEH_Maps', 'espresso_google_map_js' ), 11 ); |
|
594 | + add_filter('FHEE_load_EE_Session', '__return_true'); |
|
595 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 10); |
|
596 | + if (EE_Registry::instance()->CFG->map_settings->use_google_maps) { |
|
597 | + add_action('wp_enqueue_scripts', array('EEH_Maps', 'espresso_google_map_js'), 11); |
|
598 | 598 | } |
599 | 599 | //add_filter( 'the_excerpt', array( $this, 'the_excerpt' ), 999 ); |
600 | 600 | } |
@@ -609,8 +609,8 @@ discard block |
||
609 | 609 | * @access private |
610 | 610 | * @return string |
611 | 611 | */ |
612 | - private function _get_template( $which = 'part' ) { |
|
613 | - return EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'; |
|
612 | + private function _get_template($which = 'part') { |
|
613 | + return EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'; |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | |
@@ -621,13 +621,13 @@ discard block |
||
621 | 621 | * @access public |
622 | 622 | * @return void |
623 | 623 | */ |
624 | - public function excerpt_length( $length ) { |
|
624 | + public function excerpt_length($length) { |
|
625 | 625 | |
626 | - if ( self::$_type == 'grid' ) { |
|
626 | + if (self::$_type == 'grid') { |
|
627 | 627 | return 36; |
628 | 628 | } |
629 | 629 | |
630 | - switch ( EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) { |
|
630 | + switch (EE_Registry::instance()->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) { |
|
631 | 631 | case 'tiny' : |
632 | 632 | return 12; |
633 | 633 | break; |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | * @access public |
652 | 652 | * @return void |
653 | 653 | */ |
654 | - public function excerpt_more( $more ) { |
|
654 | + public function excerpt_more($more) { |
|
655 | 655 | return '…'; |
656 | 656 | } |
657 | 657 | |
@@ -681,22 +681,22 @@ discard block |
||
681 | 681 | */ |
682 | 682 | public function wp_enqueue_scripts() { |
683 | 683 | // get some style |
684 | - if ( apply_filters( 'FHEE_enable_default_espresso_css', FALSE ) ) { |
|
684 | + if (apply_filters('FHEE_enable_default_espresso_css', FALSE)) { |
|
685 | 685 | // first check uploads folder |
686 | - if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css' )) { |
|
687 | - wp_register_style( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' )); |
|
686 | + if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.css')) { |
|
687 | + wp_register_style('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default')); |
|
688 | 688 | } else { |
689 | - wp_register_style( 'archive-espresso_events', EE_TEMPLATES_URL . EE_Config::get_current_theme() . DS . 'archive-espresso_events.css', array( 'dashicons', 'espresso_default' )); |
|
689 | + wp_register_style('archive-espresso_events', EE_TEMPLATES_URL.EE_Config::get_current_theme().DS.'archive-espresso_events.css', array('dashicons', 'espresso_default')); |
|
690 | 690 | } |
691 | - if ( is_readable( get_stylesheet_directory() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js' )) { |
|
692 | - wp_register_script( 'archive-espresso_events', get_stylesheet_directory_uri() . EE_Config::get_current_theme() . DS . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE ); |
|
691 | + if (is_readable(get_stylesheet_directory().EE_Config::get_current_theme().DS.'archive-espresso_events.js')) { |
|
692 | + wp_register_script('archive-espresso_events', get_stylesheet_directory_uri().EE_Config::get_current_theme().DS.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE); |
|
693 | 693 | } else { |
694 | - wp_register_script( 'archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL . 'archive-espresso_events.js', array( 'jquery-masonry' ), '1.0', TRUE ); |
|
694 | + wp_register_script('archive-espresso_events', EVENTS_ARCHIVE_ASSETS_URL.'archive-espresso_events.js', array('jquery-masonry'), '1.0', TRUE); |
|
695 | 695 | } |
696 | - wp_enqueue_style( 'archive-espresso_events' ); |
|
697 | - wp_enqueue_script( 'jquery-masonry' ); |
|
698 | - wp_enqueue_script( 'archive-espresso_events' ); |
|
699 | - add_action( 'wp_footer', array( 'EED_Events_Archive_Filters', 'localize_grid_event_lists' ), 1 ); |
|
696 | + wp_enqueue_style('archive-espresso_events'); |
|
697 | + wp_enqueue_script('jquery-masonry'); |
|
698 | + wp_enqueue_script('archive-espresso_events'); |
|
699 | + add_action('wp_footer', array('EED_Events_Archive_Filters', 'localize_grid_event_lists'), 1); |
|
700 | 700 | } |
701 | 701 | } |
702 | 702 | |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | * @return void |
712 | 712 | */ |
713 | 713 | public static function localize_grid_event_lists() { |
714 | - wp_localize_script( 'archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists ); |
|
714 | + wp_localize_script('archive-espresso_events', 'espresso_grid_event_lists', EED_Events_Archive_Filters::$espresso_grid_event_lists); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | |
@@ -726,9 +726,9 @@ discard block |
||
726 | 726 | */ |
727 | 727 | public static function template_settings_form() { |
728 | 728 | $EE = EE_Registry::instance(); |
729 | - $EE->CFG->template_settings->EED_Events_Archive_Filters = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config(); |
|
730 | - $EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters( 'FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters ); |
|
731 | - EEH_Template::display_template( EVENTS_ARCHIVE_TEMPLATES_PATH . 'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters ); |
|
729 | + $EE->CFG->template_settings->EED_Events_Archive_Filters = isset($EE->CFG->template_settings->EED_Events_Archive_Filters) ? $EE->CFG->template_settings->EED_Events_Archive_Filters : new EE_Events_Archive_Config(); |
|
730 | + $EE->CFG->template_settings->EED_Events_Archive_Filters = apply_filters('FHEE__Event_List__template_settings_form__event_list_config', $EE->CFG->template_settings->EED_Events_Archive_Filters); |
|
731 | + EEH_Template::display_template(EVENTS_ARCHIVE_TEMPLATES_PATH.'admin-event-list-settings.template.php', $EE->CFG->template_settings->EED_Events_Archive_Filters); |
|
732 | 732 | } |
733 | 733 | |
734 | 734 | |
@@ -742,16 +742,16 @@ discard block |
||
742 | 742 | * @static |
743 | 743 | * @return void |
744 | 744 | */ |
745 | - public static function set_default_settings( $CFG ) { |
|
745 | + public static function set_default_settings($CFG) { |
|
746 | 746 | //EEH_Debug_Tools::printr( $CFG, '$CFG <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
747 | - $CFG->display_description = isset( $CFG->display_description ) && ! empty( $CFG->display_description ) ? $CFG->display_description : 1; |
|
748 | - $CFG->display_address = isset( $CFG->display_address ) && ! empty( $CFG->display_address ) ? $CFG->display_address : TRUE; |
|
749 | - $CFG->display_venue_details = isset( $CFG->display_venue_details ) && ! empty( $CFG->display_venue_details ) ? $CFG->display_venue_details : TRUE; |
|
750 | - $CFG->display_expired_events = isset( $CFG->display_expired_events ) && ! empty( $CFG->display_expired_events ) ? $CFG->display_expired_events : FALSE; |
|
751 | - $CFG->default_type = isset( $CFG->default_type ) && ! empty( $CFG->default_type ) ? $CFG->default_type : 'grid'; |
|
752 | - $CFG->event_list_grid_size = isset( $CFG->event_list_grid_size ) && ! empty( $CFG->event_list_grid_size ) ? $CFG->event_list_grid_size : 'medium'; |
|
753 | - $CFG->templates['full'] = isset( $CFG->templates['full'] ) && ! empty( $CFG->templates['full'] ) ? $CFG->templates['full'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php'; |
|
754 | - $CFG->templates['part'] = isset( $CFG->templates['part'] ) && ! empty( $CFG->templates['part'] ) ? $CFG->templates['part'] : EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php'; |
|
747 | + $CFG->display_description = isset($CFG->display_description) && ! empty($CFG->display_description) ? $CFG->display_description : 1; |
|
748 | + $CFG->display_address = isset($CFG->display_address) && ! empty($CFG->display_address) ? $CFG->display_address : TRUE; |
|
749 | + $CFG->display_venue_details = isset($CFG->display_venue_details) && ! empty($CFG->display_venue_details) ? $CFG->display_venue_details : TRUE; |
|
750 | + $CFG->display_expired_events = isset($CFG->display_expired_events) && ! empty($CFG->display_expired_events) ? $CFG->display_expired_events : FALSE; |
|
751 | + $CFG->default_type = isset($CFG->default_type) && ! empty($CFG->default_type) ? $CFG->default_type : 'grid'; |
|
752 | + $CFG->event_list_grid_size = isset($CFG->event_list_grid_size) && ! empty($CFG->event_list_grid_size) ? $CFG->event_list_grid_size : 'medium'; |
|
753 | + $CFG->templates['full'] = isset($CFG->templates['full']) && ! empty($CFG->templates['full']) ? $CFG->templates['full'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php'; |
|
754 | + $CFG->templates['part'] = isset($CFG->templates['part']) && ! empty($CFG->templates['part']) ? $CFG->templates['part'] : EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php'; |
|
755 | 755 | return $CFG; |
756 | 756 | } |
757 | 757 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | * @access public |
764 | 764 | * @return void |
765 | 765 | */ |
766 | - public function filter_config( $CFG ) { |
|
766 | + public function filter_config($CFG) { |
|
767 | 767 | return $CFG; |
768 | 768 | } |
769 | 769 | |
@@ -776,32 +776,32 @@ discard block |
||
776 | 776 | * @access public |
777 | 777 | * @return void |
778 | 778 | */ |
779 | - public static function update_template_settings( $CFG, $REQ ) { |
|
779 | + public static function update_template_settings($CFG, $REQ) { |
|
780 | 780 | // EEH_Debug_Tools::printr( $REQ, '$REQ <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
781 | 781 | // EEH_Debug_Tools::printr( $CFG, '$CFG <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
782 | 782 | //$CFG->template_settings->EED_Events_Archive_Filters = new stdClass(); |
783 | - $CFG->EED_Events_Archive_Filters->display_description = isset( $REQ['display_description_in_event_list'] ) ? absint( $REQ['display_description_in_event_list'] ) : 1; |
|
784 | - $CFG->EED_Events_Archive_Filters->display_address = isset( $REQ['display_address_in_event_list'] ) ? absint( $REQ['display_address_in_event_list'] ) : TRUE; |
|
785 | - $CFG->EED_Events_Archive_Filters->display_venue_details = isset( $REQ['display_venue_details_in_event_list'] ) ? absint( $REQ['display_venue_details_in_event_list'] ) : TRUE; |
|
786 | - $CFG->EED_Events_Archive_Filters->display_expired_events = isset( $REQ['display_expired_events'] ) ? absint( $REQ['display_expired_events'] ) : FALSE; |
|
787 | - $CFG->EED_Events_Archive_Filters->default_type = isset( $REQ['default_type'] ) ? sanitize_text_field( $REQ['default_type'] ) : 'grid'; |
|
788 | - $CFG->EED_Events_Archive_Filters->event_list_grid_size = isset( $REQ['event_list_grid_size'] ) ? sanitize_text_field( $REQ['event_list_grid_size'] ) : 'medium'; |
|
783 | + $CFG->EED_Events_Archive_Filters->display_description = isset($REQ['display_description_in_event_list']) ? absint($REQ['display_description_in_event_list']) : 1; |
|
784 | + $CFG->EED_Events_Archive_Filters->display_address = isset($REQ['display_address_in_event_list']) ? absint($REQ['display_address_in_event_list']) : TRUE; |
|
785 | + $CFG->EED_Events_Archive_Filters->display_venue_details = isset($REQ['display_venue_details_in_event_list']) ? absint($REQ['display_venue_details_in_event_list']) : TRUE; |
|
786 | + $CFG->EED_Events_Archive_Filters->display_expired_events = isset($REQ['display_expired_events']) ? absint($REQ['display_expired_events']) : FALSE; |
|
787 | + $CFG->EED_Events_Archive_Filters->default_type = isset($REQ['default_type']) ? sanitize_text_field($REQ['default_type']) : 'grid'; |
|
788 | + $CFG->EED_Events_Archive_Filters->event_list_grid_size = isset($REQ['event_list_grid_size']) ? sanitize_text_field($REQ['event_list_grid_size']) : 'medium'; |
|
789 | 789 | $CFG->EED_Events_Archive_Filters->templates = array( |
790 | - 'full' => EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events.php' |
|
790 | + 'full' => EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events.php' |
|
791 | 791 | ); |
792 | 792 | |
793 | - switch ( $CFG->EED_Events_Archive_Filters->default_type ) { |
|
793 | + switch ($CFG->EED_Events_Archive_Filters->default_type) { |
|
794 | 794 | case 'dates' : |
795 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-dates-view.php'; |
|
795 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-dates-view.php'; |
|
796 | 796 | break; |
797 | 797 | case 'text' : |
798 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-text-view.php'; |
|
798 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-text-view.php'; |
|
799 | 799 | break; |
800 | 800 | default : |
801 | - $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-grid-view.php'; |
|
801 | + $CFG->EED_Events_Archive_Filters->templates['part'] = EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-grid-view.php'; |
|
802 | 802 | } |
803 | 803 | |
804 | - $CFG->EED_Events_Archive_Filters = isset( $REQ['reset_event_list_settings'] ) && absint( $REQ['reset_event_list_settings'] ) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters; |
|
804 | + $CFG->EED_Events_Archive_Filters = isset($REQ['reset_event_list_settings']) && absint($REQ['reset_event_list_settings']) == 1 ? new EE_Events_Archive_Config() : $CFG->EED_Events_Archive_Filters; |
|
805 | 805 | return $CFG; |
806 | 806 | } |
807 | 807 | |
@@ -816,7 +816,7 @@ discard block |
||
816 | 816 | * @return void |
817 | 817 | */ |
818 | 818 | public static function get_template_part() { |
819 | - switch ( self::$_type ) { |
|
819 | + switch (self::$_type) { |
|
820 | 820 | case 'dates' : |
821 | 821 | return 'archive-espresso_events-dates-view.php'; |
822 | 822 | break; |
@@ -840,13 +840,13 @@ discard block |
||
840 | 840 | */ |
841 | 841 | public function event_list_template_filters() { |
842 | 842 | $args = array( |
843 | - 'form_url' => get_post_type_archive_link( 'espresso_events' ), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ), |
|
843 | + 'form_url' => get_post_type_archive_link('espresso_events'), //add_query_arg( array( 'post_type' => 'espresso_events' ), home_url() ), |
|
844 | 844 | 'elf_month' => EED_Events_Archive_Filters::_display_month(), |
845 | 845 | 'elf_category' => EED_Events_Archive_Filters::_event_category_slug(), |
846 | 846 | 'elf_show_expired' => EED_Events_Archive_Filters::_show_expired(), |
847 | 847 | 'elf_type' => self::$_type |
848 | 848 | ); |
849 | - EEH_Template::display_template( EE_TEMPLATES . EE_Config::get_current_theme() . DS . 'archive-espresso_events-filters.php', $args ); |
|
849 | + EEH_Template::display_template(EE_TEMPLATES.EE_Config::get_current_theme().DS.'archive-espresso_events-filters.php', $args); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | |
@@ -859,16 +859,16 @@ discard block |
||
859 | 859 | * @access public |
860 | 860 | * @return void |
861 | 861 | */ |
862 | - public static function event_list_css( $extra_class = '' ) { |
|
862 | + public static function event_list_css($extra_class = '') { |
|
863 | 863 | $EE = EE_Registry::instance(); |
864 | - $event_list_css = ! empty( $extra_class ) ? array( $extra_class ) : array(); |
|
864 | + $event_list_css = ! empty($extra_class) ? array($extra_class) : array(); |
|
865 | 865 | $event_list_css[] = 'espresso-event-list-event'; |
866 | - if ( self::$_type == 'grid' ) { |
|
867 | - $event_list_grid_size = isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium'; |
|
868 | - $event_list_css[] = $event_list_grid_size . '-event-list-grid'; |
|
866 | + if (self::$_type == 'grid') { |
|
867 | + $event_list_grid_size = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->event_list_grid_size : 'medium'; |
|
868 | + $event_list_css[] = $event_list_grid_size.'-event-list-grid'; |
|
869 | 869 | } |
870 | - $event_list_css = apply_filters( 'EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css ); |
|
871 | - return implode( ' ', $event_list_css ); |
|
870 | + $event_list_css = apply_filters('EED_Events_Archive_Filters__event_list_css__event_list_css_array', $event_list_css); |
|
871 | + return implode(' ', $event_list_css); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | |
@@ -894,9 +894,9 @@ discard block |
||
894 | 894 | * @access public |
895 | 895 | * @return void |
896 | 896 | */ |
897 | - public static function display_description( $value ) { |
|
897 | + public static function display_description($value) { |
|
898 | 898 | $EE = EE_Registry::instance(); |
899 | - $display_description= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1; |
|
899 | + $display_description = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_description) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_description : 1; |
|
900 | 900 | return $display_description === $value ? TRUE : FALSE; |
901 | 901 | } |
902 | 902 | |
@@ -910,9 +910,9 @@ discard block |
||
910 | 910 | */ |
911 | 911 | public static function display_venue_details() { |
912 | 912 | $EE = EE_Registry::instance(); |
913 | - $display_venue_details= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE; |
|
913 | + $display_venue_details = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_venue_details : TRUE; |
|
914 | 914 | $venue_name = EEH_Venue_View::venue_name(); |
915 | - return $display_venue_details && ! empty( $venue_name ) ? TRUE : FALSE; |
|
915 | + return $display_venue_details && ! empty($venue_name) ? TRUE : FALSE; |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | |
@@ -924,9 +924,9 @@ discard block |
||
924 | 924 | */ |
925 | 925 | public static function display_address() { |
926 | 926 | $EE = EE_Registry::instance(); |
927 | - $display_address= isset( $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address ) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE; |
|
927 | + $display_address = isset($EE->CFG->template_settings->EED_Events_Archive_Filters->display_address) ? $EE->CFG->template_settings->EED_Events_Archive_Filters->display_address : FALSE; |
|
928 | 928 | $venue_name = EEH_Venue_View::venue_name(); |
929 | - return $display_address && ! empty( $venue_name ) ? TRUE : FALSE; |
|
929 | + return $display_address && ! empty($venue_name) ? TRUE : FALSE; |
|
930 | 930 | } |
931 | 931 | |
932 | 932 | |
@@ -940,22 +940,22 @@ discard block |
||
940 | 940 | public static function pagination() { |
941 | 941 | global $wp_query; |
942 | 942 | $big = 999999999; // need an unlikely integer |
943 | - $pagination = paginate_links( array( |
|
944 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
943 | + $pagination = paginate_links(array( |
|
944 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
945 | 945 | 'format' => '?paged=%#%', |
946 | - 'current' => max( 1, get_query_var('paged') ), |
|
946 | + 'current' => max(1, get_query_var('paged')), |
|
947 | 947 | 'total' => $wp_query->max_num_pages, |
948 | 948 | 'show_all' => TRUE, |
949 | 949 | 'end_size' => 10, |
950 | 950 | 'mid_size' => 6, |
951 | 951 | 'prev_next' => TRUE, |
952 | - 'prev_text' => __( '‹ PREV', 'event_espresso' ), |
|
953 | - 'next_text' => __( 'NEXT ›', 'event_espresso' ), |
|
952 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
953 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
954 | 954 | 'type' => 'plain', |
955 | 955 | 'add_args' => FALSE, |
956 | 956 | 'add_fragment' => '' |
957 | 957 | )); |
958 | - return ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; |
|
958 | + return ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : ''; |
|
959 | 959 | } |
960 | 960 | |
961 | 961 | |
@@ -969,7 +969,7 @@ discard block |
||
969 | 969 | * @return void |
970 | 970 | */ |
971 | 971 | public static function event_list_title() { |
972 | - return apply_filters( 'EED_Events_Archive_Filters__event_list_title__event_list_title', __( 'Upcoming Events', 'event_espresso' )); |
|
972 | + return apply_filters('EED_Events_Archive_Filters__event_list_title__event_list_title', __('Upcoming Events', 'event_espresso')); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | * @ link http://www.eventespresso.com |
10 | 10 | * @ version 4+ |
11 | 11 | */ |
12 | -define( 'EE_THEME_FUNCTIONS_LOADED', TRUE ); |
|
12 | +define('EE_THEME_FUNCTIONS_LOADED', TRUE); |
|
13 | 13 | |
14 | -if ( ! function_exists( 'espresso_pagination' ) ) { |
|
14 | +if ( ! function_exists('espresso_pagination')) { |
|
15 | 15 | /** |
16 | 16 | * espresso_pagination |
17 | 17 | * |
@@ -23,21 +23,21 @@ discard block |
||
23 | 23 | $big = 999999999; // need an unlikely integer |
24 | 24 | $pagination = paginate_links( |
25 | 25 | array( |
26 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
26 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
27 | 27 | 'format' => '?paged=%#%', |
28 | - 'current' => max( 1, get_query_var( 'paged' ) ), |
|
28 | + 'current' => max(1, get_query_var('paged')), |
|
29 | 29 | 'total' => $wp_query->max_num_pages, |
30 | 30 | 'show_all' => true, |
31 | 31 | 'end_size' => 10, |
32 | 32 | 'mid_size' => 6, |
33 | 33 | 'prev_next' => true, |
34 | - 'prev_text' => __( '‹ PREV', 'event_espresso' ), |
|
35 | - 'next_text' => __( 'NEXT ›', 'event_espresso' ), |
|
34 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
35 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
36 | 36 | 'type' => 'plain', |
37 | 37 | 'add_args' => false, |
38 | 38 | 'add_fragment' => '' |
39 | 39 | ) |
40 | 40 | ); |
41 | - echo ! empty( $pagination ) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
41 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | /** |
6 | 6 | * Event Espresso |
@@ -16,35 +16,35 @@ discard block |
||
16 | 16 | |
17 | 17 | |
18 | 18 | if ( ! function_exists('espresso_get_template_part')) { |
19 | - /** |
|
20 | - * espresso_get_template_part |
|
21 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
22 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
23 | - * |
|
24 | - * @param string $slug The slug name for the generic template. |
|
25 | - * @param string $name The name of the specialised template. |
|
26 | - * @return string the html output for the formatted money value |
|
27 | - */ |
|
28 | - function espresso_get_template_part($slug = null, $name = null) |
|
29 | - { |
|
30 | - EEH_Template::get_template_part($slug, $name); |
|
31 | - } |
|
19 | + /** |
|
20 | + * espresso_get_template_part |
|
21 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
22 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
23 | + * |
|
24 | + * @param string $slug The slug name for the generic template. |
|
25 | + * @param string $name The name of the specialised template. |
|
26 | + * @return string the html output for the formatted money value |
|
27 | + */ |
|
28 | + function espresso_get_template_part($slug = null, $name = null) |
|
29 | + { |
|
30 | + EEH_Template::get_template_part($slug, $name); |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
35 | 35 | if ( ! function_exists('espresso_get_object_css_class')) { |
36 | - /** |
|
37 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
38 | - * |
|
39 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
40 | - * @param string $prefix added to the beginning of the generated class |
|
41 | - * @param string $suffix added to the end of the generated class |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
45 | - { |
|
46 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
47 | - } |
|
36 | + /** |
|
37 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
38 | + * |
|
39 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
40 | + * @param string $prefix added to the beginning of the generated class |
|
41 | + * @param string $suffix added to the end of the generated class |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
45 | + { |
|
46 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
47 | + } |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | |
@@ -59,650 +59,650 @@ discard block |
||
59 | 59 | class EEH_Template |
60 | 60 | { |
61 | 61 | |
62 | - private static $_espresso_themes = array(); |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
67 | - * |
|
68 | - * @return boolean |
|
69 | - */ |
|
70 | - public static function is_espresso_theme() |
|
71 | - { |
|
72 | - return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
77 | - * load it's functions.php file ( if not already loaded ) |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public static function load_espresso_theme_functions() |
|
82 | - { |
|
83 | - if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
84 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
85 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
93 | - * |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public static function get_espresso_themes() |
|
97 | - { |
|
98 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
99 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
100 | - if (empty($espresso_themes)) { |
|
101 | - return array(); |
|
102 | - } |
|
103 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
104 | - unset($espresso_themes[$key]); |
|
105 | - } |
|
106 | - EEH_Template::$_espresso_themes = array(); |
|
107 | - foreach ($espresso_themes as $espresso_theme) { |
|
108 | - EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
109 | - } |
|
110 | - } |
|
111 | - return EEH_Template::$_espresso_themes; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * EEH_Template::get_template_part |
|
117 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
118 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
119 | - * filtering based off of the entire template part name |
|
120 | - * |
|
121 | - * @param string $slug The slug name for the generic template. |
|
122 | - * @param string $name The name of the specialised template. |
|
123 | - * @param array $template_args |
|
124 | - * @param bool $return_string |
|
125 | - * @return string the html output for the formatted money value |
|
126 | - */ |
|
127 | - public static function get_template_part( |
|
128 | - $slug = null, |
|
129 | - $name = null, |
|
130 | - $template_args = array(), |
|
131 | - $return_string = false |
|
132 | - ) { |
|
133 | - do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
134 | - $templates = array(); |
|
135 | - $name = (string)$name; |
|
136 | - if ($name != '') { |
|
137 | - $templates[] = "{$slug}-{$name}.php"; |
|
138 | - } |
|
139 | - // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
140 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
141 | - EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * locate_template |
|
148 | - * locate a template file by looking in the following places, in the following order: |
|
149 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
150 | - * <assumed full absolute server path> |
|
151 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
152 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
153 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
154 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
155 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
156 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
157 | - * Example: |
|
158 | - * You are using the WordPress Twenty Sixteen theme, |
|
159 | - * and you want to customize the "some-event.template.php" template, |
|
160 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
161 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
162 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
163 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
164 | - * /relative/path/to/some-event.template.php |
|
165 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
166 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
167 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
168 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
169 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
170 | - * Had you passed an absolute path to your template that was in some other location, |
|
171 | - * ie: "/absolute/path/to/some-event.template.php" |
|
172 | - * then the search would have been : |
|
173 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
174 | - * /absolute/path/to/some-event.template.php |
|
175 | - * and stopped there upon finding it in the second location |
|
176 | - * |
|
177 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
178 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
179 | - * @param boolean $load whether to pass the located template path on to the |
|
180 | - * EEH_Template::display_template() method or simply return it |
|
181 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
182 | - * string |
|
183 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
184 | - * generate a custom template or not. Used in places where you don't actually |
|
185 | - * load the template, you just want to know if there's a custom version of it. |
|
186 | - * @return mixed |
|
187 | - */ |
|
188 | - public static function locate_template( |
|
189 | - $templates = array(), |
|
190 | - $template_args = array(), |
|
191 | - $load = true, |
|
192 | - $return_string = true, |
|
193 | - $check_if_custom = false |
|
194 | - ) { |
|
195 | - // first use WP locate_template to check for template in the current theme folder |
|
196 | - $template_path = locate_template($templates); |
|
197 | - |
|
198 | - if ($check_if_custom && ! empty($template_path)) { |
|
199 | - return true; |
|
200 | - } |
|
201 | - |
|
202 | - // not in the theme |
|
203 | - if (empty($template_path)) { |
|
204 | - // not even a template to look for ? |
|
205 | - if (empty($templates)) { |
|
206 | - // get post_type |
|
207 | - $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
208 | - // get array of EE Custom Post Types |
|
209 | - $EE_CPTs = EE_Register_CPTs::get_CPTs(); |
|
210 | - // build template name based on request |
|
211 | - if (isset($EE_CPTs[$post_type])) { |
|
212 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
213 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
214 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
215 | - } |
|
216 | - } |
|
217 | - // currently active EE template theme |
|
218 | - $current_theme = EE_Config::get_current_theme(); |
|
219 | - |
|
220 | - // array of paths to folders that may contain templates |
|
221 | - $template_folder_paths = array( |
|
222 | - // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
223 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
224 | - // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
225 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
226 | - ); |
|
227 | - |
|
228 | - //add core plugin folders for checking only if we're not $check_if_custom |
|
229 | - if ( ! $check_if_custom) { |
|
230 | - $core_paths = array( |
|
231 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
232 | - EE_PUBLIC . $current_theme, |
|
233 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
234 | - EE_TEMPLATES . $current_theme, |
|
235 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
236 | - EE_PLUGIN_DIR_PATH, |
|
237 | - ); |
|
238 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
239 | - } |
|
240 | - |
|
241 | - // now filter that array |
|
242 | - $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', |
|
243 | - $template_folder_paths); |
|
244 | - $templates = is_array($templates) ? $templates : array($templates); |
|
245 | - $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
246 | - // array to hold all possible template paths |
|
247 | - $full_template_paths = array(); |
|
248 | - |
|
249 | - // loop through $templates |
|
250 | - foreach ($templates as $template) { |
|
251 | - // normalize directory separators |
|
252 | - $template = EEH_File::standardise_directory_separators($template); |
|
253 | - $file_name = basename($template); |
|
254 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
255 | - // while looping through all template folder paths |
|
256 | - foreach ($template_folder_paths as $template_folder_path) { |
|
257 | - // normalize directory separators |
|
258 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
259 | - // determine if any common base path exists between the two paths |
|
260 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
261 | - array($template_folder_path, $template_path_minus_file_name) |
|
262 | - ); |
|
263 | - if ($common_base_path !== '') { |
|
264 | - // both paths have a common base, so just tack the filename onto our search path |
|
265 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
266 | - } else { |
|
267 | - // no common base path, so let's just concatenate |
|
268 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
269 | - } |
|
270 | - // build up our template locations array by adding our resolved paths |
|
271 | - $full_template_paths[] = $resolved_path; |
|
272 | - } |
|
273 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
274 | - array_unshift($full_template_paths, $template); |
|
275 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
276 | - array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
277 | - } |
|
278 | - // filter final array of full template paths |
|
279 | - $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
|
280 | - $full_template_paths, $file_name); |
|
281 | - // now loop through our final array of template location paths and check each location |
|
282 | - foreach ((array)$full_template_paths as $full_template_path) { |
|
283 | - if (is_readable($full_template_path)) { |
|
284 | - $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
285 | - break; |
|
286 | - } |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - // hook that can be used to display the full template path that will be used |
|
291 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
292 | - |
|
293 | - // if we got it and you want to see it... |
|
294 | - if ($template_path && $load && ! $check_if_custom) { |
|
295 | - if ($return_string) { |
|
296 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
297 | - } else { |
|
298 | - EEH_Template::display_template($template_path, $template_args, false); |
|
299 | - } |
|
300 | - } |
|
301 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * _find_common_base_path |
|
307 | - * given two paths, this determines if there is a common base path between the two |
|
308 | - * |
|
309 | - * @param array $paths |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - protected static function _find_common_base_path($paths) |
|
313 | - { |
|
314 | - $last_offset = 0; |
|
315 | - $common_base_path = ''; |
|
316 | - while (($index = strpos($paths[0], DS, $last_offset)) !== false) { |
|
317 | - $dir_length = $index - $last_offset + 1; |
|
318 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
319 | - foreach ($paths as $path) { |
|
320 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
321 | - return $common_base_path; |
|
322 | - } |
|
323 | - } |
|
324 | - $common_base_path .= $directory; |
|
325 | - $last_offset = $index + 1; |
|
326 | - } |
|
327 | - return substr($common_base_path, 0, -1); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * load and display a template |
|
333 | - * |
|
334 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
335 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
336 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
337 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
338 | - * not found or is not readable |
|
339 | - * @return mixed string |
|
340 | - * @throws \DomainException |
|
341 | - */ |
|
62 | + private static $_espresso_themes = array(); |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
67 | + * |
|
68 | + * @return boolean |
|
69 | + */ |
|
70 | + public static function is_espresso_theme() |
|
71 | + { |
|
72 | + return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
77 | + * load it's functions.php file ( if not already loaded ) |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public static function load_espresso_theme_functions() |
|
82 | + { |
|
83 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
84 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
85 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
93 | + * |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public static function get_espresso_themes() |
|
97 | + { |
|
98 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
99 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
100 | + if (empty($espresso_themes)) { |
|
101 | + return array(); |
|
102 | + } |
|
103 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
104 | + unset($espresso_themes[$key]); |
|
105 | + } |
|
106 | + EEH_Template::$_espresso_themes = array(); |
|
107 | + foreach ($espresso_themes as $espresso_theme) { |
|
108 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
109 | + } |
|
110 | + } |
|
111 | + return EEH_Template::$_espresso_themes; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * EEH_Template::get_template_part |
|
117 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
118 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
119 | + * filtering based off of the entire template part name |
|
120 | + * |
|
121 | + * @param string $slug The slug name for the generic template. |
|
122 | + * @param string $name The name of the specialised template. |
|
123 | + * @param array $template_args |
|
124 | + * @param bool $return_string |
|
125 | + * @return string the html output for the formatted money value |
|
126 | + */ |
|
127 | + public static function get_template_part( |
|
128 | + $slug = null, |
|
129 | + $name = null, |
|
130 | + $template_args = array(), |
|
131 | + $return_string = false |
|
132 | + ) { |
|
133 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
134 | + $templates = array(); |
|
135 | + $name = (string)$name; |
|
136 | + if ($name != '') { |
|
137 | + $templates[] = "{$slug}-{$name}.php"; |
|
138 | + } |
|
139 | + // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
140 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
141 | + EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * locate_template |
|
148 | + * locate a template file by looking in the following places, in the following order: |
|
149 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
150 | + * <assumed full absolute server path> |
|
151 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
152 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
153 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
154 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
155 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
156 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
157 | + * Example: |
|
158 | + * You are using the WordPress Twenty Sixteen theme, |
|
159 | + * and you want to customize the "some-event.template.php" template, |
|
160 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
161 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
162 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
163 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
164 | + * /relative/path/to/some-event.template.php |
|
165 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
166 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
167 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
168 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
169 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
170 | + * Had you passed an absolute path to your template that was in some other location, |
|
171 | + * ie: "/absolute/path/to/some-event.template.php" |
|
172 | + * then the search would have been : |
|
173 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
174 | + * /absolute/path/to/some-event.template.php |
|
175 | + * and stopped there upon finding it in the second location |
|
176 | + * |
|
177 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
178 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
179 | + * @param boolean $load whether to pass the located template path on to the |
|
180 | + * EEH_Template::display_template() method or simply return it |
|
181 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
182 | + * string |
|
183 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
184 | + * generate a custom template or not. Used in places where you don't actually |
|
185 | + * load the template, you just want to know if there's a custom version of it. |
|
186 | + * @return mixed |
|
187 | + */ |
|
188 | + public static function locate_template( |
|
189 | + $templates = array(), |
|
190 | + $template_args = array(), |
|
191 | + $load = true, |
|
192 | + $return_string = true, |
|
193 | + $check_if_custom = false |
|
194 | + ) { |
|
195 | + // first use WP locate_template to check for template in the current theme folder |
|
196 | + $template_path = locate_template($templates); |
|
197 | + |
|
198 | + if ($check_if_custom && ! empty($template_path)) { |
|
199 | + return true; |
|
200 | + } |
|
201 | + |
|
202 | + // not in the theme |
|
203 | + if (empty($template_path)) { |
|
204 | + // not even a template to look for ? |
|
205 | + if (empty($templates)) { |
|
206 | + // get post_type |
|
207 | + $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
208 | + // get array of EE Custom Post Types |
|
209 | + $EE_CPTs = EE_Register_CPTs::get_CPTs(); |
|
210 | + // build template name based on request |
|
211 | + if (isset($EE_CPTs[$post_type])) { |
|
212 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
213 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
214 | + $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
215 | + } |
|
216 | + } |
|
217 | + // currently active EE template theme |
|
218 | + $current_theme = EE_Config::get_current_theme(); |
|
219 | + |
|
220 | + // array of paths to folders that may contain templates |
|
221 | + $template_folder_paths = array( |
|
222 | + // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
223 | + EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
224 | + // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
225 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
226 | + ); |
|
227 | + |
|
228 | + //add core plugin folders for checking only if we're not $check_if_custom |
|
229 | + if ( ! $check_if_custom) { |
|
230 | + $core_paths = array( |
|
231 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
232 | + EE_PUBLIC . $current_theme, |
|
233 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
234 | + EE_TEMPLATES . $current_theme, |
|
235 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
236 | + EE_PLUGIN_DIR_PATH, |
|
237 | + ); |
|
238 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
239 | + } |
|
240 | + |
|
241 | + // now filter that array |
|
242 | + $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', |
|
243 | + $template_folder_paths); |
|
244 | + $templates = is_array($templates) ? $templates : array($templates); |
|
245 | + $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
246 | + // array to hold all possible template paths |
|
247 | + $full_template_paths = array(); |
|
248 | + |
|
249 | + // loop through $templates |
|
250 | + foreach ($templates as $template) { |
|
251 | + // normalize directory separators |
|
252 | + $template = EEH_File::standardise_directory_separators($template); |
|
253 | + $file_name = basename($template); |
|
254 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
255 | + // while looping through all template folder paths |
|
256 | + foreach ($template_folder_paths as $template_folder_path) { |
|
257 | + // normalize directory separators |
|
258 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
259 | + // determine if any common base path exists between the two paths |
|
260 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
261 | + array($template_folder_path, $template_path_minus_file_name) |
|
262 | + ); |
|
263 | + if ($common_base_path !== '') { |
|
264 | + // both paths have a common base, so just tack the filename onto our search path |
|
265 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
266 | + } else { |
|
267 | + // no common base path, so let's just concatenate |
|
268 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
269 | + } |
|
270 | + // build up our template locations array by adding our resolved paths |
|
271 | + $full_template_paths[] = $resolved_path; |
|
272 | + } |
|
273 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
274 | + array_unshift($full_template_paths, $template); |
|
275 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
276 | + array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
277 | + } |
|
278 | + // filter final array of full template paths |
|
279 | + $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
|
280 | + $full_template_paths, $file_name); |
|
281 | + // now loop through our final array of template location paths and check each location |
|
282 | + foreach ((array)$full_template_paths as $full_template_path) { |
|
283 | + if (is_readable($full_template_path)) { |
|
284 | + $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
285 | + break; |
|
286 | + } |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + // hook that can be used to display the full template path that will be used |
|
291 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
292 | + |
|
293 | + // if we got it and you want to see it... |
|
294 | + if ($template_path && $load && ! $check_if_custom) { |
|
295 | + if ($return_string) { |
|
296 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
297 | + } else { |
|
298 | + EEH_Template::display_template($template_path, $template_args, false); |
|
299 | + } |
|
300 | + } |
|
301 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * _find_common_base_path |
|
307 | + * given two paths, this determines if there is a common base path between the two |
|
308 | + * |
|
309 | + * @param array $paths |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + protected static function _find_common_base_path($paths) |
|
313 | + { |
|
314 | + $last_offset = 0; |
|
315 | + $common_base_path = ''; |
|
316 | + while (($index = strpos($paths[0], DS, $last_offset)) !== false) { |
|
317 | + $dir_length = $index - $last_offset + 1; |
|
318 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
319 | + foreach ($paths as $path) { |
|
320 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
321 | + return $common_base_path; |
|
322 | + } |
|
323 | + } |
|
324 | + $common_base_path .= $directory; |
|
325 | + $last_offset = $index + 1; |
|
326 | + } |
|
327 | + return substr($common_base_path, 0, -1); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * load and display a template |
|
333 | + * |
|
334 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
335 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
336 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
337 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
338 | + * not found or is not readable |
|
339 | + * @return mixed string |
|
340 | + * @throws \DomainException |
|
341 | + */ |
|
342 | 342 | public static function display_template( |
343 | - $template_path = false, |
|
344 | - $template_args = array(), |
|
345 | - $return_string = false, |
|
346 | - $throw_exceptions = false |
|
347 | - ) { |
|
348 | - |
|
349 | - /** |
|
350 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
351 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
352 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
353 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
354 | - * using this. |
|
355 | - * |
|
356 | - * @since 4.6.0 |
|
357 | - */ |
|
358 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
359 | - $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
360 | - |
|
361 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
362 | - if ( ! $template_path || ! is_readable($template_path)) { |
|
363 | - return ''; |
|
364 | - } |
|
365 | - // if $template_args are not in an array, then make it so |
|
366 | - if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
367 | - $template_args = array($template_args); |
|
368 | - } |
|
369 | - extract( $template_args, EXTR_SKIP ); |
|
370 | - // ignore whether template is accessible ? |
|
371 | - if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
372 | - throw new \DomainException( |
|
373 | - esc_html__( |
|
374 | - 'Invalid, unreadable, or missing file.', |
|
375 | - 'event_espresso' |
|
376 | - ) |
|
377 | - ); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - if ($return_string) { |
|
382 | - // because we want to return a string, we are going to capture the output |
|
383 | - ob_start(); |
|
384 | - include($template_path); |
|
385 | - return ob_get_clean(); |
|
386 | - } else { |
|
387 | - include($template_path); |
|
388 | - } |
|
389 | - return ''; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
395 | - * |
|
396 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
397 | - * @param string $prefix added to the beginning of the generated class |
|
398 | - * @param string $suffix added to the end of the generated class |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
402 | - { |
|
403 | - // in the beginning... |
|
404 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
405 | - // da muddle |
|
406 | - $class = ''; |
|
407 | - // the end |
|
408 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
409 | - // is the passed object an EE object ? |
|
410 | - if ($object instanceof EE_Base_Class) { |
|
411 | - // grab the exact type of object |
|
412 | - $obj_class = get_class($object); |
|
413 | - // depending on the type of object... |
|
414 | - switch ($obj_class) { |
|
415 | - // no specifics just yet... |
|
416 | - default : |
|
417 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
418 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
419 | - |
|
420 | - } |
|
421 | - } |
|
422 | - return $prefix . $class . $suffix; |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * EEH_Template::format_currency |
|
429 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
430 | - * the country currency settings from the supplied country ISO code |
|
431 | - * |
|
432 | - * @param float $amount raw money value |
|
433 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
434 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
435 | - * @param string $CNT_ISO 2 letter ISO code for a country |
|
436 | - * @param string $cur_code_span_class |
|
437 | - * @return string the html output for the formatted money value |
|
438 | - * @throws \EE_Error |
|
439 | - */ |
|
440 | - public static function format_currency( |
|
441 | - $amount = null, |
|
442 | - $return_raw = false, |
|
443 | - $display_code = true, |
|
444 | - $CNT_ISO = '', |
|
445 | - $cur_code_span_class = 'currency-code' |
|
446 | - ) { |
|
447 | - // ensure amount was received |
|
448 | - if ($amount === null) { |
|
449 | - $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
450 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
451 | - return ''; |
|
452 | - } |
|
453 | - //ensure amount is float |
|
454 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
455 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
456 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
457 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
458 | - // still a number or was amount converted to a string like "free" ? |
|
459 | - if (is_float($amount_formatted)) { |
|
460 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
461 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
462 | - // verify results |
|
463 | - if ( ! $mny instanceof EE_Currency_Config) { |
|
464 | - // set default config country currency settings |
|
465 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
466 | - ? EE_Registry::instance()->CFG->currency |
|
467 | - : new EE_Currency_Config(); |
|
468 | - } |
|
469 | - // format float |
|
470 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
471 | - // add formatting ? |
|
472 | - if ( ! $return_raw) { |
|
473 | - // add currency sign |
|
474 | - if ($mny->sign_b4) { |
|
475 | - if ($amount >= 0) { |
|
476 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
477 | - } else { |
|
478 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
479 | - } |
|
480 | - |
|
481 | - } else { |
|
482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
483 | - } |
|
484 | - |
|
485 | - // filter to allow global setting of display_code |
|
486 | - $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
487 | - |
|
488 | - // add currency code ? |
|
489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
490 | - } |
|
491 | - // filter results |
|
492 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
|
493 | - $amount_formatted, $mny, $return_raw); |
|
494 | - } |
|
495 | - // clean up vars |
|
496 | - unset($mny); |
|
497 | - // return formatted currency amount |
|
498 | - return $amount_formatted; |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
504 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
505 | - * related status model or model object (i.e. in documentation etc.) |
|
506 | - * |
|
507 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
508 | - * match, then 'Unknown' will be returned. |
|
509 | - * @param boolean $plural Whether to return plural or not |
|
510 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
511 | - * @return string The localized label for the status id. |
|
512 | - */ |
|
513 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
514 | - { |
|
515 | - /** @type EEM_Status $EEM_Status */ |
|
516 | - $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
517 | - $status = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural, |
|
518 | - $schema); |
|
519 | - return $status[$status_id]; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * This helper just returns a button or link for the given parameters |
|
525 | - * |
|
526 | - * @param string $url the url for the link |
|
527 | - * @param string $label What is the label you want displayed for the button |
|
528 | - * @param string $class what class is used for the button (defaults to 'button-primary') |
|
529 | - * @param string $icon |
|
530 | - * @param string $title |
|
531 | - * @return string the html output for the button |
|
532 | - */ |
|
533 | - public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
534 | - { |
|
535 | - $icon_html = ''; |
|
536 | - if ( ! empty($icon)) { |
|
537 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
538 | - $dashicons = array_filter($dashicons); |
|
539 | - $count = count($dashicons); |
|
540 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
541 | - foreach ($dashicons as $dashicon) { |
|
542 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
543 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
544 | - } |
|
545 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
546 | - } |
|
547 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
548 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
549 | - return $button; |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * This returns a generated link that will load the related help tab on admin pages. |
|
555 | - * |
|
556 | - * @param string $help_tab_id the id for the connected help tab |
|
557 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
558 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
559 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
560 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
561 | - * @return string generated link |
|
562 | - */ |
|
563 | - public static function get_help_tab_link( |
|
564 | - $help_tab_id, |
|
565 | - $page = false, |
|
566 | - $action = false, |
|
567 | - $icon_style = false, |
|
568 | - $help_text = false |
|
569 | - ) { |
|
570 | - |
|
571 | - if ( ! $page) { |
|
572 | - $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
573 | - } |
|
574 | - |
|
575 | - if ( ! $action) { |
|
576 | - $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
577 | - } |
|
578 | - |
|
579 | - $action = empty($action) ? 'default' : $action; |
|
580 | - |
|
581 | - |
|
582 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
583 | - $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
584 | - $help_text = ! $help_text ? '' : $help_text; |
|
585 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
586 | - 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
592 | - * |
|
593 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
594 | - * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
595 | - * @param EE_Help_Tour |
|
596 | - * @return string html |
|
597 | - */ |
|
598 | - public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
599 | - { |
|
600 | - $id = $tour->get_slug(); |
|
601 | - $stops = $tour->get_stops(); |
|
602 | - |
|
603 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
604 | - |
|
605 | - foreach ($stops as $stop) { |
|
606 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
607 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
608 | - |
|
609 | - //if container is set to modal then let's make sure we set the options accordingly |
|
610 | - if (empty($data_id) && empty($data_class)) { |
|
611 | - $stop['options']['modal'] = true; |
|
612 | - $stop['options']['expose'] = true; |
|
613 | - } |
|
614 | - |
|
615 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
616 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
617 | - $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
618 | - |
|
619 | - //options |
|
620 | - if (isset($stop['options']) && is_array($stop['options'])) { |
|
621 | - $options = ' data-options="'; |
|
622 | - foreach ($stop['options'] as $option => $value) { |
|
623 | - $options .= $option . ':' . $value . ';'; |
|
624 | - } |
|
625 | - $options .= '"'; |
|
626 | - } else { |
|
627 | - $options = ''; |
|
628 | - } |
|
629 | - |
|
630 | - //let's put all together |
|
631 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
632 | - } |
|
633 | - |
|
634 | - $content .= '</ol>'; |
|
635 | - return $content; |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * This is a helper method to generate a status legend for a given status array. |
|
641 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
642 | - * status_array. |
|
643 | - * |
|
644 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
645 | - * array( |
|
646 | - * 'status_item' => 'status_name' |
|
647 | - * ) |
|
648 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
649 | - * the legend. |
|
650 | - * @throws EE_Error |
|
651 | - * @return string html structure for status. |
|
652 | - */ |
|
653 | - public static function status_legend($status_array, $active_status = '') |
|
654 | - { |
|
655 | - if ( ! is_array($status_array)) { |
|
656 | - throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
657 | - 'event_espresso')); |
|
658 | - } |
|
659 | - |
|
660 | - $setup_array = array(); |
|
661 | - foreach ($status_array as $item => $status) { |
|
662 | - $setup_array[$item] = array( |
|
663 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
664 | - 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
665 | - 'status' => $status, |
|
666 | - ); |
|
667 | - } |
|
668 | - |
|
669 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
670 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
671 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
672 | - foreach ($setup_array as $item => $details) { |
|
673 | - $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
674 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
675 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
676 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
677 | - $content .= '</dt>' . "\n"; |
|
678 | - } |
|
679 | - $content .= '</dl>' . "\n"; |
|
680 | - $content .= '</div>' . "\n"; |
|
681 | - return $content; |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
687 | - * that's nice for presenting in the wp admin |
|
688 | - * |
|
689 | - * @param mixed $data |
|
690 | - * @return string |
|
691 | - */ |
|
692 | - public static function layout_array_as_table($data) |
|
693 | - { |
|
694 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
695 | - $data = (array)$data; |
|
696 | - } |
|
697 | - ob_start(); |
|
698 | - if (is_array($data)) { |
|
699 | - if (EEH_Array::is_associative_array($data)) { |
|
700 | - ?> |
|
343 | + $template_path = false, |
|
344 | + $template_args = array(), |
|
345 | + $return_string = false, |
|
346 | + $throw_exceptions = false |
|
347 | + ) { |
|
348 | + |
|
349 | + /** |
|
350 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
351 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
352 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
353 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
354 | + * using this. |
|
355 | + * |
|
356 | + * @since 4.6.0 |
|
357 | + */ |
|
358 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
359 | + $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
360 | + |
|
361 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
362 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
363 | + return ''; |
|
364 | + } |
|
365 | + // if $template_args are not in an array, then make it so |
|
366 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
367 | + $template_args = array($template_args); |
|
368 | + } |
|
369 | + extract( $template_args, EXTR_SKIP ); |
|
370 | + // ignore whether template is accessible ? |
|
371 | + if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
372 | + throw new \DomainException( |
|
373 | + esc_html__( |
|
374 | + 'Invalid, unreadable, or missing file.', |
|
375 | + 'event_espresso' |
|
376 | + ) |
|
377 | + ); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + if ($return_string) { |
|
382 | + // because we want to return a string, we are going to capture the output |
|
383 | + ob_start(); |
|
384 | + include($template_path); |
|
385 | + return ob_get_clean(); |
|
386 | + } else { |
|
387 | + include($template_path); |
|
388 | + } |
|
389 | + return ''; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
395 | + * |
|
396 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
397 | + * @param string $prefix added to the beginning of the generated class |
|
398 | + * @param string $suffix added to the end of the generated class |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
402 | + { |
|
403 | + // in the beginning... |
|
404 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
405 | + // da muddle |
|
406 | + $class = ''; |
|
407 | + // the end |
|
408 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
409 | + // is the passed object an EE object ? |
|
410 | + if ($object instanceof EE_Base_Class) { |
|
411 | + // grab the exact type of object |
|
412 | + $obj_class = get_class($object); |
|
413 | + // depending on the type of object... |
|
414 | + switch ($obj_class) { |
|
415 | + // no specifics just yet... |
|
416 | + default : |
|
417 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
418 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
419 | + |
|
420 | + } |
|
421 | + } |
|
422 | + return $prefix . $class . $suffix; |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * EEH_Template::format_currency |
|
429 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
430 | + * the country currency settings from the supplied country ISO code |
|
431 | + * |
|
432 | + * @param float $amount raw money value |
|
433 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
434 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
435 | + * @param string $CNT_ISO 2 letter ISO code for a country |
|
436 | + * @param string $cur_code_span_class |
|
437 | + * @return string the html output for the formatted money value |
|
438 | + * @throws \EE_Error |
|
439 | + */ |
|
440 | + public static function format_currency( |
|
441 | + $amount = null, |
|
442 | + $return_raw = false, |
|
443 | + $display_code = true, |
|
444 | + $CNT_ISO = '', |
|
445 | + $cur_code_span_class = 'currency-code' |
|
446 | + ) { |
|
447 | + // ensure amount was received |
|
448 | + if ($amount === null) { |
|
449 | + $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
450 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
451 | + return ''; |
|
452 | + } |
|
453 | + //ensure amount is float |
|
454 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
455 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
456 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
457 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
458 | + // still a number or was amount converted to a string like "free" ? |
|
459 | + if (is_float($amount_formatted)) { |
|
460 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
461 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
462 | + // verify results |
|
463 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
464 | + // set default config country currency settings |
|
465 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
466 | + ? EE_Registry::instance()->CFG->currency |
|
467 | + : new EE_Currency_Config(); |
|
468 | + } |
|
469 | + // format float |
|
470 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
471 | + // add formatting ? |
|
472 | + if ( ! $return_raw) { |
|
473 | + // add currency sign |
|
474 | + if ($mny->sign_b4) { |
|
475 | + if ($amount >= 0) { |
|
476 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
477 | + } else { |
|
478 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
479 | + } |
|
480 | + |
|
481 | + } else { |
|
482 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
483 | + } |
|
484 | + |
|
485 | + // filter to allow global setting of display_code |
|
486 | + $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
487 | + |
|
488 | + // add currency code ? |
|
489 | + $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
490 | + } |
|
491 | + // filter results |
|
492 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
|
493 | + $amount_formatted, $mny, $return_raw); |
|
494 | + } |
|
495 | + // clean up vars |
|
496 | + unset($mny); |
|
497 | + // return formatted currency amount |
|
498 | + return $amount_formatted; |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
504 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
505 | + * related status model or model object (i.e. in documentation etc.) |
|
506 | + * |
|
507 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
508 | + * match, then 'Unknown' will be returned. |
|
509 | + * @param boolean $plural Whether to return plural or not |
|
510 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
511 | + * @return string The localized label for the status id. |
|
512 | + */ |
|
513 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
514 | + { |
|
515 | + /** @type EEM_Status $EEM_Status */ |
|
516 | + $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
517 | + $status = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural, |
|
518 | + $schema); |
|
519 | + return $status[$status_id]; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * This helper just returns a button or link for the given parameters |
|
525 | + * |
|
526 | + * @param string $url the url for the link |
|
527 | + * @param string $label What is the label you want displayed for the button |
|
528 | + * @param string $class what class is used for the button (defaults to 'button-primary') |
|
529 | + * @param string $icon |
|
530 | + * @param string $title |
|
531 | + * @return string the html output for the button |
|
532 | + */ |
|
533 | + public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
534 | + { |
|
535 | + $icon_html = ''; |
|
536 | + if ( ! empty($icon)) { |
|
537 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
538 | + $dashicons = array_filter($dashicons); |
|
539 | + $count = count($dashicons); |
|
540 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
541 | + foreach ($dashicons as $dashicon) { |
|
542 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
543 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
544 | + } |
|
545 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
546 | + } |
|
547 | + $label = ! empty($icon) ? $icon_html . $label : $label; |
|
548 | + $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
549 | + return $button; |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * This returns a generated link that will load the related help tab on admin pages. |
|
555 | + * |
|
556 | + * @param string $help_tab_id the id for the connected help tab |
|
557 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
558 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
559 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
560 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
561 | + * @return string generated link |
|
562 | + */ |
|
563 | + public static function get_help_tab_link( |
|
564 | + $help_tab_id, |
|
565 | + $page = false, |
|
566 | + $action = false, |
|
567 | + $icon_style = false, |
|
568 | + $help_text = false |
|
569 | + ) { |
|
570 | + |
|
571 | + if ( ! $page) { |
|
572 | + $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
573 | + } |
|
574 | + |
|
575 | + if ( ! $action) { |
|
576 | + $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
577 | + } |
|
578 | + |
|
579 | + $action = empty($action) ? 'default' : $action; |
|
580 | + |
|
581 | + |
|
582 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
583 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
584 | + $help_text = ! $help_text ? '' : $help_text; |
|
585 | + return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
586 | + 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
592 | + * |
|
593 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
594 | + * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
595 | + * @param EE_Help_Tour |
|
596 | + * @return string html |
|
597 | + */ |
|
598 | + public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
599 | + { |
|
600 | + $id = $tour->get_slug(); |
|
601 | + $stops = $tour->get_stops(); |
|
602 | + |
|
603 | + $content = '<ol style="display:none" id="' . $id . '">'; |
|
604 | + |
|
605 | + foreach ($stops as $stop) { |
|
606 | + $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
607 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
608 | + |
|
609 | + //if container is set to modal then let's make sure we set the options accordingly |
|
610 | + if (empty($data_id) && empty($data_class)) { |
|
611 | + $stop['options']['modal'] = true; |
|
612 | + $stop['options']['expose'] = true; |
|
613 | + } |
|
614 | + |
|
615 | + $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
616 | + $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
617 | + $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
618 | + |
|
619 | + //options |
|
620 | + if (isset($stop['options']) && is_array($stop['options'])) { |
|
621 | + $options = ' data-options="'; |
|
622 | + foreach ($stop['options'] as $option => $value) { |
|
623 | + $options .= $option . ':' . $value . ';'; |
|
624 | + } |
|
625 | + $options .= '"'; |
|
626 | + } else { |
|
627 | + $options = ''; |
|
628 | + } |
|
629 | + |
|
630 | + //let's put all together |
|
631 | + $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
632 | + } |
|
633 | + |
|
634 | + $content .= '</ol>'; |
|
635 | + return $content; |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * This is a helper method to generate a status legend for a given status array. |
|
641 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
642 | + * status_array. |
|
643 | + * |
|
644 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
645 | + * array( |
|
646 | + * 'status_item' => 'status_name' |
|
647 | + * ) |
|
648 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
649 | + * the legend. |
|
650 | + * @throws EE_Error |
|
651 | + * @return string html structure for status. |
|
652 | + */ |
|
653 | + public static function status_legend($status_array, $active_status = '') |
|
654 | + { |
|
655 | + if ( ! is_array($status_array)) { |
|
656 | + throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
657 | + 'event_espresso')); |
|
658 | + } |
|
659 | + |
|
660 | + $setup_array = array(); |
|
661 | + foreach ($status_array as $item => $status) { |
|
662 | + $setup_array[$item] = array( |
|
663 | + 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
664 | + 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
665 | + 'status' => $status, |
|
666 | + ); |
|
667 | + } |
|
668 | + |
|
669 | + $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
670 | + $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
671 | + $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
672 | + foreach ($setup_array as $item => $details) { |
|
673 | + $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
674 | + $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
675 | + $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
676 | + $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
677 | + $content .= '</dt>' . "\n"; |
|
678 | + } |
|
679 | + $content .= '</dl>' . "\n"; |
|
680 | + $content .= '</div>' . "\n"; |
|
681 | + return $content; |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
687 | + * that's nice for presenting in the wp admin |
|
688 | + * |
|
689 | + * @param mixed $data |
|
690 | + * @return string |
|
691 | + */ |
|
692 | + public static function layout_array_as_table($data) |
|
693 | + { |
|
694 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
695 | + $data = (array)$data; |
|
696 | + } |
|
697 | + ob_start(); |
|
698 | + if (is_array($data)) { |
|
699 | + if (EEH_Array::is_associative_array($data)) { |
|
700 | + ?> |
|
701 | 701 | <table class="widefat"> |
702 | 702 | <tbody> |
703 | 703 | <?php |
704 | - foreach ($data as $data_key => $data_values) { |
|
705 | - ?> |
|
704 | + foreach ($data as $data_key => $data_values) { |
|
705 | + ?> |
|
706 | 706 | <tr> |
707 | 707 | <td> |
708 | 708 | <?php echo $data_key; ?> |
@@ -712,248 +712,248 @@ discard block |
||
712 | 712 | </td> |
713 | 713 | </tr> |
714 | 714 | <?php |
715 | - } ?> |
|
715 | + } ?> |
|
716 | 716 | </tbody> |
717 | 717 | </table> |
718 | 718 | <?php |
719 | - } else { |
|
720 | - ?> |
|
719 | + } else { |
|
720 | + ?> |
|
721 | 721 | <ul> |
722 | 722 | <?php |
723 | - foreach ($data as $datum) { |
|
724 | - echo "<li>"; |
|
725 | - echo self::layout_array_as_table($datum); |
|
726 | - echo "</li>"; |
|
727 | - } ?> |
|
723 | + foreach ($data as $datum) { |
|
724 | + echo "<li>"; |
|
725 | + echo self::layout_array_as_table($datum); |
|
726 | + echo "</li>"; |
|
727 | + } ?> |
|
728 | 728 | </ul> |
729 | 729 | <?php |
730 | - } |
|
731 | - } else { |
|
732 | - //simple value |
|
733 | - echo esc_html($data); |
|
734 | - } |
|
735 | - return ob_get_clean(); |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
741 | - * |
|
742 | - * @since 4.4.0 |
|
743 | - * @see self:get_paging_html() for argument docs. |
|
744 | - * @param $total_items |
|
745 | - * @param $current |
|
746 | - * @param $per_page |
|
747 | - * @param $url |
|
748 | - * @param bool $show_num_field |
|
749 | - * @param string $paged_arg_name |
|
750 | - * @param array $items_label |
|
751 | - * @return string |
|
752 | - */ |
|
753 | - public static function paging_html( |
|
754 | - $total_items, |
|
755 | - $current, |
|
756 | - $per_page, |
|
757 | - $url, |
|
758 | - $show_num_field = true, |
|
759 | - $paged_arg_name = 'paged', |
|
760 | - $items_label = array() |
|
761 | - ) { |
|
762 | - echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, |
|
763 | - $items_label); |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - /** |
|
768 | - * A method for generating paging similar to WP_List_Table |
|
769 | - * |
|
770 | - * @since 4.4.0 |
|
771 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
772 | - * @param integer $total_items How many total items there are to page. |
|
773 | - * @param integer $current What the current page is. |
|
774 | - * @param integer $per_page How many items per page. |
|
775 | - * @param string $url What the base url for page links is. |
|
776 | - * @param boolean $show_num_field Whether to show the input for changing page number. |
|
777 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
778 | - * @param array $items_label An array of singular/plural values for the items label: |
|
779 | - * array( |
|
780 | - * 'single' => 'item', |
|
781 | - * 'plural' => 'items' |
|
782 | - * ) |
|
783 | - * @return string |
|
784 | - */ |
|
785 | - public static function get_paging_html( |
|
786 | - $total_items, |
|
787 | - $current, |
|
788 | - $per_page, |
|
789 | - $url, |
|
790 | - $show_num_field = true, |
|
791 | - $paged_arg_name = 'paged', |
|
792 | - $items_label = array() |
|
793 | - ) { |
|
794 | - $page_links = array(); |
|
795 | - $disable_first = $disable_last = ''; |
|
796 | - $total_items = (int)$total_items; |
|
797 | - $per_page = (int)$per_page; |
|
798 | - $current = (int)$current; |
|
799 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
800 | - |
|
801 | - //filter items_label |
|
802 | - $items_label = apply_filters( |
|
803 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
804 | - $items_label |
|
805 | - ); |
|
806 | - |
|
807 | - if (empty($items_label) |
|
808 | - || ! is_array($items_label) |
|
809 | - || ! isset($items_label['single']) |
|
810 | - || ! isset($items_label['plural']) |
|
811 | - ) { |
|
812 | - $items_label = array( |
|
813 | - 'single' => __('1 item', 'event_espresso'), |
|
814 | - 'plural' => __('%s items', 'event_espresso'), |
|
815 | - ); |
|
816 | - } else { |
|
817 | - $items_label = array( |
|
818 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
819 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
820 | - ); |
|
821 | - } |
|
822 | - |
|
823 | - $total_pages = ceil($total_items / $per_page); |
|
824 | - |
|
825 | - if ($total_pages <= 1) { |
|
826 | - return ''; |
|
827 | - } |
|
828 | - |
|
829 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
830 | - |
|
831 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
832 | - |
|
833 | - if ($current === 1) { |
|
834 | - $disable_first = ' disabled'; |
|
835 | - } |
|
836 | - if ($current == $total_pages) { |
|
837 | - $disable_last = ' disabled'; |
|
838 | - } |
|
839 | - |
|
840 | - $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
|
841 | - 'first-page' . $disable_first, |
|
842 | - esc_attr__('Go to the first page'), |
|
843 | - esc_url(remove_query_arg($paged_arg_name, $url)), |
|
844 | - '«' |
|
845 | - ); |
|
846 | - |
|
847 | - $page_links[] = sprintf( |
|
848 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
849 | - 'prev-page' . $disable_first, |
|
850 | - esc_attr__('Go to the previous page'), |
|
851 | - esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
852 | - '‹' |
|
853 | - ); |
|
854 | - |
|
855 | - if ( ! $show_num_field) { |
|
856 | - $html_current_page = $current; |
|
857 | - } else { |
|
858 | - $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
859 | - esc_attr__('Current page'), |
|
860 | - $current, |
|
861 | - strlen($total_pages) |
|
862 | - ); |
|
863 | - } |
|
864 | - |
|
865 | - $html_total_pages = sprintf( |
|
866 | - '<span class="total-pages">%s</span>', |
|
867 | - number_format_i18n($total_pages) |
|
868 | - ); |
|
869 | - $page_links[] = sprintf( |
|
870 | - _x('%3$s%1$s of %2$s%4$s', 'paging'), |
|
871 | - $html_current_page, |
|
872 | - $html_total_pages, |
|
873 | - '<span class="paging-input">', |
|
874 | - '</span>' |
|
875 | - ); |
|
876 | - |
|
877 | - $page_links[] = sprintf( |
|
878 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
879 | - 'next-page' . $disable_last, |
|
880 | - esc_attr__('Go to the next page'), |
|
881 | - esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
882 | - '›' |
|
883 | - ); |
|
884 | - |
|
885 | - $page_links[] = sprintf( |
|
886 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
887 | - 'last-page' . $disable_last, |
|
888 | - esc_attr__('Go to the last page'), |
|
889 | - esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
890 | - '»' |
|
891 | - ); |
|
892 | - |
|
893 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
894 | - // set page class |
|
895 | - if ($total_pages) { |
|
896 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
897 | - } else { |
|
898 | - $page_class = ' no-pages'; |
|
899 | - } |
|
900 | - |
|
901 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * @param string $wrap_class |
|
907 | - * @param string $wrap_id |
|
908 | - * @return string |
|
909 | - */ |
|
910 | - public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
911 | - { |
|
912 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
913 | - if ( |
|
914 | - ! $admin && |
|
915 | - ! apply_filters( |
|
916 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
917 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
918 | - ) |
|
919 | - ) { |
|
920 | - return ''; |
|
921 | - } |
|
922 | - $tag = $admin ? 'span' : 'div'; |
|
923 | - $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
924 | - $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
925 | - $attributes .= ! empty($wrap_class) |
|
926 | - ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
927 | - : ' class="powered-by-event-espresso-credit"'; |
|
928 | - $query_args = array_merge( |
|
929 | - array( |
|
930 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
931 | - 'utm_source' => 'powered_by_event_espresso', |
|
932 | - 'utm_medium' => 'link', |
|
933 | - 'utm_campaign' => 'powered_by', |
|
934 | - ), |
|
935 | - $query_args |
|
936 | - ); |
|
937 | - $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
|
938 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
939 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
940 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
941 | - return (string)apply_filters( |
|
942 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
943 | - sprintf( |
|
944 | - esc_html_x( |
|
945 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
946 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
947 | - 'event_espresso' |
|
948 | - ), |
|
949 | - "<{$tag}{$attributes}>", |
|
950 | - "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
951 | - $admin ? '' : '<br />' |
|
952 | - ), |
|
953 | - $wrap_class, |
|
954 | - $wrap_id |
|
955 | - ); |
|
956 | - } |
|
730 | + } |
|
731 | + } else { |
|
732 | + //simple value |
|
733 | + echo esc_html($data); |
|
734 | + } |
|
735 | + return ob_get_clean(); |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
741 | + * |
|
742 | + * @since 4.4.0 |
|
743 | + * @see self:get_paging_html() for argument docs. |
|
744 | + * @param $total_items |
|
745 | + * @param $current |
|
746 | + * @param $per_page |
|
747 | + * @param $url |
|
748 | + * @param bool $show_num_field |
|
749 | + * @param string $paged_arg_name |
|
750 | + * @param array $items_label |
|
751 | + * @return string |
|
752 | + */ |
|
753 | + public static function paging_html( |
|
754 | + $total_items, |
|
755 | + $current, |
|
756 | + $per_page, |
|
757 | + $url, |
|
758 | + $show_num_field = true, |
|
759 | + $paged_arg_name = 'paged', |
|
760 | + $items_label = array() |
|
761 | + ) { |
|
762 | + echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, |
|
763 | + $items_label); |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + /** |
|
768 | + * A method for generating paging similar to WP_List_Table |
|
769 | + * |
|
770 | + * @since 4.4.0 |
|
771 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
772 | + * @param integer $total_items How many total items there are to page. |
|
773 | + * @param integer $current What the current page is. |
|
774 | + * @param integer $per_page How many items per page. |
|
775 | + * @param string $url What the base url for page links is. |
|
776 | + * @param boolean $show_num_field Whether to show the input for changing page number. |
|
777 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
778 | + * @param array $items_label An array of singular/plural values for the items label: |
|
779 | + * array( |
|
780 | + * 'single' => 'item', |
|
781 | + * 'plural' => 'items' |
|
782 | + * ) |
|
783 | + * @return string |
|
784 | + */ |
|
785 | + public static function get_paging_html( |
|
786 | + $total_items, |
|
787 | + $current, |
|
788 | + $per_page, |
|
789 | + $url, |
|
790 | + $show_num_field = true, |
|
791 | + $paged_arg_name = 'paged', |
|
792 | + $items_label = array() |
|
793 | + ) { |
|
794 | + $page_links = array(); |
|
795 | + $disable_first = $disable_last = ''; |
|
796 | + $total_items = (int)$total_items; |
|
797 | + $per_page = (int)$per_page; |
|
798 | + $current = (int)$current; |
|
799 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
800 | + |
|
801 | + //filter items_label |
|
802 | + $items_label = apply_filters( |
|
803 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
804 | + $items_label |
|
805 | + ); |
|
806 | + |
|
807 | + if (empty($items_label) |
|
808 | + || ! is_array($items_label) |
|
809 | + || ! isset($items_label['single']) |
|
810 | + || ! isset($items_label['plural']) |
|
811 | + ) { |
|
812 | + $items_label = array( |
|
813 | + 'single' => __('1 item', 'event_espresso'), |
|
814 | + 'plural' => __('%s items', 'event_espresso'), |
|
815 | + ); |
|
816 | + } else { |
|
817 | + $items_label = array( |
|
818 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
819 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
820 | + ); |
|
821 | + } |
|
822 | + |
|
823 | + $total_pages = ceil($total_items / $per_page); |
|
824 | + |
|
825 | + if ($total_pages <= 1) { |
|
826 | + return ''; |
|
827 | + } |
|
828 | + |
|
829 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
830 | + |
|
831 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
832 | + |
|
833 | + if ($current === 1) { |
|
834 | + $disable_first = ' disabled'; |
|
835 | + } |
|
836 | + if ($current == $total_pages) { |
|
837 | + $disable_last = ' disabled'; |
|
838 | + } |
|
839 | + |
|
840 | + $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
|
841 | + 'first-page' . $disable_first, |
|
842 | + esc_attr__('Go to the first page'), |
|
843 | + esc_url(remove_query_arg($paged_arg_name, $url)), |
|
844 | + '«' |
|
845 | + ); |
|
846 | + |
|
847 | + $page_links[] = sprintf( |
|
848 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
849 | + 'prev-page' . $disable_first, |
|
850 | + esc_attr__('Go to the previous page'), |
|
851 | + esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
852 | + '‹' |
|
853 | + ); |
|
854 | + |
|
855 | + if ( ! $show_num_field) { |
|
856 | + $html_current_page = $current; |
|
857 | + } else { |
|
858 | + $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
859 | + esc_attr__('Current page'), |
|
860 | + $current, |
|
861 | + strlen($total_pages) |
|
862 | + ); |
|
863 | + } |
|
864 | + |
|
865 | + $html_total_pages = sprintf( |
|
866 | + '<span class="total-pages">%s</span>', |
|
867 | + number_format_i18n($total_pages) |
|
868 | + ); |
|
869 | + $page_links[] = sprintf( |
|
870 | + _x('%3$s%1$s of %2$s%4$s', 'paging'), |
|
871 | + $html_current_page, |
|
872 | + $html_total_pages, |
|
873 | + '<span class="paging-input">', |
|
874 | + '</span>' |
|
875 | + ); |
|
876 | + |
|
877 | + $page_links[] = sprintf( |
|
878 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
879 | + 'next-page' . $disable_last, |
|
880 | + esc_attr__('Go to the next page'), |
|
881 | + esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
882 | + '›' |
|
883 | + ); |
|
884 | + |
|
885 | + $page_links[] = sprintf( |
|
886 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
887 | + 'last-page' . $disable_last, |
|
888 | + esc_attr__('Go to the last page'), |
|
889 | + esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
890 | + '»' |
|
891 | + ); |
|
892 | + |
|
893 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
894 | + // set page class |
|
895 | + if ($total_pages) { |
|
896 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
897 | + } else { |
|
898 | + $page_class = ' no-pages'; |
|
899 | + } |
|
900 | + |
|
901 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * @param string $wrap_class |
|
907 | + * @param string $wrap_id |
|
908 | + * @return string |
|
909 | + */ |
|
910 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
911 | + { |
|
912 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
913 | + if ( |
|
914 | + ! $admin && |
|
915 | + ! apply_filters( |
|
916 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
917 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
918 | + ) |
|
919 | + ) { |
|
920 | + return ''; |
|
921 | + } |
|
922 | + $tag = $admin ? 'span' : 'div'; |
|
923 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
924 | + $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
925 | + $attributes .= ! empty($wrap_class) |
|
926 | + ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
927 | + : ' class="powered-by-event-espresso-credit"'; |
|
928 | + $query_args = array_merge( |
|
929 | + array( |
|
930 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
931 | + 'utm_source' => 'powered_by_event_espresso', |
|
932 | + 'utm_medium' => 'link', |
|
933 | + 'utm_campaign' => 'powered_by', |
|
934 | + ), |
|
935 | + $query_args |
|
936 | + ); |
|
937 | + $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
|
938 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
939 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
940 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
941 | + return (string)apply_filters( |
|
942 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
943 | + sprintf( |
|
944 | + esc_html_x( |
|
945 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
946 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
947 | + 'event_espresso' |
|
948 | + ), |
|
949 | + "<{$tag}{$attributes}>", |
|
950 | + "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
951 | + $admin ? '' : '<br />' |
|
952 | + ), |
|
953 | + $wrap_class, |
|
954 | + $wrap_id |
|
955 | + ); |
|
956 | + } |
|
957 | 957 | |
958 | 958 | |
959 | 959 | } //end EEH_Template class |
@@ -962,33 +962,33 @@ discard block |
||
962 | 962 | |
963 | 963 | |
964 | 964 | if ( ! function_exists('espresso_pagination')) { |
965 | - /** |
|
966 | - * espresso_pagination |
|
967 | - * |
|
968 | - * @access public |
|
969 | - * @return void |
|
970 | - */ |
|
971 | - function espresso_pagination() |
|
972 | - { |
|
973 | - global $wp_query; |
|
974 | - $big = 999999999; // need an unlikely integer |
|
975 | - $pagination = paginate_links( |
|
976 | - array( |
|
977 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
978 | - 'format' => '?paged=%#%', |
|
979 | - 'current' => max(1, get_query_var('paged')), |
|
980 | - 'total' => $wp_query->max_num_pages, |
|
981 | - 'show_all' => true, |
|
982 | - 'end_size' => 10, |
|
983 | - 'mid_size' => 6, |
|
984 | - 'prev_next' => true, |
|
985 | - 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
986 | - 'next_text' => __('NEXT ›', 'event_espresso'), |
|
987 | - 'type' => 'plain', |
|
988 | - 'add_args' => false, |
|
989 | - 'add_fragment' => '', |
|
990 | - ) |
|
991 | - ); |
|
992 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
993 | - } |
|
965 | + /** |
|
966 | + * espresso_pagination |
|
967 | + * |
|
968 | + * @access public |
|
969 | + * @return void |
|
970 | + */ |
|
971 | + function espresso_pagination() |
|
972 | + { |
|
973 | + global $wp_query; |
|
974 | + $big = 999999999; // need an unlikely integer |
|
975 | + $pagination = paginate_links( |
|
976 | + array( |
|
977 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
978 | + 'format' => '?paged=%#%', |
|
979 | + 'current' => max(1, get_query_var('paged')), |
|
980 | + 'total' => $wp_query->max_num_pages, |
|
981 | + 'show_all' => true, |
|
982 | + 'end_size' => 10, |
|
983 | + 'mid_size' => 6, |
|
984 | + 'prev_next' => true, |
|
985 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
986 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
987 | + 'type' => 'plain', |
|
988 | + 'add_args' => false, |
|
989 | + 'add_fragment' => '', |
|
990 | + ) |
|
991 | + ); |
|
992 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
993 | + } |
|
994 | 994 | } |
995 | 995 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | /** |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | public static function load_espresso_theme_functions() |
82 | 82 | { |
83 | 83 | if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
84 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
85 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
84 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) { |
|
85 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php'); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public static function get_espresso_themes() |
97 | 97 | { |
98 | 98 | if (empty(EEH_Template::$_espresso_themes)) { |
99 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
99 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
100 | 100 | if (empty($espresso_themes)) { |
101 | 101 | return array(); |
102 | 102 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | ) { |
133 | 133 | do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
134 | 134 | $templates = array(); |
135 | - $name = (string)$name; |
|
135 | + $name = (string) $name; |
|
136 | 136 | if ($name != '') { |
137 | 137 | $templates[] = "{$slug}-{$name}.php"; |
138 | 138 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | if (isset($EE_CPTs[$post_type])) { |
212 | 212 | $archive_or_single = is_archive() ? 'archive' : ''; |
213 | 213 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
214 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
214 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | // currently active EE template theme |
@@ -220,18 +220,18 @@ discard block |
||
220 | 220 | // array of paths to folders that may contain templates |
221 | 221 | $template_folder_paths = array( |
222 | 222 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
223 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
223 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
224 | 224 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
225 | 225 | EVENT_ESPRESSO_TEMPLATE_DIR, |
226 | 226 | ); |
227 | 227 | |
228 | 228 | //add core plugin folders for checking only if we're not $check_if_custom |
229 | 229 | if ( ! $check_if_custom) { |
230 | - $core_paths = array( |
|
230 | + $core_paths = array( |
|
231 | 231 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
232 | - EE_PUBLIC . $current_theme, |
|
232 | + EE_PUBLIC.$current_theme, |
|
233 | 233 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
234 | - EE_TEMPLATES . $current_theme, |
|
234 | + EE_TEMPLATES.$current_theme, |
|
235 | 235 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
236 | 236 | EE_PLUGIN_DIR_PATH, |
237 | 237 | ); |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | ); |
263 | 263 | if ($common_base_path !== '') { |
264 | 264 | // both paths have a common base, so just tack the filename onto our search path |
265 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
265 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
266 | 266 | } else { |
267 | 267 | // no common base path, so let's just concatenate |
268 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
268 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
269 | 269 | } |
270 | 270 | // build up our template locations array by adding our resolved paths |
271 | 271 | $full_template_paths[] = $resolved_path; |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
274 | 274 | array_unshift($full_template_paths, $template); |
275 | 275 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
276 | - array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
276 | + array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name); |
|
277 | 277 | } |
278 | 278 | // filter final array of full template paths |
279 | 279 | $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
280 | 280 | $full_template_paths, $file_name); |
281 | 281 | // now loop through our final array of template location paths and check each location |
282 | - foreach ((array)$full_template_paths as $full_template_path) { |
|
282 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
283 | 283 | if (is_readable($full_template_path)) { |
284 | 284 | $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
285 | 285 | break; |
@@ -366,9 +366,9 @@ discard block |
||
366 | 366 | if ( ! is_array($template_args) && ! is_object($template_args)) { |
367 | 367 | $template_args = array($template_args); |
368 | 368 | } |
369 | - extract( $template_args, EXTR_SKIP ); |
|
369 | + extract($template_args, EXTR_SKIP); |
|
370 | 370 | // ignore whether template is accessible ? |
371 | - if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
371 | + if ($throw_exceptions && ! is_readable($template_path)) { |
|
372 | 372 | throw new \DomainException( |
373 | 373 | esc_html__( |
374 | 374 | 'Invalid, unreadable, or missing file.', |
@@ -401,11 +401,11 @@ discard block |
||
401 | 401 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
402 | 402 | { |
403 | 403 | // in the beginning... |
404 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
404 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
405 | 405 | // da muddle |
406 | 406 | $class = ''; |
407 | 407 | // the end |
408 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
408 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
409 | 409 | // is the passed object an EE object ? |
410 | 410 | if ($object instanceof EE_Base_Class) { |
411 | 411 | // grab the exact type of object |
@@ -415,11 +415,11 @@ discard block |
||
415 | 415 | // no specifics just yet... |
416 | 416 | default : |
417 | 417 | $class = strtolower(str_replace('_', '-', $obj_class)); |
418 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
418 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
419 | 419 | |
420 | 420 | } |
421 | 421 | } |
422 | - return $prefix . $class . $suffix; |
|
422 | + return $prefix.$class.$suffix; |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | return ''; |
452 | 452 | } |
453 | 453 | //ensure amount is float |
454 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
454 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
455 | 455 | $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
456 | 456 | // filter raw amount (allows 0.00 to be changed to "free" for example) |
457 | 457 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
@@ -473,20 +473,20 @@ discard block |
||
473 | 473 | // add currency sign |
474 | 474 | if ($mny->sign_b4) { |
475 | 475 | if ($amount >= 0) { |
476 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
476 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
477 | 477 | } else { |
478 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
478 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | } else { |
482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
482 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | // filter to allow global setting of display_code |
486 | 486 | $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
487 | 487 | |
488 | 488 | // add currency code ? |
489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
489 | + $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted; |
|
490 | 490 | } |
491 | 491 | // filter results |
492 | 492 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
@@ -540,12 +540,12 @@ discard block |
||
540 | 540 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
541 | 541 | foreach ($dashicons as $dashicon) { |
542 | 542 | $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
543 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
543 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
544 | 544 | } |
545 | 545 | $icon_html .= $count > 1 ? '</span>' : ''; |
546 | 546 | } |
547 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
548 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
547 | + $label = ! empty($icon) ? $icon_html.$label : $label; |
|
548 | + $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.$url.'" class="'.$class.'" title="'.$title.'">'.$label.'</a>'; |
|
549 | 549 | return $button; |
550 | 550 | } |
551 | 551 | |
@@ -579,11 +579,11 @@ discard block |
||
579 | 579 | $action = empty($action) ? 'default' : $action; |
580 | 580 | |
581 | 581 | |
582 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
582 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
583 | 583 | $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
584 | 584 | $help_text = ! $help_text ? '' : $help_text; |
585 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
586 | - 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
585 | + return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
586 | + 'event_espresso').'" > '.$help_text.' </a>'; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | |
@@ -600,11 +600,11 @@ discard block |
||
600 | 600 | $id = $tour->get_slug(); |
601 | 601 | $stops = $tour->get_stops(); |
602 | 602 | |
603 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
603 | + $content = '<ol style="display:none" id="'.$id.'">'; |
|
604 | 604 | |
605 | 605 | foreach ($stops as $stop) { |
606 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
607 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
606 | + $data_id = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : ''; |
|
607 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : ''; |
|
608 | 608 | |
609 | 609 | //if container is set to modal then let's make sure we set the options accordingly |
610 | 610 | if (empty($data_id) && empty($data_class)) { |
@@ -612,15 +612,15 @@ discard block |
||
612 | 612 | $stop['options']['expose'] = true; |
613 | 613 | } |
614 | 614 | |
615 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
616 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
615 | + $custom_class = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : ''; |
|
616 | + $button_text = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : ''; |
|
617 | 617 | $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
618 | 618 | |
619 | 619 | //options |
620 | 620 | if (isset($stop['options']) && is_array($stop['options'])) { |
621 | 621 | $options = ' data-options="'; |
622 | 622 | foreach ($stop['options'] as $option => $value) { |
623 | - $options .= $option . ':' . $value . ';'; |
|
623 | + $options .= $option.':'.$value.';'; |
|
624 | 624 | } |
625 | 625 | $options .= '"'; |
626 | 626 | } else { |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | } |
629 | 629 | |
630 | 630 | //let's put all together |
631 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
631 | + $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>'; |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | $content .= '</ol>'; |
@@ -660,24 +660,24 @@ discard block |
||
660 | 660 | $setup_array = array(); |
661 | 661 | foreach ($status_array as $item => $status) { |
662 | 662 | $setup_array[$item] = array( |
663 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
663 | + 'class' => 'ee-status-legend ee-status-legend-'.$status, |
|
664 | 664 | 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
665 | 665 | 'status' => $status, |
666 | 666 | ); |
667 | 667 | } |
668 | 668 | |
669 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
670 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
671 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
669 | + $content = '<div class="ee-list-table-legend-container">'."\n"; |
|
670 | + $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n"; |
|
671 | + $content .= '<dl class="ee-list-table-legend">'."\n\t"; |
|
672 | 672 | foreach ($setup_array as $item => $details) { |
673 | 673 | $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
674 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
675 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
676 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
677 | - $content .= '</dt>' . "\n"; |
|
674 | + $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t"; |
|
675 | + $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t"; |
|
676 | + $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t"; |
|
677 | + $content .= '</dt>'."\n"; |
|
678 | 678 | } |
679 | - $content .= '</dl>' . "\n"; |
|
680 | - $content .= '</div>' . "\n"; |
|
679 | + $content .= '</dl>'."\n"; |
|
680 | + $content .= '</div>'."\n"; |
|
681 | 681 | return $content; |
682 | 682 | } |
683 | 683 | |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | public static function layout_array_as_table($data) |
693 | 693 | { |
694 | 694 | if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
695 | - $data = (array)$data; |
|
695 | + $data = (array) $data; |
|
696 | 696 | } |
697 | 697 | ob_start(); |
698 | 698 | if (is_array($data)) { |
@@ -793,9 +793,9 @@ discard block |
||
793 | 793 | ) { |
794 | 794 | $page_links = array(); |
795 | 795 | $disable_first = $disable_last = ''; |
796 | - $total_items = (int)$total_items; |
|
797 | - $per_page = (int)$per_page; |
|
798 | - $current = (int)$current; |
|
796 | + $total_items = (int) $total_items; |
|
797 | + $per_page = (int) $per_page; |
|
798 | + $current = (int) $current; |
|
799 | 799 | $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
800 | 800 | |
801 | 801 | //filter items_label |
@@ -815,8 +815,8 @@ discard block |
||
815 | 815 | ); |
816 | 816 | } else { |
817 | 817 | $items_label = array( |
818 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
819 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
818 | + 'single' => '1 '.esc_html($items_label['single']), |
|
819 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
820 | 820 | ); |
821 | 821 | } |
822 | 822 | |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | |
829 | 829 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
830 | 830 | |
831 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
831 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
832 | 832 | |
833 | 833 | if ($current === 1) { |
834 | 834 | $disable_first = ' disabled'; |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | } |
839 | 839 | |
840 | 840 | $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
841 | - 'first-page' . $disable_first, |
|
841 | + 'first-page'.$disable_first, |
|
842 | 842 | esc_attr__('Go to the first page'), |
843 | 843 | esc_url(remove_query_arg($paged_arg_name, $url)), |
844 | 844 | '«' |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | |
847 | 847 | $page_links[] = sprintf( |
848 | 848 | '<a class="%s" title="%s" href="%s">%s</a>', |
849 | - 'prev-page' . $disable_first, |
|
849 | + 'prev-page'.$disable_first, |
|
850 | 850 | esc_attr__('Go to the previous page'), |
851 | 851 | esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
852 | 852 | '‹' |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | '<span class="total-pages">%s</span>', |
867 | 867 | number_format_i18n($total_pages) |
868 | 868 | ); |
869 | - $page_links[] = sprintf( |
|
869 | + $page_links[] = sprintf( |
|
870 | 870 | _x('%3$s%1$s of %2$s%4$s', 'paging'), |
871 | 871 | $html_current_page, |
872 | 872 | $html_total_pages, |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | |
877 | 877 | $page_links[] = sprintf( |
878 | 878 | '<a class="%s" title="%s" href="%s">%s</a>', |
879 | - 'next-page' . $disable_last, |
|
879 | + 'next-page'.$disable_last, |
|
880 | 880 | esc_attr__('Go to the next page'), |
881 | 881 | esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
882 | 882 | '›' |
@@ -884,13 +884,13 @@ discard block |
||
884 | 884 | |
885 | 885 | $page_links[] = sprintf( |
886 | 886 | '<a class="%s" title="%s" href="%s">%s</a>', |
887 | - 'last-page' . $disable_last, |
|
887 | + 'last-page'.$disable_last, |
|
888 | 888 | esc_attr__('Go to the last page'), |
889 | 889 | esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
890 | 890 | '»' |
891 | 891 | ); |
892 | 892 | |
893 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
893 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
894 | 894 | // set page class |
895 | 895 | if ($total_pages) { |
896 | 896 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | $page_class = ' no-pages'; |
899 | 899 | } |
900 | 900 | |
901 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
901 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | |
@@ -935,10 +935,10 @@ discard block |
||
935 | 935 | $query_args |
936 | 936 | ); |
937 | 937 | $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
938 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
938 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
939 | 939 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
940 | 940 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
941 | - return (string)apply_filters( |
|
941 | + return (string) apply_filters( |
|
942 | 942 | 'FHEE__EEH_Template__powered_by_event_espresso__html', |
943 | 943 | sprintf( |
944 | 944 | esc_html_x( |
@@ -989,6 +989,6 @@ discard block |
||
989 | 989 | 'add_fragment' => '', |
990 | 990 | ) |
991 | 991 | ); |
992 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
992 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
993 | 993 | } |
994 | 994 | } |
995 | 995 | \ No newline at end of file |
@@ -27,83 +27,83 @@ |
||
27 | 27 | class AttendeeContactDetailsMetaboxFormHandler extends FormHandler{ |
28 | 28 | |
29 | 29 | |
30 | - protected $attendee; |
|
30 | + protected $attendee; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * AttendeeContactDetailsMetaboxFormHandler constructor. |
|
35 | - * |
|
36 | - * @param EE_Attendee $attendee |
|
37 | - * @param EE_Registry $registry |
|
38 | - * @throws DomainException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidArgumentException |
|
41 | - */ |
|
42 | - public function __construct(EE_Attendee $attendee, EE_Registry $registry) |
|
43 | - { |
|
44 | - $this->attendee = $attendee; |
|
45 | - $label = esc_html__('Contact Details', 'event_espresso'); |
|
46 | - parent::__construct( |
|
47 | - $label, |
|
48 | - $label, |
|
49 | - 'attendee_contact_details', |
|
50 | - '', |
|
51 | - FormHandler::DO_NOT_SETUP_FORM, |
|
52 | - $registry |
|
53 | - ); |
|
54 | - } |
|
33 | + /** |
|
34 | + * AttendeeContactDetailsMetaboxFormHandler constructor. |
|
35 | + * |
|
36 | + * @param EE_Attendee $attendee |
|
37 | + * @param EE_Registry $registry |
|
38 | + * @throws DomainException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidArgumentException |
|
41 | + */ |
|
42 | + public function __construct(EE_Attendee $attendee, EE_Registry $registry) |
|
43 | + { |
|
44 | + $this->attendee = $attendee; |
|
45 | + $label = esc_html__('Contact Details', 'event_espresso'); |
|
46 | + parent::__construct( |
|
47 | + $label, |
|
48 | + $label, |
|
49 | + 'attendee_contact_details', |
|
50 | + '', |
|
51 | + FormHandler::DO_NOT_SETUP_FORM, |
|
52 | + $registry |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * creates and returns the actual form |
|
58 | - * |
|
59 | - * @return EE_Form_Section_Proper |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public function generate() |
|
63 | - { |
|
64 | - return new EE_Form_Section_Proper( |
|
65 | - array( |
|
66 | - 'name' => 'attendee_contact_details', |
|
67 | - 'html_id' => 'attendee-contact-details', |
|
68 | - 'html_class' => 'form-table', |
|
69 | - 'layout_strategy' => new EE_Admin_One_Column_Layout(), |
|
70 | - 'subsections' => array( |
|
71 | - 'ATT_email' => new EE_Email_Input( |
|
72 | - array( |
|
73 | - 'default' => $this->attendee->email(), |
|
74 | - 'html_label_text' => esc_html__('Email Address', 'event_espresso'), |
|
75 | - 'required' => true |
|
76 | - ) |
|
77 | - ), |
|
78 | - 'ATT_phone' => new EE_Text_Input( |
|
79 | - array( |
|
80 | - 'default' => $this->attendee->phone(), |
|
81 | - 'html_label_text' => esc_html__('Phone Number', 'event_espresso') |
|
82 | - ) |
|
83 | - ) |
|
84 | - ) |
|
85 | - ) |
|
86 | - ); |
|
87 | - } |
|
56 | + /** |
|
57 | + * creates and returns the actual form |
|
58 | + * |
|
59 | + * @return EE_Form_Section_Proper |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public function generate() |
|
63 | + { |
|
64 | + return new EE_Form_Section_Proper( |
|
65 | + array( |
|
66 | + 'name' => 'attendee_contact_details', |
|
67 | + 'html_id' => 'attendee-contact-details', |
|
68 | + 'html_class' => 'form-table', |
|
69 | + 'layout_strategy' => new EE_Admin_One_Column_Layout(), |
|
70 | + 'subsections' => array( |
|
71 | + 'ATT_email' => new EE_Email_Input( |
|
72 | + array( |
|
73 | + 'default' => $this->attendee->email(), |
|
74 | + 'html_label_text' => esc_html__('Email Address', 'event_espresso'), |
|
75 | + 'required' => true |
|
76 | + ) |
|
77 | + ), |
|
78 | + 'ATT_phone' => new EE_Text_Input( |
|
79 | + array( |
|
80 | + 'default' => $this->attendee->phone(), |
|
81 | + 'html_label_text' => esc_html__('Phone Number', 'event_espresso') |
|
82 | + ) |
|
83 | + ) |
|
84 | + ) |
|
85 | + ) |
|
86 | + ); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * Process form data. |
|
92 | - * @param array $form_data |
|
93 | - * @return bool |
|
94 | - * @throws EE_Error |
|
95 | - * @throws InvalidFormSubmissionException |
|
96 | - * @throws LogicException |
|
97 | - */ |
|
98 | - public function process($form_data = array()) |
|
99 | - { |
|
100 | - $valid_data = (array) parent::process($form_data); |
|
101 | - if (empty($valid_data)) { |
|
102 | - return false; |
|
103 | - } |
|
104 | - $this->attendee->set_email($valid_data['ATT_email']); |
|
105 | - $this->attendee->set_phone($valid_data['ATT_phone']); |
|
106 | - $updated = $this->attendee->save(); |
|
107 | - return $updated !== false; |
|
108 | - } |
|
90 | + /** |
|
91 | + * Process form data. |
|
92 | + * @param array $form_data |
|
93 | + * @return bool |
|
94 | + * @throws EE_Error |
|
95 | + * @throws InvalidFormSubmissionException |
|
96 | + * @throws LogicException |
|
97 | + */ |
|
98 | + public function process($form_data = array()) |
|
99 | + { |
|
100 | + $valid_data = (array) parent::process($form_data); |
|
101 | + if (empty($valid_data)) { |
|
102 | + return false; |
|
103 | + } |
|
104 | + $this->attendee->set_email($valid_data['ATT_email']); |
|
105 | + $this->attendee->set_phone($valid_data['ATT_phone']); |
|
106 | + $updated = $this->attendee->save(); |
|
107 | + return $updated !== false; |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | \ No newline at end of file |
@@ -24,7 +24,7 @@ |
||
24 | 24 | * @author Darren Ethier |
25 | 25 | * @since 1.0.0 |
26 | 26 | */ |
27 | -class AttendeeContactDetailsMetaboxFormHandler extends FormHandler{ |
|
27 | +class AttendeeContactDetailsMetaboxFormHandler extends FormHandler { |
|
28 | 28 | |
29 | 29 | |
30 | 30 | protected $attendee; |
@@ -10,80 +10,80 @@ |
||
10 | 10 | class EE_Admin_Two_Column_Layout extends EE_Two_Column_Layout |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * Overriding the parent table layout to include <tbody> tags |
|
15 | - * |
|
16 | - * @param array $additional_args |
|
17 | - * @return string |
|
18 | - */ |
|
19 | - public function layout_form_begin($additional_args = array()) |
|
20 | - { |
|
21 | - $this->_form_section->set_html_class($this->_form_section->html_class() . ' form-table'); |
|
22 | - return parent::layout_form_begin($additional_args); |
|
23 | - } |
|
13 | + /** |
|
14 | + * Overriding the parent table layout to include <tbody> tags |
|
15 | + * |
|
16 | + * @param array $additional_args |
|
17 | + * @return string |
|
18 | + */ |
|
19 | + public function layout_form_begin($additional_args = array()) |
|
20 | + { |
|
21 | + $this->_form_section->set_html_class($this->_form_section->html_class() . ' form-table'); |
|
22 | + return parent::layout_form_begin($additional_args); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * Lays out a row for the subsection |
|
29 | - * |
|
30 | - * @param EE_Form_Section_Proper $form_section |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - public function layout_subsection($form_section) |
|
34 | - { |
|
35 | - if ($form_section instanceof EE_Form_Section_Proper |
|
36 | - || $form_section instanceof EE_Form_Section_HTML |
|
37 | - ) { |
|
38 | - return EEH_HTML::no_row($form_section->get_html()); |
|
39 | - } |
|
40 | - return ''; |
|
41 | - } |
|
27 | + /** |
|
28 | + * Lays out a row for the subsection |
|
29 | + * |
|
30 | + * @param EE_Form_Section_Proper $form_section |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + public function layout_subsection($form_section) |
|
34 | + { |
|
35 | + if ($form_section instanceof EE_Form_Section_Proper |
|
36 | + || $form_section instanceof EE_Form_Section_HTML |
|
37 | + ) { |
|
38 | + return EEH_HTML::no_row($form_section->get_html()); |
|
39 | + } |
|
40 | + return ''; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * Lays out the row for the input, including label and errors |
|
47 | - * |
|
48 | - * @param EE_Form_Input_Base $input |
|
49 | - * @return string |
|
50 | - * @throws EE_Error |
|
51 | - */ |
|
52 | - public function layout_input($input) |
|
53 | - { |
|
54 | - if ($input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy |
|
55 | - || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
|
56 | - || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
|
57 | - ) { |
|
58 | - $input->set_html_class($input->html_class() . ' large-text'); |
|
59 | - } |
|
60 | - if ($input instanceof EE_Text_Area_Input) { |
|
61 | - $input->set_rows(4); |
|
62 | - $input->set_cols(60); |
|
63 | - } |
|
64 | - $input_html = $input->get_html_for_input(); |
|
65 | - // maybe add errors and help text ? |
|
66 | - $input_html .= $input->get_html_for_errors() !== '' |
|
67 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
68 | - : ''; |
|
69 | - $input_html .= $input->get_html_for_help() !== '' |
|
70 | - ? EEH_HTML::nl() . $input->get_html_for_help() |
|
71 | - : ''; |
|
72 | - //overriding parent to add wp admin specific things. |
|
73 | - $html = ''; |
|
74 | - if ($input instanceof EE_Hidden_Input) { |
|
75 | - $html .= EEH_HTML::no_row($input->get_html_for_input()); |
|
76 | - } else { |
|
77 | - $html .= EEH_HTML::tr( |
|
78 | - EEH_HTML::th( |
|
79 | - $input->get_html_for_label(), |
|
80 | - '', |
|
81 | - '', |
|
82 | - '', |
|
83 | - 'scope="row"' |
|
84 | - ) . EEH_HTML::td($input_html) |
|
85 | - ); |
|
86 | - } |
|
87 | - return $html; |
|
88 | - } |
|
45 | + /** |
|
46 | + * Lays out the row for the input, including label and errors |
|
47 | + * |
|
48 | + * @param EE_Form_Input_Base $input |
|
49 | + * @return string |
|
50 | + * @throws EE_Error |
|
51 | + */ |
|
52 | + public function layout_input($input) |
|
53 | + { |
|
54 | + if ($input->get_display_strategy() instanceof EE_Text_Area_Display_Strategy |
|
55 | + || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
|
56 | + || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
|
57 | + ) { |
|
58 | + $input->set_html_class($input->html_class() . ' large-text'); |
|
59 | + } |
|
60 | + if ($input instanceof EE_Text_Area_Input) { |
|
61 | + $input->set_rows(4); |
|
62 | + $input->set_cols(60); |
|
63 | + } |
|
64 | + $input_html = $input->get_html_for_input(); |
|
65 | + // maybe add errors and help text ? |
|
66 | + $input_html .= $input->get_html_for_errors() !== '' |
|
67 | + ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
68 | + : ''; |
|
69 | + $input_html .= $input->get_html_for_help() !== '' |
|
70 | + ? EEH_HTML::nl() . $input->get_html_for_help() |
|
71 | + : ''; |
|
72 | + //overriding parent to add wp admin specific things. |
|
73 | + $html = ''; |
|
74 | + if ($input instanceof EE_Hidden_Input) { |
|
75 | + $html .= EEH_HTML::no_row($input->get_html_for_input()); |
|
76 | + } else { |
|
77 | + $html .= EEH_HTML::tr( |
|
78 | + EEH_HTML::th( |
|
79 | + $input->get_html_for_label(), |
|
80 | + '', |
|
81 | + '', |
|
82 | + '', |
|
83 | + 'scope="row"' |
|
84 | + ) . EEH_HTML::td($input_html) |
|
85 | + ); |
|
86 | + } |
|
87 | + return $html; |
|
88 | + } |
|
89 | 89 | } |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | */ |
19 | 19 | public function layout_form_begin($additional_args = array()) |
20 | 20 | { |
21 | - $this->_form_section->set_html_class($this->_form_section->html_class() . ' form-table'); |
|
21 | + $this->_form_section->set_html_class($this->_form_section->html_class().' form-table'); |
|
22 | 22 | return parent::layout_form_begin($additional_args); |
23 | 23 | } |
24 | 24 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | || $input->get_display_strategy() instanceof EE_Text_Input_Display_Strategy |
56 | 56 | || $input->get_display_strategy() instanceof EE_Admin_File_Uploader_Display_Strategy |
57 | 57 | ) { |
58 | - $input->set_html_class($input->html_class() . ' large-text'); |
|
58 | + $input->set_html_class($input->html_class().' large-text'); |
|
59 | 59 | } |
60 | 60 | if ($input instanceof EE_Text_Area_Input) { |
61 | 61 | $input->set_rows(4); |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | $input_html = $input->get_html_for_input(); |
65 | 65 | // maybe add errors and help text ? |
66 | 66 | $input_html .= $input->get_html_for_errors() !== '' |
67 | - ? EEH_HTML::nl() . $input->get_html_for_errors() |
|
67 | + ? EEH_HTML::nl().$input->get_html_for_errors() |
|
68 | 68 | : ''; |
69 | 69 | $input_html .= $input->get_html_for_help() !== '' |
70 | - ? EEH_HTML::nl() . $input->get_html_for_help() |
|
70 | + ? EEH_HTML::nl().$input->get_html_for_help() |
|
71 | 71 | : ''; |
72 | 72 | //overriding parent to add wp admin specific things. |
73 | 73 | $html = ''; |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | '', |
82 | 82 | '', |
83 | 83 | 'scope="row"' |
84 | - ) . EEH_HTML::td($input_html) |
|
84 | + ).EEH_HTML::td($input_html) |
|
85 | 85 | ); |
86 | 86 | } |
87 | 87 | return $html; |