@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | use EE_Error; |
19 | 19 | |
20 | 20 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
21 | - exit('No direct script access allowed'); |
|
21 | + exit('No direct script access allowed'); |
|
22 | 22 | } |
23 | 23 | |
24 | 24 | |
@@ -36,334 +36,334 @@ discard block |
||
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - public function __construct() |
|
40 | - { |
|
41 | - parent::__construct(); |
|
42 | - EE_Registry::instance()->load_helper('Inflector'); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
49 | - * |
|
50 | - * @param WP_REST_Request $request |
|
51 | - * @param string $version |
|
52 | - * @param string $model_name |
|
53 | - * @return WP_REST_Response|\WP_Error |
|
54 | - */ |
|
55 | - public static function handleRequestInsert(WP_REST_Request $request, $version, $model_name) |
|
56 | - { |
|
57 | - $controller = new Write(); |
|
58 | - try { |
|
59 | - $controller->setRequestedVersion($version); |
|
60 | - return $controller->sendResponse( |
|
61 | - $controller->insert( |
|
62 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
63 | - $request |
|
64 | - ) |
|
65 | - ); |
|
66 | - } catch (\Exception $e) { |
|
67 | - return $controller->sendResponse($e); |
|
68 | - } |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Handles a request from \WP_REST_Server to update an EE model |
|
75 | - * |
|
76 | - * @param WP_REST_Request $request |
|
77 | - * @param string $version |
|
78 | - * @param string $model_name |
|
79 | - * @return WP_REST_Response|\WP_Error |
|
80 | - */ |
|
81 | - public static function handleRequestUpdate(WP_REST_Request $request, $version, $model_name) |
|
82 | - { |
|
83 | - $controller = new Write(); |
|
84 | - try { |
|
85 | - $controller->setRequestedVersion($version); |
|
86 | - return $controller->sendResponse( |
|
87 | - $controller->update( |
|
88 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
89 | - $request |
|
90 | - ) |
|
91 | - ); |
|
92 | - } catch (\Exception $e) { |
|
93 | - return $controller->sendResponse($e); |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Deletes a single model object and returns it. Unless |
|
101 | - * |
|
102 | - * @param WP_REST_Request $request |
|
103 | - * @param string $version |
|
104 | - * @param string $model_name |
|
105 | - * @return WP_REST_Response|\WP_Error |
|
106 | - */ |
|
107 | - public static function handleRequestDelete(WP_REST_Request $request, $version, $model_name) |
|
108 | - { |
|
109 | - $controller = new Write(); |
|
110 | - try { |
|
111 | - $controller->setRequestedVersion($version); |
|
112 | - return $controller->sendResponse( |
|
113 | - $controller->delete( |
|
114 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
115 | - $request |
|
116 | - ) |
|
117 | - ); |
|
118 | - } catch (\Exception $e) { |
|
119 | - return $controller->sendResponse($e); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Inserts a new model object according to the $request |
|
127 | - * |
|
128 | - * @param EEM_Base $model |
|
129 | - * @param WP_REST_Request $request |
|
130 | - * @return array |
|
131 | - * @throws EE_Error |
|
132 | - * @throws RestException |
|
133 | - */ |
|
134 | - public function insert(EEM_Base $model, WP_REST_Request $request) |
|
135 | - { |
|
136 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
|
137 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
138 | - if (! current_user_can($default_cap_to_check_for)) { |
|
139 | - throw new RestException( |
|
140 | - 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
141 | - sprintf( |
|
142 | - esc_html__( |
|
143 | - // @codingStandardsIgnoreStart |
|
144 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.', |
|
145 | - // @codingStandardsIgnoreEnd |
|
146 | - 'event_espresso' |
|
147 | - ), |
|
148 | - $default_cap_to_check_for |
|
149 | - ), |
|
150 | - array('status' => 403) |
|
151 | - ); |
|
152 | - } |
|
153 | - $submitted_json_data = array_merge((array)$request->get_body_params(), (array)$request->get_json_params()); |
|
154 | - $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
155 | - $submitted_json_data, |
|
156 | - $model, |
|
157 | - $this->getModelVersionInfo()->requestedVersion(), |
|
158 | - true |
|
159 | - ); |
|
160 | - $model_obj = EE_Registry::instance()->load_class( |
|
161 | - $model->get_this_model_name(), |
|
162 | - array($model_data, $model->get_timezone()), |
|
163 | - false, |
|
164 | - false |
|
165 | - ); |
|
166 | - $model_obj->save(); |
|
167 | - $new_id = $model_obj->ID(); |
|
168 | - if (! $new_id) { |
|
169 | - throw new RestException( |
|
170 | - 'rest_insertion_failed', |
|
171 | - sprintf(__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
172 | - ); |
|
173 | - } |
|
174 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Updates an existing model object according to the $request |
|
181 | - * |
|
182 | - * @param EEM_Base $model |
|
183 | - * @param WP_REST_Request $request |
|
184 | - * @return array |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public function update(EEM_Base $model, WP_REST_Request $request) |
|
188 | - { |
|
189 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
190 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
191 | - if (! current_user_can($default_cap_to_check_for)) { |
|
192 | - throw new RestException( |
|
193 | - 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
194 | - sprintf( |
|
195 | - esc_html__( |
|
196 | - // @codingStandardsIgnoreStart |
|
197 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.', |
|
198 | - // @codingStandardsIgnoreEnd |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - $default_cap_to_check_for |
|
202 | - ), |
|
203 | - array('status' => 403) |
|
204 | - ); |
|
205 | - } |
|
206 | - $obj_id = $request->get_param('id'); |
|
207 | - if (! $obj_id) { |
|
208 | - throw new RestException( |
|
209 | - 'rest_edit_failed', |
|
210 | - sprintf(__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
211 | - ); |
|
212 | - } |
|
213 | - $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
214 | - $this->getBodyParams($request), |
|
215 | - $model, |
|
216 | - $this->getModelVersionInfo()->requestedVersion(), |
|
217 | - true |
|
218 | - ); |
|
219 | - $model_obj = $model->get_one_by_ID($obj_id); |
|
220 | - if (! $model_obj instanceof EE_Base_Class) { |
|
221 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
222 | - throw new RestException( |
|
223 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
224 | - sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
225 | - array('status' => 404) |
|
226 | - ); |
|
227 | - } |
|
228 | - $model_obj->save($model_data); |
|
229 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * Updates an existing model object according to the $request |
|
236 | - * |
|
237 | - * @param EEM_Base $model |
|
238 | - * @param WP_REST_Request $request |
|
239 | - * @return array of either the soft-deleted item, or |
|
240 | - * @throws EE_Error |
|
241 | - */ |
|
242 | - public function delete(EEM_Base $model, WP_REST_Request $request) |
|
243 | - { |
|
244 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
|
245 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
246 | - if (! current_user_can($default_cap_to_check_for)) { |
|
247 | - throw new RestException( |
|
248 | - 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
249 | - sprintf( |
|
250 | - esc_html__( |
|
251 | - // @codingStandardsIgnoreStart |
|
252 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.', |
|
253 | - // @codingStandardsIgnoreEnd |
|
254 | - 'event_espresso' |
|
255 | - ), |
|
256 | - $default_cap_to_check_for |
|
257 | - ), |
|
258 | - array('status' => 403) |
|
259 | - ); |
|
260 | - } |
|
261 | - $obj_id = $request->get_param('id'); |
|
262 | - //this is where we would apply more fine-grained caps |
|
263 | - $model_obj = $model->get_one_by_ID($obj_id); |
|
264 | - if (! $model_obj instanceof EE_Base_Class) { |
|
265 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
266 | - throw new RestException( |
|
267 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
268 | - sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
269 | - array('status' => 404) |
|
270 | - ); |
|
271 | - } |
|
272 | - $requested_permanent_delete = filter_var($request->get_param('force'), FILTER_VALIDATE_BOOLEAN); |
|
273 | - $requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN); |
|
274 | - if ($requested_permanent_delete) { |
|
275 | - $previous = $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
276 | - $deleted = (bool)$model->delete_permanently_by_ID($obj_id, $requested_allow_blocking); |
|
277 | - return array( |
|
278 | - 'deleted' => $deleted, |
|
279 | - 'previous' => $previous, |
|
280 | - ); |
|
281 | - } else { |
|
282 | - if ($model instanceof EEM_Soft_Delete_Base) { |
|
283 | - $model->delete_by_ID($obj_id, $requested_allow_blocking); |
|
284 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
285 | - } else { |
|
286 | - throw new RestException( |
|
287 | - 'rest_trash_not_supported', |
|
288 | - 501, |
|
289 | - sprintf( |
|
290 | - esc_html__('%1$s do not support trashing. Set force=1 to delete.', 'event_espresso'), |
|
291 | - EEH_Inflector::pluralize($model->get_this_model_name()) |
|
292 | - ) |
|
293 | - ); |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - /** |
|
301 | - * Returns an array ready to be converted into a JSON response, based solely on the model object |
|
302 | - * |
|
303 | - * @param EE_Base_Class $model_obj |
|
304 | - * @param WP_REST_Request $request |
|
305 | - * @return array ready for a response |
|
306 | - */ |
|
307 | - protected function returnModelObjAsJsonResponse(EE_Base_Class $model_obj, WP_REST_Request $request) |
|
308 | - { |
|
309 | - $model = $model_obj->get_model(); |
|
310 | - //create an array exactly like the wpdb results row, |
|
311 | - // so we can pass it to controllers/model/Read::create_entity_from_wpdb_result() |
|
312 | - $simulated_db_row = array(); |
|
313 | - foreach ($model->field_settings(true) as $field_name => $field_obj) { |
|
314 | - //we need to reconstruct the normal wpdb results, including the db-only fields |
|
315 | - //like a secondary table's primary key. The models expect those (but don't care what value they have) |
|
316 | - if( $field_obj instanceof EE_DB_Only_Field_Base){ |
|
317 | - $raw_value = true; |
|
318 | - } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
319 | - $raw_value = $model_obj->get_DateTime_object($field_name); |
|
320 | - } else { |
|
321 | - $raw_value = $model_obj->get_raw($field_name); |
|
322 | - } |
|
323 | - $simulated_db_row[$field_obj->get_qualified_column()] = $field_obj->prepare_for_use_in_db($raw_value); |
|
324 | - } |
|
325 | - $read_controller = new Read(); |
|
326 | - $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
327 | - //the simulates request really doesn't need any info downstream |
|
328 | - $simulated_request = new WP_REST_Request('GET'); |
|
329 | - return $read_controller->createEntityFromWpdbResult( |
|
330 | - $model_obj->get_model(), |
|
331 | - $simulated_db_row, |
|
332 | - $simulated_request |
|
333 | - ); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Gets the item affected by this request |
|
340 | - * |
|
341 | - * @param EEM_Base $model |
|
342 | - * @param WP_REST_Request $request |
|
343 | - * @param int|string $obj_id |
|
344 | - * @return \WP_Error|array |
|
345 | - */ |
|
346 | - protected function getOneBasedOnRequest(EEM_Base $model, WP_REST_Request $request, $obj_id) |
|
347 | - { |
|
348 | - $requested_version = $this->getRequestedVersion($request->get_route()); |
|
349 | - $get_request = new WP_REST_Request( |
|
350 | - 'GET', |
|
351 | - EED_Core_Rest_Api::ee_api_namespace |
|
352 | - . $requested_version |
|
353 | - . '/' |
|
354 | - . EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
355 | - . '/' |
|
356 | - . $obj_id |
|
357 | - ); |
|
358 | - $get_request->set_url_params( |
|
359 | - array( |
|
360 | - 'id' => $obj_id, |
|
361 | - 'include' => $request->get_param('include'), |
|
362 | - ) |
|
363 | - ); |
|
364 | - $read_controller = new Read(); |
|
365 | - $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
366 | - return $read_controller->getEntityFromModel($model, $get_request); |
|
367 | - } |
|
39 | + public function __construct() |
|
40 | + { |
|
41 | + parent::__construct(); |
|
42 | + EE_Registry::instance()->load_helper('Inflector'); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
49 | + * |
|
50 | + * @param WP_REST_Request $request |
|
51 | + * @param string $version |
|
52 | + * @param string $model_name |
|
53 | + * @return WP_REST_Response|\WP_Error |
|
54 | + */ |
|
55 | + public static function handleRequestInsert(WP_REST_Request $request, $version, $model_name) |
|
56 | + { |
|
57 | + $controller = new Write(); |
|
58 | + try { |
|
59 | + $controller->setRequestedVersion($version); |
|
60 | + return $controller->sendResponse( |
|
61 | + $controller->insert( |
|
62 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
63 | + $request |
|
64 | + ) |
|
65 | + ); |
|
66 | + } catch (\Exception $e) { |
|
67 | + return $controller->sendResponse($e); |
|
68 | + } |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Handles a request from \WP_REST_Server to update an EE model |
|
75 | + * |
|
76 | + * @param WP_REST_Request $request |
|
77 | + * @param string $version |
|
78 | + * @param string $model_name |
|
79 | + * @return WP_REST_Response|\WP_Error |
|
80 | + */ |
|
81 | + public static function handleRequestUpdate(WP_REST_Request $request, $version, $model_name) |
|
82 | + { |
|
83 | + $controller = new Write(); |
|
84 | + try { |
|
85 | + $controller->setRequestedVersion($version); |
|
86 | + return $controller->sendResponse( |
|
87 | + $controller->update( |
|
88 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
89 | + $request |
|
90 | + ) |
|
91 | + ); |
|
92 | + } catch (\Exception $e) { |
|
93 | + return $controller->sendResponse($e); |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Deletes a single model object and returns it. Unless |
|
101 | + * |
|
102 | + * @param WP_REST_Request $request |
|
103 | + * @param string $version |
|
104 | + * @param string $model_name |
|
105 | + * @return WP_REST_Response|\WP_Error |
|
106 | + */ |
|
107 | + public static function handleRequestDelete(WP_REST_Request $request, $version, $model_name) |
|
108 | + { |
|
109 | + $controller = new Write(); |
|
110 | + try { |
|
111 | + $controller->setRequestedVersion($version); |
|
112 | + return $controller->sendResponse( |
|
113 | + $controller->delete( |
|
114 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
115 | + $request |
|
116 | + ) |
|
117 | + ); |
|
118 | + } catch (\Exception $e) { |
|
119 | + return $controller->sendResponse($e); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Inserts a new model object according to the $request |
|
127 | + * |
|
128 | + * @param EEM_Base $model |
|
129 | + * @param WP_REST_Request $request |
|
130 | + * @return array |
|
131 | + * @throws EE_Error |
|
132 | + * @throws RestException |
|
133 | + */ |
|
134 | + public function insert(EEM_Base $model, WP_REST_Request $request) |
|
135 | + { |
|
136 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
|
137 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
138 | + if (! current_user_can($default_cap_to_check_for)) { |
|
139 | + throw new RestException( |
|
140 | + 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
141 | + sprintf( |
|
142 | + esc_html__( |
|
143 | + // @codingStandardsIgnoreStart |
|
144 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.', |
|
145 | + // @codingStandardsIgnoreEnd |
|
146 | + 'event_espresso' |
|
147 | + ), |
|
148 | + $default_cap_to_check_for |
|
149 | + ), |
|
150 | + array('status' => 403) |
|
151 | + ); |
|
152 | + } |
|
153 | + $submitted_json_data = array_merge((array)$request->get_body_params(), (array)$request->get_json_params()); |
|
154 | + $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
155 | + $submitted_json_data, |
|
156 | + $model, |
|
157 | + $this->getModelVersionInfo()->requestedVersion(), |
|
158 | + true |
|
159 | + ); |
|
160 | + $model_obj = EE_Registry::instance()->load_class( |
|
161 | + $model->get_this_model_name(), |
|
162 | + array($model_data, $model->get_timezone()), |
|
163 | + false, |
|
164 | + false |
|
165 | + ); |
|
166 | + $model_obj->save(); |
|
167 | + $new_id = $model_obj->ID(); |
|
168 | + if (! $new_id) { |
|
169 | + throw new RestException( |
|
170 | + 'rest_insertion_failed', |
|
171 | + sprintf(__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
172 | + ); |
|
173 | + } |
|
174 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Updates an existing model object according to the $request |
|
181 | + * |
|
182 | + * @param EEM_Base $model |
|
183 | + * @param WP_REST_Request $request |
|
184 | + * @return array |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public function update(EEM_Base $model, WP_REST_Request $request) |
|
188 | + { |
|
189 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
190 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
191 | + if (! current_user_can($default_cap_to_check_for)) { |
|
192 | + throw new RestException( |
|
193 | + 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
194 | + sprintf( |
|
195 | + esc_html__( |
|
196 | + // @codingStandardsIgnoreStart |
|
197 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.', |
|
198 | + // @codingStandardsIgnoreEnd |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + $default_cap_to_check_for |
|
202 | + ), |
|
203 | + array('status' => 403) |
|
204 | + ); |
|
205 | + } |
|
206 | + $obj_id = $request->get_param('id'); |
|
207 | + if (! $obj_id) { |
|
208 | + throw new RestException( |
|
209 | + 'rest_edit_failed', |
|
210 | + sprintf(__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
211 | + ); |
|
212 | + } |
|
213 | + $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
214 | + $this->getBodyParams($request), |
|
215 | + $model, |
|
216 | + $this->getModelVersionInfo()->requestedVersion(), |
|
217 | + true |
|
218 | + ); |
|
219 | + $model_obj = $model->get_one_by_ID($obj_id); |
|
220 | + if (! $model_obj instanceof EE_Base_Class) { |
|
221 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
222 | + throw new RestException( |
|
223 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
224 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
225 | + array('status' => 404) |
|
226 | + ); |
|
227 | + } |
|
228 | + $model_obj->save($model_data); |
|
229 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * Updates an existing model object according to the $request |
|
236 | + * |
|
237 | + * @param EEM_Base $model |
|
238 | + * @param WP_REST_Request $request |
|
239 | + * @return array of either the soft-deleted item, or |
|
240 | + * @throws EE_Error |
|
241 | + */ |
|
242 | + public function delete(EEM_Base $model, WP_REST_Request $request) |
|
243 | + { |
|
244 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
|
245 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
246 | + if (! current_user_can($default_cap_to_check_for)) { |
|
247 | + throw new RestException( |
|
248 | + 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
249 | + sprintf( |
|
250 | + esc_html__( |
|
251 | + // @codingStandardsIgnoreStart |
|
252 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.', |
|
253 | + // @codingStandardsIgnoreEnd |
|
254 | + 'event_espresso' |
|
255 | + ), |
|
256 | + $default_cap_to_check_for |
|
257 | + ), |
|
258 | + array('status' => 403) |
|
259 | + ); |
|
260 | + } |
|
261 | + $obj_id = $request->get_param('id'); |
|
262 | + //this is where we would apply more fine-grained caps |
|
263 | + $model_obj = $model->get_one_by_ID($obj_id); |
|
264 | + if (! $model_obj instanceof EE_Base_Class) { |
|
265 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
266 | + throw new RestException( |
|
267 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
268 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
269 | + array('status' => 404) |
|
270 | + ); |
|
271 | + } |
|
272 | + $requested_permanent_delete = filter_var($request->get_param('force'), FILTER_VALIDATE_BOOLEAN); |
|
273 | + $requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN); |
|
274 | + if ($requested_permanent_delete) { |
|
275 | + $previous = $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
276 | + $deleted = (bool)$model->delete_permanently_by_ID($obj_id, $requested_allow_blocking); |
|
277 | + return array( |
|
278 | + 'deleted' => $deleted, |
|
279 | + 'previous' => $previous, |
|
280 | + ); |
|
281 | + } else { |
|
282 | + if ($model instanceof EEM_Soft_Delete_Base) { |
|
283 | + $model->delete_by_ID($obj_id, $requested_allow_blocking); |
|
284 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
285 | + } else { |
|
286 | + throw new RestException( |
|
287 | + 'rest_trash_not_supported', |
|
288 | + 501, |
|
289 | + sprintf( |
|
290 | + esc_html__('%1$s do not support trashing. Set force=1 to delete.', 'event_espresso'), |
|
291 | + EEH_Inflector::pluralize($model->get_this_model_name()) |
|
292 | + ) |
|
293 | + ); |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + /** |
|
301 | + * Returns an array ready to be converted into a JSON response, based solely on the model object |
|
302 | + * |
|
303 | + * @param EE_Base_Class $model_obj |
|
304 | + * @param WP_REST_Request $request |
|
305 | + * @return array ready for a response |
|
306 | + */ |
|
307 | + protected function returnModelObjAsJsonResponse(EE_Base_Class $model_obj, WP_REST_Request $request) |
|
308 | + { |
|
309 | + $model = $model_obj->get_model(); |
|
310 | + //create an array exactly like the wpdb results row, |
|
311 | + // so we can pass it to controllers/model/Read::create_entity_from_wpdb_result() |
|
312 | + $simulated_db_row = array(); |
|
313 | + foreach ($model->field_settings(true) as $field_name => $field_obj) { |
|
314 | + //we need to reconstruct the normal wpdb results, including the db-only fields |
|
315 | + //like a secondary table's primary key. The models expect those (but don't care what value they have) |
|
316 | + if( $field_obj instanceof EE_DB_Only_Field_Base){ |
|
317 | + $raw_value = true; |
|
318 | + } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
319 | + $raw_value = $model_obj->get_DateTime_object($field_name); |
|
320 | + } else { |
|
321 | + $raw_value = $model_obj->get_raw($field_name); |
|
322 | + } |
|
323 | + $simulated_db_row[$field_obj->get_qualified_column()] = $field_obj->prepare_for_use_in_db($raw_value); |
|
324 | + } |
|
325 | + $read_controller = new Read(); |
|
326 | + $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
327 | + //the simulates request really doesn't need any info downstream |
|
328 | + $simulated_request = new WP_REST_Request('GET'); |
|
329 | + return $read_controller->createEntityFromWpdbResult( |
|
330 | + $model_obj->get_model(), |
|
331 | + $simulated_db_row, |
|
332 | + $simulated_request |
|
333 | + ); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Gets the item affected by this request |
|
340 | + * |
|
341 | + * @param EEM_Base $model |
|
342 | + * @param WP_REST_Request $request |
|
343 | + * @param int|string $obj_id |
|
344 | + * @return \WP_Error|array |
|
345 | + */ |
|
346 | + protected function getOneBasedOnRequest(EEM_Base $model, WP_REST_Request $request, $obj_id) |
|
347 | + { |
|
348 | + $requested_version = $this->getRequestedVersion($request->get_route()); |
|
349 | + $get_request = new WP_REST_Request( |
|
350 | + 'GET', |
|
351 | + EED_Core_Rest_Api::ee_api_namespace |
|
352 | + . $requested_version |
|
353 | + . '/' |
|
354 | + . EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
355 | + . '/' |
|
356 | + . $obj_id |
|
357 | + ); |
|
358 | + $get_request->set_url_params( |
|
359 | + array( |
|
360 | + 'id' => $obj_id, |
|
361 | + 'include' => $request->get_param('include'), |
|
362 | + ) |
|
363 | + ); |
|
364 | + $read_controller = new Read(); |
|
365 | + $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
366 | + return $read_controller->getEntityFromModel($model, $get_request); |
|
367 | + } |
|
368 | 368 | } |
369 | 369 | // End of file Read.php |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | use EEH_Inflector; |
18 | 18 | use EE_Error; |
19 | 19 | |
20 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
20 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
21 | 21 | exit('No direct script access allowed'); |
22 | 22 | } |
23 | 23 | |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | { |
136 | 136 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
137 | 137 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
138 | - if (! current_user_can($default_cap_to_check_for)) { |
|
138 | + if ( ! current_user_can($default_cap_to_check_for)) { |
|
139 | 139 | throw new RestException( |
140 | - 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
140 | + 'rest_cannot_create_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
141 | 141 | sprintf( |
142 | 142 | esc_html__( |
143 | 143 | // @codingStandardsIgnoreStart |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | array('status' => 403) |
151 | 151 | ); |
152 | 152 | } |
153 | - $submitted_json_data = array_merge((array)$request->get_body_params(), (array)$request->get_json_params()); |
|
153 | + $submitted_json_data = array_merge((array) $request->get_body_params(), (array) $request->get_json_params()); |
|
154 | 154 | $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
155 | 155 | $submitted_json_data, |
156 | 156 | $model, |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | ); |
166 | 166 | $model_obj->save(); |
167 | 167 | $new_id = $model_obj->ID(); |
168 | - if (! $new_id) { |
|
168 | + if ( ! $new_id) { |
|
169 | 169 | throw new RestException( |
170 | 170 | 'rest_insertion_failed', |
171 | 171 | sprintf(__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name()) |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | { |
189 | 189 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
190 | 190 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
191 | - if (! current_user_can($default_cap_to_check_for)) { |
|
191 | + if ( ! current_user_can($default_cap_to_check_for)) { |
|
192 | 192 | throw new RestException( |
193 | - 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
193 | + 'rest_cannot_edit_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
194 | 194 | sprintf( |
195 | 195 | esc_html__( |
196 | 196 | // @codingStandardsIgnoreStart |
@@ -204,7 +204,7 @@ discard block |
||
204 | 204 | ); |
205 | 205 | } |
206 | 206 | $obj_id = $request->get_param('id'); |
207 | - if (! $obj_id) { |
|
207 | + if ( ! $obj_id) { |
|
208 | 208 | throw new RestException( |
209 | 209 | 'rest_edit_failed', |
210 | 210 | sprintf(__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name()) |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | true |
218 | 218 | ); |
219 | 219 | $model_obj = $model->get_one_by_ID($obj_id); |
220 | - if (! $model_obj instanceof EE_Base_Class) { |
|
220 | + if ( ! $model_obj instanceof EE_Base_Class) { |
|
221 | 221 | $lowercase_model_name = strtolower($model->get_this_model_name()); |
222 | 222 | throw new RestException( |
223 | 223 | sprintf('rest_%s_invalid_id', $lowercase_model_name), |
@@ -243,9 +243,9 @@ discard block |
||
243 | 243 | { |
244 | 244 | Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
245 | 245 | $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
246 | - if (! current_user_can($default_cap_to_check_for)) { |
|
246 | + if ( ! current_user_can($default_cap_to_check_for)) { |
|
247 | 247 | throw new RestException( |
248 | - 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
248 | + 'rest_cannot_delete_'.EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
249 | 249 | sprintf( |
250 | 250 | esc_html__( |
251 | 251 | // @codingStandardsIgnoreStart |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | $obj_id = $request->get_param('id'); |
262 | 262 | //this is where we would apply more fine-grained caps |
263 | 263 | $model_obj = $model->get_one_by_ID($obj_id); |
264 | - if (! $model_obj instanceof EE_Base_Class) { |
|
264 | + if ( ! $model_obj instanceof EE_Base_Class) { |
|
265 | 265 | $lowercase_model_name = strtolower($model->get_this_model_name()); |
266 | 266 | throw new RestException( |
267 | 267 | sprintf('rest_%s_invalid_id', $lowercase_model_name), |
@@ -273,7 +273,7 @@ discard block |
||
273 | 273 | $requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN); |
274 | 274 | if ($requested_permanent_delete) { |
275 | 275 | $previous = $this->returnModelObjAsJsonResponse($model_obj, $request); |
276 | - $deleted = (bool)$model->delete_permanently_by_ID($obj_id, $requested_allow_blocking); |
|
276 | + $deleted = (bool) $model->delete_permanently_by_ID($obj_id, $requested_allow_blocking); |
|
277 | 277 | return array( |
278 | 278 | 'deleted' => $deleted, |
279 | 279 | 'previous' => $previous, |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | foreach ($model->field_settings(true) as $field_name => $field_obj) { |
314 | 314 | //we need to reconstruct the normal wpdb results, including the db-only fields |
315 | 315 | //like a secondary table's primary key. The models expect those (but don't care what value they have) |
316 | - if( $field_obj instanceof EE_DB_Only_Field_Base){ |
|
316 | + if ($field_obj instanceof EE_DB_Only_Field_Base) { |
|
317 | 317 | $raw_value = true; |
318 | 318 | } elseif ($field_obj instanceof EE_Datetime_Field) { |
319 | 319 | $raw_value = $model_obj->get_DateTime_object($field_name); |
@@ -13,93 +13,93 @@ discard block |
||
13 | 13 | class EEM_Change_Log extends EEM_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * the related object was created log type |
|
18 | - */ |
|
19 | - const type_create = 'create'; |
|
20 | - /** |
|
21 | - * the related object was updated (changed, or soft-deleted) |
|
22 | - */ |
|
23 | - const type_update = 'update'; |
|
24 | - /** |
|
25 | - * the related object was deleted permanently |
|
26 | - */ |
|
27 | - const type_delete = 'delete'; |
|
28 | - /** |
|
29 | - * the related item had something worth noting happen on it, but |
|
30 | - * only for the purposes of debugging problems |
|
31 | - */ |
|
32 | - const type_debug = 'debug'; |
|
33 | - /** |
|
34 | - * the related item had an error occur on it |
|
35 | - */ |
|
36 | - const type_error = 'error'; |
|
37 | - /** |
|
38 | - * the related item is regarding some gateway interaction, like an IPN |
|
39 | - * or request to process a payment |
|
40 | - */ |
|
41 | - const type_gateway = 'gateway'; |
|
16 | + /** |
|
17 | + * the related object was created log type |
|
18 | + */ |
|
19 | + const type_create = 'create'; |
|
20 | + /** |
|
21 | + * the related object was updated (changed, or soft-deleted) |
|
22 | + */ |
|
23 | + const type_update = 'update'; |
|
24 | + /** |
|
25 | + * the related object was deleted permanently |
|
26 | + */ |
|
27 | + const type_delete = 'delete'; |
|
28 | + /** |
|
29 | + * the related item had something worth noting happen on it, but |
|
30 | + * only for the purposes of debugging problems |
|
31 | + */ |
|
32 | + const type_debug = 'debug'; |
|
33 | + /** |
|
34 | + * the related item had an error occur on it |
|
35 | + */ |
|
36 | + const type_error = 'error'; |
|
37 | + /** |
|
38 | + * the related item is regarding some gateway interaction, like an IPN |
|
39 | + * or request to process a payment |
|
40 | + */ |
|
41 | + const type_gateway = 'gateway'; |
|
42 | 42 | |
43 | - /** |
|
44 | - * private instance of the EEM_Change_Log object |
|
45 | - * |
|
46 | - * @access private |
|
47 | - * @var EEM_Change_Log $_instance |
|
48 | - */ |
|
49 | - protected static $_instance = null; |
|
43 | + /** |
|
44 | + * private instance of the EEM_Change_Log object |
|
45 | + * |
|
46 | + * @access private |
|
47 | + * @var EEM_Change_Log $_instance |
|
48 | + */ |
|
49 | + protected static $_instance = null; |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * constructor |
|
54 | - * |
|
55 | - * @access protected |
|
56 | - * @param null $timezone |
|
57 | - * @throws EE_Error |
|
58 | - */ |
|
59 | - protected function __construct($timezone = null) |
|
60 | - { |
|
61 | - global $current_user; |
|
62 | - $this->singular_item = esc_html__('Log', 'event_espresso'); |
|
63 | - $this->plural_item = esc_html__('Logs', 'event_espresso'); |
|
64 | - $this->_tables = array( |
|
65 | - 'Log' => new EE_Primary_Table('esp_log', 'LOG_ID'), |
|
66 | - ); |
|
67 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
68 | - $this->_fields = array( |
|
69 | - 'Log' => array( |
|
70 | - 'LOG_ID' => new EE_Primary_Key_Int_Field('LOG_ID', esc_html__('Log ID', 'event_espresso')), |
|
71 | - 'LOG_time' => new EE_Datetime_Field( |
|
72 | - 'LOG_time', |
|
73 | - esc_html__("Log Time", 'event_espresso'), |
|
74 | - false, |
|
75 | - EE_Datetime_Field::now |
|
76 | - ), |
|
77 | - 'OBJ_ID' => new EE_Foreign_Key_String_Field( |
|
78 | - 'OBJ_ID', |
|
79 | - esc_html__("Object ID (int or string)", 'event_espresso'), |
|
80 | - true, |
|
81 | - null, |
|
82 | - $models_this_can_attach_to |
|
83 | - ), |
|
84 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
85 | - 'OBJ_type', |
|
86 | - esc_html__("Object Type", 'event_espresso'), |
|
87 | - true, |
|
88 | - null, |
|
89 | - $models_this_can_attach_to |
|
90 | - ), |
|
91 | - 'LOG_type' => new EE_Plain_Text_Field( |
|
92 | - 'LOG_type', |
|
93 | - esc_html__("Type of log entry", "event_espresso"), |
|
94 | - false, |
|
95 | - self::type_debug |
|
96 | - ), |
|
97 | - 'LOG_message' => new EE_Maybe_Serialized_Text_Field( |
|
98 | - 'LOG_message', |
|
99 | - esc_html__("Log Message (body)", 'event_espresso'), |
|
100 | - true |
|
101 | - ), |
|
102 | - /* |
|
52 | + /** |
|
53 | + * constructor |
|
54 | + * |
|
55 | + * @access protected |
|
56 | + * @param null $timezone |
|
57 | + * @throws EE_Error |
|
58 | + */ |
|
59 | + protected function __construct($timezone = null) |
|
60 | + { |
|
61 | + global $current_user; |
|
62 | + $this->singular_item = esc_html__('Log', 'event_espresso'); |
|
63 | + $this->plural_item = esc_html__('Logs', 'event_espresso'); |
|
64 | + $this->_tables = array( |
|
65 | + 'Log' => new EE_Primary_Table('esp_log', 'LOG_ID'), |
|
66 | + ); |
|
67 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
68 | + $this->_fields = array( |
|
69 | + 'Log' => array( |
|
70 | + 'LOG_ID' => new EE_Primary_Key_Int_Field('LOG_ID', esc_html__('Log ID', 'event_espresso')), |
|
71 | + 'LOG_time' => new EE_Datetime_Field( |
|
72 | + 'LOG_time', |
|
73 | + esc_html__("Log Time", 'event_espresso'), |
|
74 | + false, |
|
75 | + EE_Datetime_Field::now |
|
76 | + ), |
|
77 | + 'OBJ_ID' => new EE_Foreign_Key_String_Field( |
|
78 | + 'OBJ_ID', |
|
79 | + esc_html__("Object ID (int or string)", 'event_espresso'), |
|
80 | + true, |
|
81 | + null, |
|
82 | + $models_this_can_attach_to |
|
83 | + ), |
|
84 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
85 | + 'OBJ_type', |
|
86 | + esc_html__("Object Type", 'event_espresso'), |
|
87 | + true, |
|
88 | + null, |
|
89 | + $models_this_can_attach_to |
|
90 | + ), |
|
91 | + 'LOG_type' => new EE_Plain_Text_Field( |
|
92 | + 'LOG_type', |
|
93 | + esc_html__("Type of log entry", "event_espresso"), |
|
94 | + false, |
|
95 | + self::type_debug |
|
96 | + ), |
|
97 | + 'LOG_message' => new EE_Maybe_Serialized_Text_Field( |
|
98 | + 'LOG_message', |
|
99 | + esc_html__("Log Message (body)", 'event_espresso'), |
|
100 | + true |
|
101 | + ), |
|
102 | + /* |
|
103 | 103 | * Note: when querying for a change log's user, the OBJ_ID and OBJ_type fields are used, |
104 | 104 | * not the LOG_wp_user field. E.g., |
105 | 105 | * `EEM_Change_Log::instance()->get_all(array(array('WP_User.ID'=>1)))` will actually return |
@@ -108,158 +108,158 @@ discard block |
||
108 | 108 | * If you want the latter, you can't use the model's magic joining. E.g, you would need to do |
109 | 109 | * `EEM_Change_Log::instance()->get_all(array(array('LOG_wp_user' => 1)))`. |
110 | 110 | */ |
111 | - 'LOG_wp_user' => new EE_WP_User_Field( |
|
112 | - 'LOG_wp_user', |
|
113 | - esc_html__("User who was logged in while this occurred", 'event_espresso'), |
|
114 | - true |
|
115 | - ), |
|
116 | - ), |
|
117 | - ); |
|
118 | - $this->_model_relations = array(); |
|
119 | - foreach ($models_this_can_attach_to as $model) { |
|
120 | - if ($model != 'Change_Log') { |
|
121 | - $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
122 | - } |
|
123 | - } |
|
124 | - //use completely custom caps for this |
|
125 | - $this->_cap_restriction_generators = false; |
|
126 | - //caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
|
127 | - foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
128 | - $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] |
|
129 | - = new EE_Return_None_Where_Conditions(); |
|
130 | - } |
|
131 | - parent::__construct($timezone); |
|
132 | - } |
|
111 | + 'LOG_wp_user' => new EE_WP_User_Field( |
|
112 | + 'LOG_wp_user', |
|
113 | + esc_html__("User who was logged in while this occurred", 'event_espresso'), |
|
114 | + true |
|
115 | + ), |
|
116 | + ), |
|
117 | + ); |
|
118 | + $this->_model_relations = array(); |
|
119 | + foreach ($models_this_can_attach_to as $model) { |
|
120 | + if ($model != 'Change_Log') { |
|
121 | + $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
122 | + } |
|
123 | + } |
|
124 | + //use completely custom caps for this |
|
125 | + $this->_cap_restriction_generators = false; |
|
126 | + //caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
|
127 | + foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
128 | + $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] |
|
129 | + = new EE_Return_None_Where_Conditions(); |
|
130 | + } |
|
131 | + parent::__construct($timezone); |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
|
136 | - * @param mixed $message array|string of the message you want to record |
|
137 | - * @param EE_Base_Class $related_model_obj |
|
138 | - * @return EE_Change_Log |
|
139 | - * @throws EE_Error |
|
140 | - */ |
|
141 | - public function log($log_type, $message, $related_model_obj) |
|
142 | - { |
|
143 | - if ($related_model_obj instanceof EE_Base_Class) { |
|
144 | - $obj_id = $related_model_obj->ID(); |
|
145 | - $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
|
146 | - } else { |
|
147 | - $obj_id = null; |
|
148 | - $obj_type = null; |
|
149 | - } |
|
150 | - /** @var EE_Change_Log $log */ |
|
151 | - $log = EE_Change_Log::new_instance(array( |
|
152 | - 'LOG_type' => $log_type, |
|
153 | - 'LOG_message' => $message, |
|
154 | - 'OBJ_ID' => $obj_id, |
|
155 | - 'OBJ_type' => $obj_type, |
|
156 | - )); |
|
157 | - $log->save(); |
|
158 | - return $log; |
|
159 | - } |
|
134 | + /** |
|
135 | + * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
|
136 | + * @param mixed $message array|string of the message you want to record |
|
137 | + * @param EE_Base_Class $related_model_obj |
|
138 | + * @return EE_Change_Log |
|
139 | + * @throws EE_Error |
|
140 | + */ |
|
141 | + public function log($log_type, $message, $related_model_obj) |
|
142 | + { |
|
143 | + if ($related_model_obj instanceof EE_Base_Class) { |
|
144 | + $obj_id = $related_model_obj->ID(); |
|
145 | + $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
|
146 | + } else { |
|
147 | + $obj_id = null; |
|
148 | + $obj_type = null; |
|
149 | + } |
|
150 | + /** @var EE_Change_Log $log */ |
|
151 | + $log = EE_Change_Log::new_instance(array( |
|
152 | + 'LOG_type' => $log_type, |
|
153 | + 'LOG_message' => $message, |
|
154 | + 'OBJ_ID' => $obj_id, |
|
155 | + 'OBJ_type' => $obj_type, |
|
156 | + )); |
|
157 | + $log->save(); |
|
158 | + return $log; |
|
159 | + } |
|
160 | 160 | |
161 | 161 | |
162 | - /** |
|
163 | - * Adds a gateway log for the specified object, given its ID and type |
|
164 | - * |
|
165 | - * @param string $message |
|
166 | - * @param mixed $related_obj_id |
|
167 | - * @param string $related_obj_type |
|
168 | - * @throws EE_Error |
|
169 | - * @return EE_Change_Log |
|
170 | - */ |
|
171 | - public function gateway_log($message, $related_obj_id, $related_obj_type) |
|
172 | - { |
|
173 | - if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
174 | - throw new EE_Error( |
|
175 | - sprintf( |
|
176 | - esc_html__( |
|
177 | - "'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", |
|
178 | - "event_espresso" |
|
179 | - ), |
|
180 | - $related_obj_type |
|
181 | - ) |
|
182 | - ); |
|
183 | - } |
|
184 | - /** @var EE_Change_Log $log */ |
|
185 | - $log = EE_Change_Log::new_instance(array( |
|
186 | - 'LOG_type' => EEM_Change_Log::type_gateway, |
|
187 | - 'LOG_message' => $message, |
|
188 | - 'OBJ_ID' => $related_obj_id, |
|
189 | - 'OBJ_type' => $related_obj_type, |
|
190 | - )); |
|
191 | - $log->save(); |
|
192 | - return $log; |
|
193 | - } |
|
162 | + /** |
|
163 | + * Adds a gateway log for the specified object, given its ID and type |
|
164 | + * |
|
165 | + * @param string $message |
|
166 | + * @param mixed $related_obj_id |
|
167 | + * @param string $related_obj_type |
|
168 | + * @throws EE_Error |
|
169 | + * @return EE_Change_Log |
|
170 | + */ |
|
171 | + public function gateway_log($message, $related_obj_id, $related_obj_type) |
|
172 | + { |
|
173 | + if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
174 | + throw new EE_Error( |
|
175 | + sprintf( |
|
176 | + esc_html__( |
|
177 | + "'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", |
|
178 | + "event_espresso" |
|
179 | + ), |
|
180 | + $related_obj_type |
|
181 | + ) |
|
182 | + ); |
|
183 | + } |
|
184 | + /** @var EE_Change_Log $log */ |
|
185 | + $log = EE_Change_Log::new_instance(array( |
|
186 | + 'LOG_type' => EEM_Change_Log::type_gateway, |
|
187 | + 'LOG_message' => $message, |
|
188 | + 'OBJ_ID' => $related_obj_id, |
|
189 | + 'OBJ_type' => $related_obj_type, |
|
190 | + )); |
|
191 | + $log->save(); |
|
192 | + return $log; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | |
196 | - /** |
|
197 | - * Just gets the bare-bones wpdb results as an array in cases where efficiency is essential |
|
198 | - * |
|
199 | - * @param array $query_params @see EEM_Base::get_all |
|
200 | - * @return array of arrays |
|
201 | - * @throws EE_Error |
|
202 | - */ |
|
203 | - public function get_all_efficiently($query_params) |
|
204 | - { |
|
205 | - return $this->_get_all_wpdb_results($query_params); |
|
206 | - } |
|
196 | + /** |
|
197 | + * Just gets the bare-bones wpdb results as an array in cases where efficiency is essential |
|
198 | + * |
|
199 | + * @param array $query_params @see EEM_Base::get_all |
|
200 | + * @return array of arrays |
|
201 | + * @throws EE_Error |
|
202 | + */ |
|
203 | + public function get_all_efficiently($query_params) |
|
204 | + { |
|
205 | + return $this->_get_all_wpdb_results($query_params); |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | - /** |
|
210 | - * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
211 | - * models after this, they may be out-of-sync with the database |
|
212 | - * |
|
213 | - * @param DateTime $datetime |
|
214 | - * @return false|int |
|
215 | - * @throws EE_Error |
|
216 | - */ |
|
217 | - public function delete_gateway_logs_older_than(DateTime $datetime) |
|
218 | - { |
|
219 | - global $wpdb; |
|
220 | - return $wpdb->query( |
|
221 | - $wpdb->prepare( |
|
222 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
223 | - EEM_Change_Log::type_gateway, |
|
224 | - $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
225 | - ) |
|
226 | - ); |
|
227 | - } |
|
209 | + /** |
|
210 | + * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
211 | + * models after this, they may be out-of-sync with the database |
|
212 | + * |
|
213 | + * @param DateTime $datetime |
|
214 | + * @return false|int |
|
215 | + * @throws EE_Error |
|
216 | + */ |
|
217 | + public function delete_gateway_logs_older_than(DateTime $datetime) |
|
218 | + { |
|
219 | + global $wpdb; |
|
220 | + return $wpdb->query( |
|
221 | + $wpdb->prepare( |
|
222 | + 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
223 | + EEM_Change_Log::type_gateway, |
|
224 | + $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
225 | + ) |
|
226 | + ); |
|
227 | + } |
|
228 | 228 | |
229 | 229 | |
230 | - /** |
|
231 | - * Returns the map of type to pretty label for identifiers used for `LOG_type`. Client code can register their own |
|
232 | - * map vai the given filter. |
|
233 | - * |
|
234 | - * @return array |
|
235 | - */ |
|
236 | - public static function get_pretty_label_map_for_registered_types() |
|
237 | - { |
|
238 | - return apply_filters( |
|
239 | - 'FHEE__EEM_Change_Log__get_pretty_label_map_for_registered_types', |
|
240 | - array( |
|
241 | - self::type_create=> esc_html__("Create", "event_espresso"), |
|
242 | - self::type_update=> esc_html__("Update", "event_espresso"), |
|
243 | - self::type_delete => esc_html__("Delete", "event_espresso"), |
|
244 | - self::type_debug=> esc_html__("Debug", "event_espresso"), |
|
245 | - self::type_error=> esc_html__("Error", "event_espresso"), |
|
246 | - self::type_gateway=> esc_html__("Gateway Interaction (IPN or Direct Payment)", 'event_espresso') |
|
247 | - ) |
|
248 | - ); |
|
249 | - } |
|
230 | + /** |
|
231 | + * Returns the map of type to pretty label for identifiers used for `LOG_type`. Client code can register their own |
|
232 | + * map vai the given filter. |
|
233 | + * |
|
234 | + * @return array |
|
235 | + */ |
|
236 | + public static function get_pretty_label_map_for_registered_types() |
|
237 | + { |
|
238 | + return apply_filters( |
|
239 | + 'FHEE__EEM_Change_Log__get_pretty_label_map_for_registered_types', |
|
240 | + array( |
|
241 | + self::type_create=> esc_html__("Create", "event_espresso"), |
|
242 | + self::type_update=> esc_html__("Update", "event_espresso"), |
|
243 | + self::type_delete => esc_html__("Delete", "event_espresso"), |
|
244 | + self::type_debug=> esc_html__("Debug", "event_espresso"), |
|
245 | + self::type_error=> esc_html__("Error", "event_espresso"), |
|
246 | + self::type_gateway=> esc_html__("Gateway Interaction (IPN or Direct Payment)", 'event_espresso') |
|
247 | + ) |
|
248 | + ); |
|
249 | + } |
|
250 | 250 | |
251 | 251 | |
252 | - /** |
|
253 | - * Return the pretty (localized) label for the given log type identifier. |
|
254 | - * @param string $type_identifier |
|
255 | - * @return string |
|
256 | - */ |
|
257 | - public static function get_pretty_label_for_type($type_identifier) |
|
258 | - { |
|
259 | - $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
|
260 | - //we fallback to the incoming type identifier if there is no localized label for it. |
|
261 | - return isset($type_identifier_map[$type_identifier]) |
|
262 | - ? $type_identifier_map[$type_identifier] |
|
263 | - : $type_identifier; |
|
264 | - } |
|
252 | + /** |
|
253 | + * Return the pretty (localized) label for the given log type identifier. |
|
254 | + * @param string $type_identifier |
|
255 | + * @return string |
|
256 | + */ |
|
257 | + public static function get_pretty_label_for_type($type_identifier) |
|
258 | + { |
|
259 | + $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
|
260 | + //we fallback to the incoming type identifier if there is no localized label for it. |
|
261 | + return isset($type_identifier_map[$type_identifier]) |
|
262 | + ? $type_identifier_map[$type_identifier] |
|
263 | + : $type_identifier; |
|
264 | + } |
|
265 | 265 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | ), |
116 | 116 | ), |
117 | 117 | ); |
118 | - $this->_model_relations = array(); |
|
118 | + $this->_model_relations = array(); |
|
119 | 119 | foreach ($models_this_can_attach_to as $model) { |
120 | 120 | if ($model != 'Change_Log') { |
121 | 121 | $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function gateway_log($message, $related_obj_id, $related_obj_type) |
172 | 172 | { |
173 | - if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
173 | + if ( ! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
174 | 174 | throw new EE_Error( |
175 | 175 | sprintf( |
176 | 176 | esc_html__( |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | global $wpdb; |
220 | 220 | return $wpdb->query( |
221 | 221 | $wpdb->prepare( |
222 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
222 | + 'DELETE FROM '.$this->table().' WHERE LOG_type = %s AND LOG_time < %s', |
|
223 | 223 | EEM_Change_Log::type_gateway, |
224 | 224 | $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
225 | 225 | ) |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
2 | 2 | /** |
3 | 3 | * |
4 | 4 | * EEH_Line_Item |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @return boolean success |
46 | 46 | * @throws \EE_Error |
47 | 47 | */ |
48 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
49 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
48 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
49 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
50 | 50 | $line_item = EE_Line_Item::new_instance(array( |
51 | 51 | 'LIN_name' => $name, |
52 | 52 | 'LIN_desc' => $description, |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'LIN_quantity' => $quantity, |
55 | 55 | 'LIN_percent' => null, |
56 | 56 | 'LIN_is_taxable' => $taxable, |
57 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
57 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
58 | 58 | 'LIN_total' => (float) $unit_price * (int) $quantity, |
59 | 59 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
60 | 60 | 'LIN_code' => $code, |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $line_item, |
65 | 65 | $parent_line_item |
66 | 66 | ); |
67 | - return self::add_item( $parent_line_item, $line_item ); |
|
67 | + return self::add_item($parent_line_item, $line_item); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return boolean success |
87 | 87 | * @throws \EE_Error |
88 | 88 | */ |
89 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
89 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
90 | 90 | $line_item = EE_Line_Item::new_instance(array( |
91 | 91 | 'LIN_name' => $name, |
92 | 92 | 'LIN_desc' => $description, |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'LIN_percent' => $percentage_amount, |
95 | 95 | 'LIN_quantity' => NULL, |
96 | 96 | 'LIN_is_taxable' => $taxable, |
97 | - 'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ), |
|
97 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
98 | 98 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
99 | 99 | 'LIN_parent' => $parent_line_item->ID() |
100 | 100 | )); |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @return \EE_Line_Item |
124 | 124 | * @throws \EE_Error |
125 | 125 | */ |
126 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
127 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
128 | - throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) ); |
|
126 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
127 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
128 | + throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
129 | 129 | } |
130 | 130 | // either increment the qty for an existing ticket |
131 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
131 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
132 | 132 | // or add a new one |
133 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
134 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
133 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
134 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
135 | 135 | } |
136 | 136 | $total_line_item->recalculate_total_including_taxes(); |
137 | 137 | return $line_item; |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @return \EE_Line_Item |
148 | 148 | * @throws \EE_Error |
149 | 149 | */ |
150 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
150 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
151 | 151 | $line_item = null; |
152 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
153 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
154 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
152 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
153 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
154 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
155 | 155 | if ( |
156 | 156 | $ticket_line_item instanceof EE_Line_Item |
157 | 157 | && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | - if ( $line_item instanceof EE_Line_Item ) { |
|
165 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
164 | + if ($line_item instanceof EE_Line_Item) { |
|
165 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
166 | 166 | return $line_item; |
167 | 167 | } |
168 | 168 | return null; |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | * @throws \EE_Error |
181 | 181 | */ |
182 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
183 | - if( ! $line_item->is_percent() ) { |
|
182 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
183 | + if ( ! $line_item->is_percent()) { |
|
184 | 184 | $qty += $line_item->quantity(); |
185 | - $line_item->set_quantity( $qty ); |
|
186 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
185 | + $line_item->set_quantity($qty); |
|
186 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
187 | 187 | $line_item->save(); |
188 | 188 | } |
189 | - foreach( $line_item->children() as $child ) { |
|
190 | - if( $child->is_sub_line_item() ) { |
|
191 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
189 | + foreach ($line_item->children() as $child) { |
|
190 | + if ($child->is_sub_line_item()) { |
|
191 | + EEH_Line_Item::update_quantity($child, $qty); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | * @return void |
205 | 205 | * @throws \EE_Error |
206 | 206 | */ |
207 | - public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
208 | - if( ! $line_item->is_percent() ) { |
|
207 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
208 | + if ( ! $line_item->is_percent()) { |
|
209 | 209 | $qty = $line_item->quantity() - $qty; |
210 | - $qty = max( $qty, 0 ); |
|
211 | - $line_item->set_quantity( $qty ); |
|
212 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
210 | + $qty = max($qty, 0); |
|
211 | + $line_item->set_quantity($qty); |
|
212 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
213 | 213 | $line_item->save(); |
214 | 214 | } |
215 | - foreach( $line_item->children() as $child ) { |
|
216 | - if( $child->is_sub_line_item() ) { |
|
217 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
215 | + foreach ($line_item->children() as $child) { |
|
216 | + if ($child->is_sub_line_item()) { |
|
217 | + EEH_Line_Item::update_quantity($child, $qty); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | * @param int $new_quantity |
230 | 230 | * @throws \EE_Error |
231 | 231 | */ |
232 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
233 | - if( ! $line_item->is_percent() ) { |
|
234 | - $line_item->set_quantity( $new_quantity ); |
|
235 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
232 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
233 | + if ( ! $line_item->is_percent()) { |
|
234 | + $line_item->set_quantity($new_quantity); |
|
235 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
236 | 236 | $line_item->save(); |
237 | 237 | } |
238 | - foreach( $line_item->children() as $child ) { |
|
239 | - if( $child->is_sub_line_item() ) { |
|
240 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
238 | + foreach ($line_item->children() as $child) { |
|
239 | + if ($child->is_sub_line_item()) { |
|
240 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
@@ -252,43 +252,43 @@ discard block |
||
252 | 252 | * @return \EE_Line_Item |
253 | 253 | * @throws \EE_Error |
254 | 254 | */ |
255 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
255 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
256 | 256 | $datetimes = $ticket->datetimes(); |
257 | - $first_datetime = reset( $datetimes ); |
|
258 | - if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) { |
|
257 | + $first_datetime = reset($datetimes); |
|
258 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
259 | 259 | $first_datetime_name = $first_datetime->event()->name(); |
260 | 260 | } else { |
261 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
261 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
262 | 262 | } |
263 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
263 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
264 | 264 | // get event subtotal line |
265 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
265 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
266 | 266 | // add $ticket to cart |
267 | - $line_item = EE_Line_Item::new_instance( array( |
|
267 | + $line_item = EE_Line_Item::new_instance(array( |
|
268 | 268 | 'LIN_name' => $ticket->name(), |
269 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
269 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description().' '.$event : $event, |
|
270 | 270 | 'LIN_unit_price' => $ticket->price(), |
271 | 271 | 'LIN_quantity' => $qty, |
272 | 272 | 'LIN_is_taxable' => $ticket->taxable(), |
273 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
273 | + 'LIN_order' => count($events_sub_total->children()), |
|
274 | 274 | 'LIN_total' => $ticket->price() * $qty, |
275 | 275 | 'LIN_type' => EEM_Line_Item::type_line_item, |
276 | 276 | 'OBJ_ID' => $ticket->ID(), |
277 | 277 | 'OBJ_type' => 'Ticket' |
278 | - ) ); |
|
278 | + )); |
|
279 | 279 | $line_item = apply_filters( |
280 | 280 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
281 | 281 | $line_item |
282 | 282 | ); |
283 | - $events_sub_total->add_child_line_item( $line_item ); |
|
283 | + $events_sub_total->add_child_line_item($line_item); |
|
284 | 284 | //now add the sub-line items |
285 | 285 | $running_total_for_ticket = 0; |
286 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
286 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
287 | 287 | $sign = $price->is_discount() ? -1 : 1; |
288 | 288 | $price_total = $price->is_percent() |
289 | 289 | ? $running_total_for_ticket * $price->amount() / 100 |
290 | 290 | : $price->amount() * $qty; |
291 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
291 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
292 | 292 | 'LIN_name' => $price->name(), |
293 | 293 | 'LIN_desc' => $price->desc(), |
294 | 294 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -298,18 +298,18 @@ discard block |
||
298 | 298 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
299 | 299 | 'OBJ_ID' => $price->ID(), |
300 | 300 | 'OBJ_type' => 'Price' |
301 | - ) ); |
|
301 | + )); |
|
302 | 302 | $sub_line_item = apply_filters( |
303 | 303 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
304 | 304 | $sub_line_item |
305 | 305 | ); |
306 | - if ( $price->is_percent() ) { |
|
307 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
306 | + if ($price->is_percent()) { |
|
307 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
308 | 308 | } else { |
309 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
309 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
310 | 310 | } |
311 | 311 | $running_total_for_ticket += $price_total; |
312 | - $line_item->add_child_line_item( $sub_line_item ); |
|
312 | + $line_item->add_child_line_item($sub_line_item); |
|
313 | 313 | } |
314 | 314 | return $line_item; |
315 | 315 | } |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | * @return boolean |
330 | 330 | * @throws \EE_Error |
331 | 331 | */ |
332 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
333 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
334 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
332 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
333 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
334 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
335 | 335 | $success = $pre_tax_subtotal->add_child_line_item($item); |
336 | - }else{ |
|
336 | + } else { |
|
337 | 337 | return FALSE; |
338 | 338 | } |
339 | 339 | $total_line_item->recalculate_total_including_taxes(); |
@@ -352,34 +352,34 @@ discard block |
||
352 | 352 | * @return bool success |
353 | 353 | * @throws \EE_Error |
354 | 354 | */ |
355 | - public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
355 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
356 | 356 | // validate incoming line_item |
357 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
357 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
358 | 358 | throw new EE_Error( |
359 | 359 | sprintf( |
360 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
360 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
361 | 361 | $ticket_line_item->type() |
362 | 362 | ) |
363 | 363 | ); |
364 | 364 | } |
365 | - if ( $ticket_line_item->quantity() < $qty ) { |
|
365 | + if ($ticket_line_item->quantity() < $qty) { |
|
366 | 366 | throw new EE_Error( |
367 | 367 | sprintf( |
368 | - __( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ), |
|
368 | + __('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'), |
|
369 | 369 | $qty, |
370 | 370 | $ticket_line_item->quantity() |
371 | 371 | ) |
372 | 372 | ); |
373 | 373 | } |
374 | 374 | // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
375 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty ); |
|
376 | - foreach( $ticket_line_item->children() as $child_line_item ) { |
|
377 | - if( |
|
375 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
376 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
377 | + if ( |
|
378 | 378 | $child_line_item->is_sub_line_item() |
379 | 379 | && ! $child_line_item->is_percent() |
380 | 380 | && ! $child_line_item->is_cancellation() |
381 | 381 | ) { |
382 | - $child_line_item->set_quantity( $child_line_item->quantity() - $qty ); |
|
382 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | // get cancellation sub line item |
@@ -387,37 +387,37 @@ discard block |
||
387 | 387 | $ticket_line_item, |
388 | 388 | EEM_Line_Item::type_cancellation |
389 | 389 | ); |
390 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
390 | + $cancellation_line_item = reset($cancellation_line_item); |
|
391 | 391 | // verify that this ticket was indeed previously cancelled |
392 | - if ( $cancellation_line_item instanceof EE_Line_Item ) { |
|
392 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
393 | 393 | // increment cancelled quantity |
394 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty ); |
|
394 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
395 | 395 | } else { |
396 | 396 | // create cancellation sub line item |
397 | - $cancellation_line_item = EE_Line_Item::new_instance( array( |
|
398 | - 'LIN_name' => __( 'Cancellation', 'event_espresso' ), |
|
397 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
398 | + 'LIN_name' => __('Cancellation', 'event_espresso'), |
|
399 | 399 | 'LIN_desc' => sprintf( |
400 | - _x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ), |
|
400 | + _x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'), |
|
401 | 401 | $ticket_line_item->name(), |
402 | - current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) |
|
402 | + current_time(get_option('date_format').' '.get_option('time_format')) |
|
403 | 403 | ), |
404 | 404 | 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
405 | 405 | 'LIN_quantity' => $qty, |
406 | 406 | 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
407 | - 'LIN_order' => count( $ticket_line_item->children() ), |
|
407 | + 'LIN_order' => count($ticket_line_item->children()), |
|
408 | 408 | 'LIN_total' => 0, // $ticket_line_item->unit_price() |
409 | 409 | 'LIN_type' => EEM_Line_Item::type_cancellation, |
410 | - ) ); |
|
411 | - $ticket_line_item->add_child_line_item( $cancellation_line_item ); |
|
410 | + )); |
|
411 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
412 | 412 | } |
413 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
413 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
414 | 414 | // decrement parent line item quantity |
415 | 415 | $event_line_item = $ticket_line_item->parent(); |
416 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
417 | - $event_line_item->set_quantity( $event_line_item->quantity() - $qty ); |
|
416 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
417 | + $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
418 | 418 | $event_line_item->save(); |
419 | 419 | } |
420 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
420 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
421 | 421 | return true; |
422 | 422 | } |
423 | 423 | return false; |
@@ -435,12 +435,12 @@ discard block |
||
435 | 435 | * @return bool success |
436 | 436 | * @throws \EE_Error |
437 | 437 | */ |
438 | - public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
438 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
439 | 439 | // validate incoming line_item |
440 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
440 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
441 | 441 | throw new EE_Error( |
442 | 442 | sprintf( |
443 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
443 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
444 | 444 | $ticket_line_item->type() |
445 | 445 | ) |
446 | 446 | ); |
@@ -450,42 +450,42 @@ discard block |
||
450 | 450 | $ticket_line_item, |
451 | 451 | EEM_Line_Item::type_cancellation |
452 | 452 | ); |
453 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
453 | + $cancellation_line_item = reset($cancellation_line_item); |
|
454 | 454 | // verify that this ticket was indeed previously cancelled |
455 | - if ( ! $cancellation_line_item instanceof EE_Line_Item ) { |
|
455 | + if ( ! $cancellation_line_item instanceof EE_Line_Item) { |
|
456 | 456 | return false; |
457 | 457 | } |
458 | - if ( $cancellation_line_item->quantity() > $qty ) { |
|
458 | + if ($cancellation_line_item->quantity() > $qty) { |
|
459 | 459 | // decrement cancelled quantity |
460 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
461 | - } else if ( $cancellation_line_item->quantity() == $qty ) { |
|
460 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
461 | + } else if ($cancellation_line_item->quantity() == $qty) { |
|
462 | 462 | // decrement cancelled quantity in case anyone still has the object kicking around |
463 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
463 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
464 | 464 | // delete because quantity will end up as 0 |
465 | 465 | $cancellation_line_item->delete(); |
466 | 466 | // and attempt to destroy the object, |
467 | 467 | // even though PHP won't actually destroy it until it needs the memory |
468 | - unset( $cancellation_line_item ); |
|
468 | + unset($cancellation_line_item); |
|
469 | 469 | } else { |
470 | 470 | // what ?!?! negative quantity ?!?! |
471 | 471 | throw new EE_Error( |
472 | 472 | sprintf( |
473 | - __( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
474 | - 'event_espresso' ), |
|
473 | + __('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
474 | + 'event_espresso'), |
|
475 | 475 | $qty, |
476 | 476 | $cancellation_line_item->quantity() |
477 | 477 | ) |
478 | 478 | ); |
479 | 479 | } |
480 | 480 | // increment ticket quantity |
481 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty ); |
|
482 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
481 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
482 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
483 | 483 | // increment parent line item quantity |
484 | 484 | $event_line_item = $ticket_line_item->parent(); |
485 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
486 | - $event_line_item->set_quantity( $event_line_item->quantity() + $qty ); |
|
485 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
486 | + $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
487 | 487 | } |
488 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
488 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
489 | 489 | return true; |
490 | 490 | } |
491 | 491 | return false; |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param EE_Line_Item $line_item |
501 | 501 | * @return \EE_Line_Item |
502 | 502 | */ |
503 | - public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){ |
|
504 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item ); |
|
503 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) { |
|
504 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
505 | 505 | return $grand_total_line_item->recalculate_total_including_taxes(); |
506 | 506 | } |
507 | 507 | |
@@ -514,11 +514,11 @@ discard block |
||
514 | 514 | * @return \EE_Line_Item |
515 | 515 | * @throws \EE_Error |
516 | 516 | */ |
517 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
518 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
517 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
518 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
519 | 519 | return $pre_tax_subtotal instanceof EE_Line_Item |
520 | 520 | ? $pre_tax_subtotal |
521 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
521 | + : self::create_pre_tax_subtotal($total_line_item); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -530,9 +530,9 @@ discard block |
||
530 | 530 | * @return \EE_Line_Item |
531 | 531 | * @throws \EE_Error |
532 | 532 | */ |
533 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
534 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
535 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
533 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
534 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
535 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | |
@@ -545,12 +545,12 @@ discard block |
||
545 | 545 | * @return void |
546 | 546 | * @throws \EE_Error |
547 | 547 | */ |
548 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
549 | - if( $transaction ){ |
|
548 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
549 | + if ($transaction) { |
|
550 | 550 | /** @type EEM_Transaction $EEM_Transaction */ |
551 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
552 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
553 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
551 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
552 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
553 | + $line_item->set_TXN_ID($TXN_ID); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | * @return \EE_Line_Item of type total |
566 | 566 | * @throws \EE_Error |
567 | 567 | */ |
568 | - public static function create_total_line_item( $transaction = NULL ){ |
|
569 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
568 | + public static function create_total_line_item($transaction = NULL) { |
|
569 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
570 | 570 | 'LIN_code' => 'total', |
571 | 571 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
572 | 572 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
577 | 577 | $total_line_item |
578 | 578 | ); |
579 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
580 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
581 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
579 | + self::set_TXN_ID($total_line_item, $transaction); |
|
580 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
581 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
582 | 582 | return $total_line_item; |
583 | 583 | } |
584 | 584 | |
@@ -592,19 +592,19 @@ discard block |
||
592 | 592 | * @return EE_Line_Item |
593 | 593 | * @throws \EE_Error |
594 | 594 | */ |
595 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
596 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
595 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
596 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
597 | 597 | 'LIN_code' => 'pre-tax-subtotal', |
598 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
598 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
599 | 599 | 'LIN_type' => EEM_Line_Item::type_sub_total |
600 | - ) ); |
|
600 | + )); |
|
601 | 601 | $pre_tax_line_item = apply_filters( |
602 | 602 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
603 | 603 | $pre_tax_line_item |
604 | 604 | ); |
605 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
606 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
607 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
605 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
606 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
607 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
608 | 608 | return $pre_tax_line_item; |
609 | 609 | } |
610 | 610 | |
@@ -619,21 +619,21 @@ discard block |
||
619 | 619 | * @return EE_Line_Item |
620 | 620 | * @throws \EE_Error |
621 | 621 | */ |
622 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
622 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
623 | 623 | $tax_line_item = EE_Line_Item::new_instance(array( |
624 | 624 | 'LIN_code' => 'taxes', |
625 | 625 | 'LIN_name' => __('Taxes', 'event_espresso'), |
626 | 626 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
627 | - 'LIN_order' => 1000,//this should always come last |
|
627 | + 'LIN_order' => 1000, //this should always come last |
|
628 | 628 | )); |
629 | 629 | $tax_line_item = apply_filters( |
630 | 630 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
631 | 631 | $tax_line_item |
632 | 632 | ); |
633 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
634 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
633 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
634 | + $total_line_item->add_child_line_item($tax_line_item); |
|
635 | 635 | //and lastly, add the actual taxes |
636 | - self::apply_taxes( $total_line_item ); |
|
636 | + self::apply_taxes($total_line_item); |
|
637 | 637 | return $tax_line_item; |
638 | 638 | } |
639 | 639 | |
@@ -648,11 +648,11 @@ discard block |
||
648 | 648 | * @return EE_Line_Item |
649 | 649 | * @throws \EE_Error |
650 | 650 | */ |
651 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
651 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
652 | 652 | $event_line_item = EE_Line_Item::new_instance(array( |
653 | - 'LIN_code' => self::get_event_code( $event ), |
|
654 | - 'LIN_name' => self::get_event_name( $event ), |
|
655 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
653 | + 'LIN_code' => self::get_event_code($event), |
|
654 | + 'LIN_name' => self::get_event_name($event), |
|
655 | + 'LIN_desc' => self::get_event_desc($event), |
|
656 | 656 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
657 | 657 | 'OBJ_type' => 'Event', |
658 | 658 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -661,8 +661,8 @@ discard block |
||
661 | 661 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
662 | 662 | $event_line_item |
663 | 663 | ); |
664 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
665 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
664 | + self::set_TXN_ID($event_line_item, $transaction); |
|
665 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
666 | 666 | return $event_line_item; |
667 | 667 | } |
668 | 668 | |
@@ -675,8 +675,8 @@ discard block |
||
675 | 675 | * @return string |
676 | 676 | * @throws \EE_Error |
677 | 677 | */ |
678 | - public static function get_event_code( $event ) { |
|
679 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
678 | + public static function get_event_code($event) { |
|
679 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | /** |
@@ -684,8 +684,8 @@ discard block |
||
684 | 684 | * @param EE_Event $event |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public static function get_event_name( $event ) { |
|
688 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
687 | + public static function get_event_name($event) { |
|
688 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | * @param EE_Event $event |
694 | 694 | * @return string |
695 | 695 | */ |
696 | - public static function get_event_desc( $event ) { |
|
696 | + public static function get_event_desc($event) { |
|
697 | 697 | return $event instanceof EE_Event ? $event->short_description() : ''; |
698 | 698 | } |
699 | 699 | |
@@ -707,27 +707,27 @@ discard block |
||
707 | 707 | * @throws \EE_Error |
708 | 708 | * @return EE_Line_Item |
709 | 709 | */ |
710 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
710 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
711 | 711 | $first_datetime = $ticket->first_datetime(); |
712 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
712 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
713 | 713 | throw new EE_Error( |
714 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
714 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
715 | 715 | ); |
716 | 716 | } |
717 | 717 | $event = $first_datetime->event(); |
718 | - if ( ! $event instanceof EE_Event ) { |
|
718 | + if ( ! $event instanceof EE_Event) { |
|
719 | 719 | throw new EE_Error( |
720 | 720 | sprintf( |
721 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
721 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
722 | 722 | $ticket->ID() |
723 | 723 | ) |
724 | 724 | ); |
725 | 725 | } |
726 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
727 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
726 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
727 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
728 | 728 | throw new EE_Error( |
729 | 729 | sprintf( |
730 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
730 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
731 | 731 | $ticket->ID(), |
732 | 732 | $grand_total->ID() |
733 | 733 | ) |
@@ -746,31 +746,31 @@ discard block |
||
746 | 746 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
747 | 747 | * @throws \EE_Error |
748 | 748 | */ |
749 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
749 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
750 | 750 | /** @type EE_Event $event */ |
751 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
751 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
752 | 752 | $event_line_item = NULL; |
753 | 753 | $found = false; |
754 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
754 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
755 | 755 | // default event subtotal, we should only ever find this the first time this method is called |
756 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
756 | + if ( ! $event_line_item->OBJ_ID()) { |
|
757 | 757 | // let's use this! but first... set the event details |
758 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
758 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
759 | 759 | $found = true; |
760 | 760 | break; |
761 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
761 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
762 | 762 | // found existing line item for this event in the cart, so break out of loop and use this one |
763 | 763 | $found = true; |
764 | 764 | break; |
765 | 765 | } |
766 | 766 | } |
767 | - if ( ! $found ) { |
|
767 | + if ( ! $found) { |
|
768 | 768 | //there is no event sub-total yet, so add it |
769 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
769 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
770 | 770 | // create a new "event" subtotal below that |
771 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
771 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
772 | 772 | // and set the event details |
773 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
773 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
774 | 774 | } |
775 | 775 | return $event_line_item; |
776 | 776 | } |
@@ -791,13 +791,13 @@ discard block |
||
791 | 791 | EE_Event $event, |
792 | 792 | $transaction = null |
793 | 793 | ) { |
794 | - if ( $event instanceof EE_Event ) { |
|
795 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
796 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
797 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
798 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
794 | + if ($event instanceof EE_Event) { |
|
795 | + $event_line_item->set_code(self::get_event_code($event)); |
|
796 | + $event_line_item->set_name(self::get_event_name($event)); |
|
797 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
798 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
799 | 799 | } |
800 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
800 | + self::set_TXN_ID($event_line_item, $transaction); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | |
@@ -810,19 +810,19 @@ discard block |
||
810 | 810 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
811 | 811 | * @throws \EE_Error |
812 | 812 | */ |
813 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
813 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
814 | 814 | /** @type EEM_Price $EEM_Price */ |
815 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
815 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
816 | 816 | // get array of taxes via Price Model |
817 | 817 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
818 | - ksort( $ordered_taxes ); |
|
819 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
818 | + ksort($ordered_taxes); |
|
819 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
820 | 820 | //just to be safe, remove its old tax line items |
821 | 821 | $taxes_line_item->delete_children_line_items(); |
822 | 822 | //loop thru taxes |
823 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
824 | - foreach ( $taxes as $tax ) { |
|
825 | - if ( $tax instanceof EE_Price ) { |
|
823 | + foreach ($ordered_taxes as $order => $taxes) { |
|
824 | + foreach ($taxes as $tax) { |
|
825 | + if ($tax instanceof EE_Price) { |
|
826 | 826 | $tax_line_item = EE_Line_Item::new_instance( |
827 | 827 | array( |
828 | 828 | 'LIN_name' => $tax->name(), |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
841 | 841 | $tax_line_item |
842 | 842 | ); |
843 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
843 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
844 | 844 | } |
845 | 845 | } |
846 | 846 | } |
@@ -857,10 +857,10 @@ discard block |
||
857 | 857 | * @return float |
858 | 858 | * @throws \EE_Error |
859 | 859 | */ |
860 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
861 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
862 | - if( ! $taxes_subtotal->children()){ |
|
863 | - self::apply_taxes( $total_line_item ); |
|
860 | + public static function ensure_taxes_applied($total_line_item) { |
|
861 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
862 | + if ( ! $taxes_subtotal->children()) { |
|
863 | + self::apply_taxes($total_line_item); |
|
864 | 864 | } |
865 | 865 | return $taxes_subtotal->total(); |
866 | 866 | } |
@@ -874,16 +874,16 @@ discard block |
||
874 | 874 | * @return bool |
875 | 875 | * @throws \EE_Error |
876 | 876 | */ |
877 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
877 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
878 | 878 | $deleted = 0; |
879 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
880 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
881 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
882 | - if ( $child_line_item->ID() ) { |
|
879 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
880 | + if ($child_line_item instanceof EE_Line_Item) { |
|
881 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
882 | + if ($child_line_item->ID()) { |
|
883 | 883 | $child_line_item->delete(); |
884 | - unset( $child_line_item ); |
|
884 | + unset($child_line_item); |
|
885 | 885 | } else { |
886 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
886 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
887 | 887 | } |
888 | 888 | $deleted++; |
889 | 889 | } |
@@ -905,9 +905,9 @@ discard block |
||
905 | 905 | * @param array|bool|string $line_item_codes |
906 | 906 | * @return int number of items successfully removed |
907 | 907 | */ |
908 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
908 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
909 | 909 | |
910 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
910 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
911 | 911 | EE_Error::doing_it_wrong( |
912 | 912 | 'EEH_Line_Item::delete_items', |
913 | 913 | __( |
@@ -917,20 +917,20 @@ discard block |
||
917 | 917 | '4.6.18' |
918 | 918 | ); |
919 | 919 | } |
920 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
920 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
921 | 921 | |
922 | 922 | // check if only a single line_item_id was passed |
923 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
923 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
924 | 924 | // place single line_item_id in an array to appear as multiple line_item_ids |
925 | - $line_item_codes = array ( $line_item_codes ); |
|
925 | + $line_item_codes = array($line_item_codes); |
|
926 | 926 | } |
927 | 927 | $removals = 0; |
928 | 928 | // cycle thru line_item_ids |
929 | - foreach ( $line_item_codes as $line_item_id ) { |
|
929 | + foreach ($line_item_codes as $line_item_id) { |
|
930 | 930 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
931 | 931 | } |
932 | 932 | |
933 | - if ( $removals > 0 ) { |
|
933 | + if ($removals > 0) { |
|
934 | 934 | $total_line_item->recalculate_taxes_and_tax_total(); |
935 | 935 | return $removals; |
936 | 936 | } else { |
@@ -963,33 +963,33 @@ discard block |
||
963 | 963 | $code = null, |
964 | 964 | $add_to_existing_line_item = false |
965 | 965 | ) { |
966 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
966 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
967 | 967 | $taxable_total = $total_line_item->taxable_total(); |
968 | 968 | |
969 | - if( $add_to_existing_line_item ) { |
|
970 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
969 | + if ($add_to_existing_line_item) { |
|
970 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
971 | 971 | EEM_Line_Item::instance()->delete( |
972 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
972 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
973 | 973 | ); |
974 | 974 | } else { |
975 | 975 | $new_tax = null; |
976 | 976 | $tax_subtotal->delete_children_line_items(); |
977 | 977 | } |
978 | - if( $new_tax ) { |
|
979 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
980 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
978 | + if ($new_tax) { |
|
979 | + $new_tax->set_total($new_tax->total() + $amount); |
|
980 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
981 | 981 | } else { |
982 | 982 | //no existing tax item. Create it |
983 | - $new_tax = EE_Line_Item::new_instance( array( |
|
983 | + $new_tax = EE_Line_Item::new_instance(array( |
|
984 | 984 | 'TXN_ID' => $total_line_item->TXN_ID(), |
985 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
985 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
986 | 986 | 'LIN_desc' => $description ? $description : '', |
987 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
987 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
988 | 988 | 'LIN_total' => $amount, |
989 | 989 | 'LIN_parent' => $tax_subtotal->ID(), |
990 | 990 | 'LIN_type' => EEM_Line_Item::type_tax, |
991 | 991 | 'LIN_code' => $code |
992 | - ) ); |
|
992 | + )); |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | $new_tax = apply_filters( |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | $total_line_item |
999 | 999 | ); |
1000 | 1000 | $new_tax->save(); |
1001 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
1001 | + $tax_subtotal->set_total($new_tax->total()); |
|
1002 | 1002 | $tax_subtotal->save(); |
1003 | 1003 | $total_line_item->recalculate_total_including_taxes(); |
1004 | 1004 | return $new_tax; |
@@ -1020,14 +1020,14 @@ discard block |
||
1020 | 1020 | $code_substring_for_whitelist = null |
1021 | 1021 | ) { |
1022 | 1022 | $whitelisted = false; |
1023 | - if( $code_substring_for_whitelist !== null ) { |
|
1024 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
1023 | + if ($code_substring_for_whitelist !== null) { |
|
1024 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
1025 | 1025 | } |
1026 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
1027 | - $line_item->set_is_taxable( $taxable ); |
|
1026 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
1027 | + $line_item->set_is_taxable($taxable); |
|
1028 | 1028 | } |
1029 | - foreach( $line_item->children() as $child_line_item ) { |
|
1030 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
1029 | + foreach ($line_item->children() as $child_line_item) { |
|
1030 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
1031 | 1031 | } |
1032 | 1032 | } |
1033 | 1033 | |
@@ -1040,8 +1040,8 @@ discard block |
||
1040 | 1040 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1041 | 1041 | * @return EE_Line_Item[] |
1042 | 1042 | */ |
1043 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
1044 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
1043 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
1044 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | * @param string $obj_type |
1055 | 1055 | * @return EE_Line_Item[] |
1056 | 1056 | */ |
1057 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1057 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1058 | 1058 | return self::_get_descendants_by_type_and_object_type( |
1059 | 1059 | $parent_line_item, |
1060 | 1060 | EEM_Line_Item::type_sub_total, |
@@ -1071,8 +1071,8 @@ discard block |
||
1071 | 1071 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1072 | 1072 | * @return EE_Line_Item[] |
1073 | 1073 | */ |
1074 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
1075 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
1074 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
1075 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | |
@@ -1085,8 +1085,8 @@ discard block |
||
1085 | 1085 | * @param string $obj_type |
1086 | 1086 | * @return EE_Line_Item[] |
1087 | 1087 | */ |
1088 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1089 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
1088 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1089 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1098 | 1098 | * @return EE_Line_Item[] |
1099 | 1099 | */ |
1100 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
1101 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
1100 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
1101 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | |
@@ -1109,8 +1109,8 @@ discard block |
||
1109 | 1109 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1110 | 1110 | * @return EE_Line_Item[] |
1111 | 1111 | */ |
1112 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
1113 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
1112 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
1113 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | |
@@ -1123,8 +1123,8 @@ discard block |
||
1123 | 1123 | * @param string $line_item_type one of the EEM_Line_Item constants |
1124 | 1124 | * @return EE_Line_Item[] |
1125 | 1125 | */ |
1126 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
1127 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
1126 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
1127 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | |
@@ -1143,8 +1143,8 @@ discard block |
||
1143 | 1143 | $obj_type = null |
1144 | 1144 | ) { |
1145 | 1145 | $objects = array(); |
1146 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1147 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1146 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1147 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1148 | 1148 | if ( |
1149 | 1149 | $child_line_item->type() === $line_item_type |
1150 | 1150 | && ( |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | $OBJ_type = '', |
1185 | 1185 | $OBJ_IDs = array() |
1186 | 1186 | ) { |
1187 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
1187 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | |
@@ -1203,12 +1203,12 @@ discard block |
||
1203 | 1203 | $OBJ_IDs |
1204 | 1204 | ) { |
1205 | 1205 | $objects = array(); |
1206 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1207 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1206 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1207 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1208 | 1208 | if ( |
1209 | 1209 | $child_line_item->OBJ_type() === $OBJ_type |
1210 | - && is_array( $OBJ_IDs ) |
|
1211 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
1210 | + && is_array($OBJ_IDs) |
|
1211 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1212 | 1212 | ) { |
1213 | 1213 | $objects[] = $child_line_item; |
1214 | 1214 | } else { |
@@ -1238,8 +1238,8 @@ discard block |
||
1238 | 1238 | * @param string $type like one of the EEM_Line_Item::type_* |
1239 | 1239 | * @return EE_Line_Item |
1240 | 1240 | */ |
1241 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
1242 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
1241 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
1242 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1243 | 1243 | } |
1244 | 1244 | |
1245 | 1245 | |
@@ -1253,8 +1253,8 @@ discard block |
||
1253 | 1253 | * @param string $code any value used for LIN_code |
1254 | 1254 | * @return EE_Line_Item |
1255 | 1255 | */ |
1256 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
1257 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
1256 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
1257 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1258 | 1258 | } |
1259 | 1259 | |
1260 | 1260 | |
@@ -1268,15 +1268,15 @@ discard block |
||
1268 | 1268 | * @param string $value any value stored in $search_field |
1269 | 1269 | * @return EE_Line_Item |
1270 | 1270 | */ |
1271 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
1272 | - foreach( $parent_line_item->children() as $child ){ |
|
1273 | - if ( $child->get( $search_field ) == $value ){ |
|
1271 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
1272 | + foreach ($parent_line_item->children() as $child) { |
|
1273 | + if ($child->get($search_field) == $value) { |
|
1274 | 1274 | return $child; |
1275 | 1275 | } |
1276 | 1276 | } |
1277 | - foreach( $parent_line_item->children() as $child ){ |
|
1278 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
1279 | - if ( $descendant_found ){ |
|
1277 | + foreach ($parent_line_item->children() as $child) { |
|
1278 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
1279 | + if ($descendant_found) { |
|
1280 | 1280 | return $descendant_found; |
1281 | 1281 | } |
1282 | 1282 | } |
@@ -1293,24 +1293,24 @@ discard block |
||
1293 | 1293 | * @return \EE_Line_Item |
1294 | 1294 | * @throws \EE_Error |
1295 | 1295 | */ |
1296 | - public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){ |
|
1297 | - if ( $line_item->TXN_ID() ) { |
|
1298 | - $total_line_item = $line_item->transaction()->total_line_item( false ); |
|
1299 | - if ( $total_line_item instanceof EE_Line_Item ) { |
|
1296 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) { |
|
1297 | + if ($line_item->TXN_ID()) { |
|
1298 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
1299 | + if ($total_line_item instanceof EE_Line_Item) { |
|
1300 | 1300 | return $total_line_item; |
1301 | 1301 | } |
1302 | 1302 | } else { |
1303 | 1303 | $line_item_parent = $line_item->parent(); |
1304 | - if ( $line_item_parent instanceof EE_Line_Item ) { |
|
1305 | - if ( $line_item_parent->is_total() ) { |
|
1304 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
1305 | + if ($line_item_parent->is_total()) { |
|
1306 | 1306 | return $line_item_parent; |
1307 | 1307 | } |
1308 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent ); |
|
1308 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
1309 | 1309 | } |
1310 | 1310 | } |
1311 | 1311 | throw new EE_Error( |
1312 | 1312 | sprintf( |
1313 | - __( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ), |
|
1313 | + __('A valid grand total for line item %1$d was not found.', 'event_espresso'), |
|
1314 | 1314 | $line_item->ID() |
1315 | 1315 | ) |
1316 | 1316 | ); |
@@ -1327,31 +1327,31 @@ discard block |
||
1327 | 1327 | * @return void |
1328 | 1328 | * @throws \EE_Error |
1329 | 1329 | */ |
1330 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
1330 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
1331 | 1331 | echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
1332 | - if ( ! $indentation ) { |
|
1333 | - echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />'; |
|
1332 | + if ( ! $indentation) { |
|
1333 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1334 | 1334 | } |
1335 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
1335 | + for ($i = 0; $i < $indentation; $i++) { |
|
1336 | 1336 | echo ". "; |
1337 | 1337 | } |
1338 | 1338 | $breakdown = ''; |
1339 | - if ( $line_item->is_line_item()){ |
|
1340 | - if ( $line_item->is_percent() ) { |
|
1339 | + if ($line_item->is_line_item()) { |
|
1340 | + if ($line_item->is_percent()) { |
|
1341 | 1341 | $breakdown = "{$line_item->percent()}%"; |
1342 | 1342 | } else { |
1343 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1343 | + $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1344 | 1344 | } |
1345 | 1345 | } |
1346 | - echo $line_item->name() . " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : " . '$' . "{$line_item->total()}"; |
|
1347 | - if ( $breakdown ) { |
|
1346 | + echo $line_item->name()." [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ".'$'."{$line_item->total()}"; |
|
1347 | + if ($breakdown) { |
|
1348 | 1348 | echo " ( {$breakdown} )"; |
1349 | 1349 | } |
1350 | - if( $line_item->is_taxable() ){ |
|
1350 | + if ($line_item->is_taxable()) { |
|
1351 | 1351 | echo " * taxable"; |
1352 | 1352 | } |
1353 | - if( $line_item->children() ){ |
|
1354 | - foreach($line_item->children() as $child){ |
|
1353 | + if ($line_item->children()) { |
|
1354 | + foreach ($line_item->children() as $child) { |
|
1355 | 1355 | self::visualize($child, $indentation + 1); |
1356 | 1356 | } |
1357 | 1357 | } |
@@ -1392,97 +1392,97 @@ discard block |
||
1392 | 1392 | * is theirs, which can be done with |
1393 | 1393 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
1394 | 1394 | */ |
1395 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
1395 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
1396 | 1396 | //init running grand total if not already |
1397 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
1398 | - $running_totals[ 'total' ] = 0; |
|
1397 | + if ( ! isset($running_totals['total'])) { |
|
1398 | + $running_totals['total'] = 0; |
|
1399 | 1399 | } |
1400 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
1401 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
1400 | + if ( ! isset($running_totals['taxable'])) { |
|
1401 | + $running_totals['taxable'] = array('total' => 0); |
|
1402 | 1402 | } |
1403 | - foreach ( $line_item->children() as $child_line_item ) { |
|
1404 | - switch ( $child_line_item->type() ) { |
|
1403 | + foreach ($line_item->children() as $child_line_item) { |
|
1404 | + switch ($child_line_item->type()) { |
|
1405 | 1405 | |
1406 | 1406 | case EEM_Line_Item::type_sub_total : |
1407 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
1407 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
1408 | 1408 | //combine arrays but preserve numeric keys |
1409 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
1410 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
1411 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
1409 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1410 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1411 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1412 | 1412 | break; |
1413 | 1413 | |
1414 | 1414 | case EEM_Line_Item::type_tax_sub_total : |
1415 | 1415 | |
1416 | 1416 | //find how much the taxes percentage is |
1417 | - if ( $child_line_item->percent() !== 0 ) { |
|
1417 | + if ($child_line_item->percent() !== 0) { |
|
1418 | 1418 | $tax_percent_decimal = $child_line_item->percent() / 100; |
1419 | 1419 | } else { |
1420 | 1420 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
1421 | 1421 | } |
1422 | 1422 | //and apply to all the taxable totals, and add to the pretax totals |
1423 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1423 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1424 | 1424 | //"total" and "taxable" array key is an exception |
1425 | - if ( $line_item_id === 'taxable' ) { |
|
1425 | + if ($line_item_id === 'taxable') { |
|
1426 | 1426 | continue; |
1427 | 1427 | } |
1428 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1429 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
1428 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
1429 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
1430 | 1430 | } |
1431 | 1431 | break; |
1432 | 1432 | |
1433 | 1433 | case EEM_Line_Item::type_line_item : |
1434 | 1434 | |
1435 | 1435 | // ticket line items or ???? |
1436 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
1436 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
1437 | 1437 | // kk it's a ticket |
1438 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
1438 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
1439 | 1439 | //huh? that shouldn't happen. |
1440 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
1440 | + $running_totals['total'] += $child_line_item->total(); |
|
1441 | 1441 | } else { |
1442 | 1442 | //its not in our running totals yet. great. |
1443 | - if ( $child_line_item->is_taxable() ) { |
|
1443 | + if ($child_line_item->is_taxable()) { |
|
1444 | 1444 | $taxable_amount = $child_line_item->unit_price(); |
1445 | 1445 | } else { |
1446 | 1446 | $taxable_amount = 0; |
1447 | 1447 | } |
1448 | 1448 | // are we only calculating totals for some tickets? |
1449 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
1450 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1451 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
1449 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
1450 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
1451 | + $running_totals[$child_line_item->ID()] = $quantity |
|
1452 | 1452 | ? $child_line_item->unit_price() |
1453 | 1453 | : 0; |
1454 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
1454 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
1455 | 1455 | ? $taxable_amount |
1456 | 1456 | : 0; |
1457 | 1457 | } else { |
1458 | 1458 | $quantity = $child_line_item->quantity(); |
1459 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1460 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
1459 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
1460 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
1461 | 1461 | } |
1462 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
1463 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
1462 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1463 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1464 | 1464 | } |
1465 | 1465 | } else { |
1466 | 1466 | // it's some other type of item added to the cart |
1467 | 1467 | // it should affect the running totals |
1468 | 1468 | // basically we want to convert it into a PERCENT modifier. Because |
1469 | 1469 | // more clearly affect all registration's final price equally |
1470 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
1471 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
1470 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1471 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1472 | 1472 | : 1; |
1473 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1473 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1474 | 1474 | //the "taxable" array key is an exception |
1475 | - if ( $line_item_id === 'taxable' ) { |
|
1475 | + if ($line_item_id === 'taxable') { |
|
1476 | 1476 | continue; |
1477 | 1477 | } |
1478 | 1478 | // update the running totals |
1479 | 1479 | // yes this actually even works for the running grand total! |
1480 | - $running_totals[ $line_item_id ] = |
|
1480 | + $running_totals[$line_item_id] = |
|
1481 | 1481 | $line_items_percent_of_running_total * $this_running_total; |
1482 | 1482 | |
1483 | - if ( $child_line_item->is_taxable() ) { |
|
1484 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
1485 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1483 | + if ($child_line_item->is_taxable()) { |
|
1484 | + $running_totals['taxable'][$line_item_id] = |
|
1485 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | } |
@@ -1500,16 +1500,16 @@ discard block |
||
1500 | 1500 | * @return float | null |
1501 | 1501 | * @throws \OutOfRangeException |
1502 | 1502 | */ |
1503 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
1503 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
1504 | 1504 | static $final_prices_per_ticket_line_item = array(); |
1505 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
1505 | + if (empty($final_prices_per_ticket_line_item)) { |
|
1506 | 1506 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
1507 | 1507 | $total_line_item |
1508 | 1508 | ); |
1509 | 1509 | } |
1510 | 1510 | //ok now find this new registration's final price |
1511 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
1512 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
1511 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
1512 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
1513 | 1513 | } |
1514 | 1514 | $message = sprintf( |
1515 | 1515 | __( |
@@ -1518,11 +1518,11 @@ discard block |
||
1518 | 1518 | ), |
1519 | 1519 | $ticket_line_item->ID() |
1520 | 1520 | ); |
1521 | - if ( WP_DEBUG ) { |
|
1522 | - $message .= '<br>' . print_r( $final_prices_per_ticket_line_item, true ); |
|
1523 | - throw new \OutOfRangeException( $message ); |
|
1521 | + if (WP_DEBUG) { |
|
1522 | + $message .= '<br>'.print_r($final_prices_per_ticket_line_item, true); |
|
1523 | + throw new \OutOfRangeException($message); |
|
1524 | 1524 | } else { |
1525 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
1525 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1526 | 1526 | } |
1527 | 1527 | return null; |
1528 | 1528 | } |
@@ -1538,15 +1538,15 @@ discard block |
||
1538 | 1538 | * @return \EE_Line_Item |
1539 | 1539 | * @throws \EE_Error |
1540 | 1540 | */ |
1541 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
1542 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
1543 | - foreach ( $line_item->children() as $child_li ) { |
|
1544 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
1541 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
1542 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1543 | + foreach ($line_item->children() as $child_li) { |
|
1544 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
1545 | 1545 | } |
1546 | 1546 | //if this is the grand total line item, make sure the totals all add up |
1547 | 1547 | //(we could have duplicated this logic AS we copied the line items, but |
1548 | 1548 | //it seems DRYer this way) |
1549 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
1549 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1550 | 1550 | $copy_li->recalculate_total_including_taxes(); |
1551 | 1551 | } |
1552 | 1552 | return $copy_li; |
@@ -1563,24 +1563,24 @@ discard block |
||
1563 | 1563 | * @throws \EE_Error |
1564 | 1564 | * @param EE_Registration[] $registrations |
1565 | 1565 | */ |
1566 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
1566 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
1567 | 1567 | $new_li_fields = $line_item->model_field_array(); |
1568 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1568 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1569 | 1569 | $line_item->OBJ_type() === 'Ticket' |
1570 | 1570 | ) { |
1571 | 1571 | $count = 0; |
1572 | - foreach ( $registrations as $registration ) { |
|
1573 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1574 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
1572 | + foreach ($registrations as $registration) { |
|
1573 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1574 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
1575 | 1575 | ) { |
1576 | 1576 | $count++; |
1577 | 1577 | } |
1578 | 1578 | } |
1579 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
1579 | + $new_li_fields['LIN_quantity'] = $count; |
|
1580 | 1580 | } |
1581 | 1581 | //don't set the total. We'll leave that up to the code that calculates it |
1582 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
1583 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1582 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1583 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1584 | 1584 | } |
1585 | 1585 | |
1586 | 1586 | |
@@ -1593,19 +1593,19 @@ discard block |
||
1593 | 1593 | * @return \EE_Line_Item|null |
1594 | 1594 | * @throws \EE_Error |
1595 | 1595 | */ |
1596 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
1597 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
1598 | - if ( $copied_li === null ) { |
|
1596 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
1597 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1598 | + if ($copied_li === null) { |
|
1599 | 1599 | return null; |
1600 | 1600 | } |
1601 | 1601 | //if this is an event subtotal, we want to only include it if it |
1602 | 1602 | //has a non-zero total and at least one ticket line item child |
1603 | 1603 | $ticket_children = 0; |
1604 | - foreach ( $line_item->children() as $child_li ) { |
|
1605 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
1606 | - if ( $child_li_copy !== null ) { |
|
1607 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
1608 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1604 | + foreach ($line_item->children() as $child_li) { |
|
1605 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1606 | + if ($child_li_copy !== null) { |
|
1607 | + $copied_li->add_child_line_item($child_li_copy); |
|
1608 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1609 | 1609 | $child_li_copy->OBJ_type() === 'Ticket' |
1610 | 1610 | ) { |
1611 | 1611 | $ticket_children++; |
@@ -1635,8 +1635,8 @@ discard block |
||
1635 | 1635 | * @return EE_Line_Item |
1636 | 1636 | * @throws \EE_Error |
1637 | 1637 | */ |
1638 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
1639 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1638 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
1639 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1640 | 1640 | $line_item->OBJ_type() === 'Ticket' && |
1641 | 1641 | $line_item->quantity() === 0 |
1642 | 1642 | ) { |
@@ -1644,8 +1644,8 @@ discard block |
||
1644 | 1644 | } |
1645 | 1645 | $new_li_fields = $line_item->model_field_array(); |
1646 | 1646 | //don't set the total. We'll leave that up to the code that calculates it |
1647 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
1648 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1647 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1648 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1649 | 1649 | } |
1650 | 1650 | |
1651 | 1651 | |
@@ -1657,9 +1657,9 @@ discard block |
||
1657 | 1657 | * @return \EE_Line_Item |
1658 | 1658 | * @throws \EE_Error |
1659 | 1659 | */ |
1660 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
1661 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1662 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
1660 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
1661 | + EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1662 | + return self::get_pre_tax_subtotal($total_line_item); |
|
1663 | 1663 | } |
1664 | 1664 | |
1665 | 1665 | |
@@ -1670,9 +1670,9 @@ discard block |
||
1670 | 1670 | * @return \EE_Line_Item |
1671 | 1671 | * @throws \EE_Error |
1672 | 1672 | */ |
1673 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
1674 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' ); |
|
1675 | - return self::create_total_line_item( $transaction ); |
|
1673 | + public static function create_default_total_line_item($transaction = NULL) { |
|
1674 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0'); |
|
1675 | + return self::create_total_line_item($transaction); |
|
1676 | 1676 | } |
1677 | 1677 | |
1678 | 1678 | |
@@ -1684,9 +1684,9 @@ discard block |
||
1684 | 1684 | * @return \EE_Line_Item |
1685 | 1685 | * @throws \EE_Error |
1686 | 1686 | */ |
1687 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1688 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1689 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
1687 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1688 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1689 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
1690 | 1690 | } |
1691 | 1691 | |
1692 | 1692 | |
@@ -1698,9 +1698,9 @@ discard block |
||
1698 | 1698 | * @return \EE_Line_Item |
1699 | 1699 | * @throws \EE_Error |
1700 | 1700 | */ |
1701 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1702 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1703 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
1701 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1702 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0'); |
|
1703 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
1704 | 1704 | } |
1705 | 1705 | |
1706 | 1706 | |
@@ -1712,9 +1712,9 @@ discard block |
||
1712 | 1712 | * @return \EE_Line_Item |
1713 | 1713 | * @throws \EE_Error |
1714 | 1714 | */ |
1715 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1716 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1717 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
1715 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1716 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0'); |
|
1717 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
1718 | 1718 | } |
1719 | 1719 | |
1720 | 1720 |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; |
6 | 6 | |
7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | |
@@ -22,794 +22,794 @@ discard block |
||
22 | 22 | class EE_Dependency_Map |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - /** |
|
31 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | - */ |
|
33 | - const load_new_object = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | - */ |
|
39 | - const load_from_cache = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * When registering a dependency, |
|
43 | - * this indicates to keep any existing dependencies that already exist, |
|
44 | - * and simply discard any new dependencies declared in the incoming data |
|
45 | - */ |
|
46 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | - |
|
48 | - /** |
|
49 | - * When registering a dependency, |
|
50 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | - */ |
|
52 | - const OVERWRITE_DEPENDENCIES = 1; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @type EE_Dependency_Map $_instance |
|
58 | - */ |
|
59 | - protected static $_instance; |
|
60 | - |
|
61 | - /** |
|
62 | - * @type EE_Request $request |
|
63 | - */ |
|
64 | - protected $_request; |
|
65 | - |
|
66 | - /** |
|
67 | - * @type EE_Response $response |
|
68 | - */ |
|
69 | - protected $_response; |
|
70 | - |
|
71 | - /** |
|
72 | - * @type LoaderInterface $loader |
|
73 | - */ |
|
74 | - protected $loader; |
|
75 | - |
|
76 | - /** |
|
77 | - * @type array $_dependency_map |
|
78 | - */ |
|
79 | - protected $_dependency_map = array(); |
|
80 | - |
|
81 | - /** |
|
82 | - * @type array $_class_loaders |
|
83 | - */ |
|
84 | - protected $_class_loaders = array(); |
|
85 | - |
|
86 | - /** |
|
87 | - * @type array $_aliases |
|
88 | - */ |
|
89 | - protected $_aliases = array(); |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * EE_Dependency_Map constructor. |
|
95 | - * |
|
96 | - * @param EE_Request $request |
|
97 | - * @param EE_Response $response |
|
98 | - */ |
|
99 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
100 | - { |
|
101 | - $this->_request = $request; |
|
102 | - $this->_response = $response; |
|
103 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
104 | - do_action('EE_Dependency_Map____construct'); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @throws InvalidDataTypeException |
|
111 | - * @throws InvalidInterfaceException |
|
112 | - * @throws InvalidArgumentException |
|
113 | - */ |
|
114 | - public function initialize() |
|
115 | - { |
|
116 | - $this->_register_core_dependencies(); |
|
117 | - $this->_register_core_class_loaders(); |
|
118 | - $this->_register_core_aliases(); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @singleton method used to instantiate class object |
|
125 | - * @access public |
|
126 | - * @param EE_Request $request |
|
127 | - * @param EE_Response $response |
|
128 | - * @return EE_Dependency_Map |
|
129 | - */ |
|
130 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
131 | - { |
|
132 | - // check if class object is instantiated, and instantiated properly |
|
133 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
135 | - } |
|
136 | - return self::$_instance; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * @param LoaderInterface $loader |
|
143 | - */ |
|
144 | - public function setLoader(LoaderInterface $loader) |
|
145 | - { |
|
146 | - $this->loader = $loader; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $class |
|
153 | - * @param array $dependencies |
|
154 | - * @param int $overwrite |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public static function register_dependencies( |
|
158 | - $class, |
|
159 | - array $dependencies, |
|
160 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
161 | - ) { |
|
162 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
169 | - * to the class specified by the first parameter. |
|
170 | - * IMPORTANT !!! |
|
171 | - * The order of elements in the incoming $dependencies array MUST match |
|
172 | - * the order of the constructor parameters for the class in question. |
|
173 | - * This is especially important when overriding any existing dependencies that are registered. |
|
174 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
175 | - * |
|
176 | - * @param string $class |
|
177 | - * @param array $dependencies |
|
178 | - * @param int $overwrite |
|
179 | - * @return bool |
|
180 | - */ |
|
181 | - public function registerDependencies( |
|
182 | - $class, |
|
183 | - array $dependencies, |
|
184 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
185 | - ) { |
|
186 | - $class = trim($class, '\\'); |
|
187 | - $registered = false; |
|
188 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
190 | - } |
|
191 | - // we need to make sure that any aliases used when registering a dependency |
|
192 | - // get resolved to the correct class name |
|
193 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
194 | - $alias = self::$_instance->get_alias($dependency); |
|
195 | - if ( |
|
196 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
198 | - ) { |
|
199 | - unset($dependencies[$dependency]); |
|
200 | - $dependencies[$alias] = $load_source; |
|
201 | - $registered = true; |
|
202 | - } |
|
203 | - } |
|
204 | - // now add our two lists of dependencies together. |
|
205 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
206 | - // so $dependencies is NOT overwritten because it is listed first |
|
207 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
208 | - // Union is way faster than array_merge() but should be used with caution... |
|
209 | - // especially with numerically indexed arrays |
|
210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
211 | - // now we need to ensure that the resulting dependencies |
|
212 | - // array only has the entries that are required for the class |
|
213 | - // so first count how many dependencies were originally registered for the class |
|
214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
215 | - // if that count is non-zero (meaning dependencies were already registered) |
|
216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
217 | - // then truncate the final array to match that count |
|
218 | - ? array_slice($dependencies, 0, $dependency_count) |
|
219 | - // otherwise just take the incoming array because nothing previously existed |
|
220 | - : $dependencies; |
|
221 | - return $registered; |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - /** |
|
227 | - * @param string $class_name |
|
228 | - * @param string $loader |
|
229 | - * @return bool |
|
230 | - * @throws DomainException |
|
231 | - */ |
|
232 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
233 | - { |
|
234 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | - throw new DomainException( |
|
236 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
237 | - ); |
|
238 | - } |
|
239 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
240 | - if ( |
|
241 | - ! is_callable($loader) |
|
242 | - && ( |
|
243 | - strpos($loader, 'load_') !== 0 |
|
244 | - || ! method_exists('EE_Registry', $loader) |
|
245 | - ) |
|
246 | - ) { |
|
247 | - throw new DomainException( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $loader |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - $class_name = self::$_instance->get_alias($class_name); |
|
258 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
260 | - return true; |
|
261 | - } |
|
262 | - return false; |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @return array |
|
269 | - */ |
|
270 | - public function dependency_map() |
|
271 | - { |
|
272 | - return $this->_dependency_map; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
279 | - * |
|
280 | - * @param string $class_name |
|
281 | - * @return boolean |
|
282 | - */ |
|
283 | - public function has($class_name = '') |
|
284 | - { |
|
285 | - // all legacy models have the same dependencies |
|
286 | - if (strpos($class_name, 'EEM_') === 0) { |
|
287 | - $class_name = 'LEGACY_MODELS'; |
|
288 | - } |
|
289 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
296 | - * |
|
297 | - * @param string $class_name |
|
298 | - * @param string $dependency |
|
299 | - * @return bool |
|
300 | - */ |
|
301 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
302 | - { |
|
303 | - // all legacy models have the same dependencies |
|
304 | - if (strpos($class_name, 'EEM_') === 0) { |
|
305 | - $class_name = 'LEGACY_MODELS'; |
|
306 | - } |
|
307 | - $dependency = $this->get_alias($dependency); |
|
308 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
309 | - ? true |
|
310 | - : false; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
317 | - * |
|
318 | - * @param string $class_name |
|
319 | - * @param string $dependency |
|
320 | - * @return int |
|
321 | - */ |
|
322 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
323 | - { |
|
324 | - // all legacy models have the same dependencies |
|
325 | - if (strpos($class_name, 'EEM_') === 0) { |
|
326 | - $class_name = 'LEGACY_MODELS'; |
|
327 | - } |
|
328 | - $dependency = $this->get_alias($dependency); |
|
329 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
330 | - ? $this->_dependency_map[$class_name][$dependency] |
|
331 | - : EE_Dependency_Map::not_registered; |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * @param string $class_name |
|
338 | - * @return string | Closure |
|
339 | - */ |
|
340 | - public function class_loader($class_name) |
|
341 | - { |
|
342 | - // all legacy models use load_model() |
|
343 | - if(strpos($class_name, 'EEM_') === 0){ |
|
344 | - return 'load_model'; |
|
345 | - } |
|
346 | - $class_name = $this->get_alias($class_name); |
|
347 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * @return array |
|
354 | - */ |
|
355 | - public function class_loaders() |
|
356 | - { |
|
357 | - return $this->_class_loaders; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * adds an alias for a classname |
|
364 | - * |
|
365 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
366 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
367 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
368 | - */ |
|
369 | - public function add_alias($class_name, $alias, $for_class = '') |
|
370 | - { |
|
371 | - if ($for_class !== '') { |
|
372 | - if (! isset($this->_aliases[$for_class])) { |
|
373 | - $this->_aliases[$for_class] = array(); |
|
374 | - } |
|
375 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
376 | - } |
|
377 | - $this->_aliases[$class_name] = $alias; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * returns TRUE if the provided class name has an alias |
|
384 | - * |
|
385 | - * @param string $class_name |
|
386 | - * @param string $for_class |
|
387 | - * @return bool |
|
388 | - */ |
|
389 | - public function has_alias($class_name = '', $for_class = '') |
|
390 | - { |
|
391 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
392 | - || ( |
|
393 | - isset($this->_aliases[$class_name]) |
|
394 | - && ! is_array($this->_aliases[$class_name]) |
|
395 | - ); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
402 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
403 | - * for example: |
|
404 | - * if the following two entries were added to the _aliases array: |
|
405 | - * array( |
|
406 | - * 'interface_alias' => 'some\namespace\interface' |
|
407 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
408 | - * ) |
|
409 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
410 | - * to load an instance of 'some\namespace\classname' |
|
411 | - * |
|
412 | - * @param string $class_name |
|
413 | - * @param string $for_class |
|
414 | - * @return string |
|
415 | - */ |
|
416 | - public function get_alias($class_name = '', $for_class = '') |
|
417 | - { |
|
418 | - if (! $this->has_alias($class_name, $for_class)) { |
|
419 | - return $class_name; |
|
420 | - } |
|
421 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
422 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
423 | - } |
|
424 | - return $this->get_alias($this->_aliases[$class_name]); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | - * This is done by using the following class constants: |
|
433 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | - */ |
|
436 | - protected function _register_core_dependencies() |
|
437 | - { |
|
438 | - $this->_dependency_map = array( |
|
439 | - 'EE_Request_Handler' => array( |
|
440 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | - ), |
|
442 | - 'EE_System' => array( |
|
443 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
445 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
446 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
447 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_Session' => array( |
|
450 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
452 | - ), |
|
453 | - 'EE_Cart' => array( |
|
454 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
455 | - ), |
|
456 | - 'EE_Front_Controller' => array( |
|
457 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
460 | - ), |
|
461 | - 'EE_Messenger_Collection_Loader' => array( |
|
462 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
463 | - ), |
|
464 | - 'EE_Message_Type_Collection_Loader' => array( |
|
465 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
466 | - ), |
|
467 | - 'EE_Message_Resource_Manager' => array( |
|
468 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
469 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
470 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
471 | - ), |
|
472 | - 'EE_Message_Factory' => array( |
|
473 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
474 | - ), |
|
475 | - 'EE_messages' => array( |
|
476 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
477 | - ), |
|
478 | - 'EE_Messages_Generator' => array( |
|
479 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
480 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
481 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EE_Messages_Processor' => array( |
|
485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EE_Messages_Queue' => array( |
|
488 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
489 | - ), |
|
490 | - 'EE_Messages_Template_Defaults' => array( |
|
491 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
492 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
493 | - ), |
|
494 | - 'EE_Message_To_Generate_From_Request' => array( |
|
495 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
496 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
497 | - ), |
|
498 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
499 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
500 | - ), |
|
501 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
502 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
503 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
504 | - ), |
|
505 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
506 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
507 | - ), |
|
508 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
509 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
510 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
511 | - ), |
|
512 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
513 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
514 | - ), |
|
515 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
516 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
517 | - ), |
|
518 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
519 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
520 | - ), |
|
521 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
522 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
523 | - ), |
|
524 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
525 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
526 | - ), |
|
527 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
528 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
531 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
532 | - ), |
|
533 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
534 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
537 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
540 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
543 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
546 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
549 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
552 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EE_Data_Migration_Class_Base' => array( |
|
555 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
556 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
557 | - ), |
|
558 | - 'EE_DMS_Core_4_1_0' => array( |
|
559 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
560 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
561 | - ), |
|
562 | - 'EE_DMS_Core_4_2_0' => array( |
|
563 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
564 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
565 | - ), |
|
566 | - 'EE_DMS_Core_4_3_0' => array( |
|
567 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | - ), |
|
570 | - 'EE_DMS_Core_4_4_0' => array( |
|
571 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | - ), |
|
574 | - 'EE_DMS_Core_4_5_0' => array( |
|
575 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | - ), |
|
578 | - 'EE_DMS_Core_4_6_0' => array( |
|
579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | - ), |
|
582 | - 'EE_DMS_Core_4_7_0' => array( |
|
583 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | - ), |
|
586 | - 'EE_DMS_Core_4_8_0' => array( |
|
587 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | - ), |
|
590 | - 'EE_DMS_Core_4_9_0' => array( |
|
591 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | - ), |
|
594 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
595 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
596 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
597 | - ), |
|
598 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
599 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
600 | - ), |
|
601 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
602 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
603 | - ), |
|
604 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
605 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
606 | - ), |
|
607 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
608 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
609 | - ), |
|
610 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
611 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
612 | - ), |
|
613 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
614 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
615 | - ), |
|
616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | - ), |
|
619 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
620 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
621 | - ), |
|
622 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
623 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
624 | - ), |
|
625 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
626 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
627 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
628 | - ), |
|
629 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
630 | - null, |
|
631 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
632 | - ), |
|
633 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
634 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
635 | - ), |
|
636 | - 'LEGACY_MODELS' => array( |
|
637 | - null, |
|
638 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
639 | - ), |
|
640 | - 'EE_Module_Request_Router' => array( |
|
641 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
642 | - ), |
|
643 | - ); |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * Registers how core classes are loaded. |
|
650 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
651 | - * 'EE_Request_Handler' => 'load_core' |
|
652 | - * 'EE_Messages_Queue' => 'load_lib' |
|
653 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
654 | - * or, if greater control is required, by providing a custom closure. For example: |
|
655 | - * 'Some_Class' => function () { |
|
656 | - * return new Some_Class(); |
|
657 | - * }, |
|
658 | - * This is required for instantiating dependencies |
|
659 | - * where an interface has been type hinted in a class constructor. For example: |
|
660 | - * 'Required_Interface' => function () { |
|
661 | - * return new A_Class_That_Implements_Required_Interface(); |
|
662 | - * }, |
|
663 | - * |
|
664 | - * @throws InvalidInterfaceException |
|
665 | - * @throws InvalidDataTypeException |
|
666 | - * @throws InvalidArgumentException |
|
667 | - */ |
|
668 | - protected function _register_core_class_loaders() |
|
669 | - { |
|
670 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
671 | - //be used in a closure. |
|
672 | - $request = &$this->_request; |
|
673 | - $response = &$this->_response; |
|
674 | - // $loader = &$this->loader; |
|
675 | - $this->_class_loaders = array( |
|
676 | - //load_core |
|
677 | - 'EE_Capabilities' => 'load_core', |
|
678 | - 'EE_Encryption' => 'load_core', |
|
679 | - 'EE_Front_Controller' => 'load_core', |
|
680 | - 'EE_Module_Request_Router' => 'load_core', |
|
681 | - 'EE_Registry' => 'load_core', |
|
682 | - 'EE_Request' => function () use (&$request) { |
|
683 | - return $request; |
|
684 | - }, |
|
685 | - 'EE_Response' => function () use (&$response) { |
|
686 | - return $response; |
|
687 | - }, |
|
688 | - 'EE_Request_Handler' => 'load_core', |
|
689 | - 'EE_Session' => 'load_core', |
|
690 | - 'EE_Cron_Tasks' => 'load_core', |
|
691 | - 'EE_System' => 'load_core', |
|
692 | - 'EE_Maintenance_Mode' => 'load_core', |
|
693 | - 'EE_Register_CPTs' => 'load_core', |
|
694 | - 'EE_Admin' => 'load_core', |
|
695 | - //load_lib |
|
696 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
697 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
698 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
699 | - 'EE_Messenger_Collection' => 'load_lib', |
|
700 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
701 | - 'EE_Messages_Processor' => 'load_lib', |
|
702 | - 'EE_Message_Repository' => 'load_lib', |
|
703 | - 'EE_Messages_Queue' => 'load_lib', |
|
704 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
705 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
706 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
707 | - 'EE_Messages_Generator' => function () { |
|
708 | - return EE_Registry::instance()->load_lib( |
|
709 | - 'Messages_Generator', |
|
710 | - array(), |
|
711 | - false, |
|
712 | - false |
|
713 | - ); |
|
714 | - }, |
|
715 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
716 | - return EE_Registry::instance()->load_lib( |
|
717 | - 'Messages_Template_Defaults', |
|
718 | - $arguments, |
|
719 | - false, |
|
720 | - false |
|
721 | - ); |
|
722 | - }, |
|
723 | - //load_model |
|
724 | - // 'EEM_Attendee' => 'load_model', |
|
725 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
726 | - // 'EEM_Message_Template' => 'load_model', |
|
727 | - //load_helper |
|
728 | - 'EEH_Parse_Shortcodes' => function () { |
|
729 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
730 | - return new EEH_Parse_Shortcodes(); |
|
731 | - } |
|
732 | - return null; |
|
733 | - }, |
|
734 | - 'EE_Template_Config' => function () { |
|
735 | - return EE_Config::instance()->template_settings; |
|
736 | - }, |
|
737 | - 'EE_Currency_Config' => function () { |
|
738 | - return EE_Config::instance()->currency; |
|
739 | - }, |
|
740 | - 'EE_Registration_Config' => function () { |
|
741 | - return EE_Config::instance()->registration; |
|
742 | - }, |
|
743 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
744 | - return LoaderFactory::getLoader(); |
|
745 | - }, |
|
746 | - ); |
|
747 | - } |
|
748 | - |
|
749 | - |
|
750 | - |
|
751 | - /** |
|
752 | - * can be used for supplying alternate names for classes, |
|
753 | - * or for connecting interface names to instantiable classes |
|
754 | - */ |
|
755 | - protected function _register_core_aliases() |
|
756 | - { |
|
757 | - $this->_aliases = array( |
|
758 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
759 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
760 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
761 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
762 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
763 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
764 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
765 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
766 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
767 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
768 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
769 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
770 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
771 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
772 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
773 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
774 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
775 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
776 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
777 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
778 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
779 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
780 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
781 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
782 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
783 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
784 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
785 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
786 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
787 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
788 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
789 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
790 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
791 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
792 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
793 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
794 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
795 | - ); |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - |
|
800 | - /** |
|
801 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
802 | - * request Primarily used by unit tests. |
|
803 | - * |
|
804 | - * @throws InvalidDataTypeException |
|
805 | - * @throws InvalidInterfaceException |
|
806 | - * @throws InvalidArgumentException |
|
807 | - */ |
|
808 | - public function reset() |
|
809 | - { |
|
810 | - $this->_register_core_class_loaders(); |
|
811 | - $this->_register_core_dependencies(); |
|
812 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + /** |
|
31 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
32 | + */ |
|
33 | + const load_new_object = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
37 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
38 | + */ |
|
39 | + const load_from_cache = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * When registering a dependency, |
|
43 | + * this indicates to keep any existing dependencies that already exist, |
|
44 | + * and simply discard any new dependencies declared in the incoming data |
|
45 | + */ |
|
46 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
47 | + |
|
48 | + /** |
|
49 | + * When registering a dependency, |
|
50 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
51 | + */ |
|
52 | + const OVERWRITE_DEPENDENCIES = 1; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @type EE_Dependency_Map $_instance |
|
58 | + */ |
|
59 | + protected static $_instance; |
|
60 | + |
|
61 | + /** |
|
62 | + * @type EE_Request $request |
|
63 | + */ |
|
64 | + protected $_request; |
|
65 | + |
|
66 | + /** |
|
67 | + * @type EE_Response $response |
|
68 | + */ |
|
69 | + protected $_response; |
|
70 | + |
|
71 | + /** |
|
72 | + * @type LoaderInterface $loader |
|
73 | + */ |
|
74 | + protected $loader; |
|
75 | + |
|
76 | + /** |
|
77 | + * @type array $_dependency_map |
|
78 | + */ |
|
79 | + protected $_dependency_map = array(); |
|
80 | + |
|
81 | + /** |
|
82 | + * @type array $_class_loaders |
|
83 | + */ |
|
84 | + protected $_class_loaders = array(); |
|
85 | + |
|
86 | + /** |
|
87 | + * @type array $_aliases |
|
88 | + */ |
|
89 | + protected $_aliases = array(); |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * EE_Dependency_Map constructor. |
|
95 | + * |
|
96 | + * @param EE_Request $request |
|
97 | + * @param EE_Response $response |
|
98 | + */ |
|
99 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
100 | + { |
|
101 | + $this->_request = $request; |
|
102 | + $this->_response = $response; |
|
103 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
104 | + do_action('EE_Dependency_Map____construct'); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @throws InvalidDataTypeException |
|
111 | + * @throws InvalidInterfaceException |
|
112 | + * @throws InvalidArgumentException |
|
113 | + */ |
|
114 | + public function initialize() |
|
115 | + { |
|
116 | + $this->_register_core_dependencies(); |
|
117 | + $this->_register_core_class_loaders(); |
|
118 | + $this->_register_core_aliases(); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @singleton method used to instantiate class object |
|
125 | + * @access public |
|
126 | + * @param EE_Request $request |
|
127 | + * @param EE_Response $response |
|
128 | + * @return EE_Dependency_Map |
|
129 | + */ |
|
130 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
131 | + { |
|
132 | + // check if class object is instantiated, and instantiated properly |
|
133 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
135 | + } |
|
136 | + return self::$_instance; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * @param LoaderInterface $loader |
|
143 | + */ |
|
144 | + public function setLoader(LoaderInterface $loader) |
|
145 | + { |
|
146 | + $this->loader = $loader; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $class |
|
153 | + * @param array $dependencies |
|
154 | + * @param int $overwrite |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public static function register_dependencies( |
|
158 | + $class, |
|
159 | + array $dependencies, |
|
160 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
161 | + ) { |
|
162 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
169 | + * to the class specified by the first parameter. |
|
170 | + * IMPORTANT !!! |
|
171 | + * The order of elements in the incoming $dependencies array MUST match |
|
172 | + * the order of the constructor parameters for the class in question. |
|
173 | + * This is especially important when overriding any existing dependencies that are registered. |
|
174 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
175 | + * |
|
176 | + * @param string $class |
|
177 | + * @param array $dependencies |
|
178 | + * @param int $overwrite |
|
179 | + * @return bool |
|
180 | + */ |
|
181 | + public function registerDependencies( |
|
182 | + $class, |
|
183 | + array $dependencies, |
|
184 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
185 | + ) { |
|
186 | + $class = trim($class, '\\'); |
|
187 | + $registered = false; |
|
188 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
190 | + } |
|
191 | + // we need to make sure that any aliases used when registering a dependency |
|
192 | + // get resolved to the correct class name |
|
193 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
194 | + $alias = self::$_instance->get_alias($dependency); |
|
195 | + if ( |
|
196 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
197 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
198 | + ) { |
|
199 | + unset($dependencies[$dependency]); |
|
200 | + $dependencies[$alias] = $load_source; |
|
201 | + $registered = true; |
|
202 | + } |
|
203 | + } |
|
204 | + // now add our two lists of dependencies together. |
|
205 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
206 | + // so $dependencies is NOT overwritten because it is listed first |
|
207 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
208 | + // Union is way faster than array_merge() but should be used with caution... |
|
209 | + // especially with numerically indexed arrays |
|
210 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
211 | + // now we need to ensure that the resulting dependencies |
|
212 | + // array only has the entries that are required for the class |
|
213 | + // so first count how many dependencies were originally registered for the class |
|
214 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
215 | + // if that count is non-zero (meaning dependencies were already registered) |
|
216 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
217 | + // then truncate the final array to match that count |
|
218 | + ? array_slice($dependencies, 0, $dependency_count) |
|
219 | + // otherwise just take the incoming array because nothing previously existed |
|
220 | + : $dependencies; |
|
221 | + return $registered; |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + /** |
|
227 | + * @param string $class_name |
|
228 | + * @param string $loader |
|
229 | + * @return bool |
|
230 | + * @throws DomainException |
|
231 | + */ |
|
232 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
233 | + { |
|
234 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | + throw new DomainException( |
|
236 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
237 | + ); |
|
238 | + } |
|
239 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
240 | + if ( |
|
241 | + ! is_callable($loader) |
|
242 | + && ( |
|
243 | + strpos($loader, 'load_') !== 0 |
|
244 | + || ! method_exists('EE_Registry', $loader) |
|
245 | + ) |
|
246 | + ) { |
|
247 | + throw new DomainException( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $loader |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + $class_name = self::$_instance->get_alias($class_name); |
|
258 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
260 | + return true; |
|
261 | + } |
|
262 | + return false; |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @return array |
|
269 | + */ |
|
270 | + public function dependency_map() |
|
271 | + { |
|
272 | + return $this->_dependency_map; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
279 | + * |
|
280 | + * @param string $class_name |
|
281 | + * @return boolean |
|
282 | + */ |
|
283 | + public function has($class_name = '') |
|
284 | + { |
|
285 | + // all legacy models have the same dependencies |
|
286 | + if (strpos($class_name, 'EEM_') === 0) { |
|
287 | + $class_name = 'LEGACY_MODELS'; |
|
288 | + } |
|
289 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
296 | + * |
|
297 | + * @param string $class_name |
|
298 | + * @param string $dependency |
|
299 | + * @return bool |
|
300 | + */ |
|
301 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
302 | + { |
|
303 | + // all legacy models have the same dependencies |
|
304 | + if (strpos($class_name, 'EEM_') === 0) { |
|
305 | + $class_name = 'LEGACY_MODELS'; |
|
306 | + } |
|
307 | + $dependency = $this->get_alias($dependency); |
|
308 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
309 | + ? true |
|
310 | + : false; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
317 | + * |
|
318 | + * @param string $class_name |
|
319 | + * @param string $dependency |
|
320 | + * @return int |
|
321 | + */ |
|
322 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
323 | + { |
|
324 | + // all legacy models have the same dependencies |
|
325 | + if (strpos($class_name, 'EEM_') === 0) { |
|
326 | + $class_name = 'LEGACY_MODELS'; |
|
327 | + } |
|
328 | + $dependency = $this->get_alias($dependency); |
|
329 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
330 | + ? $this->_dependency_map[$class_name][$dependency] |
|
331 | + : EE_Dependency_Map::not_registered; |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * @param string $class_name |
|
338 | + * @return string | Closure |
|
339 | + */ |
|
340 | + public function class_loader($class_name) |
|
341 | + { |
|
342 | + // all legacy models use load_model() |
|
343 | + if(strpos($class_name, 'EEM_') === 0){ |
|
344 | + return 'load_model'; |
|
345 | + } |
|
346 | + $class_name = $this->get_alias($class_name); |
|
347 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * @return array |
|
354 | + */ |
|
355 | + public function class_loaders() |
|
356 | + { |
|
357 | + return $this->_class_loaders; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * adds an alias for a classname |
|
364 | + * |
|
365 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
366 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
367 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
368 | + */ |
|
369 | + public function add_alias($class_name, $alias, $for_class = '') |
|
370 | + { |
|
371 | + if ($for_class !== '') { |
|
372 | + if (! isset($this->_aliases[$for_class])) { |
|
373 | + $this->_aliases[$for_class] = array(); |
|
374 | + } |
|
375 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
376 | + } |
|
377 | + $this->_aliases[$class_name] = $alias; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * returns TRUE if the provided class name has an alias |
|
384 | + * |
|
385 | + * @param string $class_name |
|
386 | + * @param string $for_class |
|
387 | + * @return bool |
|
388 | + */ |
|
389 | + public function has_alias($class_name = '', $for_class = '') |
|
390 | + { |
|
391 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
392 | + || ( |
|
393 | + isset($this->_aliases[$class_name]) |
|
394 | + && ! is_array($this->_aliases[$class_name]) |
|
395 | + ); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
402 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
403 | + * for example: |
|
404 | + * if the following two entries were added to the _aliases array: |
|
405 | + * array( |
|
406 | + * 'interface_alias' => 'some\namespace\interface' |
|
407 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
408 | + * ) |
|
409 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
410 | + * to load an instance of 'some\namespace\classname' |
|
411 | + * |
|
412 | + * @param string $class_name |
|
413 | + * @param string $for_class |
|
414 | + * @return string |
|
415 | + */ |
|
416 | + public function get_alias($class_name = '', $for_class = '') |
|
417 | + { |
|
418 | + if (! $this->has_alias($class_name, $for_class)) { |
|
419 | + return $class_name; |
|
420 | + } |
|
421 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
422 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
423 | + } |
|
424 | + return $this->get_alias($this->_aliases[$class_name]); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
431 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
432 | + * This is done by using the following class constants: |
|
433 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
434 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
435 | + */ |
|
436 | + protected function _register_core_dependencies() |
|
437 | + { |
|
438 | + $this->_dependency_map = array( |
|
439 | + 'EE_Request_Handler' => array( |
|
440 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
441 | + ), |
|
442 | + 'EE_System' => array( |
|
443 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
444 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
445 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
446 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
447 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_Session' => array( |
|
450 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
452 | + ), |
|
453 | + 'EE_Cart' => array( |
|
454 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
455 | + ), |
|
456 | + 'EE_Front_Controller' => array( |
|
457 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
460 | + ), |
|
461 | + 'EE_Messenger_Collection_Loader' => array( |
|
462 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
463 | + ), |
|
464 | + 'EE_Message_Type_Collection_Loader' => array( |
|
465 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
466 | + ), |
|
467 | + 'EE_Message_Resource_Manager' => array( |
|
468 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
469 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
470 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
471 | + ), |
|
472 | + 'EE_Message_Factory' => array( |
|
473 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
474 | + ), |
|
475 | + 'EE_messages' => array( |
|
476 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
477 | + ), |
|
478 | + 'EE_Messages_Generator' => array( |
|
479 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
480 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
481 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
482 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EE_Messages_Processor' => array( |
|
485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EE_Messages_Queue' => array( |
|
488 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
489 | + ), |
|
490 | + 'EE_Messages_Template_Defaults' => array( |
|
491 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
492 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
493 | + ), |
|
494 | + 'EE_Message_To_Generate_From_Request' => array( |
|
495 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
496 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
497 | + ), |
|
498 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
499 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
500 | + ), |
|
501 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
502 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
503 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
504 | + ), |
|
505 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
506 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
507 | + ), |
|
508 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
509 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
510 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
511 | + ), |
|
512 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
513 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
514 | + ), |
|
515 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
516 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
517 | + ), |
|
518 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
519 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
520 | + ), |
|
521 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
522 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
523 | + ), |
|
524 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
525 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
526 | + ), |
|
527 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
528 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
531 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
532 | + ), |
|
533 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
534 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
537 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
540 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
543 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
546 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
549 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
552 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EE_Data_Migration_Class_Base' => array( |
|
555 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
556 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
557 | + ), |
|
558 | + 'EE_DMS_Core_4_1_0' => array( |
|
559 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
560 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
561 | + ), |
|
562 | + 'EE_DMS_Core_4_2_0' => array( |
|
563 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
564 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
565 | + ), |
|
566 | + 'EE_DMS_Core_4_3_0' => array( |
|
567 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
568 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
569 | + ), |
|
570 | + 'EE_DMS_Core_4_4_0' => array( |
|
571 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
572 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
573 | + ), |
|
574 | + 'EE_DMS_Core_4_5_0' => array( |
|
575 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
576 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
577 | + ), |
|
578 | + 'EE_DMS_Core_4_6_0' => array( |
|
579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
581 | + ), |
|
582 | + 'EE_DMS_Core_4_7_0' => array( |
|
583 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
584 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
585 | + ), |
|
586 | + 'EE_DMS_Core_4_8_0' => array( |
|
587 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
588 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
589 | + ), |
|
590 | + 'EE_DMS_Core_4_9_0' => array( |
|
591 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
592 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
593 | + ), |
|
594 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
595 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
596 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
597 | + ), |
|
598 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
599 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
600 | + ), |
|
601 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
602 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
603 | + ), |
|
604 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
605 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
606 | + ), |
|
607 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
608 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
609 | + ), |
|
610 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
611 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
612 | + ), |
|
613 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
614 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
615 | + ), |
|
616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | + ), |
|
619 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
620 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
621 | + ), |
|
622 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
623 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
624 | + ), |
|
625 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
626 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
627 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
628 | + ), |
|
629 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
630 | + null, |
|
631 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
632 | + ), |
|
633 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
634 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
635 | + ), |
|
636 | + 'LEGACY_MODELS' => array( |
|
637 | + null, |
|
638 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
639 | + ), |
|
640 | + 'EE_Module_Request_Router' => array( |
|
641 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
642 | + ), |
|
643 | + ); |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * Registers how core classes are loaded. |
|
650 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
651 | + * 'EE_Request_Handler' => 'load_core' |
|
652 | + * 'EE_Messages_Queue' => 'load_lib' |
|
653 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
654 | + * or, if greater control is required, by providing a custom closure. For example: |
|
655 | + * 'Some_Class' => function () { |
|
656 | + * return new Some_Class(); |
|
657 | + * }, |
|
658 | + * This is required for instantiating dependencies |
|
659 | + * where an interface has been type hinted in a class constructor. For example: |
|
660 | + * 'Required_Interface' => function () { |
|
661 | + * return new A_Class_That_Implements_Required_Interface(); |
|
662 | + * }, |
|
663 | + * |
|
664 | + * @throws InvalidInterfaceException |
|
665 | + * @throws InvalidDataTypeException |
|
666 | + * @throws InvalidArgumentException |
|
667 | + */ |
|
668 | + protected function _register_core_class_loaders() |
|
669 | + { |
|
670 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
671 | + //be used in a closure. |
|
672 | + $request = &$this->_request; |
|
673 | + $response = &$this->_response; |
|
674 | + // $loader = &$this->loader; |
|
675 | + $this->_class_loaders = array( |
|
676 | + //load_core |
|
677 | + 'EE_Capabilities' => 'load_core', |
|
678 | + 'EE_Encryption' => 'load_core', |
|
679 | + 'EE_Front_Controller' => 'load_core', |
|
680 | + 'EE_Module_Request_Router' => 'load_core', |
|
681 | + 'EE_Registry' => 'load_core', |
|
682 | + 'EE_Request' => function () use (&$request) { |
|
683 | + return $request; |
|
684 | + }, |
|
685 | + 'EE_Response' => function () use (&$response) { |
|
686 | + return $response; |
|
687 | + }, |
|
688 | + 'EE_Request_Handler' => 'load_core', |
|
689 | + 'EE_Session' => 'load_core', |
|
690 | + 'EE_Cron_Tasks' => 'load_core', |
|
691 | + 'EE_System' => 'load_core', |
|
692 | + 'EE_Maintenance_Mode' => 'load_core', |
|
693 | + 'EE_Register_CPTs' => 'load_core', |
|
694 | + 'EE_Admin' => 'load_core', |
|
695 | + //load_lib |
|
696 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
697 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
698 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
699 | + 'EE_Messenger_Collection' => 'load_lib', |
|
700 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
701 | + 'EE_Messages_Processor' => 'load_lib', |
|
702 | + 'EE_Message_Repository' => 'load_lib', |
|
703 | + 'EE_Messages_Queue' => 'load_lib', |
|
704 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
705 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
706 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
707 | + 'EE_Messages_Generator' => function () { |
|
708 | + return EE_Registry::instance()->load_lib( |
|
709 | + 'Messages_Generator', |
|
710 | + array(), |
|
711 | + false, |
|
712 | + false |
|
713 | + ); |
|
714 | + }, |
|
715 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
716 | + return EE_Registry::instance()->load_lib( |
|
717 | + 'Messages_Template_Defaults', |
|
718 | + $arguments, |
|
719 | + false, |
|
720 | + false |
|
721 | + ); |
|
722 | + }, |
|
723 | + //load_model |
|
724 | + // 'EEM_Attendee' => 'load_model', |
|
725 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
726 | + // 'EEM_Message_Template' => 'load_model', |
|
727 | + //load_helper |
|
728 | + 'EEH_Parse_Shortcodes' => function () { |
|
729 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
730 | + return new EEH_Parse_Shortcodes(); |
|
731 | + } |
|
732 | + return null; |
|
733 | + }, |
|
734 | + 'EE_Template_Config' => function () { |
|
735 | + return EE_Config::instance()->template_settings; |
|
736 | + }, |
|
737 | + 'EE_Currency_Config' => function () { |
|
738 | + return EE_Config::instance()->currency; |
|
739 | + }, |
|
740 | + 'EE_Registration_Config' => function () { |
|
741 | + return EE_Config::instance()->registration; |
|
742 | + }, |
|
743 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
744 | + return LoaderFactory::getLoader(); |
|
745 | + }, |
|
746 | + ); |
|
747 | + } |
|
748 | + |
|
749 | + |
|
750 | + |
|
751 | + /** |
|
752 | + * can be used for supplying alternate names for classes, |
|
753 | + * or for connecting interface names to instantiable classes |
|
754 | + */ |
|
755 | + protected function _register_core_aliases() |
|
756 | + { |
|
757 | + $this->_aliases = array( |
|
758 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
759 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
760 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
761 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
762 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
763 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
764 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
765 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
766 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
767 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
768 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
769 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
770 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
771 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
772 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
773 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
774 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
775 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
776 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
777 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
778 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
779 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
780 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
781 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
782 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
783 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
784 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
785 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
786 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
787 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
788 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
789 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
790 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
791 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
792 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
793 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
794 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
795 | + ); |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + |
|
800 | + /** |
|
801 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
802 | + * request Primarily used by unit tests. |
|
803 | + * |
|
804 | + * @throws InvalidDataTypeException |
|
805 | + * @throws InvalidInterfaceException |
|
806 | + * @throws InvalidArgumentException |
|
807 | + */ |
|
808 | + public function reset() |
|
809 | + { |
|
810 | + $this->_register_core_class_loaders(); |
|
811 | + $this->_register_core_dependencies(); |
|
812 | + } |
|
813 | 813 | |
814 | 814 | |
815 | 815 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; |
5 | 5 | use EventEspresso\core\services\loaders\LoaderInterface; |
6 | 6 | |
7 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
8 | 8 | exit('No direct script access allowed'); |
9 | 9 | } |
10 | 10 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
131 | 131 | { |
132 | 132 | // check if class object is instantiated, and instantiated properly |
133 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
134 | 134 | self::$_instance = new EE_Dependency_Map($request, $response); |
135 | 135 | } |
136 | 136 | return self::$_instance; |
@@ -185,16 +185,16 @@ discard block |
||
185 | 185 | ) { |
186 | 186 | $class = trim($class, '\\'); |
187 | 187 | $registered = false; |
188 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
189 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
188 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
189 | + self::$_instance->_dependency_map[$class] = array(); |
|
190 | 190 | } |
191 | 191 | // we need to make sure that any aliases used when registering a dependency |
192 | 192 | // get resolved to the correct class name |
193 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
193 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
194 | 194 | $alias = self::$_instance->get_alias($dependency); |
195 | 195 | if ( |
196 | 196 | $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
197 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
197 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
198 | 198 | ) { |
199 | 199 | unset($dependencies[$dependency]); |
200 | 200 | $dependencies[$alias] = $load_source; |
@@ -207,13 +207,13 @@ discard block |
||
207 | 207 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
208 | 208 | // Union is way faster than array_merge() but should be used with caution... |
209 | 209 | // especially with numerically indexed arrays |
210 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
210 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
211 | 211 | // now we need to ensure that the resulting dependencies |
212 | 212 | // array only has the entries that are required for the class |
213 | 213 | // so first count how many dependencies were originally registered for the class |
214 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
214 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
215 | 215 | // if that count is non-zero (meaning dependencies were already registered) |
216 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
216 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
217 | 217 | // then truncate the final array to match that count |
218 | 218 | ? array_slice($dependencies, 0, $dependency_count) |
219 | 219 | // otherwise just take the incoming array because nothing previously existed |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | */ |
232 | 232 | public static function register_class_loader($class_name, $loader = 'load_core') |
233 | 233 | { |
234 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
234 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
235 | 235 | throw new DomainException( |
236 | 236 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
237 | 237 | ); |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | ); |
256 | 256 | } |
257 | 257 | $class_name = self::$_instance->get_alias($class_name); |
258 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
258 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
259 | 259 | self::$_instance->_class_loaders[$class_name] = $loader; |
260 | 260 | return true; |
261 | 261 | } |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | public function class_loader($class_name) |
341 | 341 | { |
342 | 342 | // all legacy models use load_model() |
343 | - if(strpos($class_name, 'EEM_') === 0){ |
|
343 | + if (strpos($class_name, 'EEM_') === 0) { |
|
344 | 344 | return 'load_model'; |
345 | 345 | } |
346 | 346 | $class_name = $this->get_alias($class_name); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | public function add_alias($class_name, $alias, $for_class = '') |
370 | 370 | { |
371 | 371 | if ($for_class !== '') { |
372 | - if (! isset($this->_aliases[$for_class])) { |
|
372 | + if ( ! isset($this->_aliases[$for_class])) { |
|
373 | 373 | $this->_aliases[$for_class] = array(); |
374 | 374 | } |
375 | 375 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -415,10 +415,10 @@ discard block |
||
415 | 415 | */ |
416 | 416 | public function get_alias($class_name = '', $for_class = '') |
417 | 417 | { |
418 | - if (! $this->has_alias($class_name, $for_class)) { |
|
418 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
419 | 419 | return $class_name; |
420 | 420 | } |
421 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
421 | + if ($for_class !== '' && isset($this->_aliases[$for_class][$class_name])) { |
|
422 | 422 | return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
423 | 423 | } |
424 | 424 | return $this->get_alias($this->_aliases[$class_name]); |
@@ -679,10 +679,10 @@ discard block |
||
679 | 679 | 'EE_Front_Controller' => 'load_core', |
680 | 680 | 'EE_Module_Request_Router' => 'load_core', |
681 | 681 | 'EE_Registry' => 'load_core', |
682 | - 'EE_Request' => function () use (&$request) { |
|
682 | + 'EE_Request' => function() use (&$request) { |
|
683 | 683 | return $request; |
684 | 684 | }, |
685 | - 'EE_Response' => function () use (&$response) { |
|
685 | + 'EE_Response' => function() use (&$response) { |
|
686 | 686 | return $response; |
687 | 687 | }, |
688 | 688 | 'EE_Request_Handler' => 'load_core', |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
705 | 705 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
706 | 706 | 'EE_Payment_Method_Manager' => 'load_lib', |
707 | - 'EE_Messages_Generator' => function () { |
|
707 | + 'EE_Messages_Generator' => function() { |
|
708 | 708 | return EE_Registry::instance()->load_lib( |
709 | 709 | 'Messages_Generator', |
710 | 710 | array(), |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | false |
713 | 713 | ); |
714 | 714 | }, |
715 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
715 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
716 | 716 | return EE_Registry::instance()->load_lib( |
717 | 717 | 'Messages_Template_Defaults', |
718 | 718 | $arguments, |
@@ -725,22 +725,22 @@ discard block |
||
725 | 725 | // 'EEM_Message_Template_Group' => 'load_model', |
726 | 726 | // 'EEM_Message_Template' => 'load_model', |
727 | 727 | //load_helper |
728 | - 'EEH_Parse_Shortcodes' => function () { |
|
728 | + 'EEH_Parse_Shortcodes' => function() { |
|
729 | 729 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
730 | 730 | return new EEH_Parse_Shortcodes(); |
731 | 731 | } |
732 | 732 | return null; |
733 | 733 | }, |
734 | - 'EE_Template_Config' => function () { |
|
734 | + 'EE_Template_Config' => function() { |
|
735 | 735 | return EE_Config::instance()->template_settings; |
736 | 736 | }, |
737 | - 'EE_Currency_Config' => function () { |
|
737 | + 'EE_Currency_Config' => function() { |
|
738 | 738 | return EE_Config::instance()->currency; |
739 | 739 | }, |
740 | - 'EE_Registration_Config' => function () { |
|
740 | + 'EE_Registration_Config' => function() { |
|
741 | 741 | return EE_Config::instance()->registration; |
742 | 742 | }, |
743 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
743 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
744 | 744 | return LoaderFactory::getLoader(); |
745 | 745 | }, |
746 | 746 | ); |
@@ -22,163 +22,163 @@ |
||
22 | 22 | class EE_Register_Payment_Method implements EEI_Plugin_API |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Holds values for registered payment methods |
|
27 | - * |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - protected static $_settings = array(); |
|
31 | - |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Method for registering new EE_PMT_Base children |
|
36 | - * |
|
37 | - * @since 4.5.0 |
|
38 | - * @param string $payment_method_id a unique identifier for this set of modules Required. |
|
39 | - * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
40 | - * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
41 | - * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
42 | - * the files EE_PMT_Payomatic.pm.php) |
|
43 | - * } |
|
44 | - * @throws EE_Error |
|
45 | - * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
46 | - * children, or to the EED_Module files themselves |
|
47 | - * @return void |
|
48 | - * @throws InvalidDataTypeException |
|
49 | - * @throws DomainException |
|
50 | - * @throws InvalidArgumentException |
|
51 | - * @throws InvalidInterfaceException |
|
52 | - * @throws InvalidDataTypeException |
|
53 | - */ |
|
54 | - public static function register($payment_method_id = null, $setup_args = array()) |
|
55 | - { |
|
56 | - //required fields MUST be present, so let's make sure they are. |
|
57 | - if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
58 | - throw new EE_Error( |
|
59 | - esc_html__( |
|
60 | - 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
61 | - 'event_espresso' |
|
62 | - ) |
|
63 | - ); |
|
64 | - } |
|
65 | - //make sure we don't register twice |
|
66 | - if (isset(self::$_settings[$payment_method_id])) { |
|
67 | - return; |
|
68 | - } |
|
69 | - //make sure this was called in the right place! |
|
70 | - if ( |
|
71 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
72 | - || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
73 | - ) { |
|
74 | - EE_Error::doing_it_wrong( |
|
75 | - __METHOD__, |
|
76 | - esc_html__( |
|
77 | - 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
78 | - 'event_espresso' |
|
79 | - ), |
|
80 | - '4.3.0' |
|
81 | - ); |
|
82 | - } |
|
83 | - //setup $_settings array from incoming values. |
|
84 | - self::$_settings[$payment_method_id] = array( |
|
85 | - // array of full server paths to any EE_PMT_Base children used |
|
86 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
87 | - ? (array)$setup_args['payment_method_paths'] |
|
88 | - : array(), |
|
89 | - ); |
|
90 | - // add to list of modules to be registered |
|
91 | - add_filter( |
|
92 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
93 | - array('EE_Register_Payment_Method', 'add_payment_methods') |
|
94 | - ); |
|
95 | - // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
96 | - // then we need to add our caps for this payment method manually |
|
97 | - if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
98 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
99 | - // register payment methods directly |
|
100 | - foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) { |
|
101 | - $payment_method_manager->register_payment_method($payment_method_path); |
|
102 | - } |
|
103 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
104 | - $capabilities->addCaps( |
|
105 | - self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id]) |
|
106 | - ); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Filters the list of payment methods to add ours. |
|
114 | - * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
115 | - * |
|
116 | - * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - public static function add_payment_methods($payment_method_folders) |
|
120 | - { |
|
121 | - foreach (self::$_settings as $settings) { |
|
122 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
123 | - $payment_method_folders[] = $payment_method_path; |
|
124 | - } |
|
125 | - } |
|
126 | - return $payment_method_folders; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * This deregisters a module that was previously registered with a specific $module_id. |
|
133 | - * |
|
134 | - * @since 4.3.0 |
|
135 | - * |
|
136 | - * @param string $module_id the name for the module that was previously registered |
|
137 | - * @return void |
|
138 | - * @throws DomainException |
|
139 | - * @throws EE_Error |
|
140 | - * @throws InvalidArgumentException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - * @throws InvalidDataTypeException |
|
143 | - */ |
|
144 | - public static function deregister($module_id = null) |
|
145 | - { |
|
146 | - if (isset(self::$_settings[$module_id])) { |
|
147 | - $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
148 | - $capabilities->removeCaps( |
|
149 | - self::getPaymentMethodCapabilities(self::$_settings[$module_id]) |
|
150 | - ); |
|
151 | - unset(self::$_settings[$module_id]); |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * returns an array of the caps that get added when a Payment Method is registered |
|
159 | - * |
|
160 | - * @param array $settings |
|
161 | - * @return array |
|
162 | - * @throws DomainException |
|
163 | - * @throws EE_Error |
|
164 | - * @throws InvalidArgumentException |
|
165 | - * @throws InvalidInterfaceException |
|
166 | - * @throws InvalidDataTypeException |
|
167 | - */ |
|
168 | - private static function getPaymentMethodCapabilities(array $settings) |
|
169 | - { |
|
170 | - $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
171 | - $payment_method_caps = array('administrator' => array()); |
|
172 | - if (isset($settings['payment_method_paths'])) { |
|
173 | - foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
174 | - $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
175 | - strtolower(basename($payment_method_path)), |
|
176 | - $payment_method_caps |
|
177 | - ); |
|
178 | - } |
|
179 | - } |
|
180 | - return $payment_method_caps; |
|
181 | - } |
|
25 | + /** |
|
26 | + * Holds values for registered payment methods |
|
27 | + * |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + protected static $_settings = array(); |
|
31 | + |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Method for registering new EE_PMT_Base children |
|
36 | + * |
|
37 | + * @since 4.5.0 |
|
38 | + * @param string $payment_method_id a unique identifier for this set of modules Required. |
|
39 | + * @param array $setup_args an array of arguments provided for registering modules Required.{ |
|
40 | + * @type string[] $payment_method_paths each element is the folder containing the EE_PMT_Base child class |
|
41 | + * (eg, 'public_html/wp-content/plugins/my_plugin/Payomatic/' which contains |
|
42 | + * the files EE_PMT_Payomatic.pm.php) |
|
43 | + * } |
|
44 | + * @throws EE_Error |
|
45 | + * @type array payment_method_paths an array of full server paths to folders containing any EE_PMT_Base |
|
46 | + * children, or to the EED_Module files themselves |
|
47 | + * @return void |
|
48 | + * @throws InvalidDataTypeException |
|
49 | + * @throws DomainException |
|
50 | + * @throws InvalidArgumentException |
|
51 | + * @throws InvalidInterfaceException |
|
52 | + * @throws InvalidDataTypeException |
|
53 | + */ |
|
54 | + public static function register($payment_method_id = null, $setup_args = array()) |
|
55 | + { |
|
56 | + //required fields MUST be present, so let's make sure they are. |
|
57 | + if (empty($payment_method_id) || ! is_array($setup_args) || empty($setup_args['payment_method_paths'])) { |
|
58 | + throw new EE_Error( |
|
59 | + esc_html__( |
|
60 | + 'In order to register Payment Methods with EE_Register_Payment_Method::register(), you must include a "payment_method_id" (a unique identifier for this set of modules), and an array containing the following keys: "payment_method_paths" (an array of full server paths to folders that contain modules, or to the module files themselves)', |
|
61 | + 'event_espresso' |
|
62 | + ) |
|
63 | + ); |
|
64 | + } |
|
65 | + //make sure we don't register twice |
|
66 | + if (isset(self::$_settings[$payment_method_id])) { |
|
67 | + return; |
|
68 | + } |
|
69 | + //make sure this was called in the right place! |
|
70 | + if ( |
|
71 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
72 | + || did_action('AHEE__EE_System__register_shortcodes_modules_and_widgets') |
|
73 | + ) { |
|
74 | + EE_Error::doing_it_wrong( |
|
75 | + __METHOD__, |
|
76 | + esc_html__( |
|
77 | + 'An attempt to register modules has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__register_shortcodes_modules_and_widgets" hook to register modules.', |
|
78 | + 'event_espresso' |
|
79 | + ), |
|
80 | + '4.3.0' |
|
81 | + ); |
|
82 | + } |
|
83 | + //setup $_settings array from incoming values. |
|
84 | + self::$_settings[$payment_method_id] = array( |
|
85 | + // array of full server paths to any EE_PMT_Base children used |
|
86 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
87 | + ? (array)$setup_args['payment_method_paths'] |
|
88 | + : array(), |
|
89 | + ); |
|
90 | + // add to list of modules to be registered |
|
91 | + add_filter( |
|
92 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
93 | + array('EE_Register_Payment_Method', 'add_payment_methods') |
|
94 | + ); |
|
95 | + // If EE_Payment_Method_Manager::register_payment_methods has already been called, |
|
96 | + // then we need to add our caps for this payment method manually |
|
97 | + if (did_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods')) { |
|
98 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
99 | + // register payment methods directly |
|
100 | + foreach (self::$_settings[$payment_method_id]['payment_method_paths'] as $payment_method_path) { |
|
101 | + $payment_method_manager->register_payment_method($payment_method_path); |
|
102 | + } |
|
103 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
104 | + $capabilities->addCaps( |
|
105 | + self::getPaymentMethodCapabilities(self::$_settings[$payment_method_id]) |
|
106 | + ); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Filters the list of payment methods to add ours. |
|
114 | + * and they're just full filepaths to FOLDERS containing a payment method class file. Eg. |
|
115 | + * |
|
116 | + * @param array $payment_method_folders array of paths to all payment methods that require registering |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + public static function add_payment_methods($payment_method_folders) |
|
120 | + { |
|
121 | + foreach (self::$_settings as $settings) { |
|
122 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
123 | + $payment_method_folders[] = $payment_method_path; |
|
124 | + } |
|
125 | + } |
|
126 | + return $payment_method_folders; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * This deregisters a module that was previously registered with a specific $module_id. |
|
133 | + * |
|
134 | + * @since 4.3.0 |
|
135 | + * |
|
136 | + * @param string $module_id the name for the module that was previously registered |
|
137 | + * @return void |
|
138 | + * @throws DomainException |
|
139 | + * @throws EE_Error |
|
140 | + * @throws InvalidArgumentException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + * @throws InvalidDataTypeException |
|
143 | + */ |
|
144 | + public static function deregister($module_id = null) |
|
145 | + { |
|
146 | + if (isset(self::$_settings[$module_id])) { |
|
147 | + $capabilities = LoaderFactory::getLoader()->getShared('EE_Capabilities'); |
|
148 | + $capabilities->removeCaps( |
|
149 | + self::getPaymentMethodCapabilities(self::$_settings[$module_id]) |
|
150 | + ); |
|
151 | + unset(self::$_settings[$module_id]); |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * returns an array of the caps that get added when a Payment Method is registered |
|
159 | + * |
|
160 | + * @param array $settings |
|
161 | + * @return array |
|
162 | + * @throws DomainException |
|
163 | + * @throws EE_Error |
|
164 | + * @throws InvalidArgumentException |
|
165 | + * @throws InvalidInterfaceException |
|
166 | + * @throws InvalidDataTypeException |
|
167 | + */ |
|
168 | + private static function getPaymentMethodCapabilities(array $settings) |
|
169 | + { |
|
170 | + $payment_method_manager = LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
171 | + $payment_method_caps = array('administrator' => array()); |
|
172 | + if (isset($settings['payment_method_paths'])) { |
|
173 | + foreach ($settings['payment_method_paths'] as $payment_method_path) { |
|
174 | + $payment_method_caps = $payment_method_manager->addPaymentMethodCap( |
|
175 | + strtolower(basename($payment_method_path)), |
|
176 | + $payment_method_caps |
|
177 | + ); |
|
178 | + } |
|
179 | + } |
|
180 | + return $payment_method_caps; |
|
181 | + } |
|
182 | 182 | |
183 | 183 | } |
184 | 184 | // End of file EE_Register_Payment_Method.lib.php |
@@ -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 | |
@@ -26,10 +26,10 @@ discard block |
||
26 | 26 | * classname to create an alternative index for retrieving data_handlers. |
27 | 27 | * @return bool |
28 | 28 | */ |
29 | - public function add( $data_handler, $data = null) { |
|
29 | + public function add($data_handler, $data = null) { |
|
30 | 30 | $data = $data === null ? array() : (array) $data; |
31 | - $info['key'] = $this->get_key( get_class( $data_handler ), $data ); |
|
32 | - return parent::add( $data_handler, $info ); |
|
31 | + $info['key'] = $this->get_key(get_class($data_handler), $data); |
|
32 | + return parent::add($data_handler, $info); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return string md5 hash using provided info. |
46 | 46 | */ |
47 | - public function get_key( $classname, $data ) { |
|
48 | - return md5( $classname . serialize( $data ) ); |
|
47 | + public function get_key($classname, $data) { |
|
48 | + return md5($classname.serialize($data)); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | * |
62 | 62 | * @return null|EE_Messages_incoming_data |
63 | 63 | */ |
64 | - public function get_by_key( $key ) { |
|
64 | + public function get_by_key($key) { |
|
65 | 65 | $this->rewind(); |
66 | - while( $this->valid() ) { |
|
66 | + while ($this->valid()) { |
|
67 | 67 | $data = $this->getInfo(); |
68 | - if ( isset( $data['key'] ) && $data['key'] === $key ) { |
|
68 | + if (isset($data['key']) && $data['key'] === $key) { |
|
69 | 69 | $handler = $this->current(); |
70 | 70 | $this->rewind(); |
71 | 71 | return $handler; |
@@ -14,254 +14,254 @@ |
||
14 | 14 | class MessagesAdmin extends CoreAdmin |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Context slug for the admin messages context. |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - const ADMIN_CONTEXT_SLUG = 'admin'; |
|
17 | + /** |
|
18 | + * Context slug for the admin messages context. |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + const ADMIN_CONTEXT_SLUG = 'admin'; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Context slug for the primary attendee messages context |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
23 | + /** |
|
24 | + * Context slug for the primary attendee messages context |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + const PRIMARY_ATTENDEE_CONTEXT_SLUG = 'primary_attendee'; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * Status reference for the EEM_Message::status_sent status. |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - const MESSAGE_STATUS_SENT = 'MSN'; |
|
30 | + /** |
|
31 | + * Status reference for the EEM_Message::status_sent status. |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + const MESSAGE_STATUS_SENT = 'MSN'; |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Message type slug for the Payment Failed message type |
|
39 | - */ |
|
40 | - const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
37 | + /** |
|
38 | + * Message type slug for the Payment Failed message type |
|
39 | + */ |
|
40 | + const PAYMENT_FAILED_MESSAGE_TYPE_SLUG = 'payment_failed'; |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = |
|
48 | - '#global_messages_settings-do-messages-on-same-request'; |
|
49 | - |
|
43 | + /** |
|
44 | + * Selector for the Global Messages "Send on same request" field in the Messages Settings tab. |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + const GLOBAL_MESSAGES_SETTINGS_ON_REQUEST_SELECTION_SELECTOR = |
|
48 | + '#global_messages_settings-do-messages-on-same-request'; |
|
49 | + |
|
50 | 50 | |
51 | - /** |
|
52 | - * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * This is the container where active message types for a messenger are found/dragged to. |
|
60 | - * @var string |
|
61 | - */ |
|
62 | - const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Locator for the context switcher selector on the Message Template Editor page. |
|
67 | - * @var string |
|
68 | - */ |
|
69 | - const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select"; |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Locator for the context switcher submit button in the Message Template Editor page. |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt"; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Locator for the dialog container used for housing viewed messages in the message activity list table. |
|
81 | - * @var string |
|
82 | - */ |
|
83 | - const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content'; |
|
84 | - |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
89 | - * a string. |
|
90 | - * @return string |
|
91 | - */ |
|
92 | - public static function messageActivityListTableUrl($additional_params = '') |
|
93 | - { |
|
94 | - return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
100 | - * a string. |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
104 | - { |
|
105 | - return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
111 | - * a string. |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public static function customMessageTemplateListTableUrl($additional_params = '') |
|
115 | - { |
|
116 | - return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public static function messageSettingsUrl() |
|
124 | - { |
|
125 | - return self::adminUrl('espresso_messages', 'settings'); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
131 | - $message_type_slug, |
|
132 | - $messenger_slug = 'email' |
|
133 | - ) { |
|
134 | - return "#$message_type_slug-messagetype-$messenger_slug"; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @param string $message_type_slug |
|
140 | - * @param string $context |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
144 | - { |
|
145 | - return $context |
|
146 | - ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
147 | - : '.' . $message_type_slug . '-edit-link'; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
153 | - * |
|
154 | - * @param $field |
|
155 | - * @param $message_type_label |
|
156 | - * @param string $message_status |
|
157 | - * @param string $messenger |
|
158 | - * @param string $context |
|
159 | - * @param string $table_cell_content_for_field |
|
160 | - * @param int $number_in_set It's possible that the given parameters could match multiple items in the view. |
|
161 | - * This allows you to indicate which item from the set to match. If this is set to 0 |
|
162 | - * then all matches for the locator will be returned. |
|
163 | - * @return string |
|
164 | - */ |
|
165 | - public static function messagesActivityListTableCellSelectorFor( |
|
166 | - $field, |
|
167 | - $message_type_label, |
|
168 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
169 | - $messenger = 'Email', |
|
170 | - $context = 'Event Admin', |
|
171 | - $table_cell_content_for_field = '', |
|
172 | - $number_in_set = 1 |
|
173 | - ) { |
|
174 | - $selector = "//tbody[@id='the-list']"; |
|
175 | - $selector .= "//tr[contains(@class, 'msg-status-$message_status')]" |
|
176 | - . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
177 | - if ($messenger) { |
|
178 | - $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
179 | - } |
|
180 | - $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
181 | - $selector .= $table_cell_content_for_field |
|
182 | - ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
183 | - : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
184 | - return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Selector for the Create Custom button found in the message template list table. |
|
190 | - * @param string $message_type_label |
|
191 | - * @param string $messenger_label |
|
192 | - * @return string |
|
193 | - */ |
|
194 | - public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label) |
|
195 | - { |
|
196 | - $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']" |
|
197 | - . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]" |
|
198 | - . "//ancestor::tr/td/a[@class='button button-small']"; |
|
199 | - return $selector; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to |
|
205 | - * the FIRST match (which will be the latest message sent if the table is default sorted). |
|
206 | - * |
|
207 | - * @param string $message_type_label The visible message type label for the row you want to match |
|
208 | - * @param string $message_status The status of the message for the row you want to match. |
|
209 | - * @param string $messenger The visible messenger label for the row you want to match. |
|
210 | - * @param string $context The visible context label for the row you want to match. |
|
211 | - * @param int $number_in_set It's possible that the given parameters could match multiple items in the |
|
212 | - * view. This allows you to indicate which item from the set to match. |
|
213 | - * @return string |
|
214 | - */ |
|
215 | - public static function messagesActivityListTableViewButtonSelectorFor( |
|
216 | - $message_type_label, |
|
217 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
218 | - $messenger = 'Email', |
|
219 | - $context = 'Event Admin', |
|
220 | - $number_in_set = 1 |
|
221 | - ) { |
|
222 | - $selector = self::messagesActivityListTableCellSelectorFor( |
|
223 | - 'action', |
|
224 | - $message_type_label, |
|
225 | - $message_status, |
|
226 | - $messenger, |
|
227 | - $context, |
|
228 | - '', |
|
229 | - $number_in_set |
|
230 | - ); |
|
231 | - $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')" |
|
232 | - . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]"; |
|
233 | - return $selector; |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Locator for the delete action link for a message item in the message activity list table. |
|
240 | - * Note: The link is not visible by default, so the column would need hovered over for the link to appear. |
|
241 | - * @param $message_type_label |
|
242 | - * @param string $message_status |
|
243 | - * @param string $messenger |
|
244 | - * @param string $context |
|
245 | - * @param int $number_in_set |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public static function messagesActivityListTableDeleteActionSelectorFor( |
|
249 | - $message_type_label, |
|
250 | - $message_status = self::MESSAGE_STATUS_SENT, |
|
251 | - $messenger = 'Email', |
|
252 | - $context = 'Event Admin', |
|
253 | - $number_in_set = 1 |
|
254 | - ) { |
|
255 | - $selector = self::messagesActivityListTableCellSelectorFor( |
|
256 | - 'to', |
|
257 | - $message_type_label, |
|
258 | - $message_status, |
|
259 | - $messenger, |
|
260 | - $context, |
|
261 | - '', |
|
262 | - $number_in_set |
|
263 | - ); |
|
264 | - $selector .= "/div/span[@class='delete']/a"; |
|
265 | - return $selector; |
|
266 | - } |
|
51 | + /** |
|
52 | + * Selector for the Global Messages Settings submit button in the Messages Settings tab. |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + const GLOBAL_MESSAGES_SETTINGS_SUBMIT_SELECTOR = '#global_messages_settings-update-settings-submit'; |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * This is the container where active message types for a messenger are found/dragged to. |
|
60 | + * @var string |
|
61 | + */ |
|
62 | + const MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR = '#active-message-types'; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Locator for the context switcher selector on the Message Template Editor page. |
|
67 | + * @var string |
|
68 | + */ |
|
69 | + const MESSAGES_CONTEXT_SWITCHER_SELECTOR = "//form[@id='ee-msg-context-switcher-frm']/select"; |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Locator for the context switcher submit button in the Message Template Editor page. |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + const MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR = "#submit-msg-context-switcher-sbmt"; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Locator for the dialog container used for housing viewed messages in the message activity list table. |
|
81 | + * @var string |
|
82 | + */ |
|
83 | + const MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR = '.ee-admin-dialog-container-inner-content'; |
|
84 | + |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
89 | + * a string. |
|
90 | + * @return string |
|
91 | + */ |
|
92 | + public static function messageActivityListTableUrl($additional_params = '') |
|
93 | + { |
|
94 | + return self::adminUrl('espresso_messages', 'default', $additional_params); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
100 | + * a string. |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public static function defaultMessageTemplateListTableUrl($additional_params = '') |
|
104 | + { |
|
105 | + return self::adminUrl('espresso_messages', 'global_mtps', $additional_params); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
111 | + * a string. |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public static function customMessageTemplateListTableUrl($additional_params = '') |
|
115 | + { |
|
116 | + return self::adminUrl('espresso_messages', 'custom_mtps', $additional_params); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public static function messageSettingsUrl() |
|
124 | + { |
|
125 | + return self::adminUrl('espresso_messages', 'settings'); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + public static function draggableSettingsBoxSelectorForMessageTypeAndMessenger( |
|
131 | + $message_type_slug, |
|
132 | + $messenger_slug = 'email' |
|
133 | + ) { |
|
134 | + return "#$message_type_slug-messagetype-$messenger_slug"; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @param string $message_type_slug |
|
140 | + * @param string $context |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public static function editMessageTemplateClassByMessageType($message_type_slug, $context = '') |
|
144 | + { |
|
145 | + return $context |
|
146 | + ? '.' . $message_type_slug . '-' . $context . '-edit-link' |
|
147 | + : '.' . $message_type_slug . '-edit-link'; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Selector for (a) specific table cell(s) in the Messages Activity list table for the given parameters. |
|
153 | + * |
|
154 | + * @param $field |
|
155 | + * @param $message_type_label |
|
156 | + * @param string $message_status |
|
157 | + * @param string $messenger |
|
158 | + * @param string $context |
|
159 | + * @param string $table_cell_content_for_field |
|
160 | + * @param int $number_in_set It's possible that the given parameters could match multiple items in the view. |
|
161 | + * This allows you to indicate which item from the set to match. If this is set to 0 |
|
162 | + * then all matches for the locator will be returned. |
|
163 | + * @return string |
|
164 | + */ |
|
165 | + public static function messagesActivityListTableCellSelectorFor( |
|
166 | + $field, |
|
167 | + $message_type_label, |
|
168 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
169 | + $messenger = 'Email', |
|
170 | + $context = 'Event Admin', |
|
171 | + $table_cell_content_for_field = '', |
|
172 | + $number_in_set = 1 |
|
173 | + ) { |
|
174 | + $selector = "//tbody[@id='the-list']"; |
|
175 | + $selector .= "//tr[contains(@class, 'msg-status-$message_status')]" |
|
176 | + . "//td[contains(@class, 'message_type') and text()='$message_type_label']"; |
|
177 | + if ($messenger) { |
|
178 | + $selector .= "/ancestor::tr/td[contains(@class, 'messenger') and text()='$messenger']"; |
|
179 | + } |
|
180 | + $selector .= "/ancestor::tr/td[contains(@class, 'column-context') and text()='$context']"; |
|
181 | + $selector .= $table_cell_content_for_field |
|
182 | + ? "/ancestor::tr/td[contains(@class, 'column-$field') and text()='$table_cell_content_for_field']" |
|
183 | + : "/ancestor::tr/td[contains(@class, 'column-$field')]"; |
|
184 | + return $number_in_set > 0 ? Locator::elementAt($selector, $number_in_set) : $selector; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Selector for the Create Custom button found in the message template list table. |
|
190 | + * @param string $message_type_label |
|
191 | + * @param string $messenger_label |
|
192 | + * @return string |
|
193 | + */ |
|
194 | + public static function createCustomButtonForMessageTypeAndMessenger($message_type_label, $messenger_label) |
|
195 | + { |
|
196 | + $selector = "//tr/td[contains(@class, 'message_type') and text()='$message_type_label']" |
|
197 | + . "//ancestor::tr/td[contains(@class, 'messenger') and contains(., '$messenger_label')]" |
|
198 | + . "//ancestor::tr/td/a[@class='button button-small']"; |
|
199 | + return $selector; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Note, this could potentially match multiple buttons in the view so the selector is intentionally restricted to |
|
205 | + * the FIRST match (which will be the latest message sent if the table is default sorted). |
|
206 | + * |
|
207 | + * @param string $message_type_label The visible message type label for the row you want to match |
|
208 | + * @param string $message_status The status of the message for the row you want to match. |
|
209 | + * @param string $messenger The visible messenger label for the row you want to match. |
|
210 | + * @param string $context The visible context label for the row you want to match. |
|
211 | + * @param int $number_in_set It's possible that the given parameters could match multiple items in the |
|
212 | + * view. This allows you to indicate which item from the set to match. |
|
213 | + * @return string |
|
214 | + */ |
|
215 | + public static function messagesActivityListTableViewButtonSelectorFor( |
|
216 | + $message_type_label, |
|
217 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
218 | + $messenger = 'Email', |
|
219 | + $context = 'Event Admin', |
|
220 | + $number_in_set = 1 |
|
221 | + ) { |
|
222 | + $selector = self::messagesActivityListTableCellSelectorFor( |
|
223 | + 'action', |
|
224 | + $message_type_label, |
|
225 | + $message_status, |
|
226 | + $messenger, |
|
227 | + $context, |
|
228 | + '', |
|
229 | + $number_in_set |
|
230 | + ); |
|
231 | + $selector .= "/a/span[contains(@class, 'ee-message-action-link-view')" |
|
232 | + . " and not(contains(@class, 'ee-message-action-link-view_transaction'))]"; |
|
233 | + return $selector; |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Locator for the delete action link for a message item in the message activity list table. |
|
240 | + * Note: The link is not visible by default, so the column would need hovered over for the link to appear. |
|
241 | + * @param $message_type_label |
|
242 | + * @param string $message_status |
|
243 | + * @param string $messenger |
|
244 | + * @param string $context |
|
245 | + * @param int $number_in_set |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public static function messagesActivityListTableDeleteActionSelectorFor( |
|
249 | + $message_type_label, |
|
250 | + $message_status = self::MESSAGE_STATUS_SENT, |
|
251 | + $messenger = 'Email', |
|
252 | + $context = 'Event Admin', |
|
253 | + $number_in_set = 1 |
|
254 | + ) { |
|
255 | + $selector = self::messagesActivityListTableCellSelectorFor( |
|
256 | + 'to', |
|
257 | + $message_type_label, |
|
258 | + $message_status, |
|
259 | + $messenger, |
|
260 | + $context, |
|
261 | + '', |
|
262 | + $number_in_set |
|
263 | + ); |
|
264 | + $selector .= "/div/span[@class='delete']/a"; |
|
265 | + return $selector; |
|
266 | + } |
|
267 | 267 | } |
268 | 268 | \ No newline at end of file |
@@ -18,14 +18,14 @@ discard block |
||
18 | 18 | $event_one_link = $event_two_link = $event_three_link = ''; |
19 | 19 | |
20 | 20 | $I->wantTo( |
21 | - 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
22 | - . 'template, that that custom template will be used.' |
|
21 | + 'Test that when registrations for multiple events are completed, and those events share the same custom' |
|
22 | + . 'template, that that custom template will be used.' |
|
23 | 23 | ); |
24 | 24 | |
25 | 25 | //need the MER plugin active for this test (we'll deactivate it after). |
26 | 26 | $I->ensurePluginActive( |
27 | - 'event-espresso-mer-multi-event-registration', |
|
28 | - 'activated' |
|
27 | + 'event-espresso-mer-multi-event-registration', |
|
28 | + 'activated' |
|
29 | 29 | ); |
30 | 30 | |
31 | 31 | $I->loginAsAdmin(); |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | |
84 | 84 | |
85 | 85 | $test_registration_details = array( |
86 | - 'fname' => 'CTGuy', |
|
87 | - 'lname' => 'Dude', |
|
88 | - 'email' => '[email protected]' |
|
86 | + 'fname' => 'CTGuy', |
|
87 | + 'lname' => 'Dude', |
|
88 | + 'email' => '[email protected]' |
|
89 | 89 | ); |
90 | 90 | |
91 | 91 | $I->amGoingTo('Register for Event One and Event Two and verify Custom Template A was used.'); |
@@ -111,23 +111,23 @@ discard block |
||
111 | 111 | $I->loginAsAdmin(); |
112 | 112 | $I->amOnMessagesActivityListTablePage(); |
113 | 113 | $I->viewMessageInMessagesListTableFor( |
114 | - 'Registration Approved', |
|
115 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
116 | - 'Email', |
|
117 | - 'Registrant' |
|
114 | + 'Registration Approved', |
|
115 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
116 | + 'Email', |
|
117 | + 'Registrant' |
|
118 | 118 | ); |
119 | 119 | $I->seeTextInViewMessageModal($custom_template_a_label); |
120 | 120 | $I->dismissMessageModal(); |
121 | 121 | $I->deleteMessageInMessagesListTableFor( |
122 | - 'Registration Approved', |
|
123 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
124 | - 'Email', |
|
125 | - 'Registrant' |
|
122 | + 'Registration Approved', |
|
123 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
124 | + 'Email', |
|
125 | + 'Registrant' |
|
126 | 126 | ); |
127 | 127 | |
128 | 128 | //verify admin context |
129 | 129 | $I->viewMessageInMessagesListTableFor( |
130 | - 'Registration Approved' |
|
130 | + 'Registration Approved' |
|
131 | 131 | ); |
132 | 132 | $I->seeTextInViewMessageModal($custom_template_a_label); |
133 | 133 | $I->dismissMessageModal(); |
@@ -156,25 +156,25 @@ discard block |
||
156 | 156 | $I->loginAsAdmin(); |
157 | 157 | $I->amOnMessagesActivityListTablePage(); |
158 | 158 | $I->viewMessageInMessagesListTableFor( |
159 | - 'Registration Approved', |
|
160 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
161 | - 'Email', |
|
162 | - 'Registrant' |
|
159 | + 'Registration Approved', |
|
160 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
161 | + 'Email', |
|
162 | + 'Registrant' |
|
163 | 163 | ); |
164 | 164 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
165 | 165 | $I->dontSeeTextInViewMessageModal($custom_template_a_label); |
166 | 166 | $I->dontSeeTextInViewMessageModal($custom_template_b_label); |
167 | 167 | $I->dismissMessageModal(); |
168 | 168 | $I->deleteMessageInMessagesListTableFor( |
169 | - 'Registration Approved', |
|
170 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
171 | - 'Email', |
|
172 | - 'Registrant' |
|
169 | + 'Registration Approved', |
|
170 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
171 | + 'Email', |
|
172 | + 'Registrant' |
|
173 | 173 | ); |
174 | 174 | |
175 | 175 | //verify admin context |
176 | 176 | $I->viewMessageInMessagesListTableFor( |
177 | - 'Registration Approved' |
|
177 | + 'Registration Approved' |
|
178 | 178 | ); |
179 | 179 | $I->waitForElementVisible(MessagesAdmin::MESSAGES_LIST_TABLE_VIEW_MESSAGE_DIALOG_CONTAINER_SELECTOR); |
180 | 180 | $I->dontSee($custom_template_a_label); |
@@ -186,6 +186,6 @@ discard block |
||
186 | 186 | |
187 | 187 | //deactivate MER plugin so its not active for future tests |
188 | 188 | $I->ensurePluginDeactivated( |
189 | - 'event-espresso-mer-multi-event-registration', |
|
190 | - 'Plugin deactivated' |
|
189 | + 'event-espresso-mer-multi-event-registration', |
|
190 | + 'Plugin deactivated' |
|
191 | 191 | ); |
192 | 192 | \ No newline at end of file |
@@ -10,242 +10,242 @@ |
||
10 | 10 | */ |
11 | 11 | trait MessagesAdmin |
12 | 12 | { |
13 | - /** |
|
14 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | - * a string. |
|
16 | - */ |
|
17 | - public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | - { |
|
19 | - $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | - } |
|
21 | - |
|
22 | - /** |
|
23 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | - * a string. |
|
25 | - */ |
|
26 | - public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | - { |
|
28 | - $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | - * a string. |
|
35 | - */ |
|
36 | - public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | - { |
|
38 | - $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | - } |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Directs to message settings page |
|
44 | - */ |
|
45 | - public function amOnMessageSettingsPage() |
|
46 | - { |
|
47 | - $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | - } |
|
49 | - |
|
50 | - |
|
51 | - public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | - { |
|
53 | - $this->actor()->dragAndDrop( |
|
54 | - MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | - MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | - ); |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | - * @param string $message_type_slug |
|
63 | - * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | - */ |
|
65 | - public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | - { |
|
67 | - $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | - * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | - * |
|
75 | - * @param int $expected_occurence_count |
|
76 | - * @param string $text_to_check_for |
|
77 | - * @param string $field |
|
78 | - * @param string $message_type_label |
|
79 | - * @param string $message_status |
|
80 | - * @param string $messenger |
|
81 | - * @param string $context |
|
82 | - */ |
|
83 | - public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | - $expected_occurence_count, |
|
85 | - $text_to_check_for, |
|
86 | - $field, |
|
87 | - $message_type_label, |
|
88 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | - $messenger = 'Email', |
|
90 | - $context = 'Event Admin' |
|
91 | - ) { |
|
92 | - $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | - $field, |
|
94 | - $message_type_label, |
|
95 | - $message_status, |
|
96 | - $messenger, |
|
97 | - $context, |
|
98 | - $text_to_check_for, |
|
99 | - 0 |
|
100 | - )); |
|
101 | - $actual_count = count($elements); |
|
102 | - $this->actor()->assertEquals( |
|
103 | - $expected_occurence_count, |
|
104 | - $actual_count, |
|
105 | - sprintf( |
|
106 | - 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | - $expected_occurence_count, |
|
108 | - $text_to_check_for, |
|
109 | - $field, |
|
110 | - $actual_count |
|
111 | - ) |
|
112 | - ); |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - /** |
|
117 | - * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | - * default (global) message template list table. |
|
119 | - * Also takes care of verifying the template was created. |
|
120 | - * @param string $message_type_label |
|
121 | - * @param string $messenger_label |
|
122 | - */ |
|
123 | - public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | - { |
|
125 | - $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | - $this->actor()->click( |
|
127 | - MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | - $message_type_label, |
|
129 | - $messenger_label |
|
130 | - ) |
|
131 | - ); |
|
132 | - $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This switches the context of the current messages template to the given reference. |
|
138 | - * @param string $context_reference This should be the visible label for the option. |
|
139 | - */ |
|
140 | - public function switchContextTo($context_reference) |
|
141 | - { |
|
142 | - $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | - $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | - $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * This takes care of clicking the View Message icon for the given parameters. |
|
150 | - * Assumes you are already viewing the messages activity list table. |
|
151 | - * @param $message_type_label |
|
152 | - * @param $message_status |
|
153 | - * @param string $messenger |
|
154 | - * @param string $context |
|
155 | - * @param int $number_in_set |
|
156 | - */ |
|
157 | - public function viewMessageInMessagesListTableFor( |
|
158 | - $message_type_label, |
|
159 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
160 | - $messenger = 'Email', |
|
161 | - $context = 'Event Admin', |
|
162 | - $number_in_set = 1 |
|
163 | - ) { |
|
164 | - $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
165 | - $message_type_label, |
|
166 | - $message_status, |
|
167 | - $messenger, |
|
168 | - $context, |
|
169 | - $number_in_set |
|
170 | - )); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
176 | - * Assumes you are already viewing the messages activity list table. |
|
177 | - * @param $message_type_label |
|
178 | - * @param $message_status |
|
179 | - * @param string $messenger |
|
180 | - * @param string $context |
|
181 | - * @param int $number_in_set |
|
182 | - */ |
|
183 | - public function deleteMessageInMessagesListTableFor( |
|
184 | - $message_type_label, |
|
185 | - $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
186 | - $messenger = 'Email', |
|
187 | - $context = 'Event Admin', |
|
188 | - $number_in_set = 1 |
|
189 | - ) { |
|
190 | - $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
191 | - $message_type_label, |
|
192 | - $message_status, |
|
193 | - $messenger, |
|
194 | - $context, |
|
195 | - $number_in_set |
|
196 | - ); |
|
197 | - $this->actor()->moveMouseOver( |
|
198 | - MessagesPage::messagesActivityListTableCellSelectorFor( |
|
199 | - 'to', |
|
200 | - $message_type_label, |
|
201 | - $message_status, |
|
202 | - $messenger, |
|
203 | - $context, |
|
204 | - '', |
|
205 | - $number_in_set |
|
206 | - ), |
|
207 | - 5, |
|
208 | - 5 |
|
209 | - ); |
|
210 | - $this->actor()->waitForElementVisible( |
|
211 | - $delete_action_selector |
|
212 | - ); |
|
213 | - $this->actor()->click( |
|
214 | - $delete_action_selector |
|
215 | - ); |
|
216 | - $this->actor()->waitForText('successfully deleted'); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
222 | - * list table, this will take care of validating the given text is in that window. |
|
223 | - * @param string $text_to_view |
|
224 | - */ |
|
225 | - public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
226 | - { |
|
227 | - $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
228 | - $this->actor()->switchToIframe('message-view-window'); |
|
229 | - $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
230 | - $this->actor()->switchToIframe(); |
|
231 | - } |
|
232 | - |
|
233 | - |
|
234 | - /** |
|
235 | - * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
236 | - * list table, this will take care of validating the given text is NOT that window. |
|
237 | - * @param string $text_to_view |
|
238 | - */ |
|
239 | - public function dontSeeTextInViewMessageModal($text_to_view) |
|
240 | - { |
|
241 | - $this->seeTextInViewMessageModal($text_to_view, true); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - public function dismissMessageModal() |
|
246 | - { |
|
247 | - $this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
248 | - //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
249 | - $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
250 | - } |
|
13 | + /** |
|
14 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
15 | + * a string. |
|
16 | + */ |
|
17 | + public function amOnMessagesActivityListTablePage($additional_params = '') |
|
18 | + { |
|
19 | + $this->actor()->amOnAdminPage(MessagesPage::messageActivityListTableUrl($additional_params)); |
|
20 | + } |
|
21 | + |
|
22 | + /** |
|
23 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
24 | + * a string. |
|
25 | + */ |
|
26 | + public function amOnDefaultMessageTemplateListTablePage($additional_params = '') |
|
27 | + { |
|
28 | + $this->actor()->amOnAdminPage(MessagesPage::defaultMessageTemplateListTableUrl($additional_params)); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param string $additional_params Any additional request parameters for the generated url should be included as |
|
34 | + * a string. |
|
35 | + */ |
|
36 | + public function amOnCustomMessageTemplateListTablePage($additional_params = '') |
|
37 | + { |
|
38 | + $this->actor()->amOnAdminPage(MessagesPage::customMessageTemplateListTableUrl($additional_params)); |
|
39 | + } |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Directs to message settings page |
|
44 | + */ |
|
45 | + public function amOnMessageSettingsPage() |
|
46 | + { |
|
47 | + $this->actor()->amOnAdminPage(MessagesPage::messageSettingsUrl()); |
|
48 | + } |
|
49 | + |
|
50 | + |
|
51 | + public function activateMessageTypeForMessenger($message_type_slug, $messenger_slug = 'email') |
|
52 | + { |
|
53 | + $this->actor()->dragAndDrop( |
|
54 | + MessagesPage::draggableSettingsBoxSelectorForMessageTypeAndMessenger($message_type_slug, $messenger_slug), |
|
55 | + MessagesPage::MESSAGES_SETTINGS_ACTIVE_MESSAGE_TYPES_CONTAINER_SELECTOR |
|
56 | + ); |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * Assumes you are already on the list table page that has the ui for editing the template. |
|
62 | + * @param string $message_type_slug |
|
63 | + * @param string $context [optional] if you want to click directly to the given context in the editor |
|
64 | + */ |
|
65 | + public function clickToEditMessageTemplateByMessageType($message_type_slug, $context = '') |
|
66 | + { |
|
67 | + $this->actor()->click(MessagesPage::editMessageTemplateClassByMessageType($message_type_slug, $context)); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * Use this action to verify that the count for the given text in the specified field is as expected. For example |
|
73 | + * filling the condition of, "There should only be 1 instance of `[email protected]` in all the 'to' column. |
|
74 | + * |
|
75 | + * @param int $expected_occurence_count |
|
76 | + * @param string $text_to_check_for |
|
77 | + * @param string $field |
|
78 | + * @param string $message_type_label |
|
79 | + * @param string $message_status |
|
80 | + * @param string $messenger |
|
81 | + * @param string $context |
|
82 | + */ |
|
83 | + public function verifyMatchingCountofTextInMessageActivityListTableFor( |
|
84 | + $expected_occurence_count, |
|
85 | + $text_to_check_for, |
|
86 | + $field, |
|
87 | + $message_type_label, |
|
88 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
89 | + $messenger = 'Email', |
|
90 | + $context = 'Event Admin' |
|
91 | + ) { |
|
92 | + $elements = $this->actor()->grabMultiple(MessagesPage::messagesActivityListTableCellSelectorFor( |
|
93 | + $field, |
|
94 | + $message_type_label, |
|
95 | + $message_status, |
|
96 | + $messenger, |
|
97 | + $context, |
|
98 | + $text_to_check_for, |
|
99 | + 0 |
|
100 | + )); |
|
101 | + $actual_count = count($elements); |
|
102 | + $this->actor()->assertEquals( |
|
103 | + $expected_occurence_count, |
|
104 | + $actual_count, |
|
105 | + sprintf( |
|
106 | + 'Expected %s of the %s text for the %s field but there were actually %s counted.', |
|
107 | + $expected_occurence_count, |
|
108 | + $text_to_check_for, |
|
109 | + $field, |
|
110 | + $actual_count |
|
111 | + ) |
|
112 | + ); |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + /** |
|
117 | + * This will create a custom message template for the given messenger and message type from the context of the |
|
118 | + * default (global) message template list table. |
|
119 | + * Also takes care of verifying the template was created. |
|
120 | + * @param string $message_type_label |
|
121 | + * @param string $messenger_label |
|
122 | + */ |
|
123 | + public function createCustomMessageTemplateFromDefaultFor($message_type_label, $messenger_label) |
|
124 | + { |
|
125 | + $this->amOnDefaultMessageTemplateListTablePage(); |
|
126 | + $this->actor()->click( |
|
127 | + MessagesPage::createCustomButtonForMessageTypeAndMessenger( |
|
128 | + $message_type_label, |
|
129 | + $messenger_label |
|
130 | + ) |
|
131 | + ); |
|
132 | + $this->actor()->seeInField('#title', 'New Custom Template'); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This switches the context of the current messages template to the given reference. |
|
138 | + * @param string $context_reference This should be the visible label for the option. |
|
139 | + */ |
|
140 | + public function switchContextTo($context_reference) |
|
141 | + { |
|
142 | + $this->actor()->selectOption(MessagesPage::MESSAGES_CONTEXT_SWITCHER_SELECTOR, $context_reference); |
|
143 | + $this->actor()->click(MessagesPage::MESSAGES_CONTEXT_SWITCHER_BUTTON_SELECTOR); |
|
144 | + $this->actor()->waitForText($context_reference, 10, 'h1'); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * This takes care of clicking the View Message icon for the given parameters. |
|
150 | + * Assumes you are already viewing the messages activity list table. |
|
151 | + * @param $message_type_label |
|
152 | + * @param $message_status |
|
153 | + * @param string $messenger |
|
154 | + * @param string $context |
|
155 | + * @param int $number_in_set |
|
156 | + */ |
|
157 | + public function viewMessageInMessagesListTableFor( |
|
158 | + $message_type_label, |
|
159 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
160 | + $messenger = 'Email', |
|
161 | + $context = 'Event Admin', |
|
162 | + $number_in_set = 1 |
|
163 | + ) { |
|
164 | + $this->actor()->click(MessagesPage::messagesActivityListTableViewButtonSelectorFor( |
|
165 | + $message_type_label, |
|
166 | + $message_status, |
|
167 | + $messenger, |
|
168 | + $context, |
|
169 | + $number_in_set |
|
170 | + )); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Takes care of deleting a message matching the given parameters via the message activity list table. |
|
176 | + * Assumes you are already viewing the messages activity list table. |
|
177 | + * @param $message_type_label |
|
178 | + * @param $message_status |
|
179 | + * @param string $messenger |
|
180 | + * @param string $context |
|
181 | + * @param int $number_in_set |
|
182 | + */ |
|
183 | + public function deleteMessageInMessagesListTableFor( |
|
184 | + $message_type_label, |
|
185 | + $message_status = MessagesPage::MESSAGE_STATUS_SENT, |
|
186 | + $messenger = 'Email', |
|
187 | + $context = 'Event Admin', |
|
188 | + $number_in_set = 1 |
|
189 | + ) { |
|
190 | + $delete_action_selector = MessagesPage::messagesActivityListTableDeleteActionSelectorFor( |
|
191 | + $message_type_label, |
|
192 | + $message_status, |
|
193 | + $messenger, |
|
194 | + $context, |
|
195 | + $number_in_set |
|
196 | + ); |
|
197 | + $this->actor()->moveMouseOver( |
|
198 | + MessagesPage::messagesActivityListTableCellSelectorFor( |
|
199 | + 'to', |
|
200 | + $message_type_label, |
|
201 | + $message_status, |
|
202 | + $messenger, |
|
203 | + $context, |
|
204 | + '', |
|
205 | + $number_in_set |
|
206 | + ), |
|
207 | + 5, |
|
208 | + 5 |
|
209 | + ); |
|
210 | + $this->actor()->waitForElementVisible( |
|
211 | + $delete_action_selector |
|
212 | + ); |
|
213 | + $this->actor()->click( |
|
214 | + $delete_action_selector |
|
215 | + ); |
|
216 | + $this->actor()->waitForText('successfully deleted'); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
222 | + * list table, this will take care of validating the given text is in that window. |
|
223 | + * @param string $text_to_view |
|
224 | + */ |
|
225 | + public function seeTextInViewMessageModal($text_to_view, $should_not_see = false) |
|
226 | + { |
|
227 | + $this->actor()->waitForElementVisible('.ee-admin-dialog-container-inner-content'); |
|
228 | + $this->actor()->switchToIframe('message-view-window'); |
|
229 | + $should_not_see ? $this->actor()->dontSee($text_to_view) : $this->actor()->see($text_to_view); |
|
230 | + $this->actor()->switchToIframe(); |
|
231 | + } |
|
232 | + |
|
233 | + |
|
234 | + /** |
|
235 | + * Assuming you have already triggered the view modal for a single message from the context of the message activity |
|
236 | + * list table, this will take care of validating the given text is NOT that window. |
|
237 | + * @param string $text_to_view |
|
238 | + */ |
|
239 | + public function dontSeeTextInViewMessageModal($text_to_view) |
|
240 | + { |
|
241 | + $this->seeTextInViewMessageModal($text_to_view, true); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + public function dismissMessageModal() |
|
246 | + { |
|
247 | + $this->actor()->click('#espresso-admin-page-overlay-dv'); |
|
248 | + //this is needed otherwise phantom js gets stuck in the wrong context and any future element events will fail. |
|
249 | + $this->actor()->click('form#EE_Message_List_Table-table-frm'); |
|
250 | + } |
|
251 | 251 | } |