@@ -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 | } |
@@ -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 | } |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
58 | 58 | ]; |
59 | 59 | $path_to_event = 'Event'; |
60 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
60 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
61 | 61 | $path_to_event |
62 | 62 | ); |
63 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
63 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected( |
|
64 | 64 | $path_to_event |
65 | 65 | ); |
66 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
66 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
67 | 67 | $path_to_event |
68 | 68 | ); |
69 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
69 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected( |
|
70 | 70 | $path_to_event, |
71 | 71 | EEM_Base::caps_edit |
72 | 72 | ); |
@@ -115,10 +115,10 @@ discard block |
||
115 | 115 | } |
116 | 116 | |
117 | 117 | $where = []; |
118 | - if (! empty($GRP_IDs)) { |
|
118 | + if ( ! empty($GRP_IDs)) { |
|
119 | 119 | $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
120 | 120 | } |
121 | - if (! empty($EVT_IDs)) { |
|
121 | + if ( ! empty($EVT_IDs)) { |
|
122 | 122 | $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
123 | 123 | } |
124 | 124 |
@@ -11,116 +11,116 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Event_Message_Template extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the EEM_Event_Message_Template object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Event_Message_Template object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * protected constructor to prevent direct creation |
|
20 | - * |
|
21 | - * @param null $timezone |
|
22 | - * @throws EE_Error |
|
23 | - */ |
|
24 | - protected function __construct($timezone = null) |
|
25 | - { |
|
26 | - $this->singular_item = esc_html__('Event Message Template', 'event_espresso'); |
|
27 | - $this->plural_item = esc_html__('Event Message Templates', 'event_espresso'); |
|
18 | + /** |
|
19 | + * protected constructor to prevent direct creation |
|
20 | + * |
|
21 | + * @param null $timezone |
|
22 | + * @throws EE_Error |
|
23 | + */ |
|
24 | + protected function __construct($timezone = null) |
|
25 | + { |
|
26 | + $this->singular_item = esc_html__('Event Message Template', 'event_espresso'); |
|
27 | + $this->plural_item = esc_html__('Event Message Templates', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = [ |
|
30 | - 'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'), |
|
31 | - ]; |
|
32 | - $this->_fields = [ |
|
33 | - 'Event_Message_Template' => [ |
|
34 | - 'EMT_ID' => new EE_Primary_Key_Int_Field( |
|
35 | - 'EMT_ID', |
|
36 | - esc_html__('Event Message Template ID', 'event_espresso') |
|
37 | - ), |
|
38 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
39 | - 'EVT_ID', |
|
40 | - esc_html__('The ID to the Event', 'event_espresso'), |
|
41 | - false, |
|
42 | - 0, |
|
43 | - 'Event' |
|
44 | - ), |
|
45 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | - 'GRP_ID', |
|
47 | - esc_html__('The ID to the Message Template Group', 'event_espresso'), |
|
48 | - false, |
|
49 | - 0, |
|
50 | - 'Message_Template_Group' |
|
51 | - ), |
|
52 | - ], |
|
53 | - ]; |
|
54 | - $this->_model_relations = [ |
|
55 | - 'Event' => new EE_Belongs_To_Relation(), |
|
56 | - 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
57 | - ]; |
|
58 | - $path_to_event = 'Event'; |
|
59 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
60 | - $path_to_event |
|
61 | - ); |
|
62 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
63 | - $path_to_event |
|
64 | - ); |
|
65 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
66 | - $path_to_event |
|
67 | - ); |
|
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
69 | - $path_to_event, |
|
70 | - EEM_Base::caps_edit |
|
71 | - ); |
|
72 | - parent::__construct($timezone); |
|
73 | - } |
|
29 | + $this->_tables = [ |
|
30 | + 'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'), |
|
31 | + ]; |
|
32 | + $this->_fields = [ |
|
33 | + 'Event_Message_Template' => [ |
|
34 | + 'EMT_ID' => new EE_Primary_Key_Int_Field( |
|
35 | + 'EMT_ID', |
|
36 | + esc_html__('Event Message Template ID', 'event_espresso') |
|
37 | + ), |
|
38 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
39 | + 'EVT_ID', |
|
40 | + esc_html__('The ID to the Event', 'event_espresso'), |
|
41 | + false, |
|
42 | + 0, |
|
43 | + 'Event' |
|
44 | + ), |
|
45 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | + 'GRP_ID', |
|
47 | + esc_html__('The ID to the Message Template Group', 'event_espresso'), |
|
48 | + false, |
|
49 | + 0, |
|
50 | + 'Message_Template_Group' |
|
51 | + ), |
|
52 | + ], |
|
53 | + ]; |
|
54 | + $this->_model_relations = [ |
|
55 | + 'Event' => new EE_Belongs_To_Relation(), |
|
56 | + 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
57 | + ]; |
|
58 | + $path_to_event = 'Event'; |
|
59 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
60 | + $path_to_event |
|
61 | + ); |
|
62 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
63 | + $path_to_event |
|
64 | + ); |
|
65 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
66 | + $path_to_event |
|
67 | + ); |
|
68 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
69 | + $path_to_event, |
|
70 | + EEM_Base::caps_edit |
|
71 | + ); |
|
72 | + parent::__construct($timezone); |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * helper method to simply return an array of event ids for events attached to the given |
|
78 | - * message template group. |
|
79 | - * |
|
80 | - * @param int $GRP_ID The MTP group we want attached events for. |
|
81 | - * @return array An array of event ids. |
|
82 | - * @throws EE_Error |
|
83 | - * @since 4.3.0 |
|
84 | - */ |
|
85 | - public function get_attached_event_ids($GRP_ID) |
|
86 | - { |
|
87 | - $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID'); |
|
88 | - $event_ids = call_user_func_array('array_merge', $event_ids); |
|
89 | - return $event_ids; |
|
90 | - } |
|
76 | + /** |
|
77 | + * helper method to simply return an array of event ids for events attached to the given |
|
78 | + * message template group. |
|
79 | + * |
|
80 | + * @param int $GRP_ID The MTP group we want attached events for. |
|
81 | + * @return array An array of event ids. |
|
82 | + * @throws EE_Error |
|
83 | + * @since 4.3.0 |
|
84 | + */ |
|
85 | + public function get_attached_event_ids($GRP_ID) |
|
86 | + { |
|
87 | + $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID'); |
|
88 | + $event_ids = call_user_func_array('array_merge', $event_ids); |
|
89 | + return $event_ids; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * helper method for clearing event/group relations for the given event ids and grp ids. |
|
95 | - * |
|
96 | - * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs. |
|
97 | - * @param array $EVT_IDs An array of EVT_IDs. Optional. If empty then there must be GRP IDs. |
|
98 | - * @return int How many rows were deleted. |
|
99 | - * @throws EE_Error |
|
100 | - * @throws EE_Error |
|
101 | - */ |
|
102 | - public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = []) |
|
103 | - { |
|
104 | - if (empty($GRP_IDs) && empty($EVT_IDs)) { |
|
105 | - throw new EE_Error( |
|
106 | - sprintf( |
|
107 | - esc_html__( |
|
108 | - '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', |
|
109 | - 'event_espresso' |
|
110 | - ), |
|
111 | - __METHOD__ |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
93 | + /** |
|
94 | + * helper method for clearing event/group relations for the given event ids and grp ids. |
|
95 | + * |
|
96 | + * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs. |
|
97 | + * @param array $EVT_IDs An array of EVT_IDs. Optional. If empty then there must be GRP IDs. |
|
98 | + * @return int How many rows were deleted. |
|
99 | + * @throws EE_Error |
|
100 | + * @throws EE_Error |
|
101 | + */ |
|
102 | + public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = []) |
|
103 | + { |
|
104 | + if (empty($GRP_IDs) && empty($EVT_IDs)) { |
|
105 | + throw new EE_Error( |
|
106 | + sprintf( |
|
107 | + esc_html__( |
|
108 | + '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.', |
|
109 | + 'event_espresso' |
|
110 | + ), |
|
111 | + __METHOD__ |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | 115 | |
116 | - $where = []; |
|
117 | - if (! empty($GRP_IDs)) { |
|
118 | - $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
|
119 | - } |
|
120 | - if (! empty($EVT_IDs)) { |
|
121 | - $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
|
122 | - } |
|
116 | + $where = []; |
|
117 | + if (! empty($GRP_IDs)) { |
|
118 | + $where['GRP_ID'] = ['IN', (array) $GRP_IDs]; |
|
119 | + } |
|
120 | + if (! empty($EVT_IDs)) { |
|
121 | + $where['EVT_ID'] = ['IN', (array) $EVT_IDs]; |
|
122 | + } |
|
123 | 123 | |
124 | - return $this->delete([$where], false); |
|
125 | - } |
|
124 | + return $this->delete([$where], false); |
|
125 | + } |
|
126 | 126 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + if ( ! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | 42 | /** |
43 | 43 | * espresso_duplicate_plugin_error |
44 | 44 | * displays if more than one version of EE is activated at the same time |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
63 | 63 | } else { |
64 | 64 | define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | 66 | /** |
67 | 67 | * espresso_minimum_php_version_error |
68 | 68 | * |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | |
117 | 117 | register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
119 | + require_once __DIR__.'/core/bootstrap_espresso.php'; |
|
120 | 120 | bootstrap_espresso(); |
121 | 121 | } |
122 | 122 | } |
123 | -if (! function_exists('espresso_deactivate_plugin')) { |
|
123 | +if ( ! function_exists('espresso_deactivate_plugin')) { |
|
124 | 124 | /** |
125 | 125 | * deactivate_plugin |
126 | 126 | * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | */ |
132 | 132 | function espresso_deactivate_plugin($plugin_basename = '') |
133 | 133 | { |
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
134 | + if ( ! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
136 | 136 | } |
137 | 137 | unset($_GET['activate'], $_REQUEST['activate']); |
138 | 138 | deactivate_plugins($plugin_basename); |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.6.2'); |
|
65 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.39.rc.018'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.39.rc.018'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |