@@ -32,158 +32,158 @@ |
||
32 | 32 | */ |
33 | 33 | class ExecuteBatchDeletion extends JobHandler |
34 | 34 | { |
35 | - /** |
|
36 | - * @var NodeGroupDao |
|
37 | - */ |
|
38 | - protected $model_obj_node_group_persister; |
|
39 | - public function __construct(NodeGroupDao $model_obj_node_group_persister) |
|
40 | - { |
|
41 | - $this->model_obj_node_group_persister = $model_obj_node_group_persister; |
|
42 | - } |
|
35 | + /** |
|
36 | + * @var NodeGroupDao |
|
37 | + */ |
|
38 | + protected $model_obj_node_group_persister; |
|
39 | + public function __construct(NodeGroupDao $model_obj_node_group_persister) |
|
40 | + { |
|
41 | + $this->model_obj_node_group_persister = $model_obj_node_group_persister; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
46 | - /** |
|
47 | - * |
|
48 | - * @param JobParameters $job_parameters |
|
49 | - * @throws BatchRequestException |
|
50 | - * @return JobStepResponse |
|
51 | - */ |
|
52 | - public function create_job(JobParameters $job_parameters) |
|
53 | - { |
|
54 | - $deletion_job_code = $job_parameters->request_datum('deletion_job_code', null); |
|
55 | - $roots = $this->model_obj_node_group_persister->getModelObjNodesInGroup($deletion_job_code); |
|
56 | - if ($roots === null) { |
|
57 | - throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso')); |
|
58 | - } |
|
59 | - $models_and_ids_to_delete = []; |
|
60 | - foreach ($roots as $root) { |
|
61 | - if (! $root instanceof ModelObjNode) { |
|
62 | - throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
63 | - } |
|
64 | - $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
65 | - } |
|
66 | - $job_parameters->set_extra_data( |
|
67 | - [ |
|
68 | - 'models_and_ids_to_delete' => $models_and_ids_to_delete |
|
69 | - ] |
|
70 | - ); |
|
71 | - // Find the job's actual size. |
|
72 | - $job_size = 0; |
|
73 | - foreach ($models_and_ids_to_delete as $model_name => $ids) { |
|
74 | - $job_size += count($ids); |
|
75 | - } |
|
76 | - $job_parameters->set_job_size($job_size); |
|
77 | - return new JobStepResponse( |
|
78 | - $job_parameters, |
|
79 | - esc_html__('Beginning to delete items...', 'event_espresso') |
|
80 | - ); |
|
81 | - } |
|
45 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
46 | + /** |
|
47 | + * |
|
48 | + * @param JobParameters $job_parameters |
|
49 | + * @throws BatchRequestException |
|
50 | + * @return JobStepResponse |
|
51 | + */ |
|
52 | + public function create_job(JobParameters $job_parameters) |
|
53 | + { |
|
54 | + $deletion_job_code = $job_parameters->request_datum('deletion_job_code', null); |
|
55 | + $roots = $this->model_obj_node_group_persister->getModelObjNodesInGroup($deletion_job_code); |
|
56 | + if ($roots === null) { |
|
57 | + throw new UnexpectedEntityException($roots, 'array', esc_html__('The job seems to be stale. Please press the back button in your browser twice.', 'event_espresso')); |
|
58 | + } |
|
59 | + $models_and_ids_to_delete = []; |
|
60 | + foreach ($roots as $root) { |
|
61 | + if (! $root instanceof ModelObjNode) { |
|
62 | + throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
63 | + } |
|
64 | + $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
65 | + } |
|
66 | + $job_parameters->set_extra_data( |
|
67 | + [ |
|
68 | + 'models_and_ids_to_delete' => $models_and_ids_to_delete |
|
69 | + ] |
|
70 | + ); |
|
71 | + // Find the job's actual size. |
|
72 | + $job_size = 0; |
|
73 | + foreach ($models_and_ids_to_delete as $model_name => $ids) { |
|
74 | + $job_size += count($ids); |
|
75 | + } |
|
76 | + $job_parameters->set_job_size($job_size); |
|
77 | + return new JobStepResponse( |
|
78 | + $job_parameters, |
|
79 | + esc_html__('Beginning to delete items...', 'event_espresso') |
|
80 | + ); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Performs another step of the job |
|
85 | - * @param JobParameters $job_parameters |
|
86 | - * @param int $batch_size |
|
87 | - * @return JobStepResponse |
|
88 | - * @throws BatchRequestException |
|
89 | - */ |
|
90 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
91 | - { |
|
92 | - // We already have the items IDs. So deleting is really fast. Let's speed it up. |
|
93 | - $batch_size *= 10; |
|
94 | - $units_processed = 0; |
|
95 | - $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []); |
|
96 | - // Build a new list of everything leftover after this request's of deletions. |
|
97 | - $models_and_ids_remaining = []; |
|
98 | - foreach ($models_and_ids_to_delete as $model_name => $ids_to_delete) { |
|
99 | - if ($units_processed < $batch_size) { |
|
100 | - $model = EE_Registry::instance()->load_model($model_name); |
|
101 | - $ids_to_delete_this_query = array_slice($ids_to_delete, 0, $batch_size - $units_processed, true); |
|
102 | - if ($model->has_primary_key_field()) { |
|
103 | - $where_conditions = [ |
|
104 | - $model->primary_key_name() => [ |
|
105 | - 'IN', |
|
106 | - $ids_to_delete_this_query |
|
107 | - ] |
|
108 | - ]; |
|
109 | - } else { |
|
110 | - $where_conditions = [ |
|
111 | - 'OR' => [] |
|
112 | - ]; |
|
113 | - foreach ($ids_to_delete_this_query as $index_primary_key_string) { |
|
114 | - $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
|
115 | - $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
116 | - } |
|
117 | - } |
|
118 | - // Deleting time! |
|
119 | - // The model's deletion method reports every ROW deleted, and in the case of CPT models that will be |
|
120 | - // two rows deleted for event CPT item. So don't rely on it for the count of items deleted. |
|
121 | - $model->delete_permanently( |
|
122 | - [ |
|
123 | - $where_conditions |
|
124 | - ], |
|
125 | - false |
|
126 | - ); |
|
127 | - $units_processed += count($ids_to_delete_this_query); |
|
128 | - $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query); |
|
129 | - // If there's any more from this model, we'll do them next time. |
|
130 | - if (count($remaining_ids) > 0) { |
|
131 | - $models_and_ids_remaining[ $model_name ] = $remaining_ids; |
|
132 | - } |
|
133 | - } else { |
|
134 | - $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ]; |
|
135 | - } |
|
136 | - } |
|
137 | - $job_parameters->mark_processed($units_processed); |
|
138 | - // All done deleting for this request. Is there anything to do next time? |
|
139 | - if (empty($models_and_ids_remaining)) { |
|
140 | - $job_parameters->set_status(JobParameters::status_complete); |
|
141 | - return new JobStepResponse( |
|
142 | - $job_parameters, |
|
143 | - esc_html__('Deletion complete.', 'event_espresso') |
|
144 | - ); |
|
145 | - } |
|
146 | - $job_parameters->add_extra_data('models_and_ids_to_delete', $models_and_ids_remaining); |
|
147 | - return new JobStepResponse( |
|
148 | - $job_parameters, |
|
149 | - sprintf( |
|
150 | - esc_html__('Deleted %d items.', 'event_espresso'), |
|
151 | - $units_processed |
|
152 | - ) |
|
153 | - ); |
|
154 | - } |
|
83 | + /** |
|
84 | + * Performs another step of the job |
|
85 | + * @param JobParameters $job_parameters |
|
86 | + * @param int $batch_size |
|
87 | + * @return JobStepResponse |
|
88 | + * @throws BatchRequestException |
|
89 | + */ |
|
90 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
91 | + { |
|
92 | + // We already have the items IDs. So deleting is really fast. Let's speed it up. |
|
93 | + $batch_size *= 10; |
|
94 | + $units_processed = 0; |
|
95 | + $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []); |
|
96 | + // Build a new list of everything leftover after this request's of deletions. |
|
97 | + $models_and_ids_remaining = []; |
|
98 | + foreach ($models_and_ids_to_delete as $model_name => $ids_to_delete) { |
|
99 | + if ($units_processed < $batch_size) { |
|
100 | + $model = EE_Registry::instance()->load_model($model_name); |
|
101 | + $ids_to_delete_this_query = array_slice($ids_to_delete, 0, $batch_size - $units_processed, true); |
|
102 | + if ($model->has_primary_key_field()) { |
|
103 | + $where_conditions = [ |
|
104 | + $model->primary_key_name() => [ |
|
105 | + 'IN', |
|
106 | + $ids_to_delete_this_query |
|
107 | + ] |
|
108 | + ]; |
|
109 | + } else { |
|
110 | + $where_conditions = [ |
|
111 | + 'OR' => [] |
|
112 | + ]; |
|
113 | + foreach ($ids_to_delete_this_query as $index_primary_key_string) { |
|
114 | + $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
|
115 | + $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
116 | + } |
|
117 | + } |
|
118 | + // Deleting time! |
|
119 | + // The model's deletion method reports every ROW deleted, and in the case of CPT models that will be |
|
120 | + // two rows deleted for event CPT item. So don't rely on it for the count of items deleted. |
|
121 | + $model->delete_permanently( |
|
122 | + [ |
|
123 | + $where_conditions |
|
124 | + ], |
|
125 | + false |
|
126 | + ); |
|
127 | + $units_processed += count($ids_to_delete_this_query); |
|
128 | + $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query); |
|
129 | + // If there's any more from this model, we'll do them next time. |
|
130 | + if (count($remaining_ids) > 0) { |
|
131 | + $models_and_ids_remaining[ $model_name ] = $remaining_ids; |
|
132 | + } |
|
133 | + } else { |
|
134 | + $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ]; |
|
135 | + } |
|
136 | + } |
|
137 | + $job_parameters->mark_processed($units_processed); |
|
138 | + // All done deleting for this request. Is there anything to do next time? |
|
139 | + if (empty($models_and_ids_remaining)) { |
|
140 | + $job_parameters->set_status(JobParameters::status_complete); |
|
141 | + return new JobStepResponse( |
|
142 | + $job_parameters, |
|
143 | + esc_html__('Deletion complete.', 'event_espresso') |
|
144 | + ); |
|
145 | + } |
|
146 | + $job_parameters->add_extra_data('models_and_ids_to_delete', $models_and_ids_remaining); |
|
147 | + return new JobStepResponse( |
|
148 | + $job_parameters, |
|
149 | + sprintf( |
|
150 | + esc_html__('Deleted %d items.', 'event_espresso'), |
|
151 | + $units_processed |
|
152 | + ) |
|
153 | + ); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Performs any clean-up logic when we know the job is completed |
|
158 | - * @param JobParameters $job_parameters |
|
159 | - * @return JobStepResponse |
|
160 | - */ |
|
161 | - public function cleanup_job(JobParameters $job_parameters) |
|
162 | - { |
|
163 | - $this->model_obj_node_group_persister->deleteModelObjNodesInGroup( |
|
164 | - $job_parameters->request_datum('deletion_job_code') |
|
165 | - ); |
|
166 | - // For backwards compatibility with how we used to delete events, make sure we still trigger the old action. |
|
167 | - $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []); |
|
168 | - foreach ($models_and_ids_to_delete['Event'] as $event_id) { |
|
169 | - // Create a log entry so we know who and when this event was permanently deleted. |
|
170 | - (EE_Change_Log::new_instance( |
|
171 | - [ |
|
172 | - 'OBJ_ID' => $event_id, |
|
173 | - 'OBJ_type' => 'Event', |
|
174 | - 'LOG_message' => sprintf( |
|
175 | - esc_html__('Event %1$d permanently deleted using ExecuteBatchDeletion.', 'event_espresso'), |
|
176 | - $event_id |
|
177 | - ) |
|
178 | - ] |
|
179 | - ))->save(); |
|
180 | - do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id); |
|
181 | - } |
|
182 | - return new JobStepResponse( |
|
183 | - $job_parameters, |
|
184 | - esc_html__('All done', 'event_espresso') |
|
185 | - ); |
|
186 | - } |
|
156 | + /** |
|
157 | + * Performs any clean-up logic when we know the job is completed |
|
158 | + * @param JobParameters $job_parameters |
|
159 | + * @return JobStepResponse |
|
160 | + */ |
|
161 | + public function cleanup_job(JobParameters $job_parameters) |
|
162 | + { |
|
163 | + $this->model_obj_node_group_persister->deleteModelObjNodesInGroup( |
|
164 | + $job_parameters->request_datum('deletion_job_code') |
|
165 | + ); |
|
166 | + // For backwards compatibility with how we used to delete events, make sure we still trigger the old action. |
|
167 | + $models_and_ids_to_delete = $job_parameters->extra_datum('models_and_ids_to_delete', []); |
|
168 | + foreach ($models_and_ids_to_delete['Event'] as $event_id) { |
|
169 | + // Create a log entry so we know who and when this event was permanently deleted. |
|
170 | + (EE_Change_Log::new_instance( |
|
171 | + [ |
|
172 | + 'OBJ_ID' => $event_id, |
|
173 | + 'OBJ_type' => 'Event', |
|
174 | + 'LOG_message' => sprintf( |
|
175 | + esc_html__('Event %1$d permanently deleted using ExecuteBatchDeletion.', 'event_espresso'), |
|
176 | + $event_id |
|
177 | + ) |
|
178 | + ] |
|
179 | + ))->save(); |
|
180 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $event_id); |
|
181 | + } |
|
182 | + return new JobStepResponse( |
|
183 | + $job_parameters, |
|
184 | + esc_html__('All done', 'event_espresso') |
|
185 | + ); |
|
186 | + } |
|
187 | 187 | } |
188 | 188 | // End of file EventDeletion.php |
189 | 189 | // Location: EventEspressoBatchRequest\JobHandlers/EventDeletion.php |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | } |
59 | 59 | $models_and_ids_to_delete = []; |
60 | 60 | foreach ($roots as $root) { |
61 | - if (! $root instanceof ModelObjNode) { |
|
61 | + if ( ! $root instanceof ModelObjNode) { |
|
62 | 62 | throw new UnexpectedEntityException($root, 'ModelObjNode'); |
63 | 63 | } |
64 | 64 | $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | ]; |
113 | 113 | foreach ($ids_to_delete_this_query as $index_primary_key_string) { |
114 | 114 | $keys_n_values = $model->parse_index_primary_key_string($index_primary_key_string); |
115 | - $where_conditions['OR'][ 'AND*' . $index_primary_key_string ] = $keys_n_values; |
|
115 | + $where_conditions['OR']['AND*'.$index_primary_key_string] = $keys_n_values; |
|
116 | 116 | } |
117 | 117 | } |
118 | 118 | // Deleting time! |
@@ -128,10 +128,10 @@ discard block |
||
128 | 128 | $remaining_ids = array_diff_key($ids_to_delete, $ids_to_delete_this_query); |
129 | 129 | // If there's any more from this model, we'll do them next time. |
130 | 130 | if (count($remaining_ids) > 0) { |
131 | - $models_and_ids_remaining[ $model_name ] = $remaining_ids; |
|
131 | + $models_and_ids_remaining[$model_name] = $remaining_ids; |
|
132 | 132 | } |
133 | 133 | } else { |
134 | - $models_and_ids_remaining[ $model_name ] = $models_and_ids_to_delete[ $model_name ]; |
|
134 | + $models_and_ids_remaining[$model_name] = $models_and_ids_to_delete[$model_name]; |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | $job_parameters->mark_processed($units_processed); |
@@ -89,17 +89,17 @@ discard block |
||
89 | 89 | $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
90 | 90 | $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
91 | 91 | $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
92 | - if (empty($event_ids) || !is_array($event_ids)) { |
|
92 | + if (empty($event_ids) || ! is_array($event_ids)) { |
|
93 | 93 | throw new EE_Error( |
94 | 94 | esc_html__('No Events were found to delete.', 'event_espresso') |
95 | 95 | ); |
96 | 96 | } |
97 | 97 | $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
98 | - if (!is_array($datetime_ids)) { |
|
98 | + if ( ! is_array($datetime_ids)) { |
|
99 | 99 | throw new UnexpectedEntityException($datetime_ids, 'array'); |
100 | 100 | } |
101 | 101 | $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
102 | - if (!is_array($registration_ids)) { |
|
102 | + if ( ! is_array($registration_ids)) { |
|
103 | 103 | throw new UnexpectedEntityException($registration_ids, 'array'); |
104 | 104 | } |
105 | 105 | $num_registrations_to_show = 10; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | ]; |
136 | 136 | return [ |
137 | 137 | 'admin_page_content' => EEH_Template::display_template( |
138 | - EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
|
138 | + EVENTS_TEMPLATE_PATH.'event_preview_deletion.template.php', |
|
139 | 139 | [ |
140 | 140 | 'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
141 | 141 | $confirm_deletion_args, |
@@ -31,127 +31,127 @@ |
||
31 | 31 | */ |
32 | 32 | class PreviewDeletion |
33 | 33 | { |
34 | - /** |
|
35 | - * @var NodeGroupDao |
|
36 | - */ |
|
37 | - protected $dao; |
|
34 | + /** |
|
35 | + * @var NodeGroupDao |
|
36 | + */ |
|
37 | + protected $dao; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var EEM_Event |
|
41 | - */ |
|
42 | - protected $event_model; |
|
39 | + /** |
|
40 | + * @var EEM_Event |
|
41 | + */ |
|
42 | + protected $event_model; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var EEM_Datetime |
|
46 | - */ |
|
47 | - protected $datetime_model; |
|
44 | + /** |
|
45 | + * @var EEM_Datetime |
|
46 | + */ |
|
47 | + protected $datetime_model; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var EEM_Registration |
|
51 | - */ |
|
52 | - protected $registration_model; |
|
49 | + /** |
|
50 | + * @var EEM_Registration |
|
51 | + */ |
|
52 | + protected $registration_model; |
|
53 | 53 | |
54 | - /** |
|
55 | - * PreviewDeletion constructor. |
|
56 | - * @param NodeGroupDao $dao |
|
57 | - * @param EEM_Event $event_model |
|
58 | - * @param EEM_Datetime $datetime_model |
|
59 | - * @param EEM_Registration $registration_model |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - NodeGroupDao $dao, |
|
63 | - EEM_Event $event_model, |
|
64 | - EEM_Datetime $datetime_model, |
|
65 | - EEM_Registration $registration_model |
|
66 | - ) { |
|
67 | - $this->dao = $dao; |
|
68 | - $this->event_model = $event_model; |
|
69 | - $this->datetime_model = $datetime_model; |
|
70 | - $this->registration_model = $registration_model; |
|
71 | - } |
|
54 | + /** |
|
55 | + * PreviewDeletion constructor. |
|
56 | + * @param NodeGroupDao $dao |
|
57 | + * @param EEM_Event $event_model |
|
58 | + * @param EEM_Datetime $datetime_model |
|
59 | + * @param EEM_Registration $registration_model |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + NodeGroupDao $dao, |
|
63 | + EEM_Event $event_model, |
|
64 | + EEM_Datetime $datetime_model, |
|
65 | + EEM_Registration $registration_model |
|
66 | + ) { |
|
67 | + $this->dao = $dao; |
|
68 | + $this->event_model = $event_model; |
|
69 | + $this->datetime_model = $datetime_model; |
|
70 | + $this->registration_model = $registration_model; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Renders the preview deletion page. |
|
75 | - * @since 4.10.12.p |
|
76 | - * @param $request_data |
|
77 | - * @param $admin_base_url |
|
78 | - * @return array |
|
79 | - * @throws UnexpectedEntityException |
|
80 | - * @throws DomainException |
|
81 | - * @throws EE_Error |
|
82 | - * @throws InvalidDataTypeException |
|
83 | - * @throws InvalidInterfaceException |
|
84 | - * @throws InvalidArgumentException |
|
85 | - * @throws ReflectionException |
|
86 | - */ |
|
87 | - public function handle($request_data, $admin_base_url) |
|
88 | - { |
|
89 | - $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
|
90 | - $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
|
91 | - $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
|
92 | - if (empty($event_ids) || !is_array($event_ids)) { |
|
93 | - throw new EE_Error( |
|
94 | - esc_html__('No Events were found to delete.', 'event_espresso') |
|
95 | - ); |
|
96 | - } |
|
97 | - $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
|
98 | - if (!is_array($datetime_ids)) { |
|
99 | - throw new UnexpectedEntityException($datetime_ids, 'array'); |
|
100 | - } |
|
101 | - $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
|
102 | - if (!is_array($registration_ids)) { |
|
103 | - throw new UnexpectedEntityException($registration_ids, 'array'); |
|
104 | - } |
|
105 | - $num_registrations_to_show = 10; |
|
106 | - $reg_count = count($registration_ids); |
|
107 | - if ($reg_count > $num_registrations_to_show) { |
|
108 | - $registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show); |
|
109 | - } |
|
110 | - $form = new ConfirmEventDeletionForm($event_ids); |
|
111 | - $events = $this->event_model->get_all_deleted_and_undeleted( |
|
112 | - [ |
|
113 | - [ |
|
114 | - 'EVT_ID' => ['IN', $event_ids] |
|
115 | - ] |
|
116 | - ] |
|
117 | - ); |
|
118 | - $datetimes = $this->datetime_model->get_all_deleted_and_undeleted( |
|
119 | - [ |
|
120 | - [ |
|
121 | - 'DTT_ID' => ['IN', $datetime_ids] |
|
122 | - ] |
|
123 | - ] |
|
124 | - ); |
|
125 | - $registrations = $this->registration_model->get_all_deleted_and_undeleted( |
|
126 | - [ |
|
127 | - [ |
|
128 | - 'REG_ID' => ['IN', $registration_ids] |
|
129 | - ] |
|
130 | - ] |
|
131 | - ); |
|
132 | - $confirm_deletion_args = [ |
|
133 | - 'action' => 'confirm_deletion', |
|
134 | - 'deletion_job_code' => $deletion_job_code |
|
135 | - ]; |
|
136 | - return [ |
|
137 | - 'admin_page_content' => EEH_Template::display_template( |
|
138 | - EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
|
139 | - [ |
|
140 | - 'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
|
141 | - $confirm_deletion_args, |
|
142 | - $admin_base_url |
|
143 | - ), |
|
144 | - 'form' => $form, |
|
145 | - 'events' => $events, |
|
146 | - 'datetimes' => $datetimes, |
|
147 | - 'registrations' => $registrations, |
|
148 | - 'reg_count' => $reg_count, |
|
149 | - 'num_registrations_to_show' => $num_registrations_to_show |
|
150 | - ], |
|
151 | - true |
|
152 | - ) |
|
153 | - ]; |
|
154 | - } |
|
73 | + /** |
|
74 | + * Renders the preview deletion page. |
|
75 | + * @since 4.10.12.p |
|
76 | + * @param $request_data |
|
77 | + * @param $admin_base_url |
|
78 | + * @return array |
|
79 | + * @throws UnexpectedEntityException |
|
80 | + * @throws DomainException |
|
81 | + * @throws EE_Error |
|
82 | + * @throws InvalidDataTypeException |
|
83 | + * @throws InvalidInterfaceException |
|
84 | + * @throws InvalidArgumentException |
|
85 | + * @throws ReflectionException |
|
86 | + */ |
|
87 | + public function handle($request_data, $admin_base_url) |
|
88 | + { |
|
89 | + $deletion_job_code = isset($request_data['deletion_job_code']) ? sanitize_key($request_data['deletion_job_code']) : ''; |
|
90 | + $models_and_ids_to_delete = $this->dao->getModelsAndIdsFromGroup($deletion_job_code); |
|
91 | + $event_ids = isset($models_and_ids_to_delete['Event']) ? $models_and_ids_to_delete['Event'] : array(); |
|
92 | + if (empty($event_ids) || !is_array($event_ids)) { |
|
93 | + throw new EE_Error( |
|
94 | + esc_html__('No Events were found to delete.', 'event_espresso') |
|
95 | + ); |
|
96 | + } |
|
97 | + $datetime_ids = isset($models_and_ids_to_delete['Datetime']) ? $models_and_ids_to_delete['Datetime'] : array(); |
|
98 | + if (!is_array($datetime_ids)) { |
|
99 | + throw new UnexpectedEntityException($datetime_ids, 'array'); |
|
100 | + } |
|
101 | + $registration_ids = isset($models_and_ids_to_delete['Registration']) ? $models_and_ids_to_delete['Registration'] : array(); |
|
102 | + if (!is_array($registration_ids)) { |
|
103 | + throw new UnexpectedEntityException($registration_ids, 'array'); |
|
104 | + } |
|
105 | + $num_registrations_to_show = 10; |
|
106 | + $reg_count = count($registration_ids); |
|
107 | + if ($reg_count > $num_registrations_to_show) { |
|
108 | + $registration_ids = array_slice($registration_ids, 0, $num_registrations_to_show); |
|
109 | + } |
|
110 | + $form = new ConfirmEventDeletionForm($event_ids); |
|
111 | + $events = $this->event_model->get_all_deleted_and_undeleted( |
|
112 | + [ |
|
113 | + [ |
|
114 | + 'EVT_ID' => ['IN', $event_ids] |
|
115 | + ] |
|
116 | + ] |
|
117 | + ); |
|
118 | + $datetimes = $this->datetime_model->get_all_deleted_and_undeleted( |
|
119 | + [ |
|
120 | + [ |
|
121 | + 'DTT_ID' => ['IN', $datetime_ids] |
|
122 | + ] |
|
123 | + ] |
|
124 | + ); |
|
125 | + $registrations = $this->registration_model->get_all_deleted_and_undeleted( |
|
126 | + [ |
|
127 | + [ |
|
128 | + 'REG_ID' => ['IN', $registration_ids] |
|
129 | + ] |
|
130 | + ] |
|
131 | + ); |
|
132 | + $confirm_deletion_args = [ |
|
133 | + 'action' => 'confirm_deletion', |
|
134 | + 'deletion_job_code' => $deletion_job_code |
|
135 | + ]; |
|
136 | + return [ |
|
137 | + 'admin_page_content' => EEH_Template::display_template( |
|
138 | + EVENTS_TEMPLATE_PATH . 'event_preview_deletion.template.php', |
|
139 | + [ |
|
140 | + 'form_url' => EE_Admin_Page::add_query_args_and_nonce( |
|
141 | + $confirm_deletion_args, |
|
142 | + $admin_base_url |
|
143 | + ), |
|
144 | + 'form' => $form, |
|
145 | + 'events' => $events, |
|
146 | + 'datetimes' => $datetimes, |
|
147 | + 'registrations' => $registrations, |
|
148 | + 'reg_count' => $reg_count, |
|
149 | + 'num_registrations_to_show' => $num_registrations_to_show |
|
150 | + ], |
|
151 | + true |
|
152 | + ) |
|
153 | + ]; |
|
154 | + } |
|
155 | 155 | } |
156 | 156 | // End of file PreviewDeletion.php |
157 | 157 | // Location: EventEspresso\core\domain\services\admin\events\data/PreviewDeletion.php |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | // Add entity nodes for each of the model objects we fetched. |
94 | 94 | foreach ($related_model_objs as $related_model_obj) { |
95 | 95 | $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models); |
96 | - $this->nodes[ $related_model_obj->ID() ] = $entity_node; |
|
97 | - $new_item_nodes[ $related_model_obj->ID() ] = $entity_node; |
|
96 | + $this->nodes[$related_model_obj->ID()] = $entity_node; |
|
97 | + $new_item_nodes[$related_model_obj->ID()] = $entity_node; |
|
98 | 98 | } |
99 | 99 | $num_identified += count($new_item_nodes); |
100 | 100 | if ($num_identified < $model_objects_to_identify) { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | protected function allChildrenComplete() |
121 | 121 | { |
122 | 122 | foreach ($this->nodes as $model_obj_node) { |
123 | - if (! $model_obj_node->isComplete()) { |
|
123 | + if ( ! $model_obj_node->isComplete()) { |
|
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget) |
138 | 138 | { |
139 | 139 | $work_done = 0; |
140 | - if (! $model_obj_nodes) { |
|
140 | + if ( ! $model_obj_nodes) { |
|
141 | 141 | return 0; |
142 | 142 | } |
143 | 143 | foreach ($model_obj_nodes as $model_obj_node) { |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | */ |
200 | 200 | protected function whereQueryParams() |
201 | 201 | { |
202 | - $where_params = [ |
|
202 | + $where_params = [ |
|
203 | 203 | $this->related_model->get_foreign_key_to( |
204 | 204 | $this->main_model->get_this_model_name() |
205 | 205 | )->get_name() => $this->id |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | $relation_settings = null; |
213 | 213 | } |
214 | 214 | if ($relation_settings instanceof EE_Has_Many_Any_Relation) { |
215 | - $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name(); |
|
215 | + $where_params[$this->related_model->get_field_containing_related_model_name()->get_name()] = $this->main_model->get_this_model_name(); |
|
216 | 216 | } |
217 | 217 | return $where_params; |
218 | 218 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | 'objs' => [] |
229 | 229 | ]; |
230 | 230 | foreach ($this->nodes as $id => $model_obj_node) { |
231 | - $tree['objs'][ $id ] = $model_obj_node->toArray(); |
|
231 | + $tree['objs'][$id] = $model_obj_node->toArray(); |
|
232 | 232 | } |
233 | 233 | return $tree; |
234 | 234 | } |
@@ -27,289 +27,289 @@ |
||
27 | 27 | */ |
28 | 28 | class RelationNode extends BaseNode |
29 | 29 | { |
30 | - /** |
|
31 | - * @var string|int |
|
32 | - */ |
|
33 | - protected $id; |
|
30 | + /** |
|
31 | + * @var string|int |
|
32 | + */ |
|
33 | + protected $id; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var EEM_Base |
|
37 | - */ |
|
38 | - protected $main_model; |
|
35 | + /** |
|
36 | + * @var EEM_Base |
|
37 | + */ |
|
38 | + protected $main_model; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var int |
|
42 | - */ |
|
43 | - protected $count; |
|
40 | + /** |
|
41 | + * @var int |
|
42 | + */ |
|
43 | + protected $count; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @var EEM_Base |
|
47 | - */ |
|
48 | - protected $related_model; |
|
45 | + /** |
|
46 | + * @var EEM_Base |
|
47 | + */ |
|
48 | + protected $related_model; |
|
49 | 49 | |
50 | - /** |
|
51 | - * @var ModelObjNode[] |
|
52 | - */ |
|
53 | - protected $nodes; |
|
50 | + /** |
|
51 | + * @var ModelObjNode[] |
|
52 | + */ |
|
53 | + protected $nodes; |
|
54 | 54 | |
55 | - /** |
|
56 | - * RelationNode constructor. |
|
57 | - * @param $main_model_obj_id |
|
58 | - * @param EEM_Base $main_model |
|
59 | - * @param EEM_Base $related_model |
|
60 | - * @param array $dont_traverse_models array of model names we DON'T want to traverse |
|
61 | - */ |
|
62 | - public function __construct( |
|
63 | - $main_model_obj_id, |
|
64 | - EEM_Base $main_model, |
|
65 | - EEM_Base $related_model, |
|
66 | - array $dont_traverse_models = [] |
|
67 | - ) { |
|
68 | - $this->id = $main_model_obj_id; |
|
69 | - $this->main_model = $main_model; |
|
70 | - $this->related_model = $related_model; |
|
71 | - $this->nodes = []; |
|
72 | - $this->dont_traverse_models = $dont_traverse_models; |
|
73 | - } |
|
55 | + /** |
|
56 | + * RelationNode constructor. |
|
57 | + * @param $main_model_obj_id |
|
58 | + * @param EEM_Base $main_model |
|
59 | + * @param EEM_Base $related_model |
|
60 | + * @param array $dont_traverse_models array of model names we DON'T want to traverse |
|
61 | + */ |
|
62 | + public function __construct( |
|
63 | + $main_model_obj_id, |
|
64 | + EEM_Base $main_model, |
|
65 | + EEM_Base $related_model, |
|
66 | + array $dont_traverse_models = [] |
|
67 | + ) { |
|
68 | + $this->id = $main_model_obj_id; |
|
69 | + $this->main_model = $main_model; |
|
70 | + $this->related_model = $related_model; |
|
71 | + $this->nodes = []; |
|
72 | + $this->dont_traverse_models = $dont_traverse_models; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Here is where most of the work happens. We've counted how many related model objects exist, here we identify |
|
78 | - * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc. |
|
79 | - * @since 4.10.12.p |
|
80 | - * @param int $model_objects_to_identify |
|
81 | - * @return int |
|
82 | - * @throws EE_Error |
|
83 | - * @throws InvalidArgumentException |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - * @throws InvalidInterfaceException |
|
86 | - * @throws ReflectionException |
|
87 | - */ |
|
88 | - protected function work($model_objects_to_identify) |
|
89 | - { |
|
90 | - $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify); |
|
91 | - if ($num_identified < $model_objects_to_identify) { |
|
92 | - $related_model_objs = $this->related_model->get_all( |
|
93 | - [ |
|
94 | - $this->whereQueryParams(), |
|
95 | - 'limit' => [ |
|
96 | - count($this->nodes), |
|
97 | - $model_objects_to_identify - $num_identified |
|
98 | - ] |
|
99 | - ] |
|
100 | - ); |
|
101 | - $new_item_nodes = []; |
|
76 | + /** |
|
77 | + * Here is where most of the work happens. We've counted how many related model objects exist, here we identify |
|
78 | + * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc. |
|
79 | + * @since 4.10.12.p |
|
80 | + * @param int $model_objects_to_identify |
|
81 | + * @return int |
|
82 | + * @throws EE_Error |
|
83 | + * @throws InvalidArgumentException |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + * @throws InvalidInterfaceException |
|
86 | + * @throws ReflectionException |
|
87 | + */ |
|
88 | + protected function work($model_objects_to_identify) |
|
89 | + { |
|
90 | + $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify); |
|
91 | + if ($num_identified < $model_objects_to_identify) { |
|
92 | + $related_model_objs = $this->related_model->get_all( |
|
93 | + [ |
|
94 | + $this->whereQueryParams(), |
|
95 | + 'limit' => [ |
|
96 | + count($this->nodes), |
|
97 | + $model_objects_to_identify - $num_identified |
|
98 | + ] |
|
99 | + ] |
|
100 | + ); |
|
101 | + $new_item_nodes = []; |
|
102 | 102 | |
103 | - // Add entity nodes for each of the model objects we fetched. |
|
104 | - foreach ($related_model_objs as $related_model_obj) { |
|
105 | - $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models); |
|
106 | - $this->nodes[ $related_model_obj->ID() ] = $entity_node; |
|
107 | - $new_item_nodes[ $related_model_obj->ID() ] = $entity_node; |
|
108 | - } |
|
109 | - $num_identified += count($new_item_nodes); |
|
110 | - if ($num_identified < $model_objects_to_identify) { |
|
111 | - // And lastly do the work. |
|
112 | - $num_identified += $this->visitAlreadyDiscoveredNodes( |
|
113 | - $new_item_nodes, |
|
114 | - $model_objects_to_identify - $num_identified |
|
115 | - ); |
|
116 | - } |
|
117 | - } |
|
103 | + // Add entity nodes for each of the model objects we fetched. |
|
104 | + foreach ($related_model_objs as $related_model_obj) { |
|
105 | + $entity_node = new ModelObjNode($related_model_obj->ID(), $related_model_obj->get_model(), $this->dont_traverse_models); |
|
106 | + $this->nodes[ $related_model_obj->ID() ] = $entity_node; |
|
107 | + $new_item_nodes[ $related_model_obj->ID() ] = $entity_node; |
|
108 | + } |
|
109 | + $num_identified += count($new_item_nodes); |
|
110 | + if ($num_identified < $model_objects_to_identify) { |
|
111 | + // And lastly do the work. |
|
112 | + $num_identified += $this->visitAlreadyDiscoveredNodes( |
|
113 | + $new_item_nodes, |
|
114 | + $model_objects_to_identify - $num_identified |
|
115 | + ); |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) { |
|
120 | - $this->complete = true; |
|
121 | - } |
|
122 | - return $num_identified; |
|
123 | - } |
|
119 | + if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) { |
|
120 | + $this->complete = true; |
|
121 | + } |
|
122 | + return $num_identified; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Checks if all the identified child nodes are complete or not. |
|
127 | - * @since 4.10.12.p |
|
128 | - * @return bool |
|
129 | - */ |
|
130 | - protected function allChildrenComplete() |
|
131 | - { |
|
132 | - foreach ($this->nodes as $model_obj_node) { |
|
133 | - if (! $model_obj_node->isComplete()) { |
|
134 | - return false; |
|
135 | - } |
|
136 | - } |
|
137 | - return true; |
|
138 | - } |
|
125 | + /** |
|
126 | + * Checks if all the identified child nodes are complete or not. |
|
127 | + * @since 4.10.12.p |
|
128 | + * @return bool |
|
129 | + */ |
|
130 | + protected function allChildrenComplete() |
|
131 | + { |
|
132 | + foreach ($this->nodes as $model_obj_node) { |
|
133 | + if (! $model_obj_node->isComplete()) { |
|
134 | + return false; |
|
135 | + } |
|
136 | + } |
|
137 | + return true; |
|
138 | + } |
|
139 | 139 | |
140 | - /** |
|
141 | - * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget. |
|
142 | - * @since 4.10.12.p |
|
143 | - * @param ModelObjNode[] $model_obj_nodes |
|
144 | - * @param $work_budget |
|
145 | - * @return int |
|
146 | - */ |
|
147 | - protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget) |
|
148 | - { |
|
149 | - $work_done = 0; |
|
150 | - if (! $model_obj_nodes) { |
|
151 | - return 0; |
|
152 | - } |
|
153 | - foreach ($model_obj_nodes as $model_obj_node) { |
|
154 | - if ($work_done >= $work_budget) { |
|
155 | - break; |
|
156 | - } |
|
157 | - $work_done += $model_obj_node->visit($work_budget - $work_done); |
|
158 | - } |
|
159 | - return $work_done; |
|
160 | - } |
|
140 | + /** |
|
141 | + * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget. |
|
142 | + * @since 4.10.12.p |
|
143 | + * @param ModelObjNode[] $model_obj_nodes |
|
144 | + * @param $work_budget |
|
145 | + * @return int |
|
146 | + */ |
|
147 | + protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget) |
|
148 | + { |
|
149 | + $work_done = 0; |
|
150 | + if (! $model_obj_nodes) { |
|
151 | + return 0; |
|
152 | + } |
|
153 | + foreach ($model_obj_nodes as $model_obj_node) { |
|
154 | + if ($work_done >= $work_budget) { |
|
155 | + break; |
|
156 | + } |
|
157 | + $work_done += $model_obj_node->visit($work_budget - $work_done); |
|
158 | + } |
|
159 | + return $work_done; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * Whether this item has already been initialized |
|
164 | - */ |
|
165 | - protected function isDiscovered() |
|
166 | - { |
|
167 | - return $this->count !== null; |
|
168 | - } |
|
162 | + /** |
|
163 | + * Whether this item has already been initialized |
|
164 | + */ |
|
165 | + protected function isDiscovered() |
|
166 | + { |
|
167 | + return $this->count !== null; |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * @since 4.10.12.p |
|
172 | - * @return boolean |
|
173 | - */ |
|
174 | - public function isComplete() |
|
175 | - { |
|
176 | - if ($this->complete === null) { |
|
177 | - if (count($this->nodes) === $this->count) { |
|
178 | - $this->complete = true; |
|
179 | - } else { |
|
180 | - $this->complete = false; |
|
181 | - } |
|
182 | - } |
|
183 | - return $this->complete; |
|
184 | - } |
|
170 | + /** |
|
171 | + * @since 4.10.12.p |
|
172 | + * @return boolean |
|
173 | + */ |
|
174 | + public function isComplete() |
|
175 | + { |
|
176 | + if ($this->complete === null) { |
|
177 | + if (count($this->nodes) === $this->count) { |
|
178 | + $this->complete = true; |
|
179 | + } else { |
|
180 | + $this->complete = false; |
|
181 | + } |
|
182 | + } |
|
183 | + return $this->complete; |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Discovers how many related model objects exist. |
|
188 | - * @since 4.10.12.p |
|
189 | - * @return mixed|void |
|
190 | - * @throws EE_Error |
|
191 | - * @throws InvalidArgumentException |
|
192 | - * @throws InvalidDataTypeException |
|
193 | - * @throws InvalidInterfaceException |
|
194 | - * @throws ReflectionException |
|
195 | - */ |
|
196 | - protected function discover() |
|
197 | - { |
|
198 | - $this->count = $this->related_model->count([$this->whereQueryParams()]); |
|
199 | - } |
|
186 | + /** |
|
187 | + * Discovers how many related model objects exist. |
|
188 | + * @since 4.10.12.p |
|
189 | + * @return mixed|void |
|
190 | + * @throws EE_Error |
|
191 | + * @throws InvalidArgumentException |
|
192 | + * @throws InvalidDataTypeException |
|
193 | + * @throws InvalidInterfaceException |
|
194 | + * @throws ReflectionException |
|
195 | + */ |
|
196 | + protected function discover() |
|
197 | + { |
|
198 | + $this->count = $this->related_model->count([$this->whereQueryParams()]); |
|
199 | + } |
|
200 | 200 | |
201 | - /** |
|
202 | - * @since 4.10.12.p |
|
203 | - * @return array |
|
204 | - * @throws EE_Error |
|
205 | - * @throws InvalidDataTypeException |
|
206 | - * @throws InvalidInterfaceException |
|
207 | - * @throws InvalidArgumentException |
|
208 | - * @throws ReflectionException |
|
209 | - */ |
|
210 | - protected function whereQueryParams() |
|
211 | - { |
|
212 | - $where_params = [ |
|
213 | - $this->related_model->get_foreign_key_to( |
|
214 | - $this->main_model->get_this_model_name() |
|
215 | - )->get_name() => $this->id |
|
216 | - ]; |
|
217 | - try { |
|
218 | - $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name()); |
|
219 | - } catch (EE_Error $e) { |
|
220 | - // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table |
|
221 | - // which hasn't been explicitly declared in the main model object's model's relations. |
|
222 | - $relation_settings = null; |
|
223 | - } |
|
224 | - if ($relation_settings instanceof EE_Has_Many_Any_Relation) { |
|
225 | - $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name(); |
|
226 | - } |
|
227 | - return $where_params; |
|
228 | - } |
|
229 | - /** |
|
230 | - * @since 4.10.12.p |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - public function toArray() |
|
234 | - { |
|
235 | - $tree = [ |
|
236 | - 'count' => $this->count, |
|
237 | - 'complete' => $this->isComplete(), |
|
238 | - 'objs' => [] |
|
239 | - ]; |
|
240 | - foreach ($this->nodes as $id => $model_obj_node) { |
|
241 | - $tree['objs'][ $id ] = $model_obj_node->toArray(); |
|
242 | - } |
|
243 | - return $tree; |
|
244 | - } |
|
201 | + /** |
|
202 | + * @since 4.10.12.p |
|
203 | + * @return array |
|
204 | + * @throws EE_Error |
|
205 | + * @throws InvalidDataTypeException |
|
206 | + * @throws InvalidInterfaceException |
|
207 | + * @throws InvalidArgumentException |
|
208 | + * @throws ReflectionException |
|
209 | + */ |
|
210 | + protected function whereQueryParams() |
|
211 | + { |
|
212 | + $where_params = [ |
|
213 | + $this->related_model->get_foreign_key_to( |
|
214 | + $this->main_model->get_this_model_name() |
|
215 | + )->get_name() => $this->id |
|
216 | + ]; |
|
217 | + try { |
|
218 | + $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name()); |
|
219 | + } catch (EE_Error $e) { |
|
220 | + // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table |
|
221 | + // which hasn't been explicitly declared in the main model object's model's relations. |
|
222 | + $relation_settings = null; |
|
223 | + } |
|
224 | + if ($relation_settings instanceof EE_Has_Many_Any_Relation) { |
|
225 | + $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = $this->main_model->get_this_model_name(); |
|
226 | + } |
|
227 | + return $where_params; |
|
228 | + } |
|
229 | + /** |
|
230 | + * @since 4.10.12.p |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + public function toArray() |
|
234 | + { |
|
235 | + $tree = [ |
|
236 | + 'count' => $this->count, |
|
237 | + 'complete' => $this->isComplete(), |
|
238 | + 'objs' => [] |
|
239 | + ]; |
|
240 | + foreach ($this->nodes as $id => $model_obj_node) { |
|
241 | + $tree['objs'][ $id ] = $model_obj_node->toArray(); |
|
242 | + } |
|
243 | + return $tree; |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * Gets the IDs of all the model objects to delete; indexed first by model object name. |
|
248 | - * @since 4.10.12.p |
|
249 | - * @return array |
|
250 | - */ |
|
251 | - public function getIds() |
|
252 | - { |
|
253 | - if (empty($this->nodes)) { |
|
254 | - return []; |
|
255 | - } |
|
256 | - $ids = [ |
|
257 | - $this->related_model->get_this_model_name() => array_combine( |
|
258 | - array_keys($this->nodes), |
|
259 | - array_keys($this->nodes) |
|
260 | - ) |
|
261 | - ]; |
|
262 | - foreach ($this->nodes as $model_obj_node) { |
|
263 | - $ids = array_replace_recursive($ids, $model_obj_node->getIds()); |
|
264 | - } |
|
265 | - return $ids; |
|
266 | - } |
|
246 | + /** |
|
247 | + * Gets the IDs of all the model objects to delete; indexed first by model object name. |
|
248 | + * @since 4.10.12.p |
|
249 | + * @return array |
|
250 | + */ |
|
251 | + public function getIds() |
|
252 | + { |
|
253 | + if (empty($this->nodes)) { |
|
254 | + return []; |
|
255 | + } |
|
256 | + $ids = [ |
|
257 | + $this->related_model->get_this_model_name() => array_combine( |
|
258 | + array_keys($this->nodes), |
|
259 | + array_keys($this->nodes) |
|
260 | + ) |
|
261 | + ]; |
|
262 | + foreach ($this->nodes as $model_obj_node) { |
|
263 | + $ids = array_replace_recursive($ids, $model_obj_node->getIds()); |
|
264 | + } |
|
265 | + return $ids; |
|
266 | + } |
|
267 | 267 | |
268 | - /** |
|
269 | - * Returns the number of sub-nodes found (ie, related model objects across this relation.) |
|
270 | - * @since 4.10.12.p |
|
271 | - * @return int |
|
272 | - */ |
|
273 | - public function countSubNodes() |
|
274 | - { |
|
275 | - return count($this->nodes); |
|
276 | - } |
|
268 | + /** |
|
269 | + * Returns the number of sub-nodes found (ie, related model objects across this relation.) |
|
270 | + * @since 4.10.12.p |
|
271 | + * @return int |
|
272 | + */ |
|
273 | + public function countSubNodes() |
|
274 | + { |
|
275 | + return count($this->nodes); |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
279 | - * Don't serialize the models. Just record their names on some dynamic properties. |
|
280 | - * @since 4.10.12.p |
|
281 | - */ |
|
282 | - public function __sleep() |
|
283 | - { |
|
284 | - $this->m = $this->main_model->get_this_model_name(); |
|
285 | - $this->rm = $this->related_model->get_this_model_name(); |
|
286 | - return array_merge( |
|
287 | - [ |
|
288 | - 'm', |
|
289 | - 'rm', |
|
290 | - 'id', |
|
291 | - 'count', |
|
292 | - 'nodes', |
|
293 | - ], |
|
294 | - parent::__sleep() |
|
295 | - ); |
|
296 | - } |
|
278 | + /** |
|
279 | + * Don't serialize the models. Just record their names on some dynamic properties. |
|
280 | + * @since 4.10.12.p |
|
281 | + */ |
|
282 | + public function __sleep() |
|
283 | + { |
|
284 | + $this->m = $this->main_model->get_this_model_name(); |
|
285 | + $this->rm = $this->related_model->get_this_model_name(); |
|
286 | + return array_merge( |
|
287 | + [ |
|
288 | + 'm', |
|
289 | + 'rm', |
|
290 | + 'id', |
|
291 | + 'count', |
|
292 | + 'nodes', |
|
293 | + ], |
|
294 | + parent::__sleep() |
|
295 | + ); |
|
296 | + } |
|
297 | 297 | |
298 | - /** |
|
299 | - * Use the dynamic properties to instantiate the models we use. |
|
300 | - * @since 4.10.12.p |
|
301 | - * @throws EE_Error |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidDataTypeException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - * @throws ReflectionException |
|
306 | - */ |
|
307 | - public function __wakeup() |
|
308 | - { |
|
309 | - $this->main_model = EE_Registry::instance()->load_model($this->m); |
|
310 | - $this->related_model = EE_Registry::instance()->load_model($this->rm); |
|
311 | - parent::__wakeup(); |
|
312 | - } |
|
298 | + /** |
|
299 | + * Use the dynamic properties to instantiate the models we use. |
|
300 | + * @since 4.10.12.p |
|
301 | + * @throws EE_Error |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidDataTypeException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + * @throws ReflectionException |
|
306 | + */ |
|
307 | + public function __wakeup() |
|
308 | + { |
|
309 | + $this->main_model = EE_Registry::instance()->load_model($this->m); |
|
310 | + $this->related_model = EE_Registry::instance()->load_model($this->rm); |
|
311 | + parent::__wakeup(); |
|
312 | + } |
|
313 | 313 | } |
314 | 314 | // End of file RelationNode.php |
315 | 315 | // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php |
@@ -22,55 +22,55 @@ |
||
22 | 22 | */ |
23 | 23 | class ConfirmEventDeletionForm extends \EE_Form_Section_Proper |
24 | 24 | { |
25 | - /** |
|
26 | - * @var EE_Event[] |
|
27 | - */ |
|
28 | - protected $events; |
|
29 | - public function __construct($event_ids, $options_array = array()) |
|
30 | - { |
|
31 | - if (! isset($options_array['subsections'])) { |
|
32 | - $options_array['subsections'] = []; |
|
33 | - } |
|
34 | - if (! isset($options_array['subsections']['events'])) { |
|
35 | - $events_subsection = new \EE_Form_Section_Proper(); |
|
36 | - $options_array['subsections']['events'] = $events_subsection; |
|
37 | - } |
|
38 | - $events = EEM_Event::instance()->get_all_deleted_and_undeleted( |
|
39 | - [ |
|
40 | - [ |
|
41 | - 'EVT_ID' => ['IN',$event_ids] |
|
42 | - ] |
|
43 | - ] |
|
44 | - ); |
|
45 | - if (! is_array($events)) { |
|
46 | - throw new UnexpectedEntityException($event_ids, 'array'); |
|
47 | - } |
|
48 | - $this->events = $events; |
|
49 | - $events_inputs = [ |
|
50 | - ]; |
|
51 | - foreach ($events as $event) { |
|
52 | - $events_inputs[ $event->ID() ] = new EE_Checkbox_Multi_Input( |
|
53 | - [ |
|
54 | - 'yes' => $event->name(), |
|
55 | - ], |
|
56 | - [ |
|
57 | - 'html_label_text' => esc_html__('Please confirm you wish to delete:', 'event_espresso'), |
|
58 | - 'required' => true |
|
59 | - ] |
|
60 | - ); |
|
61 | - } |
|
62 | - $events_subsection->add_subsections($events_inputs); |
|
63 | - $options_array['subsections']['backup'] = new EE_Checkbox_Multi_Input( |
|
64 | - [ |
|
65 | - 'yes' => esc_html__('I have backed up my database.', 'event_espresso') |
|
66 | - ], |
|
67 | - [ |
|
68 | - 'html_label_text' => esc_html__('Deleting this data cannot be undone. Please confirm you have a usable database backup.', 'event_espresso'), |
|
69 | - 'required' => true |
|
70 | - ] |
|
71 | - ); |
|
72 | - parent::__construct($options_array); |
|
73 | - } |
|
25 | + /** |
|
26 | + * @var EE_Event[] |
|
27 | + */ |
|
28 | + protected $events; |
|
29 | + public function __construct($event_ids, $options_array = array()) |
|
30 | + { |
|
31 | + if (! isset($options_array['subsections'])) { |
|
32 | + $options_array['subsections'] = []; |
|
33 | + } |
|
34 | + if (! isset($options_array['subsections']['events'])) { |
|
35 | + $events_subsection = new \EE_Form_Section_Proper(); |
|
36 | + $options_array['subsections']['events'] = $events_subsection; |
|
37 | + } |
|
38 | + $events = EEM_Event::instance()->get_all_deleted_and_undeleted( |
|
39 | + [ |
|
40 | + [ |
|
41 | + 'EVT_ID' => ['IN',$event_ids] |
|
42 | + ] |
|
43 | + ] |
|
44 | + ); |
|
45 | + if (! is_array($events)) { |
|
46 | + throw new UnexpectedEntityException($event_ids, 'array'); |
|
47 | + } |
|
48 | + $this->events = $events; |
|
49 | + $events_inputs = [ |
|
50 | + ]; |
|
51 | + foreach ($events as $event) { |
|
52 | + $events_inputs[ $event->ID() ] = new EE_Checkbox_Multi_Input( |
|
53 | + [ |
|
54 | + 'yes' => $event->name(), |
|
55 | + ], |
|
56 | + [ |
|
57 | + 'html_label_text' => esc_html__('Please confirm you wish to delete:', 'event_espresso'), |
|
58 | + 'required' => true |
|
59 | + ] |
|
60 | + ); |
|
61 | + } |
|
62 | + $events_subsection->add_subsections($events_inputs); |
|
63 | + $options_array['subsections']['backup'] = new EE_Checkbox_Multi_Input( |
|
64 | + [ |
|
65 | + 'yes' => esc_html__('I have backed up my database.', 'event_espresso') |
|
66 | + ], |
|
67 | + [ |
|
68 | + 'html_label_text' => esc_html__('Deleting this data cannot be undone. Please confirm you have a usable database backup.', 'event_espresso'), |
|
69 | + 'required' => true |
|
70 | + ] |
|
71 | + ); |
|
72 | + parent::__construct($options_array); |
|
73 | + } |
|
74 | 74 | } |
75 | 75 | // End of file ConfirmEventDeletionForm.php |
76 | 76 | // Location: EventEspresso\admin_pages\events\form_sections/ConfirmEventDeletionForm.php |
@@ -28,28 +28,28 @@ |
||
28 | 28 | protected $events; |
29 | 29 | public function __construct($event_ids, $options_array = array()) |
30 | 30 | { |
31 | - if (! isset($options_array['subsections'])) { |
|
31 | + if ( ! isset($options_array['subsections'])) { |
|
32 | 32 | $options_array['subsections'] = []; |
33 | 33 | } |
34 | - if (! isset($options_array['subsections']['events'])) { |
|
34 | + if ( ! isset($options_array['subsections']['events'])) { |
|
35 | 35 | $events_subsection = new \EE_Form_Section_Proper(); |
36 | 36 | $options_array['subsections']['events'] = $events_subsection; |
37 | 37 | } |
38 | 38 | $events = EEM_Event::instance()->get_all_deleted_and_undeleted( |
39 | 39 | [ |
40 | 40 | [ |
41 | - 'EVT_ID' => ['IN',$event_ids] |
|
41 | + 'EVT_ID' => ['IN', $event_ids] |
|
42 | 42 | ] |
43 | 43 | ] |
44 | 44 | ); |
45 | - if (! is_array($events)) { |
|
45 | + if ( ! is_array($events)) { |
|
46 | 46 | throw new UnexpectedEntityException($event_ids, 'array'); |
47 | 47 | } |
48 | 48 | $this->events = $events; |
49 | 49 | $events_inputs = [ |
50 | 50 | ]; |
51 | 51 | foreach ($events as $event) { |
52 | - $events_inputs[ $event->ID() ] = new EE_Checkbox_Multi_Input( |
|
52 | + $events_inputs[$event->ID()] = new EE_Checkbox_Multi_Input( |
|
53 | 53 | [ |
54 | 54 | 'yes' => $event->name(), |
55 | 55 | ], |
@@ -29,10 +29,10 @@ |
||
29 | 29 | isset($input_settings['validation_error_message']) |
30 | 30 | ? $input_settings['validation_error_message'] |
31 | 31 | : null, |
32 | - '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
32 | + '#'.str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | 33 | ) |
34 | 34 | ); |
35 | 35 | parent::__construct($input_settings); |
36 | - $this->set_html_class($this->html_class() . ' email'); |
|
36 | + $this->set_html_class($this->html_class().' email'); |
|
37 | 37 | } |
38 | 38 | } |
@@ -10,29 +10,29 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Email_Confirm_Input extends EE_Form_Input_Base |
12 | 12 | { |
13 | - /** |
|
14 | - * @param array $input_settings |
|
15 | - */ |
|
16 | - public function __construct($input_settings = array()) |
|
17 | - { |
|
18 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
19 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | - $this->_add_validation_strategy( |
|
21 | - new EE_Email_Validation_Strategy( |
|
22 | - isset($input_settings['validation_error_message']) |
|
23 | - ? $input_settings['validation_error_message'] |
|
24 | - : null |
|
25 | - ) |
|
26 | - ); |
|
27 | - $this->_add_validation_strategy( |
|
28 | - new EE_Equal_To_Validation_Strategy( |
|
29 | - isset($input_settings['validation_error_message']) |
|
30 | - ? $input_settings['validation_error_message'] |
|
31 | - : null, |
|
32 | - '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | - ) |
|
34 | - ); |
|
35 | - parent::__construct($input_settings); |
|
36 | - $this->set_html_class($this->html_class() . ' email'); |
|
37 | - } |
|
13 | + /** |
|
14 | + * @param array $input_settings |
|
15 | + */ |
|
16 | + public function __construct($input_settings = array()) |
|
17 | + { |
|
18 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
19 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | + $this->_add_validation_strategy( |
|
21 | + new EE_Email_Validation_Strategy( |
|
22 | + isset($input_settings['validation_error_message']) |
|
23 | + ? $input_settings['validation_error_message'] |
|
24 | + : null |
|
25 | + ) |
|
26 | + ); |
|
27 | + $this->_add_validation_strategy( |
|
28 | + new EE_Equal_To_Validation_Strategy( |
|
29 | + isset($input_settings['validation_error_message']) |
|
30 | + ? $input_settings['validation_error_message'] |
|
31 | + : null, |
|
32 | + '#' . str_replace('email_confirm', 'email', $input_settings['html_id']) |
|
33 | + ) |
|
34 | + ); |
|
35 | + parent::__construct($input_settings); |
|
36 | + $this->set_html_class($this->html_class() . ' email'); |
|
37 | + } |
|
38 | 38 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | */ |
24 | 24 | public function __construct($validation_error_message = '', $compare_to) |
25 | 25 | { |
26 | - if (! $validation_error_message) { |
|
26 | + if ( ! $validation_error_message) { |
|
27 | 27 | $validation_error_message = apply_filters( |
28 | 28 | 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
29 | 29 | esc_html__('Fields do not match.', 'event_espresso') |
@@ -15,49 +15,49 @@ |
||
15 | 15 | */ |
16 | 16 | class EE_Equal_To_Validation_Strategy extends EE_Text_Validation_Strategy |
17 | 17 | { |
18 | - protected $_compare_to = null; |
|
19 | - |
|
20 | - |
|
21 | - /** |
|
22 | - * @param string $validation_error_message |
|
23 | - */ |
|
24 | - public function __construct($validation_error_message = '', $compare_to) |
|
25 | - { |
|
26 | - if (! $validation_error_message) { |
|
27 | - $validation_error_message = apply_filters( |
|
28 | - 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
|
29 | - esc_html__('Fields do not match.', 'event_espresso') |
|
30 | - ); |
|
31 | - } |
|
32 | - parent::__construct($validation_error_message); |
|
33 | - $this->_compare_to = $compare_to; |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * just checks the field isn't blank |
|
40 | - * |
|
41 | - * @param $normalized_value |
|
42 | - * @return bool |
|
43 | - * @throws InvalidArgumentException |
|
44 | - * @throws InvalidInterfaceException |
|
45 | - * @throws InvalidDataTypeException |
|
46 | - * @throws EE_Validation_Error |
|
47 | - */ |
|
48 | - public function validate($normalized_value) |
|
49 | - { |
|
50 | - // No need to be validated |
|
51 | - return true; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @return array |
|
58 | - */ |
|
59 | - public function get_jquery_validation_rule_array() |
|
60 | - { |
|
61 | - return array('equalTo' => $this->_compare_to, 'messages' => array('equalTo' => $this->get_validation_error_message())); |
|
62 | - } |
|
18 | + protected $_compare_to = null; |
|
19 | + |
|
20 | + |
|
21 | + /** |
|
22 | + * @param string $validation_error_message |
|
23 | + */ |
|
24 | + public function __construct($validation_error_message = '', $compare_to) |
|
25 | + { |
|
26 | + if (! $validation_error_message) { |
|
27 | + $validation_error_message = apply_filters( |
|
28 | + 'FHEE__EE_Equal_To_Validation_Strategy____construct__validation_error_message', |
|
29 | + esc_html__('Fields do not match.', 'event_espresso') |
|
30 | + ); |
|
31 | + } |
|
32 | + parent::__construct($validation_error_message); |
|
33 | + $this->_compare_to = $compare_to; |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * just checks the field isn't blank |
|
40 | + * |
|
41 | + * @param $normalized_value |
|
42 | + * @return bool |
|
43 | + * @throws InvalidArgumentException |
|
44 | + * @throws InvalidInterfaceException |
|
45 | + * @throws InvalidDataTypeException |
|
46 | + * @throws EE_Validation_Error |
|
47 | + */ |
|
48 | + public function validate($normalized_value) |
|
49 | + { |
|
50 | + // No need to be validated |
|
51 | + return true; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @return array |
|
58 | + */ |
|
59 | + public function get_jquery_validation_rule_array() |
|
60 | + { |
|
61 | + return array('equalTo' => $this->_compare_to, 'messages' => array('equalTo' => $this->get_validation_error_message())); |
|
62 | + } |
|
63 | 63 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation(); |
203 | 203 | $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation(); |
204 | 204 | $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback( |
205 | - static function () { |
|
205 | + static function() { |
|
206 | 206 | wp_add_inline_script( |
207 | 207 | CoreAssetManager::JS_HANDLE_DATA_STORES, |
208 | 208 | is_admin() |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | |
262 | 262 | $this->addJavascript( |
263 | 263 | CoreAssetManager::JS_HANDLE_CORE, |
264 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
264 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
265 | 265 | array(CoreAssetManager::JS_HANDLE_JQUERY) |
266 | 266 | ) |
267 | 267 | ->setInlineDataCallback( |
268 | - static function () { |
|
268 | + static function() { |
|
269 | 269 | wp_localize_script( |
270 | 270 | CoreAssetManager::JS_HANDLE_CORE, |
271 | 271 | CoreAssetManager::JS_HANDLE_I18N, |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | if ($this->template_config->enable_default_style && ! is_admin()) { |
371 | 371 | $this->addStylesheet( |
372 | 372 | CoreAssetManager::CSS_HANDLE_DEFAULT, |
373 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
373 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/espresso_default.css') |
|
374 | 374 | ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
375 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
375 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css', |
|
376 | 376 | array('dashicons') |
377 | 377 | ); |
378 | 378 | //Load custom style sheet if available |
379 | 379 | if ($this->template_config->custom_style_sheet !== null) { |
380 | 380 | $this->addStylesheet( |
381 | 381 | CoreAssetManager::CSS_HANDLE_CUSTOM, |
382 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
382 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
383 | 383 | array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
384 | 384 | ); |
385 | 385 | } |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | { |
403 | 403 | $this->addJavascript( |
404 | 404 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
405 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
405 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
406 | 406 | array(CoreAssetManager::JS_HANDLE_JQUERY), |
407 | 407 | true, |
408 | 408 | '1.15.0' |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | |
411 | 411 | $this->addJavascript( |
412 | 412 | CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
413 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
413 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
414 | 414 | array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
415 | 415 | true, |
416 | 416 | '1.15.0' |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | // @link http://josscrowcroft.github.io/accounting.js/ |
434 | 434 | $this->addJavascript( |
435 | 435 | CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
436 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
436 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
437 | 437 | array(CoreAssetManager::JS_HANDLE_UNDERSCORE), |
438 | 438 | true, |
439 | 439 | '0.3.2' |
@@ -441,11 +441,11 @@ discard block |
||
441 | 441 | |
442 | 442 | $this->addJavascript( |
443 | 443 | CoreAssetManager::JS_HANDLE_ACCOUNTING, |
444 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
444 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
445 | 445 | array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
446 | 446 | ) |
447 | 447 | ->setInlineDataCallback( |
448 | - function () { |
|
448 | + function() { |
|
449 | 449 | wp_localize_script( |
450 | 450 | CoreAssetManager::JS_HANDLE_ACCOUNTING, |
451 | 451 | 'EE_ACCOUNTING_CFG', |
@@ -32,461 +32,461 @@ |
||
32 | 32 | class CoreAssetManager extends AssetManager |
33 | 33 | { |
34 | 34 | |
35 | - // WordPress core / Third party JS asset handles |
|
36 | - const JS_HANDLE_JQUERY = 'jquery'; |
|
35 | + // WordPress core / Third party JS asset handles |
|
36 | + const JS_HANDLE_JQUERY = 'jquery'; |
|
37 | 37 | |
38 | - const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
38 | + const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate'; |
|
39 | 39 | |
40 | - const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
40 | + const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods'; |
|
41 | 41 | |
42 | - const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
42 | + const JS_HANDLE_UNDERSCORE = 'underscore'; |
|
43 | 43 | |
44 | - const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
44 | + const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core'; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @since 4.9.71.p |
|
48 | - */ |
|
49 | - const JS_HANDLE_REACT = 'react'; |
|
46 | + /** |
|
47 | + * @since 4.9.71.p |
|
48 | + */ |
|
49 | + const JS_HANDLE_REACT = 'react'; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @since 4.9.71.p |
|
53 | - */ |
|
54 | - const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
51 | + /** |
|
52 | + * @since 4.9.71.p |
|
53 | + */ |
|
54 | + const JS_HANDLE_REACT_DOM = 'react-dom'; |
|
55 | 55 | |
56 | - /** |
|
57 | - * @since 4.9.71.p |
|
58 | - */ |
|
59 | - const JS_HANDLE_LODASH = 'lodash'; |
|
56 | + /** |
|
57 | + * @since 4.9.71.p |
|
58 | + */ |
|
59 | + const JS_HANDLE_LODASH = 'lodash'; |
|
60 | 60 | |
61 | - const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
61 | + const JS_HANDLE_JS_CORE = 'eejs-core'; |
|
62 | 62 | |
63 | - const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
63 | + const JS_HANDLE_VENDOR = 'eventespresso-vendor'; |
|
64 | 64 | |
65 | - const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores'; |
|
65 | + const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores'; |
|
66 | 66 | |
67 | - const JS_HANDLE_HELPERS = 'eventespresso-helpers'; |
|
67 | + const JS_HANDLE_HELPERS = 'eventespresso-helpers'; |
|
68 | 68 | |
69 | - const JS_HANDLE_MODEL = 'eventespresso-model'; |
|
69 | + const JS_HANDLE_MODEL = 'eventespresso-model'; |
|
70 | 70 | |
71 | - const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects'; |
|
71 | + const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects'; |
|
72 | 72 | |
73 | - const JS_HANDLE_HOCS = 'eventespresso-hocs'; |
|
73 | + const JS_HANDLE_HOCS = 'eventespresso-hocs'; |
|
74 | 74 | |
75 | - const JS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
75 | + const JS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
76 | 76 | |
77 | - const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs'; |
|
78 | - |
|
79 | - const JS_HANDLE_VALIDATORS = 'eventespresso-validators'; |
|
77 | + const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs'; |
|
78 | + |
|
79 | + const JS_HANDLE_VALIDATORS = 'eventespresso-validators'; |
|
80 | 80 | |
81 | - const JS_HANDLE_CORE = 'espresso_core'; |
|
81 | + const JS_HANDLE_CORE = 'espresso_core'; |
|
82 | 82 | |
83 | - const JS_HANDLE_I18N = 'eei18n'; |
|
83 | + const JS_HANDLE_I18N = 'eei18n'; |
|
84 | 84 | |
85 | - const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
86 | - |
|
87 | - const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
88 | - |
|
89 | - // EE CSS assets handles |
|
90 | - const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
91 | - |
|
92 | - const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
93 | - |
|
94 | - const CSS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
95 | - |
|
96 | - const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default'; |
|
97 | - |
|
98 | - /** |
|
99 | - * @var EE_Currency_Config $currency_config |
|
100 | - */ |
|
101 | - protected $currency_config; |
|
102 | - |
|
103 | - /** |
|
104 | - * @var EE_Template_Config $template_config |
|
105 | - */ |
|
106 | - protected $template_config; |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * CoreAssetRegister constructor. |
|
111 | - * |
|
112 | - * @param AssetCollection $assets |
|
113 | - * @param EE_Currency_Config $currency_config |
|
114 | - * @param EE_Template_Config $template_config |
|
115 | - * @param DomainInterface $domain |
|
116 | - * @param Registry $registry |
|
117 | - */ |
|
118 | - public function __construct( |
|
119 | - AssetCollection $assets, |
|
120 | - EE_Currency_Config $currency_config, |
|
121 | - EE_Template_Config $template_config, |
|
122 | - DomainInterface $domain, |
|
123 | - Registry $registry |
|
124 | - ) { |
|
125 | - $this->currency_config = $currency_config; |
|
126 | - $this->template_config = $template_config; |
|
127 | - parent::__construct($domain, $assets, $registry); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @since 4.9.62.p |
|
133 | - * @throws DomainException |
|
134 | - * @throws DuplicateCollectionIdentifierException |
|
135 | - * @throws InvalidArgumentException |
|
136 | - * @throws InvalidDataTypeException |
|
137 | - * @throws InvalidEntityException |
|
138 | - * @throws InvalidInterfaceException |
|
139 | - */ |
|
140 | - public function addAssets() |
|
141 | - { |
|
142 | - $this->addJavascriptFiles(); |
|
143 | - $this->addStylesheetFiles(); |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @since 4.9.62.p |
|
149 | - * @throws DomainException |
|
150 | - * @throws DuplicateCollectionIdentifierException |
|
151 | - * @throws InvalidArgumentException |
|
152 | - * @throws InvalidDataTypeException |
|
153 | - * @throws InvalidEntityException |
|
154 | - * @throws InvalidInterfaceException |
|
155 | - */ |
|
156 | - public function addJavascriptFiles() |
|
157 | - { |
|
158 | - $this->loadCoreJs(); |
|
159 | - $this->loadJqueryValidate(); |
|
160 | - $this->loadAccountingJs(); |
|
161 | - add_action( |
|
162 | - 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
163 | - array($this, 'loadQtipJs') |
|
164 | - ); |
|
165 | - $this->registerAdminAssets(); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @throws DuplicateCollectionIdentifierException |
|
171 | - * @throws InvalidDataTypeException |
|
172 | - * @throws InvalidEntityException |
|
173 | - * @throws DomainException |
|
174 | - * @since 4.9.62.p |
|
175 | - */ |
|
176 | - public function addStylesheetFiles() |
|
177 | - { |
|
178 | - $this->loadCoreCss(); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * core default javascript |
|
184 | - * |
|
185 | - * @since 4.9.62.p |
|
186 | - * @throws DomainException |
|
187 | - * @throws DuplicateCollectionIdentifierException |
|
188 | - * @throws InvalidArgumentException |
|
189 | - * @throws InvalidDataTypeException |
|
190 | - * @throws InvalidEntityException |
|
191 | - * @throws InvalidInterfaceException |
|
192 | - */ |
|
193 | - private function loadCoreJs() |
|
194 | - { |
|
195 | - // conditionally load third-party libraries that WP core MIGHT have. |
|
196 | - $this->registerWpAssets(); |
|
197 | - |
|
198 | - $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
199 | - $this->addJs(self::JS_HANDLE_VENDOR); |
|
200 | - $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation(); |
|
201 | - $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation(); |
|
202 | - $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation(); |
|
203 | - $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation(); |
|
204 | - $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback( |
|
205 | - static function () { |
|
206 | - wp_add_inline_script( |
|
207 | - CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
208 | - is_admin() |
|
209 | - ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )' |
|
210 | - : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )' |
|
211 | - ); |
|
212 | - } |
|
213 | - ); |
|
214 | - $this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation(); |
|
215 | - $this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation(); |
|
216 | - $this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation(); |
|
217 | - |
|
218 | - $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
219 | - $this->registry->addData( |
|
220 | - 'paths', |
|
221 | - array( |
|
222 | - 'base_rest_route' => rest_url(), |
|
223 | - 'rest_route' => rest_url('ee/v4.8.36/'), |
|
224 | - 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
225 | - 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
226 | - 'site_url' => site_url('/'), |
|
227 | - 'admin_url' => admin_url('/'), |
|
228 | - ) |
|
229 | - ); |
|
230 | - // Event Espresso brand name |
|
231 | - $this->registry->addData('brandName', Domain::brandName()); |
|
232 | - /** site formatting values **/ |
|
233 | - $this->registry->addData( |
|
234 | - 'site_formats', |
|
235 | - array( |
|
236 | - 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
237 | - ) |
|
238 | - ); |
|
239 | - /** currency data **/ |
|
240 | - $this->registry->addData( |
|
241 | - 'currency_config', |
|
242 | - $this->getCurrencySettings() |
|
243 | - ); |
|
244 | - /** site timezone */ |
|
245 | - $this->registry->addData( |
|
246 | - 'default_timezone', |
|
247 | - array( |
|
248 | - 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
249 | - 'string' => get_option('timezone_string'), |
|
250 | - 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
251 | - ) |
|
252 | - ); |
|
253 | - /** site locale (user locale if user logged in) */ |
|
254 | - $this->registry->addData( |
|
255 | - 'locale', |
|
256 | - array( |
|
257 | - 'user' => get_user_locale(), |
|
258 | - 'site' => get_locale() |
|
259 | - ) |
|
260 | - ); |
|
261 | - |
|
262 | - $this->addJavascript( |
|
263 | - CoreAssetManager::JS_HANDLE_CORE, |
|
264 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
265 | - array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
266 | - ) |
|
267 | - ->setInlineDataCallback( |
|
268 | - static function () { |
|
269 | - wp_localize_script( |
|
270 | - CoreAssetManager::JS_HANDLE_CORE, |
|
271 | - CoreAssetManager::JS_HANDLE_I18N, |
|
272 | - EE_Registry::sanitize_i18n_js_strings() |
|
273 | - ); |
|
274 | - } |
|
275 | - ); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Registers vendor files that are bundled with a later version WP but might not be for the current version of |
|
281 | - * WordPress in the running environment. |
|
282 | - * |
|
283 | - * @throws DuplicateCollectionIdentifierException |
|
284 | - * @throws InvalidDataTypeException |
|
285 | - * @throws InvalidEntityException |
|
286 | - * @throws DomainException |
|
287 | - * @since 4.9.71.p |
|
288 | - */ |
|
289 | - private function registerWpAssets() |
|
290 | - { |
|
291 | - global $wp_version; |
|
292 | - if (version_compare($wp_version, '5.0.beta', '>=')) { |
|
293 | - return; |
|
294 | - } |
|
295 | - $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0'); |
|
296 | - $this->addVendorJavascript( |
|
297 | - CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
298 | - array(CoreAssetManager::JS_HANDLE_REACT), |
|
299 | - true, |
|
300 | - '16.6.0' |
|
301 | - ); |
|
302 | - $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11') |
|
303 | - ->setInlineDataCallback( |
|
304 | - static function() { |
|
305 | - wp_add_inline_script( |
|
306 | - CoreAssetManager::JS_HANDLE_LODASH, |
|
307 | - 'window.lodash = _.noConflict();' |
|
308 | - ); |
|
309 | - } |
|
310 | - ); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Returns configuration data for the accounting-js library. |
|
316 | - * @since 4.9.71.p |
|
317 | - * @return array |
|
318 | - */ |
|
319 | - private function getAccountingSettings() { |
|
320 | - return array( |
|
321 | - 'currency' => array( |
|
322 | - 'symbol' => $this->currency_config->sign, |
|
323 | - 'format' => array( |
|
324 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
325 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
326 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
327 | - ), |
|
328 | - 'decimal' => $this->currency_config->dec_mrk, |
|
329 | - 'thousand' => $this->currency_config->thsnds, |
|
330 | - 'precision' => $this->currency_config->dec_plc, |
|
331 | - ), |
|
332 | - 'number' => array( |
|
333 | - 'precision' => $this->currency_config->dec_plc, |
|
334 | - 'thousand' => $this->currency_config->thsnds, |
|
335 | - 'decimal' => $this->currency_config->dec_mrk, |
|
336 | - ), |
|
337 | - ); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * Returns configuration data for the js Currency VO. |
|
343 | - * @since 4.9.71.p |
|
344 | - * @return array |
|
345 | - */ |
|
346 | - private function getCurrencySettings() |
|
347 | - { |
|
348 | - return array( |
|
349 | - 'code' => $this->currency_config->code, |
|
350 | - 'singularLabel' => $this->currency_config->name, |
|
351 | - 'pluralLabel' => $this->currency_config->plural, |
|
352 | - 'sign' => $this->currency_config->sign, |
|
353 | - 'signB4' => $this->currency_config->sign_b4, |
|
354 | - 'decimalPlaces' => $this->currency_config->dec_plc, |
|
355 | - 'decimalMark' => $this->currency_config->dec_mrk, |
|
356 | - 'thousandsSeparator' => $this->currency_config->thsnds, |
|
357 | - ); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * @throws DuplicateCollectionIdentifierException |
|
363 | - * @throws InvalidDataTypeException |
|
364 | - * @throws InvalidEntityException |
|
365 | - * @throws DomainException |
|
366 | - * @since 4.9.62.p |
|
367 | - */ |
|
368 | - private function loadCoreCss() |
|
369 | - { |
|
370 | - if ($this->template_config->enable_default_style && ! is_admin()) { |
|
371 | - $this->addStylesheet( |
|
372 | - CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
373 | - is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
374 | - ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
|
375 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
376 | - array('dashicons') |
|
377 | - ); |
|
378 | - //Load custom style sheet if available |
|
379 | - if ($this->template_config->custom_style_sheet !== null) { |
|
380 | - $this->addStylesheet( |
|
381 | - CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
382 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
383 | - array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
384 | - ); |
|
385 | - } |
|
386 | - } |
|
387 | - $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']); |
|
388 | - $this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * jQuery Validate for form validation |
|
394 | - * |
|
395 | - * @since 4.9.62.p |
|
396 | - * @throws DomainException |
|
397 | - * @throws DuplicateCollectionIdentifierException |
|
398 | - * @throws InvalidDataTypeException |
|
399 | - * @throws InvalidEntityException |
|
400 | - */ |
|
401 | - private function loadJqueryValidate() |
|
402 | - { |
|
403 | - $this->addJavascript( |
|
404 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
405 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
406 | - array(CoreAssetManager::JS_HANDLE_JQUERY), |
|
407 | - true, |
|
408 | - '1.15.0' |
|
409 | - ); |
|
410 | - |
|
411 | - $this->addJavascript( |
|
412 | - CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
413 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
414 | - array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
|
415 | - true, |
|
416 | - '1.15.0' |
|
417 | - ); |
|
418 | - } |
|
419 | - |
|
420 | - |
|
421 | - /** |
|
422 | - * accounting.js for performing client-side calculations |
|
423 | - * |
|
424 | - * @since 4.9.62.p |
|
425 | - * @throws DomainException |
|
426 | - * @throws DuplicateCollectionIdentifierException |
|
427 | - * @throws InvalidDataTypeException |
|
428 | - * @throws InvalidEntityException |
|
429 | - */ |
|
430 | - private function loadAccountingJs() |
|
431 | - { |
|
432 | - //accounting.js library |
|
433 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
434 | - $this->addJavascript( |
|
435 | - CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
436 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
437 | - array(CoreAssetManager::JS_HANDLE_UNDERSCORE), |
|
438 | - true, |
|
439 | - '0.3.2' |
|
440 | - ); |
|
441 | - |
|
442 | - $this->addJavascript( |
|
443 | - CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
444 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
445 | - array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
446 | - ) |
|
447 | - ->setInlineDataCallback( |
|
448 | - function () { |
|
449 | - wp_localize_script( |
|
450 | - CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
451 | - 'EE_ACCOUNTING_CFG', |
|
452 | - $this->getAccountingSettings() |
|
453 | - ); |
|
454 | - } |
|
455 | - ); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * registers assets for cleaning your ears |
|
461 | - * |
|
462 | - * @param JavascriptAsset $script |
|
463 | - */ |
|
464 | - public function loadQtipJs(JavascriptAsset $script) |
|
465 | - { |
|
466 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
467 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
468 | - if ( |
|
469 | - $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
470 | - && apply_filters('FHEE_load_qtip', false) |
|
471 | - ) { |
|
472 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
473 | - } |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * assets that are used in the WordPress admin |
|
479 | - * |
|
480 | - * @throws DuplicateCollectionIdentifierException |
|
481 | - * @throws InvalidDataTypeException |
|
482 | - * @throws InvalidEntityException |
|
483 | - * @throws DomainException |
|
484 | - * @since 4.9.62.p |
|
485 | - */ |
|
486 | - private function registerAdminAssets() |
|
487 | - { |
|
488 | - $this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation(); |
|
489 | - // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle. |
|
490 | - $this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE); |
|
491 | - } |
|
85 | + const JS_HANDLE_ACCOUNTING = 'ee-accounting'; |
|
86 | + |
|
87 | + const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page'; |
|
88 | + |
|
89 | + // EE CSS assets handles |
|
90 | + const CSS_HANDLE_DEFAULT = 'espresso_default'; |
|
91 | + |
|
92 | + const CSS_HANDLE_CUSTOM = 'espresso_custom_css'; |
|
93 | + |
|
94 | + const CSS_HANDLE_COMPONENTS = 'eventespresso-components'; |
|
95 | + |
|
96 | + const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default'; |
|
97 | + |
|
98 | + /** |
|
99 | + * @var EE_Currency_Config $currency_config |
|
100 | + */ |
|
101 | + protected $currency_config; |
|
102 | + |
|
103 | + /** |
|
104 | + * @var EE_Template_Config $template_config |
|
105 | + */ |
|
106 | + protected $template_config; |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * CoreAssetRegister constructor. |
|
111 | + * |
|
112 | + * @param AssetCollection $assets |
|
113 | + * @param EE_Currency_Config $currency_config |
|
114 | + * @param EE_Template_Config $template_config |
|
115 | + * @param DomainInterface $domain |
|
116 | + * @param Registry $registry |
|
117 | + */ |
|
118 | + public function __construct( |
|
119 | + AssetCollection $assets, |
|
120 | + EE_Currency_Config $currency_config, |
|
121 | + EE_Template_Config $template_config, |
|
122 | + DomainInterface $domain, |
|
123 | + Registry $registry |
|
124 | + ) { |
|
125 | + $this->currency_config = $currency_config; |
|
126 | + $this->template_config = $template_config; |
|
127 | + parent::__construct($domain, $assets, $registry); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @since 4.9.62.p |
|
133 | + * @throws DomainException |
|
134 | + * @throws DuplicateCollectionIdentifierException |
|
135 | + * @throws InvalidArgumentException |
|
136 | + * @throws InvalidDataTypeException |
|
137 | + * @throws InvalidEntityException |
|
138 | + * @throws InvalidInterfaceException |
|
139 | + */ |
|
140 | + public function addAssets() |
|
141 | + { |
|
142 | + $this->addJavascriptFiles(); |
|
143 | + $this->addStylesheetFiles(); |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @since 4.9.62.p |
|
149 | + * @throws DomainException |
|
150 | + * @throws DuplicateCollectionIdentifierException |
|
151 | + * @throws InvalidArgumentException |
|
152 | + * @throws InvalidDataTypeException |
|
153 | + * @throws InvalidEntityException |
|
154 | + * @throws InvalidInterfaceException |
|
155 | + */ |
|
156 | + public function addJavascriptFiles() |
|
157 | + { |
|
158 | + $this->loadCoreJs(); |
|
159 | + $this->loadJqueryValidate(); |
|
160 | + $this->loadAccountingJs(); |
|
161 | + add_action( |
|
162 | + 'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script', |
|
163 | + array($this, 'loadQtipJs') |
|
164 | + ); |
|
165 | + $this->registerAdminAssets(); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @throws DuplicateCollectionIdentifierException |
|
171 | + * @throws InvalidDataTypeException |
|
172 | + * @throws InvalidEntityException |
|
173 | + * @throws DomainException |
|
174 | + * @since 4.9.62.p |
|
175 | + */ |
|
176 | + public function addStylesheetFiles() |
|
177 | + { |
|
178 | + $this->loadCoreCss(); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * core default javascript |
|
184 | + * |
|
185 | + * @since 4.9.62.p |
|
186 | + * @throws DomainException |
|
187 | + * @throws DuplicateCollectionIdentifierException |
|
188 | + * @throws InvalidArgumentException |
|
189 | + * @throws InvalidDataTypeException |
|
190 | + * @throws InvalidEntityException |
|
191 | + * @throws InvalidInterfaceException |
|
192 | + */ |
|
193 | + private function loadCoreJs() |
|
194 | + { |
|
195 | + // conditionally load third-party libraries that WP core MIGHT have. |
|
196 | + $this->registerWpAssets(); |
|
197 | + |
|
198 | + $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData(); |
|
199 | + $this->addJs(self::JS_HANDLE_VENDOR); |
|
200 | + $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation(); |
|
201 | + $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation(); |
|
202 | + $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation(); |
|
203 | + $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation(); |
|
204 | + $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback( |
|
205 | + static function () { |
|
206 | + wp_add_inline_script( |
|
207 | + CoreAssetManager::JS_HANDLE_DATA_STORES, |
|
208 | + is_admin() |
|
209 | + ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )' |
|
210 | + : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )' |
|
211 | + ); |
|
212 | + } |
|
213 | + ); |
|
214 | + $this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation(); |
|
215 | + $this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation(); |
|
216 | + $this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation(); |
|
217 | + |
|
218 | + $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest')); |
|
219 | + $this->registry->addData( |
|
220 | + 'paths', |
|
221 | + array( |
|
222 | + 'base_rest_route' => rest_url(), |
|
223 | + 'rest_route' => rest_url('ee/v4.8.36/'), |
|
224 | + 'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(), |
|
225 | + 'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(), |
|
226 | + 'site_url' => site_url('/'), |
|
227 | + 'admin_url' => admin_url('/'), |
|
228 | + ) |
|
229 | + ); |
|
230 | + // Event Espresso brand name |
|
231 | + $this->registry->addData('brandName', Domain::brandName()); |
|
232 | + /** site formatting values **/ |
|
233 | + $this->registry->addData( |
|
234 | + 'site_formats', |
|
235 | + array( |
|
236 | + 'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats() |
|
237 | + ) |
|
238 | + ); |
|
239 | + /** currency data **/ |
|
240 | + $this->registry->addData( |
|
241 | + 'currency_config', |
|
242 | + $this->getCurrencySettings() |
|
243 | + ); |
|
244 | + /** site timezone */ |
|
245 | + $this->registry->addData( |
|
246 | + 'default_timezone', |
|
247 | + array( |
|
248 | + 'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(), |
|
249 | + 'string' => get_option('timezone_string'), |
|
250 | + 'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(), |
|
251 | + ) |
|
252 | + ); |
|
253 | + /** site locale (user locale if user logged in) */ |
|
254 | + $this->registry->addData( |
|
255 | + 'locale', |
|
256 | + array( |
|
257 | + 'user' => get_user_locale(), |
|
258 | + 'site' => get_locale() |
|
259 | + ) |
|
260 | + ); |
|
261 | + |
|
262 | + $this->addJavascript( |
|
263 | + CoreAssetManager::JS_HANDLE_CORE, |
|
264 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
265 | + array(CoreAssetManager::JS_HANDLE_JQUERY) |
|
266 | + ) |
|
267 | + ->setInlineDataCallback( |
|
268 | + static function () { |
|
269 | + wp_localize_script( |
|
270 | + CoreAssetManager::JS_HANDLE_CORE, |
|
271 | + CoreAssetManager::JS_HANDLE_I18N, |
|
272 | + EE_Registry::sanitize_i18n_js_strings() |
|
273 | + ); |
|
274 | + } |
|
275 | + ); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Registers vendor files that are bundled with a later version WP but might not be for the current version of |
|
281 | + * WordPress in the running environment. |
|
282 | + * |
|
283 | + * @throws DuplicateCollectionIdentifierException |
|
284 | + * @throws InvalidDataTypeException |
|
285 | + * @throws InvalidEntityException |
|
286 | + * @throws DomainException |
|
287 | + * @since 4.9.71.p |
|
288 | + */ |
|
289 | + private function registerWpAssets() |
|
290 | + { |
|
291 | + global $wp_version; |
|
292 | + if (version_compare($wp_version, '5.0.beta', '>=')) { |
|
293 | + return; |
|
294 | + } |
|
295 | + $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0'); |
|
296 | + $this->addVendorJavascript( |
|
297 | + CoreAssetManager::JS_HANDLE_REACT_DOM, |
|
298 | + array(CoreAssetManager::JS_HANDLE_REACT), |
|
299 | + true, |
|
300 | + '16.6.0' |
|
301 | + ); |
|
302 | + $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11') |
|
303 | + ->setInlineDataCallback( |
|
304 | + static function() { |
|
305 | + wp_add_inline_script( |
|
306 | + CoreAssetManager::JS_HANDLE_LODASH, |
|
307 | + 'window.lodash = _.noConflict();' |
|
308 | + ); |
|
309 | + } |
|
310 | + ); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Returns configuration data for the accounting-js library. |
|
316 | + * @since 4.9.71.p |
|
317 | + * @return array |
|
318 | + */ |
|
319 | + private function getAccountingSettings() { |
|
320 | + return array( |
|
321 | + 'currency' => array( |
|
322 | + 'symbol' => $this->currency_config->sign, |
|
323 | + 'format' => array( |
|
324 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
325 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
326 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
327 | + ), |
|
328 | + 'decimal' => $this->currency_config->dec_mrk, |
|
329 | + 'thousand' => $this->currency_config->thsnds, |
|
330 | + 'precision' => $this->currency_config->dec_plc, |
|
331 | + ), |
|
332 | + 'number' => array( |
|
333 | + 'precision' => $this->currency_config->dec_plc, |
|
334 | + 'thousand' => $this->currency_config->thsnds, |
|
335 | + 'decimal' => $this->currency_config->dec_mrk, |
|
336 | + ), |
|
337 | + ); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * Returns configuration data for the js Currency VO. |
|
343 | + * @since 4.9.71.p |
|
344 | + * @return array |
|
345 | + */ |
|
346 | + private function getCurrencySettings() |
|
347 | + { |
|
348 | + return array( |
|
349 | + 'code' => $this->currency_config->code, |
|
350 | + 'singularLabel' => $this->currency_config->name, |
|
351 | + 'pluralLabel' => $this->currency_config->plural, |
|
352 | + 'sign' => $this->currency_config->sign, |
|
353 | + 'signB4' => $this->currency_config->sign_b4, |
|
354 | + 'decimalPlaces' => $this->currency_config->dec_plc, |
|
355 | + 'decimalMark' => $this->currency_config->dec_mrk, |
|
356 | + 'thousandsSeparator' => $this->currency_config->thsnds, |
|
357 | + ); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * @throws DuplicateCollectionIdentifierException |
|
363 | + * @throws InvalidDataTypeException |
|
364 | + * @throws InvalidEntityException |
|
365 | + * @throws DomainException |
|
366 | + * @since 4.9.62.p |
|
367 | + */ |
|
368 | + private function loadCoreCss() |
|
369 | + { |
|
370 | + if ($this->template_config->enable_default_style && ! is_admin()) { |
|
371 | + $this->addStylesheet( |
|
372 | + CoreAssetManager::CSS_HANDLE_DEFAULT, |
|
373 | + is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css') |
|
374 | + ? EVENT_ESPRESSO_UPLOAD_URL . 'css/espresso_default.css' |
|
375 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
376 | + array('dashicons') |
|
377 | + ); |
|
378 | + //Load custom style sheet if available |
|
379 | + if ($this->template_config->custom_style_sheet !== null) { |
|
380 | + $this->addStylesheet( |
|
381 | + CoreAssetManager::CSS_HANDLE_CUSTOM, |
|
382 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
383 | + array(CoreAssetManager::CSS_HANDLE_DEFAULT) |
|
384 | + ); |
|
385 | + } |
|
386 | + } |
|
387 | + $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']); |
|
388 | + $this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * jQuery Validate for form validation |
|
394 | + * |
|
395 | + * @since 4.9.62.p |
|
396 | + * @throws DomainException |
|
397 | + * @throws DuplicateCollectionIdentifierException |
|
398 | + * @throws InvalidDataTypeException |
|
399 | + * @throws InvalidEntityException |
|
400 | + */ |
|
401 | + private function loadJqueryValidate() |
|
402 | + { |
|
403 | + $this->addJavascript( |
|
404 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE, |
|
405 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
406 | + array(CoreAssetManager::JS_HANDLE_JQUERY), |
|
407 | + true, |
|
408 | + '1.15.0' |
|
409 | + ); |
|
410 | + |
|
411 | + $this->addJavascript( |
|
412 | + CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA, |
|
413 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
414 | + array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE), |
|
415 | + true, |
|
416 | + '1.15.0' |
|
417 | + ); |
|
418 | + } |
|
419 | + |
|
420 | + |
|
421 | + /** |
|
422 | + * accounting.js for performing client-side calculations |
|
423 | + * |
|
424 | + * @since 4.9.62.p |
|
425 | + * @throws DomainException |
|
426 | + * @throws DuplicateCollectionIdentifierException |
|
427 | + * @throws InvalidDataTypeException |
|
428 | + * @throws InvalidEntityException |
|
429 | + */ |
|
430 | + private function loadAccountingJs() |
|
431 | + { |
|
432 | + //accounting.js library |
|
433 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
434 | + $this->addJavascript( |
|
435 | + CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE, |
|
436 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
437 | + array(CoreAssetManager::JS_HANDLE_UNDERSCORE), |
|
438 | + true, |
|
439 | + '0.3.2' |
|
440 | + ); |
|
441 | + |
|
442 | + $this->addJavascript( |
|
443 | + CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
444 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
445 | + array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE) |
|
446 | + ) |
|
447 | + ->setInlineDataCallback( |
|
448 | + function () { |
|
449 | + wp_localize_script( |
|
450 | + CoreAssetManager::JS_HANDLE_ACCOUNTING, |
|
451 | + 'EE_ACCOUNTING_CFG', |
|
452 | + $this->getAccountingSettings() |
|
453 | + ); |
|
454 | + } |
|
455 | + ); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * registers assets for cleaning your ears |
|
461 | + * |
|
462 | + * @param JavascriptAsset $script |
|
463 | + */ |
|
464 | + public function loadQtipJs(JavascriptAsset $script) |
|
465 | + { |
|
466 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
467 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
468 | + if ( |
|
469 | + $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE |
|
470 | + && apply_filters('FHEE_load_qtip', false) |
|
471 | + ) { |
|
472 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
473 | + } |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * assets that are used in the WordPress admin |
|
479 | + * |
|
480 | + * @throws DuplicateCollectionIdentifierException |
|
481 | + * @throws InvalidDataTypeException |
|
482 | + * @throws InvalidEntityException |
|
483 | + * @throws DomainException |
|
484 | + * @since 4.9.62.p |
|
485 | + */ |
|
486 | + private function registerAdminAssets() |
|
487 | + { |
|
488 | + $this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation(); |
|
489 | + // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle. |
|
490 | + $this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE); |
|
491 | + } |
|
492 | 492 | } |
@@ -112,10 +112,10 @@ |
||
112 | 112 | ]; |
113 | 113 | $this->_wp_core_model = true; |
114 | 114 | $this->_caps_slug = 'users'; |
115 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
116 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
115 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read] = 'list'; |
|
116 | + $this->_cap_contexts_to_cap_action_map[EEM_Base::caps_read_admin] = 'list'; |
|
117 | 117 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
118 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
118 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_WP_User(); |
|
119 | 119 | } |
120 | 120 | // @todo: account for create_users controls whether they can create users at all |
121 | 121 | parent::__construct($timezone); |
@@ -12,133 +12,133 @@ |
||
12 | 12 | */ |
13 | 13 | class EEM_WP_User extends EEM_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * private instance of the EEM_WP_User object |
|
17 | - * |
|
18 | - * @type EEM_WP_User |
|
19 | - */ |
|
20 | - protected static $_instance; |
|
15 | + /** |
|
16 | + * private instance of the EEM_WP_User object |
|
17 | + * |
|
18 | + * @type EEM_WP_User |
|
19 | + */ |
|
20 | + protected static $_instance; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * constructor |
|
25 | - * |
|
26 | - * @param null $timezone |
|
27 | - * @param ModelFieldFactory $model_field_factory |
|
28 | - * @throws EE_Error |
|
29 | - * @throws InvalidArgumentException |
|
30 | - */ |
|
31 | - protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
32 | - { |
|
33 | - $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
34 | - $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
35 | - global $wpdb; |
|
36 | - $this->_tables = array( |
|
37 | - 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
38 | - ); |
|
39 | - $this->_fields = array( |
|
40 | - 'WP_User' => array( |
|
41 | - 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
42 | - 'ID', |
|
43 | - esc_html__('WP_User ID', 'event_espresso') |
|
44 | - ), |
|
45 | - 'user_login' => $model_field_factory->createPlainTextField( |
|
46 | - 'user_login', |
|
47 | - esc_html__('User Login', 'event_espresso'), |
|
48 | - false |
|
49 | - ), |
|
50 | - 'user_pass' => $model_field_factory->createPlainTextField( |
|
51 | - 'user_pass', |
|
52 | - esc_html__('User Password', 'event_espresso'), |
|
53 | - false |
|
54 | - ), |
|
55 | - 'user_nicename' => $model_field_factory->createPlainTextField( |
|
56 | - 'user_nicename', |
|
57 | - esc_html__(' User Nice Name', 'event_espresso'), |
|
58 | - false |
|
59 | - ), |
|
60 | - 'user_email' => $model_field_factory->createEmailField( |
|
61 | - 'user_email', |
|
62 | - esc_html__('User Email', 'event_espresso'), |
|
63 | - false, |
|
64 | - null |
|
65 | - ), |
|
66 | - 'user_registered' => $model_field_factory->createDatetimeField( |
|
67 | - 'user_registered', |
|
68 | - esc_html__('Date User Registered', 'event_espresso'), |
|
69 | - $timezone |
|
70 | - ), |
|
71 | - 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
72 | - 'user_activation_key', |
|
73 | - esc_html__('User Activation Key', 'event_espresso'), |
|
74 | - false |
|
75 | - ), |
|
76 | - 'user_status' => $model_field_factory->createIntegerField( |
|
77 | - 'user_status', |
|
78 | - esc_html__('User Status', 'event_espresso') |
|
79 | - ), |
|
80 | - 'display_name' => $model_field_factory->createPlainTextField( |
|
81 | - 'display_name', |
|
82 | - esc_html__('Display Name', 'event_espresso'), |
|
83 | - false |
|
84 | - ), |
|
85 | - ), |
|
86 | - ); |
|
87 | - $this->_model_relations = array( |
|
88 | - 'Attendee' => new EE_Has_Many_Relation(), |
|
89 | - // all models are related to the change log |
|
90 | - // 'Change_Log' => new EE_Has_Many_Relation(), |
|
91 | - 'Event' => new EE_Has_Many_Relation(), |
|
92 | - 'Message' => new EE_Has_Many_Relation(), |
|
93 | - 'Payment_Method' => new EE_Has_Many_Relation(), |
|
94 | - 'Price' => new EE_Has_Many_Relation(), |
|
95 | - 'Price_Type' => new EE_Has_Many_Relation(), |
|
96 | - 'Question' => new EE_Has_Many_Relation(), |
|
97 | - 'Question_Group' => new EE_Has_Many_Relation(), |
|
98 | - 'Ticket' => new EE_Has_Many_Relation(), |
|
99 | - 'Venue' => new EE_Has_Many_Relation(), |
|
100 | - ); |
|
101 | - $this->foreign_key_aliases = [ |
|
102 | - 'Event.EVT_wp_user' => 'WP_User.ID', |
|
103 | - 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
104 | - 'Price.PRC_wp_user' => 'WP_User.ID', |
|
105 | - 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
106 | - 'Question.QST_wp_user' => 'WP_User.ID', |
|
107 | - 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
108 | - 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
109 | - 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
110 | - ]; |
|
111 | - $this->_wp_core_model = true; |
|
112 | - $this->_caps_slug = 'users'; |
|
113 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
114 | - $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
115 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
116 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
117 | - } |
|
118 | - // @todo: account for create_users controls whether they can create users at all |
|
119 | - parent::__construct($timezone); |
|
120 | - } |
|
23 | + /** |
|
24 | + * constructor |
|
25 | + * |
|
26 | + * @param null $timezone |
|
27 | + * @param ModelFieldFactory $model_field_factory |
|
28 | + * @throws EE_Error |
|
29 | + * @throws InvalidArgumentException |
|
30 | + */ |
|
31 | + protected function __construct($timezone, ModelFieldFactory $model_field_factory) |
|
32 | + { |
|
33 | + $this->singular_item = esc_html__('WP_User', 'event_espresso'); |
|
34 | + $this->plural_item = esc_html__('WP_Users', 'event_espresso'); |
|
35 | + global $wpdb; |
|
36 | + $this->_tables = array( |
|
37 | + 'WP_User' => new EE_Primary_Table($wpdb->users, 'ID', true), |
|
38 | + ); |
|
39 | + $this->_fields = array( |
|
40 | + 'WP_User' => array( |
|
41 | + 'ID' => $model_field_factory->createPrimaryKeyIntField( |
|
42 | + 'ID', |
|
43 | + esc_html__('WP_User ID', 'event_espresso') |
|
44 | + ), |
|
45 | + 'user_login' => $model_field_factory->createPlainTextField( |
|
46 | + 'user_login', |
|
47 | + esc_html__('User Login', 'event_espresso'), |
|
48 | + false |
|
49 | + ), |
|
50 | + 'user_pass' => $model_field_factory->createPlainTextField( |
|
51 | + 'user_pass', |
|
52 | + esc_html__('User Password', 'event_espresso'), |
|
53 | + false |
|
54 | + ), |
|
55 | + 'user_nicename' => $model_field_factory->createPlainTextField( |
|
56 | + 'user_nicename', |
|
57 | + esc_html__(' User Nice Name', 'event_espresso'), |
|
58 | + false |
|
59 | + ), |
|
60 | + 'user_email' => $model_field_factory->createEmailField( |
|
61 | + 'user_email', |
|
62 | + esc_html__('User Email', 'event_espresso'), |
|
63 | + false, |
|
64 | + null |
|
65 | + ), |
|
66 | + 'user_registered' => $model_field_factory->createDatetimeField( |
|
67 | + 'user_registered', |
|
68 | + esc_html__('Date User Registered', 'event_espresso'), |
|
69 | + $timezone |
|
70 | + ), |
|
71 | + 'user_activation_key' => $model_field_factory->createPlainTextField( |
|
72 | + 'user_activation_key', |
|
73 | + esc_html__('User Activation Key', 'event_espresso'), |
|
74 | + false |
|
75 | + ), |
|
76 | + 'user_status' => $model_field_factory->createIntegerField( |
|
77 | + 'user_status', |
|
78 | + esc_html__('User Status', 'event_espresso') |
|
79 | + ), |
|
80 | + 'display_name' => $model_field_factory->createPlainTextField( |
|
81 | + 'display_name', |
|
82 | + esc_html__('Display Name', 'event_espresso'), |
|
83 | + false |
|
84 | + ), |
|
85 | + ), |
|
86 | + ); |
|
87 | + $this->_model_relations = array( |
|
88 | + 'Attendee' => new EE_Has_Many_Relation(), |
|
89 | + // all models are related to the change log |
|
90 | + // 'Change_Log' => new EE_Has_Many_Relation(), |
|
91 | + 'Event' => new EE_Has_Many_Relation(), |
|
92 | + 'Message' => new EE_Has_Many_Relation(), |
|
93 | + 'Payment_Method' => new EE_Has_Many_Relation(), |
|
94 | + 'Price' => new EE_Has_Many_Relation(), |
|
95 | + 'Price_Type' => new EE_Has_Many_Relation(), |
|
96 | + 'Question' => new EE_Has_Many_Relation(), |
|
97 | + 'Question_Group' => new EE_Has_Many_Relation(), |
|
98 | + 'Ticket' => new EE_Has_Many_Relation(), |
|
99 | + 'Venue' => new EE_Has_Many_Relation(), |
|
100 | + ); |
|
101 | + $this->foreign_key_aliases = [ |
|
102 | + 'Event.EVT_wp_user' => 'WP_User.ID', |
|
103 | + 'Payment_Method.PMD_wp_user' => 'WP_User.ID', |
|
104 | + 'Price.PRC_wp_user' => 'WP_User.ID', |
|
105 | + 'Price_Type.PRT_wp_user' => 'WP_User.ID', |
|
106 | + 'Question.QST_wp_user' => 'WP_User.ID', |
|
107 | + 'Question_Group.QSG_wp_user' => 'WP_User.ID', |
|
108 | + 'Ticket.VNU_wp_user' => 'WP_User.ID', |
|
109 | + 'Venue.TKT_wp_user' => 'WP_User.ID', |
|
110 | + ]; |
|
111 | + $this->_wp_core_model = true; |
|
112 | + $this->_caps_slug = 'users'; |
|
113 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read ] = 'list'; |
|
114 | + $this->_cap_contexts_to_cap_action_map[ EEM_Base::caps_read_admin ] = 'list'; |
|
115 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
116 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_WP_User(); |
|
117 | + } |
|
118 | + // @todo: account for create_users controls whether they can create users at all |
|
119 | + parent::__construct($timezone); |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * We don't need a foreign key to the WP_User model, we just need its primary key |
|
125 | - * |
|
126 | - * @return string |
|
127 | - * @throws EE_Error |
|
128 | - */ |
|
129 | - public function wp_user_field_name() |
|
130 | - { |
|
131 | - return $this->primary_key_name(); |
|
132 | - } |
|
123 | + /** |
|
124 | + * We don't need a foreign key to the WP_User model, we just need its primary key |
|
125 | + * |
|
126 | + * @return string |
|
127 | + * @throws EE_Error |
|
128 | + */ |
|
129 | + public function wp_user_field_name() |
|
130 | + { |
|
131 | + return $this->primary_key_name(); |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | - /** |
|
136 | - * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
137 | - * |
|
138 | - * @return boolean |
|
139 | - */ |
|
140 | - public function is_owned() |
|
141 | - { |
|
142 | - return true; |
|
143 | - } |
|
135 | + /** |
|
136 | + * This WP_User model IS owned, even though it doesn't have a foreign key to itself |
|
137 | + * |
|
138 | + * @return boolean |
|
139 | + */ |
|
140 | + public function is_owned() |
|
141 | + { |
|
142 | + return true; |
|
143 | + } |
|
144 | 144 | } |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | public function is_valid_scope($scope) |
171 | 171 | { |
172 | 172 | $scopes = $this->scopes(); |
173 | - if (isset($scopes[ $scope ])) { |
|
173 | + if (isset($scopes[$scope])) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | return false; |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | */ |
188 | 188 | public function get_all_active($scope = null, $query_params = []) |
189 | 189 | { |
190 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | + if ( ! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
191 | 191 | $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
192 | 192 | } |
193 | 193 | return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | $count = 0; |
236 | 236 | foreach ($this->scopes() as $scope_name => $desc) { |
237 | 237 | $count++; |
238 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | + $acceptable_scopes['PMD_scope*'.$count] = ['LIKE', '%'.$scope_name.'%']; |
|
239 | 239 | } |
240 | 240 | return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
241 | 241 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | $usable_payment_methods = []; |
392 | 392 | foreach ($payment_methods as $key => $payment_method) { |
393 | 393 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
394 | - $usable_payment_methods[ $key ] = $payment_method; |
|
394 | + $usable_payment_methods[$key] = $payment_method; |
|
395 | 395 | // some payment methods enqueue their scripts in EE_PMT_*::__construct |
396 | 396 | // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
397 | 397 | // its scripts). but for backwards-compat we should continue to do that |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | $payment_method |
406 | 406 | ); |
407 | 407 | new PersistentAdminNotice( |
408 | - 'auto-deactivated-' . $payment_method->type(), |
|
408 | + 'auto-deactivated-'.$payment_method->type(), |
|
409 | 409 | sprintf( |
410 | 410 | esc_html__( |
411 | 411 | 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | ), |
414 | 414 | $payment_method->admin_name(), |
415 | 415 | '<br />', |
416 | - '<a href="' . admin_url('plugins.php') . '">', |
|
416 | + '<a href="'.admin_url('plugins.php').'">', |
|
417 | 417 | '</a>' |
418 | 418 | ), |
419 | 419 | true |
@@ -16,456 +16,456 @@ |
||
16 | 16 | */ |
17 | 17 | class EEM_Payment_Method extends EEM_Base |
18 | 18 | { |
19 | - const scope_cart = 'CART'; |
|
20 | - |
|
21 | - const scope_admin = 'ADMIN'; |
|
22 | - |
|
23 | - const scope_api = 'API'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @type EEM_Payment_Method |
|
27 | - */ |
|
28 | - protected static $_instance = null; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * private constructor to prevent direct creation |
|
33 | - * |
|
34 | - * @param null $timezone |
|
35 | - * @throws EE_Error |
|
36 | - */ |
|
37 | - protected function __construct($timezone = null) |
|
38 | - { |
|
39 | - $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
40 | - $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
41 | - $this->_tables = [ |
|
42 | - 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
43 | - ]; |
|
44 | - $this->_fields = [ |
|
45 | - 'Payment_Method' => [ |
|
46 | - 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
47 | - 'PMD_ID', |
|
48 | - esc_html__('ID', 'event_espresso') |
|
49 | - ), |
|
50 | - 'PMD_type' => new EE_Plain_Text_Field( |
|
51 | - 'PMD_type', |
|
52 | - esc_html__('Payment Method Type', 'event_espresso'), |
|
53 | - false, |
|
54 | - 'Admin_Only' |
|
55 | - ), |
|
56 | - 'PMD_name' => new EE_Plain_Text_Field( |
|
57 | - 'PMD_name', |
|
58 | - esc_html__('Name', 'event_espresso'), |
|
59 | - false |
|
60 | - ), |
|
61 | - 'PMD_desc' => new EE_Post_Content_Field( |
|
62 | - 'PMD_desc', |
|
63 | - esc_html__('Description', 'event_espresso'), |
|
64 | - false, |
|
65 | - '' |
|
66 | - ), |
|
67 | - 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
68 | - 'PMD_admin_name', |
|
69 | - esc_html__('Admin-Only Name', 'event_espresso'), |
|
70 | - true |
|
71 | - ), |
|
72 | - 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
73 | - 'PMD_admin_desc', |
|
74 | - esc_html__('Admin-Only Description', 'event_espresso'), |
|
75 | - true |
|
76 | - ), |
|
77 | - 'PMD_slug' => new EE_Slug_Field( |
|
78 | - 'PMD_slug', |
|
79 | - esc_html__('Slug', 'event_espresso'), |
|
80 | - false |
|
81 | - ), |
|
82 | - 'PMD_order' => new EE_Integer_Field( |
|
83 | - 'PMD_order', |
|
84 | - esc_html__('Order', 'event_espresso'), |
|
85 | - false, |
|
86 | - 0 |
|
87 | - ), |
|
88 | - 'PMD_debug_mode' => new EE_Boolean_Field( |
|
89 | - 'PMD_debug_mode', |
|
90 | - esc_html__('Debug Mode On?', 'event_espresso'), |
|
91 | - false, |
|
92 | - false |
|
93 | - ), |
|
94 | - 'PMD_wp_user' => new EE_WP_User_Field( |
|
95 | - 'PMD_wp_user', |
|
96 | - esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
97 | - false |
|
98 | - ), |
|
99 | - 'PMD_open_by_default' => new EE_Boolean_Field( |
|
100 | - 'PMD_open_by_default', |
|
101 | - esc_html__('Open by Default?', 'event_espresso'), |
|
102 | - false, |
|
103 | - false |
|
104 | - ), |
|
105 | - 'PMD_button_url' => new EE_Plain_Text_Field( |
|
106 | - 'PMD_button_url', |
|
107 | - esc_html__('Button URL', 'event_espresso'), |
|
108 | - true, |
|
109 | - '' |
|
110 | - ), |
|
111 | - 'PMD_scope' => new EE_Serialized_Text_Field( |
|
112 | - 'PMD_scope', |
|
113 | - esc_html__('Usable From?', 'event_espresso'), |
|
114 | - false, |
|
115 | - []// possible values currently are 'CART','ADMIN','API' |
|
116 | - ), |
|
117 | - ], |
|
118 | - ]; |
|
119 | - $this->_model_relations = [ |
|
120 | - 'Payment' => new EE_Has_Many_Relation(), |
|
121 | - 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
122 | - 'Transaction' => new EE_Has_Many_Relation(), |
|
123 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
124 | - ]; |
|
125 | - parent::__construct($timezone); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Gets one by the slug provided |
|
131 | - * |
|
132 | - * @param string $slug |
|
133 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
134 | - * @throws EE_Error |
|
135 | - */ |
|
136 | - public function get_one_by_slug($slug) |
|
137 | - { |
|
138 | - return $this->get_one([['PMD_slug' => $slug]]); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * Gets all the acceptable scopes for payment methods. |
|
144 | - * Keys are their names as store din the DB, and values are nice names for displaying them |
|
145 | - * |
|
146 | - * @return array |
|
147 | - */ |
|
148 | - public function scopes() |
|
149 | - { |
|
150 | - return apply_filters( |
|
151 | - 'FHEE__EEM_Payment_Method__scopes', |
|
152 | - [ |
|
153 | - EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
154 | - EEM_Payment_Method::scope_admin => esc_html__( |
|
155 | - 'Admin Registration Page (no online processing)', |
|
156 | - 'event_espresso' |
|
157 | - ), |
|
158 | - ] |
|
159 | - ); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Determines if this is an valid scope |
|
165 | - * |
|
166 | - * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
167 | - * @return boolean |
|
168 | - */ |
|
169 | - public function is_valid_scope($scope) |
|
170 | - { |
|
171 | - $scopes = $this->scopes(); |
|
172 | - if (isset($scopes[ $scope ])) { |
|
173 | - return true; |
|
174 | - } |
|
175 | - return false; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Gets all active payment methods |
|
181 | - * |
|
182 | - * @param string $scope one of |
|
183 | - * @param array $query_params |
|
184 | - * @return EE_Base_Class[]|EE_Payment_Method[] |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public function get_all_active($scope = null, $query_params = []) |
|
188 | - { |
|
189 | - if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | - $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
191 | - } |
|
192 | - return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * Counts all active gateways in the specified scope |
|
198 | - * |
|
199 | - * @param string $scope one of EEM_Payment_Method::scope_* |
|
200 | - * @param array $query_params |
|
201 | - * @return int |
|
202 | - * @throws EE_Error |
|
203 | - */ |
|
204 | - public function count_active($scope = null, $query_params = []) |
|
205 | - { |
|
206 | - return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
212 | - * argument to get all active for a given scope |
|
213 | - * |
|
214 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
215 | - * @param array $query_params |
|
216 | - * @return array |
|
217 | - * @throws EE_Error |
|
218 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
219 | - */ |
|
220 | - protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
|
221 | - { |
|
222 | - if ($scope) { |
|
223 | - if ($this->is_valid_scope($scope)) { |
|
224 | - return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
225 | - } |
|
226 | - throw new EE_Error( |
|
227 | - sprintf( |
|
228 | - esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
229 | - $scope |
|
230 | - ) |
|
231 | - ); |
|
232 | - } |
|
233 | - $acceptable_scopes = []; |
|
234 | - $count = 0; |
|
235 | - foreach ($this->scopes() as $scope_name => $desc) { |
|
236 | - $count++; |
|
237 | - $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | - } |
|
239 | - return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
245 | - * argument to get all active for a given scope |
|
246 | - * |
|
247 | - * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
248 | - * @param array $query_params |
|
249 | - * @return array |
|
250 | - * @throws EE_Error |
|
251 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
252 | - */ |
|
253 | - public function get_query_params_for_all_active($scope = null, $query_params = []) |
|
254 | - { |
|
255 | - return $this->_get_query_params_for_all_active($scope, $query_params); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Gets one active payment method. see @get_all_active for documentation |
|
261 | - * |
|
262 | - * @param string $scope |
|
263 | - * @param array $query_params |
|
264 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
265 | - * @throws EE_Error |
|
266 | - */ |
|
267 | - public function get_one_active($scope = null, $query_params = []) |
|
268 | - { |
|
269 | - return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Gets one payment method of that type, regardless of whether its active or not |
|
275 | - * |
|
276 | - * @param string $type |
|
277 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
278 | - * @throws EE_Error |
|
279 | - */ |
|
280 | - public function get_one_of_type($type) |
|
281 | - { |
|
282 | - return $this->get_one([['PMD_type' => $type]]); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Overrides parent ot also check by the slug |
|
288 | - * |
|
289 | - * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
290 | - * @param boolean $ensure_is_in_db |
|
291 | - * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
|
292 | - * @throws EE_Error |
|
293 | - * @see EEM_Base::ensure_is_obj() |
|
294 | - */ |
|
295 | - public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
296 | - { |
|
297 | - // first: check if it's a slug |
|
298 | - if (is_string($base_class_obj_or_id)) { |
|
299 | - $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
300 | - if ($obj) { |
|
301 | - return $obj; |
|
302 | - } |
|
303 | - } |
|
304 | - // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
305 | - try { |
|
306 | - return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
307 | - } catch (EE_Error $e) { |
|
308 | - // handle it outside the catch |
|
309 | - } |
|
310 | - throw new EE_Error( |
|
311 | - sprintf( |
|
312 | - esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'), |
|
313 | - $base_class_obj_or_id |
|
314 | - ) |
|
315 | - ); |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Gets the ID of this object, or if its a string finds the object's id |
|
321 | - * associated with that slug |
|
322 | - * |
|
323 | - * @param mixed $base_obj_or_id_or_slug |
|
324 | - * @return int |
|
325 | - * @throws EE_Error |
|
326 | - */ |
|
327 | - public function ensure_is_ID($base_obj_or_id_or_slug) |
|
328 | - { |
|
329 | - if (is_string($base_obj_or_id_or_slug)) { |
|
330 | - // assume it's a slug |
|
331 | - $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
332 | - } |
|
333 | - return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Verifies the button urls on all the passed payment methods have a valid button url. |
|
339 | - * If not, resets them to their default. |
|
340 | - * |
|
341 | - * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
|
342 | - * @throws EE_Error |
|
343 | - * @throws ReflectionException |
|
344 | - */ |
|
345 | - public function verify_button_urls($payment_methods = null) |
|
346 | - { |
|
347 | - $payment_methods = is_array($payment_methods) |
|
348 | - ? $payment_methods |
|
349 | - : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
350 | - foreach ($payment_methods as $payment_method) { |
|
351 | - try { |
|
352 | - // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
353 | - // though this is a caffeinated install, reset it to the default. |
|
354 | - $current_button_url = $payment_method->button_url(); |
|
355 | - if ( |
|
356 | - empty($current_button_url) |
|
357 | - || ( |
|
358 | - strpos($current_button_url, 'decaf') !== false |
|
359 | - && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
360 | - ) |
|
361 | - ) { |
|
362 | - $payment_method->save( |
|
363 | - [ |
|
364 | - 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
365 | - ] |
|
366 | - ); |
|
367 | - } |
|
368 | - } catch (EE_Error $e) { |
|
369 | - $payment_method->deactivate(); |
|
370 | - } |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
377 | - * but also verifies the payment method type of each is a usable object. If not, |
|
378 | - * deactivate it, sets a notification, and deactivates it |
|
379 | - * |
|
380 | - * @param array $rows |
|
381 | - * @return EE_Payment_Method[] |
|
382 | - * @throws EE_Error |
|
383 | - * @throws InvalidDataTypeException |
|
384 | - * @throws ReflectionException |
|
385 | - */ |
|
386 | - protected function _create_objects($rows = []) |
|
387 | - { |
|
388 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
389 | - $payment_methods = parent::_create_objects($rows); |
|
390 | - /* @var $payment_methods EE_Payment_Method[] */ |
|
391 | - $usable_payment_methods = []; |
|
392 | - foreach ($payment_methods as $key => $payment_method) { |
|
393 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
394 | - $usable_payment_methods[ $key ] = $payment_method; |
|
395 | - // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
396 | - // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
397 | - // its scripts). but for backwards-compat we should continue to do that |
|
398 | - $payment_method->type_obj(); |
|
399 | - } elseif ($payment_method->active()) { |
|
400 | - // only deactivate and notify the admin if the payment is active somewhere |
|
401 | - $payment_method->deactivate(); |
|
402 | - $payment_method->save(); |
|
403 | - do_action( |
|
404 | - 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
405 | - $payment_method |
|
406 | - ); |
|
407 | - new PersistentAdminNotice( |
|
408 | - 'auto-deactivated-' . $payment_method->type(), |
|
409 | - sprintf( |
|
410 | - esc_html__( |
|
411 | - 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
412 | - 'event_espresso' |
|
413 | - ), |
|
414 | - $payment_method->admin_name(), |
|
415 | - '<br />', |
|
416 | - '<a href="' . admin_url('plugins.php') . '">', |
|
417 | - '</a>' |
|
418 | - ), |
|
419 | - true |
|
420 | - ); |
|
421 | - } |
|
422 | - } |
|
423 | - return $usable_payment_methods; |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Gets all the payment methods which can be used for transaction |
|
429 | - * (according to the relations between payment methods and events, and |
|
430 | - * the currencies used for the transaction and their relation to payment methods) |
|
431 | - * |
|
432 | - * @param EE_Transaction $transaction |
|
433 | - * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
434 | - * @return EE_Payment_Method[] |
|
435 | - * @throws EE_Error |
|
436 | - */ |
|
437 | - public function get_all_for_transaction($transaction, $scope) |
|
438 | - { |
|
439 | - // give addons a chance to override what payment methods are chosen based on the transaction |
|
440 | - return apply_filters( |
|
441 | - 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
442 | - $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
443 | - $transaction, |
|
444 | - $scope |
|
445 | - ); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * Returns the payment method used for the last payment made for a registration. |
|
451 | - * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
452 | - * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
453 | - * |
|
454 | - * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
455 | - * registration. |
|
456 | - * @return EE_Payment|null |
|
457 | - * @throws EE_Error |
|
458 | - */ |
|
459 | - public function get_last_used_for_registration($registration_or_reg_id) |
|
460 | - { |
|
461 | - $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
462 | - |
|
463 | - $query_params = [ |
|
464 | - 0 => [ |
|
465 | - 'Payment.Registration.REG_ID' => $registration_id, |
|
466 | - ], |
|
467 | - 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
468 | - ]; |
|
469 | - return $this->get_one($query_params); |
|
470 | - } |
|
19 | + const scope_cart = 'CART'; |
|
20 | + |
|
21 | + const scope_admin = 'ADMIN'; |
|
22 | + |
|
23 | + const scope_api = 'API'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @type EEM_Payment_Method |
|
27 | + */ |
|
28 | + protected static $_instance = null; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * private constructor to prevent direct creation |
|
33 | + * |
|
34 | + * @param null $timezone |
|
35 | + * @throws EE_Error |
|
36 | + */ |
|
37 | + protected function __construct($timezone = null) |
|
38 | + { |
|
39 | + $this->singular_item = esc_html__('Payment Method', 'event_espresso'); |
|
40 | + $this->plural_item = esc_html__('Payment Methods', 'event_espresso'); |
|
41 | + $this->_tables = [ |
|
42 | + 'Payment_Method' => new EE_Primary_Table('esp_payment_method', 'PMD_ID'), |
|
43 | + ]; |
|
44 | + $this->_fields = [ |
|
45 | + 'Payment_Method' => [ |
|
46 | + 'PMD_ID' => new EE_Primary_Key_Int_Field( |
|
47 | + 'PMD_ID', |
|
48 | + esc_html__('ID', 'event_espresso') |
|
49 | + ), |
|
50 | + 'PMD_type' => new EE_Plain_Text_Field( |
|
51 | + 'PMD_type', |
|
52 | + esc_html__('Payment Method Type', 'event_espresso'), |
|
53 | + false, |
|
54 | + 'Admin_Only' |
|
55 | + ), |
|
56 | + 'PMD_name' => new EE_Plain_Text_Field( |
|
57 | + 'PMD_name', |
|
58 | + esc_html__('Name', 'event_espresso'), |
|
59 | + false |
|
60 | + ), |
|
61 | + 'PMD_desc' => new EE_Post_Content_Field( |
|
62 | + 'PMD_desc', |
|
63 | + esc_html__('Description', 'event_espresso'), |
|
64 | + false, |
|
65 | + '' |
|
66 | + ), |
|
67 | + 'PMD_admin_name' => new EE_Plain_Text_Field( |
|
68 | + 'PMD_admin_name', |
|
69 | + esc_html__('Admin-Only Name', 'event_espresso'), |
|
70 | + true |
|
71 | + ), |
|
72 | + 'PMD_admin_desc' => new EE_Post_Content_Field( |
|
73 | + 'PMD_admin_desc', |
|
74 | + esc_html__('Admin-Only Description', 'event_espresso'), |
|
75 | + true |
|
76 | + ), |
|
77 | + 'PMD_slug' => new EE_Slug_Field( |
|
78 | + 'PMD_slug', |
|
79 | + esc_html__('Slug', 'event_espresso'), |
|
80 | + false |
|
81 | + ), |
|
82 | + 'PMD_order' => new EE_Integer_Field( |
|
83 | + 'PMD_order', |
|
84 | + esc_html__('Order', 'event_espresso'), |
|
85 | + false, |
|
86 | + 0 |
|
87 | + ), |
|
88 | + 'PMD_debug_mode' => new EE_Boolean_Field( |
|
89 | + 'PMD_debug_mode', |
|
90 | + esc_html__('Debug Mode On?', 'event_espresso'), |
|
91 | + false, |
|
92 | + false |
|
93 | + ), |
|
94 | + 'PMD_wp_user' => new EE_WP_User_Field( |
|
95 | + 'PMD_wp_user', |
|
96 | + esc_html__('Payment Method Creator ID', 'event_espresso'), |
|
97 | + false |
|
98 | + ), |
|
99 | + 'PMD_open_by_default' => new EE_Boolean_Field( |
|
100 | + 'PMD_open_by_default', |
|
101 | + esc_html__('Open by Default?', 'event_espresso'), |
|
102 | + false, |
|
103 | + false |
|
104 | + ), |
|
105 | + 'PMD_button_url' => new EE_Plain_Text_Field( |
|
106 | + 'PMD_button_url', |
|
107 | + esc_html__('Button URL', 'event_espresso'), |
|
108 | + true, |
|
109 | + '' |
|
110 | + ), |
|
111 | + 'PMD_scope' => new EE_Serialized_Text_Field( |
|
112 | + 'PMD_scope', |
|
113 | + esc_html__('Usable From?', 'event_espresso'), |
|
114 | + false, |
|
115 | + []// possible values currently are 'CART','ADMIN','API' |
|
116 | + ), |
|
117 | + ], |
|
118 | + ]; |
|
119 | + $this->_model_relations = [ |
|
120 | + 'Payment' => new EE_Has_Many_Relation(), |
|
121 | + 'Currency' => new EE_HABTM_Relation('Currency_Payment_Method'), |
|
122 | + 'Transaction' => new EE_Has_Many_Relation(), |
|
123 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
124 | + ]; |
|
125 | + parent::__construct($timezone); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Gets one by the slug provided |
|
131 | + * |
|
132 | + * @param string $slug |
|
133 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
134 | + * @throws EE_Error |
|
135 | + */ |
|
136 | + public function get_one_by_slug($slug) |
|
137 | + { |
|
138 | + return $this->get_one([['PMD_slug' => $slug]]); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * Gets all the acceptable scopes for payment methods. |
|
144 | + * Keys are their names as store din the DB, and values are nice names for displaying them |
|
145 | + * |
|
146 | + * @return array |
|
147 | + */ |
|
148 | + public function scopes() |
|
149 | + { |
|
150 | + return apply_filters( |
|
151 | + 'FHEE__EEM_Payment_Method__scopes', |
|
152 | + [ |
|
153 | + EEM_Payment_Method::scope_cart => esc_html__('Front-end Registration Page', 'event_espresso'), |
|
154 | + EEM_Payment_Method::scope_admin => esc_html__( |
|
155 | + 'Admin Registration Page (no online processing)', |
|
156 | + 'event_espresso' |
|
157 | + ), |
|
158 | + ] |
|
159 | + ); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Determines if this is an valid scope |
|
165 | + * |
|
166 | + * @param string $scope like one of EEM_Payment_Method::instance()->scopes() |
|
167 | + * @return boolean |
|
168 | + */ |
|
169 | + public function is_valid_scope($scope) |
|
170 | + { |
|
171 | + $scopes = $this->scopes(); |
|
172 | + if (isset($scopes[ $scope ])) { |
|
173 | + return true; |
|
174 | + } |
|
175 | + return false; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Gets all active payment methods |
|
181 | + * |
|
182 | + * @param string $scope one of |
|
183 | + * @param array $query_params |
|
184 | + * @return EE_Base_Class[]|EE_Payment_Method[] |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public function get_all_active($scope = null, $query_params = []) |
|
188 | + { |
|
189 | + if (! isset($query_params['order_by']) && ! isset($query_params['order'])) { |
|
190 | + $query_params['order_by'] = ['PMD_order' => 'ASC', 'PMD_ID' => 'ASC']; |
|
191 | + } |
|
192 | + return $this->get_all($this->_get_query_params_for_all_active($scope, $query_params)); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * Counts all active gateways in the specified scope |
|
198 | + * |
|
199 | + * @param string $scope one of EEM_Payment_Method::scope_* |
|
200 | + * @param array $query_params |
|
201 | + * @return int |
|
202 | + * @throws EE_Error |
|
203 | + */ |
|
204 | + public function count_active($scope = null, $query_params = []) |
|
205 | + { |
|
206 | + return $this->count($this->_get_query_params_for_all_active($scope, $query_params)); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
212 | + * argument to get all active for a given scope |
|
213 | + * |
|
214 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
215 | + * @param array $query_params |
|
216 | + * @return array |
|
217 | + * @throws EE_Error |
|
218 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
219 | + */ |
|
220 | + protected function _get_query_params_for_all_active($scope = null, $query_params = []) |
|
221 | + { |
|
222 | + if ($scope) { |
|
223 | + if ($this->is_valid_scope($scope)) { |
|
224 | + return array_replace_recursive([['PMD_scope' => ['LIKE', "%$scope%"]]], $query_params); |
|
225 | + } |
|
226 | + throw new EE_Error( |
|
227 | + sprintf( |
|
228 | + esc_html__("'%s' is not a valid scope for a payment method", 'event_espresso'), |
|
229 | + $scope |
|
230 | + ) |
|
231 | + ); |
|
232 | + } |
|
233 | + $acceptable_scopes = []; |
|
234 | + $count = 0; |
|
235 | + foreach ($this->scopes() as $scope_name => $desc) { |
|
236 | + $count++; |
|
237 | + $acceptable_scopes[ 'PMD_scope*' . $count ] = ['LIKE', '%' . $scope_name . '%']; |
|
238 | + } |
|
239 | + return array_replace_recursive([['OR*active_scope' => $acceptable_scopes]], $query_params); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Creates the $query_params that can be passed into any EEM_Payment_Method as their $query_params |
|
245 | + * argument to get all active for a given scope |
|
246 | + * |
|
247 | + * @param string $scope one of the constants EEM_Payment_Method::scope_* |
|
248 | + * @param array $query_params |
|
249 | + * @return array |
|
250 | + * @throws EE_Error |
|
251 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
252 | + */ |
|
253 | + public function get_query_params_for_all_active($scope = null, $query_params = []) |
|
254 | + { |
|
255 | + return $this->_get_query_params_for_all_active($scope, $query_params); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Gets one active payment method. see @get_all_active for documentation |
|
261 | + * |
|
262 | + * @param string $scope |
|
263 | + * @param array $query_params |
|
264 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
265 | + * @throws EE_Error |
|
266 | + */ |
|
267 | + public function get_one_active($scope = null, $query_params = []) |
|
268 | + { |
|
269 | + return $this->get_one($this->_get_query_params_for_all_active($scope, $query_params)); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Gets one payment method of that type, regardless of whether its active or not |
|
275 | + * |
|
276 | + * @param string $type |
|
277 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|NULL |
|
278 | + * @throws EE_Error |
|
279 | + */ |
|
280 | + public function get_one_of_type($type) |
|
281 | + { |
|
282 | + return $this->get_one([['PMD_type' => $type]]); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Overrides parent ot also check by the slug |
|
288 | + * |
|
289 | + * @param string|int|EE_Payment_Method $base_class_obj_or_id |
|
290 | + * @param boolean $ensure_is_in_db |
|
291 | + * @return EE_Base_Class|EE_Payment_Method|EE_Soft_Delete_Base_Class|int|string |
|
292 | + * @throws EE_Error |
|
293 | + * @see EEM_Base::ensure_is_obj() |
|
294 | + */ |
|
295 | + public function ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db = false) |
|
296 | + { |
|
297 | + // first: check if it's a slug |
|
298 | + if (is_string($base_class_obj_or_id)) { |
|
299 | + $obj = $this->get_one_by_slug($base_class_obj_or_id); |
|
300 | + if ($obj) { |
|
301 | + return $obj; |
|
302 | + } |
|
303 | + } |
|
304 | + // ok so it wasn't a slug we were passed. try the usual then (ie, it's an object or an ID) |
|
305 | + try { |
|
306 | + return parent::ensure_is_obj($base_class_obj_or_id, $ensure_is_in_db); |
|
307 | + } catch (EE_Error $e) { |
|
308 | + // handle it outside the catch |
|
309 | + } |
|
310 | + throw new EE_Error( |
|
311 | + sprintf( |
|
312 | + esc_html__("'%s' is neither a Payment Method ID, slug, nor object.", 'event_espresso'), |
|
313 | + $base_class_obj_or_id |
|
314 | + ) |
|
315 | + ); |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Gets the ID of this object, or if its a string finds the object's id |
|
321 | + * associated with that slug |
|
322 | + * |
|
323 | + * @param mixed $base_obj_or_id_or_slug |
|
324 | + * @return int |
|
325 | + * @throws EE_Error |
|
326 | + */ |
|
327 | + public function ensure_is_ID($base_obj_or_id_or_slug) |
|
328 | + { |
|
329 | + if (is_string($base_obj_or_id_or_slug)) { |
|
330 | + // assume it's a slug |
|
331 | + $base_obj_or_id_or_slug = $this->get_one_by_slug($base_obj_or_id_or_slug); |
|
332 | + } |
|
333 | + return parent::ensure_is_ID($base_obj_or_id_or_slug); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Verifies the button urls on all the passed payment methods have a valid button url. |
|
339 | + * If not, resets them to their default. |
|
340 | + * |
|
341 | + * @param EE_Payment_Method[] $payment_methods if NULL, defaults to all payment methods active in the cart |
|
342 | + * @throws EE_Error |
|
343 | + * @throws ReflectionException |
|
344 | + */ |
|
345 | + public function verify_button_urls($payment_methods = null) |
|
346 | + { |
|
347 | + $payment_methods = is_array($payment_methods) |
|
348 | + ? $payment_methods |
|
349 | + : $this->get_all_active(EEM_Payment_Method::scope_cart); |
|
350 | + foreach ($payment_methods as $payment_method) { |
|
351 | + try { |
|
352 | + // If there is really no button URL at all, or if the button URLs still point to decaf folder even |
|
353 | + // though this is a caffeinated install, reset it to the default. |
|
354 | + $current_button_url = $payment_method->button_url(); |
|
355 | + if ( |
|
356 | + empty($current_button_url) |
|
357 | + || ( |
|
358 | + strpos($current_button_url, 'decaf') !== false |
|
359 | + && strpos($payment_method->type_obj()->default_button_url(), 'decaf') === false |
|
360 | + ) |
|
361 | + ) { |
|
362 | + $payment_method->save( |
|
363 | + [ |
|
364 | + 'PMD_button_url' => $payment_method->type_obj()->default_button_url(), |
|
365 | + ] |
|
366 | + ); |
|
367 | + } |
|
368 | + } catch (EE_Error $e) { |
|
369 | + $payment_method->deactivate(); |
|
370 | + } |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Overrides parent to not only turn wpdb results into EE_Payment_Method objects, |
|
377 | + * but also verifies the payment method type of each is a usable object. If not, |
|
378 | + * deactivate it, sets a notification, and deactivates it |
|
379 | + * |
|
380 | + * @param array $rows |
|
381 | + * @return EE_Payment_Method[] |
|
382 | + * @throws EE_Error |
|
383 | + * @throws InvalidDataTypeException |
|
384 | + * @throws ReflectionException |
|
385 | + */ |
|
386 | + protected function _create_objects($rows = []) |
|
387 | + { |
|
388 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
389 | + $payment_methods = parent::_create_objects($rows); |
|
390 | + /* @var $payment_methods EE_Payment_Method[] */ |
|
391 | + $usable_payment_methods = []; |
|
392 | + foreach ($payment_methods as $key => $payment_method) { |
|
393 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($payment_method->type())) { |
|
394 | + $usable_payment_methods[ $key ] = $payment_method; |
|
395 | + // some payment methods enqueue their scripts in EE_PMT_*::__construct |
|
396 | + // which is kinda a no-no (just because it's being constructed doesn't mean we need to enqueue |
|
397 | + // its scripts). but for backwards-compat we should continue to do that |
|
398 | + $payment_method->type_obj(); |
|
399 | + } elseif ($payment_method->active()) { |
|
400 | + // only deactivate and notify the admin if the payment is active somewhere |
|
401 | + $payment_method->deactivate(); |
|
402 | + $payment_method->save(); |
|
403 | + do_action( |
|
404 | + 'AHEE__EEM_Payment_Method___create_objects_auto_deactivated_payment_method', |
|
405 | + $payment_method |
|
406 | + ); |
|
407 | + new PersistentAdminNotice( |
|
408 | + 'auto-deactivated-' . $payment_method->type(), |
|
409 | + sprintf( |
|
410 | + esc_html__( |
|
411 | + 'The payment method %1$s was automatically deactivated because it appears its associated Event Espresso Addon was recently deactivated.%2$sIt can be reactivated on the %3$sPlugins admin page%4$s, then you can reactivate the payment method.', |
|
412 | + 'event_espresso' |
|
413 | + ), |
|
414 | + $payment_method->admin_name(), |
|
415 | + '<br />', |
|
416 | + '<a href="' . admin_url('plugins.php') . '">', |
|
417 | + '</a>' |
|
418 | + ), |
|
419 | + true |
|
420 | + ); |
|
421 | + } |
|
422 | + } |
|
423 | + return $usable_payment_methods; |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Gets all the payment methods which can be used for transaction |
|
429 | + * (according to the relations between payment methods and events, and |
|
430 | + * the currencies used for the transaction and their relation to payment methods) |
|
431 | + * |
|
432 | + * @param EE_Transaction $transaction |
|
433 | + * @param string $scope @see EEM_Payment_Method::get_all_for_events |
|
434 | + * @return EE_Payment_Method[] |
|
435 | + * @throws EE_Error |
|
436 | + */ |
|
437 | + public function get_all_for_transaction($transaction, $scope) |
|
438 | + { |
|
439 | + // give addons a chance to override what payment methods are chosen based on the transaction |
|
440 | + return apply_filters( |
|
441 | + 'FHEE__EEM_Payment_Method__get_all_for_transaction__payment_methods', |
|
442 | + $this->get_all_active($scope, ['group_by' => 'PMD_type']), |
|
443 | + $transaction, |
|
444 | + $scope |
|
445 | + ); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * Returns the payment method used for the last payment made for a registration. |
|
451 | + * Note: if an offline payment method was selected on the related transaction then this will have no payment |
|
452 | + * methods returned. It will ONLY return a payment method for a PAYMENT recorded against the registration. |
|
453 | + * |
|
454 | + * @param EE_Registration|int $registration_or_reg_id Either the EE_Registration object or the id for the |
|
455 | + * registration. |
|
456 | + * @return EE_Payment|null |
|
457 | + * @throws EE_Error |
|
458 | + */ |
|
459 | + public function get_last_used_for_registration($registration_or_reg_id) |
|
460 | + { |
|
461 | + $registration_id = EEM_Registration::instance()->ensure_is_ID($registration_or_reg_id); |
|
462 | + |
|
463 | + $query_params = [ |
|
464 | + 0 => [ |
|
465 | + 'Payment.Registration.REG_ID' => $registration_id, |
|
466 | + ], |
|
467 | + 'order_by' => ['Payment.PAY_ID' => 'DESC'], |
|
468 | + ]; |
|
469 | + return $this->get_one($query_params); |
|
470 | + } |
|
471 | 471 | } |