@@ -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 | ) |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | public function processShortcode($attributes = array()) |
113 | 113 | { |
114 | 114 | // grab attributes and merge with defaults |
115 | - $attributes = $this->getAttributes((array)$attributes); |
|
115 | + $attributes = $this->getAttributes((array) $attributes); |
|
116 | 116 | $archive = is_archive(); |
117 | 117 | $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
118 | 118 | // don't display on archives unless 'display_on_archives' is true |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | private function validateEntities(array $attributes) |
202 | 202 | { |
203 | - if (! $this->template_args['event'] instanceof EE_Event |
|
203 | + if ( ! $this->template_args['event'] instanceof EE_Event |
|
204 | 204 | || ( |
205 | 205 | empty($attributes['event_id']) |
206 | 206 | && $attributes['datetime_id'] |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | */ |
316 | 316 | private function getDatetime(array $attributes) |
317 | 317 | { |
318 | - if (! empty($attributes['datetime_id'])) { |
|
318 | + if ( ! empty($attributes['datetime_id'])) { |
|
319 | 319 | $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
320 | 320 | if ($datetime instanceof EE_Datetime) { |
321 | 321 | return $datetime; |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | */ |
336 | 336 | private function getTicket(array $attributes) |
337 | 337 | { |
338 | - if (! empty($attributes['ticket_id'])) { |
|
338 | + if ( ! empty($attributes['ticket_id'])) { |
|
339 | 339 | $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
340 | 340 | if ($ticket instanceof EE_Ticket) { |
341 | 341 | return $ticket; |
@@ -30,339 +30,339 @@ |
||
30 | 30 | class EspressoEventAttendees extends EspressoShortcode |
31 | 31 | { |
32 | 32 | |
33 | - private $query_params = array( |
|
34 | - 0 => array() |
|
35 | - ); |
|
36 | - |
|
37 | - private $template_args = array( |
|
38 | - 'contacts' => array(), |
|
39 | - 'event' => null, |
|
40 | - 'datetime' => null, |
|
41 | - 'ticket' => null, |
|
42 | - ); |
|
43 | - |
|
44 | - /** |
|
45 | - * the actual shortcode tag that gets registered with WordPress |
|
46 | - * |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public function getTag() |
|
50 | - { |
|
51 | - return 'ESPRESSO_EVENT_ATTENDEES'; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * the time in seconds to cache the results of the processShortcode() method |
|
58 | - * 0 means the processShortcode() results will NOT be cached at all |
|
59 | - * |
|
60 | - * @return int |
|
61 | - */ |
|
62 | - public function cacheExpiration() |
|
63 | - { |
|
64 | - return 0; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * a place for adding any initialization code that needs to run prior to wp_header(). |
|
71 | - * this may be required for shortcodes that utilize a corresponding module, |
|
72 | - * and need to enqueue assets for that module |
|
73 | - * |
|
74 | - * @return void |
|
75 | - */ |
|
76 | - public function initializeShortcode() |
|
77 | - { |
|
78 | - $this->shortcodeHasBeenInitialized(); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event. |
|
84 | - * [ESPRESSO_EVENT_ATTENDEES] |
|
85 | - * - defaults to attendees for earliest active event, or earliest upcoming event. |
|
86 | - * [ESPRESSO_EVENT_ATTENDEES event_id=123] |
|
87 | - * - attendees for specific event. |
|
88 | - * [ESPRESSO_EVENT_ATTENDEES datetime_id=245] |
|
89 | - * - attendees for a specific datetime. |
|
90 | - * [ESPRESSO_EVENT_ATTENDEES ticket_id=123] |
|
91 | - * - attendees for a specific ticket. |
|
92 | - * [ESPRESSO_EVENT_ATTENDEES status=all] |
|
93 | - * - specific registration status (use status id) or all for all attendees regardless of status. |
|
94 | - * Note default is to only return approved attendees |
|
95 | - * [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] |
|
96 | - * - default is to not return gravatar. Otherwise if this is set then return gravatar for email address given. |
|
97 | - * [ESPRESSO_EVENT_ATTENDEES display_on_archives=true] |
|
98 | - * - default is to not display attendees list on archive pages. |
|
99 | - * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
100 | - * If more than one of those params is included, then preference is given to the following: |
|
101 | - * - event_id is used whenever its present and any others are ignored. |
|
102 | - * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
103 | - * - otherwise ticket_id is used if present. |
|
104 | - * |
|
105 | - * @param array $attributes |
|
106 | - * @return string |
|
107 | - * @throws EE_Error |
|
108 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
109 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
110 | - * @throws \InvalidArgumentException |
|
111 | - */ |
|
112 | - public function processShortcode($attributes = array()) |
|
113 | - { |
|
114 | - // grab attributes and merge with defaults |
|
115 | - $attributes = $this->getAttributes((array)$attributes); |
|
116 | - $archive = is_archive(); |
|
117 | - $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
|
118 | - // don't display on archives unless 'display_on_archives' is true |
|
119 | - if ($archive && ! $display_on_archives) { |
|
120 | - return ''; |
|
121 | - } |
|
122 | - |
|
123 | - try { |
|
124 | - $this->setBaseTemplateArguments($attributes); |
|
125 | - $this->validateEntities($attributes); |
|
126 | - $this->setBaseQueryParams(); |
|
127 | - } catch (EntityNotFoundException $e) { |
|
128 | - if (WP_DEBUG) { |
|
129 | - return '<div class="important-notice ee-error">' |
|
130 | - . $e->getMessage() |
|
131 | - . '</div>'; |
|
132 | - } |
|
133 | - return ''; |
|
134 | - } |
|
135 | - $this->setAdditionalQueryParams($attributes); |
|
136 | - //get contacts! |
|
137 | - $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params); |
|
138 | - //all set let's load up the template and return. |
|
139 | - return EEH_Template::locate_template( |
|
140 | - 'loop-espresso_event_attendees.php', |
|
141 | - $this->template_args |
|
142 | - ); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * merge incoming attributes with filtered defaults |
|
149 | - * |
|
150 | - * @param array $attributes |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - private function getAttributes(array $attributes) |
|
154 | - { |
|
155 | - return (array) apply_filters( |
|
156 | - 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', |
|
157 | - $attributes + array( |
|
158 | - 'event_id' => null, |
|
159 | - 'datetime_id' => null, |
|
160 | - 'ticket_id' => null, |
|
161 | - 'status' => EEM_Registration::status_id_approved, |
|
162 | - 'show_gravatar' => false, |
|
163 | - 'display_on_archives' => false, |
|
164 | - ) |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Set all the base template arguments from the incoming attributes. |
|
171 | - * |
|
172 | - * * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
173 | - * If more than one of those params is included, then preference is given to the following: |
|
174 | - * - event_id is used whenever its present and any others are ignored. |
|
175 | - * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
176 | - * - otherwise ticket_id is used if present. |
|
177 | - * |
|
178 | - * @param array $attributes |
|
179 | - * @throws EE_Error |
|
180 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
181 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
182 | - * @throws \InvalidArgumentException |
|
183 | - */ |
|
184 | - private function setBaseTemplateArguments(array $attributes) |
|
185 | - { |
|
186 | - $this->template_args['show_gravatar'] = $attributes['show_gravatar']; |
|
187 | - $this->template_args['event'] = $this->getEvent($attributes); |
|
188 | - $this->template_args['datetime'] = empty($attributes['event_id']) |
|
189 | - ? $this->getDatetime($attributes) |
|
190 | - : null; |
|
191 | - $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id']) |
|
192 | - ? $this->getTicket($attributes) |
|
193 | - : null; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * Validates the presence of entities for the given attribute values. |
|
199 | - * @param array $attributes |
|
200 | - * @throws EntityNotFoundException |
|
201 | - */ |
|
202 | - private function validateEntities(array $attributes) |
|
203 | - { |
|
204 | - if (! $this->template_args['event'] instanceof EE_Event |
|
205 | - || ( |
|
206 | - empty($attributes['event_id']) |
|
207 | - && $attributes['datetime_id'] |
|
208 | - && ! $this->template_args['datetime'] instanceof EE_Datetime |
|
209 | - ) |
|
210 | - || ( |
|
211 | - empty($attributes['event_id']) |
|
212 | - && empty($attributes['datetime_id']) |
|
213 | - && $attributes['ticket_id'] |
|
214 | - && ! $this->template_args['ticket'] instanceof EE_Ticket |
|
215 | - ) |
|
216 | - ) { |
|
217 | - throw new EntityNotFoundException( |
|
218 | - '', |
|
219 | - '', |
|
220 | - esc_html__( |
|
221 | - 'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', |
|
222 | - 'event_espresso' |
|
223 | - ) |
|
224 | - ); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Sets the query params for the base query elements. |
|
231 | - */ |
|
232 | - private function setBaseQueryParams() |
|
233 | - { |
|
234 | - switch (true) { |
|
235 | - case $this->template_args['datetime'] instanceof EE_Datetime: |
|
236 | - $this->query_params = array( |
|
237 | - 0 => array( |
|
238 | - 'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID() |
|
239 | - ), |
|
240 | - 'default_where_conditions' => 'this_model_only' |
|
241 | - ); |
|
242 | - break; |
|
243 | - case $this->template_args['ticket'] instanceof EE_Ticket: |
|
244 | - $this->query_params[0] = array( |
|
245 | - 'Registration.TKT_ID' => $this->template_args['ticket']->ID() |
|
246 | - ); |
|
247 | - break; |
|
248 | - case $this->template_args['event'] instanceof EE_Event: |
|
249 | - $this->query_params[0] = array( |
|
250 | - 'Registration.EVT_ID' => $this->template_args['event']->ID() |
|
251 | - ); |
|
252 | - break; |
|
253 | - } |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @param array $attributes |
|
259 | - * @return EE_Event|null |
|
260 | - * @throws EE_Error |
|
261 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
262 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
263 | - * @throws \InvalidArgumentException |
|
264 | - */ |
|
265 | - private function getEvent(array $attributes) |
|
266 | - { |
|
267 | - switch (true) { |
|
268 | - case ! empty($attributes['event_id']): |
|
269 | - $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
270 | - break; |
|
271 | - case ! empty($attributes['datetime_id']): |
|
272 | - $event = EEM_Event::instance()->get_one(array( |
|
273 | - array( |
|
274 | - 'Datetime.DTT_ID' => $attributes['datetime_id'] |
|
275 | - ) |
|
276 | - )); |
|
277 | - break; |
|
278 | - case ! empty($attributes['ticket_id']): |
|
279 | - $event = EEM_Event::instance()->get_one(array( |
|
280 | - array( |
|
281 | - 'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'] |
|
282 | - ) |
|
283 | - )); |
|
284 | - break; |
|
285 | - case is_espresso_event(): |
|
286 | - $event = EEH_Event_View::get_event(); |
|
287 | - break; |
|
288 | - default: |
|
289 | - // one last shot... |
|
290 | - // try getting the earliest active event |
|
291 | - $events = EEM_Event::instance()->get_active_events(array( |
|
292 | - 'limit' => 1, |
|
293 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
294 | - )); |
|
295 | - // if none then get the next upcoming |
|
296 | - $events = empty($events) |
|
297 | - ? EEM_Event::instance()->get_upcoming_events(array( |
|
298 | - 'limit' => 1, |
|
299 | - 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
300 | - )) |
|
301 | - : $events; |
|
302 | - $event = reset($events); |
|
303 | - } |
|
304 | - |
|
305 | - return $event instanceof EE_Event ? $event : null; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * @param array $attributes |
|
311 | - * @return EE_Datetime|null |
|
312 | - * @throws EE_Error |
|
313 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
314 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
315 | - * @throws \InvalidArgumentException |
|
316 | - */ |
|
317 | - private function getDatetime(array $attributes) |
|
318 | - { |
|
319 | - if (! empty($attributes['datetime_id'])) { |
|
320 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
321 | - if ($datetime instanceof EE_Datetime) { |
|
322 | - return $datetime; |
|
323 | - } |
|
324 | - } |
|
325 | - return null; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @param array $attributes |
|
331 | - * @return \EE_Base_Class|EE_Ticket|null |
|
332 | - * @throws EE_Error |
|
333 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
334 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
335 | - * @throws \InvalidArgumentException |
|
336 | - */ |
|
337 | - private function getTicket(array $attributes) |
|
338 | - { |
|
339 | - if (! empty($attributes['ticket_id'])) { |
|
340 | - $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
341 | - if ($ticket instanceof EE_Ticket) { |
|
342 | - return $ticket; |
|
343 | - } |
|
344 | - } |
|
345 | - return null; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - |
|
350 | - /** |
|
351 | - * @param array $attributes |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - private function setAdditionalQueryParams(array $attributes) |
|
355 | - { |
|
356 | - $reg_status_array = EEM_Registration::reg_status_array(); |
|
357 | - if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) { |
|
358 | - $this->query_params[0]['Registration.STS_ID'] = $attributes['status']; |
|
359 | - } |
|
360 | - $this->query_params['group_by'] = array('ATT_ID'); |
|
361 | - $this->query_params['order_by'] = (array) apply_filters( |
|
362 | - 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', |
|
363 | - array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC') |
|
364 | - ); |
|
365 | - } |
|
33 | + private $query_params = array( |
|
34 | + 0 => array() |
|
35 | + ); |
|
36 | + |
|
37 | + private $template_args = array( |
|
38 | + 'contacts' => array(), |
|
39 | + 'event' => null, |
|
40 | + 'datetime' => null, |
|
41 | + 'ticket' => null, |
|
42 | + ); |
|
43 | + |
|
44 | + /** |
|
45 | + * the actual shortcode tag that gets registered with WordPress |
|
46 | + * |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public function getTag() |
|
50 | + { |
|
51 | + return 'ESPRESSO_EVENT_ATTENDEES'; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * the time in seconds to cache the results of the processShortcode() method |
|
58 | + * 0 means the processShortcode() results will NOT be cached at all |
|
59 | + * |
|
60 | + * @return int |
|
61 | + */ |
|
62 | + public function cacheExpiration() |
|
63 | + { |
|
64 | + return 0; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * a place for adding any initialization code that needs to run prior to wp_header(). |
|
71 | + * this may be required for shortcodes that utilize a corresponding module, |
|
72 | + * and need to enqueue assets for that module |
|
73 | + * |
|
74 | + * @return void |
|
75 | + */ |
|
76 | + public function initializeShortcode() |
|
77 | + { |
|
78 | + $this->shortcodeHasBeenInitialized(); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event. |
|
84 | + * [ESPRESSO_EVENT_ATTENDEES] |
|
85 | + * - defaults to attendees for earliest active event, or earliest upcoming event. |
|
86 | + * [ESPRESSO_EVENT_ATTENDEES event_id=123] |
|
87 | + * - attendees for specific event. |
|
88 | + * [ESPRESSO_EVENT_ATTENDEES datetime_id=245] |
|
89 | + * - attendees for a specific datetime. |
|
90 | + * [ESPRESSO_EVENT_ATTENDEES ticket_id=123] |
|
91 | + * - attendees for a specific ticket. |
|
92 | + * [ESPRESSO_EVENT_ATTENDEES status=all] |
|
93 | + * - specific registration status (use status id) or all for all attendees regardless of status. |
|
94 | + * Note default is to only return approved attendees |
|
95 | + * [ESPRESSO_EVENT_ATTENDEES show_gravatar=true] |
|
96 | + * - default is to not return gravatar. Otherwise if this is set then return gravatar for email address given. |
|
97 | + * [ESPRESSO_EVENT_ATTENDEES display_on_archives=true] |
|
98 | + * - default is to not display attendees list on archive pages. |
|
99 | + * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
100 | + * If more than one of those params is included, then preference is given to the following: |
|
101 | + * - event_id is used whenever its present and any others are ignored. |
|
102 | + * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
103 | + * - otherwise ticket_id is used if present. |
|
104 | + * |
|
105 | + * @param array $attributes |
|
106 | + * @return string |
|
107 | + * @throws EE_Error |
|
108 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
109 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
110 | + * @throws \InvalidArgumentException |
|
111 | + */ |
|
112 | + public function processShortcode($attributes = array()) |
|
113 | + { |
|
114 | + // grab attributes and merge with defaults |
|
115 | + $attributes = $this->getAttributes((array)$attributes); |
|
116 | + $archive = is_archive(); |
|
117 | + $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN); |
|
118 | + // don't display on archives unless 'display_on_archives' is true |
|
119 | + if ($archive && ! $display_on_archives) { |
|
120 | + return ''; |
|
121 | + } |
|
122 | + |
|
123 | + try { |
|
124 | + $this->setBaseTemplateArguments($attributes); |
|
125 | + $this->validateEntities($attributes); |
|
126 | + $this->setBaseQueryParams(); |
|
127 | + } catch (EntityNotFoundException $e) { |
|
128 | + if (WP_DEBUG) { |
|
129 | + return '<div class="important-notice ee-error">' |
|
130 | + . $e->getMessage() |
|
131 | + . '</div>'; |
|
132 | + } |
|
133 | + return ''; |
|
134 | + } |
|
135 | + $this->setAdditionalQueryParams($attributes); |
|
136 | + //get contacts! |
|
137 | + $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params); |
|
138 | + //all set let's load up the template and return. |
|
139 | + return EEH_Template::locate_template( |
|
140 | + 'loop-espresso_event_attendees.php', |
|
141 | + $this->template_args |
|
142 | + ); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * merge incoming attributes with filtered defaults |
|
149 | + * |
|
150 | + * @param array $attributes |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + private function getAttributes(array $attributes) |
|
154 | + { |
|
155 | + return (array) apply_filters( |
|
156 | + 'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts', |
|
157 | + $attributes + array( |
|
158 | + 'event_id' => null, |
|
159 | + 'datetime_id' => null, |
|
160 | + 'ticket_id' => null, |
|
161 | + 'status' => EEM_Registration::status_id_approved, |
|
162 | + 'show_gravatar' => false, |
|
163 | + 'display_on_archives' => false, |
|
164 | + ) |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Set all the base template arguments from the incoming attributes. |
|
171 | + * |
|
172 | + * * Note: because of the relationship between event_id, ticket_id, and datetime_id: |
|
173 | + * If more than one of those params is included, then preference is given to the following: |
|
174 | + * - event_id is used whenever its present and any others are ignored. |
|
175 | + * - if no event_id then datetime is used whenever its present and any others are ignored. |
|
176 | + * - otherwise ticket_id is used if present. |
|
177 | + * |
|
178 | + * @param array $attributes |
|
179 | + * @throws EE_Error |
|
180 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
181 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
182 | + * @throws \InvalidArgumentException |
|
183 | + */ |
|
184 | + private function setBaseTemplateArguments(array $attributes) |
|
185 | + { |
|
186 | + $this->template_args['show_gravatar'] = $attributes['show_gravatar']; |
|
187 | + $this->template_args['event'] = $this->getEvent($attributes); |
|
188 | + $this->template_args['datetime'] = empty($attributes['event_id']) |
|
189 | + ? $this->getDatetime($attributes) |
|
190 | + : null; |
|
191 | + $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id']) |
|
192 | + ? $this->getTicket($attributes) |
|
193 | + : null; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * Validates the presence of entities for the given attribute values. |
|
199 | + * @param array $attributes |
|
200 | + * @throws EntityNotFoundException |
|
201 | + */ |
|
202 | + private function validateEntities(array $attributes) |
|
203 | + { |
|
204 | + if (! $this->template_args['event'] instanceof EE_Event |
|
205 | + || ( |
|
206 | + empty($attributes['event_id']) |
|
207 | + && $attributes['datetime_id'] |
|
208 | + && ! $this->template_args['datetime'] instanceof EE_Datetime |
|
209 | + ) |
|
210 | + || ( |
|
211 | + empty($attributes['event_id']) |
|
212 | + && empty($attributes['datetime_id']) |
|
213 | + && $attributes['ticket_id'] |
|
214 | + && ! $this->template_args['ticket'] instanceof EE_Ticket |
|
215 | + ) |
|
216 | + ) { |
|
217 | + throw new EntityNotFoundException( |
|
218 | + '', |
|
219 | + '', |
|
220 | + esc_html__( |
|
221 | + 'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly. Please double check the arguments you used for any typos. In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.', |
|
222 | + 'event_espresso' |
|
223 | + ) |
|
224 | + ); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Sets the query params for the base query elements. |
|
231 | + */ |
|
232 | + private function setBaseQueryParams() |
|
233 | + { |
|
234 | + switch (true) { |
|
235 | + case $this->template_args['datetime'] instanceof EE_Datetime: |
|
236 | + $this->query_params = array( |
|
237 | + 0 => array( |
|
238 | + 'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID() |
|
239 | + ), |
|
240 | + 'default_where_conditions' => 'this_model_only' |
|
241 | + ); |
|
242 | + break; |
|
243 | + case $this->template_args['ticket'] instanceof EE_Ticket: |
|
244 | + $this->query_params[0] = array( |
|
245 | + 'Registration.TKT_ID' => $this->template_args['ticket']->ID() |
|
246 | + ); |
|
247 | + break; |
|
248 | + case $this->template_args['event'] instanceof EE_Event: |
|
249 | + $this->query_params[0] = array( |
|
250 | + 'Registration.EVT_ID' => $this->template_args['event']->ID() |
|
251 | + ); |
|
252 | + break; |
|
253 | + } |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @param array $attributes |
|
259 | + * @return EE_Event|null |
|
260 | + * @throws EE_Error |
|
261 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
262 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
263 | + * @throws \InvalidArgumentException |
|
264 | + */ |
|
265 | + private function getEvent(array $attributes) |
|
266 | + { |
|
267 | + switch (true) { |
|
268 | + case ! empty($attributes['event_id']): |
|
269 | + $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']); |
|
270 | + break; |
|
271 | + case ! empty($attributes['datetime_id']): |
|
272 | + $event = EEM_Event::instance()->get_one(array( |
|
273 | + array( |
|
274 | + 'Datetime.DTT_ID' => $attributes['datetime_id'] |
|
275 | + ) |
|
276 | + )); |
|
277 | + break; |
|
278 | + case ! empty($attributes['ticket_id']): |
|
279 | + $event = EEM_Event::instance()->get_one(array( |
|
280 | + array( |
|
281 | + 'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'] |
|
282 | + ) |
|
283 | + )); |
|
284 | + break; |
|
285 | + case is_espresso_event(): |
|
286 | + $event = EEH_Event_View::get_event(); |
|
287 | + break; |
|
288 | + default: |
|
289 | + // one last shot... |
|
290 | + // try getting the earliest active event |
|
291 | + $events = EEM_Event::instance()->get_active_events(array( |
|
292 | + 'limit' => 1, |
|
293 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
294 | + )); |
|
295 | + // if none then get the next upcoming |
|
296 | + $events = empty($events) |
|
297 | + ? EEM_Event::instance()->get_upcoming_events(array( |
|
298 | + 'limit' => 1, |
|
299 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'ASC') |
|
300 | + )) |
|
301 | + : $events; |
|
302 | + $event = reset($events); |
|
303 | + } |
|
304 | + |
|
305 | + return $event instanceof EE_Event ? $event : null; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * @param array $attributes |
|
311 | + * @return EE_Datetime|null |
|
312 | + * @throws EE_Error |
|
313 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
314 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
315 | + * @throws \InvalidArgumentException |
|
316 | + */ |
|
317 | + private function getDatetime(array $attributes) |
|
318 | + { |
|
319 | + if (! empty($attributes['datetime_id'])) { |
|
320 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']); |
|
321 | + if ($datetime instanceof EE_Datetime) { |
|
322 | + return $datetime; |
|
323 | + } |
|
324 | + } |
|
325 | + return null; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @param array $attributes |
|
331 | + * @return \EE_Base_Class|EE_Ticket|null |
|
332 | + * @throws EE_Error |
|
333 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
334 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
335 | + * @throws \InvalidArgumentException |
|
336 | + */ |
|
337 | + private function getTicket(array $attributes) |
|
338 | + { |
|
339 | + if (! empty($attributes['ticket_id'])) { |
|
340 | + $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']); |
|
341 | + if ($ticket instanceof EE_Ticket) { |
|
342 | + return $ticket; |
|
343 | + } |
|
344 | + } |
|
345 | + return null; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + |
|
350 | + /** |
|
351 | + * @param array $attributes |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + private function setAdditionalQueryParams(array $attributes) |
|
355 | + { |
|
356 | + $reg_status_array = EEM_Registration::reg_status_array(); |
|
357 | + if ($attributes['status'] !== 'all' && isset($reg_status_array[$attributes['status']])) { |
|
358 | + $this->query_params[0]['Registration.STS_ID'] = $attributes['status']; |
|
359 | + } |
|
360 | + $this->query_params['group_by'] = array('ATT_ID'); |
|
361 | + $this->query_params['order_by'] = (array) apply_filters( |
|
362 | + 'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by', |
|
363 | + array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC') |
|
364 | + ); |
|
365 | + } |
|
366 | 366 | |
367 | 367 | |
368 | 368 |
@@ -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 |
@@ -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 | ); |
@@ -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,812 +22,812 @@ 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_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
446 | - ), |
|
447 | - 'EE_Session' => array( |
|
448 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
449 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
450 | - ), |
|
451 | - 'EE_Cart' => array( |
|
452 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
453 | - ), |
|
454 | - 'EE_Front_Controller' => array( |
|
455 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
456 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
457 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
458 | - ), |
|
459 | - 'EE_Messenger_Collection_Loader' => array( |
|
460 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
461 | - ), |
|
462 | - 'EE_Message_Type_Collection_Loader' => array( |
|
463 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | - ), |
|
465 | - 'EE_Message_Resource_Manager' => array( |
|
466 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
467 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
468 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Message_Factory' => array( |
|
471 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
472 | - ), |
|
473 | - 'EE_messages' => array( |
|
474 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
475 | - ), |
|
476 | - 'EE_Messages_Generator' => array( |
|
477 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
478 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
479 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
480 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
481 | - ), |
|
482 | - 'EE_Messages_Processor' => array( |
|
483 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
484 | - ), |
|
485 | - 'EE_Messages_Queue' => array( |
|
486 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
487 | - ), |
|
488 | - 'EE_Messages_Template_Defaults' => array( |
|
489 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
490 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
491 | - ), |
|
492 | - 'EE_Message_To_Generate_From_Request' => array( |
|
493 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
494 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
497 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
498 | - ), |
|
499 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
500 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
501 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
502 | - ), |
|
503 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
504 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
505 | - ), |
|
506 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
507 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
508 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
511 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
512 | - ), |
|
513 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
514 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
515 | - ), |
|
516 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
517 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
518 | - ), |
|
519 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
520 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
521 | - ), |
|
522 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
523 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
526 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
527 | - ), |
|
528 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
529 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
530 | - ), |
|
531 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
532 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
533 | - ), |
|
534 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
535 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
536 | - ), |
|
537 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
538 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
539 | - ), |
|
540 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
541 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
542 | - ), |
|
543 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
544 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
545 | - ), |
|
546 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
547 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
548 | - ), |
|
549 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
550 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | - ), |
|
552 | - 'EE_Data_Migration_Class_Base' => array( |
|
553 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
554 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
555 | - ), |
|
556 | - 'EE_DMS_Core_4_1_0' => array( |
|
557 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
558 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EE_DMS_Core_4_2_0' => array( |
|
561 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
563 | - ), |
|
564 | - 'EE_DMS_Core_4_3_0' => array( |
|
565 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
566 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
567 | - ), |
|
568 | - 'EE_DMS_Core_4_4_0' => array( |
|
569 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
570 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
571 | - ), |
|
572 | - 'EE_DMS_Core_4_5_0' => array( |
|
573 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
574 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
575 | - ), |
|
576 | - 'EE_DMS_Core_4_6_0' => array( |
|
577 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
578 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
579 | - ), |
|
580 | - 'EE_DMS_Core_4_7_0' => array( |
|
581 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
582 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
583 | - ), |
|
584 | - 'EE_DMS_Core_4_8_0' => array( |
|
585 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
586 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
587 | - ), |
|
588 | - 'EE_DMS_Core_4_9_0' => array( |
|
589 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
590 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
591 | - ), |
|
592 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
593 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
594 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
595 | - ), |
|
596 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
597 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
600 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | - ), |
|
602 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
603 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
604 | - ), |
|
605 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
606 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
607 | - ), |
|
608 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
609 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
610 | - ), |
|
611 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
612 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
613 | - ), |
|
614 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
615 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
616 | - ), |
|
617 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
618 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
619 | - ), |
|
620 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
621 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
622 | - ), |
|
623 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
624 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
625 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
626 | - ), |
|
627 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
628 | - null, |
|
629 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
632 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'LEGACY_MODELS' => array( |
|
635 | - null, |
|
636 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
637 | - ), |
|
638 | - 'EventEspresso\core\services\activation\ActivationsAndUpgradesManager' => array( |
|
639 | - 'EventEspresso\core\services\activation\ActivationHandler' => EE_Dependency_Map::load_from_cache, |
|
640 | - 'EventEspresso\core\services\activation\RequestTypeDetector' => EE_Dependency_Map::load_from_cache, |
|
641 | - ), |
|
642 | - 'EventEspresso\core\services\activation\ActivationHandler' => array( |
|
643 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
644 | - ), |
|
645 | - 'EventEspresso\core\services\activation\InitializeCore' => array( |
|
646 | - null, |
|
647 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
648 | - 'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache, |
|
649 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
650 | - ), |
|
651 | - 'EventEspresso\core\services\activation\InitializeAddon' => array( |
|
652 | - null, |
|
653 | - 'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache, |
|
654 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
655 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
656 | - ), |
|
657 | - 'EE_Module_Request_Router' => array( |
|
658 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
659 | - ), |
|
660 | - ); |
|
661 | - } |
|
662 | - |
|
663 | - |
|
664 | - |
|
665 | - /** |
|
666 | - * Registers how core classes are loaded. |
|
667 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
668 | - * 'EE_Request_Handler' => 'load_core' |
|
669 | - * 'EE_Messages_Queue' => 'load_lib' |
|
670 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
671 | - * or, if greater control is required, by providing a custom closure. For example: |
|
672 | - * 'Some_Class' => function () { |
|
673 | - * return new Some_Class(); |
|
674 | - * }, |
|
675 | - * This is required for instantiating dependencies |
|
676 | - * where an interface has been type hinted in a class constructor. For example: |
|
677 | - * 'Required_Interface' => function () { |
|
678 | - * return new A_Class_That_Implements_Required_Interface(); |
|
679 | - * }, |
|
680 | - * |
|
681 | - * @throws InvalidInterfaceException |
|
682 | - * @throws InvalidDataTypeException |
|
683 | - * @throws InvalidArgumentException |
|
684 | - */ |
|
685 | - protected function _register_core_class_loaders() |
|
686 | - { |
|
687 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
688 | - //be used in a closure. |
|
689 | - $request = &$this->_request; |
|
690 | - $response = &$this->_response; |
|
691 | - // $loader = &$this->loader; |
|
692 | - $this->_class_loaders = array( |
|
693 | - //load_core |
|
694 | - 'EE_Capabilities' => 'load_core', |
|
695 | - 'EE_Encryption' => 'load_core', |
|
696 | - 'EE_Front_Controller' => 'load_core', |
|
697 | - 'EE_Module_Request_Router' => 'load_core', |
|
698 | - 'EE_Registry' => 'load_core', |
|
699 | - 'EE_Request' => function () use (&$request) { |
|
700 | - return $request; |
|
701 | - }, |
|
702 | - 'EE_Response' => function () use (&$response) { |
|
703 | - return $response; |
|
704 | - }, |
|
705 | - 'EE_Request_Handler' => 'load_core', |
|
706 | - 'EE_Session' => 'load_core', |
|
707 | - 'EE_Cron_Tasks' => 'load_core', |
|
708 | - 'EE_System' => 'load_core', |
|
709 | - 'EE_Maintenance_Mode' => 'load_core', |
|
710 | - 'EE_Register_CPTs' => 'load_core', |
|
711 | - 'EE_Admin' => 'load_core', |
|
712 | - 'EE_Data_Migration_Manager' => 'load_core', |
|
713 | - //load_lib |
|
714 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
715 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
716 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
717 | - 'EE_Messenger_Collection' => 'load_lib', |
|
718 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
719 | - 'EE_Messages_Processor' => 'load_lib', |
|
720 | - 'EE_Message_Repository' => 'load_lib', |
|
721 | - 'EE_Messages_Queue' => 'load_lib', |
|
722 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
723 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
724 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
725 | - 'EE_Messages_Generator' => function () { |
|
726 | - return EE_Registry::instance()->load_lib( |
|
727 | - 'Messages_Generator', |
|
728 | - array(), |
|
729 | - false, |
|
730 | - false |
|
731 | - ); |
|
732 | - }, |
|
733 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
734 | - return EE_Registry::instance()->load_lib( |
|
735 | - 'Messages_Template_Defaults', |
|
736 | - $arguments, |
|
737 | - false, |
|
738 | - false |
|
739 | - ); |
|
740 | - }, |
|
741 | - //load_model |
|
742 | - // 'EEM_Attendee' => 'load_model', |
|
743 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
744 | - // 'EEM_Message_Template' => 'load_model', |
|
745 | - //load_helper |
|
746 | - 'EEH_Parse_Shortcodes' => function () { |
|
747 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
748 | - return new EEH_Parse_Shortcodes(); |
|
749 | - } |
|
750 | - return null; |
|
751 | - }, |
|
752 | - 'EE_Template_Config' => function () { |
|
753 | - return EE_Config::instance()->template_settings; |
|
754 | - }, |
|
755 | - 'EE_Currency_Config' => function () { |
|
756 | - return EE_Config::instance()->currency; |
|
757 | - }, |
|
758 | - 'EE_Registration_Config' => function () { |
|
759 | - return EE_Config::instance()->registration; |
|
760 | - }, |
|
761 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
762 | - return LoaderFactory::getLoader(); |
|
763 | - }, |
|
764 | - ); |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * can be used for supplying alternate names for classes, |
|
771 | - * or for connecting interface names to instantiable classes |
|
772 | - */ |
|
773 | - protected function _register_core_aliases() |
|
774 | - { |
|
775 | - $this->_aliases = array( |
|
776 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
777 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
778 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
779 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
780 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
781 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
782 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
783 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
784 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
785 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
786 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
787 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
788 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
789 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
790 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
791 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
792 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
793 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
794 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
795 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
796 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
797 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
798 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
799 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
800 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
801 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
802 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
803 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
804 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
805 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
806 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
807 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
808 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
809 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
810 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
811 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
812 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
813 | - ); |
|
814 | - } |
|
815 | - |
|
816 | - |
|
817 | - |
|
818 | - /** |
|
819 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
820 | - * request Primarily used by unit tests. |
|
821 | - * |
|
822 | - * @throws InvalidDataTypeException |
|
823 | - * @throws InvalidInterfaceException |
|
824 | - * @throws InvalidArgumentException |
|
825 | - */ |
|
826 | - public function reset() |
|
827 | - { |
|
828 | - $this->_register_core_class_loaders(); |
|
829 | - $this->_register_core_dependencies(); |
|
830 | - } |
|
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_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
446 | + ), |
|
447 | + 'EE_Session' => array( |
|
448 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
449 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
450 | + ), |
|
451 | + 'EE_Cart' => array( |
|
452 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
453 | + ), |
|
454 | + 'EE_Front_Controller' => array( |
|
455 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
456 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
457 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
458 | + ), |
|
459 | + 'EE_Messenger_Collection_Loader' => array( |
|
460 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
461 | + ), |
|
462 | + 'EE_Message_Type_Collection_Loader' => array( |
|
463 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
464 | + ), |
|
465 | + 'EE_Message_Resource_Manager' => array( |
|
466 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
467 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
468 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Message_Factory' => array( |
|
471 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
472 | + ), |
|
473 | + 'EE_messages' => array( |
|
474 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
475 | + ), |
|
476 | + 'EE_Messages_Generator' => array( |
|
477 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
478 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
479 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
480 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
481 | + ), |
|
482 | + 'EE_Messages_Processor' => array( |
|
483 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
484 | + ), |
|
485 | + 'EE_Messages_Queue' => array( |
|
486 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
487 | + ), |
|
488 | + 'EE_Messages_Template_Defaults' => array( |
|
489 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
490 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
491 | + ), |
|
492 | + 'EE_Message_To_Generate_From_Request' => array( |
|
493 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
494 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
497 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
498 | + ), |
|
499 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
500 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
501 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
502 | + ), |
|
503 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
504 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
505 | + ), |
|
506 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
507 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
508 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
511 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
512 | + ), |
|
513 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
514 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
515 | + ), |
|
516 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
517 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
518 | + ), |
|
519 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
520 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
521 | + ), |
|
522 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
523 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
526 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
527 | + ), |
|
528 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
529 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
530 | + ), |
|
531 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
532 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
533 | + ), |
|
534 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
535 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
536 | + ), |
|
537 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
538 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
539 | + ), |
|
540 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
541 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
542 | + ), |
|
543 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
544 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
545 | + ), |
|
546 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
547 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
548 | + ), |
|
549 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
550 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
551 | + ), |
|
552 | + 'EE_Data_Migration_Class_Base' => array( |
|
553 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
554 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
555 | + ), |
|
556 | + 'EE_DMS_Core_4_1_0' => array( |
|
557 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
558 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EE_DMS_Core_4_2_0' => array( |
|
561 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
563 | + ), |
|
564 | + 'EE_DMS_Core_4_3_0' => array( |
|
565 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
566 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
567 | + ), |
|
568 | + 'EE_DMS_Core_4_4_0' => array( |
|
569 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
570 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
571 | + ), |
|
572 | + 'EE_DMS_Core_4_5_0' => array( |
|
573 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
574 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
575 | + ), |
|
576 | + 'EE_DMS_Core_4_6_0' => array( |
|
577 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
578 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
579 | + ), |
|
580 | + 'EE_DMS_Core_4_7_0' => array( |
|
581 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
582 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
583 | + ), |
|
584 | + 'EE_DMS_Core_4_8_0' => array( |
|
585 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
586 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
587 | + ), |
|
588 | + 'EE_DMS_Core_4_9_0' => array( |
|
589 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
590 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
591 | + ), |
|
592 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
593 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
594 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
595 | + ), |
|
596 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
597 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
600 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
601 | + ), |
|
602 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
603 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
604 | + ), |
|
605 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
606 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
607 | + ), |
|
608 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
609 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
610 | + ), |
|
611 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
612 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
613 | + ), |
|
614 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
615 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
616 | + ), |
|
617 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
618 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
619 | + ), |
|
620 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
621 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
622 | + ), |
|
623 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
624 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
625 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
626 | + ), |
|
627 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
628 | + null, |
|
629 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
632 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'LEGACY_MODELS' => array( |
|
635 | + null, |
|
636 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
637 | + ), |
|
638 | + 'EventEspresso\core\services\activation\ActivationsAndUpgradesManager' => array( |
|
639 | + 'EventEspresso\core\services\activation\ActivationHandler' => EE_Dependency_Map::load_from_cache, |
|
640 | + 'EventEspresso\core\services\activation\RequestTypeDetector' => EE_Dependency_Map::load_from_cache, |
|
641 | + ), |
|
642 | + 'EventEspresso\core\services\activation\ActivationHandler' => array( |
|
643 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
644 | + ), |
|
645 | + 'EventEspresso\core\services\activation\InitializeCore' => array( |
|
646 | + null, |
|
647 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
648 | + 'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache, |
|
649 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
650 | + ), |
|
651 | + 'EventEspresso\core\services\activation\InitializeAddon' => array( |
|
652 | + null, |
|
653 | + 'EE_Data_Migration_Manager' => EE_Dependency_Map::load_from_cache, |
|
654 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
655 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
656 | + ), |
|
657 | + 'EE_Module_Request_Router' => array( |
|
658 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
659 | + ), |
|
660 | + ); |
|
661 | + } |
|
662 | + |
|
663 | + |
|
664 | + |
|
665 | + /** |
|
666 | + * Registers how core classes are loaded. |
|
667 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
668 | + * 'EE_Request_Handler' => 'load_core' |
|
669 | + * 'EE_Messages_Queue' => 'load_lib' |
|
670 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
671 | + * or, if greater control is required, by providing a custom closure. For example: |
|
672 | + * 'Some_Class' => function () { |
|
673 | + * return new Some_Class(); |
|
674 | + * }, |
|
675 | + * This is required for instantiating dependencies |
|
676 | + * where an interface has been type hinted in a class constructor. For example: |
|
677 | + * 'Required_Interface' => function () { |
|
678 | + * return new A_Class_That_Implements_Required_Interface(); |
|
679 | + * }, |
|
680 | + * |
|
681 | + * @throws InvalidInterfaceException |
|
682 | + * @throws InvalidDataTypeException |
|
683 | + * @throws InvalidArgumentException |
|
684 | + */ |
|
685 | + protected function _register_core_class_loaders() |
|
686 | + { |
|
687 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
688 | + //be used in a closure. |
|
689 | + $request = &$this->_request; |
|
690 | + $response = &$this->_response; |
|
691 | + // $loader = &$this->loader; |
|
692 | + $this->_class_loaders = array( |
|
693 | + //load_core |
|
694 | + 'EE_Capabilities' => 'load_core', |
|
695 | + 'EE_Encryption' => 'load_core', |
|
696 | + 'EE_Front_Controller' => 'load_core', |
|
697 | + 'EE_Module_Request_Router' => 'load_core', |
|
698 | + 'EE_Registry' => 'load_core', |
|
699 | + 'EE_Request' => function () use (&$request) { |
|
700 | + return $request; |
|
701 | + }, |
|
702 | + 'EE_Response' => function () use (&$response) { |
|
703 | + return $response; |
|
704 | + }, |
|
705 | + 'EE_Request_Handler' => 'load_core', |
|
706 | + 'EE_Session' => 'load_core', |
|
707 | + 'EE_Cron_Tasks' => 'load_core', |
|
708 | + 'EE_System' => 'load_core', |
|
709 | + 'EE_Maintenance_Mode' => 'load_core', |
|
710 | + 'EE_Register_CPTs' => 'load_core', |
|
711 | + 'EE_Admin' => 'load_core', |
|
712 | + 'EE_Data_Migration_Manager' => 'load_core', |
|
713 | + //load_lib |
|
714 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
715 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
716 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
717 | + 'EE_Messenger_Collection' => 'load_lib', |
|
718 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
719 | + 'EE_Messages_Processor' => 'load_lib', |
|
720 | + 'EE_Message_Repository' => 'load_lib', |
|
721 | + 'EE_Messages_Queue' => 'load_lib', |
|
722 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
723 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
724 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
725 | + 'EE_Messages_Generator' => function () { |
|
726 | + return EE_Registry::instance()->load_lib( |
|
727 | + 'Messages_Generator', |
|
728 | + array(), |
|
729 | + false, |
|
730 | + false |
|
731 | + ); |
|
732 | + }, |
|
733 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
734 | + return EE_Registry::instance()->load_lib( |
|
735 | + 'Messages_Template_Defaults', |
|
736 | + $arguments, |
|
737 | + false, |
|
738 | + false |
|
739 | + ); |
|
740 | + }, |
|
741 | + //load_model |
|
742 | + // 'EEM_Attendee' => 'load_model', |
|
743 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
744 | + // 'EEM_Message_Template' => 'load_model', |
|
745 | + //load_helper |
|
746 | + 'EEH_Parse_Shortcodes' => function () { |
|
747 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
748 | + return new EEH_Parse_Shortcodes(); |
|
749 | + } |
|
750 | + return null; |
|
751 | + }, |
|
752 | + 'EE_Template_Config' => function () { |
|
753 | + return EE_Config::instance()->template_settings; |
|
754 | + }, |
|
755 | + 'EE_Currency_Config' => function () { |
|
756 | + return EE_Config::instance()->currency; |
|
757 | + }, |
|
758 | + 'EE_Registration_Config' => function () { |
|
759 | + return EE_Config::instance()->registration; |
|
760 | + }, |
|
761 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
762 | + return LoaderFactory::getLoader(); |
|
763 | + }, |
|
764 | + ); |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * can be used for supplying alternate names for classes, |
|
771 | + * or for connecting interface names to instantiable classes |
|
772 | + */ |
|
773 | + protected function _register_core_aliases() |
|
774 | + { |
|
775 | + $this->_aliases = array( |
|
776 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
777 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
778 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
779 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
780 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
781 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
782 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
783 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
784 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
785 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
786 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
787 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
788 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
789 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
790 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
791 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
792 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
793 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
794 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
795 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
796 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
797 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
798 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
799 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
800 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
801 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
802 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
803 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
804 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
805 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
806 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
807 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
808 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
809 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
810 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
811 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
812 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
813 | + ); |
|
814 | + } |
|
815 | + |
|
816 | + |
|
817 | + |
|
818 | + /** |
|
819 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
820 | + * request Primarily used by unit tests. |
|
821 | + * |
|
822 | + * @throws InvalidDataTypeException |
|
823 | + * @throws InvalidInterfaceException |
|
824 | + * @throws InvalidArgumentException |
|
825 | + */ |
|
826 | + public function reset() |
|
827 | + { |
|
828 | + $this->_register_core_class_loaders(); |
|
829 | + $this->_register_core_dependencies(); |
|
830 | + } |
|
831 | 831 | |
832 | 832 | |
833 | 833 | } |
@@ -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; |
@@ -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 |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $this->_columns = array_merge( $columns, $this->_columns ); |
91 | 91 | $this->_primary_column = '_REG_att_checked_in'; |
92 | 92 | if ( ! empty( $evt_id ) |
93 | - && EE_Registry::instance()->CAP->current_user_can( |
|
93 | + && EE_Registry::instance()->CAP->current_user_can( |
|
94 | 94 | 'ee_read_registrations', |
95 | 95 | 'espresso_registrations_registrations_reports', |
96 | 96 | $evt_id |
@@ -107,44 +107,44 @@ discard block |
||
107 | 107 | ), |
108 | 108 | ); |
109 | 109 | } |
110 | - $this->_bottom_buttons['report_filtered'] = array( |
|
111 | - 'route' => 'registrations_checkin_report', |
|
112 | - 'extra_request' => array( |
|
113 | - 'use_filters' => true, |
|
114 | - 'filters' => array_merge( |
|
115 | - array( |
|
116 | - 'EVT_ID' => $evt_id, |
|
117 | - ), |
|
118 | - array_diff_key( |
|
119 | - $this->_req_data, |
|
120 | - array_flip( |
|
121 | - array( |
|
122 | - 'page', |
|
123 | - 'action', |
|
124 | - 'default_nonce', |
|
125 | - ) |
|
126 | - ) |
|
127 | - ) |
|
128 | - ), |
|
129 | - 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
130 | - ), |
|
131 | - ); |
|
110 | + $this->_bottom_buttons['report_filtered'] = array( |
|
111 | + 'route' => 'registrations_checkin_report', |
|
112 | + 'extra_request' => array( |
|
113 | + 'use_filters' => true, |
|
114 | + 'filters' => array_merge( |
|
115 | + array( |
|
116 | + 'EVT_ID' => $evt_id, |
|
117 | + ), |
|
118 | + array_diff_key( |
|
119 | + $this->_req_data, |
|
120 | + array_flip( |
|
121 | + array( |
|
122 | + 'page', |
|
123 | + 'action', |
|
124 | + 'default_nonce', |
|
125 | + ) |
|
126 | + ) |
|
127 | + ) |
|
128 | + ), |
|
129 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
130 | + ), |
|
131 | + ); |
|
132 | 132 | $this->_sortable_columns = array( |
133 | - /** |
|
134 | - * Allows users to change the default sort if they wish. |
|
135 | - * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
136 | - * |
|
137 | - * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
138 | - * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
139 | - * for a specific list table you can use the provided reference to this object instance. |
|
140 | - */ |
|
133 | + /** |
|
134 | + * Allows users to change the default sort if they wish. |
|
135 | + * Returning a falsey on this filter will result in the default sort to be by firstname rather than last name. |
|
136 | + * |
|
137 | + * Note: usual naming conventions for filters aren't followed here so that just one filter can be used to |
|
138 | + * change the sorts on any list table involving registration contacts. If you want to only change the filter |
|
139 | + * for a specific list table you can use the provided reference to this object instance. |
|
140 | + */ |
|
141 | 141 | 'ATT_name' => array( |
142 | - 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
143 | - true, |
|
144 | - $this |
|
145 | - ) |
|
146 | - ? array( 'ATT_lname' => true ) |
|
147 | - : array( 'ATT_fname' => true ), |
|
142 | + 'FHEE__EE_Registrations_List_Table___set_properties__default_sort_by_registration_last_name', |
|
143 | + true, |
|
144 | + $this |
|
145 | + ) |
|
146 | + ? array( 'ATT_lname' => true ) |
|
147 | + : array( 'ATT_fname' => true ), |
|
148 | 148 | 'Event' => array( 'Event.EVT.Name' => false ), |
149 | 149 | ); |
150 | 150 | $this->_hidden_columns = array(); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | if ( ! $evt->get_count_of_all_registrations() ) { |
204 | 204 | continue; |
205 | 205 | } |
206 | - $evts[] = array( |
|
206 | + $evts[] = array( |
|
207 | 207 | 'id' => $evt->ID(), |
208 | 208 | 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt), |
209 | 209 | 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
@@ -227,8 +227,8 @@ discard block |
||
227 | 227 | if ( count( $this->_dtts_for_event ) > 1 ) { |
228 | 228 | $dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' ); |
229 | 229 | foreach ( $this->_dtts_for_event as $dtt ) { |
230 | - $datetime_string = $dtt->name(); |
|
231 | - $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
230 | + $datetime_string = $dtt->name(); |
|
231 | + $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
232 | 232 | $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
233 | 233 | $dtts[ $dtt->ID() ] = $datetime_string; |
234 | 234 | } |
@@ -301,16 +301,16 @@ discard block |
||
301 | 301 | |
302 | 302 | |
303 | 303 | |
304 | - /** |
|
305 | - * column_REG_att_checked_in |
|
306 | - * |
|
307 | - * @param EE_Registration $item |
|
308 | - * @return string |
|
309 | - * @throws EE_Error |
|
310 | - * @throws InvalidArgumentException |
|
311 | - * @throws InvalidDataTypeException |
|
312 | - * @throws InvalidInterfaceException |
|
313 | - */ |
|
304 | + /** |
|
305 | + * column_REG_att_checked_in |
|
306 | + * |
|
307 | + * @param EE_Registration $item |
|
308 | + * @return string |
|
309 | + * @throws EE_Error |
|
310 | + * @throws InvalidArgumentException |
|
311 | + * @throws InvalidDataTypeException |
|
312 | + * @throws InvalidInterfaceException |
|
313 | + */ |
|
314 | 314 | public function column__REG_att_checked_in( EE_Registration $item ) { |
315 | 315 | $attendee = $item->attendee(); |
316 | 316 | $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
@@ -321,13 +321,13 @@ discard block |
||
321 | 321 | $this->_cur_dtt_id = $latest_related_datetime->ID(); |
322 | 322 | } |
323 | 323 | } |
324 | - $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
325 | - $item, |
|
326 | - $this->_cur_dtt_id |
|
327 | - ); |
|
324 | + $checkin_status_dashicon = CheckinStatusDashicon::fromRegistrationAndDatetimeId( |
|
325 | + $item, |
|
326 | + $this->_cur_dtt_id |
|
327 | + ); |
|
328 | 328 | $nonce = wp_create_nonce( 'checkin_nonce' ); |
329 | 329 | $toggle_active = ! empty ( $this->_cur_dtt_id ) |
330 | - && EE_Registry::instance()->CAP->current_user_can( |
|
330 | + && EE_Registry::instance()->CAP->current_user_can( |
|
331 | 331 | 'ee_edit_checkin', |
332 | 332 | 'espresso_registrations_toggle_checkin_status', |
333 | 333 | $item->ID() |
@@ -336,11 +336,11 @@ discard block |
||
336 | 336 | : ''; |
337 | 337 | $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
338 | 338 | return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
339 | - . ' data-_regid="' . $item->ID() . '"' |
|
340 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
341 | - . ' data-nonce="' . $nonce . '">' |
|
342 | - . '</span>' |
|
343 | - . $mobile_view_content; |
|
339 | + . ' data-_regid="' . $item->ID() . '"' |
|
340 | + . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
341 | + . ' data-nonce="' . $nonce . '">' |
|
342 | + . '</span>' |
|
343 | + . $mobile_view_content; |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | |
@@ -365,8 +365,8 @@ discard block |
||
365 | 365 | 'espresso_registrations_edit_attendee' |
366 | 366 | ) |
367 | 367 | ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
368 | - . $item->attendee()->full_name() |
|
369 | - . '</a>' |
|
368 | + . $item->attendee()->full_name() |
|
369 | + . '</a>' |
|
370 | 370 | : $item->attendee()->full_name(); |
371 | 371 | $name_link .= $item->count() === 1 |
372 | 372 | ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | ? $latest_related_datetime->ID() |
402 | 402 | : $DTT_ID; |
403 | 403 | if ( ! empty( $DTT_ID ) |
404 | - && EE_Registry::instance()->CAP->current_user_can( |
|
404 | + && EE_Registry::instance()->CAP->current_user_can( |
|
405 | 405 | 'ee_read_checkins', |
406 | 406 | 'espresso_registrations_registration_checkins' |
407 | 407 | ) |
@@ -515,15 +515,15 @@ discard block |
||
515 | 515 | ) ? ' |
516 | 516 | <span class="reg-pad-rght"> |
517 | 517 | <a class="status-' |
518 | - . $item->transaction()->status_ID() |
|
519 | - . '" href="' |
|
520 | - . $view_txn_lnk_url |
|
521 | - . '" title="' |
|
522 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
523 | - . '"> |
|
518 | + . $item->transaction()->status_ID() |
|
519 | + . '" href="' |
|
520 | + . $view_txn_lnk_url |
|
521 | + . '" title="' |
|
522 | + . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
523 | + . '"> |
|
524 | 524 | ' |
525 | - . $item->transaction()->pretty_paid() |
|
526 | - . ' |
|
525 | + . $item->transaction()->pretty_paid() |
|
526 | + . ' |
|
527 | 527 | </a> |
528 | 528 | <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
529 | 529 | } |
@@ -556,12 +556,12 @@ discard block |
||
556 | 556 | 'ee_read_transaction', |
557 | 557 | 'espresso_transactions_view_transaction' |
558 | 558 | ) ? '<a href="' |
559 | - . $view_txn_url |
|
560 | - . '" title="' |
|
561 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
562 | - . '"><span class="reg-pad-rght">' |
|
563 | - . $txn_total |
|
564 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
559 | + . $view_txn_url |
|
560 | + . '" title="' |
|
561 | + . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
562 | + . '"><span class="reg-pad-rght">' |
|
563 | + . $txn_total |
|
564 | + . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
565 | 565 | } else { |
566 | 566 | return '<span class="reg-pad-rght"></span>'; |
567 | 567 | } |
@@ -45,51 +45,51 @@ discard block |
||
45 | 45 | * |
46 | 46 | * @param \Registrations_Admin_Page $admin_page |
47 | 47 | */ |
48 | - public function __construct( $admin_page ) { |
|
49 | - parent::__construct( $admin_page ); |
|
48 | + public function __construct($admin_page) { |
|
49 | + parent::__construct($admin_page); |
|
50 | 50 | $this->_status = $this->_admin_page->get_registration_status_array(); |
51 | 51 | } |
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | 55 | protected function _setup_data() { |
56 | - $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( $this->_per_page ) |
|
57 | - : $this->_admin_page->get_event_attendees( $this->_per_page, false, true ); |
|
56 | + $this->_data = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees($this->_per_page) |
|
57 | + : $this->_admin_page->get_event_attendees($this->_per_page, false, true); |
|
58 | 58 | $this->_all_data_count = $this->_view !== 'trash' ? $this->_admin_page->get_event_attendees( |
59 | 59 | $this->_per_page, |
60 | 60 | true |
61 | - ) : $this->_admin_page->get_event_attendees( $this->_per_page, true, true ); |
|
61 | + ) : $this->_admin_page->get_event_attendees($this->_per_page, true, true); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | 66 | protected function _set_properties() { |
67 | - $evt_id = isset( $this->_req_data['event_id'] ) ? $this->_req_data['event_id'] : null; |
|
67 | + $evt_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
68 | 68 | $this->_wp_list_args = array( |
69 | - 'singular' => __( 'registrant', 'event_espresso' ), |
|
70 | - 'plural' => __( 'registrants', 'event_espresso' ), |
|
69 | + 'singular' => __('registrant', 'event_espresso'), |
|
70 | + 'plural' => __('registrants', 'event_espresso'), |
|
71 | 71 | 'ajax' => true, |
72 | 72 | 'screen' => $this->_admin_page->get_current_screen()->id, |
73 | 73 | ); |
74 | 74 | $columns = array(); |
75 | 75 | //$columns['_Reg_Status'] = ''; |
76 | - if ( ! empty( $evt_id ) ) { |
|
76 | + if ( ! empty($evt_id)) { |
|
77 | 77 | $columns['cb'] = '<input type="checkbox" />'; //Render a checkbox instead of text |
78 | 78 | $this->_has_checkbox_column = true; |
79 | 79 | } |
80 | 80 | $this->_columns = array( |
81 | 81 | '_REG_att_checked_in' => '<span class="dashicons dashicons-yes ee-icon-size-18"></span>', |
82 | - 'ATT_name' => __( 'Registrant', 'event_espresso' ), |
|
83 | - 'ATT_email' => __( 'Email Address', 'event_espresso' ), |
|
84 | - 'Event' => __( 'Event', 'event_espresso' ), |
|
85 | - 'PRC_name' => __( 'TKT Option', 'event_espresso' ), |
|
86 | - '_REG_final_price' => __( 'Price', 'event_espresso' ), |
|
87 | - 'TXN_paid' => __( 'Paid', 'event_espresso' ), |
|
88 | - 'TXN_total' => __( 'Total', 'event_espresso' ), |
|
82 | + 'ATT_name' => __('Registrant', 'event_espresso'), |
|
83 | + 'ATT_email' => __('Email Address', 'event_espresso'), |
|
84 | + 'Event' => __('Event', 'event_espresso'), |
|
85 | + 'PRC_name' => __('TKT Option', 'event_espresso'), |
|
86 | + '_REG_final_price' => __('Price', 'event_espresso'), |
|
87 | + 'TXN_paid' => __('Paid', 'event_espresso'), |
|
88 | + 'TXN_total' => __('Total', 'event_espresso'), |
|
89 | 89 | ); |
90 | - $this->_columns = array_merge( $columns, $this->_columns ); |
|
90 | + $this->_columns = array_merge($columns, $this->_columns); |
|
91 | 91 | $this->_primary_column = '_REG_att_checked_in'; |
92 | - if ( ! empty( $evt_id ) |
|
92 | + if ( ! empty($evt_id) |
|
93 | 93 | && EE_Registry::instance()->CAP->current_user_can( |
94 | 94 | 'ee_read_registrations', |
95 | 95 | 'espresso_registrations_registrations_reports', |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'extra_request' => |
103 | 103 | array( |
104 | 104 | 'EVT_ID' => $evt_id, |
105 | - 'return_url' => urlencode( "//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}" ), |
|
105 | + 'return_url' => urlencode("//{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"), |
|
106 | 106 | ), |
107 | 107 | ), |
108 | 108 | ); |
@@ -143,12 +143,12 @@ discard block |
||
143 | 143 | true, |
144 | 144 | $this |
145 | 145 | ) |
146 | - ? array( 'ATT_lname' => true ) |
|
147 | - : array( 'ATT_fname' => true ), |
|
148 | - 'Event' => array( 'Event.EVT.Name' => false ), |
|
146 | + ? array('ATT_lname' => true) |
|
147 | + : array('ATT_fname' => true), |
|
148 | + 'Event' => array('Event.EVT.Name' => false), |
|
149 | 149 | ); |
150 | 150 | $this->_hidden_columns = array(); |
151 | - $this->_evt = EEM_Event::instance()->get_one_by_ID( $evt_id ); |
|
151 | + $this->_evt = EEM_Event::instance()->get_one_by_ID($evt_id); |
|
152 | 152 | $this->_dtts_for_event = $this->_evt instanceof EE_Event ? $this->_evt->datetimes_ordered() : array(); |
153 | 153 | } |
154 | 154 | |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | * @param \EE_Registration $item |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - protected function _get_row_class( $item ) { |
|
162 | - $class = parent::_get_row_class( $item ); |
|
161 | + protected function _get_row_class($item) { |
|
162 | + $class = parent::_get_row_class($item); |
|
163 | 163 | //add status class |
164 | - $class .= ' ee-status-strip reg-status-' . $item->status_ID(); |
|
165 | - if ( $this->_has_checkbox_column ) { |
|
164 | + $class .= ' ee-status-strip reg-status-'.$item->status_ID(); |
|
165 | + if ($this->_has_checkbox_column) { |
|
166 | 166 | $class .= ' has-checkbox-column'; |
167 | 167 | } |
168 | 168 | return $class; |
@@ -176,61 +176,61 @@ discard block |
||
176 | 176 | */ |
177 | 177 | protected function _get_table_filters() { |
178 | 178 | $filters = $where = array(); |
179 | - $current_EVT_ID = isset( $this->_req_data['event_id'] ) ? (int) $this->_req_data['event_id'] : 0; |
|
180 | - if ( empty( $this->_dtts_for_event ) || count( $this->_dtts_for_event ) === 1 ) { |
|
179 | + $current_EVT_ID = isset($this->_req_data['event_id']) ? (int) $this->_req_data['event_id'] : 0; |
|
180 | + if (empty($this->_dtts_for_event) || count($this->_dtts_for_event) === 1) { |
|
181 | 181 | //this means we don't have an event so let's setup a filter dropdown for all the events to select |
182 | 182 | //note possible capability restrictions |
183 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) { |
|
184 | - $where['status**'] = array( '!=', 'private' ); |
|
183 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
184 | + $where['status**'] = array('!=', 'private'); |
|
185 | 185 | } |
186 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) { |
|
186 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
187 | 187 | $where['EVT_wp_user'] = get_current_user_id(); |
188 | 188 | } |
189 | 189 | $events = EEM_Event::instance()->get_all( |
190 | 190 | array( |
191 | 191 | $where, |
192 | - 'order_by' => array( 'Datetime.DTT_EVT_start' => 'DESC' ), |
|
192 | + 'order_by' => array('Datetime.DTT_EVT_start' => 'DESC'), |
|
193 | 193 | ) |
194 | 194 | ); |
195 | 195 | $evts[] = array( |
196 | 196 | 'id' => 0, |
197 | - 'text' => __( 'To toggle Check-in status, select an event', 'event_espresso' ), |
|
197 | + 'text' => __('To toggle Check-in status, select an event', 'event_espresso'), |
|
198 | 198 | ); |
199 | 199 | $checked = 'checked'; |
200 | 200 | /** @var EE_Event $evt */ |
201 | - foreach ( $events as $evt ) { |
|
201 | + foreach ($events as $evt) { |
|
202 | 202 | //any registrations for this event? |
203 | - if ( ! $evt->get_count_of_all_registrations() ) { |
|
203 | + if ( ! $evt->get_count_of_all_registrations()) { |
|
204 | 204 | continue; |
205 | 205 | } |
206 | 206 | $evts[] = array( |
207 | 207 | 'id' => $evt->ID(), |
208 | - 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get( 'EVT_name' ), $evt), |
|
208 | + 'text' => apply_filters('FHEE__EE_Event_Registrations___get_table_filters__event_name', $evt->get('EVT_name'), $evt), |
|
209 | 209 | 'class' => $evt->is_expired() ? 'ee-expired-event' : '', |
210 | 210 | ); |
211 | - if ( $evt->ID() === $current_EVT_ID && $evt->is_expired() ) { |
|
211 | + if ($evt->ID() === $current_EVT_ID && $evt->is_expired()) { |
|
212 | 212 | $checked = ''; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | $event_filter = '<div class="ee-event-filter">'; |
216 | - $event_filter .= EEH_Form_Fields::select_input( 'event_id', $evts, $current_EVT_ID ); |
|
216 | + $event_filter .= EEH_Form_Fields::select_input('event_id', $evts, $current_EVT_ID); |
|
217 | 217 | $event_filter .= '<span class="ee-event-filter-toggle">'; |
218 | - $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" ' . $checked . '> '; |
|
219 | - $event_filter .= __( 'Hide Expired Events', 'event_espresso' ); |
|
218 | + $event_filter .= '<input type="checkbox" id="js-ee-hide-expired-events" '.$checked.'> '; |
|
219 | + $event_filter .= __('Hide Expired Events', 'event_espresso'); |
|
220 | 220 | $event_filter .= '</span>'; |
221 | 221 | $event_filter .= '</div>'; |
222 | 222 | $filters[] = $event_filter; |
223 | 223 | } |
224 | - if ( ! empty( $this->_dtts_for_event ) ) { |
|
224 | + if ( ! empty($this->_dtts_for_event)) { |
|
225 | 225 | //DTT datetimes filter |
226 | - $this->_cur_dtt_id = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : 0; |
|
227 | - if ( count( $this->_dtts_for_event ) > 1 ) { |
|
228 | - $dtts[0] = __( 'To toggle check-in status, select a datetime.', 'event_espresso' ); |
|
229 | - foreach ( $this->_dtts_for_event as $dtt ) { |
|
226 | + $this->_cur_dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0; |
|
227 | + if (count($this->_dtts_for_event) > 1) { |
|
228 | + $dtts[0] = __('To toggle check-in status, select a datetime.', 'event_espresso'); |
|
229 | + foreach ($this->_dtts_for_event as $dtt) { |
|
230 | 230 | $datetime_string = $dtt->name(); |
231 | - $datetime_string = ! empty($datetime_string ) ? ' (' . $datetime_string . ')' : ''; |
|
232 | - $datetime_string = $dtt->start_date_and_time() . ' - ' . $dtt->end_date_and_time() . $datetime_string; |
|
233 | - $dtts[ $dtt->ID() ] = $datetime_string; |
|
231 | + $datetime_string = ! empty($datetime_string) ? ' ('.$datetime_string.')' : ''; |
|
232 | + $datetime_string = $dtt->start_date_and_time().' - '.$dtt->end_date_and_time().$datetime_string; |
|
233 | + $dtts[$dtt->ID()] = $datetime_string; |
|
234 | 234 | } |
235 | 235 | $input = new EE_Select_Input( |
236 | 236 | $dtts, |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | ) |
242 | 242 | ); |
243 | 243 | $filters[] = $input->get_html_for_input(); |
244 | - $filters[] = '<input type="hidden" name="event_id" value="' . $current_EVT_ID . '">'; |
|
244 | + $filters[] = '<input type="hidden" name="event_id" value="'.$current_EVT_ID.'">'; |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 | return $filters; |
@@ -260,22 +260,22 @@ discard block |
||
260 | 260 | * @throws \EE_Error |
261 | 261 | */ |
262 | 262 | protected function _get_total_event_attendees() { |
263 | - $EVT_ID = isset( $this->_req_data['event_id'] ) ? absint( $this->_req_data['event_id'] ) : false; |
|
263 | + $EVT_ID = isset($this->_req_data['event_id']) ? absint($this->_req_data['event_id']) : false; |
|
264 | 264 | $DTT_ID = $this->_cur_dtt_id; |
265 | 265 | $query_params = array(); |
266 | - if ( $EVT_ID ) { |
|
266 | + if ($EVT_ID) { |
|
267 | 267 | $query_params[0]['EVT_ID'] = $EVT_ID; |
268 | 268 | } |
269 | 269 | //if DTT is included we only show for that datetime. Otherwise we're showing for all datetimes (the event). |
270 | - if ( $DTT_ID ) { |
|
270 | + if ($DTT_ID) { |
|
271 | 271 | $query_params[0]['Ticket.Datetime.DTT_ID'] = $DTT_ID; |
272 | 272 | } |
273 | 273 | $status_ids_array = apply_filters( |
274 | 274 | 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
275 | - array( EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved ) |
|
275 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
276 | 276 | ); |
277 | - $query_params[0]['STS_ID'] = array( 'IN', $status_ids_array ); |
|
278 | - return EEM_Registration::instance()->count( $query_params ); |
|
277 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
278 | + return EEM_Registration::instance()->count($query_params); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * @param \EE_Registration $item |
285 | 285 | * @return string |
286 | 286 | */ |
287 | - public function column__Reg_Status( EE_Registration $item ) { |
|
288 | - return '<span class="ee-status-strip ee-status-strip-td reg-status-' . $item->status_ID() . '"></span>'; |
|
287 | + public function column__Reg_Status(EE_Registration $item) { |
|
288 | + return '<span class="ee-status-strip ee-status-strip-td reg-status-'.$item->status_ID().'"></span>'; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | * @return string |
296 | 296 | * @throws \EE_Error |
297 | 297 | */ |
298 | - public function column_cb( $item ) { |
|
299 | - return sprintf( '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID() ); |
|
298 | + public function column_cb($item) { |
|
299 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', $item->ID()); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | * @throws InvalidDataTypeException |
312 | 312 | * @throws InvalidInterfaceException |
313 | 313 | */ |
314 | - public function column__REG_att_checked_in( EE_Registration $item ) { |
|
314 | + public function column__REG_att_checked_in(EE_Registration $item) { |
|
315 | 315 | $attendee = $item->attendee(); |
316 | 316 | $attendee_name = $attendee instanceof EE_Attendee ? $attendee->full_name() : ''; |
317 | 317 | |
318 | - if ( $this->_cur_dtt_id === 0 && count( $this->_dtts_for_event ) === 1 ) { |
|
318 | + if ($this->_cur_dtt_id === 0 && count($this->_dtts_for_event) === 1) { |
|
319 | 319 | $latest_related_datetime = $item->get_latest_related_datetime(); |
320 | - if ( $latest_related_datetime instanceof EE_Datetime ) { |
|
320 | + if ($latest_related_datetime instanceof EE_Datetime) { |
|
321 | 321 | $this->_cur_dtt_id = $latest_related_datetime->ID(); |
322 | 322 | } |
323 | 323 | } |
@@ -325,8 +325,8 @@ discard block |
||
325 | 325 | $item, |
326 | 326 | $this->_cur_dtt_id |
327 | 327 | ); |
328 | - $nonce = wp_create_nonce( 'checkin_nonce' ); |
|
329 | - $toggle_active = ! empty ( $this->_cur_dtt_id ) |
|
328 | + $nonce = wp_create_nonce('checkin_nonce'); |
|
329 | + $toggle_active = ! empty ($this->_cur_dtt_id) |
|
330 | 330 | && EE_Registry::instance()->CAP->current_user_can( |
331 | 331 | 'ee_edit_checkin', |
332 | 332 | 'espresso_registrations_toggle_checkin_status', |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | ) |
335 | 335 | ? ' clickable trigger-checkin' |
336 | 336 | : ''; |
337 | - $mobile_view_content = ' <span class="show-on-mobile-view-only">' . $attendee_name . '</span>'; |
|
338 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . $toggle_active . '"' |
|
339 | - . ' data-_regid="' . $item->ID() . '"' |
|
340 | - . ' data-dttid="' . $this->_cur_dtt_id . '"' |
|
341 | - . ' data-nonce="' . $nonce . '">' |
|
337 | + $mobile_view_content = ' <span class="show-on-mobile-view-only">'.$attendee_name.'</span>'; |
|
338 | + return '<span class="'.$checkin_status_dashicon->cssClasses().$toggle_active.'"' |
|
339 | + . ' data-_regid="'.$item->ID().'"' |
|
340 | + . ' data-dttid="'.$this->_cur_dtt_id.'"' |
|
341 | + . ' data-nonce="'.$nonce.'">' |
|
342 | 342 | . '</span>' |
343 | 343 | . $mobile_view_content; |
344 | 344 | } |
@@ -350,21 +350,21 @@ discard block |
||
350 | 350 | * @return mixed|string|void |
351 | 351 | * @throws \EE_Error |
352 | 352 | */ |
353 | - public function column_ATT_name( EE_Registration $item ) { |
|
353 | + public function column_ATT_name(EE_Registration $item) { |
|
354 | 354 | $attendee = $item->attendee(); |
355 | - if ( ! $attendee instanceof EE_Attendee ) { |
|
356 | - return __( 'No contact record for this registration.', 'event_espresso' ); |
|
355 | + if ( ! $attendee instanceof EE_Attendee) { |
|
356 | + return __('No contact record for this registration.', 'event_espresso'); |
|
357 | 357 | } |
358 | 358 | // edit attendee link |
359 | 359 | $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
360 | - array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ), |
|
360 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
361 | 361 | REG_ADMIN_URL |
362 | 362 | ); |
363 | 363 | $name_link = EE_Registry::instance()->CAP->current_user_can( |
364 | 364 | 'ee_edit_contacts', |
365 | 365 | 'espresso_registrations_edit_attendee' |
366 | 366 | ) |
367 | - ? '<a href="' . $edit_lnk_url . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
|
367 | + ? '<a href="'.$edit_lnk_url.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
368 | 368 | . $item->attendee()->full_name() |
369 | 369 | . '</a>' |
370 | 370 | : $item->attendee()->full_name(); |
@@ -372,10 +372,10 @@ discard block |
||
372 | 372 | ? ' <sup><div class="dashicons dashicons-star-filled lt-blue-icon ee-icon-size-8"></div></sup> ' |
373 | 373 | : ''; |
374 | 374 | //add group details |
375 | - $name_link .= ' ' . sprintf( __( '(%s of %s)', 'event_espresso' ), $item->count(), $item->group_size() ); |
|
375 | + $name_link .= ' '.sprintf(__('(%s of %s)', 'event_espresso'), $item->count(), $item->group_size()); |
|
376 | 376 | //add regcode |
377 | 377 | $link = EE_Admin_Page::add_query_args_and_nonce( |
378 | - array( 'action' => 'view_registration', '_REG_ID' => $item->ID() ), |
|
378 | + array('action' => 'view_registration', '_REG_ID' => $item->ID()), |
|
379 | 379 | REG_ADMIN_URL |
380 | 380 | ); |
381 | 381 | $name_link .= '<br>'; |
@@ -384,50 +384,50 @@ discard block |
||
384 | 384 | 'view_registration', |
385 | 385 | $item->ID() |
386 | 386 | ) |
387 | - ? '<a href="' . $link . '" title="' . esc_attr__( 'View Registration Details', 'event_espresso' ) . '">' |
|
387 | + ? '<a href="'.$link.'" title="'.esc_attr__('View Registration Details', 'event_espresso').'">' |
|
388 | 388 | . $item->reg_code() |
389 | 389 | . '</a>' |
390 | 390 | : $item->reg_code(); |
391 | 391 | //status |
392 | 392 | $name_link .= '<br><span class="ee-status-text-small">'; |
393 | - $name_link .= EEH_Template::pretty_status( $item->status_ID(), false, 'sentence' ); |
|
393 | + $name_link .= EEH_Template::pretty_status($item->status_ID(), false, 'sentence'); |
|
394 | 394 | $name_link .= '</span>'; |
395 | 395 | $actions = array(); |
396 | 396 | $DTT_ID = $this->_cur_dtt_id; |
397 | - $latest_related_datetime = empty( $DTT_ID ) && ! empty( $this->_req_data['event_id'] ) && $item instanceof EE_Registration |
|
397 | + $latest_related_datetime = empty($DTT_ID) && ! empty($this->_req_data['event_id']) && $item instanceof EE_Registration |
|
398 | 398 | ? $item->get_latest_related_datetime() |
399 | 399 | : null; |
400 | 400 | $DTT_ID = $latest_related_datetime instanceof EE_Datetime |
401 | 401 | ? $latest_related_datetime->ID() |
402 | 402 | : $DTT_ID; |
403 | - if ( ! empty( $DTT_ID ) |
|
403 | + if ( ! empty($DTT_ID) |
|
404 | 404 | && EE_Registry::instance()->CAP->current_user_can( |
405 | 405 | 'ee_read_checkins', |
406 | 406 | 'espresso_registrations_registration_checkins' |
407 | 407 | ) |
408 | 408 | ) { |
409 | 409 | $checkin_list_url = EE_Admin_Page::add_query_args_and_nonce( |
410 | - array( 'action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID ) |
|
410 | + array('action' => 'registration_checkins', '_REGID' => $item->ID(), 'DTT_ID' => $DTT_ID) |
|
411 | 411 | ); |
412 | 412 | // get the timestamps for this registration's checkins, related to the selected datetime |
413 | - $timestamps = $item->get_many_related( 'Checkin', array( array( 'DTT_ID' => $DTT_ID ) ) ); |
|
414 | - if( ! empty( $timestamps ) ) { |
|
413 | + $timestamps = $item->get_many_related('Checkin', array(array('DTT_ID' => $DTT_ID))); |
|
414 | + if ( ! empty($timestamps)) { |
|
415 | 415 | // get the last timestamp |
416 | - $last_timestamp = end( $timestamps ); |
|
416 | + $last_timestamp = end($timestamps); |
|
417 | 417 | // checked in or checked out? |
418 | - $checkin_status = $last_timestamp->get( 'CHK_in' ) |
|
419 | - ? esc_html__( 'Checked In', 'event_espresso' ) |
|
420 | - : esc_html__( 'Checked Out', 'event_espresso' ); |
|
418 | + $checkin_status = $last_timestamp->get('CHK_in') |
|
419 | + ? esc_html__('Checked In', 'event_espresso') |
|
420 | + : esc_html__('Checked Out', 'event_espresso'); |
|
421 | 421 | // get timestamp string |
422 | - $timestamp_string = $last_timestamp->get_datetime( 'CHK_timestamp' ); |
|
423 | - $actions['checkin'] = '<a href="' . $checkin_list_url . '" title="' . esc_attr__( |
|
422 | + $timestamp_string = $last_timestamp->get_datetime('CHK_timestamp'); |
|
423 | + $actions['checkin'] = '<a href="'.$checkin_list_url.'" title="'.esc_attr__( |
|
424 | 424 | 'View this registrant\'s check-ins/checkouts for the datetime', |
425 | 425 | 'event_espresso' |
426 | - ) . '">' . $checkin_status . ': ' . $timestamp_string . '</a>'; |
|
426 | + ).'">'.$checkin_status.': '.$timestamp_string.'</a>'; |
|
427 | 427 | } |
428 | 428 | } |
429 | - return ( ! empty( $DTT_ID ) && ! empty( $timestamps ) ) |
|
430 | - ? sprintf( '%1$s %2$s', $name_link, $this->row_actions( $actions, true ) ) |
|
429 | + return ( ! empty($DTT_ID) && ! empty($timestamps)) |
|
430 | + ? sprintf('%1$s %2$s', $name_link, $this->row_actions($actions, true)) |
|
431 | 431 | : $name_link; |
432 | 432 | } |
433 | 433 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | * @param \EE_Registration $item |
438 | 438 | * @return string |
439 | 439 | */ |
440 | - public function column_ATT_email( EE_Registration $item ) { |
|
440 | + public function column_ATT_email(EE_Registration $item) { |
|
441 | 441 | $attendee = $item->attendee(); |
442 | 442 | return $attendee instanceof EE_Attendee ? $attendee->email() : ''; |
443 | 443 | } |
@@ -449,22 +449,22 @@ discard block |
||
449 | 449 | * @return bool|string |
450 | 450 | * @throws \EE_Error |
451 | 451 | */ |
452 | - public function column_Event( EE_Registration $item ) { |
|
452 | + public function column_Event(EE_Registration $item) { |
|
453 | 453 | try { |
454 | 454 | $event = $this->_evt instanceof EE_Event ? $this->_evt : $item->event(); |
455 | 455 | $chkin_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
456 | - array( 'action' => 'event_registrations', 'event_id' => $event->ID() ), |
|
456 | + array('action' => 'event_registrations', 'event_id' => $event->ID()), |
|
457 | 457 | REG_ADMIN_URL |
458 | 458 | ); |
459 | 459 | $event_label = EE_Registry::instance()->CAP->current_user_can( |
460 | 460 | 'ee_read_checkins', |
461 | 461 | 'espresso_registrations_registration_checkins' |
462 | - ) ? '<a href="' . $chkin_lnk_url . '" title="' . esc_attr__( |
|
462 | + ) ? '<a href="'.$chkin_lnk_url.'" title="'.esc_attr__( |
|
463 | 463 | 'View Checkins for this Event', |
464 | 464 | 'event_espresso' |
465 | - ) . '">' . $event->name() . '</a>' : $event->name(); |
|
466 | - } catch ( \EventEspresso\core\exceptions\EntityNotFoundException $e ) { |
|
467 | - $event_label = esc_html__( 'Unknown', 'event_espresso' ); |
|
465 | + ).'">'.$event->name().'</a>' : $event->name(); |
|
466 | + } catch (\EventEspresso\core\exceptions\EntityNotFoundException $e) { |
|
467 | + $event_label = esc_html__('Unknown', 'event_espresso'); |
|
468 | 468 | } |
469 | 469 | return $event_label; |
470 | 470 | } |
@@ -475,8 +475,8 @@ discard block |
||
475 | 475 | * @param \EE_Registration $item |
476 | 476 | * @return mixed|string|void |
477 | 477 | */ |
478 | - public function column_PRC_name( EE_Registration $item ) { |
|
479 | - return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __( "Unknown", "event_espresso" ); |
|
478 | + public function column_PRC_name(EE_Registration $item) { |
|
479 | + return $item->ticket() instanceof EE_Ticket ? $item->ticket()->name() : __("Unknown", "event_espresso"); |
|
480 | 480 | } |
481 | 481 | |
482 | 482 | |
@@ -487,8 +487,8 @@ discard block |
||
487 | 487 | * @param \EE_Registration $item |
488 | 488 | * @return string |
489 | 489 | */ |
490 | - public function column__REG_final_price( EE_Registration $item ) { |
|
491 | - return '<span class="reg-pad-rght">' . ' ' . $item->pretty_final_price() . '</span>'; |
|
490 | + public function column__REG_final_price(EE_Registration $item) { |
|
491 | + return '<span class="reg-pad-rght">'.' '.$item->pretty_final_price().'</span>'; |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | |
@@ -500,13 +500,13 @@ discard block |
||
500 | 500 | * @return string |
501 | 501 | * @throws \EE_Error |
502 | 502 | */ |
503 | - public function column_TXN_paid( EE_Registration $item ) { |
|
504 | - if ( $item->count() === 1 ) { |
|
505 | - if ( $item->transaction()->paid() >= $item->transaction()->total() ) { |
|
503 | + public function column_TXN_paid(EE_Registration $item) { |
|
504 | + if ($item->count() === 1) { |
|
505 | + if ($item->transaction()->paid() >= $item->transaction()->total()) { |
|
506 | 506 | return '<span class="reg-pad-rght"><div class="dashicons dashicons-yes green-icon"></div></span>'; |
507 | 507 | } else { |
508 | 508 | $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce( |
509 | - array( 'action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID() ), |
|
509 | + array('action' => 'view_transaction', 'TXN_ID' => $item->transaction_ID()), |
|
510 | 510 | TXN_ADMIN_URL |
511 | 511 | ); |
512 | 512 | return EE_Registry::instance()->CAP->current_user_can( |
@@ -519,13 +519,13 @@ discard block |
||
519 | 519 | . '" href="' |
520 | 520 | . $view_txn_lnk_url |
521 | 521 | . '" title="' |
522 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
522 | + . esc_attr__('View Transaction', 'event_espresso') |
|
523 | 523 | . '"> |
524 | 524 | ' |
525 | 525 | . $item->transaction()->pretty_paid() |
526 | 526 | . ' |
527 | 527 | </a> |
528 | - <span>' : '<span class="reg-pad-rght">' . $item->transaction()->pretty_paid() . '</span>'; |
|
528 | + <span>' : '<span class="reg-pad-rght">'.$item->transaction()->pretty_paid().'</span>'; |
|
529 | 529 | } |
530 | 530 | } else { |
531 | 531 | return '<span class="reg-pad-rght"></span>'; |
@@ -541,13 +541,13 @@ discard block |
||
541 | 541 | * @return string |
542 | 542 | * @throws \EE_Error |
543 | 543 | */ |
544 | - public function column_TXN_total( EE_Registration $item ) { |
|
544 | + public function column_TXN_total(EE_Registration $item) { |
|
545 | 545 | $txn = $item->transaction(); |
546 | - $view_txn_url = add_query_arg( array( 'action' => 'view_transaction', 'TXN_ID' => $txn->ID() ), TXN_ADMIN_URL ); |
|
547 | - if ( $item->get( 'REG_count' ) === 1 ) { |
|
546 | + $view_txn_url = add_query_arg(array('action' => 'view_transaction', 'TXN_ID' => $txn->ID()), TXN_ADMIN_URL); |
|
547 | + if ($item->get('REG_count') === 1) { |
|
548 | 548 | $line_total_obj = $txn->total_line_item(); |
549 | 549 | $txn_total = $line_total_obj instanceof EE_Line_Item |
550 | - ? $line_total_obj->get_pretty( 'LIN_total' ) |
|
550 | + ? $line_total_obj->get_pretty('LIN_total') |
|
551 | 551 | : __( |
552 | 552 | 'View Transaction', |
553 | 553 | 'event_espresso' |
@@ -558,10 +558,10 @@ discard block |
||
558 | 558 | ) ? '<a href="' |
559 | 559 | . $view_txn_url |
560 | 560 | . '" title="' |
561 | - . esc_attr__( 'View Transaction', 'event_espresso' ) |
|
561 | + . esc_attr__('View Transaction', 'event_espresso') |
|
562 | 562 | . '"><span class="reg-pad-rght">' |
563 | 563 | . $txn_total |
564 | - . '</span></a>' : '<span class="reg-pad-rght">' . $txn_total . '</span>'; |
|
564 | + . '</span></a>' : '<span class="reg-pad-rght">'.$txn_total.'</span>'; |
|
565 | 565 | } else { |
566 | 566 | return '<span class="reg-pad-rght"></span>'; |
567 | 567 | } |
@@ -90,8 +90,8 @@ |
||
90 | 90 | |
91 | 91 | |
92 | 92 | public function column_CHK_in( EE_Checkin $item ) { |
93 | - $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
94 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
93 | + $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
|
94 | + return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - public function __construct( $admin_page ) { |
|
33 | + public function __construct($admin_page) { |
|
34 | 34 | parent::__construct($admin_page); |
35 | 35 | } |
36 | 36 | |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | |
40 | 40 | protected function _setup_data() { |
41 | - $this->_data = $this->_get_checkins( $this->_per_page ); |
|
42 | - $this->_all_data_count = $this->_get_checkins( $this->_per_page, TRUE ); |
|
41 | + $this->_data = $this->_get_checkins($this->_per_page); |
|
42 | + $this->_all_data_count = $this->_get_checkins($this->_per_page, TRUE); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | ); |
61 | 61 | |
62 | 62 | $this->_sortable_columns = array( |
63 | - 'CHK_timestamp' => array( 'CHK_timestamp' => TRUE ) |
|
63 | + 'CHK_timestamp' => array('CHK_timestamp' => TRUE) |
|
64 | 64 | ); |
65 | 65 | |
66 | 66 | $this->_primary_column = 'CHK_in'; |
@@ -84,24 +84,24 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | |
87 | - function column_cb($item ) { |
|
88 | - return sprintf( '<input type="checkbox" name="checkbox[%1$s]" />', $item->ID() ); |
|
87 | + function column_cb($item) { |
|
88 | + return sprintf('<input type="checkbox" name="checkbox[%1$s]" />', $item->ID()); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
92 | - public function column_CHK_in( EE_Checkin $item ) { |
|
92 | + public function column_CHK_in(EE_Checkin $item) { |
|
93 | 93 | $checkin_status_dashicon = CheckinStatusDashicon::fromCheckin($item); |
94 | - return '<span class="' . $checkin_status_dashicon->cssClasses() . '"></span><span class="show-on-mobile-view-only">' . $item->get_datetime('CHK_timestamp') . '</span>'; |
|
94 | + return '<span class="'.$checkin_status_dashicon->cssClasses().'"></span><span class="show-on-mobile-view-only">'.$item->get_datetime('CHK_timestamp').'</span>'; |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | |
98 | 98 | |
99 | - function column_CHK_timestamp( EE_Checkin $item ) { |
|
99 | + function column_CHK_timestamp(EE_Checkin $item) { |
|
100 | 100 | $actions = array(); |
101 | - $delete_url = EE_Admin_Page::add_query_args_and_nonce( array('action' => 'delete_checkin_row', 'DTT_ID' => $this->_req_data['DTT_ID'], '_REGID' => $this->_req_data['_REGID'], 'CHK_ID' => $item->ID() ) ); |
|
102 | - $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can( 'ee_delete_checkins', 'espresso_registrations_delete_checkin_row' ) ? '<a href="' . $delete_url . '" title="' . esc_attr__('Click here to delete this check-in record', 'event_espresso') . '">' . __('Delete', 'event_espresso') . '</a>' : ''; |
|
101 | + $delete_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_checkin_row', 'DTT_ID' => $this->_req_data['DTT_ID'], '_REGID' => $this->_req_data['_REGID'], 'CHK_ID' => $item->ID())); |
|
102 | + $actions['delete_checkin'] = EE_Registry::instance()->CAP->current_user_can('ee_delete_checkins', 'espresso_registrations_delete_checkin_row') ? '<a href="'.$delete_url.'" title="'.esc_attr__('Click here to delete this check-in record', 'event_espresso').'">'.__('Delete', 'event_espresso').'</a>' : ''; |
|
103 | 103 | |
104 | - return sprintf( '%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions) ); |
|
104 | + return sprintf('%1$s %2$s', $item->get_datetime('CHK_timestamp'), $this->row_actions($actions)); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | |
@@ -116,30 +116,30 @@ discard block |
||
116 | 116 | * @param bool $count Whether to return a count or not |
117 | 117 | * @return EE_Checkin[]|int |
118 | 118 | */ |
119 | - protected function _get_checkins( $per_page = 10, $count = FALSE ) { |
|
120 | - $REG_ID = isset( $this->_req_data['_REGID'] ) ? $this->_req_data['_REGID'] : FALSE; |
|
121 | - $DTT_ID = isset( $this->_req_data['DTT_ID'] ) ? $this->_req_data['DTT_ID'] : FALSE; |
|
119 | + protected function _get_checkins($per_page = 10, $count = FALSE) { |
|
120 | + $REG_ID = isset($this->_req_data['_REGID']) ? $this->_req_data['_REGID'] : FALSE; |
|
121 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : FALSE; |
|
122 | 122 | |
123 | 123 | //if user does not have the capability for the checkins for this registration then get out! |
124 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_checkin', 'espresso_registrations_registration_checkins', $REG_ID ) ) { |
|
124 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', 'espresso_registrations_registration_checkins', $REG_ID)) { |
|
125 | 125 | return $count ? 0 : array(); |
126 | 126 | } |
127 | 127 | |
128 | 128 | //if no reg id then get out cause need a reg id |
129 | - if ( empty( $REG_ID ) || empty( $DTT_ID ) ) |
|
130 | - throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') ); |
|
129 | + if (empty($REG_ID) || empty($DTT_ID)) |
|
130 | + throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso')); |
|
131 | 131 | |
132 | 132 | //set orderby |
133 | 133 | $orderby = 'CHK_timestamp'; //note that with this table we're only providing the option to orderby the timestamp value. |
134 | 134 | |
135 | - $order = !empty( $this->_req_data['order'] ) ? $this->_req_data['order'] : 'ASC'; |
|
135 | + $order = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
136 | 136 | |
137 | - $current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1; |
|
138 | - $per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page; |
|
137 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
138 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
139 | 139 | $limit = NULL; |
140 | - if ( !$count ) { |
|
141 | - $offset = ($current_page-1)*$per_page; |
|
142 | - $limit = array( $offset, $per_page ); |
|
140 | + if ( ! $count) { |
|
141 | + $offset = ($current_page - 1) * $per_page; |
|
142 | + $limit = array($offset, $per_page); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | $_where = array( |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | 'DTT_ID' => $DTT_ID |
148 | 148 | ); |
149 | 149 | |
150 | - $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
|
150 | + $query_params = array($_where, 'order_by' => array($orderby => $order), 'limit' => $limit); |
|
151 | 151 | |
152 | 152 | //if no per_page value then we just want to return a count of all Check-ins |
153 | - if ( $count ) |
|
154 | - return EEM_Checkin::instance()->count( array( $_where ) ); |
|
153 | + if ($count) |
|
154 | + return EEM_Checkin::instance()->count(array($_where)); |
|
155 | 155 | |
156 | - return $count ? EEM_Checkin::instance()->count( array( $_where ) ) : EEM_Checkin::instance()->get_all($query_params); |
|
156 | + return $count ? EEM_Checkin::instance()->count(array($_where)) : EEM_Checkin::instance()->get_all($query_params); |
|
157 | 157 | } |
158 | 158 | |
159 | 159 | } //end class EE_Registration_CheckIn_List_Table |
@@ -1,6 +1,8 @@ discard block |
||
1 | 1 | <?php use EventEspresso\ui\browser\checkins\entities\CheckinStatusDashicon; |
2 | 2 | |
3 | -if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | +} |
|
4 | 6 | /** |
5 | 7 | * Event Espresso |
6 | 8 | * |
@@ -126,8 +128,9 @@ discard block |
||
126 | 128 | } |
127 | 129 | |
128 | 130 | //if no reg id then get out cause need a reg id |
129 | - if ( empty( $REG_ID ) || empty( $DTT_ID ) ) |
|
130 | - throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') ); |
|
131 | + if ( empty( $REG_ID ) || empty( $DTT_ID ) ) { |
|
132 | + throw new EE_Error(__('This route cannot be viewed unless registration and datetime IDs are included in the request (via REG_ID and DTT_ID parameters)', 'event_espresso') ); |
|
133 | + } |
|
131 | 134 | |
132 | 135 | //set orderby |
133 | 136 | $orderby = 'CHK_timestamp'; //note that with this table we're only providing the option to orderby the timestamp value. |
@@ -150,8 +153,9 @@ discard block |
||
150 | 153 | $query_params = array( $_where, 'order_by' => array( $orderby => $order ), 'limit' => $limit ); |
151 | 154 | |
152 | 155 | //if no per_page value then we just want to return a count of all Check-ins |
153 | - if ( $count ) |
|
154 | - return EEM_Checkin::instance()->count( array( $_where ) ); |
|
156 | + if ( $count ) { |
|
157 | + return EEM_Checkin::instance()->count( array( $_where ) ); |
|
158 | + } |
|
155 | 159 | |
156 | 160 | return $count ? EEM_Checkin::instance()->count( array( $_where ) ) : EEM_Checkin::instance()->get_all($query_params); |
157 | 161 | } |