@@ -16,208 +16,208 @@ |
||
16 | 16 | class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * extending the properties set in espresso_events_Registration_From_Hooks |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - protected function _extend_properties() |
|
26 | - { |
|
27 | - $this->_metaboxes = array_merge( |
|
28 | - $this->_metaboxes, |
|
29 | - array( |
|
30 | - 1 => array( |
|
31 | - 'page_route' => array('create_new', 'edit'), |
|
32 | - 'func' => 'additional_questions', |
|
33 | - 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
34 | - 'priority' => 'default', |
|
35 | - 'context' => 'side', |
|
36 | - ), |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_scripts_styles = array( |
|
40 | - 'registers' => array( |
|
41 | - 'extended-event-editor' => array( |
|
42 | - 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
43 | - . 'registration_form/assets/event-editor-question-groups.js', |
|
44 | - 'depends' => array('jquery'), |
|
45 | - ), |
|
46 | - ), |
|
47 | - 'enqueues' => array( |
|
48 | - 'extended-event-editor' => array('edit', 'create_new'), |
|
49 | - ), |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param Callable[] $callbacks |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function modify_callbacks($callbacks) |
|
59 | - { |
|
60 | - $callbacks = parent::modify_callbacks($callbacks); |
|
61 | - $callbacks[] = array($this, 'additional_question_group_update'); |
|
62 | - return $callbacks; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Call back hooked into revision restores. |
|
68 | - * |
|
69 | - * @param $post_id |
|
70 | - * @param $revision_id |
|
71 | - * @return EE_Base_Class|void |
|
72 | - * @throws EE_Error |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws InvalidDataTypeException |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws ReflectionException |
|
77 | - */ |
|
78 | - public function restore_revision($post_id, $revision_id) |
|
79 | - { |
|
80 | - $post_evt = parent::restore_revision($post_id, $revision_id); |
|
81 | - |
|
82 | - // restore revision for additional questions |
|
83 | - $post_evt->restore_revision( |
|
84 | - $revision_id, |
|
85 | - ['Question_Group'], |
|
86 | - [ |
|
87 | - 'Question_Group' => ['Event_Question_Group.EQG_additional' => true], |
|
88 | - ] |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param $post_id |
|
95 | - * @param $post |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - */ |
|
101 | - public function additional_questions($post_id, $post) |
|
102 | - { |
|
103 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | - $event_id = $this->_event->ID(); |
|
105 | - ?> |
|
19 | + /** |
|
20 | + * extending the properties set in espresso_events_Registration_From_Hooks |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + protected function _extend_properties() |
|
26 | + { |
|
27 | + $this->_metaboxes = array_merge( |
|
28 | + $this->_metaboxes, |
|
29 | + array( |
|
30 | + 1 => array( |
|
31 | + 'page_route' => array('create_new', 'edit'), |
|
32 | + 'func' => 'additional_questions', |
|
33 | + 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
34 | + 'priority' => 'default', |
|
35 | + 'context' => 'side', |
|
36 | + ), |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_scripts_styles = array( |
|
40 | + 'registers' => array( |
|
41 | + 'extended-event-editor' => array( |
|
42 | + 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
43 | + . 'registration_form/assets/event-editor-question-groups.js', |
|
44 | + 'depends' => array('jquery'), |
|
45 | + ), |
|
46 | + ), |
|
47 | + 'enqueues' => array( |
|
48 | + 'extended-event-editor' => array('edit', 'create_new'), |
|
49 | + ), |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param Callable[] $callbacks |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function modify_callbacks($callbacks) |
|
59 | + { |
|
60 | + $callbacks = parent::modify_callbacks($callbacks); |
|
61 | + $callbacks[] = array($this, 'additional_question_group_update'); |
|
62 | + return $callbacks; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Call back hooked into revision restores. |
|
68 | + * |
|
69 | + * @param $post_id |
|
70 | + * @param $revision_id |
|
71 | + * @return EE_Base_Class|void |
|
72 | + * @throws EE_Error |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws InvalidDataTypeException |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws ReflectionException |
|
77 | + */ |
|
78 | + public function restore_revision($post_id, $revision_id) |
|
79 | + { |
|
80 | + $post_evt = parent::restore_revision($post_id, $revision_id); |
|
81 | + |
|
82 | + // restore revision for additional questions |
|
83 | + $post_evt->restore_revision( |
|
84 | + $revision_id, |
|
85 | + ['Question_Group'], |
|
86 | + [ |
|
87 | + 'Question_Group' => ['Event_Question_Group.EQG_additional' => true], |
|
88 | + ] |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param $post_id |
|
95 | + * @param $post |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + */ |
|
101 | + public function additional_questions($post_id, $post) |
|
102 | + { |
|
103 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | + $event_id = $this->_event->ID(); |
|
105 | + ?> |
|
106 | 106 | <div class="inside"> |
107 | 107 | <p><strong> |
108 | 108 | <?php _e('Question Groups', 'event_espresso'); ?> |
109 | 109 | </strong><br/> |
110 | 110 | <?php |
111 | - printf( |
|
112 | - esc_html__( |
|
113 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | - '</a>' |
|
118 | - ); |
|
119 | - ?> |
|
111 | + printf( |
|
112 | + esc_html__( |
|
113 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | + '</a>' |
|
118 | + ); |
|
119 | + ?> |
|
120 | 120 | </p> |
121 | 121 | <?php |
122 | 122 | |
123 | - $qsg_where['QSG_deleted'] = false; |
|
124 | - $query_params = apply_filters( |
|
125 | - 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | - ); |
|
128 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | - $EQGs = ! empty($event_id) |
|
130 | - ? $this->_event->get_many_related( |
|
131 | - 'Question_Group', |
|
132 | - [['Event_Question_Group.EQG_additional' => true]] |
|
133 | - ) |
|
134 | - : []; |
|
135 | - $EQGids = array_keys($EQGs); |
|
136 | - |
|
137 | - if (! empty($QSGs)) { |
|
138 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | - foreach ($QSGs as $QSG) { |
|
140 | - $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | - array( |
|
143 | - 'action' => 'edit_question_group', |
|
144 | - 'QSG_ID' => $QSG->ID(), |
|
145 | - ), |
|
146 | - EE_FORMS_ADMIN_URL |
|
147 | - ); |
|
148 | - |
|
149 | - $html .= ' |
|
123 | + $qsg_where['QSG_deleted'] = false; |
|
124 | + $query_params = apply_filters( |
|
125 | + 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | + ); |
|
128 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | + $EQGs = ! empty($event_id) |
|
130 | + ? $this->_event->get_many_related( |
|
131 | + 'Question_Group', |
|
132 | + [['Event_Question_Group.EQG_additional' => true]] |
|
133 | + ) |
|
134 | + : []; |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | + |
|
137 | + if (! empty($QSGs)) { |
|
138 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | + foreach ($QSGs as $QSG) { |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | + array( |
|
143 | + 'action' => 'edit_question_group', |
|
144 | + 'QSG_ID' => $QSG->ID(), |
|
145 | + ), |
|
146 | + EE_FORMS_ADMIN_URL |
|
147 | + ); |
|
148 | + |
|
149 | + $html .= ' |
|
150 | 150 | <p id="event-question-group-' . $QSG->ID() . '"> |
151 | 151 | <input value="' . $QSG->ID() . '"' |
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | 153 | <a href="' . $edit_link . '" title="' |
154 | - . sprintf( |
|
155 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | - $QSG->get('QSG_name') |
|
157 | - ) |
|
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
154 | + . sprintf( |
|
155 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | + $QSG->get('QSG_name') |
|
157 | + ) |
|
158 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
159 | 159 | </p>'; |
160 | - if ($QSG->ID() === 2) { |
|
161 | - $html .= ' |
|
160 | + if ($QSG->ID() === 2) { |
|
161 | + $html .= ' |
|
162 | 162 | <p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">' |
163 | - . esc_html__( |
|
164 | - 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | - 'event_espresso' |
|
166 | - ) |
|
167 | - . '</p>'; |
|
168 | - } |
|
169 | - } |
|
170 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | - |
|
172 | - echo $html; |
|
173 | - } else { |
|
174 | - esc_html_e( |
|
175 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | - 'event_espresso' |
|
177 | - ); |
|
178 | - } |
|
179 | - do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
180 | - ?> |
|
163 | + . esc_html__( |
|
164 | + 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | + 'event_espresso' |
|
166 | + ) |
|
167 | + . '</p>'; |
|
168 | + } |
|
169 | + } |
|
170 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | + |
|
172 | + echo $html; |
|
173 | + } else { |
|
174 | + esc_html_e( |
|
175 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | + 'event_espresso' |
|
177 | + ); |
|
178 | + } |
|
179 | + do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
180 | + ?> |
|
181 | 181 | </div> |
182 | 182 | <?php |
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - public function additional_question_group_update($evtobj, $data) |
|
187 | - { |
|
188 | - $question_groups = ! empty($data['add_attendee_question_groups']) |
|
189 | - ? (array) $data['add_attendee_question_groups'] |
|
190 | - : []; |
|
191 | - $added_qgs = array_keys($question_groups); |
|
192 | - $success = []; |
|
193 | - |
|
194 | - // let's get all current question groups associated with this event. |
|
195 | - $current_qgs = $evtobj->get_many_related( |
|
196 | - 'Question_Group', |
|
197 | - [['Event_Question_Group.EQG_additional' => true]] |
|
198 | - ); |
|
199 | - $current_qgs = array_keys($current_qgs); // we just want the ids |
|
200 | - |
|
201 | - // now let's get the groups selected in the editor and update (IF we have data) |
|
202 | - if (! empty($question_groups)) { |
|
203 | - foreach ($question_groups as $qgid) { |
|
204 | - // add to event |
|
205 | - if ($qgid) { |
|
206 | - $qg = $evtobj->add_question_group($qgid, false); |
|
207 | - } |
|
208 | - $success[] = ! empty($qg) ? 1 : 0; |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
213 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
214 | - |
|
215 | - foreach ($removed_qgs as $qgid) { |
|
216 | - $qg = $evtobj->remove_question_group($qgid, false); |
|
217 | - $success[] = ! empty($qg) ? 1 : 0; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - return in_array(0, $success, true) ? false : true; |
|
222 | - } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + public function additional_question_group_update($evtobj, $data) |
|
187 | + { |
|
188 | + $question_groups = ! empty($data['add_attendee_question_groups']) |
|
189 | + ? (array) $data['add_attendee_question_groups'] |
|
190 | + : []; |
|
191 | + $added_qgs = array_keys($question_groups); |
|
192 | + $success = []; |
|
193 | + |
|
194 | + // let's get all current question groups associated with this event. |
|
195 | + $current_qgs = $evtobj->get_many_related( |
|
196 | + 'Question_Group', |
|
197 | + [['Event_Question_Group.EQG_additional' => true]] |
|
198 | + ); |
|
199 | + $current_qgs = array_keys($current_qgs); // we just want the ids |
|
200 | + |
|
201 | + // now let's get the groups selected in the editor and update (IF we have data) |
|
202 | + if (! empty($question_groups)) { |
|
203 | + foreach ($question_groups as $qgid) { |
|
204 | + // add to event |
|
205 | + if ($qgid) { |
|
206 | + $qg = $evtobj->add_question_group($qgid, false); |
|
207 | + } |
|
208 | + $success[] = ! empty($qg) ? 1 : 0; |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
213 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
214 | + |
|
215 | + foreach ($removed_qgs as $qgid) { |
|
216 | + $qg = $evtobj->remove_question_group($qgid, false); |
|
217 | + $success[] = ! empty($qg) ? 1 : 0; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + return in_array(0, $success, true) ? false : true; |
|
222 | + } |
|
223 | 223 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | : []; |
135 | 135 | $EQGids = array_keys($EQGs); |
136 | 136 | |
137 | - if (! empty($QSGs)) { |
|
137 | + if ( ! empty($QSGs)) { |
|
138 | 138 | $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
139 | 139 | foreach ($QSGs as $QSG) { |
140 | 140 | $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | ); |
148 | 148 | |
149 | 149 | $html .= ' |
150 | - <p id="event-question-group-' . $QSG->ID() . '"> |
|
151 | - <input value="' . $QSG->ID() . '"' |
|
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | - <a href="' . $edit_link . '" title="' |
|
150 | + <p id="event-question-group-' . $QSG->ID().'"> |
|
151 | + <input value="' . $QSG->ID().'"' |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups['.$QSG->ID().']"'.$checked.' /> |
|
153 | + <a href="' . $edit_link.'" title="' |
|
154 | 154 | . sprintf( |
155 | 155 | esc_attr__('Edit %s Group', 'event_espresso'), |
156 | 156 | $QSG->get('QSG_name') |
157 | 157 | ) |
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
158 | + . '" target="_blank">'.$QSG->get('QSG_name').'</a> |
|
159 | 159 | </p>'; |
160 | 160 | if ($QSG->ID() === 2) { |
161 | 161 | $html .= ' |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $current_qgs = array_keys($current_qgs); // we just want the ids |
200 | 200 | |
201 | 201 | // now let's get the groups selected in the editor and update (IF we have data) |
202 | - if (! empty($question_groups)) { |
|
202 | + if ( ! empty($question_groups)) { |
|
203 | 203 | foreach ($question_groups as $qgid) { |
204 | 204 | // add to event |
205 | 205 | if ($qgid) { |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | 'WP_User' => new EE_Belongs_To_Relation(), |
279 | 279 | ); |
280 | 280 | // this model is generally available for reading |
281 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
281 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
282 | 282 | $this->model_chain_to_password = ''; |
283 | 283 | parent::__construct($timezone); |
284 | 284 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function get_all_event_question_groups($EVT_ID = 0) |
373 | 373 | { |
374 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
374 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
375 | 375 | EE_Error::add_error( |
376 | 376 | esc_html__( |
377 | 377 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
407 | 407 | { |
408 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
408 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
409 | 409 | EE_Error::add_error( |
410 | 410 | esc_html__( |
411 | 411 | // @codingStandardsIgnoreStart |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | */ |
449 | 449 | public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
450 | 450 | { |
451 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
451 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
452 | 452 | EE_Error::add_error( |
453 | 453 | esc_html__( |
454 | 454 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -861,11 +861,11 @@ discard block |
||
861 | 861 | $questions = array(); |
862 | 862 | // get all question groups for event |
863 | 863 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
864 | - if (! empty($qgs)) { |
|
864 | + if ( ! empty($qgs)) { |
|
865 | 865 | foreach ($qgs as $qg) { |
866 | 866 | $qsts = $qg->questions(); |
867 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
868 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
867 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
868 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
869 | 869 | foreach ($qsts as $qst) { |
870 | 870 | if ($qst->is_system_question()) { |
871 | 871 | continue; |
@@ -879,26 +879,26 @@ discard block |
||
879 | 879 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
880 | 880 | $qst_name = $qstn_id = $qst->ID(); |
881 | 881 | $ans_id = $answer->ID(); |
882 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
882 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
883 | 883 | $input_name = ''; |
884 | 884 | $input_id = sanitize_key($qst->display_text()); |
885 | 885 | $input_class = ''; |
886 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
887 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
886 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
887 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
888 | 888 | . $input_name |
889 | 889 | . $qst_name; |
890 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
891 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
893 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
894 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
890 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
891 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
892 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
893 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
894 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
895 | 895 | // leave responses as-is, don't convert stuff into html entities please! |
896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
896 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
897 | 897 | if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
898 | 898 | $QSOs = $qst->options(true, $answer->value()); |
899 | 899 | if (is_array($QSOs)) { |
900 | 900 | foreach ($QSOs as $QSO_ID => $QSO) { |
901 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
901 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
902 | 902 | } |
903 | 903 | } |
904 | 904 | } |
@@ -14,924 +14,924 @@ |
||
14 | 14 | class EEM_Event extends EEM_CPT_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
19 | - * event |
|
20 | - */ |
|
21 | - const sold_out = 'sold_out'; |
|
22 | - |
|
23 | - /** |
|
24 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
25 | - * date) |
|
26 | - */ |
|
27 | - const postponed = 'postponed'; |
|
28 | - |
|
29 | - /** |
|
30 | - * constant used by status(), indicating that the event will no longer occur |
|
31 | - */ |
|
32 | - const cancelled = 'cancelled'; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected static $_default_reg_status; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * This is the default for the additional limit field. |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected static $_default_additional_limit = 10; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * private instance of the Event object |
|
50 | - * |
|
51 | - * @var EEM_Event |
|
52 | - */ |
|
53 | - protected static $_instance; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
58 | - * |
|
59 | - * @param string $timezone |
|
60 | - * @throws EE_Error |
|
61 | - * @throws ReflectionException |
|
62 | - */ |
|
63 | - protected function __construct($timezone = null) |
|
64 | - { |
|
65 | - EE_Registry::instance()->load_model('Registration'); |
|
66 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
67 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
68 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
69 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
70 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
71 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
72 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
73 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
74 | - $this->_custom_stati = apply_filters( |
|
75 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
76 | - array( |
|
77 | - EEM_Event::cancelled => array( |
|
78 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
79 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
80 | - ), |
|
81 | - EEM_Event::postponed => array( |
|
82 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
83 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
84 | - ), |
|
85 | - EEM_Event::sold_out => array( |
|
86 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
87 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
88 | - ), |
|
89 | - ) |
|
90 | - ); |
|
91 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
92 | - : self::$_default_reg_status; |
|
93 | - $this->_tables = array( |
|
94 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
95 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
96 | - ); |
|
97 | - $this->_fields = array( |
|
98 | - 'Event_CPT' => array( |
|
99 | - 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
100 | - 'ID', |
|
101 | - esc_html__('Post ID for Event', 'event_espresso') |
|
102 | - ), |
|
103 | - 'EVT_name' => new EE_Plain_Text_Field( |
|
104 | - 'post_title', |
|
105 | - esc_html__('Event Name', 'event_espresso'), |
|
106 | - false, |
|
107 | - '' |
|
108 | - ), |
|
109 | - 'EVT_desc' => new EE_Post_Content_Field( |
|
110 | - 'post_content', |
|
111 | - esc_html__('Event Description', 'event_espresso'), |
|
112 | - false, |
|
113 | - '' |
|
114 | - ), |
|
115 | - 'EVT_slug' => new EE_Slug_Field( |
|
116 | - 'post_name', |
|
117 | - esc_html__('Event Slug', 'event_espresso'), |
|
118 | - false, |
|
119 | - '' |
|
120 | - ), |
|
121 | - 'EVT_created' => new EE_Datetime_Field( |
|
122 | - 'post_date', |
|
123 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
124 | - false, |
|
125 | - EE_Datetime_Field::now |
|
126 | - ), |
|
127 | - 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
128 | - 'post_excerpt', |
|
129 | - esc_html__('Event Short Description', 'event_espresso'), |
|
130 | - false, |
|
131 | - '' |
|
132 | - ), |
|
133 | - 'EVT_modified' => new EE_Datetime_Field( |
|
134 | - 'post_modified', |
|
135 | - esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
136 | - false, |
|
137 | - EE_Datetime_Field::now |
|
138 | - ), |
|
139 | - 'EVT_wp_user' => new EE_WP_User_Field( |
|
140 | - 'post_author', |
|
141 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
142 | - false |
|
143 | - ), |
|
144 | - 'parent' => new EE_Integer_Field( |
|
145 | - 'post_parent', |
|
146 | - esc_html__('Event Parent ID', 'event_espresso'), |
|
147 | - false, |
|
148 | - 0 |
|
149 | - ), |
|
150 | - 'EVT_order' => new EE_Integer_Field( |
|
151 | - 'menu_order', |
|
152 | - esc_html__('Event Menu Order', 'event_espresso'), |
|
153 | - false, |
|
154 | - 1 |
|
155 | - ), |
|
156 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
157 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
158 | - 'status' => new EE_WP_Post_Status_Field( |
|
159 | - 'post_status', |
|
160 | - esc_html__('Event Status', 'event_espresso'), |
|
161 | - false, |
|
162 | - 'draft', |
|
163 | - $this->_custom_stati |
|
164 | - ), |
|
165 | - 'password' => new EE_Password_Field( |
|
166 | - 'post_password', |
|
167 | - __('Password', 'event_espresso'), |
|
168 | - false, |
|
169 | - '', |
|
170 | - array( |
|
171 | - 'EVT_desc', |
|
172 | - 'EVT_short_desc', |
|
173 | - 'EVT_display_desc', |
|
174 | - 'EVT_display_ticket_selector', |
|
175 | - 'EVT_visible_on', |
|
176 | - 'EVT_additional_limit', |
|
177 | - 'EVT_default_registration_status', |
|
178 | - 'EVT_member_only', |
|
179 | - 'EVT_phone', |
|
180 | - 'EVT_allow_overflow', |
|
181 | - 'EVT_timezone_string', |
|
182 | - 'EVT_external_URL', |
|
183 | - 'EVT_donations' |
|
184 | - ) |
|
185 | - ) |
|
186 | - ), |
|
187 | - 'Event_Meta' => array( |
|
188 | - 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
189 | - 'EVTM_ID', |
|
190 | - esc_html__('Event Meta Row ID', 'event_espresso'), |
|
191 | - false |
|
192 | - ), |
|
193 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
194 | - 'EVT_ID', |
|
195 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
196 | - false |
|
197 | - ), |
|
198 | - 'EVT_display_desc' => new EE_Boolean_Field( |
|
199 | - 'EVT_display_desc', |
|
200 | - esc_html__('Display Description Flag', 'event_espresso'), |
|
201 | - false, |
|
202 | - true |
|
203 | - ), |
|
204 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
205 | - 'EVT_display_ticket_selector', |
|
206 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
207 | - false, |
|
208 | - true |
|
209 | - ), |
|
210 | - 'EVT_visible_on' => new EE_Datetime_Field( |
|
211 | - 'EVT_visible_on', |
|
212 | - esc_html__('Event Visible Date', 'event_espresso'), |
|
213 | - true, |
|
214 | - EE_Datetime_Field::now |
|
215 | - ), |
|
216 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
217 | - 'EVT_additional_limit', |
|
218 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
219 | - true, |
|
220 | - self::$_default_additional_limit |
|
221 | - ), |
|
222 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
223 | - 'EVT_default_registration_status', |
|
224 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
225 | - false, |
|
226 | - EEM_Event::$_default_reg_status, |
|
227 | - EEM_Registration::reg_status_array() |
|
228 | - ), |
|
229 | - 'EVT_member_only' => new EE_Boolean_Field( |
|
230 | - 'EVT_member_only', |
|
231 | - esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
232 | - false, |
|
233 | - false |
|
234 | - ), |
|
235 | - 'EVT_phone' => new EE_Plain_Text_Field( |
|
236 | - 'EVT_phone', |
|
237 | - esc_html__('Event Phone Number', 'event_espresso'), |
|
238 | - false, |
|
239 | - '' |
|
240 | - ), |
|
241 | - 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
242 | - 'EVT_allow_overflow', |
|
243 | - esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
244 | - false, |
|
245 | - false |
|
246 | - ), |
|
247 | - 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
248 | - 'EVT_timezone_string', |
|
249 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
250 | - false, |
|
251 | - '' |
|
252 | - ), |
|
253 | - 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
254 | - 'EVT_external_URL', |
|
255 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
256 | - true |
|
257 | - ), |
|
258 | - 'EVT_donations' => new EE_Boolean_Field( |
|
259 | - 'EVT_donations', |
|
260 | - esc_html__('Accept Donations?', 'event_espresso'), |
|
261 | - false, |
|
262 | - false |
|
263 | - ), |
|
264 | - 'FSC_UUID' => new EE_Foreign_Key_String_Field( |
|
265 | - 'FSC_UUID', |
|
266 | - esc_html__('Registration Form UUID (universally unique identifier)', 'event_espresso'), |
|
267 | - true, |
|
268 | - null, |
|
269 | - 'Form_Section', |
|
270 | - false |
|
271 | - ), |
|
272 | - ), |
|
273 | - ); |
|
274 | - $this->_model_relations = array( |
|
275 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
276 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
277 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
278 | - 'Form_Section' => new EE_Belongs_To_Relation(), |
|
279 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
280 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
281 | - 'Registration' => new EE_Has_Many_Relation(), |
|
282 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
283 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
284 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
285 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
286 | - ); |
|
287 | - // this model is generally available for reading |
|
288 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
289 | - $this->model_chain_to_password = ''; |
|
290 | - parent::__construct($timezone); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @param string $default_reg_status |
|
296 | - * @throws EE_Error |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - public static function set_default_reg_status($default_reg_status) |
|
300 | - { |
|
301 | - self::$_default_reg_status = $default_reg_status; |
|
302 | - // if EEM_Event has already been instantiated, |
|
303 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
304 | - if (self::$_instance instanceof EEM_Event) { |
|
305 | - $default_reg_status = new EE_Enum_Text_Field( |
|
306 | - 'EVT_default_registration_status', |
|
307 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
308 | - false, |
|
309 | - $default_reg_status, |
|
310 | - EEM_Registration::reg_status_array() |
|
311 | - ); |
|
312 | - $default_reg_status->_construct_finalize( |
|
313 | - 'Event_Meta', |
|
314 | - 'EVT_default_registration_status', |
|
315 | - 'EEM_Event' |
|
316 | - ); |
|
317 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
318 | - } |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Used to override the default for the additional limit field. |
|
324 | - * @param $additional_limit |
|
325 | - */ |
|
326 | - public static function set_default_additional_limit($additional_limit) |
|
327 | - { |
|
328 | - self::$_default_additional_limit = (int) $additional_limit; |
|
329 | - if (self::$_instance instanceof EEM_Event) { |
|
330 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
331 | - 'EVT_additional_limit', |
|
332 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
333 | - true, |
|
334 | - self::$_default_additional_limit |
|
335 | - ); |
|
336 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
337 | - 'Event_Meta', |
|
338 | - 'EVT_additional_limit', |
|
339 | - 'EEM_Event' |
|
340 | - ); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Return what is currently set as the default additional limit for the event. |
|
347 | - * @return int |
|
348 | - */ |
|
349 | - public static function get_default_additional_limit() |
|
350 | - { |
|
351 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * get_question_groups |
|
357 | - * |
|
358 | - * @return array |
|
359 | - * @throws EE_Error |
|
360 | - * @throws ReflectionException |
|
361 | - */ |
|
362 | - public function get_all_question_groups() |
|
363 | - { |
|
364 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
365 | - array( |
|
366 | - array('QSG_deleted' => false), |
|
367 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
368 | - ) |
|
369 | - ); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * get_question_groups |
|
375 | - * |
|
376 | - * @param int $EVT_ID |
|
377 | - * @return array|bool |
|
378 | - * @throws EE_Error |
|
379 | - * @throws ReflectionException |
|
380 | - */ |
|
381 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
382 | - { |
|
383 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
384 | - EE_Error::add_error( |
|
385 | - esc_html__( |
|
386 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
387 | - 'event_espresso' |
|
388 | - ), |
|
389 | - __FILE__, |
|
390 | - __FUNCTION__, |
|
391 | - __LINE__ |
|
392 | - ); |
|
393 | - return false; |
|
394 | - } |
|
395 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
396 | - array( |
|
397 | - array('EVT_ID' => $EVT_ID), |
|
398 | - ) |
|
399 | - ); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * get_question_groups |
|
405 | - * |
|
406 | - * @param int $EVT_ID |
|
407 | - * @param boolean $for_primary_attendee |
|
408 | - * @return array|bool |
|
409 | - * @throws EE_Error |
|
410 | - * @throws InvalidArgumentException |
|
411 | - * @throws ReflectionException |
|
412 | - * @throws InvalidDataTypeException |
|
413 | - * @throws InvalidInterfaceException |
|
414 | - */ |
|
415 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
416 | - { |
|
417 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
418 | - EE_Error::add_error( |
|
419 | - esc_html__( |
|
420 | - // @codingStandardsIgnoreStart |
|
421 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
422 | - // @codingStandardsIgnoreEnd |
|
423 | - 'event_espresso' |
|
424 | - ), |
|
425 | - __FILE__, |
|
426 | - __FUNCTION__, |
|
427 | - __LINE__ |
|
428 | - ); |
|
429 | - return false; |
|
430 | - } |
|
431 | - $query_params = [ |
|
432 | - [ |
|
433 | - 'EVT_ID' => $EVT_ID, |
|
434 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
435 | - ] |
|
436 | - ]; |
|
437 | - if ($for_primary_attendee) { |
|
438 | - $query_params[0]['EQG_primary'] = true; |
|
439 | - } else { |
|
440 | - $query_params[0]['EQG_additional'] = true; |
|
441 | - } |
|
442 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - /** |
|
447 | - * get_question_groups |
|
448 | - * |
|
449 | - * @param int $EVT_ID |
|
450 | - * @param EE_Registration $registration |
|
451 | - * @return array|bool |
|
452 | - * @throws EE_Error |
|
453 | - * @throws InvalidArgumentException |
|
454 | - * @throws InvalidDataTypeException |
|
455 | - * @throws InvalidInterfaceException |
|
456 | - * @throws ReflectionException |
|
457 | - */ |
|
458 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
459 | - { |
|
460 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
461 | - EE_Error::add_error( |
|
462 | - esc_html__( |
|
463 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
464 | - 'event_espresso' |
|
465 | - ), |
|
466 | - __FILE__, |
|
467 | - __FUNCTION__, |
|
468 | - __LINE__ |
|
469 | - ); |
|
470 | - return false; |
|
471 | - } |
|
472 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
473 | - [ |
|
474 | - [ |
|
475 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
476 | - 'Event_Question_Group.' |
|
477 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
478 | - $registration->is_primary_registrant() |
|
479 | - ) => true |
|
480 | - ], |
|
481 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
482 | - ] |
|
483 | - ); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - /** |
|
488 | - * get_question_target_db_column |
|
489 | - * |
|
490 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
491 | - * @return array|bool |
|
492 | - * @throws EE_Error |
|
493 | - * @throws ReflectionException |
|
494 | - */ |
|
495 | - public function get_questions_in_groups($QSG_IDs = '') |
|
496 | - { |
|
497 | - if (empty($QSG_IDs)) { |
|
498 | - EE_Error::add_error( |
|
499 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
500 | - __FILE__, |
|
501 | - __FUNCTION__, |
|
502 | - __LINE__ |
|
503 | - ); |
|
504 | - return false; |
|
505 | - } |
|
506 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
507 | - array( |
|
508 | - array( |
|
509 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
510 | - 'QST_deleted' => false, |
|
511 | - 'QST_admin_only' => is_admin(), |
|
512 | - ), |
|
513 | - 'order_by' => 'QST_order', |
|
514 | - ) |
|
515 | - ); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * get_options_for_question |
|
521 | - * |
|
522 | - * @param string $QST_IDs csv list of $QST IDs |
|
523 | - * @return array|bool |
|
524 | - * @throws EE_Error |
|
525 | - * @throws ReflectionException |
|
526 | - */ |
|
527 | - public function get_options_for_question($QST_IDs) |
|
528 | - { |
|
529 | - if (empty($QST_IDs)) { |
|
530 | - EE_Error::add_error( |
|
531 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
532 | - __FILE__, |
|
533 | - __FUNCTION__, |
|
534 | - __LINE__ |
|
535 | - ); |
|
536 | - return false; |
|
537 | - } |
|
538 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
539 | - array( |
|
540 | - array( |
|
541 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
542 | - 'QSO_deleted' => false, |
|
543 | - ), |
|
544 | - 'order_by' => 'QSO_ID', |
|
545 | - ) |
|
546 | - ); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * Gets all events that are published |
|
552 | - * and have event start time earlier than now and an event end time later than now |
|
553 | - * |
|
554 | - * @param array $query_params An array of query params to further filter on |
|
555 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
556 | - * @param bool $count whether to return the count or not (default FALSE) |
|
557 | - * @return EE_Event[]|int |
|
558 | - * @throws EE_Error |
|
559 | - * @throws ReflectionException |
|
560 | - */ |
|
561 | - public function get_active_events($query_params, $count = false) |
|
562 | - { |
|
563 | - if (array_key_exists(0, $query_params)) { |
|
564 | - $where_params = $query_params[0]; |
|
565 | - unset($query_params[0]); |
|
566 | - } else { |
|
567 | - $where_params = array(); |
|
568 | - } |
|
569 | - // if we have count make sure we don't include group by |
|
570 | - if ($count && isset($query_params['group_by'])) { |
|
571 | - unset($query_params['group_by']); |
|
572 | - } |
|
573 | - // let's add specific query_params for active_events |
|
574 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
575 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
576 | - // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
577 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
578 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
579 | - '<', |
|
580 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
581 | - ); |
|
582 | - } else { |
|
583 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
584 | - '<', |
|
585 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
586 | - ); |
|
587 | - } |
|
588 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
589 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
590 | - '>', |
|
591 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
592 | - ); |
|
593 | - } else { |
|
594 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
595 | - '>', |
|
596 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
597 | - ); |
|
598 | - } |
|
599 | - $query_params[0] = $where_params; |
|
600 | - // don't use $query_params with count() |
|
601 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
602 | - return $count |
|
603 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
604 | - : $this->get_all($query_params); |
|
605 | - } |
|
606 | - |
|
607 | - |
|
608 | - /** |
|
609 | - * get all events that are published and have an event start time later than now |
|
610 | - * |
|
611 | - * @param array $query_params An array of query params to further filter on |
|
612 | - * (Note that status and DTT_EVT_start will be overridden) |
|
613 | - * @param bool $count whether to return the count or not (default FALSE) |
|
614 | - * @return EE_Event[]|int |
|
615 | - * @throws EE_Error |
|
616 | - * @throws ReflectionException |
|
617 | - */ |
|
618 | - public function get_upcoming_events($query_params, $count = false) |
|
619 | - { |
|
620 | - if (array_key_exists(0, $query_params)) { |
|
621 | - $where_params = $query_params[0]; |
|
622 | - unset($query_params[0]); |
|
623 | - } else { |
|
624 | - $where_params = array(); |
|
625 | - } |
|
626 | - // if we have count make sure we don't include group by |
|
627 | - if ($count && isset($query_params['group_by'])) { |
|
628 | - unset($query_params['group_by']); |
|
629 | - } |
|
630 | - // let's add specific query_params for active_events |
|
631 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
632 | - // we need to pull events with a status of publish and sold_out |
|
633 | - $event_status = array('publish', EEM_Event::sold_out); |
|
634 | - // check if the user can read private events and if so add the 'private status to the were params' |
|
635 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
636 | - $event_status[] = 'private'; |
|
637 | - } |
|
638 | - $where_params['status'] = array('IN', $event_status); |
|
639 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
640 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
641 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
642 | - '>', |
|
643 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
644 | - ); |
|
645 | - } else { |
|
646 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
647 | - '>', |
|
648 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
649 | - ); |
|
650 | - } |
|
651 | - $query_params[0] = $where_params; |
|
652 | - // don't use $query_params with count() |
|
653 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
654 | - return $count |
|
655 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
656 | - : $this->get_all($query_params); |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - /** |
|
661 | - * Gets all events that are published |
|
662 | - * and have an event end time later than now |
|
663 | - * |
|
664 | - * @param array $query_params An array of query params to further filter on |
|
665 | - * (note that status and DTT_EVT_end will be overridden) |
|
666 | - * @param bool $count whether to return the count or not (default FALSE) |
|
667 | - * @return EE_Event[]|int |
|
668 | - * @throws EE_Error |
|
669 | - * @throws ReflectionException |
|
670 | - */ |
|
671 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
672 | - { |
|
673 | - if (array_key_exists(0, $query_params)) { |
|
674 | - $where_params = $query_params[0]; |
|
675 | - unset($query_params[0]); |
|
676 | - } else { |
|
677 | - $where_params = array(); |
|
678 | - } |
|
679 | - // if we have count make sure we don't include group by |
|
680 | - if ($count && isset($query_params['group_by'])) { |
|
681 | - unset($query_params['group_by']); |
|
682 | - } |
|
683 | - // let's add specific query_params for active_events |
|
684 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
685 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
686 | - // add where params for DTT_EVT_end |
|
687 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
688 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
689 | - '>', |
|
690 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
691 | - ); |
|
692 | - } else { |
|
693 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
694 | - '>', |
|
695 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
696 | - ); |
|
697 | - } |
|
698 | - $query_params[0] = $where_params; |
|
699 | - // don't use $query_params with count() |
|
700 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
701 | - return $count |
|
702 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
703 | - : $this->get_all($query_params); |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - /** |
|
708 | - * This only returns events that are expired. |
|
709 | - * They may still be published but all their datetimes have expired. |
|
710 | - * |
|
711 | - * @param array $query_params An array of query params to further filter on |
|
712 | - * (note that status and DTT_EVT_end will be overridden) |
|
713 | - * @param bool $count whether to return the count or not (default FALSE) |
|
714 | - * @return EE_Event[]|int |
|
715 | - * @throws EE_Error |
|
716 | - * @throws ReflectionException |
|
717 | - */ |
|
718 | - public function get_expired_events($query_params, $count = false) |
|
719 | - { |
|
720 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
721 | - // if we have count make sure we don't include group by |
|
722 | - if ($count && isset($query_params['group_by'])) { |
|
723 | - unset($query_params['group_by']); |
|
724 | - } |
|
725 | - // let's add specific query_params for active_events |
|
726 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
727 | - if (isset($where_params['status'])) { |
|
728 | - unset($where_params['status']); |
|
729 | - } |
|
730 | - $exclude_query = $query_params; |
|
731 | - if (isset($exclude_query[0])) { |
|
732 | - unset($exclude_query[0]); |
|
733 | - } |
|
734 | - $exclude_query[0] = array( |
|
735 | - 'Datetime.DTT_EVT_end' => array( |
|
736 | - '>', |
|
737 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
738 | - ), |
|
739 | - ); |
|
740 | - // first get all events that have datetimes where its not expired. |
|
741 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
742 | - $event_ids = array_keys($event_ids); |
|
743 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
744 | - $and_condition = array( |
|
745 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
746 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
747 | - ); |
|
748 | - if (isset($where_params['OR'])) { |
|
749 | - $and_condition['OR'] = $where_params['OR']; |
|
750 | - unset($where_params['OR']); |
|
751 | - } |
|
752 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
753 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
754 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
755 | - } |
|
756 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
757 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
758 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
759 | - } |
|
760 | - // merge remaining $where params with the and conditions. |
|
761 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
762 | - $query_params[0] = $where_params; |
|
763 | - // don't use $query_params with count() |
|
764 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
765 | - return $count |
|
766 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
767 | - : $this->get_all($query_params); |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - |
|
772 | - /** |
|
773 | - * This basically just returns the events that do not have the publish status. |
|
774 | - * |
|
775 | - * @param array $query_params An array of query params to further filter on |
|
776 | - * (note that status will be overwritten) |
|
777 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
778 | - * @return EE_Event[]|int |
|
779 | - * @throws EE_Error |
|
780 | - */ |
|
781 | - public function get_inactive_events($query_params, $count = false) |
|
782 | - { |
|
783 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
784 | - // let's add in specific query_params for inactive events. |
|
785 | - if (isset($where_params['status'])) { |
|
786 | - unset($where_params['status']); |
|
787 | - } |
|
788 | - // if we have count make sure we don't include group by |
|
789 | - if ($count && isset($query_params['group_by'])) { |
|
790 | - unset($query_params['group_by']); |
|
791 | - } |
|
792 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
793 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
794 | - if (isset($where_params['OR'])) { |
|
795 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
796 | - unset($where_params['OR']); |
|
797 | - } |
|
798 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
799 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
800 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
801 | - } |
|
802 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
803 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
804 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
805 | - } |
|
806 | - $query_params[0] = $where_params; |
|
807 | - // don't use $query_params with count() |
|
808 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
809 | - return $count |
|
810 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
811 | - : $this->get_all($query_params); |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - /** |
|
816 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
817 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
818 | - * attached to the event. See parent for param descriptions |
|
819 | - * |
|
820 | - * @param $id_or_obj |
|
821 | - * @param $other_model_id_or_obj |
|
822 | - * @param string $relationName |
|
823 | - * @param array $where_query |
|
824 | - * @return EE_Base_Class |
|
825 | - * @throws EE_Error |
|
826 | - * @throws ReflectionException |
|
827 | - */ |
|
828 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
829 | - { |
|
830 | - if ($relationName === 'Price') { |
|
831 | - // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
832 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
833 | - // if EVT_ID = 0, then this is a default |
|
834 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
835 | - // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
836 | - $prc_chk->set('PRC_ID', 0); |
|
837 | - } |
|
838 | - // run parent |
|
839 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
840 | - } |
|
841 | - // otherwise carry on as normal |
|
842 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
843 | - } |
|
844 | - |
|
845 | - |
|
846 | - |
|
847 | - /******************** DEPRECATED METHODS ********************/ |
|
848 | - |
|
849 | - |
|
850 | - /** |
|
851 | - * _get_question_target_db_column |
|
852 | - * |
|
853 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
854 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
855 | - * registration). |
|
856 | - * @return array |
|
857 | - * @throws ReflectionException |
|
858 | - * @throws EE_Error*@deprecated as of 4.8.32.rc.001. Instead consider using |
|
859 | - * EE_Registration_Custom_Questions_Form located in |
|
860 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
861 | - * @access public |
|
862 | - */ |
|
863 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
864 | - { |
|
865 | - if (empty($EVT_ID)) { |
|
866 | - throw new EE_Error(__( |
|
867 | - 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
868 | - 'event_espresso' |
|
869 | - )); |
|
870 | - } |
|
871 | - $questions = array(); |
|
872 | - // get all question groups for event |
|
873 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
874 | - if (! empty($qgs)) { |
|
875 | - foreach ($qgs as $qg) { |
|
876 | - $qsts = $qg->questions(); |
|
877 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
878 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
879 | - foreach ($qsts as $qst) { |
|
880 | - if ($qst->is_system_question()) { |
|
881 | - continue; |
|
882 | - } |
|
883 | - $answer = EEM_Answer::instance()->get_one(array( |
|
884 | - array( |
|
885 | - 'QST_ID' => $qst->ID(), |
|
886 | - 'REG_ID' => $registration->ID(), |
|
887 | - ), |
|
888 | - )); |
|
889 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
890 | - $qst_name = $qstn_id = $qst->ID(); |
|
891 | - $ans_id = $answer->ID(); |
|
892 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
893 | - $input_name = ''; |
|
894 | - $input_id = sanitize_key($qst->display_text()); |
|
895 | - $input_class = ''; |
|
896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
897 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
898 | - . $input_name |
|
899 | - . $qst_name; |
|
900 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
901 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
902 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
903 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
904 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
905 | - // leave responses as-is, don't convert stuff into html entities please! |
|
906 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
907 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
908 | - $QSOs = $qst->options(true, $answer->value()); |
|
909 | - if (is_array($QSOs)) { |
|
910 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
911 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
912 | - } |
|
913 | - } |
|
914 | - } |
|
915 | - } |
|
916 | - } |
|
917 | - } |
|
918 | - return $questions; |
|
919 | - } |
|
920 | - |
|
921 | - |
|
922 | - /** |
|
923 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
924 | - * or an stdClass where each property is the name of a column, |
|
925 | - * @return EE_Base_Class |
|
926 | - * @throws EE_Error |
|
927 | - */ |
|
928 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
929 | - { |
|
930 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
931 | - if ($classInstance instanceof EE_Event) { |
|
932 | - // events have their timezone defined in the DB, so use it immediately |
|
933 | - $this->set_timezone($classInstance->get_timezone()); |
|
934 | - } |
|
935 | - return $classInstance; |
|
936 | - } |
|
17 | + /** |
|
18 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
19 | + * event |
|
20 | + */ |
|
21 | + const sold_out = 'sold_out'; |
|
22 | + |
|
23 | + /** |
|
24 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
25 | + * date) |
|
26 | + */ |
|
27 | + const postponed = 'postponed'; |
|
28 | + |
|
29 | + /** |
|
30 | + * constant used by status(), indicating that the event will no longer occur |
|
31 | + */ |
|
32 | + const cancelled = 'cancelled'; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected static $_default_reg_status; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * This is the default for the additional limit field. |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected static $_default_additional_limit = 10; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * private instance of the Event object |
|
50 | + * |
|
51 | + * @var EEM_Event |
|
52 | + */ |
|
53 | + protected static $_instance; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
58 | + * |
|
59 | + * @param string $timezone |
|
60 | + * @throws EE_Error |
|
61 | + * @throws ReflectionException |
|
62 | + */ |
|
63 | + protected function __construct($timezone = null) |
|
64 | + { |
|
65 | + EE_Registry::instance()->load_model('Registration'); |
|
66 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
67 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
68 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
69 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
70 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
71 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
72 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
73 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
74 | + $this->_custom_stati = apply_filters( |
|
75 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
76 | + array( |
|
77 | + EEM_Event::cancelled => array( |
|
78 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
79 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
80 | + ), |
|
81 | + EEM_Event::postponed => array( |
|
82 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
83 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
84 | + ), |
|
85 | + EEM_Event::sold_out => array( |
|
86 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
87 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
88 | + ), |
|
89 | + ) |
|
90 | + ); |
|
91 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
92 | + : self::$_default_reg_status; |
|
93 | + $this->_tables = array( |
|
94 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
95 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
96 | + ); |
|
97 | + $this->_fields = array( |
|
98 | + 'Event_CPT' => array( |
|
99 | + 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
100 | + 'ID', |
|
101 | + esc_html__('Post ID for Event', 'event_espresso') |
|
102 | + ), |
|
103 | + 'EVT_name' => new EE_Plain_Text_Field( |
|
104 | + 'post_title', |
|
105 | + esc_html__('Event Name', 'event_espresso'), |
|
106 | + false, |
|
107 | + '' |
|
108 | + ), |
|
109 | + 'EVT_desc' => new EE_Post_Content_Field( |
|
110 | + 'post_content', |
|
111 | + esc_html__('Event Description', 'event_espresso'), |
|
112 | + false, |
|
113 | + '' |
|
114 | + ), |
|
115 | + 'EVT_slug' => new EE_Slug_Field( |
|
116 | + 'post_name', |
|
117 | + esc_html__('Event Slug', 'event_espresso'), |
|
118 | + false, |
|
119 | + '' |
|
120 | + ), |
|
121 | + 'EVT_created' => new EE_Datetime_Field( |
|
122 | + 'post_date', |
|
123 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
124 | + false, |
|
125 | + EE_Datetime_Field::now |
|
126 | + ), |
|
127 | + 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
128 | + 'post_excerpt', |
|
129 | + esc_html__('Event Short Description', 'event_espresso'), |
|
130 | + false, |
|
131 | + '' |
|
132 | + ), |
|
133 | + 'EVT_modified' => new EE_Datetime_Field( |
|
134 | + 'post_modified', |
|
135 | + esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
136 | + false, |
|
137 | + EE_Datetime_Field::now |
|
138 | + ), |
|
139 | + 'EVT_wp_user' => new EE_WP_User_Field( |
|
140 | + 'post_author', |
|
141 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
142 | + false |
|
143 | + ), |
|
144 | + 'parent' => new EE_Integer_Field( |
|
145 | + 'post_parent', |
|
146 | + esc_html__('Event Parent ID', 'event_espresso'), |
|
147 | + false, |
|
148 | + 0 |
|
149 | + ), |
|
150 | + 'EVT_order' => new EE_Integer_Field( |
|
151 | + 'menu_order', |
|
152 | + esc_html__('Event Menu Order', 'event_espresso'), |
|
153 | + false, |
|
154 | + 1 |
|
155 | + ), |
|
156 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
157 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
158 | + 'status' => new EE_WP_Post_Status_Field( |
|
159 | + 'post_status', |
|
160 | + esc_html__('Event Status', 'event_espresso'), |
|
161 | + false, |
|
162 | + 'draft', |
|
163 | + $this->_custom_stati |
|
164 | + ), |
|
165 | + 'password' => new EE_Password_Field( |
|
166 | + 'post_password', |
|
167 | + __('Password', 'event_espresso'), |
|
168 | + false, |
|
169 | + '', |
|
170 | + array( |
|
171 | + 'EVT_desc', |
|
172 | + 'EVT_short_desc', |
|
173 | + 'EVT_display_desc', |
|
174 | + 'EVT_display_ticket_selector', |
|
175 | + 'EVT_visible_on', |
|
176 | + 'EVT_additional_limit', |
|
177 | + 'EVT_default_registration_status', |
|
178 | + 'EVT_member_only', |
|
179 | + 'EVT_phone', |
|
180 | + 'EVT_allow_overflow', |
|
181 | + 'EVT_timezone_string', |
|
182 | + 'EVT_external_URL', |
|
183 | + 'EVT_donations' |
|
184 | + ) |
|
185 | + ) |
|
186 | + ), |
|
187 | + 'Event_Meta' => array( |
|
188 | + 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
189 | + 'EVTM_ID', |
|
190 | + esc_html__('Event Meta Row ID', 'event_espresso'), |
|
191 | + false |
|
192 | + ), |
|
193 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
194 | + 'EVT_ID', |
|
195 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
196 | + false |
|
197 | + ), |
|
198 | + 'EVT_display_desc' => new EE_Boolean_Field( |
|
199 | + 'EVT_display_desc', |
|
200 | + esc_html__('Display Description Flag', 'event_espresso'), |
|
201 | + false, |
|
202 | + true |
|
203 | + ), |
|
204 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
205 | + 'EVT_display_ticket_selector', |
|
206 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
207 | + false, |
|
208 | + true |
|
209 | + ), |
|
210 | + 'EVT_visible_on' => new EE_Datetime_Field( |
|
211 | + 'EVT_visible_on', |
|
212 | + esc_html__('Event Visible Date', 'event_espresso'), |
|
213 | + true, |
|
214 | + EE_Datetime_Field::now |
|
215 | + ), |
|
216 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
217 | + 'EVT_additional_limit', |
|
218 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
219 | + true, |
|
220 | + self::$_default_additional_limit |
|
221 | + ), |
|
222 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
223 | + 'EVT_default_registration_status', |
|
224 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
225 | + false, |
|
226 | + EEM_Event::$_default_reg_status, |
|
227 | + EEM_Registration::reg_status_array() |
|
228 | + ), |
|
229 | + 'EVT_member_only' => new EE_Boolean_Field( |
|
230 | + 'EVT_member_only', |
|
231 | + esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
232 | + false, |
|
233 | + false |
|
234 | + ), |
|
235 | + 'EVT_phone' => new EE_Plain_Text_Field( |
|
236 | + 'EVT_phone', |
|
237 | + esc_html__('Event Phone Number', 'event_espresso'), |
|
238 | + false, |
|
239 | + '' |
|
240 | + ), |
|
241 | + 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
242 | + 'EVT_allow_overflow', |
|
243 | + esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
244 | + false, |
|
245 | + false |
|
246 | + ), |
|
247 | + 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
248 | + 'EVT_timezone_string', |
|
249 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
250 | + false, |
|
251 | + '' |
|
252 | + ), |
|
253 | + 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
254 | + 'EVT_external_URL', |
|
255 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
256 | + true |
|
257 | + ), |
|
258 | + 'EVT_donations' => new EE_Boolean_Field( |
|
259 | + 'EVT_donations', |
|
260 | + esc_html__('Accept Donations?', 'event_espresso'), |
|
261 | + false, |
|
262 | + false |
|
263 | + ), |
|
264 | + 'FSC_UUID' => new EE_Foreign_Key_String_Field( |
|
265 | + 'FSC_UUID', |
|
266 | + esc_html__('Registration Form UUID (universally unique identifier)', 'event_espresso'), |
|
267 | + true, |
|
268 | + null, |
|
269 | + 'Form_Section', |
|
270 | + false |
|
271 | + ), |
|
272 | + ), |
|
273 | + ); |
|
274 | + $this->_model_relations = array( |
|
275 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
276 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
277 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
278 | + 'Form_Section' => new EE_Belongs_To_Relation(), |
|
279 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
280 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
281 | + 'Registration' => new EE_Has_Many_Relation(), |
|
282 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
283 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
284 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
285 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
286 | + ); |
|
287 | + // this model is generally available for reading |
|
288 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
289 | + $this->model_chain_to_password = ''; |
|
290 | + parent::__construct($timezone); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @param string $default_reg_status |
|
296 | + * @throws EE_Error |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + public static function set_default_reg_status($default_reg_status) |
|
300 | + { |
|
301 | + self::$_default_reg_status = $default_reg_status; |
|
302 | + // if EEM_Event has already been instantiated, |
|
303 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
304 | + if (self::$_instance instanceof EEM_Event) { |
|
305 | + $default_reg_status = new EE_Enum_Text_Field( |
|
306 | + 'EVT_default_registration_status', |
|
307 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
308 | + false, |
|
309 | + $default_reg_status, |
|
310 | + EEM_Registration::reg_status_array() |
|
311 | + ); |
|
312 | + $default_reg_status->_construct_finalize( |
|
313 | + 'Event_Meta', |
|
314 | + 'EVT_default_registration_status', |
|
315 | + 'EEM_Event' |
|
316 | + ); |
|
317 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
318 | + } |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Used to override the default for the additional limit field. |
|
324 | + * @param $additional_limit |
|
325 | + */ |
|
326 | + public static function set_default_additional_limit($additional_limit) |
|
327 | + { |
|
328 | + self::$_default_additional_limit = (int) $additional_limit; |
|
329 | + if (self::$_instance instanceof EEM_Event) { |
|
330 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
331 | + 'EVT_additional_limit', |
|
332 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
333 | + true, |
|
334 | + self::$_default_additional_limit |
|
335 | + ); |
|
336 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
337 | + 'Event_Meta', |
|
338 | + 'EVT_additional_limit', |
|
339 | + 'EEM_Event' |
|
340 | + ); |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Return what is currently set as the default additional limit for the event. |
|
347 | + * @return int |
|
348 | + */ |
|
349 | + public static function get_default_additional_limit() |
|
350 | + { |
|
351 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * get_question_groups |
|
357 | + * |
|
358 | + * @return array |
|
359 | + * @throws EE_Error |
|
360 | + * @throws ReflectionException |
|
361 | + */ |
|
362 | + public function get_all_question_groups() |
|
363 | + { |
|
364 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
365 | + array( |
|
366 | + array('QSG_deleted' => false), |
|
367 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
368 | + ) |
|
369 | + ); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * get_question_groups |
|
375 | + * |
|
376 | + * @param int $EVT_ID |
|
377 | + * @return array|bool |
|
378 | + * @throws EE_Error |
|
379 | + * @throws ReflectionException |
|
380 | + */ |
|
381 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
382 | + { |
|
383 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
384 | + EE_Error::add_error( |
|
385 | + esc_html__( |
|
386 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
387 | + 'event_espresso' |
|
388 | + ), |
|
389 | + __FILE__, |
|
390 | + __FUNCTION__, |
|
391 | + __LINE__ |
|
392 | + ); |
|
393 | + return false; |
|
394 | + } |
|
395 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
396 | + array( |
|
397 | + array('EVT_ID' => $EVT_ID), |
|
398 | + ) |
|
399 | + ); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * get_question_groups |
|
405 | + * |
|
406 | + * @param int $EVT_ID |
|
407 | + * @param boolean $for_primary_attendee |
|
408 | + * @return array|bool |
|
409 | + * @throws EE_Error |
|
410 | + * @throws InvalidArgumentException |
|
411 | + * @throws ReflectionException |
|
412 | + * @throws InvalidDataTypeException |
|
413 | + * @throws InvalidInterfaceException |
|
414 | + */ |
|
415 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
416 | + { |
|
417 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
418 | + EE_Error::add_error( |
|
419 | + esc_html__( |
|
420 | + // @codingStandardsIgnoreStart |
|
421 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
422 | + // @codingStandardsIgnoreEnd |
|
423 | + 'event_espresso' |
|
424 | + ), |
|
425 | + __FILE__, |
|
426 | + __FUNCTION__, |
|
427 | + __LINE__ |
|
428 | + ); |
|
429 | + return false; |
|
430 | + } |
|
431 | + $query_params = [ |
|
432 | + [ |
|
433 | + 'EVT_ID' => $EVT_ID, |
|
434 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
435 | + ] |
|
436 | + ]; |
|
437 | + if ($for_primary_attendee) { |
|
438 | + $query_params[0]['EQG_primary'] = true; |
|
439 | + } else { |
|
440 | + $query_params[0]['EQG_additional'] = true; |
|
441 | + } |
|
442 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + /** |
|
447 | + * get_question_groups |
|
448 | + * |
|
449 | + * @param int $EVT_ID |
|
450 | + * @param EE_Registration $registration |
|
451 | + * @return array|bool |
|
452 | + * @throws EE_Error |
|
453 | + * @throws InvalidArgumentException |
|
454 | + * @throws InvalidDataTypeException |
|
455 | + * @throws InvalidInterfaceException |
|
456 | + * @throws ReflectionException |
|
457 | + */ |
|
458 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
459 | + { |
|
460 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
461 | + EE_Error::add_error( |
|
462 | + esc_html__( |
|
463 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
464 | + 'event_espresso' |
|
465 | + ), |
|
466 | + __FILE__, |
|
467 | + __FUNCTION__, |
|
468 | + __LINE__ |
|
469 | + ); |
|
470 | + return false; |
|
471 | + } |
|
472 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
473 | + [ |
|
474 | + [ |
|
475 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
476 | + 'Event_Question_Group.' |
|
477 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
478 | + $registration->is_primary_registrant() |
|
479 | + ) => true |
|
480 | + ], |
|
481 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
482 | + ] |
|
483 | + ); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + /** |
|
488 | + * get_question_target_db_column |
|
489 | + * |
|
490 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
491 | + * @return array|bool |
|
492 | + * @throws EE_Error |
|
493 | + * @throws ReflectionException |
|
494 | + */ |
|
495 | + public function get_questions_in_groups($QSG_IDs = '') |
|
496 | + { |
|
497 | + if (empty($QSG_IDs)) { |
|
498 | + EE_Error::add_error( |
|
499 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
500 | + __FILE__, |
|
501 | + __FUNCTION__, |
|
502 | + __LINE__ |
|
503 | + ); |
|
504 | + return false; |
|
505 | + } |
|
506 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
507 | + array( |
|
508 | + array( |
|
509 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
510 | + 'QST_deleted' => false, |
|
511 | + 'QST_admin_only' => is_admin(), |
|
512 | + ), |
|
513 | + 'order_by' => 'QST_order', |
|
514 | + ) |
|
515 | + ); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * get_options_for_question |
|
521 | + * |
|
522 | + * @param string $QST_IDs csv list of $QST IDs |
|
523 | + * @return array|bool |
|
524 | + * @throws EE_Error |
|
525 | + * @throws ReflectionException |
|
526 | + */ |
|
527 | + public function get_options_for_question($QST_IDs) |
|
528 | + { |
|
529 | + if (empty($QST_IDs)) { |
|
530 | + EE_Error::add_error( |
|
531 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
532 | + __FILE__, |
|
533 | + __FUNCTION__, |
|
534 | + __LINE__ |
|
535 | + ); |
|
536 | + return false; |
|
537 | + } |
|
538 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
539 | + array( |
|
540 | + array( |
|
541 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
542 | + 'QSO_deleted' => false, |
|
543 | + ), |
|
544 | + 'order_by' => 'QSO_ID', |
|
545 | + ) |
|
546 | + ); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * Gets all events that are published |
|
552 | + * and have event start time earlier than now and an event end time later than now |
|
553 | + * |
|
554 | + * @param array $query_params An array of query params to further filter on |
|
555 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
556 | + * @param bool $count whether to return the count or not (default FALSE) |
|
557 | + * @return EE_Event[]|int |
|
558 | + * @throws EE_Error |
|
559 | + * @throws ReflectionException |
|
560 | + */ |
|
561 | + public function get_active_events($query_params, $count = false) |
|
562 | + { |
|
563 | + if (array_key_exists(0, $query_params)) { |
|
564 | + $where_params = $query_params[0]; |
|
565 | + unset($query_params[0]); |
|
566 | + } else { |
|
567 | + $where_params = array(); |
|
568 | + } |
|
569 | + // if we have count make sure we don't include group by |
|
570 | + if ($count && isset($query_params['group_by'])) { |
|
571 | + unset($query_params['group_by']); |
|
572 | + } |
|
573 | + // let's add specific query_params for active_events |
|
574 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
575 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
576 | + // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
577 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
578 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
579 | + '<', |
|
580 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
581 | + ); |
|
582 | + } else { |
|
583 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
584 | + '<', |
|
585 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
586 | + ); |
|
587 | + } |
|
588 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
589 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
590 | + '>', |
|
591 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
592 | + ); |
|
593 | + } else { |
|
594 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
595 | + '>', |
|
596 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
597 | + ); |
|
598 | + } |
|
599 | + $query_params[0] = $where_params; |
|
600 | + // don't use $query_params with count() |
|
601 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
602 | + return $count |
|
603 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
604 | + : $this->get_all($query_params); |
|
605 | + } |
|
606 | + |
|
607 | + |
|
608 | + /** |
|
609 | + * get all events that are published and have an event start time later than now |
|
610 | + * |
|
611 | + * @param array $query_params An array of query params to further filter on |
|
612 | + * (Note that status and DTT_EVT_start will be overridden) |
|
613 | + * @param bool $count whether to return the count or not (default FALSE) |
|
614 | + * @return EE_Event[]|int |
|
615 | + * @throws EE_Error |
|
616 | + * @throws ReflectionException |
|
617 | + */ |
|
618 | + public function get_upcoming_events($query_params, $count = false) |
|
619 | + { |
|
620 | + if (array_key_exists(0, $query_params)) { |
|
621 | + $where_params = $query_params[0]; |
|
622 | + unset($query_params[0]); |
|
623 | + } else { |
|
624 | + $where_params = array(); |
|
625 | + } |
|
626 | + // if we have count make sure we don't include group by |
|
627 | + if ($count && isset($query_params['group_by'])) { |
|
628 | + unset($query_params['group_by']); |
|
629 | + } |
|
630 | + // let's add specific query_params for active_events |
|
631 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
632 | + // we need to pull events with a status of publish and sold_out |
|
633 | + $event_status = array('publish', EEM_Event::sold_out); |
|
634 | + // check if the user can read private events and if so add the 'private status to the were params' |
|
635 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
636 | + $event_status[] = 'private'; |
|
637 | + } |
|
638 | + $where_params['status'] = array('IN', $event_status); |
|
639 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
640 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
641 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
642 | + '>', |
|
643 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
644 | + ); |
|
645 | + } else { |
|
646 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
647 | + '>', |
|
648 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
649 | + ); |
|
650 | + } |
|
651 | + $query_params[0] = $where_params; |
|
652 | + // don't use $query_params with count() |
|
653 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
654 | + return $count |
|
655 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
656 | + : $this->get_all($query_params); |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + /** |
|
661 | + * Gets all events that are published |
|
662 | + * and have an event end time later than now |
|
663 | + * |
|
664 | + * @param array $query_params An array of query params to further filter on |
|
665 | + * (note that status and DTT_EVT_end will be overridden) |
|
666 | + * @param bool $count whether to return the count or not (default FALSE) |
|
667 | + * @return EE_Event[]|int |
|
668 | + * @throws EE_Error |
|
669 | + * @throws ReflectionException |
|
670 | + */ |
|
671 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
672 | + { |
|
673 | + if (array_key_exists(0, $query_params)) { |
|
674 | + $where_params = $query_params[0]; |
|
675 | + unset($query_params[0]); |
|
676 | + } else { |
|
677 | + $where_params = array(); |
|
678 | + } |
|
679 | + // if we have count make sure we don't include group by |
|
680 | + if ($count && isset($query_params['group_by'])) { |
|
681 | + unset($query_params['group_by']); |
|
682 | + } |
|
683 | + // let's add specific query_params for active_events |
|
684 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
685 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
686 | + // add where params for DTT_EVT_end |
|
687 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
688 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
689 | + '>', |
|
690 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
691 | + ); |
|
692 | + } else { |
|
693 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
694 | + '>', |
|
695 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
696 | + ); |
|
697 | + } |
|
698 | + $query_params[0] = $where_params; |
|
699 | + // don't use $query_params with count() |
|
700 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
701 | + return $count |
|
702 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
703 | + : $this->get_all($query_params); |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + /** |
|
708 | + * This only returns events that are expired. |
|
709 | + * They may still be published but all their datetimes have expired. |
|
710 | + * |
|
711 | + * @param array $query_params An array of query params to further filter on |
|
712 | + * (note that status and DTT_EVT_end will be overridden) |
|
713 | + * @param bool $count whether to return the count or not (default FALSE) |
|
714 | + * @return EE_Event[]|int |
|
715 | + * @throws EE_Error |
|
716 | + * @throws ReflectionException |
|
717 | + */ |
|
718 | + public function get_expired_events($query_params, $count = false) |
|
719 | + { |
|
720 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
721 | + // if we have count make sure we don't include group by |
|
722 | + if ($count && isset($query_params['group_by'])) { |
|
723 | + unset($query_params['group_by']); |
|
724 | + } |
|
725 | + // let's add specific query_params for active_events |
|
726 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
727 | + if (isset($where_params['status'])) { |
|
728 | + unset($where_params['status']); |
|
729 | + } |
|
730 | + $exclude_query = $query_params; |
|
731 | + if (isset($exclude_query[0])) { |
|
732 | + unset($exclude_query[0]); |
|
733 | + } |
|
734 | + $exclude_query[0] = array( |
|
735 | + 'Datetime.DTT_EVT_end' => array( |
|
736 | + '>', |
|
737 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
738 | + ), |
|
739 | + ); |
|
740 | + // first get all events that have datetimes where its not expired. |
|
741 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
742 | + $event_ids = array_keys($event_ids); |
|
743 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
744 | + $and_condition = array( |
|
745 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
746 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
747 | + ); |
|
748 | + if (isset($where_params['OR'])) { |
|
749 | + $and_condition['OR'] = $where_params['OR']; |
|
750 | + unset($where_params['OR']); |
|
751 | + } |
|
752 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
753 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
754 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
755 | + } |
|
756 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
757 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
758 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
759 | + } |
|
760 | + // merge remaining $where params with the and conditions. |
|
761 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
762 | + $query_params[0] = $where_params; |
|
763 | + // don't use $query_params with count() |
|
764 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
765 | + return $count |
|
766 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
767 | + : $this->get_all($query_params); |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + |
|
772 | + /** |
|
773 | + * This basically just returns the events that do not have the publish status. |
|
774 | + * |
|
775 | + * @param array $query_params An array of query params to further filter on |
|
776 | + * (note that status will be overwritten) |
|
777 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
778 | + * @return EE_Event[]|int |
|
779 | + * @throws EE_Error |
|
780 | + */ |
|
781 | + public function get_inactive_events($query_params, $count = false) |
|
782 | + { |
|
783 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
784 | + // let's add in specific query_params for inactive events. |
|
785 | + if (isset($where_params['status'])) { |
|
786 | + unset($where_params['status']); |
|
787 | + } |
|
788 | + // if we have count make sure we don't include group by |
|
789 | + if ($count && isset($query_params['group_by'])) { |
|
790 | + unset($query_params['group_by']); |
|
791 | + } |
|
792 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
793 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
794 | + if (isset($where_params['OR'])) { |
|
795 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
796 | + unset($where_params['OR']); |
|
797 | + } |
|
798 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
799 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
800 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
801 | + } |
|
802 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
803 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
804 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
805 | + } |
|
806 | + $query_params[0] = $where_params; |
|
807 | + // don't use $query_params with count() |
|
808 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
809 | + return $count |
|
810 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
811 | + : $this->get_all($query_params); |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + /** |
|
816 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
817 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
818 | + * attached to the event. See parent for param descriptions |
|
819 | + * |
|
820 | + * @param $id_or_obj |
|
821 | + * @param $other_model_id_or_obj |
|
822 | + * @param string $relationName |
|
823 | + * @param array $where_query |
|
824 | + * @return EE_Base_Class |
|
825 | + * @throws EE_Error |
|
826 | + * @throws ReflectionException |
|
827 | + */ |
|
828 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
829 | + { |
|
830 | + if ($relationName === 'Price') { |
|
831 | + // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
832 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
833 | + // if EVT_ID = 0, then this is a default |
|
834 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
835 | + // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
836 | + $prc_chk->set('PRC_ID', 0); |
|
837 | + } |
|
838 | + // run parent |
|
839 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
840 | + } |
|
841 | + // otherwise carry on as normal |
|
842 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
843 | + } |
|
844 | + |
|
845 | + |
|
846 | + |
|
847 | + /******************** DEPRECATED METHODS ********************/ |
|
848 | + |
|
849 | + |
|
850 | + /** |
|
851 | + * _get_question_target_db_column |
|
852 | + * |
|
853 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
854 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
855 | + * registration). |
|
856 | + * @return array |
|
857 | + * @throws ReflectionException |
|
858 | + * @throws EE_Error*@deprecated as of 4.8.32.rc.001. Instead consider using |
|
859 | + * EE_Registration_Custom_Questions_Form located in |
|
860 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
861 | + * @access public |
|
862 | + */ |
|
863 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
864 | + { |
|
865 | + if (empty($EVT_ID)) { |
|
866 | + throw new EE_Error(__( |
|
867 | + 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
868 | + 'event_espresso' |
|
869 | + )); |
|
870 | + } |
|
871 | + $questions = array(); |
|
872 | + // get all question groups for event |
|
873 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
874 | + if (! empty($qgs)) { |
|
875 | + foreach ($qgs as $qg) { |
|
876 | + $qsts = $qg->questions(); |
|
877 | + $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
878 | + $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
879 | + foreach ($qsts as $qst) { |
|
880 | + if ($qst->is_system_question()) { |
|
881 | + continue; |
|
882 | + } |
|
883 | + $answer = EEM_Answer::instance()->get_one(array( |
|
884 | + array( |
|
885 | + 'QST_ID' => $qst->ID(), |
|
886 | + 'REG_ID' => $registration->ID(), |
|
887 | + ), |
|
888 | + )); |
|
889 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
890 | + $qst_name = $qstn_id = $qst->ID(); |
|
891 | + $ans_id = $answer->ID(); |
|
892 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
893 | + $input_name = ''; |
|
894 | + $input_id = sanitize_key($qst->display_text()); |
|
895 | + $input_class = ''; |
|
896 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
897 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
898 | + . $input_name |
|
899 | + . $qst_name; |
|
900 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
901 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
902 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
903 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
904 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
905 | + // leave responses as-is, don't convert stuff into html entities please! |
|
906 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
907 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
908 | + $QSOs = $qst->options(true, $answer->value()); |
|
909 | + if (is_array($QSOs)) { |
|
910 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
911 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
912 | + } |
|
913 | + } |
|
914 | + } |
|
915 | + } |
|
916 | + } |
|
917 | + } |
|
918 | + return $questions; |
|
919 | + } |
|
920 | + |
|
921 | + |
|
922 | + /** |
|
923 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
924 | + * or an stdClass where each property is the name of a column, |
|
925 | + * @return EE_Base_Class |
|
926 | + * @throws EE_Error |
|
927 | + */ |
|
928 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
929 | + { |
|
930 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
931 | + if ($classInstance instanceof EE_Event) { |
|
932 | + // events have their timezone defined in the DB, so use it immediately |
|
933 | + $this->set_timezone($classInstance->get_timezone()); |
|
934 | + } |
|
935 | + return $classInstance; |
|
936 | + } |
|
937 | 937 | } |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | ); |
325 | 325 | $query = $wpdb->prepare( |
326 | 326 | 'DELETE li |
327 | - FROM ' . $this->table() . ' li |
|
328 | - LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
|
327 | + FROM ' . $this->table().' li |
|
328 | + LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID |
|
329 | 329 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
330 | 330 | // use GMT time because that's what TXN_timestamps are in |
331 | 331 | date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | */ |
599 | 599 | public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
600 | 600 | { |
601 | - if (! absint($timestamp)) { |
|
601 | + if ( ! absint($timestamp)) { |
|
602 | 602 | /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
603 | 603 | $session_lifespan = LoaderFactory::getLoader()->getShared( |
604 | 604 | 'EventEspresso\core\domain\values\session\SessionLifespan' |
@@ -28,602 +28,602 @@ |
||
28 | 28 | class EEM_Line_Item extends EEM_Base |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
33 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
34 | - * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
35 | - */ |
|
36 | - const type_tax_sub_total = 'tax-sub-total'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
40 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
41 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
42 | - */ |
|
43 | - const type_tax = 'tax'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Indicating individual items purchased, or discounts or surcharges. |
|
47 | - * The sum of all the regular line items plus the tax items should equal the grand total. |
|
48 | - * Possible children are sub-line-items and cancellations. |
|
49 | - * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
50 | - * LIN_totals. Its LIN_percent = 0. |
|
51 | - * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
52 | - * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
53 | - */ |
|
54 | - const type_line_item = 'line-item'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Line item indicating all the factors that make a single line item. |
|
58 | - * Sub-line items should have NO children line items. |
|
59 | - * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
60 | - * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
61 | - * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
62 | - * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
63 | - * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
64 | - */ |
|
65 | - const type_sub_line_item = 'sub-item'; |
|
66 | - |
|
67 | - /** |
|
68 | - * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
69 | - * Direct children should be event subtotals. |
|
70 | - * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
71 | - */ |
|
72 | - const type_sub_total = 'sub-total'; |
|
73 | - |
|
74 | - /** |
|
75 | - * Line item for the grand total of an order. |
|
76 | - * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
77 | - * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
78 | - * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
79 | - */ |
|
80 | - const type_total = 'total'; |
|
81 | - |
|
82 | - /** |
|
83 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
84 | - * should be created, indicating the quantity that were cancelled |
|
85 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
86 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
87 | - * cancelled, and only one remains). |
|
88 | - * When items are refunded, a cancellation line item should be made, which points |
|
89 | - * to teh payment model object which actually refunded the payment. |
|
90 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
91 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
92 | - * Their LIN_percent should be 0. |
|
93 | - */ |
|
94 | - const type_cancellation = 'cancellation'; |
|
95 | - |
|
96 | - // various line item object types |
|
97 | - const OBJ_TYPE_EVENT = 'Event'; |
|
98 | - |
|
99 | - const OBJ_TYPE_PRICE = 'Price'; |
|
100 | - |
|
101 | - const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
102 | - |
|
103 | - const OBJ_TYPE_TICKET = 'Ticket'; |
|
104 | - |
|
105 | - const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
106 | - |
|
107 | - /** |
|
108 | - * @var EEM_Line_Item $_instance |
|
109 | - */ |
|
110 | - protected static $_instance; |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * private constructor to prevent direct creation |
|
115 | - * |
|
116 | - * @Constructor |
|
117 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
118 | - * (and any incoming timezone data that gets saved). |
|
119 | - * Note this just sends the timezone info to the date time model field objects. |
|
120 | - * Default is NULL |
|
121 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
122 | - * @throws EE_Error |
|
123 | - * @throws InvalidArgumentException |
|
124 | - */ |
|
125 | - protected function __construct($timezone) |
|
126 | - { |
|
127 | - $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
128 | - $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
129 | - |
|
130 | - $this->_tables = array( |
|
131 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
132 | - ); |
|
133 | - $line_items_can_be_for = apply_filters( |
|
134 | - 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
135 | - array('Ticket', 'Price', 'Event') |
|
136 | - ); |
|
137 | - $this->_fields = array( |
|
138 | - 'Line_Item' => array( |
|
139 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
140 | - 'LIN_ID', |
|
141 | - esc_html__('ID', 'event_espresso') |
|
142 | - ), |
|
143 | - 'LIN_code' => new EE_Slug_Field( |
|
144 | - 'LIN_code', |
|
145 | - esc_html__('Code for index into Cart', 'event_espresso'), |
|
146 | - true |
|
147 | - ), |
|
148 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
149 | - 'TXN_ID', |
|
150 | - esc_html__('Transaction ID', 'event_espresso'), |
|
151 | - true, |
|
152 | - null, |
|
153 | - 'Transaction' |
|
154 | - ), |
|
155 | - 'LIN_name' => new EE_Full_HTML_Field( |
|
156 | - 'LIN_name', |
|
157 | - esc_html__('Line Item Name', 'event_espresso'), |
|
158 | - false, |
|
159 | - '' |
|
160 | - ), |
|
161 | - 'LIN_desc' => new EE_Full_HTML_Field( |
|
162 | - 'LIN_desc', |
|
163 | - esc_html__('Line Item Description', 'event_espresso'), |
|
164 | - true |
|
165 | - ), |
|
166 | - 'LIN_unit_price' => new EE_Money_Field( |
|
167 | - 'LIN_unit_price', |
|
168 | - esc_html__('Unit Price', 'event_espresso'), |
|
169 | - false, |
|
170 | - 0 |
|
171 | - ), |
|
172 | - 'LIN_percent' => new EE_Float_Field( |
|
173 | - 'LIN_percent', |
|
174 | - esc_html__('Percent', 'event_espresso'), |
|
175 | - false, |
|
176 | - 0 |
|
177 | - ), |
|
178 | - 'LIN_is_taxable' => new EE_Boolean_Field( |
|
179 | - 'LIN_is_taxable', |
|
180 | - esc_html__('Taxable', 'event_espresso'), |
|
181 | - false, |
|
182 | - false |
|
183 | - ), |
|
184 | - 'LIN_order' => new EE_Integer_Field( |
|
185 | - 'LIN_order', |
|
186 | - esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
187 | - false, |
|
188 | - 1 |
|
189 | - ), |
|
190 | - 'LIN_total' => new EE_Money_Field( |
|
191 | - 'LIN_total', |
|
192 | - esc_html__('Total (unit price x quantity)', 'event_espresso'), |
|
193 | - false, |
|
194 | - 0 |
|
195 | - ), |
|
196 | - 'LIN_quantity' => new EE_Integer_Field( |
|
197 | - 'LIN_quantity', |
|
198 | - esc_html__('Quantity', 'event_espresso'), |
|
199 | - true, |
|
200 | - 1 |
|
201 | - ), |
|
202 | - 'LIN_parent' => new EE_Integer_Field( |
|
203 | - 'LIN_parent', |
|
204 | - esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
205 | - true, |
|
206 | - null |
|
207 | - ), |
|
208 | - 'LIN_type' => new EE_Enum_Text_Field( |
|
209 | - 'LIN_type', |
|
210 | - esc_html__('Type', 'event_espresso'), |
|
211 | - false, |
|
212 | - 'line-item', |
|
213 | - array( |
|
214 | - self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
215 | - self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
216 | - self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
217 | - self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
218 | - self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
219 | - self::type_total => esc_html__('Total', 'event_espresso'), |
|
220 | - self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
221 | - ) |
|
222 | - ), |
|
223 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
224 | - 'OBJ_ID', |
|
225 | - esc_html__('ID of Item purchased.', 'event_espresso'), |
|
226 | - true, |
|
227 | - null, |
|
228 | - $line_items_can_be_for |
|
229 | - ), |
|
230 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
231 | - 'OBJ_type', |
|
232 | - esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
233 | - true, |
|
234 | - null, |
|
235 | - $line_items_can_be_for |
|
236 | - ), |
|
237 | - 'LIN_timestamp' => new EE_Datetime_Field( |
|
238 | - 'LIN_timestamp', |
|
239 | - esc_html__('When the line item was created', 'event_espresso'), |
|
240 | - false, |
|
241 | - EE_Datetime_Field::now, |
|
242 | - $timezone |
|
243 | - ), |
|
244 | - ), |
|
245 | - ); |
|
246 | - $this->_model_relations = array( |
|
247 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
248 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
249 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
250 | - 'Event' => new EE_Belongs_To_Any_Relation(), |
|
251 | - ); |
|
252 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
253 | - $this->_caps_slug = 'transactions'; |
|
254 | - parent::__construct($timezone); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Gets all the line items for this transaction of the given type |
|
260 | - * |
|
261 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
262 | - * @param EE_Transaction|int $transaction |
|
263 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
264 | - * @throws EE_Error |
|
265 | - * @throws InvalidArgumentException |
|
266 | - * @throws InvalidDataTypeException |
|
267 | - * @throws InvalidInterfaceException |
|
268 | - */ |
|
269 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
270 | - { |
|
271 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
272 | - return $this->get_all(array( |
|
273 | - array( |
|
274 | - 'LIN_type' => $line_item_type, |
|
275 | - 'TXN_ID' => $transaction, |
|
276 | - ), |
|
277 | - )); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Gets all line items unrelated to tickets that are normal line items |
|
283 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
284 | - * |
|
285 | - * @param EE_Transaction|int $transaction |
|
286 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
287 | - * @throws EE_Error |
|
288 | - * @throws InvalidArgumentException |
|
289 | - * @throws InvalidDataTypeException |
|
290 | - * @throws InvalidInterfaceException |
|
291 | - */ |
|
292 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
293 | - { |
|
294 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
295 | - return $this->get_all(array( |
|
296 | - array( |
|
297 | - 'LIN_type' => self::type_line_item, |
|
298 | - 'TXN_ID' => $transaction, |
|
299 | - 'OR' => array( |
|
300 | - 'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET), |
|
301 | - 'OBJ_type*null' => array('IS_NULL'), |
|
302 | - ), |
|
303 | - ), |
|
304 | - )); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
310 | - * This needs to be very efficient |
|
311 | - * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
312 | - * deleting and joining tables like this. |
|
313 | - * |
|
314 | - * @return int count of how many deleted |
|
315 | - * @throws EE_Error |
|
316 | - * @throws InvalidArgumentException |
|
317 | - * @throws InvalidDataTypeException |
|
318 | - * @throws InvalidInterfaceException |
|
319 | - */ |
|
320 | - public function delete_line_items_with_no_transaction() |
|
321 | - { |
|
322 | - /** @type WPDB $wpdb */ |
|
323 | - global $wpdb; |
|
324 | - $time_to_leave_alone = apply_filters( |
|
325 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
326 | - WEEK_IN_SECONDS |
|
327 | - ); |
|
328 | - $query = $wpdb->prepare( |
|
329 | - 'DELETE li |
|
31 | + /** |
|
32 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
33 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
34 | + * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
35 | + */ |
|
36 | + const type_tax_sub_total = 'tax-sub-total'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
40 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
41 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
42 | + */ |
|
43 | + const type_tax = 'tax'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Indicating individual items purchased, or discounts or surcharges. |
|
47 | + * The sum of all the regular line items plus the tax items should equal the grand total. |
|
48 | + * Possible children are sub-line-items and cancellations. |
|
49 | + * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
50 | + * LIN_totals. Its LIN_percent = 0. |
|
51 | + * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
52 | + * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
53 | + */ |
|
54 | + const type_line_item = 'line-item'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Line item indicating all the factors that make a single line item. |
|
58 | + * Sub-line items should have NO children line items. |
|
59 | + * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
60 | + * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
61 | + * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
62 | + * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
63 | + * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
64 | + */ |
|
65 | + const type_sub_line_item = 'sub-item'; |
|
66 | + |
|
67 | + /** |
|
68 | + * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
69 | + * Direct children should be event subtotals. |
|
70 | + * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
71 | + */ |
|
72 | + const type_sub_total = 'sub-total'; |
|
73 | + |
|
74 | + /** |
|
75 | + * Line item for the grand total of an order. |
|
76 | + * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
77 | + * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
78 | + * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
79 | + */ |
|
80 | + const type_total = 'total'; |
|
81 | + |
|
82 | + /** |
|
83 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
84 | + * should be created, indicating the quantity that were cancelled |
|
85 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
86 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
87 | + * cancelled, and only one remains). |
|
88 | + * When items are refunded, a cancellation line item should be made, which points |
|
89 | + * to teh payment model object which actually refunded the payment. |
|
90 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
91 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
92 | + * Their LIN_percent should be 0. |
|
93 | + */ |
|
94 | + const type_cancellation = 'cancellation'; |
|
95 | + |
|
96 | + // various line item object types |
|
97 | + const OBJ_TYPE_EVENT = 'Event'; |
|
98 | + |
|
99 | + const OBJ_TYPE_PRICE = 'Price'; |
|
100 | + |
|
101 | + const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
102 | + |
|
103 | + const OBJ_TYPE_TICKET = 'Ticket'; |
|
104 | + |
|
105 | + const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
106 | + |
|
107 | + /** |
|
108 | + * @var EEM_Line_Item $_instance |
|
109 | + */ |
|
110 | + protected static $_instance; |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * private constructor to prevent direct creation |
|
115 | + * |
|
116 | + * @Constructor |
|
117 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
118 | + * (and any incoming timezone data that gets saved). |
|
119 | + * Note this just sends the timezone info to the date time model field objects. |
|
120 | + * Default is NULL |
|
121 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
122 | + * @throws EE_Error |
|
123 | + * @throws InvalidArgumentException |
|
124 | + */ |
|
125 | + protected function __construct($timezone) |
|
126 | + { |
|
127 | + $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
128 | + $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
129 | + |
|
130 | + $this->_tables = array( |
|
131 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
132 | + ); |
|
133 | + $line_items_can_be_for = apply_filters( |
|
134 | + 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
135 | + array('Ticket', 'Price', 'Event') |
|
136 | + ); |
|
137 | + $this->_fields = array( |
|
138 | + 'Line_Item' => array( |
|
139 | + 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
140 | + 'LIN_ID', |
|
141 | + esc_html__('ID', 'event_espresso') |
|
142 | + ), |
|
143 | + 'LIN_code' => new EE_Slug_Field( |
|
144 | + 'LIN_code', |
|
145 | + esc_html__('Code for index into Cart', 'event_espresso'), |
|
146 | + true |
|
147 | + ), |
|
148 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
149 | + 'TXN_ID', |
|
150 | + esc_html__('Transaction ID', 'event_espresso'), |
|
151 | + true, |
|
152 | + null, |
|
153 | + 'Transaction' |
|
154 | + ), |
|
155 | + 'LIN_name' => new EE_Full_HTML_Field( |
|
156 | + 'LIN_name', |
|
157 | + esc_html__('Line Item Name', 'event_espresso'), |
|
158 | + false, |
|
159 | + '' |
|
160 | + ), |
|
161 | + 'LIN_desc' => new EE_Full_HTML_Field( |
|
162 | + 'LIN_desc', |
|
163 | + esc_html__('Line Item Description', 'event_espresso'), |
|
164 | + true |
|
165 | + ), |
|
166 | + 'LIN_unit_price' => new EE_Money_Field( |
|
167 | + 'LIN_unit_price', |
|
168 | + esc_html__('Unit Price', 'event_espresso'), |
|
169 | + false, |
|
170 | + 0 |
|
171 | + ), |
|
172 | + 'LIN_percent' => new EE_Float_Field( |
|
173 | + 'LIN_percent', |
|
174 | + esc_html__('Percent', 'event_espresso'), |
|
175 | + false, |
|
176 | + 0 |
|
177 | + ), |
|
178 | + 'LIN_is_taxable' => new EE_Boolean_Field( |
|
179 | + 'LIN_is_taxable', |
|
180 | + esc_html__('Taxable', 'event_espresso'), |
|
181 | + false, |
|
182 | + false |
|
183 | + ), |
|
184 | + 'LIN_order' => new EE_Integer_Field( |
|
185 | + 'LIN_order', |
|
186 | + esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
187 | + false, |
|
188 | + 1 |
|
189 | + ), |
|
190 | + 'LIN_total' => new EE_Money_Field( |
|
191 | + 'LIN_total', |
|
192 | + esc_html__('Total (unit price x quantity)', 'event_espresso'), |
|
193 | + false, |
|
194 | + 0 |
|
195 | + ), |
|
196 | + 'LIN_quantity' => new EE_Integer_Field( |
|
197 | + 'LIN_quantity', |
|
198 | + esc_html__('Quantity', 'event_espresso'), |
|
199 | + true, |
|
200 | + 1 |
|
201 | + ), |
|
202 | + 'LIN_parent' => new EE_Integer_Field( |
|
203 | + 'LIN_parent', |
|
204 | + esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
205 | + true, |
|
206 | + null |
|
207 | + ), |
|
208 | + 'LIN_type' => new EE_Enum_Text_Field( |
|
209 | + 'LIN_type', |
|
210 | + esc_html__('Type', 'event_espresso'), |
|
211 | + false, |
|
212 | + 'line-item', |
|
213 | + array( |
|
214 | + self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
215 | + self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
216 | + self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
217 | + self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
218 | + self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
219 | + self::type_total => esc_html__('Total', 'event_espresso'), |
|
220 | + self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
221 | + ) |
|
222 | + ), |
|
223 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
224 | + 'OBJ_ID', |
|
225 | + esc_html__('ID of Item purchased.', 'event_espresso'), |
|
226 | + true, |
|
227 | + null, |
|
228 | + $line_items_can_be_for |
|
229 | + ), |
|
230 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
231 | + 'OBJ_type', |
|
232 | + esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
233 | + true, |
|
234 | + null, |
|
235 | + $line_items_can_be_for |
|
236 | + ), |
|
237 | + 'LIN_timestamp' => new EE_Datetime_Field( |
|
238 | + 'LIN_timestamp', |
|
239 | + esc_html__('When the line item was created', 'event_espresso'), |
|
240 | + false, |
|
241 | + EE_Datetime_Field::now, |
|
242 | + $timezone |
|
243 | + ), |
|
244 | + ), |
|
245 | + ); |
|
246 | + $this->_model_relations = array( |
|
247 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
248 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
249 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
250 | + 'Event' => new EE_Belongs_To_Any_Relation(), |
|
251 | + ); |
|
252 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
253 | + $this->_caps_slug = 'transactions'; |
|
254 | + parent::__construct($timezone); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Gets all the line items for this transaction of the given type |
|
260 | + * |
|
261 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
262 | + * @param EE_Transaction|int $transaction |
|
263 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
264 | + * @throws EE_Error |
|
265 | + * @throws InvalidArgumentException |
|
266 | + * @throws InvalidDataTypeException |
|
267 | + * @throws InvalidInterfaceException |
|
268 | + */ |
|
269 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
270 | + { |
|
271 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
272 | + return $this->get_all(array( |
|
273 | + array( |
|
274 | + 'LIN_type' => $line_item_type, |
|
275 | + 'TXN_ID' => $transaction, |
|
276 | + ), |
|
277 | + )); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Gets all line items unrelated to tickets that are normal line items |
|
283 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
284 | + * |
|
285 | + * @param EE_Transaction|int $transaction |
|
286 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
287 | + * @throws EE_Error |
|
288 | + * @throws InvalidArgumentException |
|
289 | + * @throws InvalidDataTypeException |
|
290 | + * @throws InvalidInterfaceException |
|
291 | + */ |
|
292 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
293 | + { |
|
294 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
295 | + return $this->get_all(array( |
|
296 | + array( |
|
297 | + 'LIN_type' => self::type_line_item, |
|
298 | + 'TXN_ID' => $transaction, |
|
299 | + 'OR' => array( |
|
300 | + 'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET), |
|
301 | + 'OBJ_type*null' => array('IS_NULL'), |
|
302 | + ), |
|
303 | + ), |
|
304 | + )); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
310 | + * This needs to be very efficient |
|
311 | + * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
312 | + * deleting and joining tables like this. |
|
313 | + * |
|
314 | + * @return int count of how many deleted |
|
315 | + * @throws EE_Error |
|
316 | + * @throws InvalidArgumentException |
|
317 | + * @throws InvalidDataTypeException |
|
318 | + * @throws InvalidInterfaceException |
|
319 | + */ |
|
320 | + public function delete_line_items_with_no_transaction() |
|
321 | + { |
|
322 | + /** @type WPDB $wpdb */ |
|
323 | + global $wpdb; |
|
324 | + $time_to_leave_alone = apply_filters( |
|
325 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
326 | + WEEK_IN_SECONDS |
|
327 | + ); |
|
328 | + $query = $wpdb->prepare( |
|
329 | + 'DELETE li |
|
330 | 330 | FROM ' . $this->table() . ' li |
331 | 331 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
332 | 332 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
333 | - // use GMT time because that's what TXN_timestamps are in |
|
334 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
335 | - ); |
|
336 | - return $wpdb->query($query); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * get_line_item_for_transaction_object |
|
342 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
343 | - * |
|
344 | - * @param int $TXN_ID |
|
345 | - * @param EE_Base_Class $object |
|
346 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
347 | - * @throws EE_Error |
|
348 | - * @throws InvalidArgumentException |
|
349 | - * @throws InvalidDataTypeException |
|
350 | - * @throws InvalidInterfaceException |
|
351 | - * @throws ReflectionException |
|
352 | - */ |
|
353 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
354 | - { |
|
355 | - return $this->get_all(array( |
|
356 | - array( |
|
357 | - 'TXN_ID' => $TXN_ID, |
|
358 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
359 | - 'OBJ_ID' => $object->ID(), |
|
360 | - ), |
|
361 | - )); |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * get_object_line_items_for_transaction |
|
367 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
368 | - * |
|
369 | - * @param int $TXN_ID |
|
370 | - * @param string $OBJ_type |
|
371 | - * @param array $OBJ_IDs |
|
372 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
373 | - * @throws EE_Error |
|
374 | - */ |
|
375 | - public function get_object_line_items_for_transaction( |
|
376 | - $TXN_ID, |
|
377 | - $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
378 | - $OBJ_IDs = array() |
|
379 | - ) { |
|
380 | - $query_params = array( |
|
381 | - 'OBJ_type' => $OBJ_type, |
|
382 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
383 | - 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs, |
|
384 | - ); |
|
385 | - if ($TXN_ID) { |
|
386 | - $query_params['TXN_ID'] = $TXN_ID; |
|
387 | - } |
|
388 | - return $this->get_all(array($query_params)); |
|
389 | - } |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * get_all_ticket_line_items_for_transaction |
|
394 | - * |
|
395 | - * @param EE_Transaction $transaction |
|
396 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
397 | - * @throws EE_Error |
|
398 | - * @throws InvalidArgumentException |
|
399 | - * @throws InvalidDataTypeException |
|
400 | - * @throws InvalidInterfaceException |
|
401 | - * @throws ReflectionException |
|
402 | - */ |
|
403 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
404 | - { |
|
405 | - return $this->get_all(array( |
|
406 | - array( |
|
407 | - 'TXN_ID' => $transaction->ID(), |
|
408 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
409 | - ), |
|
410 | - )); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * get_ticket_line_item_for_transaction |
|
416 | - * |
|
417 | - * @param int $TXN_ID |
|
418 | - * @param int $TKT_ID |
|
419 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
420 | - * @throws EE_Error |
|
421 | - * @throws InvalidArgumentException |
|
422 | - * @throws InvalidDataTypeException |
|
423 | - * @throws InvalidInterfaceException |
|
424 | - */ |
|
425 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
426 | - { |
|
427 | - return $this->get_one(array( |
|
428 | - array( |
|
429 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
430 | - 'OBJ_ID' => $TKT_ID, |
|
431 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
432 | - ), |
|
433 | - )); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * get_existing_promotion_line_item |
|
439 | - * searches the cart for existing line items for the specified promotion |
|
440 | - * |
|
441 | - * @since 1.0.0 |
|
442 | - * @param EE_Line_Item $parent_line_item |
|
443 | - * @param EE_Promotion $promotion |
|
444 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
445 | - * @throws EE_Error |
|
446 | - * @throws InvalidArgumentException |
|
447 | - * @throws InvalidDataTypeException |
|
448 | - * @throws InvalidInterfaceException |
|
449 | - * @throws ReflectionException |
|
450 | - */ |
|
451 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
452 | - { |
|
453 | - return $this->get_one(array( |
|
454 | - array( |
|
455 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
456 | - 'LIN_parent' => $parent_line_item->ID(), |
|
457 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
458 | - 'OBJ_ID' => $promotion->ID(), |
|
459 | - ), |
|
460 | - )); |
|
461 | - } |
|
462 | - |
|
463 | - |
|
464 | - /** |
|
465 | - * get_all_promotion_line_items |
|
466 | - * searches the cart for any and all existing promotion line items |
|
467 | - * |
|
468 | - * @since 1.0.0 |
|
469 | - * @param EE_Line_Item $parent_line_item |
|
470 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
471 | - * @throws EE_Error |
|
472 | - * @throws InvalidArgumentException |
|
473 | - * @throws InvalidDataTypeException |
|
474 | - * @throws InvalidInterfaceException |
|
475 | - * @throws ReflectionException |
|
476 | - */ |
|
477 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
478 | - { |
|
479 | - return $this->get_all(array( |
|
480 | - array( |
|
481 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
482 | - 'LIN_parent' => $parent_line_item->ID(), |
|
483 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
484 | - ), |
|
485 | - )); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * Gets the registration's corresponding line item. |
|
491 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
492 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
493 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
494 | - * |
|
495 | - * @param EE_Registration $registration |
|
496 | - * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
497 | - * @throws EE_Error |
|
498 | - */ |
|
499 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
500 | - { |
|
501 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
507 | - * |
|
508 | - * @param EE_Registration $registration |
|
509 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
510 | - * @return array @see |
|
511 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
512 | - * @throws EE_Error |
|
513 | - */ |
|
514 | - public function line_item_for_registration_query_params( |
|
515 | - EE_Registration $registration, |
|
516 | - $original_query_params = array() |
|
517 | - ) { |
|
518 | - return array_replace_recursive($original_query_params, array( |
|
519 | - array( |
|
520 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
521 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
522 | - 'TXN_ID' => $registration->transaction_ID(), |
|
523 | - ), |
|
524 | - )); |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
530 | - * @throws InvalidInterfaceException |
|
531 | - * @throws InvalidDataTypeException |
|
532 | - * @throws EE_Error |
|
533 | - * @throws InvalidArgumentException |
|
534 | - */ |
|
535 | - public function get_total_line_items_with_no_transaction() |
|
536 | - { |
|
537 | - return $this->get_total_line_items_for_carts(); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
543 | - * @throws InvalidInterfaceException |
|
544 | - * @throws InvalidDataTypeException |
|
545 | - * @throws EE_Error |
|
546 | - * @throws InvalidArgumentException |
|
547 | - */ |
|
548 | - public function get_total_line_items_for_active_carts() |
|
549 | - { |
|
550 | - return $this->get_total_line_items_for_carts(false); |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
556 | - * @throws InvalidInterfaceException |
|
557 | - * @throws InvalidDataTypeException |
|
558 | - * @throws EE_Error |
|
559 | - * @throws InvalidArgumentException |
|
560 | - */ |
|
561 | - public function get_total_line_items_for_expired_carts() |
|
562 | - { |
|
563 | - return $this->get_total_line_items_for_carts(true); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
569 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
570 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
571 | - * |
|
572 | - * @param null $expired |
|
573 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
574 | - * @throws EE_Error |
|
575 | - * @throws InvalidArgumentException |
|
576 | - * @throws InvalidDataTypeException |
|
577 | - * @throws InvalidInterfaceException |
|
578 | - */ |
|
579 | - private function get_total_line_items_for_carts($expired = null) |
|
580 | - { |
|
581 | - $where_params = array( |
|
582 | - 'TXN_ID' => 0, |
|
583 | - 'LIN_type' => 'total', |
|
584 | - ); |
|
585 | - if ($expired !== null) { |
|
586 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
587 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
588 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
589 | - ); |
|
590 | - $where_params['LIN_timestamp'] = array( |
|
591 | - $expired ? '<=' : '>', |
|
592 | - $session_lifespan->expiration(), |
|
593 | - ); |
|
594 | - } |
|
595 | - return $this->get_all(array($where_params)); |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * Returns an array of ticket total line items where the TXN_ID is 0 |
|
601 | - * AND the timestamp is older than the session lifespan. |
|
602 | - * |
|
603 | - * @param int $timestamp |
|
604 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
605 | - * @throws EE_Error |
|
606 | - * @throws InvalidArgumentException |
|
607 | - * @throws InvalidDataTypeException |
|
608 | - * @throws InvalidInterfaceException |
|
609 | - */ |
|
610 | - public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
611 | - { |
|
612 | - if (! absint($timestamp)) { |
|
613 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
614 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
615 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
616 | - ); |
|
617 | - $timestamp = $session_lifespan->expiration(); |
|
618 | - } |
|
619 | - return $this->get_all( |
|
620 | - array( |
|
621 | - array( |
|
622 | - 'TXN_ID' => 0, |
|
623 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
624 | - 'LIN_timestamp' => array('<=', $timestamp), |
|
625 | - ), |
|
626 | - ) |
|
627 | - ); |
|
628 | - } |
|
333 | + // use GMT time because that's what TXN_timestamps are in |
|
334 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
335 | + ); |
|
336 | + return $wpdb->query($query); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * get_line_item_for_transaction_object |
|
342 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
343 | + * |
|
344 | + * @param int $TXN_ID |
|
345 | + * @param EE_Base_Class $object |
|
346 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
347 | + * @throws EE_Error |
|
348 | + * @throws InvalidArgumentException |
|
349 | + * @throws InvalidDataTypeException |
|
350 | + * @throws InvalidInterfaceException |
|
351 | + * @throws ReflectionException |
|
352 | + */ |
|
353 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
354 | + { |
|
355 | + return $this->get_all(array( |
|
356 | + array( |
|
357 | + 'TXN_ID' => $TXN_ID, |
|
358 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
359 | + 'OBJ_ID' => $object->ID(), |
|
360 | + ), |
|
361 | + )); |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * get_object_line_items_for_transaction |
|
367 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
368 | + * |
|
369 | + * @param int $TXN_ID |
|
370 | + * @param string $OBJ_type |
|
371 | + * @param array $OBJ_IDs |
|
372 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
373 | + * @throws EE_Error |
|
374 | + */ |
|
375 | + public function get_object_line_items_for_transaction( |
|
376 | + $TXN_ID, |
|
377 | + $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
378 | + $OBJ_IDs = array() |
|
379 | + ) { |
|
380 | + $query_params = array( |
|
381 | + 'OBJ_type' => $OBJ_type, |
|
382 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
383 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs, |
|
384 | + ); |
|
385 | + if ($TXN_ID) { |
|
386 | + $query_params['TXN_ID'] = $TXN_ID; |
|
387 | + } |
|
388 | + return $this->get_all(array($query_params)); |
|
389 | + } |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * get_all_ticket_line_items_for_transaction |
|
394 | + * |
|
395 | + * @param EE_Transaction $transaction |
|
396 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
397 | + * @throws EE_Error |
|
398 | + * @throws InvalidArgumentException |
|
399 | + * @throws InvalidDataTypeException |
|
400 | + * @throws InvalidInterfaceException |
|
401 | + * @throws ReflectionException |
|
402 | + */ |
|
403 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
404 | + { |
|
405 | + return $this->get_all(array( |
|
406 | + array( |
|
407 | + 'TXN_ID' => $transaction->ID(), |
|
408 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
409 | + ), |
|
410 | + )); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * get_ticket_line_item_for_transaction |
|
416 | + * |
|
417 | + * @param int $TXN_ID |
|
418 | + * @param int $TKT_ID |
|
419 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
420 | + * @throws EE_Error |
|
421 | + * @throws InvalidArgumentException |
|
422 | + * @throws InvalidDataTypeException |
|
423 | + * @throws InvalidInterfaceException |
|
424 | + */ |
|
425 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
426 | + { |
|
427 | + return $this->get_one(array( |
|
428 | + array( |
|
429 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
430 | + 'OBJ_ID' => $TKT_ID, |
|
431 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
432 | + ), |
|
433 | + )); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * get_existing_promotion_line_item |
|
439 | + * searches the cart for existing line items for the specified promotion |
|
440 | + * |
|
441 | + * @since 1.0.0 |
|
442 | + * @param EE_Line_Item $parent_line_item |
|
443 | + * @param EE_Promotion $promotion |
|
444 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
445 | + * @throws EE_Error |
|
446 | + * @throws InvalidArgumentException |
|
447 | + * @throws InvalidDataTypeException |
|
448 | + * @throws InvalidInterfaceException |
|
449 | + * @throws ReflectionException |
|
450 | + */ |
|
451 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
452 | + { |
|
453 | + return $this->get_one(array( |
|
454 | + array( |
|
455 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
456 | + 'LIN_parent' => $parent_line_item->ID(), |
|
457 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
458 | + 'OBJ_ID' => $promotion->ID(), |
|
459 | + ), |
|
460 | + )); |
|
461 | + } |
|
462 | + |
|
463 | + |
|
464 | + /** |
|
465 | + * get_all_promotion_line_items |
|
466 | + * searches the cart for any and all existing promotion line items |
|
467 | + * |
|
468 | + * @since 1.0.0 |
|
469 | + * @param EE_Line_Item $parent_line_item |
|
470 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
471 | + * @throws EE_Error |
|
472 | + * @throws InvalidArgumentException |
|
473 | + * @throws InvalidDataTypeException |
|
474 | + * @throws InvalidInterfaceException |
|
475 | + * @throws ReflectionException |
|
476 | + */ |
|
477 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
478 | + { |
|
479 | + return $this->get_all(array( |
|
480 | + array( |
|
481 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
482 | + 'LIN_parent' => $parent_line_item->ID(), |
|
483 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
484 | + ), |
|
485 | + )); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * Gets the registration's corresponding line item. |
|
491 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
492 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
493 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
494 | + * |
|
495 | + * @param EE_Registration $registration |
|
496 | + * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
497 | + * @throws EE_Error |
|
498 | + */ |
|
499 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
500 | + { |
|
501 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
507 | + * |
|
508 | + * @param EE_Registration $registration |
|
509 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
510 | + * @return array @see |
|
511 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
512 | + * @throws EE_Error |
|
513 | + */ |
|
514 | + public function line_item_for_registration_query_params( |
|
515 | + EE_Registration $registration, |
|
516 | + $original_query_params = array() |
|
517 | + ) { |
|
518 | + return array_replace_recursive($original_query_params, array( |
|
519 | + array( |
|
520 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
521 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
522 | + 'TXN_ID' => $registration->transaction_ID(), |
|
523 | + ), |
|
524 | + )); |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
530 | + * @throws InvalidInterfaceException |
|
531 | + * @throws InvalidDataTypeException |
|
532 | + * @throws EE_Error |
|
533 | + * @throws InvalidArgumentException |
|
534 | + */ |
|
535 | + public function get_total_line_items_with_no_transaction() |
|
536 | + { |
|
537 | + return $this->get_total_line_items_for_carts(); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
543 | + * @throws InvalidInterfaceException |
|
544 | + * @throws InvalidDataTypeException |
|
545 | + * @throws EE_Error |
|
546 | + * @throws InvalidArgumentException |
|
547 | + */ |
|
548 | + public function get_total_line_items_for_active_carts() |
|
549 | + { |
|
550 | + return $this->get_total_line_items_for_carts(false); |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
556 | + * @throws InvalidInterfaceException |
|
557 | + * @throws InvalidDataTypeException |
|
558 | + * @throws EE_Error |
|
559 | + * @throws InvalidArgumentException |
|
560 | + */ |
|
561 | + public function get_total_line_items_for_expired_carts() |
|
562 | + { |
|
563 | + return $this->get_total_line_items_for_carts(true); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
569 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
570 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
571 | + * |
|
572 | + * @param null $expired |
|
573 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
574 | + * @throws EE_Error |
|
575 | + * @throws InvalidArgumentException |
|
576 | + * @throws InvalidDataTypeException |
|
577 | + * @throws InvalidInterfaceException |
|
578 | + */ |
|
579 | + private function get_total_line_items_for_carts($expired = null) |
|
580 | + { |
|
581 | + $where_params = array( |
|
582 | + 'TXN_ID' => 0, |
|
583 | + 'LIN_type' => 'total', |
|
584 | + ); |
|
585 | + if ($expired !== null) { |
|
586 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
587 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
588 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
589 | + ); |
|
590 | + $where_params['LIN_timestamp'] = array( |
|
591 | + $expired ? '<=' : '>', |
|
592 | + $session_lifespan->expiration(), |
|
593 | + ); |
|
594 | + } |
|
595 | + return $this->get_all(array($where_params)); |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * Returns an array of ticket total line items where the TXN_ID is 0 |
|
601 | + * AND the timestamp is older than the session lifespan. |
|
602 | + * |
|
603 | + * @param int $timestamp |
|
604 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
605 | + * @throws EE_Error |
|
606 | + * @throws InvalidArgumentException |
|
607 | + * @throws InvalidDataTypeException |
|
608 | + * @throws InvalidInterfaceException |
|
609 | + */ |
|
610 | + public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
611 | + { |
|
612 | + if (! absint($timestamp)) { |
|
613 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
614 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
615 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
616 | + ); |
|
617 | + $timestamp = $session_lifespan->expiration(); |
|
618 | + } |
|
619 | + return $this->get_all( |
|
620 | + array( |
|
621 | + array( |
|
622 | + 'TXN_ID' => 0, |
|
623 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
624 | + 'LIN_timestamp' => array('<=', $timestamp), |
|
625 | + ), |
|
626 | + ) |
|
627 | + ); |
|
628 | + } |
|
629 | 629 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! class_exists('WP_List_Table')) { |
4 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
4 | + require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -20,847 +20,847 @@ discard block |
||
20 | 20 | abstract class EE_Admin_List_Table extends WP_List_Table |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * holds the data that will be processed for the table |
|
25 | - * |
|
26 | - * @var array $_data |
|
27 | - */ |
|
28 | - protected $_data; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This holds the value of all the data available for the given view (for all pages). |
|
33 | - * |
|
34 | - * @var int $_all_data_count |
|
35 | - */ |
|
36 | - protected $_all_data_count; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Will contain the count of trashed items for the view label. |
|
41 | - * |
|
42 | - * @var int $_trashed_count |
|
43 | - */ |
|
44 | - protected $_trashed_count; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * This is what will be referenced as the slug for the current screen |
|
49 | - * |
|
50 | - * @var string $_screen |
|
51 | - */ |
|
52 | - protected $_screen; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * this is the EE_Admin_Page object |
|
57 | - * |
|
58 | - * @var EE_Admin_Page $_admin_page |
|
59 | - */ |
|
60 | - protected $_admin_page; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * The current view |
|
65 | - * |
|
66 | - * @var string $_view |
|
67 | - */ |
|
68 | - protected $_view; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * array of possible views for this table |
|
73 | - * |
|
74 | - * @var array $_views |
|
75 | - */ |
|
76 | - protected $_views; |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * An array of key => value pairs containing information about the current table |
|
81 | - * array( |
|
82 | - * 'plural' => 'plural label', |
|
83 | - * 'singular' => 'singular label', |
|
84 | - * 'ajax' => false, //whether to use ajax or not |
|
85 | - * 'screen' => null, //string used to reference what screen this is |
|
86 | - * (WP_List_table converts to screen object) |
|
87 | - * ) |
|
88 | - * |
|
89 | - * @var array $_wp_list_args |
|
90 | - */ |
|
91 | - protected $_wp_list_args; |
|
92 | - |
|
93 | - /** |
|
94 | - * an array of column names |
|
95 | - * array( |
|
96 | - * 'internal-name' => 'Title' |
|
97 | - * ) |
|
98 | - * |
|
99 | - * @var array $_columns |
|
100 | - */ |
|
101 | - protected $_columns; |
|
102 | - |
|
103 | - /** |
|
104 | - * An array of sortable columns |
|
105 | - * array( |
|
106 | - * 'internal-name' => 'orderby' //or |
|
107 | - * 'internal-name' => array( 'orderby', true ) |
|
108 | - * ) |
|
109 | - * |
|
110 | - * @var array $_sortable_columns |
|
111 | - */ |
|
112 | - protected $_sortable_columns; |
|
113 | - |
|
114 | - /** |
|
115 | - * callback method used to perform AJAX row reordering |
|
116 | - * |
|
117 | - * @var string $_ajax_sorting_callback |
|
118 | - */ |
|
119 | - protected $_ajax_sorting_callback; |
|
120 | - |
|
121 | - /** |
|
122 | - * An array of hidden columns (if needed) |
|
123 | - * array('internal-name', 'internal-name') |
|
124 | - * |
|
125 | - * @var array $_hidden_columns |
|
126 | - */ |
|
127 | - protected $_hidden_columns; |
|
128 | - |
|
129 | - /** |
|
130 | - * holds the per_page value |
|
131 | - * |
|
132 | - * @var int $_per_page |
|
133 | - */ |
|
134 | - protected $_per_page; |
|
135 | - |
|
136 | - /** |
|
137 | - * holds what page number is currently being viewed |
|
138 | - * |
|
139 | - * @var int $_current_page |
|
140 | - */ |
|
141 | - protected $_current_page; |
|
142 | - |
|
143 | - /** |
|
144 | - * the reference string for the nonce_action |
|
145 | - * |
|
146 | - * @var string $_nonce_action_ref |
|
147 | - */ |
|
148 | - protected $_nonce_action_ref; |
|
149 | - |
|
150 | - /** |
|
151 | - * property to hold incoming request data (as set by the admin_page_core) |
|
152 | - * |
|
153 | - * @var array $_req_data |
|
154 | - */ |
|
155 | - protected $_req_data; |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * yes / no array for admin form fields |
|
160 | - * |
|
161 | - * @var array $_yes_no |
|
162 | - */ |
|
163 | - protected $_yes_no = array(); |
|
164 | - |
|
165 | - /** |
|
166 | - * Array describing buttons that should appear at the bottom of the page |
|
167 | - * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
168 | - * and the values are another array with the following keys |
|
169 | - * array( |
|
170 | - * 'route' => 'page_route', |
|
171 | - * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
172 | - * ) |
|
173 | - * |
|
174 | - * @var array $_bottom_buttons |
|
175 | - */ |
|
176 | - protected $_bottom_buttons = array(); |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Used to indicate what should be the primary column for the list table. |
|
181 | - * If not present then falls back to what WP calculates |
|
182 | - * as the primary column. |
|
183 | - * |
|
184 | - * @type string $_primary_column |
|
185 | - */ |
|
186 | - protected $_primary_column = ''; |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Used to indicate whether the table has a checkbox column or not. |
|
191 | - * |
|
192 | - * @type bool $_has_checkbox_column |
|
193 | - */ |
|
194 | - protected $_has_checkbox_column = false; |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
199 | - */ |
|
200 | - public function __construct(EE_Admin_Page $admin_page) |
|
201 | - { |
|
202 | - $this->_admin_page = $admin_page; |
|
203 | - $this->_req_data = $this->_admin_page->get_request_data(); |
|
204 | - $this->_view = $this->_admin_page->get_view(); |
|
205 | - $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
206 | - $this->_current_page = $this->get_pagenum(); |
|
207 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
208 | - $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
|
209 | - |
|
210 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 20); |
|
211 | - |
|
212 | - $this->_setup_data(); |
|
213 | - $this->_add_view_counts(); |
|
214 | - |
|
215 | - $this->_nonce_action_ref = $this->_view; |
|
216 | - |
|
217 | - $this->_set_properties(); |
|
218 | - |
|
219 | - // set primary column |
|
220 | - add_filter('list_table_primary_column', array($this, 'set_primary_column')); |
|
221 | - |
|
222 | - // set parent defaults |
|
223 | - parent::__construct($this->_wp_list_args); |
|
224 | - |
|
225 | - $this->prepare_items(); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * _setup_data |
|
231 | - * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
232 | - * |
|
233 | - * @uses $this->_admin_page |
|
234 | - * @return void |
|
235 | - */ |
|
236 | - abstract protected function _setup_data(); |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * set the properties that this class needs to be able to execute wp_list_table properly |
|
241 | - * properties set: |
|
242 | - * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
243 | - * _columns = set the columns in an array. |
|
244 | - * _sortable_columns = columns that are sortable (array). |
|
245 | - * _hidden_columns = columns that are hidden (array) |
|
246 | - * _default_orderby = the default orderby for sorting. |
|
247 | - * |
|
248 | - * @abstract |
|
249 | - * @access protected |
|
250 | - * @return void |
|
251 | - */ |
|
252 | - abstract protected function _set_properties(); |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * _get_table_filters |
|
257 | - * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
258 | - * get's shown in the table. |
|
259 | - * |
|
260 | - * @abstract |
|
261 | - * @access protected |
|
262 | - * @return string |
|
263 | - */ |
|
264 | - abstract protected function _get_table_filters(); |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
269 | - * counts of the views is accurate. |
|
270 | - * |
|
271 | - * @abstract |
|
272 | - * @access protected |
|
273 | - * @return void |
|
274 | - */ |
|
275 | - abstract protected function _add_view_counts(); |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * _get_hidden_fields |
|
280 | - * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
281 | - * |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - protected function _get_hidden_fields() |
|
285 | - { |
|
286 | - $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
287 | - $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
288 | - // if action is STILL empty, then we set it to default |
|
289 | - $action = empty($action) ? 'default' : $action; |
|
290 | - $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
291 | - $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
292 | - $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
293 | - |
|
294 | - $bulk_actions = $this->_get_bulk_actions(); |
|
295 | - foreach ($bulk_actions as $bulk_action => $label) { |
|
296 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
297 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
298 | - } |
|
299 | - |
|
300 | - return $field; |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * _set_column_info |
|
306 | - * we're using this to set the column headers property. |
|
307 | - * |
|
308 | - * @access protected |
|
309 | - * @return void |
|
310 | - */ |
|
311 | - protected function _set_column_info() |
|
312 | - { |
|
313 | - $columns = $this->get_columns(); |
|
314 | - $hidden = $this->get_hidden_columns(); |
|
315 | - $_sortable = $this->get_sortable_columns(); |
|
316 | - |
|
317 | - /** |
|
318 | - * Dynamic hook allowing for adding sortable columns in this list table. |
|
319 | - * Note that $this->screen->id is in the format |
|
320 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
321 | - * table it is: event-espresso_page_espresso_messages. |
|
322 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
323 | - * hook prefix ("event-espresso") will be different. |
|
324 | - * |
|
325 | - * @var array |
|
326 | - */ |
|
327 | - $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
328 | - |
|
329 | - $sortable = array(); |
|
330 | - foreach ($_sortable as $id => $data) { |
|
331 | - if (empty($data)) { |
|
332 | - continue; |
|
333 | - } |
|
334 | - // fix for offset errors with WP_List_Table default get_columninfo() |
|
335 | - if (is_array($data)) { |
|
336 | - $_data[0] = key($data); |
|
337 | - $_data[1] = isset($data[1]) ? $data[1] : false; |
|
338 | - } else { |
|
339 | - $_data[0] = $data; |
|
340 | - } |
|
341 | - |
|
342 | - $data = (array) $data; |
|
343 | - |
|
344 | - if (! isset($data[1])) { |
|
345 | - $_data[1] = false; |
|
346 | - } |
|
347 | - |
|
348 | - $sortable[ $id ] = $_data; |
|
349 | - } |
|
350 | - $primary = $this->get_primary_column_name(); |
|
351 | - $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
357 | - * |
|
358 | - * @return string |
|
359 | - */ |
|
360 | - protected function get_primary_column_name() |
|
361 | - { |
|
362 | - foreach (class_parents($this) as $parent) { |
|
363 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
364 | - return parent::get_primary_column_name(); |
|
365 | - } |
|
366 | - } |
|
367 | - return $this->_primary_column; |
|
368 | - } |
|
369 | - |
|
370 | - |
|
371 | - /** |
|
372 | - * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
373 | - * |
|
374 | - * @param EE_Base_Class $item |
|
375 | - * @param string $column_name |
|
376 | - * @param string $primary |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - protected function handle_row_actions($item, $column_name, $primary) |
|
380 | - { |
|
381 | - foreach (class_parents($this) as $parent) { |
|
382 | - if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
383 | - return parent::handle_row_actions($item, $column_name, $primary); |
|
384 | - } |
|
385 | - } |
|
386 | - return ''; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * _get_bulk_actions |
|
392 | - * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
393 | - * |
|
394 | - * @access protected |
|
395 | - * @return array bulk_actions |
|
396 | - */ |
|
397 | - protected function _get_bulk_actions() |
|
398 | - { |
|
399 | - $actions = array(); |
|
400 | - // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
401 | - // formatted array for the wp_list_table(); |
|
402 | - foreach ($this->_views as $view => $args) { |
|
403 | - if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
404 | - // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
405 | - // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
406 | - foreach ($args['bulk_action'] as $route => $label) { |
|
407 | - if ($this->_admin_page->check_user_access($route, true)) { |
|
408 | - $actions[ $route ] = $label; |
|
409 | - } |
|
410 | - } |
|
411 | - } |
|
412 | - } |
|
413 | - return $actions; |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Generate the table navigation above or below the table. |
|
419 | - * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
420 | - * |
|
421 | - * @since 4.9.44.rc.001 |
|
422 | - */ |
|
423 | - public function display_tablenav($which) |
|
424 | - { |
|
425 | - if ('top' === $which) { |
|
426 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
427 | - } |
|
428 | - ?> |
|
23 | + /** |
|
24 | + * holds the data that will be processed for the table |
|
25 | + * |
|
26 | + * @var array $_data |
|
27 | + */ |
|
28 | + protected $_data; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This holds the value of all the data available for the given view (for all pages). |
|
33 | + * |
|
34 | + * @var int $_all_data_count |
|
35 | + */ |
|
36 | + protected $_all_data_count; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Will contain the count of trashed items for the view label. |
|
41 | + * |
|
42 | + * @var int $_trashed_count |
|
43 | + */ |
|
44 | + protected $_trashed_count; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * This is what will be referenced as the slug for the current screen |
|
49 | + * |
|
50 | + * @var string $_screen |
|
51 | + */ |
|
52 | + protected $_screen; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * this is the EE_Admin_Page object |
|
57 | + * |
|
58 | + * @var EE_Admin_Page $_admin_page |
|
59 | + */ |
|
60 | + protected $_admin_page; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * The current view |
|
65 | + * |
|
66 | + * @var string $_view |
|
67 | + */ |
|
68 | + protected $_view; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * array of possible views for this table |
|
73 | + * |
|
74 | + * @var array $_views |
|
75 | + */ |
|
76 | + protected $_views; |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * An array of key => value pairs containing information about the current table |
|
81 | + * array( |
|
82 | + * 'plural' => 'plural label', |
|
83 | + * 'singular' => 'singular label', |
|
84 | + * 'ajax' => false, //whether to use ajax or not |
|
85 | + * 'screen' => null, //string used to reference what screen this is |
|
86 | + * (WP_List_table converts to screen object) |
|
87 | + * ) |
|
88 | + * |
|
89 | + * @var array $_wp_list_args |
|
90 | + */ |
|
91 | + protected $_wp_list_args; |
|
92 | + |
|
93 | + /** |
|
94 | + * an array of column names |
|
95 | + * array( |
|
96 | + * 'internal-name' => 'Title' |
|
97 | + * ) |
|
98 | + * |
|
99 | + * @var array $_columns |
|
100 | + */ |
|
101 | + protected $_columns; |
|
102 | + |
|
103 | + /** |
|
104 | + * An array of sortable columns |
|
105 | + * array( |
|
106 | + * 'internal-name' => 'orderby' //or |
|
107 | + * 'internal-name' => array( 'orderby', true ) |
|
108 | + * ) |
|
109 | + * |
|
110 | + * @var array $_sortable_columns |
|
111 | + */ |
|
112 | + protected $_sortable_columns; |
|
113 | + |
|
114 | + /** |
|
115 | + * callback method used to perform AJAX row reordering |
|
116 | + * |
|
117 | + * @var string $_ajax_sorting_callback |
|
118 | + */ |
|
119 | + protected $_ajax_sorting_callback; |
|
120 | + |
|
121 | + /** |
|
122 | + * An array of hidden columns (if needed) |
|
123 | + * array('internal-name', 'internal-name') |
|
124 | + * |
|
125 | + * @var array $_hidden_columns |
|
126 | + */ |
|
127 | + protected $_hidden_columns; |
|
128 | + |
|
129 | + /** |
|
130 | + * holds the per_page value |
|
131 | + * |
|
132 | + * @var int $_per_page |
|
133 | + */ |
|
134 | + protected $_per_page; |
|
135 | + |
|
136 | + /** |
|
137 | + * holds what page number is currently being viewed |
|
138 | + * |
|
139 | + * @var int $_current_page |
|
140 | + */ |
|
141 | + protected $_current_page; |
|
142 | + |
|
143 | + /** |
|
144 | + * the reference string for the nonce_action |
|
145 | + * |
|
146 | + * @var string $_nonce_action_ref |
|
147 | + */ |
|
148 | + protected $_nonce_action_ref; |
|
149 | + |
|
150 | + /** |
|
151 | + * property to hold incoming request data (as set by the admin_page_core) |
|
152 | + * |
|
153 | + * @var array $_req_data |
|
154 | + */ |
|
155 | + protected $_req_data; |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * yes / no array for admin form fields |
|
160 | + * |
|
161 | + * @var array $_yes_no |
|
162 | + */ |
|
163 | + protected $_yes_no = array(); |
|
164 | + |
|
165 | + /** |
|
166 | + * Array describing buttons that should appear at the bottom of the page |
|
167 | + * Keys are strings that represent the button's function (specifically a key in _labels['buttons']), |
|
168 | + * and the values are another array with the following keys |
|
169 | + * array( |
|
170 | + * 'route' => 'page_route', |
|
171 | + * 'extra_request' => array('evt_id' => 1 ); //extra request vars that need to be included in the button. |
|
172 | + * ) |
|
173 | + * |
|
174 | + * @var array $_bottom_buttons |
|
175 | + */ |
|
176 | + protected $_bottom_buttons = array(); |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Used to indicate what should be the primary column for the list table. |
|
181 | + * If not present then falls back to what WP calculates |
|
182 | + * as the primary column. |
|
183 | + * |
|
184 | + * @type string $_primary_column |
|
185 | + */ |
|
186 | + protected $_primary_column = ''; |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Used to indicate whether the table has a checkbox column or not. |
|
191 | + * |
|
192 | + * @type bool $_has_checkbox_column |
|
193 | + */ |
|
194 | + protected $_has_checkbox_column = false; |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param \EE_Admin_Page $admin_page we use this for obtaining everything we need in the list table |
|
199 | + */ |
|
200 | + public function __construct(EE_Admin_Page $admin_page) |
|
201 | + { |
|
202 | + $this->_admin_page = $admin_page; |
|
203 | + $this->_req_data = $this->_admin_page->get_request_data(); |
|
204 | + $this->_view = $this->_admin_page->get_view(); |
|
205 | + $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
|
206 | + $this->_current_page = $this->get_pagenum(); |
|
207 | + $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
208 | + $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
|
209 | + |
|
210 | + $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 20); |
|
211 | + |
|
212 | + $this->_setup_data(); |
|
213 | + $this->_add_view_counts(); |
|
214 | + |
|
215 | + $this->_nonce_action_ref = $this->_view; |
|
216 | + |
|
217 | + $this->_set_properties(); |
|
218 | + |
|
219 | + // set primary column |
|
220 | + add_filter('list_table_primary_column', array($this, 'set_primary_column')); |
|
221 | + |
|
222 | + // set parent defaults |
|
223 | + parent::__construct($this->_wp_list_args); |
|
224 | + |
|
225 | + $this->prepare_items(); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * _setup_data |
|
231 | + * this method is used to setup the $_data, $_all_data_count, and _per_page properties |
|
232 | + * |
|
233 | + * @uses $this->_admin_page |
|
234 | + * @return void |
|
235 | + */ |
|
236 | + abstract protected function _setup_data(); |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * set the properties that this class needs to be able to execute wp_list_table properly |
|
241 | + * properties set: |
|
242 | + * _wp_list_args = what the arguments required for the parent _wp_list_table. |
|
243 | + * _columns = set the columns in an array. |
|
244 | + * _sortable_columns = columns that are sortable (array). |
|
245 | + * _hidden_columns = columns that are hidden (array) |
|
246 | + * _default_orderby = the default orderby for sorting. |
|
247 | + * |
|
248 | + * @abstract |
|
249 | + * @access protected |
|
250 | + * @return void |
|
251 | + */ |
|
252 | + abstract protected function _set_properties(); |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * _get_table_filters |
|
257 | + * We use this to assemble and return any filters that are associated with this table that help further refine what |
|
258 | + * get's shown in the table. |
|
259 | + * |
|
260 | + * @abstract |
|
261 | + * @access protected |
|
262 | + * @return string |
|
263 | + */ |
|
264 | + abstract protected function _get_table_filters(); |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * this is a method that child class will do to add counts to the views array so when views are displayed the |
|
269 | + * counts of the views is accurate. |
|
270 | + * |
|
271 | + * @abstract |
|
272 | + * @access protected |
|
273 | + * @return void |
|
274 | + */ |
|
275 | + abstract protected function _add_view_counts(); |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * _get_hidden_fields |
|
280 | + * returns a html string of hidden fields so if any table filters are used the current view will be respected. |
|
281 | + * |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + protected function _get_hidden_fields() |
|
285 | + { |
|
286 | + $action = isset($this->_req_data['route']) ? $this->_req_data['route'] : ''; |
|
287 | + $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
|
288 | + // if action is STILL empty, then we set it to default |
|
289 | + $action = empty($action) ? 'default' : $action; |
|
290 | + $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
291 | + $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
292 | + $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
293 | + |
|
294 | + $bulk_actions = $this->_get_bulk_actions(); |
|
295 | + foreach ($bulk_actions as $bulk_action => $label) { |
|
296 | + $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
297 | + . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
298 | + } |
|
299 | + |
|
300 | + return $field; |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * _set_column_info |
|
306 | + * we're using this to set the column headers property. |
|
307 | + * |
|
308 | + * @access protected |
|
309 | + * @return void |
|
310 | + */ |
|
311 | + protected function _set_column_info() |
|
312 | + { |
|
313 | + $columns = $this->get_columns(); |
|
314 | + $hidden = $this->get_hidden_columns(); |
|
315 | + $_sortable = $this->get_sortable_columns(); |
|
316 | + |
|
317 | + /** |
|
318 | + * Dynamic hook allowing for adding sortable columns in this list table. |
|
319 | + * Note that $this->screen->id is in the format |
|
320 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
321 | + * table it is: event-espresso_page_espresso_messages. |
|
322 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
323 | + * hook prefix ("event-espresso") will be different. |
|
324 | + * |
|
325 | + * @var array |
|
326 | + */ |
|
327 | + $_sortable = apply_filters("FHEE_manage_{$this->screen->id}_sortable_columns", $_sortable, $this->_screen); |
|
328 | + |
|
329 | + $sortable = array(); |
|
330 | + foreach ($_sortable as $id => $data) { |
|
331 | + if (empty($data)) { |
|
332 | + continue; |
|
333 | + } |
|
334 | + // fix for offset errors with WP_List_Table default get_columninfo() |
|
335 | + if (is_array($data)) { |
|
336 | + $_data[0] = key($data); |
|
337 | + $_data[1] = isset($data[1]) ? $data[1] : false; |
|
338 | + } else { |
|
339 | + $_data[0] = $data; |
|
340 | + } |
|
341 | + |
|
342 | + $data = (array) $data; |
|
343 | + |
|
344 | + if (! isset($data[1])) { |
|
345 | + $_data[1] = false; |
|
346 | + } |
|
347 | + |
|
348 | + $sortable[ $id ] = $_data; |
|
349 | + } |
|
350 | + $primary = $this->get_primary_column_name(); |
|
351 | + $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
357 | + * |
|
358 | + * @return string |
|
359 | + */ |
|
360 | + protected function get_primary_column_name() |
|
361 | + { |
|
362 | + foreach (class_parents($this) as $parent) { |
|
363 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'get_primary_column_name')) { |
|
364 | + return parent::get_primary_column_name(); |
|
365 | + } |
|
366 | + } |
|
367 | + return $this->_primary_column; |
|
368 | + } |
|
369 | + |
|
370 | + |
|
371 | + /** |
|
372 | + * Added for WP4.1 backward compat (@see https://events.codebasehq.com/projects/event-espresso/tickets/8814) |
|
373 | + * |
|
374 | + * @param EE_Base_Class $item |
|
375 | + * @param string $column_name |
|
376 | + * @param string $primary |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + protected function handle_row_actions($item, $column_name, $primary) |
|
380 | + { |
|
381 | + foreach (class_parents($this) as $parent) { |
|
382 | + if ($parent === 'WP_List_Table' && method_exists($parent, 'handle_row_actions')) { |
|
383 | + return parent::handle_row_actions($item, $column_name, $primary); |
|
384 | + } |
|
385 | + } |
|
386 | + return ''; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * _get_bulk_actions |
|
392 | + * This is a wrapper called by WP_List_Table::get_bulk_actions() |
|
393 | + * |
|
394 | + * @access protected |
|
395 | + * @return array bulk_actions |
|
396 | + */ |
|
397 | + protected function _get_bulk_actions() |
|
398 | + { |
|
399 | + $actions = array(); |
|
400 | + // the _views property should have the bulk_actions, so let's go through and extract them into a properly |
|
401 | + // formatted array for the wp_list_table(); |
|
402 | + foreach ($this->_views as $view => $args) { |
|
403 | + if ($this->_view === $view && isset($args['bulk_action']) && is_array($args['bulk_action'])) { |
|
404 | + // each bulk action will correspond with a admin page route, so we can check whatever the capability is |
|
405 | + // for that page route and skip adding the bulk action if no access for the current logged in user. |
|
406 | + foreach ($args['bulk_action'] as $route => $label) { |
|
407 | + if ($this->_admin_page->check_user_access($route, true)) { |
|
408 | + $actions[ $route ] = $label; |
|
409 | + } |
|
410 | + } |
|
411 | + } |
|
412 | + } |
|
413 | + return $actions; |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Generate the table navigation above or below the table. |
|
419 | + * Overrides the parent table nav in WP_List_Table so we can hide the bulk action div if there are no bulk actions. |
|
420 | + * |
|
421 | + * @since 4.9.44.rc.001 |
|
422 | + */ |
|
423 | + public function display_tablenav($which) |
|
424 | + { |
|
425 | + if ('top' === $which) { |
|
426 | + wp_nonce_field('bulk-' . $this->_args['plural']); |
|
427 | + } |
|
428 | + ?> |
|
429 | 429 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
430 | 430 | <?php if ($this->_get_bulk_actions()) { ?> |
431 | 431 | <div class="alignleft actions bulkactions"> |
432 | 432 | <?php $this->bulk_actions(); ?> |
433 | 433 | </div> |
434 | 434 | <?php } |
435 | - $this->extra_tablenav($which); |
|
436 | - $this->pagination($which); |
|
437 | - ?> |
|
435 | + $this->extra_tablenav($which); |
|
436 | + $this->pagination($which); |
|
437 | + ?> |
|
438 | 438 | |
439 | 439 | <br class="clear"/> |
440 | 440 | </div> |
441 | 441 | <?php |
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * _filters |
|
447 | - * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
448 | - * button. |
|
449 | - * |
|
450 | - * @access private |
|
451 | - * @return string html showing filters |
|
452 | - */ |
|
453 | - private function _filters() |
|
454 | - { |
|
455 | - $classname = get_class($this); |
|
456 | - $filters = apply_filters( |
|
457 | - "FHEE__{$classname}__filters", |
|
458 | - (array) $this->_get_table_filters(), |
|
459 | - $this, |
|
460 | - $this->_screen |
|
461 | - ); |
|
462 | - |
|
463 | - if (empty($filters)) { |
|
464 | - return; |
|
465 | - } |
|
466 | - foreach ($filters as $filter) { |
|
467 | - echo $filter; |
|
468 | - } |
|
469 | - // add filter button at end |
|
470 | - echo '<input type="submit" class="button-secondary" value="' |
|
471 | - . esc_html__('Filter', 'event_espresso') |
|
472 | - . '" id="post-query-submit" />'; |
|
473 | - // add reset filters button at end |
|
474 | - echo '<a class="button button-secondary" href="' |
|
475 | - . $this->_admin_page->get_current_page_view_url() |
|
476 | - . '" style="display:inline-block">' |
|
477 | - . esc_html__('Reset Filters', 'event_espresso') |
|
478 | - . '</a>'; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * Callback for 'list_table_primary_column' WordPress filter |
|
484 | - * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
485 | - * column when class is instantiated. |
|
486 | - * |
|
487 | - * @see WP_List_Table::get_primary_column_name |
|
488 | - * @param string $column_name |
|
489 | - * @return string |
|
490 | - */ |
|
491 | - public function set_primary_column($column_name) |
|
492 | - { |
|
493 | - return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
494 | - } |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * |
|
499 | - */ |
|
500 | - public function prepare_items() |
|
501 | - { |
|
502 | - |
|
503 | - $this->_set_column_info(); |
|
504 | - // $this->_column_headers = $this->get_column_info(); |
|
505 | - $total_items = $this->_all_data_count; |
|
506 | - $this->process_bulk_action(); |
|
507 | - |
|
508 | - $this->items = $this->_data; |
|
509 | - $this->set_pagination_args( |
|
510 | - array( |
|
511 | - 'total_items' => $total_items, |
|
512 | - 'per_page' => $this->_per_page, |
|
513 | - 'total_pages' => ceil($total_items / $this->_per_page), |
|
514 | - ) |
|
515 | - ); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * This column is the default for when there is no defined column method for a registered column. |
|
521 | - * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
522 | - * |
|
523 | - * @param EE_Base_Class $item |
|
524 | - * @param string $column_name The column being called. |
|
525 | - * @return string html content for the column |
|
526 | - */ |
|
527 | - public function column_default($item, $column_name) |
|
528 | - { |
|
529 | - /** |
|
530 | - * Dynamic hook allowing for adding additional column content in this list table. |
|
531 | - * Note that $this->screen->id is in the format |
|
532 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
533 | - * table it is: event-espresso_page_espresso_messages. |
|
534 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
535 | - * hook prefix ("event-espresso") will be different. |
|
536 | - */ |
|
537 | - do_action( |
|
538 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
539 | - $item, |
|
540 | - $this->_screen |
|
541 | - ); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Get a list of columns. The format is: |
|
547 | - * 'internal-name' => 'Title' |
|
548 | - * |
|
549 | - * @since 3.1.0 |
|
550 | - * @access public |
|
551 | - * @abstract |
|
552 | - * @return array |
|
553 | - */ |
|
554 | - public function get_columns() |
|
555 | - { |
|
556 | - /** |
|
557 | - * Dynamic hook allowing for adding additional columns in this list table. |
|
558 | - * Note that $this->screen->id is in the format |
|
559 | - * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
560 | - * table it is: event-espresso_page_espresso_messages. |
|
561 | - * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
562 | - * hook prefix ("event-espresso") will be different. |
|
563 | - * |
|
564 | - * @var array |
|
565 | - */ |
|
566 | - $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
567 | - return $columns; |
|
568 | - } |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Get an associative array ( id => link ) with the list |
|
573 | - * of views available on this table. |
|
574 | - * |
|
575 | - * @since 3.1.0 |
|
576 | - * @access protected |
|
577 | - * @return array |
|
578 | - */ |
|
579 | - public function get_views() |
|
580 | - { |
|
581 | - return $this->_views; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - /** |
|
586 | - * Generate the views html. |
|
587 | - */ |
|
588 | - public function display_views() |
|
589 | - { |
|
590 | - $views = $this->get_views(); |
|
591 | - $assembled_views = array(); |
|
592 | - |
|
593 | - if (empty($views)) { |
|
594 | - return; |
|
595 | - } |
|
596 | - echo "<ul class='subsubsub'>\n"; |
|
597 | - foreach ($views as $view) { |
|
598 | - $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
599 | - if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
600 | - $assembled_views[ $view['slug'] ] = "\t<li class='" . $view['class'] . "'>" |
|
601 | - . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>' |
|
602 | - . ' <span class="count">(' . $count . ')</span>'; |
|
603 | - } |
|
604 | - } |
|
605 | - |
|
606 | - echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
607 | - echo "</ul>"; |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - /** |
|
612 | - * Generates content for a single row of the table |
|
613 | - * |
|
614 | - * @since 4.1 |
|
615 | - * @access public |
|
616 | - * @param EE_Base_Class $item The current item |
|
617 | - */ |
|
618 | - public function single_row($item) |
|
619 | - { |
|
620 | - $row_class = $this->_get_row_class($item); |
|
621 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
622 | - $this->single_row_columns($item); |
|
623 | - echo '</tr>'; |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * This simply sets up the row class for the table rows. |
|
629 | - * Allows for easier overriding of child methods for setting up sorting. |
|
630 | - * |
|
631 | - * @param EE_Base_Class $item the current item |
|
632 | - * @return string |
|
633 | - */ |
|
634 | - protected function _get_row_class($item) |
|
635 | - { |
|
636 | - static $row_class = ''; |
|
637 | - $row_class = ($row_class === '' ? 'alternate' : ''); |
|
638 | - |
|
639 | - $new_row_class = $row_class; |
|
640 | - |
|
641 | - if (! empty($this->_ajax_sorting_callback)) { |
|
642 | - $new_row_class .= ' rowsortable'; |
|
643 | - } |
|
644 | - |
|
645 | - return $new_row_class; |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * @return array |
|
651 | - */ |
|
652 | - public function get_sortable_columns() |
|
653 | - { |
|
654 | - return (array) $this->_sortable_columns; |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - /** |
|
659 | - * @return string |
|
660 | - */ |
|
661 | - public function get_ajax_sorting_callback() |
|
662 | - { |
|
663 | - return $this->_ajax_sorting_callback; |
|
664 | - } |
|
665 | - |
|
666 | - |
|
667 | - /** |
|
668 | - * @return array |
|
669 | - */ |
|
670 | - public function get_hidden_columns() |
|
671 | - { |
|
672 | - $user_id = get_current_user_id(); |
|
673 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
674 | - if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
675 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
676 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
677 | - } |
|
678 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
679 | - return (array) get_user_option($ref, $user_id); |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * Generates the columns for a single row of the table. |
|
685 | - * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
686 | - * column. |
|
687 | - * |
|
688 | - * @since 3.1.0 |
|
689 | - * @param EE_Base_Class $item The current item |
|
690 | - */ |
|
691 | - public function single_row_columns($item) |
|
692 | - { |
|
693 | - list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
694 | - |
|
695 | - global $wp_version; |
|
696 | - $use_hidden_class = version_compare($wp_version, '4.3-RC', '>='); |
|
697 | - |
|
698 | - foreach ($columns as $column_name => $column_display_name) { |
|
699 | - |
|
700 | - /** |
|
701 | - * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
702 | - * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
703 | - */ |
|
704 | - $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
|
705 | - $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
|
706 | - |
|
707 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
708 | - if ($primary === $column_name) { |
|
709 | - $classes .= ' has-row-actions column-primary'; |
|
710 | - } |
|
711 | - |
|
712 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
713 | - |
|
714 | - $class = "class='$classes'"; |
|
715 | - |
|
716 | - $attributes = "$class$style$data"; |
|
717 | - |
|
718 | - if ($column_name === 'cb') { |
|
719 | - echo '<th scope="row" class="check-column">'; |
|
720 | - echo apply_filters( |
|
721 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
722 | - $this->column_cb($item), |
|
723 | - $item, |
|
724 | - $this |
|
725 | - ); |
|
726 | - echo '</th>'; |
|
727 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
728 | - echo "<td $attributes>"; |
|
729 | - echo apply_filters( |
|
730 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
731 | - call_user_func(array($this, 'column_' . $column_name), $item), |
|
732 | - $item, |
|
733 | - $this |
|
734 | - ); |
|
735 | - echo $this->handle_row_actions($item, $column_name, $primary); |
|
736 | - echo "</td>"; |
|
737 | - } else { |
|
738 | - echo "<td $attributes>"; |
|
739 | - echo apply_filters( |
|
740 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
741 | - $this->column_default($item, $column_name), |
|
742 | - $item, |
|
743 | - $column_name, |
|
744 | - $this |
|
745 | - ); |
|
746 | - echo $this->handle_row_actions($item, $column_name, $primary); |
|
747 | - echo "</td>"; |
|
748 | - } |
|
749 | - } |
|
750 | - } |
|
751 | - |
|
752 | - |
|
753 | - /** |
|
754 | - * Extra controls to be displayed between bulk actions and pagination |
|
755 | - * |
|
756 | - * @access public |
|
757 | - * @param string $which |
|
758 | - * @throws \EE_Error |
|
759 | - */ |
|
760 | - public function extra_tablenav($which) |
|
761 | - { |
|
762 | - if ($which === 'top') { |
|
763 | - $this->_filters(); |
|
764 | - echo $this->_get_hidden_fields(); |
|
765 | - } else { |
|
766 | - echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
767 | - foreach ($this->_bottom_buttons as $type => $action) { |
|
768 | - $route = isset($action['route']) ? $action['route'] : ''; |
|
769 | - $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
770 | - echo $this->_admin_page->get_action_link_or_button( |
|
771 | - $route, |
|
772 | - $type, |
|
773 | - $extra_request, |
|
774 | - 'button button-secondary', |
|
775 | - '', |
|
776 | - false |
|
777 | - ); |
|
778 | - } |
|
779 | - do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
780 | - echo '</div>'; |
|
781 | - } |
|
782 | - // echo $this->_entries_per_page_dropdown; |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * Get an associative array ( option_name => option_title ) with the list |
|
788 | - * of bulk actions available on this table. |
|
789 | - * |
|
790 | - * @since 3.1.0 |
|
791 | - * @access protected |
|
792 | - * @return array |
|
793 | - */ |
|
794 | - public function get_bulk_actions() |
|
795 | - { |
|
796 | - return (array) $this->_get_bulk_actions(); |
|
797 | - } |
|
798 | - |
|
799 | - /** |
|
800 | - * Processing bulk actions. |
|
801 | - */ |
|
802 | - public function process_bulk_action() |
|
803 | - { |
|
804 | - // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
805 | - // reference in case there is a case where it gets used. |
|
806 | - } |
|
807 | - |
|
808 | - |
|
809 | - /** |
|
810 | - * returns the EE admin page this list table is associated with |
|
811 | - * |
|
812 | - * @return EE_Admin_Page |
|
813 | - */ |
|
814 | - public function get_admin_page() |
|
815 | - { |
|
816 | - return $this->_admin_page; |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - /** |
|
821 | - * A "helper" function for all children to provide an html string of |
|
822 | - * actions to output in their content. It is preferable for child classes |
|
823 | - * to use this method for generating their actions content so that it's |
|
824 | - * filterable by plugins |
|
825 | - * |
|
826 | - * @param string $action_container what are the html container |
|
827 | - * elements for this actions string? |
|
828 | - * @param string $action_class What class is for the container |
|
829 | - * element. |
|
830 | - * @param string $action_items The contents for the action items |
|
831 | - * container. This is filtered before |
|
832 | - * returned. |
|
833 | - * @param string $action_id What id (optional) is used for the |
|
834 | - * container element. |
|
835 | - * @param EE_Base_Class $item The object for the column displaying |
|
836 | - * the actions. |
|
837 | - * @return string The assembled action elements container. |
|
838 | - */ |
|
839 | - protected function _action_string( |
|
840 | - $action_items, |
|
841 | - $item, |
|
842 | - $action_container = 'ul', |
|
843 | - $action_class = '', |
|
844 | - $action_id = '' |
|
845 | - ) { |
|
846 | - $content = ''; |
|
847 | - $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
848 | - $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
849 | - $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
850 | - try { |
|
851 | - $content .= apply_filters( |
|
852 | - 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
853 | - $action_items, |
|
854 | - $item, |
|
855 | - $this |
|
856 | - ); |
|
857 | - } catch (\Exception $e) { |
|
858 | - if (WP_DEBUG) { |
|
859 | - \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
860 | - } |
|
861 | - $content .= $action_items; |
|
862 | - } |
|
863 | - $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
864 | - return $content; |
|
865 | - } |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * _filters |
|
447 | + * This receives the filters array from children _get_table_filters() and assembles the string including the filter |
|
448 | + * button. |
|
449 | + * |
|
450 | + * @access private |
|
451 | + * @return string html showing filters |
|
452 | + */ |
|
453 | + private function _filters() |
|
454 | + { |
|
455 | + $classname = get_class($this); |
|
456 | + $filters = apply_filters( |
|
457 | + "FHEE__{$classname}__filters", |
|
458 | + (array) $this->_get_table_filters(), |
|
459 | + $this, |
|
460 | + $this->_screen |
|
461 | + ); |
|
462 | + |
|
463 | + if (empty($filters)) { |
|
464 | + return; |
|
465 | + } |
|
466 | + foreach ($filters as $filter) { |
|
467 | + echo $filter; |
|
468 | + } |
|
469 | + // add filter button at end |
|
470 | + echo '<input type="submit" class="button-secondary" value="' |
|
471 | + . esc_html__('Filter', 'event_espresso') |
|
472 | + . '" id="post-query-submit" />'; |
|
473 | + // add reset filters button at end |
|
474 | + echo '<a class="button button-secondary" href="' |
|
475 | + . $this->_admin_page->get_current_page_view_url() |
|
476 | + . '" style="display:inline-block">' |
|
477 | + . esc_html__('Reset Filters', 'event_espresso') |
|
478 | + . '</a>'; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * Callback for 'list_table_primary_column' WordPress filter |
|
484 | + * If child EE_Admin_List_Table classes set the _primary_column property then that will be set as the primary |
|
485 | + * column when class is instantiated. |
|
486 | + * |
|
487 | + * @see WP_List_Table::get_primary_column_name |
|
488 | + * @param string $column_name |
|
489 | + * @return string |
|
490 | + */ |
|
491 | + public function set_primary_column($column_name) |
|
492 | + { |
|
493 | + return ! empty($this->_primary_column) ? $this->_primary_column : $column_name; |
|
494 | + } |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * |
|
499 | + */ |
|
500 | + public function prepare_items() |
|
501 | + { |
|
502 | + |
|
503 | + $this->_set_column_info(); |
|
504 | + // $this->_column_headers = $this->get_column_info(); |
|
505 | + $total_items = $this->_all_data_count; |
|
506 | + $this->process_bulk_action(); |
|
507 | + |
|
508 | + $this->items = $this->_data; |
|
509 | + $this->set_pagination_args( |
|
510 | + array( |
|
511 | + 'total_items' => $total_items, |
|
512 | + 'per_page' => $this->_per_page, |
|
513 | + 'total_pages' => ceil($total_items / $this->_per_page), |
|
514 | + ) |
|
515 | + ); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * This column is the default for when there is no defined column method for a registered column. |
|
521 | + * This can be overridden by child classes, but allows for hooking in for custom columns. |
|
522 | + * |
|
523 | + * @param EE_Base_Class $item |
|
524 | + * @param string $column_name The column being called. |
|
525 | + * @return string html content for the column |
|
526 | + */ |
|
527 | + public function column_default($item, $column_name) |
|
528 | + { |
|
529 | + /** |
|
530 | + * Dynamic hook allowing for adding additional column content in this list table. |
|
531 | + * Note that $this->screen->id is in the format |
|
532 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
533 | + * table it is: event-espresso_page_espresso_messages. |
|
534 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
535 | + * hook prefix ("event-espresso") will be different. |
|
536 | + */ |
|
537 | + do_action( |
|
538 | + 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
539 | + $item, |
|
540 | + $this->_screen |
|
541 | + ); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Get a list of columns. The format is: |
|
547 | + * 'internal-name' => 'Title' |
|
548 | + * |
|
549 | + * @since 3.1.0 |
|
550 | + * @access public |
|
551 | + * @abstract |
|
552 | + * @return array |
|
553 | + */ |
|
554 | + public function get_columns() |
|
555 | + { |
|
556 | + /** |
|
557 | + * Dynamic hook allowing for adding additional columns in this list table. |
|
558 | + * Note that $this->screen->id is in the format |
|
559 | + * {sanitize_title($top_level_menu_label)}_page_{$espresso_admin_page_slug}. So for the messages list |
|
560 | + * table it is: event-espresso_page_espresso_messages. |
|
561 | + * However, take note that if the top level menu label has been translated (i.e. "Event Espresso"). then the |
|
562 | + * hook prefix ("event-espresso") will be different. |
|
563 | + * |
|
564 | + * @var array |
|
565 | + */ |
|
566 | + $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
567 | + return $columns; |
|
568 | + } |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Get an associative array ( id => link ) with the list |
|
573 | + * of views available on this table. |
|
574 | + * |
|
575 | + * @since 3.1.0 |
|
576 | + * @access protected |
|
577 | + * @return array |
|
578 | + */ |
|
579 | + public function get_views() |
|
580 | + { |
|
581 | + return $this->_views; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + /** |
|
586 | + * Generate the views html. |
|
587 | + */ |
|
588 | + public function display_views() |
|
589 | + { |
|
590 | + $views = $this->get_views(); |
|
591 | + $assembled_views = array(); |
|
592 | + |
|
593 | + if (empty($views)) { |
|
594 | + return; |
|
595 | + } |
|
596 | + echo "<ul class='subsubsub'>\n"; |
|
597 | + foreach ($views as $view) { |
|
598 | + $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
|
599 | + if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
|
600 | + $assembled_views[ $view['slug'] ] = "\t<li class='" . $view['class'] . "'>" |
|
601 | + . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>' |
|
602 | + . ' <span class="count">(' . $count . ')</span>'; |
|
603 | + } |
|
604 | + } |
|
605 | + |
|
606 | + echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
607 | + echo "</ul>"; |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + /** |
|
612 | + * Generates content for a single row of the table |
|
613 | + * |
|
614 | + * @since 4.1 |
|
615 | + * @access public |
|
616 | + * @param EE_Base_Class $item The current item |
|
617 | + */ |
|
618 | + public function single_row($item) |
|
619 | + { |
|
620 | + $row_class = $this->_get_row_class($item); |
|
621 | + echo '<tr class="' . esc_attr($row_class) . '">'; |
|
622 | + $this->single_row_columns($item); |
|
623 | + echo '</tr>'; |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * This simply sets up the row class for the table rows. |
|
629 | + * Allows for easier overriding of child methods for setting up sorting. |
|
630 | + * |
|
631 | + * @param EE_Base_Class $item the current item |
|
632 | + * @return string |
|
633 | + */ |
|
634 | + protected function _get_row_class($item) |
|
635 | + { |
|
636 | + static $row_class = ''; |
|
637 | + $row_class = ($row_class === '' ? 'alternate' : ''); |
|
638 | + |
|
639 | + $new_row_class = $row_class; |
|
640 | + |
|
641 | + if (! empty($this->_ajax_sorting_callback)) { |
|
642 | + $new_row_class .= ' rowsortable'; |
|
643 | + } |
|
644 | + |
|
645 | + return $new_row_class; |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * @return array |
|
651 | + */ |
|
652 | + public function get_sortable_columns() |
|
653 | + { |
|
654 | + return (array) $this->_sortable_columns; |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + /** |
|
659 | + * @return string |
|
660 | + */ |
|
661 | + public function get_ajax_sorting_callback() |
|
662 | + { |
|
663 | + return $this->_ajax_sorting_callback; |
|
664 | + } |
|
665 | + |
|
666 | + |
|
667 | + /** |
|
668 | + * @return array |
|
669 | + */ |
|
670 | + public function get_hidden_columns() |
|
671 | + { |
|
672 | + $user_id = get_current_user_id(); |
|
673 | + $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
674 | + if (empty($has_default) && ! empty($this->_hidden_columns)) { |
|
675 | + update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
676 | + update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
677 | + } |
|
678 | + $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
679 | + return (array) get_user_option($ref, $user_id); |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * Generates the columns for a single row of the table. |
|
685 | + * Overridden from wp_list_table so as to allow us to filter the column content for a given |
|
686 | + * column. |
|
687 | + * |
|
688 | + * @since 3.1.0 |
|
689 | + * @param EE_Base_Class $item The current item |
|
690 | + */ |
|
691 | + public function single_row_columns($item) |
|
692 | + { |
|
693 | + list($columns, $hidden, $sortable, $primary) = $this->get_column_info(); |
|
694 | + |
|
695 | + global $wp_version; |
|
696 | + $use_hidden_class = version_compare($wp_version, '4.3-RC', '>='); |
|
697 | + |
|
698 | + foreach ($columns as $column_name => $column_display_name) { |
|
699 | + |
|
700 | + /** |
|
701 | + * With WordPress version 4.3.RC+ WordPress started using the hidden css class to control whether columns |
|
702 | + * are hidden or not instead of using "display:none;". This bit of code provides backward compat. |
|
703 | + */ |
|
704 | + $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
|
705 | + $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
|
706 | + |
|
707 | + $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
708 | + if ($primary === $column_name) { |
|
709 | + $classes .= ' has-row-actions column-primary'; |
|
710 | + } |
|
711 | + |
|
712 | + $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
713 | + |
|
714 | + $class = "class='$classes'"; |
|
715 | + |
|
716 | + $attributes = "$class$style$data"; |
|
717 | + |
|
718 | + if ($column_name === 'cb') { |
|
719 | + echo '<th scope="row" class="check-column">'; |
|
720 | + echo apply_filters( |
|
721 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_cb_content', |
|
722 | + $this->column_cb($item), |
|
723 | + $item, |
|
724 | + $this |
|
725 | + ); |
|
726 | + echo '</th>'; |
|
727 | + } elseif (method_exists($this, 'column_' . $column_name)) { |
|
728 | + echo "<td $attributes>"; |
|
729 | + echo apply_filters( |
|
730 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
731 | + call_user_func(array($this, 'column_' . $column_name), $item), |
|
732 | + $item, |
|
733 | + $this |
|
734 | + ); |
|
735 | + echo $this->handle_row_actions($item, $column_name, $primary); |
|
736 | + echo "</td>"; |
|
737 | + } else { |
|
738 | + echo "<td $attributes>"; |
|
739 | + echo apply_filters( |
|
740 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_default__column_content', |
|
741 | + $this->column_default($item, $column_name), |
|
742 | + $item, |
|
743 | + $column_name, |
|
744 | + $this |
|
745 | + ); |
|
746 | + echo $this->handle_row_actions($item, $column_name, $primary); |
|
747 | + echo "</td>"; |
|
748 | + } |
|
749 | + } |
|
750 | + } |
|
751 | + |
|
752 | + |
|
753 | + /** |
|
754 | + * Extra controls to be displayed between bulk actions and pagination |
|
755 | + * |
|
756 | + * @access public |
|
757 | + * @param string $which |
|
758 | + * @throws \EE_Error |
|
759 | + */ |
|
760 | + public function extra_tablenav($which) |
|
761 | + { |
|
762 | + if ($which === 'top') { |
|
763 | + $this->_filters(); |
|
764 | + echo $this->_get_hidden_fields(); |
|
765 | + } else { |
|
766 | + echo '<div class="list-table-bottom-buttons alignleft actions">'; |
|
767 | + foreach ($this->_bottom_buttons as $type => $action) { |
|
768 | + $route = isset($action['route']) ? $action['route'] : ''; |
|
769 | + $extra_request = isset($action['extra_request']) ? $action['extra_request'] : ''; |
|
770 | + echo $this->_admin_page->get_action_link_or_button( |
|
771 | + $route, |
|
772 | + $type, |
|
773 | + $extra_request, |
|
774 | + 'button button-secondary', |
|
775 | + '', |
|
776 | + false |
|
777 | + ); |
|
778 | + } |
|
779 | + do_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', $this, $this->_screen); |
|
780 | + echo '</div>'; |
|
781 | + } |
|
782 | + // echo $this->_entries_per_page_dropdown; |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * Get an associative array ( option_name => option_title ) with the list |
|
788 | + * of bulk actions available on this table. |
|
789 | + * |
|
790 | + * @since 3.1.0 |
|
791 | + * @access protected |
|
792 | + * @return array |
|
793 | + */ |
|
794 | + public function get_bulk_actions() |
|
795 | + { |
|
796 | + return (array) $this->_get_bulk_actions(); |
|
797 | + } |
|
798 | + |
|
799 | + /** |
|
800 | + * Processing bulk actions. |
|
801 | + */ |
|
802 | + public function process_bulk_action() |
|
803 | + { |
|
804 | + // this is not used it is handled by the child EE_Admin_Page class (routes). However, including here for |
|
805 | + // reference in case there is a case where it gets used. |
|
806 | + } |
|
807 | + |
|
808 | + |
|
809 | + /** |
|
810 | + * returns the EE admin page this list table is associated with |
|
811 | + * |
|
812 | + * @return EE_Admin_Page |
|
813 | + */ |
|
814 | + public function get_admin_page() |
|
815 | + { |
|
816 | + return $this->_admin_page; |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + /** |
|
821 | + * A "helper" function for all children to provide an html string of |
|
822 | + * actions to output in their content. It is preferable for child classes |
|
823 | + * to use this method for generating their actions content so that it's |
|
824 | + * filterable by plugins |
|
825 | + * |
|
826 | + * @param string $action_container what are the html container |
|
827 | + * elements for this actions string? |
|
828 | + * @param string $action_class What class is for the container |
|
829 | + * element. |
|
830 | + * @param string $action_items The contents for the action items |
|
831 | + * container. This is filtered before |
|
832 | + * returned. |
|
833 | + * @param string $action_id What id (optional) is used for the |
|
834 | + * container element. |
|
835 | + * @param EE_Base_Class $item The object for the column displaying |
|
836 | + * the actions. |
|
837 | + * @return string The assembled action elements container. |
|
838 | + */ |
|
839 | + protected function _action_string( |
|
840 | + $action_items, |
|
841 | + $item, |
|
842 | + $action_container = 'ul', |
|
843 | + $action_class = '', |
|
844 | + $action_id = '' |
|
845 | + ) { |
|
846 | + $content = ''; |
|
847 | + $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
848 | + $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
849 | + $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
850 | + try { |
|
851 | + $content .= apply_filters( |
|
852 | + 'FHEE__EE_Admin_List_Table___action_string__action_items', |
|
853 | + $action_items, |
|
854 | + $item, |
|
855 | + $this |
|
856 | + ); |
|
857 | + } catch (\Exception $e) { |
|
858 | + if (WP_DEBUG) { |
|
859 | + \EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
860 | + } |
|
861 | + $content .= $action_items; |
|
862 | + } |
|
863 | + $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
864 | + return $content; |
|
865 | + } |
|
866 | 866 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! class_exists('WP_List_Table')) { |
|
4 | - require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
3 | +if ( ! class_exists('WP_List_Table')) { |
|
4 | + require_once ABSPATH.'wp-admin/includes/class-wp-list-table.php'; |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -204,10 +204,10 @@ discard block |
||
204 | 204 | $this->_view = $this->_admin_page->get_view(); |
205 | 205 | $this->_views = empty($this->_views) ? $this->_admin_page->get_list_table_view_RLs() : $this->_views; |
206 | 206 | $this->_current_page = $this->get_pagenum(); |
207 | - $this->_screen = $this->_admin_page->get_current_page() . '_' . $this->_admin_page->get_current_view(); |
|
207 | + $this->_screen = $this->_admin_page->get_current_page().'_'.$this->_admin_page->get_current_view(); |
|
208 | 208 | $this->_yes_no = array(__('No', 'event_espresso'), __('Yes', 'event_espresso')); |
209 | 209 | |
210 | - $this->_per_page = $this->get_items_per_page($this->_screen . '_per_page', 20); |
|
210 | + $this->_per_page = $this->get_items_per_page($this->_screen.'_per_page', 20); |
|
211 | 211 | |
212 | 212 | $this->_setup_data(); |
213 | 213 | $this->_add_view_counts(); |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | $action = empty($action) && isset($this->_req_data['action']) ? $this->_req_data['action'] : $action; |
288 | 288 | // if action is STILL empty, then we set it to default |
289 | 289 | $action = empty($action) ? 'default' : $action; |
290 | - $field = '<input type="hidden" name="page" value="' . $this->_req_data['page'] . '" />' . "\n"; |
|
291 | - $field .= '<input type="hidden" name="route" value="' . $action . '" />' . "\n";/**/ |
|
292 | - $field .= '<input type="hidden" name="perpage" value="' . $this->_per_page . '" />' . "\n"; |
|
290 | + $field = '<input type="hidden" name="page" value="'.$this->_req_data['page'].'" />'."\n"; |
|
291 | + $field .= '<input type="hidden" name="route" value="'.$action.'" />'."\n"; /**/ |
|
292 | + $field .= '<input type="hidden" name="perpage" value="'.$this->_per_page.'" />'."\n"; |
|
293 | 293 | |
294 | 294 | $bulk_actions = $this->_get_bulk_actions(); |
295 | 295 | foreach ($bulk_actions as $bulk_action => $label) { |
296 | - $field .= '<input type="hidden" name="' . $bulk_action . '_nonce"' |
|
297 | - . ' value="' . wp_create_nonce($bulk_action . '_nonce') . '" />' . "\n"; |
|
296 | + $field .= '<input type="hidden" name="'.$bulk_action.'_nonce"' |
|
297 | + . ' value="'.wp_create_nonce($bulk_action.'_nonce').'" />'."\n"; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | return $field; |
@@ -341,11 +341,11 @@ discard block |
||
341 | 341 | |
342 | 342 | $data = (array) $data; |
343 | 343 | |
344 | - if (! isset($data[1])) { |
|
344 | + if ( ! isset($data[1])) { |
|
345 | 345 | $_data[1] = false; |
346 | 346 | } |
347 | 347 | |
348 | - $sortable[ $id ] = $_data; |
|
348 | + $sortable[$id] = $_data; |
|
349 | 349 | } |
350 | 350 | $primary = $this->get_primary_column_name(); |
351 | 351 | $this->_column_headers = array($columns, $hidden, $sortable, $primary); |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | // for that page route and skip adding the bulk action if no access for the current logged in user. |
406 | 406 | foreach ($args['bulk_action'] as $route => $label) { |
407 | 407 | if ($this->_admin_page->check_user_access($route, true)) { |
408 | - $actions[ $route ] = $label; |
|
408 | + $actions[$route] = $label; |
|
409 | 409 | } |
410 | 410 | } |
411 | 411 | } |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | public function display_tablenav($which) |
424 | 424 | { |
425 | 425 | if ('top' === $which) { |
426 | - wp_nonce_field('bulk-' . $this->_args['plural']); |
|
426 | + wp_nonce_field('bulk-'.$this->_args['plural']); |
|
427 | 427 | } |
428 | 428 | ?> |
429 | 429 | <div class="tablenav <?php echo esc_attr($which); ?>"> |
@@ -535,7 +535,7 @@ discard block |
||
535 | 535 | * hook prefix ("event-espresso") will be different. |
536 | 536 | */ |
537 | 537 | do_action( |
538 | - 'AHEE__EE_Admin_List_Table__column_' . $column_name . '__' . $this->screen->id, |
|
538 | + 'AHEE__EE_Admin_List_Table__column_'.$column_name.'__'.$this->screen->id, |
|
539 | 539 | $item, |
540 | 540 | $this->_screen |
541 | 541 | ); |
@@ -563,7 +563,7 @@ discard block |
||
563 | 563 | * |
564 | 564 | * @var array |
565 | 565 | */ |
566 | - $columns = apply_filters('FHEE_manage_' . $this->screen->id . '_columns', $this->_columns, $this->_screen); |
|
566 | + $columns = apply_filters('FHEE_manage_'.$this->screen->id.'_columns', $this->_columns, $this->_screen); |
|
567 | 567 | return $columns; |
568 | 568 | } |
569 | 569 | |
@@ -597,13 +597,13 @@ discard block |
||
597 | 597 | foreach ($views as $view) { |
598 | 598 | $count = isset($view['count']) && ! empty($view['count']) ? absint($view['count']) : 0; |
599 | 599 | if (isset($view['slug'], $view['class'], $view['url'], $view['label'])) { |
600 | - $assembled_views[ $view['slug'] ] = "\t<li class='" . $view['class'] . "'>" |
|
601 | - . '<a href="' . $view['url'] . '">' . $view['label'] . '</a>' |
|
602 | - . ' <span class="count">(' . $count . ')</span>'; |
|
600 | + $assembled_views[$view['slug']] = "\t<li class='".$view['class']."'>" |
|
601 | + . '<a href="'.$view['url'].'">'.$view['label'].'</a>' |
|
602 | + . ' <span class="count">('.$count.')</span>'; |
|
603 | 603 | } |
604 | 604 | } |
605 | 605 | |
606 | - echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views) . "</li>\n" : ''; |
|
606 | + echo ! empty($assembled_views) ? implode(" |</li>\n", $assembled_views)."</li>\n" : ''; |
|
607 | 607 | echo "</ul>"; |
608 | 608 | } |
609 | 609 | |
@@ -618,7 +618,7 @@ discard block |
||
618 | 618 | public function single_row($item) |
619 | 619 | { |
620 | 620 | $row_class = $this->_get_row_class($item); |
621 | - echo '<tr class="' . esc_attr($row_class) . '">'; |
|
621 | + echo '<tr class="'.esc_attr($row_class).'">'; |
|
622 | 622 | $this->single_row_columns($item); |
623 | 623 | echo '</tr>'; |
624 | 624 | } |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | |
639 | 639 | $new_row_class = $row_class; |
640 | 640 | |
641 | - if (! empty($this->_ajax_sorting_callback)) { |
|
641 | + if ( ! empty($this->_ajax_sorting_callback)) { |
|
642 | 642 | $new_row_class .= ' rowsortable'; |
643 | 643 | } |
644 | 644 | |
@@ -670,12 +670,12 @@ discard block |
||
670 | 670 | public function get_hidden_columns() |
671 | 671 | { |
672 | 672 | $user_id = get_current_user_id(); |
673 | - $has_default = get_user_option('default' . $this->screen->id . 'columnshidden', $user_id); |
|
673 | + $has_default = get_user_option('default'.$this->screen->id.'columnshidden', $user_id); |
|
674 | 674 | if (empty($has_default) && ! empty($this->_hidden_columns)) { |
675 | - update_user_option($user_id, 'default' . $this->screen->id . 'columnshidden', true); |
|
676 | - update_user_option($user_id, 'manage' . $this->screen->id . 'columnshidden', $this->_hidden_columns, true); |
|
675 | + update_user_option($user_id, 'default'.$this->screen->id.'columnshidden', true); |
|
676 | + update_user_option($user_id, 'manage'.$this->screen->id.'columnshidden', $this->_hidden_columns, true); |
|
677 | 677 | } |
678 | - $ref = 'manage' . $this->screen->id . 'columnshidden'; |
|
678 | + $ref = 'manage'.$this->screen->id.'columnshidden'; |
|
679 | 679 | return (array) get_user_option($ref, $user_id); |
680 | 680 | } |
681 | 681 | |
@@ -704,12 +704,12 @@ discard block |
||
704 | 704 | $hidden_class = $use_hidden_class && in_array($column_name, $hidden) ? ' hidden' : ''; |
705 | 705 | $style = ! $use_hidden_class && in_array($column_name, $hidden) ? ' style="display:none;"' : ''; |
706 | 706 | |
707 | - $classes = $column_name . ' column-' . $column_name . $hidden_class; |
|
707 | + $classes = $column_name.' column-'.$column_name.$hidden_class; |
|
708 | 708 | if ($primary === $column_name) { |
709 | 709 | $classes .= ' has-row-actions column-primary'; |
710 | 710 | } |
711 | 711 | |
712 | - $data = ' data-colname="' . wp_strip_all_tags($column_display_name) . '"'; |
|
712 | + $data = ' data-colname="'.wp_strip_all_tags($column_display_name).'"'; |
|
713 | 713 | |
714 | 714 | $class = "class='$classes'"; |
715 | 715 | |
@@ -724,11 +724,11 @@ discard block |
||
724 | 724 | $this |
725 | 725 | ); |
726 | 726 | echo '</th>'; |
727 | - } elseif (method_exists($this, 'column_' . $column_name)) { |
|
727 | + } elseif (method_exists($this, 'column_'.$column_name)) { |
|
728 | 728 | echo "<td $attributes>"; |
729 | 729 | echo apply_filters( |
730 | - 'FHEE__EE_Admin_List_Table__single_row_columns__column_' . $column_name . '__column_content', |
|
731 | - call_user_func(array($this, 'column_' . $column_name), $item), |
|
730 | + 'FHEE__EE_Admin_List_Table__single_row_columns__column_'.$column_name.'__column_content', |
|
731 | + call_user_func(array($this, 'column_'.$column_name), $item), |
|
732 | 732 | $item, |
733 | 733 | $this |
734 | 734 | ); |
@@ -844,9 +844,9 @@ discard block |
||
844 | 844 | $action_id = '' |
845 | 845 | ) { |
846 | 846 | $content = ''; |
847 | - $action_class = ! empty($action_class) ? ' class="' . $action_class . '"' : ''; |
|
848 | - $action_id = ! empty($action_id) ? ' id="' . $action_id . '"' : ''; |
|
849 | - $content .= ! empty($action_container) ? '<' . $action_container . $action_class . $action_id . '>' : ''; |
|
847 | + $action_class = ! empty($action_class) ? ' class="'.$action_class.'"' : ''; |
|
848 | + $action_id = ! empty($action_id) ? ' id="'.$action_id.'"' : ''; |
|
849 | + $content .= ! empty($action_container) ? '<'.$action_container.$action_class.$action_id.'>' : ''; |
|
850 | 850 | try { |
851 | 851 | $content .= apply_filters( |
852 | 852 | 'FHEE__EE_Admin_List_Table___action_string__action_items', |
@@ -860,7 +860,7 @@ discard block |
||
860 | 860 | } |
861 | 861 | $content .= $action_items; |
862 | 862 | } |
863 | - $content .= ! empty($action_container) ? '</' . $action_container . '>' : ''; |
|
863 | + $content .= ! empty($action_container) ? '</'.$action_container.'>' : ''; |
|
864 | 864 | return $content; |
865 | 865 | } |
866 | 866 | } |
@@ -14,27 +14,27 @@ |
||
14 | 14 | class EE_Admin_File_Uploader_Input extends EE_Form_Input_Base |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * @param array $input_settings |
|
19 | - * @throws InvalidArgumentException |
|
20 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
21 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
22 | - */ |
|
23 | - public function __construct($input_settings = array()) |
|
24 | - { |
|
25 | - $this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy()); |
|
26 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
27 | - $this->_add_validation_strategy( |
|
28 | - LoaderFactory::getLoader()->getNew( |
|
29 | - 'EE_URL_Validation_Strategy', |
|
30 | - array( |
|
31 | - isset($input_settings['validation_error_message']) |
|
32 | - ? $input_settings['validation_error_message'] |
|
33 | - : null, |
|
34 | - false |
|
35 | - ) |
|
36 | - ) |
|
37 | - ); |
|
38 | - parent::__construct($input_settings); |
|
39 | - } |
|
17 | + /** |
|
18 | + * @param array $input_settings |
|
19 | + * @throws InvalidArgumentException |
|
20 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
21 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
22 | + */ |
|
23 | + public function __construct($input_settings = array()) |
|
24 | + { |
|
25 | + $this->_set_display_strategy(new EE_Admin_File_Uploader_Display_Strategy()); |
|
26 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
27 | + $this->_add_validation_strategy( |
|
28 | + LoaderFactory::getLoader()->getNew( |
|
29 | + 'EE_URL_Validation_Strategy', |
|
30 | + array( |
|
31 | + isset($input_settings['validation_error_message']) |
|
32 | + ? $input_settings['validation_error_message'] |
|
33 | + : null, |
|
34 | + false |
|
35 | + ) |
|
36 | + ) |
|
37 | + ); |
|
38 | + parent::__construct($input_settings); |
|
39 | + } |
|
40 | 40 | } |
@@ -16,142 +16,142 @@ |
||
16 | 16 | class Event_Categories_Admin_List_Table extends EE_Admin_List_Table |
17 | 17 | { |
18 | 18 | |
19 | - public function __construct($admin_page) |
|
20 | - { |
|
21 | - parent::__construct($admin_page); |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - protected function _setup_data() |
|
26 | - { |
|
27 | - $this->_data = $this->_admin_page->get_categories($this->_per_page, $this->_current_page); |
|
28 | - $this->_all_data_count = EEM_Term_Taxonomy::instance()->count( |
|
29 | - array(array('taxonomy' => 'espresso_event_categories')) |
|
30 | - ); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - protected function _set_properties() |
|
35 | - { |
|
36 | - $this->_wp_list_args = array( |
|
37 | - 'singular' => esc_html__('event category', 'event_espresso'), |
|
38 | - 'plural' => esc_html__('event categories', 'event_espresso'), |
|
39 | - 'ajax' => true, // for now, |
|
40 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
41 | - ); |
|
42 | - |
|
43 | - $this->_columns = array( |
|
44 | - 'cb' => '<input type="checkbox" />', |
|
45 | - 'id' => esc_html__('ID', 'event_espresso'), |
|
46 | - 'name' => esc_html__('Name', 'event_espresso'), |
|
47 | - 'shortcode' => esc_html__('Shortcode', 'event_espresso'), |
|
48 | - 'count' => esc_html__('Events', 'event_espresso'), |
|
49 | - ); |
|
50 | - |
|
51 | - $this->_sortable_columns = array( |
|
52 | - 'id' => array('Term.term_id' => true), |
|
53 | - 'name' => array('Term.slug' => false), |
|
54 | - 'count' => array('term_count' => false), |
|
55 | - ); |
|
56 | - |
|
57 | - $this->_primary_column = 'id'; |
|
58 | - |
|
59 | - $this->_hidden_columns = array(); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - // not needed |
|
64 | - protected function _get_table_filters() |
|
65 | - { |
|
66 | - return array(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - protected function _add_view_counts() |
|
71 | - { |
|
72 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - public function column_cb($item) |
|
77 | - { |
|
78 | - return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id')); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - public function column_id($item) |
|
83 | - { |
|
84 | - $content = $item->get('term_id'); |
|
85 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->get_first_related('Term')->get( |
|
86 | - 'name' |
|
87 | - ) . '</span>'; |
|
88 | - return $content; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - public function column_name($item) |
|
93 | - { |
|
94 | - $edit_query_args = array( |
|
95 | - 'action' => 'edit_category', |
|
96 | - 'EVT_CAT_ID' => $item->get('term_id'), |
|
97 | - ); |
|
98 | - |
|
99 | - $delete_query_args = array( |
|
100 | - 'action' => 'delete_category', |
|
101 | - 'EVT_CAT_ID' => $item->get('term_id'), |
|
102 | - ); |
|
103 | - |
|
104 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
105 | - $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL); |
|
106 | - |
|
107 | - $actions = array( |
|
108 | - 'edit' => '<a href="' . $edit_link . '" aria-label="' . esc_attr__( |
|
109 | - 'Edit Category', |
|
110 | - 'event_espresso' |
|
111 | - ) . '">' . esc_html__('Edit', 'event_espresso') . '</a>', |
|
112 | - ); |
|
113 | - |
|
114 | - $actions['delete'] = '<a href="' . $delete_link . '" aria-label="' . esc_attr__( |
|
115 | - 'Delete Category', |
|
116 | - 'event_espresso' |
|
117 | - ) . '">' . esc_html__('Delete', 'event_espresso') . '</a>'; |
|
118 | - |
|
119 | - $actions['view'] = sprintf( |
|
120 | - '<a href="%s" aria-label="%s">%s</a>', |
|
121 | - get_term_link($item->get('term_id')), |
|
122 | - esc_attr( |
|
123 | - sprintf( |
|
124 | - /* translators: %s: event category name */ |
|
125 | - __('View “%s” archive', 'event_espresso'), |
|
126 | - $item->get_first_related('Term')->get('name') |
|
127 | - ) |
|
128 | - ), |
|
129 | - esc_html__('View', 'event_espresso') |
|
130 | - ); |
|
131 | - |
|
132 | - $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->get_first_related('Term')->get( |
|
133 | - 'name' |
|
134 | - ) . '</a></strong>'; |
|
135 | - $content .= $this->row_actions($actions); |
|
136 | - return $content; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - public function column_shortcode($item) |
|
141 | - { |
|
142 | - $content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']'; |
|
143 | - return $content; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - public function column_count($item) |
|
148 | - { |
|
149 | - $e_args = array( |
|
150 | - 'action' => 'default', |
|
151 | - 'EVT_CAT' => $item->get_first_related('Term')->ID(), |
|
152 | - ); |
|
153 | - $e_link = EE_Admin_Page::add_query_args_and_nonce($e_args, EVENTS_ADMIN_URL); |
|
154 | - $content = '<a href="' . $e_link . '">' . $item->get('term_count') . '</a>'; |
|
155 | - return $content; |
|
156 | - } |
|
19 | + public function __construct($admin_page) |
|
20 | + { |
|
21 | + parent::__construct($admin_page); |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + protected function _setup_data() |
|
26 | + { |
|
27 | + $this->_data = $this->_admin_page->get_categories($this->_per_page, $this->_current_page); |
|
28 | + $this->_all_data_count = EEM_Term_Taxonomy::instance()->count( |
|
29 | + array(array('taxonomy' => 'espresso_event_categories')) |
|
30 | + ); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + protected function _set_properties() |
|
35 | + { |
|
36 | + $this->_wp_list_args = array( |
|
37 | + 'singular' => esc_html__('event category', 'event_espresso'), |
|
38 | + 'plural' => esc_html__('event categories', 'event_espresso'), |
|
39 | + 'ajax' => true, // for now, |
|
40 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
41 | + ); |
|
42 | + |
|
43 | + $this->_columns = array( |
|
44 | + 'cb' => '<input type="checkbox" />', |
|
45 | + 'id' => esc_html__('ID', 'event_espresso'), |
|
46 | + 'name' => esc_html__('Name', 'event_espresso'), |
|
47 | + 'shortcode' => esc_html__('Shortcode', 'event_espresso'), |
|
48 | + 'count' => esc_html__('Events', 'event_espresso'), |
|
49 | + ); |
|
50 | + |
|
51 | + $this->_sortable_columns = array( |
|
52 | + 'id' => array('Term.term_id' => true), |
|
53 | + 'name' => array('Term.slug' => false), |
|
54 | + 'count' => array('term_count' => false), |
|
55 | + ); |
|
56 | + |
|
57 | + $this->_primary_column = 'id'; |
|
58 | + |
|
59 | + $this->_hidden_columns = array(); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + // not needed |
|
64 | + protected function _get_table_filters() |
|
65 | + { |
|
66 | + return array(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + protected function _add_view_counts() |
|
71 | + { |
|
72 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + public function column_cb($item) |
|
77 | + { |
|
78 | + return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id')); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + public function column_id($item) |
|
83 | + { |
|
84 | + $content = $item->get('term_id'); |
|
85 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->get_first_related('Term')->get( |
|
86 | + 'name' |
|
87 | + ) . '</span>'; |
|
88 | + return $content; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + public function column_name($item) |
|
93 | + { |
|
94 | + $edit_query_args = array( |
|
95 | + 'action' => 'edit_category', |
|
96 | + 'EVT_CAT_ID' => $item->get('term_id'), |
|
97 | + ); |
|
98 | + |
|
99 | + $delete_query_args = array( |
|
100 | + 'action' => 'delete_category', |
|
101 | + 'EVT_CAT_ID' => $item->get('term_id'), |
|
102 | + ); |
|
103 | + |
|
104 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
105 | + $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL); |
|
106 | + |
|
107 | + $actions = array( |
|
108 | + 'edit' => '<a href="' . $edit_link . '" aria-label="' . esc_attr__( |
|
109 | + 'Edit Category', |
|
110 | + 'event_espresso' |
|
111 | + ) . '">' . esc_html__('Edit', 'event_espresso') . '</a>', |
|
112 | + ); |
|
113 | + |
|
114 | + $actions['delete'] = '<a href="' . $delete_link . '" aria-label="' . esc_attr__( |
|
115 | + 'Delete Category', |
|
116 | + 'event_espresso' |
|
117 | + ) . '">' . esc_html__('Delete', 'event_espresso') . '</a>'; |
|
118 | + |
|
119 | + $actions['view'] = sprintf( |
|
120 | + '<a href="%s" aria-label="%s">%s</a>', |
|
121 | + get_term_link($item->get('term_id')), |
|
122 | + esc_attr( |
|
123 | + sprintf( |
|
124 | + /* translators: %s: event category name */ |
|
125 | + __('View “%s” archive', 'event_espresso'), |
|
126 | + $item->get_first_related('Term')->get('name') |
|
127 | + ) |
|
128 | + ), |
|
129 | + esc_html__('View', 'event_espresso') |
|
130 | + ); |
|
131 | + |
|
132 | + $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->get_first_related('Term')->get( |
|
133 | + 'name' |
|
134 | + ) . '</a></strong>'; |
|
135 | + $content .= $this->row_actions($actions); |
|
136 | + return $content; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + public function column_shortcode($item) |
|
141 | + { |
|
142 | + $content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']'; |
|
143 | + return $content; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + public function column_count($item) |
|
148 | + { |
|
149 | + $e_args = array( |
|
150 | + 'action' => 'default', |
|
151 | + 'EVT_CAT' => $item->get_first_related('Term')->ID(), |
|
152 | + ); |
|
153 | + $e_link = EE_Admin_Page::add_query_args_and_nonce($e_args, EVENTS_ADMIN_URL); |
|
154 | + $content = '<a href="' . $e_link . '">' . $item->get('term_count') . '</a>'; |
|
155 | + return $content; |
|
156 | + } |
|
157 | 157 | } |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | public function column_id($item) |
83 | 83 | { |
84 | 84 | $content = $item->get('term_id'); |
85 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->get_first_related('Term')->get( |
|
85 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->get_first_related('Term')->get( |
|
86 | 86 | 'name' |
87 | - ) . '</span>'; |
|
87 | + ).'</span>'; |
|
88 | 88 | return $content; |
89 | 89 | } |
90 | 90 | |
@@ -105,16 +105,16 @@ discard block |
||
105 | 105 | $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL); |
106 | 106 | |
107 | 107 | $actions = array( |
108 | - 'edit' => '<a href="' . $edit_link . '" aria-label="' . esc_attr__( |
|
108 | + 'edit' => '<a href="'.$edit_link.'" aria-label="'.esc_attr__( |
|
109 | 109 | 'Edit Category', |
110 | 110 | 'event_espresso' |
111 | - ) . '">' . esc_html__('Edit', 'event_espresso') . '</a>', |
|
111 | + ).'">'.esc_html__('Edit', 'event_espresso').'</a>', |
|
112 | 112 | ); |
113 | 113 | |
114 | - $actions['delete'] = '<a href="' . $delete_link . '" aria-label="' . esc_attr__( |
|
114 | + $actions['delete'] = '<a href="'.$delete_link.'" aria-label="'.esc_attr__( |
|
115 | 115 | 'Delete Category', |
116 | 116 | 'event_espresso' |
117 | - ) . '">' . esc_html__('Delete', 'event_espresso') . '</a>'; |
|
117 | + ).'">'.esc_html__('Delete', 'event_espresso').'</a>'; |
|
118 | 118 | |
119 | 119 | $actions['view'] = sprintf( |
120 | 120 | '<a href="%s" aria-label="%s">%s</a>', |
@@ -129,9 +129,9 @@ discard block |
||
129 | 129 | esc_html__('View', 'event_espresso') |
130 | 130 | ); |
131 | 131 | |
132 | - $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->get_first_related('Term')->get( |
|
132 | + $content = '<strong><a class="row-title" href="'.$edit_link.'">'.$item->get_first_related('Term')->get( |
|
133 | 133 | 'name' |
134 | - ) . '</a></strong>'; |
|
134 | + ).'</a></strong>'; |
|
135 | 135 | $content .= $this->row_actions($actions); |
136 | 136 | return $content; |
137 | 137 | } |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | public function column_shortcode($item) |
141 | 141 | { |
142 | - $content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']'; |
|
142 | + $content = '[ESPRESSO_EVENTS category_slug='.$item->get_first_related('Term')->get('slug').']'; |
|
143 | 143 | return $content; |
144 | 144 | } |
145 | 145 | |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | 'EVT_CAT' => $item->get_first_related('Term')->ID(), |
152 | 152 | ); |
153 | 153 | $e_link = EE_Admin_Page::add_query_args_and_nonce($e_args, EVENTS_ADMIN_URL); |
154 | - $content = '<a href="' . $e_link . '">' . $item->get('term_count') . '</a>'; |
|
154 | + $content = '<a href="'.$e_link.'">'.$item->get('term_count').'</a>'; |
|
155 | 155 | return $content; |
156 | 156 | } |
157 | 157 | } |
@@ -12,173 +12,173 @@ |
||
12 | 12 | class EEH_Maps |
13 | 13 | { |
14 | 14 | |
15 | - // array of map settings |
|
16 | - public static $gmap_vars = array(); |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * google_map - creates a Google Map Link |
|
21 | - * |
|
22 | - * @param array $ee_gmaps_opts array of attributes required for the map link generation |
|
23 | - * @return string (link to map!) |
|
24 | - */ |
|
25 | - public static function google_map($ee_gmaps_opts) |
|
26 | - { |
|
27 | - |
|
28 | - $ee_map_width = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300'; |
|
29 | - $ee_map_height = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185'; |
|
30 | - $ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12'; |
|
31 | - $ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false'; |
|
32 | - $ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size']) |
|
33 | - ? $ee_gmaps_opts['ee_map_nav_size'] |
|
34 | - : 'default'; |
|
35 | - $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control']) |
|
36 | - ? $ee_gmaps_opts['ee_map_type_control'] |
|
37 | - : 'default'; |
|
38 | - $static_url = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false; |
|
39 | - |
|
40 | - if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
41 | - switch ($ee_gmaps_opts['ee_map_align']) { |
|
42 | - case "left": |
|
43 | - $map_align = 'ee-gmap-align-left left'; |
|
44 | - break; |
|
45 | - case "right": |
|
46 | - $map_align = 'ee-gmap-align-right right'; |
|
47 | - break; |
|
48 | - case "center": |
|
49 | - $map_align = 'ee-gmap-align-center center'; |
|
50 | - break; |
|
51 | - case "none": |
|
52 | - default: |
|
53 | - $map_align = 'ee-gmap-align-none'; |
|
54 | - } |
|
55 | - } else { |
|
56 | - $map_align = 'ee-gmap-align-none'; |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - // Determine whether user has set a hardoded url to use and |
|
61 | - // if so display a Google static iframe map else run V3 api |
|
62 | - if ($static_url) { |
|
63 | - $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">'; |
|
64 | - $html .= '<iframe src="' . $static_url . '&output=embed"' |
|
65 | - . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"' |
|
66 | - . ' frameborder="0" scrolling="no">'; |
|
67 | - $html .= '</iframe>'; |
|
68 | - $html .= '<a href="' . $static_url . '">View Large map</a>'; |
|
69 | - $html .= '</div>'; |
|
70 | - return $html; |
|
71 | - } else { |
|
72 | - EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = array( |
|
73 | - 'map_ID' => $ee_gmaps_opts['map_ID'], |
|
74 | - 'ee_map_zoom' => $ee_map_zoom, |
|
75 | - 'ee_map_nav_display' => $ee_map_nav_display, |
|
76 | - 'ee_map_nav_size' => $ee_map_nav_size, |
|
77 | - 'ee_map_type_control' => $ee_map_type_control, |
|
78 | - 'location' => $ee_gmaps_opts['location'], |
|
79 | - ); |
|
80 | - |
|
81 | - $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
82 | - $html = '<div class="ee-gmap-wrapper ' . $map_align . '">' |
|
83 | - . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"' |
|
84 | - . ' style="' . $style . '"></div>' |
|
85 | - . '</div>'; |
|
86 | - |
|
87 | - wp_enqueue_script('gmap_api'); |
|
88 | - wp_enqueue_script('ee_gmap'); |
|
89 | - add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script')); |
|
90 | - |
|
91 | - return $html; |
|
92 | - } // end auto map or static url map check |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * enqueue_script |
|
98 | - * |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public static function footer_enqueue_script() |
|
102 | - { |
|
103 | - wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * registers scripts for maps |
|
109 | - */ |
|
110 | - public static function espresso_google_map_js() |
|
111 | - { |
|
112 | - $api_url = sprintf( |
|
113 | - "https://maps.googleapis.com/maps/api/js?key=%s", |
|
114 | - apply_filters( |
|
115 | - 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
116 | - EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
117 | - ) |
|
118 | - ); |
|
119 | - wp_register_script('gmap_api', $api_url, array('jquery'), null, true); |
|
120 | - wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * creates a Google Map Link |
|
125 | - * |
|
126 | - * @param array $atts array of attributes required for the map link generation |
|
127 | - * @return string (link to map!) |
|
128 | - */ |
|
129 | - public static function google_map_link($atts) |
|
130 | - { |
|
131 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
132 | - extract($atts); |
|
133 | - /** @var string $address */ |
|
134 | - /** @var string $city */ |
|
135 | - /** @var string $state */ |
|
136 | - /** @var string $zip */ |
|
137 | - /** @var string $country */ |
|
138 | - $address = "{$address}"; |
|
139 | - $city = "{$city}"; |
|
140 | - $state = "{$state}"; |
|
141 | - $zip = "{$zip}"; |
|
142 | - $country = "{$country}"; |
|
143 | - $text = isset($text) ? "{$text}" : ""; |
|
144 | - $type = isset($type) ? "{$type}" : ""; |
|
145 | - $map_w = isset($map_w) ? "{$map_w}" : 400; |
|
146 | - $map_h = isset($map_h) ? "{$map_h}" : 400; |
|
147 | - $id = isset($id) ? $id : 'not_set'; |
|
148 | - $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
|
149 | - |
|
150 | - $address_string = ($address != '' ? $address : '') |
|
151 | - . ($city != '' ? ',' . $city : '') |
|
152 | - . ($state != '' ? ',' . $state : '') |
|
153 | - . ($zip != '' ? ',' . $zip : '') |
|
154 | - . ($country != '' ? ',' . $country : ''); |
|
155 | - |
|
156 | - $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string)); |
|
157 | - |
|
158 | - switch ($type) { |
|
159 | - case 'text': |
|
160 | - default: |
|
161 | - $text = $text == '' ? esc_html__('Map and Directions', 'event_espresso') : $text; |
|
162 | - break; |
|
163 | - |
|
164 | - case 'url_only': |
|
165 | - case 'url': |
|
166 | - $text = $google_map; |
|
167 | - break; |
|
168 | - |
|
169 | - case 'map': |
|
170 | - $scheme = is_ssl() ? 'https://' : 'http://'; |
|
171 | - |
|
172 | - $api_key = apply_filters( |
|
173 | - 'FHEE__EEH_Maps__espresso_google_maps_link__api_key', |
|
174 | - EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
175 | - ); |
|
176 | - |
|
177 | - return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank" rel="noopener noreferrer">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&zoom=14&size=' . $map_w . 'x' . $map_h . '&markers=color:green|label:|' . urlencode($address_string) . '&sensor=false&key=' . $api_key) . '" /></a>'; |
|
178 | - } |
|
179 | - |
|
180 | - return $type === 'url_only' |
|
181 | - ? $text |
|
182 | - : '<a href="' . $google_map . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>'; |
|
183 | - } |
|
15 | + // array of map settings |
|
16 | + public static $gmap_vars = array(); |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * google_map - creates a Google Map Link |
|
21 | + * |
|
22 | + * @param array $ee_gmaps_opts array of attributes required for the map link generation |
|
23 | + * @return string (link to map!) |
|
24 | + */ |
|
25 | + public static function google_map($ee_gmaps_opts) |
|
26 | + { |
|
27 | + |
|
28 | + $ee_map_width = ! empty($ee_gmaps_opts['ee_map_width']) ? $ee_gmaps_opts['ee_map_width'] : '300'; |
|
29 | + $ee_map_height = ! empty($ee_gmaps_opts['ee_map_height']) ? $ee_gmaps_opts['ee_map_height'] : '185'; |
|
30 | + $ee_map_zoom = ! empty($ee_gmaps_opts['ee_map_zoom']) ? $ee_gmaps_opts['ee_map_zoom'] : '12'; |
|
31 | + $ee_map_nav_display = ! empty($ee_gmaps_opts['ee_map_nav_display']) ? 'true' : 'false'; |
|
32 | + $ee_map_nav_size = ! empty($ee_gmaps_opts['ee_map_nav_size']) |
|
33 | + ? $ee_gmaps_opts['ee_map_nav_size'] |
|
34 | + : 'default'; |
|
35 | + $ee_map_type_control = ! empty($ee_gmaps_opts['ee_map_type_control']) |
|
36 | + ? $ee_gmaps_opts['ee_map_type_control'] |
|
37 | + : 'default'; |
|
38 | + $static_url = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false; |
|
39 | + |
|
40 | + if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
41 | + switch ($ee_gmaps_opts['ee_map_align']) { |
|
42 | + case "left": |
|
43 | + $map_align = 'ee-gmap-align-left left'; |
|
44 | + break; |
|
45 | + case "right": |
|
46 | + $map_align = 'ee-gmap-align-right right'; |
|
47 | + break; |
|
48 | + case "center": |
|
49 | + $map_align = 'ee-gmap-align-center center'; |
|
50 | + break; |
|
51 | + case "none": |
|
52 | + default: |
|
53 | + $map_align = 'ee-gmap-align-none'; |
|
54 | + } |
|
55 | + } else { |
|
56 | + $map_align = 'ee-gmap-align-none'; |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + // Determine whether user has set a hardoded url to use and |
|
61 | + // if so display a Google static iframe map else run V3 api |
|
62 | + if ($static_url) { |
|
63 | + $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">'; |
|
64 | + $html .= '<iframe src="' . $static_url . '&output=embed"' |
|
65 | + . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"' |
|
66 | + . ' frameborder="0" scrolling="no">'; |
|
67 | + $html .= '</iframe>'; |
|
68 | + $html .= '<a href="' . $static_url . '">View Large map</a>'; |
|
69 | + $html .= '</div>'; |
|
70 | + return $html; |
|
71 | + } else { |
|
72 | + EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = array( |
|
73 | + 'map_ID' => $ee_gmaps_opts['map_ID'], |
|
74 | + 'ee_map_zoom' => $ee_map_zoom, |
|
75 | + 'ee_map_nav_display' => $ee_map_nav_display, |
|
76 | + 'ee_map_nav_size' => $ee_map_nav_size, |
|
77 | + 'ee_map_type_control' => $ee_map_type_control, |
|
78 | + 'location' => $ee_gmaps_opts['location'], |
|
79 | + ); |
|
80 | + |
|
81 | + $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
82 | + $html = '<div class="ee-gmap-wrapper ' . $map_align . '">' |
|
83 | + . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"' |
|
84 | + . ' style="' . $style . '"></div>' |
|
85 | + . '</div>'; |
|
86 | + |
|
87 | + wp_enqueue_script('gmap_api'); |
|
88 | + wp_enqueue_script('ee_gmap'); |
|
89 | + add_action('wp_footer', array('EEH_Maps', 'footer_enqueue_script')); |
|
90 | + |
|
91 | + return $html; |
|
92 | + } // end auto map or static url map check |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * enqueue_script |
|
98 | + * |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public static function footer_enqueue_script() |
|
102 | + { |
|
103 | + wp_localize_script('ee_gmap', 'ee_gmap_vars', EEH_Maps::$gmap_vars); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * registers scripts for maps |
|
109 | + */ |
|
110 | + public static function espresso_google_map_js() |
|
111 | + { |
|
112 | + $api_url = sprintf( |
|
113 | + "https://maps.googleapis.com/maps/api/js?key=%s", |
|
114 | + apply_filters( |
|
115 | + 'FHEE__EEH_Maps__espresso_google_maps_js__api_key', |
|
116 | + EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
117 | + ) |
|
118 | + ); |
|
119 | + wp_register_script('gmap_api', $api_url, array('jquery'), null, true); |
|
120 | + wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * creates a Google Map Link |
|
125 | + * |
|
126 | + * @param array $atts array of attributes required for the map link generation |
|
127 | + * @return string (link to map!) |
|
128 | + */ |
|
129 | + public static function google_map_link($atts) |
|
130 | + { |
|
131 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
132 | + extract($atts); |
|
133 | + /** @var string $address */ |
|
134 | + /** @var string $city */ |
|
135 | + /** @var string $state */ |
|
136 | + /** @var string $zip */ |
|
137 | + /** @var string $country */ |
|
138 | + $address = "{$address}"; |
|
139 | + $city = "{$city}"; |
|
140 | + $state = "{$state}"; |
|
141 | + $zip = "{$zip}"; |
|
142 | + $country = "{$country}"; |
|
143 | + $text = isset($text) ? "{$text}" : ""; |
|
144 | + $type = isset($type) ? "{$type}" : ""; |
|
145 | + $map_w = isset($map_w) ? "{$map_w}" : 400; |
|
146 | + $map_h = isset($map_h) ? "{$map_h}" : 400; |
|
147 | + $id = isset($id) ? $id : 'not_set'; |
|
148 | + $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
|
149 | + |
|
150 | + $address_string = ($address != '' ? $address : '') |
|
151 | + . ($city != '' ? ',' . $city : '') |
|
152 | + . ($state != '' ? ',' . $state : '') |
|
153 | + . ($zip != '' ? ',' . $zip : '') |
|
154 | + . ($country != '' ? ',' . $country : ''); |
|
155 | + |
|
156 | + $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string)); |
|
157 | + |
|
158 | + switch ($type) { |
|
159 | + case 'text': |
|
160 | + default: |
|
161 | + $text = $text == '' ? esc_html__('Map and Directions', 'event_espresso') : $text; |
|
162 | + break; |
|
163 | + |
|
164 | + case 'url_only': |
|
165 | + case 'url': |
|
166 | + $text = $google_map; |
|
167 | + break; |
|
168 | + |
|
169 | + case 'map': |
|
170 | + $scheme = is_ssl() ? 'https://' : 'http://'; |
|
171 | + |
|
172 | + $api_key = apply_filters( |
|
173 | + 'FHEE__EEH_Maps__espresso_google_maps_link__api_key', |
|
174 | + EE_Registry::instance()->CFG->map_settings->google_map_api_key |
|
175 | + ); |
|
176 | + |
|
177 | + return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank" rel="noopener noreferrer">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&zoom=14&size=' . $map_w . 'x' . $map_h . '&markers=color:green|label:|' . urlencode($address_string) . '&sensor=false&key=' . $api_key) . '" /></a>'; |
|
178 | + } |
|
179 | + |
|
180 | + return $type === 'url_only' |
|
181 | + ? $text |
|
182 | + : '<a href="' . $google_map . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>'; |
|
183 | + } |
|
184 | 184 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | : 'default'; |
38 | 38 | $static_url = ! empty($ee_gmaps_opts['ee_static_url']) ? $ee_gmaps_opts['ee_static_url'] : false; |
39 | 39 | |
40 | - if (! empty($ee_gmaps_opts['ee_map_align'])) { |
|
40 | + if ( ! empty($ee_gmaps_opts['ee_map_align'])) { |
|
41 | 41 | switch ($ee_gmaps_opts['ee_map_align']) { |
42 | 42 | case "left": |
43 | 43 | $map_align = 'ee-gmap-align-left left'; |
@@ -60,16 +60,16 @@ discard block |
||
60 | 60 | // Determine whether user has set a hardoded url to use and |
61 | 61 | // if so display a Google static iframe map else run V3 api |
62 | 62 | if ($static_url) { |
63 | - $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper ' . $map_align . '">'; |
|
64 | - $html .= '<iframe src="' . $static_url . '&output=embed"' |
|
65 | - . ' style="width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;"' |
|
63 | + $html = '<div class="ee-gmap-iframewrap ee-gmap-wrapper '.$map_align.'">'; |
|
64 | + $html .= '<iframe src="'.$static_url.'&output=embed"' |
|
65 | + . ' style="width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;"' |
|
66 | 66 | . ' frameborder="0" scrolling="no">'; |
67 | 67 | $html .= '</iframe>'; |
68 | - $html .= '<a href="' . $static_url . '">View Large map</a>'; |
|
68 | + $html .= '<a href="'.$static_url.'">View Large map</a>'; |
|
69 | 69 | $html .= '</div>'; |
70 | 70 | return $html; |
71 | 71 | } else { |
72 | - EEH_Maps::$gmap_vars[ $ee_gmaps_opts['map_ID'] ] = array( |
|
72 | + EEH_Maps::$gmap_vars[$ee_gmaps_opts['map_ID']] = array( |
|
73 | 73 | 'map_ID' => $ee_gmaps_opts['map_ID'], |
74 | 74 | 'ee_map_zoom' => $ee_map_zoom, |
75 | 75 | 'ee_map_nav_display' => $ee_map_nav_display, |
@@ -78,10 +78,10 @@ discard block |
||
78 | 78 | 'location' => $ee_gmaps_opts['location'], |
79 | 79 | ); |
80 | 80 | |
81 | - $style = 'width: ' . $ee_map_width . 'px; height: ' . $ee_map_height . 'px;'; |
|
82 | - $html = '<div class="ee-gmap-wrapper ' . $map_align . '">' |
|
83 | - . '<div class="ee-gmap" id="map_canvas_' . $ee_gmaps_opts['map_ID'] . '"' |
|
84 | - . ' style="' . $style . '"></div>' |
|
81 | + $style = 'width: '.$ee_map_width.'px; height: '.$ee_map_height.'px;'; |
|
82 | + $html = '<div class="ee-gmap-wrapper '.$map_align.'">' |
|
83 | + . '<div class="ee-gmap" id="map_canvas_'.$ee_gmaps_opts['map_ID'].'"' |
|
84 | + . ' style="'.$style.'"></div>' |
|
85 | 85 | . '</div>'; |
86 | 86 | |
87 | 87 | wp_enqueue_script('gmap_api'); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ) |
118 | 118 | ); |
119 | 119 | wp_register_script('gmap_api', $api_url, array('jquery'), null, true); |
120 | - wp_register_script('ee_gmap', plugin_dir_url(__FILE__) . 'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
|
120 | + wp_register_script('ee_gmap', plugin_dir_url(__FILE__).'assets/ee_gmap.js', array('gmap_api'), '1.0', true); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -148,12 +148,12 @@ discard block |
||
148 | 148 | $map_image_class = isset($map_image_class) ? $map_image_class : 'ee_google_map_view'; |
149 | 149 | |
150 | 150 | $address_string = ($address != '' ? $address : '') |
151 | - . ($city != '' ? ',' . $city : '') |
|
152 | - . ($state != '' ? ',' . $state : '') |
|
153 | - . ($zip != '' ? ',' . $zip : '') |
|
154 | - . ($country != '' ? ',' . $country : ''); |
|
151 | + . ($city != '' ? ','.$city : '') |
|
152 | + . ($state != '' ? ','.$state : '') |
|
153 | + . ($zip != '' ? ','.$zip : '') |
|
154 | + . ($country != '' ? ','.$country : ''); |
|
155 | 155 | |
156 | - $google_map = htmlentities2('http://maps.google.com/maps?q=' . urlencode($address_string)); |
|
156 | + $google_map = htmlentities2('http://maps.google.com/maps?q='.urlencode($address_string)); |
|
157 | 157 | |
158 | 158 | switch ($type) { |
159 | 159 | case 'text': |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | EE_Registry::instance()->CFG->map_settings->google_map_api_key |
175 | 175 | ); |
176 | 176 | |
177 | - return '<a class="a_map_image_link" href="' . $google_map . '" target="_blank" rel="noopener noreferrer">' . '<img class="map_image_link" id="venue_map_' . $id . '" ' . $map_image_class . ' src="' . htmlentities2($scheme . 'maps.googleapis.com/maps/api/staticmap?center=' . urlencode($address_string) . '&zoom=14&size=' . $map_w . 'x' . $map_h . '&markers=color:green|label:|' . urlencode($address_string) . '&sensor=false&key=' . $api_key) . '" /></a>'; |
|
177 | + return '<a class="a_map_image_link" href="'.$google_map.'" target="_blank" rel="noopener noreferrer">'.'<img class="map_image_link" id="venue_map_'.$id.'" '.$map_image_class.' src="'.htmlentities2($scheme.'maps.googleapis.com/maps/api/staticmap?center='.urlencode($address_string).'&zoom=14&size='.$map_w.'x'.$map_h.'&markers=color:green|label:|'.urlencode($address_string).'&sensor=false&key='.$api_key).'" /></a>'; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | return $type === 'url_only' |
181 | 181 | ? $text |
182 | - : '<a href="' . $google_map . '" target="_blank" rel="noopener noreferrer">' . $text . '</a>'; |
|
182 | + : '<a href="'.$google_map.'" target="_blank" rel="noopener noreferrer">'.$text.'</a>'; |
|
183 | 183 | } |
184 | 184 | } |
@@ -1,8 +1,8 @@ |
||
1 | 1 | <div class="padding"> |
2 | 2 | <p><?php |
3 | - printf( |
|
4 | - esc_html__('Check out the %1$sroadmap for Event Espresso%2$s.', 'event_espresso'), |
|
5 | - '<a href="https://trello.com/b/zg9DCIpe/event-espresso-public-roadmap" target="_blank" rel="noopener noreferrer">', |
|
6 | - '</a>' |
|
7 | - ); ?></p> |
|
3 | + printf( |
|
4 | + esc_html__('Check out the %1$sroadmap for Event Espresso%2$s.', 'event_espresso'), |
|
5 | + '<a href="https://trello.com/b/zg9DCIpe/event-espresso-public-roadmap" target="_blank" rel="noopener noreferrer">', |
|
6 | + '</a>' |
|
7 | + ); ?></p> |
|
8 | 8 | </div> |
9 | 9 | \ No newline at end of file |
@@ -16,39 +16,39 @@ discard block |
||
16 | 16 | <div class="sandbox-panel"> |
17 | 17 | <h2 class="section-title"><?php _e('PayPal Sandbox Mode', 'event_espresso'); ?></h2> |
18 | 18 | <h3 style="color:#ff0000;"><?php |
19 | - _e( |
|
20 | - 'Debug Mode Is Turned On. Payments will not be processed', |
|
21 | - 'event_espresso' |
|
22 | - ); ?></h3> |
|
19 | + _e( |
|
20 | + 'Debug Mode Is Turned On. Payments will not be processed', |
|
21 | + 'event_espresso' |
|
22 | + ); ?></h3> |
|
23 | 23 | |
24 | 24 | <p class="test-credit-cards-info-pg" style="margin-bottom:0;"> |
25 | 25 | <strong><?php _e('Testing Guidelines', 'event_espresso'); ?></strong> |
26 | 26 | </p> |
27 | 27 | <ul style="margin:1em 2em 1.5em; line-height:1.2em;"> |
28 | 28 | <li><?php |
29 | - _e( |
|
30 | - 'While testing, use the credit card number associated with your sandbox account.', |
|
31 | - 'event_espresso' |
|
32 | - ); ?></li> |
|
29 | + _e( |
|
30 | + 'While testing, use the credit card number associated with your sandbox account.', |
|
31 | + 'event_espresso' |
|
32 | + ); ?></li> |
|
33 | 33 | <li><?php |
34 | - printf( |
|
35 | - __( |
|
36 | - 'To find the sandbox account\'s credit card, go to %1$s, then "Dashboard", then under Sandbox click "Accounts", then click your account and click "Profile", then in the popup that appears click on the "Funding" tab. Your testing card is listed there.', |
|
37 | - 'event_espresso' |
|
38 | - ), |
|
39 | - '<a href="http://developer.paypal.com">developer.paypal.com</a>' |
|
40 | - ); ?></li> |
|
34 | + printf( |
|
35 | + __( |
|
36 | + 'To find the sandbox account\'s credit card, go to %1$s, then "Dashboard", then under Sandbox click "Accounts", then click your account and click "Profile", then in the popup that appears click on the "Funding" tab. Your testing card is listed there.', |
|
37 | + 'event_espresso' |
|
38 | + ), |
|
39 | + '<a href="http://developer.paypal.com">developer.paypal.com</a>' |
|
40 | + ); ?></li> |
|
41 | 41 | <li><?php |
42 | - esc_html_e('CVV2 should be 115', 'event_espresso'); ?></li> |
|
42 | + esc_html_e('CVV2 should be 115', 'event_espresso'); ?></li> |
|
43 | 43 | </ul> |
44 | 44 | |
45 | 45 | <p class="test-credit-cards-info-pg"> |
46 | 46 | <strong><?php _e('Credit Card Numbers Used for Testing', 'event_espresso'); ?></strong><br/> |
47 | 47 | <span class="small-text"><?php |
48 | - _e( |
|
49 | - 'Use the following credit card numbers for testing. Any other card number produces a general failure.', |
|
50 | - 'event_espresso' |
|
51 | - ); ?></span> |
|
48 | + _e( |
|
49 | + 'Use the following credit card numbers for testing. Any other card number produces a general failure.', |
|
50 | + 'event_espresso' |
|
51 | + ); ?></span> |
|
52 | 52 | </p> |
53 | 53 | |
54 | 54 | <div class="tbl-wrap"> |
@@ -72,18 +72,18 @@ discard block |
||
72 | 72 | <p class="test-credit-cards-info-pg"> |
73 | 73 | <strong><?php _e('Testing Result Code Responses', 'event_espresso'); ?></strong><br/> |
74 | 74 | <span class="small-text"><?php |
75 | - printf( |
|
76 | - __( |
|
77 | - 'You can use the amount of the transaction to generate a particular result code (see %s PayPal\'s documentation%s). The table below lists the general guidelines for specifying amounts. IMPORTANT: before you attempt any of these, ensure your sandbox PayPal account has %s "Negative Testing" set to on%s. Also be aware that you can generate AVS errors by using certain strings in your address field, and CVV errors using certain CVV values. See %s this PayPal doc %s', |
|
78 | - 'event_espresso' |
|
79 | - ), |
|
80 | - "<a href='https://developer.paypal.com/docs/classic/api/errorcodes/#id09C3GA00GR1' target='_blank'>", |
|
81 | - "</a>", |
|
82 | - "<a href='https://docs.google.com/a/eventespresso.com/file/d/0B5P8GXTvZgfMNXNkZ2s5VUlHTUk/edit?usp=drivesdk' target='_blank'>", |
|
83 | - "</a>", |
|
84 | - "<a href='https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_testing_SBTestErrorConditions' target='_blank'>", |
|
85 | - "</a>" |
|
86 | - ); ?></span> |
|
75 | + printf( |
|
76 | + __( |
|
77 | + 'You can use the amount of the transaction to generate a particular result code (see %s PayPal\'s documentation%s). The table below lists the general guidelines for specifying amounts. IMPORTANT: before you attempt any of these, ensure your sandbox PayPal account has %s "Negative Testing" set to on%s. Also be aware that you can generate AVS errors by using certain strings in your address field, and CVV errors using certain CVV values. See %s this PayPal doc %s', |
|
78 | + 'event_espresso' |
|
79 | + ), |
|
80 | + "<a href='https://developer.paypal.com/docs/classic/api/errorcodes/#id09C3GA00GR1' target='_blank'>", |
|
81 | + "</a>", |
|
82 | + "<a href='https://docs.google.com/a/eventespresso.com/file/d/0B5P8GXTvZgfMNXNkZ2s5VUlHTUk/edit?usp=drivesdk' target='_blank'>", |
|
83 | + "</a>", |
|
84 | + "<a href='https://cms.paypal.com/ca/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_testing_SBTestErrorConditions' target='_blank'>", |
|
85 | + "</a>" |
|
86 | + ); ?></span> |
|
87 | 87 | </p> |
88 | 88 | |
89 | 89 | <div class="tbl-wrap"> |