@@ -17,214 +17,214 @@ |
||
17 | 17 | |
18 | 18 | class Datetime extends DatetimeCalculationBase |
19 | 19 | { |
20 | - /** |
|
21 | - * @var EEM_Datetime |
|
22 | - */ |
|
23 | - protected $datetime_model; |
|
20 | + /** |
|
21 | + * @var EEM_Datetime |
|
22 | + */ |
|
23 | + protected $datetime_model; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var EEM_Registration |
|
27 | - */ |
|
28 | - protected $registration_model; |
|
29 | - public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model) |
|
30 | - { |
|
31 | - $this->datetime_model = $datetime_model; |
|
32 | - $this->registration_model = $registration_model; |
|
33 | - } |
|
25 | + /** |
|
26 | + * @var EEM_Registration |
|
27 | + */ |
|
28 | + protected $registration_model; |
|
29 | + public function __construct(EEM_Datetime $datetime_model, EEM_Registration $registration_model) |
|
30 | + { |
|
31 | + $this->datetime_model = $datetime_model; |
|
32 | + $this->registration_model = $registration_model; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Calculates the total spaces available on the datetime, taking into account |
|
37 | - * ticket limits too. |
|
38 | - * |
|
39 | - * @see EE_Datetime::spaces_remaining( true ) |
|
40 | - * @param array $wpdb_row |
|
41 | - * @param WP_REST_Request $request |
|
42 | - * @param DatetimeControllerBase $controller |
|
43 | - * @return int |
|
44 | - * @throws EE_Error |
|
45 | - * @throws InvalidDataTypeException |
|
46 | - * @throws InvalidInterfaceException |
|
47 | - * @throws InvalidArgumentException |
|
48 | - * @throws ReflectionException |
|
49 | - */ |
|
50 | - public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller) |
|
51 | - { |
|
52 | - if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
53 | - $dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
54 | - } else { |
|
55 | - $dtt_obj = null; |
|
56 | - } |
|
57 | - if ($dtt_obj instanceof EE_Datetime) { |
|
58 | - return $dtt_obj->spaces_remaining(true); |
|
59 | - } |
|
60 | - throw new EE_Error( |
|
61 | - sprintf( |
|
62 | - __( |
|
63 | - // @codingStandardsIgnoreStart |
|
64 | - 'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', |
|
65 | - // @codingStandardsIgnoreEnd |
|
66 | - 'event_espresso' |
|
67 | - ), |
|
68 | - $wpdb_row['Datetime.DTT_ID'], |
|
69 | - print_r($wpdb_row, true) |
|
70 | - ) |
|
71 | - ); |
|
72 | - } |
|
35 | + /** |
|
36 | + * Calculates the total spaces available on the datetime, taking into account |
|
37 | + * ticket limits too. |
|
38 | + * |
|
39 | + * @see EE_Datetime::spaces_remaining( true ) |
|
40 | + * @param array $wpdb_row |
|
41 | + * @param WP_REST_Request $request |
|
42 | + * @param DatetimeControllerBase $controller |
|
43 | + * @return int |
|
44 | + * @throws EE_Error |
|
45 | + * @throws InvalidDataTypeException |
|
46 | + * @throws InvalidInterfaceException |
|
47 | + * @throws InvalidArgumentException |
|
48 | + * @throws ReflectionException |
|
49 | + */ |
|
50 | + public function spacesRemainingConsideringTickets($wpdb_row, $request, $controller) |
|
51 | + { |
|
52 | + if (is_array($wpdb_row) && isset($wpdb_row['Datetime.DTT_ID'])) { |
|
53 | + $dtt_obj = $this->datetime_model->get_one_by_ID($wpdb_row['Datetime.DTT_ID']); |
|
54 | + } else { |
|
55 | + $dtt_obj = null; |
|
56 | + } |
|
57 | + if ($dtt_obj instanceof EE_Datetime) { |
|
58 | + return $dtt_obj->spaces_remaining(true); |
|
59 | + } |
|
60 | + throw new EE_Error( |
|
61 | + sprintf( |
|
62 | + __( |
|
63 | + // @codingStandardsIgnoreStart |
|
64 | + 'Cannot calculate spaces_remaining_considering_tickets because the datetime with ID %1$s (from database row %2$s) was not found', |
|
65 | + // @codingStandardsIgnoreEnd |
|
66 | + 'event_espresso' |
|
67 | + ), |
|
68 | + $wpdb_row['Datetime.DTT_ID'], |
|
69 | + print_r($wpdb_row, true) |
|
70 | + ) |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * Counts registrations who have checked into this datetime |
|
77 | - * |
|
78 | - * @param array $wpdb_row |
|
79 | - * @param WP_REST_Request $request |
|
80 | - * @param DatetimeControllerBase $controller |
|
81 | - * @return int |
|
82 | - * @throws EE_Error |
|
83 | - * @throws InvalidArgumentException |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - * @throws InvalidInterfaceException |
|
86 | - * @throws RestException |
|
87 | - */ |
|
88 | - public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
89 | - { |
|
90 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
91 | - throw new EE_Error( |
|
92 | - sprintf( |
|
93 | - __( |
|
94 | - // @codingStandardsIgnoreStart |
|
95 | - 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
96 | - // @codingStandardsIgnoreEnd |
|
97 | - 'event_espresso' |
|
98 | - ), |
|
99 | - print_r($wpdb_row, true) |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
104 | - return $this->registration_model |
|
105 | - ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
106 | - } |
|
75 | + /** |
|
76 | + * Counts registrations who have checked into this datetime |
|
77 | + * |
|
78 | + * @param array $wpdb_row |
|
79 | + * @param WP_REST_Request $request |
|
80 | + * @param DatetimeControllerBase $controller |
|
81 | + * @return int |
|
82 | + * @throws EE_Error |
|
83 | + * @throws InvalidArgumentException |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + * @throws InvalidInterfaceException |
|
86 | + * @throws RestException |
|
87 | + */ |
|
88 | + public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
89 | + { |
|
90 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
91 | + throw new EE_Error( |
|
92 | + sprintf( |
|
93 | + __( |
|
94 | + // @codingStandardsIgnoreStart |
|
95 | + 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
96 | + // @codingStandardsIgnoreEnd |
|
97 | + 'event_espresso' |
|
98 | + ), |
|
99 | + print_r($wpdb_row, true) |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
104 | + return $this->registration_model |
|
105 | + ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], true); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Counts registrations who have checked out of this datetime |
|
111 | - * |
|
112 | - * @param array $wpdb_row |
|
113 | - * @param WP_REST_Request $request |
|
114 | - * @param DatetimeControllerBase $controller |
|
115 | - * @return int |
|
116 | - * @throws EE_Error |
|
117 | - * @throws InvalidArgumentException |
|
118 | - * @throws InvalidDataTypeException |
|
119 | - * @throws InvalidInterfaceException |
|
120 | - * @throws RestException |
|
121 | - */ |
|
122 | - public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
123 | - { |
|
124 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
125 | - throw new EE_Error( |
|
126 | - sprintf( |
|
127 | - __( |
|
128 | - // @codingStandardsIgnoreStart |
|
129 | - 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
130 | - // @codingStandardsIgnoreEnd |
|
131 | - 'event_espresso' |
|
132 | - ), |
|
133 | - print_r($wpdb_row, true) |
|
134 | - ) |
|
135 | - ); |
|
136 | - } |
|
137 | - $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
138 | - return $this->registration_model |
|
139 | - ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
140 | - } |
|
109 | + /** |
|
110 | + * Counts registrations who have checked out of this datetime |
|
111 | + * |
|
112 | + * @param array $wpdb_row |
|
113 | + * @param WP_REST_Request $request |
|
114 | + * @param DatetimeControllerBase $controller |
|
115 | + * @return int |
|
116 | + * @throws EE_Error |
|
117 | + * @throws InvalidArgumentException |
|
118 | + * @throws InvalidDataTypeException |
|
119 | + * @throws InvalidInterfaceException |
|
120 | + * @throws RestException |
|
121 | + */ |
|
122 | + public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
123 | + { |
|
124 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
125 | + throw new EE_Error( |
|
126 | + sprintf( |
|
127 | + __( |
|
128 | + // @codingStandardsIgnoreStart |
|
129 | + 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
130 | + // @codingStandardsIgnoreEnd |
|
131 | + 'event_espresso' |
|
132 | + ), |
|
133 | + print_r($wpdb_row, true) |
|
134 | + ) |
|
135 | + ); |
|
136 | + } |
|
137 | + $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
138 | + return $this->registration_model |
|
139 | + ->count_registrations_checked_into_datetime($wpdb_row['Datetime.DTT_ID'], false); |
|
140 | + } |
|
141 | 141 | |
142 | 142 | |
143 | - /** |
|
144 | - * Counts the number of pending-payment registrations for this event (regardless |
|
145 | - * of how many datetimes each registrations' ticket purchase is for) |
|
146 | - * |
|
147 | - * @param array $wpdb_row |
|
148 | - * @param WP_REST_Request $request |
|
149 | - * @param DatetimeControllerBase $controller |
|
150 | - * @return int |
|
151 | - * @throws EE_Error |
|
152 | - * @throws InvalidArgumentException |
|
153 | - * @throws InvalidDataTypeException |
|
154 | - * @throws InvalidInterfaceException |
|
155 | - * @throws RestException |
|
156 | - */ |
|
157 | - public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
158 | - { |
|
159 | - if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
160 | - throw new EE_Error( |
|
161 | - sprintf( |
|
162 | - __( |
|
163 | - // @codingStandardsIgnoreStart |
|
164 | - 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
165 | - // @codingStandardsIgnoreEnd |
|
166 | - 'event_espresso' |
|
167 | - ), |
|
168 | - print_r($wpdb_row, true) |
|
169 | - ) |
|
170 | - ); |
|
171 | - } |
|
172 | - $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
173 | - return $this->registration_model->count( |
|
174 | - array( |
|
175 | - array( |
|
176 | - 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
177 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
178 | - ), |
|
179 | - ), |
|
180 | - 'REG_ID', |
|
181 | - true |
|
182 | - ); |
|
183 | - } |
|
143 | + /** |
|
144 | + * Counts the number of pending-payment registrations for this event (regardless |
|
145 | + * of how many datetimes each registrations' ticket purchase is for) |
|
146 | + * |
|
147 | + * @param array $wpdb_row |
|
148 | + * @param WP_REST_Request $request |
|
149 | + * @param DatetimeControllerBase $controller |
|
150 | + * @return int |
|
151 | + * @throws EE_Error |
|
152 | + * @throws InvalidArgumentException |
|
153 | + * @throws InvalidDataTypeException |
|
154 | + * @throws InvalidInterfaceException |
|
155 | + * @throws RestException |
|
156 | + */ |
|
157 | + public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
158 | + { |
|
159 | + if (! is_array($wpdb_row) || ! isset($wpdb_row['Datetime.DTT_ID'])) { |
|
160 | + throw new EE_Error( |
|
161 | + sprintf( |
|
162 | + __( |
|
163 | + // @codingStandardsIgnoreStart |
|
164 | + 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Datetime.DTT_ID"', |
|
165 | + // @codingStandardsIgnoreEnd |
|
166 | + 'event_espresso' |
|
167 | + ), |
|
168 | + print_r($wpdb_row, true) |
|
169 | + ) |
|
170 | + ); |
|
171 | + } |
|
172 | + $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
173 | + return $this->registration_model->count( |
|
174 | + array( |
|
175 | + array( |
|
176 | + 'Ticket.Datetime.DTT_ID' => $wpdb_row['Datetime.DTT_ID'], |
|
177 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
178 | + ), |
|
179 | + ), |
|
180 | + 'REG_ID', |
|
181 | + true |
|
182 | + ); |
|
183 | + } |
|
184 | 184 | |
185 | 185 | |
186 | - /** |
|
187 | - * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
188 | - * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
189 | - * |
|
190 | - * @since 4.9.68.p |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function schemaForCalculations() |
|
194 | - { |
|
195 | - return array( |
|
196 | - 'spaces_remaining_considering_tickets' => array( |
|
197 | - 'description' => esc_html__( |
|
198 | - 'Calculates the total spaces available on the datetime, taking into account ticket limits too.', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - 'type' => 'number', |
|
202 | - 'protected' => true, |
|
203 | - ), |
|
204 | - 'registrations_checked_in_count' => array( |
|
205 | - 'description' => esc_html__( |
|
206 | - 'Counts registrations who have checked into this datetime.', |
|
207 | - 'event_espresso' |
|
208 | - ), |
|
209 | - 'type' => 'number', |
|
210 | - 'protected' => true, |
|
211 | - ), |
|
212 | - 'registrations_checked_out_count' => array( |
|
213 | - 'description' => esc_html__( |
|
214 | - 'Counts registrations who have checked out of this datetime.', |
|
215 | - 'event_espresso' |
|
216 | - ), |
|
217 | - 'type' => 'number', |
|
218 | - 'protected' => true, |
|
219 | - ), |
|
220 | - 'spots_taken_pending_payment' => array( |
|
221 | - 'description' => esc_html__( |
|
222 | - 'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for', |
|
223 | - 'event_espresso' |
|
224 | - ), |
|
225 | - 'type' => 'number', |
|
226 | - 'protected' => true, |
|
227 | - ), |
|
228 | - ); |
|
229 | - } |
|
186 | + /** |
|
187 | + * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
188 | + * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
189 | + * |
|
190 | + * @since 4.9.68.p |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function schemaForCalculations() |
|
194 | + { |
|
195 | + return array( |
|
196 | + 'spaces_remaining_considering_tickets' => array( |
|
197 | + 'description' => esc_html__( |
|
198 | + 'Calculates the total spaces available on the datetime, taking into account ticket limits too.', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + 'type' => 'number', |
|
202 | + 'protected' => true, |
|
203 | + ), |
|
204 | + 'registrations_checked_in_count' => array( |
|
205 | + 'description' => esc_html__( |
|
206 | + 'Counts registrations who have checked into this datetime.', |
|
207 | + 'event_espresso' |
|
208 | + ), |
|
209 | + 'type' => 'number', |
|
210 | + 'protected' => true, |
|
211 | + ), |
|
212 | + 'registrations_checked_out_count' => array( |
|
213 | + 'description' => esc_html__( |
|
214 | + 'Counts registrations who have checked out of this datetime.', |
|
215 | + 'event_espresso' |
|
216 | + ), |
|
217 | + 'type' => 'number', |
|
218 | + 'protected' => true, |
|
219 | + ), |
|
220 | + 'spots_taken_pending_payment' => array( |
|
221 | + 'description' => esc_html__( |
|
222 | + 'The count of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for', |
|
223 | + 'event_espresso' |
|
224 | + ), |
|
225 | + 'type' => 'number', |
|
226 | + 'protected' => true, |
|
227 | + ), |
|
228 | + ); |
|
229 | + } |
|
230 | 230 | } |
@@ -26,571 +26,571 @@ |
||
26 | 26 | */ |
27 | 27 | class Event extends EventCalculationBase |
28 | 28 | { |
29 | - /** |
|
30 | - * @var EEM_Event |
|
31 | - */ |
|
32 | - protected $event_model; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var EEM_Registration |
|
36 | - */ |
|
37 | - protected $registration_model; |
|
38 | - public function __construct(EEM_Event $event_model, EEM_Registration $registration_model) |
|
39 | - { |
|
40 | - $this->event_model = $event_model; |
|
41 | - $this->registration_model = $registration_model; |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Calculates the total spaces on the event (not subtracting sales, but taking |
|
46 | - * sales into account; so this is the optimum sales that CAN still be achieved) |
|
47 | - * See EE_Event::total_available_spaces( true ); |
|
48 | - * |
|
49 | - * @param array $wpdb_row |
|
50 | - * @param WP_REST_Request $request |
|
51 | - * @param EventControllerBase $controller |
|
52 | - * @return int |
|
53 | - * @throws EE_Error |
|
54 | - * @throws DomainException |
|
55 | - * @throws InvalidDataTypeException |
|
56 | - * @throws InvalidInterfaceException |
|
57 | - * @throws UnexpectedEntityException |
|
58 | - * @throws InvalidArgumentException |
|
59 | - */ |
|
60 | - public function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
61 | - { |
|
62 | - $event_obj = null; |
|
63 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
64 | - $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
65 | - } |
|
66 | - if ($event_obj instanceof EE_Event) { |
|
67 | - return $event_obj->total_available_spaces(); |
|
68 | - } |
|
69 | - throw new EE_Error( |
|
70 | - sprintf( |
|
71 | - __( |
|
72 | - // @codingStandardsIgnoreStart |
|
73 | - 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
74 | - // @codingStandardsIgnoreEnd |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - $wpdb_row['Event_CPT.ID'], |
|
78 | - print_r($wpdb_row, true) |
|
79 | - ) |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
86 | - * sales that COULD have been achieved) |
|
87 | - * See EE_Event::total_available_spaces( true ); |
|
88 | - * |
|
89 | - * @param array $wpdb_row |
|
90 | - * @param WP_REST_Request $request |
|
91 | - * @param EventControllerBase $controller |
|
92 | - * @return int |
|
93 | - * @throws DomainException |
|
94 | - * @throws EE_Error |
|
95 | - * @throws InvalidArgumentException |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - * @throws UnexpectedEntityException |
|
99 | - */ |
|
100 | - public function optimumSalesNow($wpdb_row, $request, $controller) |
|
101 | - { |
|
102 | - $event_obj = null; |
|
103 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
104 | - $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
105 | - } |
|
106 | - if ($event_obj instanceof EE_Event) { |
|
107 | - return $event_obj->total_available_spaces(true); |
|
108 | - } |
|
109 | - throw new EE_Error( |
|
110 | - sprintf( |
|
111 | - __( |
|
112 | - // @codingStandardsIgnoreStart |
|
113 | - 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
114 | - // @codingStandardsIgnoreEnd |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - $wpdb_row['Event_CPT.ID'], |
|
118 | - print_r($wpdb_row, true) |
|
119 | - ) |
|
120 | - ); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * Like optimum_sales_now, but minus total sales so far. |
|
126 | - * See EE_Event::spaces_remaining_for_sale( true ); |
|
127 | - * |
|
128 | - * @param array $wpdb_row |
|
129 | - * @param WP_REST_Request $request |
|
130 | - * @param EventControllerBase $controller |
|
131 | - * @return int |
|
132 | - * @throws DomainException |
|
133 | - * @throws EE_Error |
|
134 | - * @throws InvalidArgumentException |
|
135 | - * @throws InvalidDataTypeException |
|
136 | - * @throws InvalidInterfaceException |
|
137 | - * @throws UnexpectedEntityException |
|
138 | - */ |
|
139 | - public function spacesRemaining($wpdb_row, $request, $controller) |
|
140 | - { |
|
141 | - $event_obj = null; |
|
142 | - if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
143 | - $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
144 | - } |
|
145 | - if ($event_obj instanceof EE_Event) { |
|
146 | - return $event_obj->spaces_remaining_for_sale(); |
|
147 | - } |
|
148 | - throw new EE_Error( |
|
149 | - sprintf( |
|
150 | - __( |
|
151 | - // @codingStandardsIgnoreStart |
|
152 | - 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
153 | - // @codingStandardsIgnoreEnd |
|
154 | - 'event_espresso' |
|
155 | - ), |
|
156 | - $wpdb_row['Event_CPT.ID'], |
|
157 | - print_r($wpdb_row, true) |
|
158 | - ) |
|
159 | - ); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Counts the number of approved registrations for this event (regardless |
|
165 | - * of how many datetimes each registrations' ticket purchase is for) |
|
166 | - * |
|
167 | - * @param array $wpdb_row |
|
168 | - * @param WP_REST_Request $request |
|
169 | - * @param EventControllerBase $controller |
|
170 | - * @return int |
|
171 | - * @throws EE_Error |
|
172 | - * @throws InvalidArgumentException |
|
173 | - * @throws InvalidDataTypeException |
|
174 | - * @throws InvalidInterfaceException |
|
175 | - */ |
|
176 | - public function spotsTaken($wpdb_row, $request, $controller) |
|
177 | - { |
|
178 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
179 | - throw new EE_Error( |
|
180 | - sprintf( |
|
181 | - __( |
|
182 | - // @codingStandardsIgnoreStart |
|
183 | - 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
184 | - // @codingStandardsIgnoreEnd |
|
185 | - 'event_espresso' |
|
186 | - ), |
|
187 | - print_r($wpdb_row, true) |
|
188 | - ) |
|
189 | - ); |
|
190 | - } |
|
191 | - return $this->registration_model->count( |
|
192 | - array( |
|
193 | - array( |
|
194 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
195 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
196 | - ), |
|
197 | - ), |
|
198 | - 'REG_ID', |
|
199 | - true |
|
200 | - ); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * Counts the number of pending-payment registrations for this event (regardless |
|
206 | - * of how many datetimes each registrations' ticket purchase is for) |
|
207 | - * |
|
208 | - * @param array $wpdb_row |
|
209 | - * @param WP_REST_Request $request |
|
210 | - * @param EventControllerBase $controller |
|
211 | - * @return int |
|
212 | - * @throws EE_Error |
|
213 | - * @throws InvalidArgumentException |
|
214 | - * @throws InvalidDataTypeException |
|
215 | - * @throws InvalidInterfaceException |
|
216 | - * @throws RestException |
|
217 | - */ |
|
218 | - public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
219 | - { |
|
220 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
221 | - throw new EE_Error( |
|
222 | - sprintf( |
|
223 | - __( |
|
224 | - // @codingStandardsIgnoreStart |
|
225 | - 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
226 | - // @codingStandardsIgnoreEnd |
|
227 | - 'event_espresso' |
|
228 | - ), |
|
229 | - print_r($wpdb_row, true) |
|
230 | - ) |
|
231 | - ); |
|
232 | - } |
|
233 | - $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
234 | - return $this->registration_model->count( |
|
235 | - array( |
|
236 | - array( |
|
237 | - 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
238 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
239 | - ), |
|
240 | - ), |
|
241 | - 'REG_ID', |
|
242 | - true |
|
243 | - ); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Counts all the registrations who have checked into one of this events' datetimes |
|
249 | - * See EE_Event::total_available_spaces( false ); |
|
250 | - * |
|
251 | - * @param array $wpdb_row |
|
252 | - * @param WP_REST_Request $request |
|
253 | - * @param EventControllerBase $controller |
|
254 | - * @return int|null if permission denied |
|
255 | - * @throws EE_Error |
|
256 | - * @throws InvalidArgumentException |
|
257 | - * @throws InvalidDataTypeException |
|
258 | - * @throws InvalidInterfaceException |
|
259 | - * @throws RestException |
|
260 | - */ |
|
261 | - public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
262 | - { |
|
263 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
264 | - throw new EE_Error( |
|
265 | - sprintf( |
|
266 | - __( |
|
267 | - // @codingStandardsIgnoreStart |
|
268 | - 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
269 | - // @codingStandardsIgnoreEnd |
|
270 | - 'event_espresso' |
|
271 | - ), |
|
272 | - print_r($wpdb_row, true) |
|
273 | - ) |
|
274 | - ); |
|
275 | - } |
|
276 | - $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
277 | - return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Counts all the registrations who have checked out of one of this events' datetimes |
|
283 | - * See EE_Event::total_available_spaces( false ); |
|
284 | - * |
|
285 | - * @param array $wpdb_row |
|
286 | - * @param WP_REST_Request $request |
|
287 | - * @param EventControllerBase $controller |
|
288 | - * @return int |
|
289 | - * @throws EE_Error |
|
290 | - * @throws InvalidArgumentException |
|
291 | - * @throws InvalidDataTypeException |
|
292 | - * @throws InvalidInterfaceException |
|
293 | - * @throws RestException |
|
294 | - */ |
|
295 | - public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
296 | - { |
|
297 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
298 | - throw new EE_Error( |
|
299 | - sprintf( |
|
300 | - __( |
|
301 | - // @codingStandardsIgnoreStart |
|
302 | - 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
303 | - // @codingStandardsIgnoreEnd |
|
304 | - 'event_espresso' |
|
305 | - ), |
|
306 | - print_r($wpdb_row, true) |
|
307 | - ) |
|
308 | - ); |
|
309 | - } |
|
310 | - $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
311 | - return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Gets the thumbnail image |
|
317 | - * |
|
318 | - * @param array $wpdb_row |
|
319 | - * @param WP_REST_Request $request |
|
320 | - * @param EventControllerBase $controller |
|
321 | - * @return array |
|
322 | - * @throws EE_Error |
|
323 | - */ |
|
324 | - public function imageThumbnail($wpdb_row, $request, $controller) |
|
325 | - { |
|
326 | - return self::calculateImageData($wpdb_row, 'thumbnail'); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * Gets the medium image |
|
332 | - * |
|
333 | - * @param array $wpdb_row |
|
334 | - * @param WP_REST_Request $request |
|
335 | - * @param EventControllerBase $controller |
|
336 | - * @return array |
|
337 | - * @throws EE_Error |
|
338 | - */ |
|
339 | - public function imageMedium($wpdb_row, $request, $controller) |
|
340 | - { |
|
341 | - return self::calculateImageData($wpdb_row, 'medium'); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - /** |
|
346 | - * Gets the medium-large image |
|
347 | - * |
|
348 | - * @param array $wpdb_row |
|
349 | - * @param WP_REST_Request $request |
|
350 | - * @param EventControllerBase $controller |
|
351 | - * @return array |
|
352 | - * @throws EE_Error |
|
353 | - */ |
|
354 | - public function imageMediumLarge($wpdb_row, $request, $controller) |
|
355 | - { |
|
356 | - return self::calculateImageData($wpdb_row, 'medium_large'); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Gets the large image |
|
362 | - * |
|
363 | - * @param array $wpdb_row |
|
364 | - * @param WP_REST_Request $request |
|
365 | - * @param EventControllerBase $controller |
|
366 | - * @return array |
|
367 | - * @throws EE_Error |
|
368 | - */ |
|
369 | - public function imageLarge($wpdb_row, $request, $controller) |
|
370 | - { |
|
371 | - return self::calculateImageData($wpdb_row, 'large'); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Gets the post-thumbnail image |
|
377 | - * |
|
378 | - * @param array $wpdb_row |
|
379 | - * @param WP_REST_Request $request |
|
380 | - * @param EventControllerBase $controller |
|
381 | - * @return array |
|
382 | - * @throws EE_Error |
|
383 | - */ |
|
384 | - public function imagePostThumbnail($wpdb_row, $request, $controller) |
|
385 | - { |
|
386 | - return self::calculateImageData($wpdb_row, 'post-thumbnail'); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Gets the full size image |
|
392 | - * |
|
393 | - * @param array $wpdb_row |
|
394 | - * @param WP_REST_Request $request |
|
395 | - * @param EventControllerBase $controller |
|
396 | - * @return array |
|
397 | - * @throws EE_Error |
|
398 | - */ |
|
399 | - public function imageFull($wpdb_row, $request, $controller) |
|
400 | - { |
|
401 | - return self::calculateImageData($wpdb_row, 'full'); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Gets image specs and formats them for the display in the API, |
|
407 | - * according to the image size requested |
|
408 | - * |
|
409 | - * @param array $wpdb_row |
|
410 | - * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
411 | - * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
412 | - * @throws EE_Error |
|
413 | - */ |
|
414 | - protected function calculateImageData($wpdb_row, $image_size) |
|
415 | - { |
|
416 | - if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
417 | - throw new EE_Error( |
|
418 | - sprintf( |
|
419 | - __( |
|
420 | - // @codingStandardsIgnoreStart |
|
421 | - 'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
422 | - // @codingStandardsIgnoreEnd |
|
423 | - 'event_espresso' |
|
424 | - ), |
|
425 | - print_r($wpdb_row, true) |
|
426 | - ) |
|
427 | - ); |
|
428 | - } |
|
429 | - $EVT_ID = $wpdb_row['Event_CPT.ID']; |
|
430 | - $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
431 | - $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
432 | - if (! $data) { |
|
433 | - return null; |
|
434 | - } |
|
435 | - $generated = true; |
|
436 | - if (isset($data[3])) { |
|
437 | - $generated = $data[3]; |
|
438 | - } |
|
439 | - return array( |
|
440 | - 'url' => $data[0], |
|
441 | - 'width' => $data[1], |
|
442 | - 'height' => $data[2], |
|
443 | - 'generated' => $generated, |
|
444 | - ); |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise |
|
450 | - * |
|
451 | - * @param array $wpdb_row |
|
452 | - * @return bool |
|
453 | - */ |
|
454 | - protected function wpdbRowHasEventId($wpdb_row) |
|
455 | - { |
|
456 | - return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
462 | - * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
463 | - * |
|
464 | - * @since 4.9.68.p |
|
465 | - * @return array |
|
466 | - */ |
|
467 | - public function schemaForCalculations() |
|
468 | - { |
|
469 | - $image_object_properties = array( |
|
470 | - 'url' => array( |
|
471 | - 'type' => 'string', |
|
472 | - ), |
|
473 | - 'width' => array( |
|
474 | - 'type' => 'number', |
|
475 | - ), |
|
476 | - 'height' => array( |
|
477 | - 'type' => 'number', |
|
478 | - ), |
|
479 | - 'generated' => array( |
|
480 | - 'type' => 'boolean', |
|
481 | - ), |
|
482 | - ); |
|
483 | - return array( |
|
484 | - 'optimum_sales_at_start' => array( |
|
485 | - 'description' => esc_html__( |
|
486 | - 'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.', |
|
487 | - 'event_espresso' |
|
488 | - ), |
|
489 | - 'type' => 'number', |
|
490 | - 'protected' => true, |
|
491 | - ), |
|
492 | - 'optimum_sales_now' => array( |
|
493 | - 'description' => esc_html__( |
|
494 | - 'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.', |
|
495 | - 'event_espresso' |
|
496 | - ), |
|
497 | - 'type' => 'number', |
|
498 | - 'protected' => true, |
|
499 | - ), |
|
500 | - 'spaces_remaining' => array( |
|
501 | - 'description' => esc_html__( |
|
502 | - 'The optimum_sales_number result, minus total sales so far.', |
|
503 | - 'event_espresso' |
|
504 | - ), |
|
505 | - 'type' => 'number', |
|
506 | - 'protected' => true, |
|
507 | - ), |
|
508 | - 'spots_taken' => array( |
|
509 | - 'description' => esc_html__( |
|
510 | - 'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)', |
|
511 | - 'event_espresso' |
|
512 | - ), |
|
513 | - 'type' => 'number', |
|
514 | - 'protected' => true, |
|
515 | - ), |
|
516 | - 'spots_taken_pending_payment' => array( |
|
517 | - 'description' => esc_html__( |
|
518 | - 'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)', |
|
519 | - 'event_espresso' |
|
520 | - ), |
|
521 | - 'type' => 'number', |
|
522 | - 'protected' => true, |
|
523 | - ), |
|
524 | - 'registrations_checked_in_count' => array( |
|
525 | - 'description' => esc_html__( |
|
526 | - 'The count of all the registrations who have checked into one of this event\'s datetimes.', |
|
527 | - 'event_espresso' |
|
528 | - ), |
|
529 | - 'type' => 'number', |
|
530 | - 'protected' => true, |
|
531 | - ), |
|
532 | - 'registrations_checked_out_count' => array( |
|
533 | - 'description' => esc_html__( |
|
534 | - 'The count of all registrations who have checked out of one of this event\'s datetimes.', |
|
535 | - 'event_espresso' |
|
536 | - ), |
|
537 | - 'type' => 'number', |
|
538 | - 'protected' => true, |
|
539 | - ), |
|
540 | - 'image_thumbnail' => array( |
|
541 | - 'description' => esc_html__( |
|
542 | - 'The thumbnail image data.', |
|
543 | - 'event_espresso' |
|
544 | - ), |
|
545 | - 'type' => 'object', |
|
546 | - 'properties' => $image_object_properties, |
|
547 | - 'additionalProperties' => false, |
|
548 | - ), |
|
549 | - 'image_medium' => array( |
|
550 | - 'description' => esc_html__( |
|
551 | - 'The medium image data.', |
|
552 | - 'event_espresso' |
|
553 | - ), |
|
554 | - 'type' => 'object', |
|
555 | - 'properties' => $image_object_properties, |
|
556 | - 'additionalProperties' => false, |
|
557 | - ), |
|
558 | - 'image_medium_large' => array( |
|
559 | - 'description' => esc_html__( |
|
560 | - 'The medium-large image data.', |
|
561 | - 'event_espresso' |
|
562 | - ), |
|
563 | - 'type' => 'object', |
|
564 | - 'properties' => $image_object_properties, |
|
565 | - 'additionalProperties' => false, |
|
566 | - ), |
|
567 | - 'image_large' => array( |
|
568 | - 'description' => esc_html__( |
|
569 | - 'The large image data.', |
|
570 | - 'event_espresso' |
|
571 | - ), |
|
572 | - 'type' => 'object', |
|
573 | - 'properties' => $image_object_properties, |
|
574 | - 'additionalProperties' => false, |
|
575 | - ), |
|
576 | - 'image_post_thumbnail' => array( |
|
577 | - 'description' => esc_html__( |
|
578 | - 'The post-thumbnail image data.', |
|
579 | - 'event_espresso' |
|
580 | - ), |
|
581 | - 'type' => 'object', |
|
582 | - 'properties' => $image_object_properties, |
|
583 | - 'additionalProperties' => false, |
|
584 | - ), |
|
585 | - 'image_full' => array( |
|
586 | - 'description' => esc_html__( |
|
587 | - 'The full size image data', |
|
588 | - 'event_espresso' |
|
589 | - ), |
|
590 | - 'type' => 'object', |
|
591 | - 'properties' => $image_object_properties, |
|
592 | - 'additionalProperties' => false, |
|
593 | - ), |
|
594 | - ); |
|
595 | - } |
|
29 | + /** |
|
30 | + * @var EEM_Event |
|
31 | + */ |
|
32 | + protected $event_model; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var EEM_Registration |
|
36 | + */ |
|
37 | + protected $registration_model; |
|
38 | + public function __construct(EEM_Event $event_model, EEM_Registration $registration_model) |
|
39 | + { |
|
40 | + $this->event_model = $event_model; |
|
41 | + $this->registration_model = $registration_model; |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Calculates the total spaces on the event (not subtracting sales, but taking |
|
46 | + * sales into account; so this is the optimum sales that CAN still be achieved) |
|
47 | + * See EE_Event::total_available_spaces( true ); |
|
48 | + * |
|
49 | + * @param array $wpdb_row |
|
50 | + * @param WP_REST_Request $request |
|
51 | + * @param EventControllerBase $controller |
|
52 | + * @return int |
|
53 | + * @throws EE_Error |
|
54 | + * @throws DomainException |
|
55 | + * @throws InvalidDataTypeException |
|
56 | + * @throws InvalidInterfaceException |
|
57 | + * @throws UnexpectedEntityException |
|
58 | + * @throws InvalidArgumentException |
|
59 | + */ |
|
60 | + public function optimumSalesAtStart($wpdb_row, $request, $controller) |
|
61 | + { |
|
62 | + $event_obj = null; |
|
63 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
64 | + $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
65 | + } |
|
66 | + if ($event_obj instanceof EE_Event) { |
|
67 | + return $event_obj->total_available_spaces(); |
|
68 | + } |
|
69 | + throw new EE_Error( |
|
70 | + sprintf( |
|
71 | + __( |
|
72 | + // @codingStandardsIgnoreStart |
|
73 | + 'Cannot calculate optimum_sales_at_start because the event with ID %1$s (from database row %2$s) was not found', |
|
74 | + // @codingStandardsIgnoreEnd |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + $wpdb_row['Event_CPT.ID'], |
|
78 | + print_r($wpdb_row, true) |
|
79 | + ) |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Calculates the total spaces on the event (ignoring all sales; so this is the optimum |
|
86 | + * sales that COULD have been achieved) |
|
87 | + * See EE_Event::total_available_spaces( true ); |
|
88 | + * |
|
89 | + * @param array $wpdb_row |
|
90 | + * @param WP_REST_Request $request |
|
91 | + * @param EventControllerBase $controller |
|
92 | + * @return int |
|
93 | + * @throws DomainException |
|
94 | + * @throws EE_Error |
|
95 | + * @throws InvalidArgumentException |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + * @throws UnexpectedEntityException |
|
99 | + */ |
|
100 | + public function optimumSalesNow($wpdb_row, $request, $controller) |
|
101 | + { |
|
102 | + $event_obj = null; |
|
103 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
104 | + $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
105 | + } |
|
106 | + if ($event_obj instanceof EE_Event) { |
|
107 | + return $event_obj->total_available_spaces(true); |
|
108 | + } |
|
109 | + throw new EE_Error( |
|
110 | + sprintf( |
|
111 | + __( |
|
112 | + // @codingStandardsIgnoreStart |
|
113 | + 'Cannot calculate optimum_sales_now because the event with ID %1$s (from database row %2$s) was not found', |
|
114 | + // @codingStandardsIgnoreEnd |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + $wpdb_row['Event_CPT.ID'], |
|
118 | + print_r($wpdb_row, true) |
|
119 | + ) |
|
120 | + ); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * Like optimum_sales_now, but minus total sales so far. |
|
126 | + * See EE_Event::spaces_remaining_for_sale( true ); |
|
127 | + * |
|
128 | + * @param array $wpdb_row |
|
129 | + * @param WP_REST_Request $request |
|
130 | + * @param EventControllerBase $controller |
|
131 | + * @return int |
|
132 | + * @throws DomainException |
|
133 | + * @throws EE_Error |
|
134 | + * @throws InvalidArgumentException |
|
135 | + * @throws InvalidDataTypeException |
|
136 | + * @throws InvalidInterfaceException |
|
137 | + * @throws UnexpectedEntityException |
|
138 | + */ |
|
139 | + public function spacesRemaining($wpdb_row, $request, $controller) |
|
140 | + { |
|
141 | + $event_obj = null; |
|
142 | + if (Event::wpdbRowHasEventId($wpdb_row)) { |
|
143 | + $event_obj = $this->event_model->get_one_by_ID($wpdb_row['Event_CPT.ID']); |
|
144 | + } |
|
145 | + if ($event_obj instanceof EE_Event) { |
|
146 | + return $event_obj->spaces_remaining_for_sale(); |
|
147 | + } |
|
148 | + throw new EE_Error( |
|
149 | + sprintf( |
|
150 | + __( |
|
151 | + // @codingStandardsIgnoreStart |
|
152 | + 'Cannot calculate spaces_remaining because the event with ID %1$s (from database row %2$s) was not found', |
|
153 | + // @codingStandardsIgnoreEnd |
|
154 | + 'event_espresso' |
|
155 | + ), |
|
156 | + $wpdb_row['Event_CPT.ID'], |
|
157 | + print_r($wpdb_row, true) |
|
158 | + ) |
|
159 | + ); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Counts the number of approved registrations for this event (regardless |
|
165 | + * of how many datetimes each registrations' ticket purchase is for) |
|
166 | + * |
|
167 | + * @param array $wpdb_row |
|
168 | + * @param WP_REST_Request $request |
|
169 | + * @param EventControllerBase $controller |
|
170 | + * @return int |
|
171 | + * @throws EE_Error |
|
172 | + * @throws InvalidArgumentException |
|
173 | + * @throws InvalidDataTypeException |
|
174 | + * @throws InvalidInterfaceException |
|
175 | + */ |
|
176 | + public function spotsTaken($wpdb_row, $request, $controller) |
|
177 | + { |
|
178 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
179 | + throw new EE_Error( |
|
180 | + sprintf( |
|
181 | + __( |
|
182 | + // @codingStandardsIgnoreStart |
|
183 | + 'Cannot calculate spots_taken because the database row %1$s does not have a valid entry for "Event_CPT.ID"', |
|
184 | + // @codingStandardsIgnoreEnd |
|
185 | + 'event_espresso' |
|
186 | + ), |
|
187 | + print_r($wpdb_row, true) |
|
188 | + ) |
|
189 | + ); |
|
190 | + } |
|
191 | + return $this->registration_model->count( |
|
192 | + array( |
|
193 | + array( |
|
194 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
195 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
196 | + ), |
|
197 | + ), |
|
198 | + 'REG_ID', |
|
199 | + true |
|
200 | + ); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * Counts the number of pending-payment registrations for this event (regardless |
|
206 | + * of how many datetimes each registrations' ticket purchase is for) |
|
207 | + * |
|
208 | + * @param array $wpdb_row |
|
209 | + * @param WP_REST_Request $request |
|
210 | + * @param EventControllerBase $controller |
|
211 | + * @return int |
|
212 | + * @throws EE_Error |
|
213 | + * @throws InvalidArgumentException |
|
214 | + * @throws InvalidDataTypeException |
|
215 | + * @throws InvalidInterfaceException |
|
216 | + * @throws RestException |
|
217 | + */ |
|
218 | + public function spotsTakenPendingPayment($wpdb_row, $request, $controller) |
|
219 | + { |
|
220 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
221 | + throw new EE_Error( |
|
222 | + sprintf( |
|
223 | + __( |
|
224 | + // @codingStandardsIgnoreStart |
|
225 | + 'Cannot calculate spots_taken_pending_payment because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
226 | + // @codingStandardsIgnoreEnd |
|
227 | + 'event_espresso' |
|
228 | + ), |
|
229 | + print_r($wpdb_row, true) |
|
230 | + ) |
|
231 | + ); |
|
232 | + } |
|
233 | + $this->verifyCurrentUserCan('ee_read_registrations', 'spots_taken_pending_payment'); |
|
234 | + return $this->registration_model->count( |
|
235 | + array( |
|
236 | + array( |
|
237 | + 'EVT_ID' => $wpdb_row['Event_CPT.ID'], |
|
238 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
239 | + ), |
|
240 | + ), |
|
241 | + 'REG_ID', |
|
242 | + true |
|
243 | + ); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Counts all the registrations who have checked into one of this events' datetimes |
|
249 | + * See EE_Event::total_available_spaces( false ); |
|
250 | + * |
|
251 | + * @param array $wpdb_row |
|
252 | + * @param WP_REST_Request $request |
|
253 | + * @param EventControllerBase $controller |
|
254 | + * @return int|null if permission denied |
|
255 | + * @throws EE_Error |
|
256 | + * @throws InvalidArgumentException |
|
257 | + * @throws InvalidDataTypeException |
|
258 | + * @throws InvalidInterfaceException |
|
259 | + * @throws RestException |
|
260 | + */ |
|
261 | + public function registrationsCheckedInCount($wpdb_row, $request, $controller) |
|
262 | + { |
|
263 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
264 | + throw new EE_Error( |
|
265 | + sprintf( |
|
266 | + __( |
|
267 | + // @codingStandardsIgnoreStart |
|
268 | + 'Cannot calculate registrations_checked_in_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
269 | + // @codingStandardsIgnoreEnd |
|
270 | + 'event_espresso' |
|
271 | + ), |
|
272 | + print_r($wpdb_row, true) |
|
273 | + ) |
|
274 | + ); |
|
275 | + } |
|
276 | + $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_in_count'); |
|
277 | + return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], true); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Counts all the registrations who have checked out of one of this events' datetimes |
|
283 | + * See EE_Event::total_available_spaces( false ); |
|
284 | + * |
|
285 | + * @param array $wpdb_row |
|
286 | + * @param WP_REST_Request $request |
|
287 | + * @param EventControllerBase $controller |
|
288 | + * @return int |
|
289 | + * @throws EE_Error |
|
290 | + * @throws InvalidArgumentException |
|
291 | + * @throws InvalidDataTypeException |
|
292 | + * @throws InvalidInterfaceException |
|
293 | + * @throws RestException |
|
294 | + */ |
|
295 | + public function registrationsCheckedOutCount($wpdb_row, $request, $controller) |
|
296 | + { |
|
297 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
298 | + throw new EE_Error( |
|
299 | + sprintf( |
|
300 | + __( |
|
301 | + // @codingStandardsIgnoreStart |
|
302 | + 'Cannot calculate registrations_checked_out_count because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
303 | + // @codingStandardsIgnoreEnd |
|
304 | + 'event_espresso' |
|
305 | + ), |
|
306 | + print_r($wpdb_row, true) |
|
307 | + ) |
|
308 | + ); |
|
309 | + } |
|
310 | + $this->verifyCurrentUserCan('ee_read_checkins', 'registrations_checked_out_count'); |
|
311 | + return $this->registration_model->count_registrations_checked_into_event($wpdb_row['Event_CPT.ID'], false); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Gets the thumbnail image |
|
317 | + * |
|
318 | + * @param array $wpdb_row |
|
319 | + * @param WP_REST_Request $request |
|
320 | + * @param EventControllerBase $controller |
|
321 | + * @return array |
|
322 | + * @throws EE_Error |
|
323 | + */ |
|
324 | + public function imageThumbnail($wpdb_row, $request, $controller) |
|
325 | + { |
|
326 | + return self::calculateImageData($wpdb_row, 'thumbnail'); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * Gets the medium image |
|
332 | + * |
|
333 | + * @param array $wpdb_row |
|
334 | + * @param WP_REST_Request $request |
|
335 | + * @param EventControllerBase $controller |
|
336 | + * @return array |
|
337 | + * @throws EE_Error |
|
338 | + */ |
|
339 | + public function imageMedium($wpdb_row, $request, $controller) |
|
340 | + { |
|
341 | + return self::calculateImageData($wpdb_row, 'medium'); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + /** |
|
346 | + * Gets the medium-large image |
|
347 | + * |
|
348 | + * @param array $wpdb_row |
|
349 | + * @param WP_REST_Request $request |
|
350 | + * @param EventControllerBase $controller |
|
351 | + * @return array |
|
352 | + * @throws EE_Error |
|
353 | + */ |
|
354 | + public function imageMediumLarge($wpdb_row, $request, $controller) |
|
355 | + { |
|
356 | + return self::calculateImageData($wpdb_row, 'medium_large'); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Gets the large image |
|
362 | + * |
|
363 | + * @param array $wpdb_row |
|
364 | + * @param WP_REST_Request $request |
|
365 | + * @param EventControllerBase $controller |
|
366 | + * @return array |
|
367 | + * @throws EE_Error |
|
368 | + */ |
|
369 | + public function imageLarge($wpdb_row, $request, $controller) |
|
370 | + { |
|
371 | + return self::calculateImageData($wpdb_row, 'large'); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Gets the post-thumbnail image |
|
377 | + * |
|
378 | + * @param array $wpdb_row |
|
379 | + * @param WP_REST_Request $request |
|
380 | + * @param EventControllerBase $controller |
|
381 | + * @return array |
|
382 | + * @throws EE_Error |
|
383 | + */ |
|
384 | + public function imagePostThumbnail($wpdb_row, $request, $controller) |
|
385 | + { |
|
386 | + return self::calculateImageData($wpdb_row, 'post-thumbnail'); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Gets the full size image |
|
392 | + * |
|
393 | + * @param array $wpdb_row |
|
394 | + * @param WP_REST_Request $request |
|
395 | + * @param EventControllerBase $controller |
|
396 | + * @return array |
|
397 | + * @throws EE_Error |
|
398 | + */ |
|
399 | + public function imageFull($wpdb_row, $request, $controller) |
|
400 | + { |
|
401 | + return self::calculateImageData($wpdb_row, 'full'); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Gets image specs and formats them for the display in the API, |
|
407 | + * according to the image size requested |
|
408 | + * |
|
409 | + * @param array $wpdb_row |
|
410 | + * @param string $image_size one of these: thumbnail, medium, medium_large, large, post-thumbnail, full |
|
411 | + * @return array|false if no such image exists. If array it will have keys 'url', 'width', 'height' and 'original' |
|
412 | + * @throws EE_Error |
|
413 | + */ |
|
414 | + protected function calculateImageData($wpdb_row, $image_size) |
|
415 | + { |
|
416 | + if (! Event::wpdbRowHasEventId($wpdb_row)) { |
|
417 | + throw new EE_Error( |
|
418 | + sprintf( |
|
419 | + __( |
|
420 | + // @codingStandardsIgnoreStart |
|
421 | + 'Cannot calculate image because the database row %1$s does not have an entry for "Event_CPT.ID"', |
|
422 | + // @codingStandardsIgnoreEnd |
|
423 | + 'event_espresso' |
|
424 | + ), |
|
425 | + print_r($wpdb_row, true) |
|
426 | + ) |
|
427 | + ); |
|
428 | + } |
|
429 | + $EVT_ID = $wpdb_row['Event_CPT.ID']; |
|
430 | + $attachment_id = get_post_thumbnail_id($EVT_ID); |
|
431 | + $data = wp_get_attachment_image_src($attachment_id, $image_size); |
|
432 | + if (! $data) { |
|
433 | + return null; |
|
434 | + } |
|
435 | + $generated = true; |
|
436 | + if (isset($data[3])) { |
|
437 | + $generated = $data[3]; |
|
438 | + } |
|
439 | + return array( |
|
440 | + 'url' => $data[0], |
|
441 | + 'width' => $data[1], |
|
442 | + 'height' => $data[2], |
|
443 | + 'generated' => $generated, |
|
444 | + ); |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * Returns true if the array of data contains 'Event_CPT.ID'. False otherwise |
|
450 | + * |
|
451 | + * @param array $wpdb_row |
|
452 | + * @return bool |
|
453 | + */ |
|
454 | + protected function wpdbRowHasEventId($wpdb_row) |
|
455 | + { |
|
456 | + return (is_array($wpdb_row) && isset($wpdb_row['Event_CPT.ID']) && absint($wpdb_row['Event_CPT.ID'])); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * Provides an array for all the calculations possible that outlines a json schema for those calculations. |
|
462 | + * Array is indexed by calculation (snake case) and value is the schema for that calculation. |
|
463 | + * |
|
464 | + * @since 4.9.68.p |
|
465 | + * @return array |
|
466 | + */ |
|
467 | + public function schemaForCalculations() |
|
468 | + { |
|
469 | + $image_object_properties = array( |
|
470 | + 'url' => array( |
|
471 | + 'type' => 'string', |
|
472 | + ), |
|
473 | + 'width' => array( |
|
474 | + 'type' => 'number', |
|
475 | + ), |
|
476 | + 'height' => array( |
|
477 | + 'type' => 'number', |
|
478 | + ), |
|
479 | + 'generated' => array( |
|
480 | + 'type' => 'boolean', |
|
481 | + ), |
|
482 | + ); |
|
483 | + return array( |
|
484 | + 'optimum_sales_at_start' => array( |
|
485 | + 'description' => esc_html__( |
|
486 | + 'The total spaces on the event (not subtracting sales, but taking sales into account; so this is the optimum sales that CAN still be achieved.', |
|
487 | + 'event_espresso' |
|
488 | + ), |
|
489 | + 'type' => 'number', |
|
490 | + 'protected' => true, |
|
491 | + ), |
|
492 | + 'optimum_sales_now' => array( |
|
493 | + 'description' => esc_html__( |
|
494 | + 'The total spaces on the event (ignoring all sales; so this is the optimum sales that could have been achieved.', |
|
495 | + 'event_espresso' |
|
496 | + ), |
|
497 | + 'type' => 'number', |
|
498 | + 'protected' => true, |
|
499 | + ), |
|
500 | + 'spaces_remaining' => array( |
|
501 | + 'description' => esc_html__( |
|
502 | + 'The optimum_sales_number result, minus total sales so far.', |
|
503 | + 'event_espresso' |
|
504 | + ), |
|
505 | + 'type' => 'number', |
|
506 | + 'protected' => true, |
|
507 | + ), |
|
508 | + 'spots_taken' => array( |
|
509 | + 'description' => esc_html__( |
|
510 | + 'The number of approved registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)', |
|
511 | + 'event_espresso' |
|
512 | + ), |
|
513 | + 'type' => 'number', |
|
514 | + 'protected' => true, |
|
515 | + ), |
|
516 | + 'spots_taken_pending_payment' => array( |
|
517 | + 'description' => esc_html__( |
|
518 | + 'The number of pending-payment registrations for this event (regardless of how many datetimes each registration\'s ticket purchase is for)', |
|
519 | + 'event_espresso' |
|
520 | + ), |
|
521 | + 'type' => 'number', |
|
522 | + 'protected' => true, |
|
523 | + ), |
|
524 | + 'registrations_checked_in_count' => array( |
|
525 | + 'description' => esc_html__( |
|
526 | + 'The count of all the registrations who have checked into one of this event\'s datetimes.', |
|
527 | + 'event_espresso' |
|
528 | + ), |
|
529 | + 'type' => 'number', |
|
530 | + 'protected' => true, |
|
531 | + ), |
|
532 | + 'registrations_checked_out_count' => array( |
|
533 | + 'description' => esc_html__( |
|
534 | + 'The count of all registrations who have checked out of one of this event\'s datetimes.', |
|
535 | + 'event_espresso' |
|
536 | + ), |
|
537 | + 'type' => 'number', |
|
538 | + 'protected' => true, |
|
539 | + ), |
|
540 | + 'image_thumbnail' => array( |
|
541 | + 'description' => esc_html__( |
|
542 | + 'The thumbnail image data.', |
|
543 | + 'event_espresso' |
|
544 | + ), |
|
545 | + 'type' => 'object', |
|
546 | + 'properties' => $image_object_properties, |
|
547 | + 'additionalProperties' => false, |
|
548 | + ), |
|
549 | + 'image_medium' => array( |
|
550 | + 'description' => esc_html__( |
|
551 | + 'The medium image data.', |
|
552 | + 'event_espresso' |
|
553 | + ), |
|
554 | + 'type' => 'object', |
|
555 | + 'properties' => $image_object_properties, |
|
556 | + 'additionalProperties' => false, |
|
557 | + ), |
|
558 | + 'image_medium_large' => array( |
|
559 | + 'description' => esc_html__( |
|
560 | + 'The medium-large image data.', |
|
561 | + 'event_espresso' |
|
562 | + ), |
|
563 | + 'type' => 'object', |
|
564 | + 'properties' => $image_object_properties, |
|
565 | + 'additionalProperties' => false, |
|
566 | + ), |
|
567 | + 'image_large' => array( |
|
568 | + 'description' => esc_html__( |
|
569 | + 'The large image data.', |
|
570 | + 'event_espresso' |
|
571 | + ), |
|
572 | + 'type' => 'object', |
|
573 | + 'properties' => $image_object_properties, |
|
574 | + 'additionalProperties' => false, |
|
575 | + ), |
|
576 | + 'image_post_thumbnail' => array( |
|
577 | + 'description' => esc_html__( |
|
578 | + 'The post-thumbnail image data.', |
|
579 | + 'event_espresso' |
|
580 | + ), |
|
581 | + 'type' => 'object', |
|
582 | + 'properties' => $image_object_properties, |
|
583 | + 'additionalProperties' => false, |
|
584 | + ), |
|
585 | + 'image_full' => array( |
|
586 | + 'description' => esc_html__( |
|
587 | + 'The full size image data', |
|
588 | + 'event_espresso' |
|
589 | + ), |
|
590 | + 'type' => 'object', |
|
591 | + 'properties' => $image_object_properties, |
|
592 | + 'additionalProperties' => false, |
|
593 | + ), |
|
594 | + ); |
|
595 | + } |
|
596 | 596 | } |
@@ -28,704 +28,704 @@ |
||
28 | 28 | */ |
29 | 29 | class RestIncomingQueryParamMetadata |
30 | 30 | { |
31 | - private $query_param_key; |
|
32 | - private $query_param_value; |
|
33 | - /** |
|
34 | - * @var RestIncomingQueryParamContext |
|
35 | - */ |
|
36 | - private $context; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var EE_Model_Field_Base|null |
|
40 | - */ |
|
41 | - private $field; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string same as $query_param_key but has the * and anything after it removed |
|
45 | - */ |
|
46 | - private $query_param_key_sans_stars; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string for timezone or timezone offset |
|
50 | - */ |
|
51 | - private $timezone; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var boolean if the field in $query_param_key is for a GMT field (eg `EVT_modified_gmt`) |
|
55 | - */ |
|
56 | - private $is_gmt_field = false; |
|
57 | - |
|
58 | - /** |
|
59 | - * RestIncomingQueryParamMetadata constructor. |
|
60 | - * You probably want to call |
|
61 | - * @param string $query_param_key |
|
62 | - * @param string $query_param_value |
|
63 | - * @param RestIncomingQueryParamContext $context |
|
64 | - */ |
|
65 | - public function __construct($query_param_key, $query_param_value, RestIncomingQueryParamContext $context) |
|
66 | - { |
|
67 | - $this->query_param_key = $query_param_key; |
|
68 | - $this->query_param_value = $query_param_value; |
|
69 | - $this->context = $context; |
|
70 | - $this->determineFieldAndTimezone(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Gets the query parameter key. This may have been modified (see setQueryParamValue()) |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - public function getQueryParamKey() |
|
78 | - { |
|
79 | - return $this->query_param_key; |
|
80 | - } |
|
81 | - |
|
82 | - /** |
|
83 | - * Modifies the query parameter key passed in (Eg this is done when rewriting the simplified specified operator REST |
|
84 | - * query parameters into the legacy structure) |
|
85 | - * @param string|array|int|float $query_param_value |
|
86 | - */ |
|
87 | - private function setQueryParamValue($query_param_value) |
|
88 | - { |
|
89 | - $this->query_param_value = $query_param_value; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Gets the original query parameter value passed in. |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - public function getQueryParamValue() |
|
97 | - { |
|
98 | - return $this->query_param_value; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Gets the context object. |
|
103 | - * @return RestIncomingQueryParamContext |
|
104 | - */ |
|
105 | - public function getContext() |
|
106 | - { |
|
107 | - return $this->context; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Sets the query parameter key. This may be used to rewrite a key into its non-GMT alternative. |
|
112 | - * @param string $query_param_key |
|
113 | - */ |
|
114 | - private function setQueryParamKey($query_param_key) |
|
115 | - { |
|
116 | - $this->query_param_key = $query_param_key; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Gets the field the query parameter key indicated. This may be null (in cases where the query parameter key |
|
121 | - * did not indicate a field, eg if it were `OR`). |
|
122 | - * @return EE_Model_Field_Base|null |
|
123 | - */ |
|
124 | - public function getField() |
|
125 | - { |
|
126 | - return $this->field; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Gets the query parameter key (with the star and everything afterwards removed). |
|
131 | - * @return string |
|
132 | - */ |
|
133 | - public function getQueryParamKeySansStars() |
|
134 | - { |
|
135 | - return $this->query_param_key_sans_stars; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Gets the timezone associated with this model (the site timezone, except for GMT datetime fields). |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function getTimezone() |
|
143 | - { |
|
144 | - return $this->timezone; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Returns whether or not this is a GMT field |
|
149 | - * @return boolean |
|
150 | - */ |
|
151 | - public function isGmtField() |
|
152 | - { |
|
153 | - return $this->is_gmt_field; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Sets the field indicated by the query parameter key (might be null). |
|
158 | - * @param EE_Model_Field_Base|null $field |
|
159 | - */ |
|
160 | - private function setField(EE_Model_Field_Base $field = null) |
|
161 | - { |
|
162 | - $this->field = $field; |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Sets the query parameter key-with-stars-removed. |
|
167 | - * @param string $query_param_key_sans_stars |
|
168 | - */ |
|
169 | - private function setQueryParamKeySansStars($query_param_key_sans_stars) |
|
170 | - { |
|
171 | - $this->query_param_key_sans_stars = $query_param_key_sans_stars; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Sets the timezone (this could be a timezeon offset string). |
|
176 | - * @param string $timezone |
|
177 | - */ |
|
178 | - private function setTimezone($timezone) |
|
179 | - { |
|
180 | - $this->timezone = $timezone; |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @param mixed $is_gmt_field |
|
185 | - */ |
|
186 | - private function setIsGmtField($is_gmt_field) |
|
187 | - { |
|
188 | - $this->is_gmt_field = $is_gmt_field; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Determines what field, query param name, and query param name without stars, and timezone to use. |
|
193 | - * @since 4.9.72.p |
|
194 | - * @type EE_Model_Field_Base $field |
|
195 | - * @return void { |
|
196 | - * @throws EE_Error |
|
197 | - * @throws InvalidDataTypeException |
|
198 | - * @throws InvalidInterfaceException |
|
199 | - * @throws InvalidArgumentException |
|
200 | - */ |
|
201 | - private function determineFieldAndTimezone() |
|
202 | - { |
|
203 | - $this->setQueryParamKeySansStars(ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
|
204 | - $this->getQueryParamKey() |
|
205 | - )); |
|
206 | - $this->setField(ModelDataTranslator::deduceFieldFromQueryParam( |
|
207 | - $this->getQueryParamKeySansStars(), |
|
208 | - $this->getContext()->getModel() |
|
209 | - )); |
|
210 | - // double-check is it a *_gmt field? |
|
211 | - if (!$this->getField() instanceof EE_Model_Field_Base |
|
212 | - && ModelDataTranslator::isGmtDateFieldName($this->getQueryParamKeySansStars()) |
|
213 | - ) { |
|
214 | - // yep, take off '_gmt', and find the field |
|
215 | - $this->setQueryParamKey(ModelDataTranslator::removeGmtFromFieldName($this->getQueryParamKeySansStars())); |
|
216 | - $this->setField(ModelDataTranslator::deduceFieldFromQueryParam( |
|
217 | - $this->getQueryParamKey(), |
|
218 | - $this->context->getModel() |
|
219 | - )); |
|
220 | - $this->setTimezone('UTC'); |
|
221 | - $this->setIsGmtField(true); |
|
222 | - } elseif ($this->getField() instanceof EE_Datetime_Field) { |
|
223 | - // so it's not a GMT field. Set the timezone on the model to the default |
|
224 | - $this->setTimezone(EEH_DTT_Helper::get_valid_timezone_string()); |
|
225 | - } else { |
|
226 | - // just keep using what's already set for the timezone |
|
227 | - $this->setTimezone($this->context->getModel()->get_timezone()); |
|
228 | - } |
|
229 | - $this->assertOnlyAdminCanReadPasswordFields(); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * Throws an exception if a non-admin is trying to query by password. |
|
234 | - * @since $VID:$ |
|
235 | - * @throws RestException |
|
236 | - */ |
|
237 | - private function assertOnlyAdminCanReadPasswordFields() |
|
238 | - { |
|
239 | - if ($this->getField() instanceof EE_Password_Field |
|
240 | - && ! current_user_can(EE_Restriction_Generator_Base::get_default_restrictions_cap())) { |
|
241 | - // only full admins can query by password. sorry bub! |
|
242 | - throw new RestException( |
|
243 | - 'only_admins_can_query_by_password', |
|
244 | - // @codingStandardsIgnoreStart |
|
245 | - esc_html__('You attempted to filter by a password field without the needed privileges. Only a full admin is allowed to do that.', 'event_espresso'), |
|
246 | - // @codingStandardsIgnoreEnd |
|
247 | - array( |
|
248 | - 'status' => 403 |
|
249 | - ) |
|
250 | - ); |
|
251 | - } |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Given a ton of input, determines the value to use for the models. |
|
256 | - * @since 4.9.72.p |
|
257 | - * @return array|null |
|
258 | - * @throws DomainException |
|
259 | - * @throws EE_Error |
|
260 | - * @throws RestException |
|
261 | - * @throws DomainException |
|
262 | - */ |
|
263 | - public function determineConditionsQueryParameterValue() |
|
264 | - { |
|
265 | - if ($this->valueIsArrayDuringRead()) { |
|
266 | - return $this->determineModelValueGivenRestInputArray(); |
|
267 | - } |
|
268 | - return ModelDataTranslator::prepareFieldValueFromJson( |
|
269 | - $this->getField(), |
|
270 | - $this->getQueryParamValue(), |
|
271 | - $this->getContext()->getRequestedVersion(), |
|
272 | - $this->getTimezone() |
|
273 | - ); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * Given that the array value provided was itself an array, handles finding the correct value to pass to the model. |
|
278 | - * @since 4.9.72.p |
|
279 | - * @return array|null |
|
280 | - * @throws RestException |
|
281 | - */ |
|
282 | - private function determineModelValueGivenRestInputArray() |
|
283 | - { |
|
284 | - $this->transformSimplifiedSpecifiedOperatorSyntaxIntoStandardSyntax(); |
|
285 | - // did they specify an operator? |
|
286 | - if ($this->valueIsLegacySpecifiedOperator()) { |
|
287 | - $query_param_value = $this->getQueryParamValue(); |
|
288 | - $sub_array_key = $query_param_value[0]; |
|
289 | - $translated_value = array($sub_array_key); |
|
290 | - if ($this->operatorIsNAry($sub_array_key)) { |
|
291 | - $translated_value[] = $this->prepareValuesFromJson($query_param_value[1]); |
|
292 | - } elseif ($this->operatorIsTernary($sub_array_key)) { |
|
293 | - $translated_value[] = array( |
|
294 | - $this->prepareValuesFromJson($query_param_value[1][0]), |
|
295 | - $this->prepareValuesFromJson($query_param_value[1][1]) |
|
296 | - ); |
|
297 | - } elseif ($this->operatorIsLike($sub_array_key)) { |
|
298 | - // we want to leave this value mostly-as-is (eg don't force it to be a float |
|
299 | - // or a boolean or an enum value. Leave it as-is with wildcards etc) |
|
300 | - // but do verify it at least doesn't have any serialized data |
|
301 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]); |
|
302 | - $translated_value[] = $query_param_value[1]; |
|
303 | - } elseif ($this->operatorIsUnary($sub_array_key)) { |
|
304 | - // no arguments should have been provided, so don't look for any |
|
305 | - } elseif ($this->operatorisBinary($sub_array_key)) { |
|
306 | - // it's a valid operator, but none of the exceptions. Treat it normally. |
|
307 | - $translated_value[] = $this->prepareValuesFromJson($query_param_value[1]); |
|
308 | - } else { |
|
309 | - // so they provided a valid operator, but wrong number of arguments |
|
310 | - $this->throwWrongNumberOfArgsExceptionIfDebugging($sub_array_key); |
|
311 | - $translated_value = null; |
|
312 | - } |
|
313 | - } else { |
|
314 | - // so they didn't provide a valid operator |
|
315 | - // if we aren't in debug mode, then just try our best to fulfill the user's request |
|
316 | - $this->throwInvalidOperatorExceptionIfDebugging(); |
|
317 | - $translated_value = null; |
|
318 | - } |
|
319 | - return $translated_value; |
|
320 | - } |
|
321 | - |
|
322 | - /** |
|
323 | - * Returns if this request is a "read" request and the value provided was an array. |
|
324 | - * This will indicate is such things as `array('<', 123)` and `array('IN', array(1,2,3))` are acceptable or not. |
|
325 | - * @since 4.9.72.p |
|
326 | - * @return boolean |
|
327 | - */ |
|
328 | - private function valueIsArrayDuringRead() |
|
329 | - { |
|
330 | - return !$this->getContext()->isWriting() && is_array($this->getQueryParamValue()); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Returns if the value provided was an associative array (we should have already verified it's an array of some |
|
335 | - * sort). If the value is an associative array, it had better be in the simplified specified operator structure. |
|
336 | - * @since 4.9.72.p |
|
337 | - * @return boolean |
|
338 | - */ |
|
339 | - private function valueIsAssociativeArray() |
|
340 | - { |
|
341 | - return !EEH_Array::is_array_numerically_and_sequentially_indexed($this->getQueryParamValue()); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Checks if the array value is itself an array that fits into the simplified specified operator structure |
|
346 | - * (eg `array('!=' => 123)`). |
|
347 | - * @since 4.9.72.p |
|
348 | - * @return boolean |
|
349 | - */ |
|
350 | - private function valueIsSimplifiedSpecifiedOperator() |
|
351 | - { |
|
352 | - return count($this->getQueryParamValue()) === 1 |
|
353 | - && array_key_exists( |
|
354 | - key($this->getQueryParamValue()), |
|
355 | - $this->getContext()->getModel()->valid_operators() |
|
356 | - ); |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Throws an exception if the sub-value is an array (eg `array('!=' => array())`). It needs to just be a string, |
|
361 | - * of either comma-separated-values, or a JSON array. |
|
362 | - * @since 4.9.72.p |
|
363 | - * @param $sub_array_key |
|
364 | - * @param $sub_array_value |
|
365 | - * @throws RestException |
|
366 | - */ |
|
367 | - private function assertSubValueIsntArray($sub_array_key, $sub_array_value) |
|
368 | - { |
|
369 | - if (is_array($sub_array_value) && EED_Core_Rest_Api::debugMode()) { |
|
370 | - throw new RestException( |
|
371 | - 'csv_or_json_string_only', |
|
372 | - sprintf( |
|
373 | - /* translators: 1: variable name*/ |
|
374 | - esc_html__( |
|
375 | - 'The value provided for the operator "%1$s" should be comma-separated value string or a JSON array.', |
|
376 | - 'event_espresso' |
|
377 | - ), |
|
378 | - $sub_array_key |
|
379 | - ), |
|
380 | - array( |
|
381 | - 'status' => 400, |
|
382 | - ) |
|
383 | - ); |
|
384 | - } |
|
385 | - } |
|
386 | - |
|
387 | - /** |
|
388 | - * Determines if the sub-array key is an operator taking 3 or more operators. |
|
389 | - * @since 4.9.72.p |
|
390 | - * @param $sub_array_key |
|
391 | - * @return boolean |
|
392 | - */ |
|
393 | - private function subArrayKeyIsNonBinaryOperator($sub_array_key) |
|
394 | - { |
|
395 | - return array_key_exists( |
|
396 | - $sub_array_key, |
|
397 | - array_merge( |
|
398 | - $this->getContext()->getModel()->valid_in_style_operators(), |
|
399 | - $this->getContext()->getModel()->valid_between_style_operators() |
|
400 | - ) |
|
401 | - ); |
|
402 | - } |
|
403 | - |
|
404 | - /** |
|
405 | - * Given that the $sub_array_key is a string, checks if it's an operator taking only 1 argument. |
|
406 | - * @since 4.9.72.p |
|
407 | - * @param string $sub_array_key |
|
408 | - * @return boolean |
|
409 | - */ |
|
410 | - private function subArrayKeyIsUnaryOperator($sub_array_key) |
|
411 | - { |
|
412 | - return array_key_exists( |
|
413 | - $sub_array_key, |
|
414 | - $this->getContext()->getModel()->valid_null_style_operators() |
|
415 | - ); |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Parses the $sub_array_value string into an array (given it could either be a comma-separated-list or a JSON |
|
420 | - * array). eg `"1,2,3"` or `"[1,2,3]"` into `array(1,2,3)`. |
|
421 | - * @since 4.9.72.p |
|
422 | - * @param $sub_array_value |
|
423 | - * @return array|mixed|object |
|
424 | - */ |
|
425 | - private function extractQuickStyleSpecifiedOperatorValue($sub_array_value) |
|
426 | - { |
|
427 | - // the value should be JSON or CSV |
|
428 | - $values = json_decode($sub_array_value); |
|
429 | - if (!is_array($values)) { |
|
430 | - $values = array_filter( |
|
431 | - array_map( |
|
432 | - 'trim', |
|
433 | - explode( |
|
434 | - ',', |
|
435 | - $sub_array_value |
|
436 | - ) |
|
437 | - ) |
|
438 | - ); |
|
439 | - } |
|
440 | - return $values; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Throws an exception if the value isn't a simplified specified operator (only called when we expect that). |
|
445 | - * @since 4.9.72.p |
|
446 | - * @throws RestException |
|
447 | - */ |
|
448 | - private function assertSimplifiedSpecifiedOperator() |
|
449 | - { |
|
450 | - if (!$this->valueIsSimplifiedSpecifiedOperator() && EED_Core_Rest_Api::debugMode()) { |
|
451 | - throw new RestException( |
|
452 | - 'numerically_indexed_array_of_values_only', |
|
453 | - sprintf( |
|
454 | - /* translators: 1: variable name*/ |
|
455 | - esc_html__( |
|
456 | - 'The array provided for the parameter "%1$s" should be numerically indexed.', |
|
457 | - 'event_espresso' |
|
458 | - ), |
|
459 | - $this->getQueryParamKey() |
|
460 | - ), |
|
461 | - array( |
|
462 | - 'status' => 400, |
|
463 | - ) |
|
464 | - ); |
|
465 | - } |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * If query_param_value were in the simplified specific operator structure, change it into the legacy structure. |
|
470 | - * @since 4.9.72.p |
|
471 | - * @throws RestException |
|
472 | - */ |
|
473 | - private function transformSimplifiedSpecifiedOperatorSyntaxIntoStandardSyntax() |
|
474 | - { |
|
475 | - if ($this->valueIsAssociativeArray()) { |
|
476 | - $this->assertSimplifiedSpecifiedOperator(); |
|
477 | - $query_param_value = $this->getQueryParamValue(); |
|
478 | - $sub_array_value = reset($query_param_value); |
|
479 | - $sub_array_key = key($query_param_value); |
|
480 | - $this->assertSubValueIsntArray($sub_array_key, $sub_array_value); |
|
481 | - // they're doing something like "&where[EVT_ID][IN]=1,2,3" or "&where[EVT_ID][>]=5" |
|
482 | - if ($this->subArrayKeyIsNonBinaryOperator($sub_array_key)) { |
|
483 | - $this->setQueryParamValue(array( |
|
484 | - $sub_array_key, |
|
485 | - $this->extractQuickStyleSpecifiedOperatorValue($sub_array_value) |
|
486 | - )); |
|
487 | - } elseif ($this->subArrayKeyIsUnaryOperator($sub_array_key)) { |
|
488 | - $this->setQueryParamValue(array($sub_array_key)); |
|
489 | - } else { |
|
490 | - $this->setQueryParamValue(array($sub_array_key, $sub_array_value)); |
|
491 | - } |
|
492 | - } |
|
493 | - } |
|
494 | - |
|
495 | - /** |
|
496 | - * Returns true is the value is an array using the legacy structure to specify the operator. Eg `array('!=',123)`. |
|
497 | - * @since 4.9.72.p |
|
498 | - * @return boolean |
|
499 | - */ |
|
500 | - private function valueIsLegacySpecifiedOperator() |
|
501 | - { |
|
502 | - $valid_operators = $this->getContext()->getModel()->valid_operators(); |
|
503 | - $query_param_value = $this->getQueryParamValue(); |
|
504 | - return isset($query_param_value[0]) |
|
505 | - && isset($valid_operators[ $query_param_value[0] ]); |
|
506 | - } |
|
507 | - |
|
508 | - /** |
|
509 | - * Returns true if the value specified operator accepts arbitrary number of arguments, like "IN". |
|
510 | - * @since 4.9.72.p |
|
511 | - * @param $operator |
|
512 | - * @return boolean |
|
513 | - */ |
|
514 | - private function operatorIsNAry($operator) |
|
515 | - { |
|
516 | - $valueArray = $this->getQueryParamValue(); |
|
517 | - return array_key_exists( |
|
518 | - $operator, |
|
519 | - $this->getContext()->getModel()->valid_in_style_operators() |
|
520 | - ) |
|
521 | - && isset($valueArray[1]) |
|
522 | - && is_array($valueArray[1]) |
|
523 | - && !isset($valueArray[2]); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Returns true if the operator accepts 3 arguments (eg "BETWEEN"). |
|
528 | - * So we're looking for a value that looks like |
|
529 | - * `array('BETWEEN', array('2015-01-01T00:00:00', '2016-01-01T00:00:00'))`. |
|
530 | - * @since 4.9.72.p |
|
531 | - * @param $operator |
|
532 | - * @return boolean |
|
533 | - */ |
|
534 | - private function operatorIsTernary($operator) |
|
535 | - { |
|
536 | - $query_param_value = $this->getQueryParamValue(); |
|
537 | - return array_key_exists($operator, $this->getContext()->getModel()->valid_between_style_operators()) |
|
538 | - && isset($query_param_value[1]) |
|
539 | - && is_array($query_param_value[1]) |
|
540 | - && isset($query_param_value[1][0], $query_param_value[1][1]) |
|
541 | - && !isset($query_param_value[1][2]) |
|
542 | - && !isset($query_param_value[2]); |
|
543 | - } |
|
544 | - |
|
545 | - /** |
|
546 | - * Returns true if the operator is a similar to LIKE, indicating the value may have wildcards we should leave alone. |
|
547 | - * @since 4.9.72.p |
|
548 | - * @param $operator |
|
549 | - * @return boolean |
|
550 | - */ |
|
551 | - private function operatorIsLike($operator) |
|
552 | - { |
|
553 | - $query_param_value = $this->getQueryParamValue(); |
|
554 | - return array_key_exists($operator, $this->getContext()->getModel()->valid_like_style_operators()) |
|
555 | - && isset($query_param_value[1]) |
|
556 | - && !isset($query_param_value[2]); |
|
557 | - } |
|
558 | - |
|
559 | - /** |
|
560 | - * Returns true if the operator only takes one argument (eg it's like `IS NULL`). |
|
561 | - * @since 4.9.72.p |
|
562 | - * @param $operator |
|
563 | - * @return boolean |
|
564 | - */ |
|
565 | - private function operatorIsUnary($operator) |
|
566 | - { |
|
567 | - $query_param_value = $this->getQueryParamValue(); |
|
568 | - return array_key_exists($operator, $this->getContext()->getModel()->valid_null_style_operators()) |
|
569 | - && !isset($query_param_value[1]); |
|
570 | - } |
|
571 | - |
|
572 | - /** |
|
573 | - * Returns true if the operator specified is a binary opeator (eg `=`, `!=`) |
|
574 | - * @since 4.9.72.p |
|
575 | - * @param $operator |
|
576 | - * @return boolean |
|
577 | - */ |
|
578 | - private function operatorisBinary($operator) |
|
579 | - { |
|
580 | - $query_param_value = $this->getQueryParamValue(); |
|
581 | - $model = $this->getContext()->getModel(); |
|
582 | - return isset($query_param_value[1]) |
|
583 | - && !isset($query_param_value[2]) |
|
584 | - && !array_key_exists( |
|
585 | - $operator, |
|
586 | - array_merge( |
|
587 | - $model->valid_in_style_operators(), |
|
588 | - $model->valid_null_style_operators(), |
|
589 | - $model->valid_like_style_operators(), |
|
590 | - $model->valid_between_style_operators() |
|
591 | - ) |
|
592 | - ); |
|
593 | - } |
|
594 | - |
|
595 | - /** |
|
596 | - * If we're debugging, throws an exception saying that the wrong number of arguments was provided. |
|
597 | - * @since 4.9.72.p |
|
598 | - * @param $operator |
|
599 | - * @throws RestException |
|
600 | - */ |
|
601 | - private function throwWrongNumberOfArgsExceptionIfDebugging($operator) |
|
602 | - { |
|
603 | - if (EED_Core_Rest_Api::debugMode()) { |
|
604 | - throw new RestException( |
|
605 | - 'wrong_number_of_arguments', |
|
606 | - sprintf( |
|
607 | - esc_html__( |
|
608 | - 'The operator you provided, "%1$s" had the wrong number of arguments', |
|
609 | - 'event_espresso' |
|
610 | - ), |
|
611 | - $operator |
|
612 | - ), |
|
613 | - array( |
|
614 | - 'status' => 400, |
|
615 | - ) |
|
616 | - ); |
|
617 | - } |
|
618 | - } |
|
619 | - |
|
620 | - /** |
|
621 | - * Wrapper for ModelDataTranslator::prepareFieldValuesFromJson(), just a tad more DRY. |
|
622 | - * @since 4.9.72.p |
|
623 | - * @param $value |
|
624 | - * @return mixed |
|
625 | - * @throws RestException |
|
626 | - */ |
|
627 | - private function prepareValuesFromJson($value) |
|
628 | - { |
|
629 | - return ModelDataTranslator::prepareFieldValuesFromJson( |
|
630 | - $this->getField(), |
|
631 | - $value, |
|
632 | - $this->getContext()->getRequestedVersion(), |
|
633 | - $this->getTimezone() |
|
634 | - ); |
|
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * Throws an exception if an invalid operator was specified and we're debugging. |
|
639 | - * @since 4.9.72.p |
|
640 | - * @throws RestException |
|
641 | - */ |
|
642 | - private function throwInvalidOperatorExceptionIfDebugging() |
|
643 | - { |
|
644 | - // so they didn't provide a valid operator |
|
645 | - if (EED_Core_Rest_Api::debugMode()) { |
|
646 | - throw new RestException( |
|
647 | - 'invalid_operator', |
|
648 | - sprintf( |
|
649 | - esc_html__( |
|
650 | - 'You provided an invalid parameter, with key "%1$s" and value "%2$s"', |
|
651 | - 'event_espresso' |
|
652 | - ), |
|
653 | - $this->getQueryParamKey(), |
|
654 | - $this->getQueryParamValue() |
|
655 | - ), |
|
656 | - array( |
|
657 | - 'status' => 400, |
|
658 | - ) |
|
659 | - ); |
|
660 | - } |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * Returns true if the query_param_key was a logic query parameter, eg `OR`, `AND`, `NOT`, `OR*`, etc. |
|
665 | - * @since 4.9.72.p |
|
666 | - * @return boolean |
|
667 | - */ |
|
668 | - private function isLogicQueryParam() |
|
669 | - { |
|
670 | - return in_array($this->getQueryParamKeySansStars(), $this->getContext()->getModel()->logic_query_param_keys()); |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - /** |
|
675 | - * If the query param isn't for a field, it must be a nested query parameter which requires different logic. |
|
676 | - * @since 4.9.72.p |
|
677 | - * @return array |
|
678 | - * @throws DomainException |
|
679 | - * @throws EE_Error |
|
680 | - * @throws RestException |
|
681 | - * @throws InvalidDataTypeException |
|
682 | - * @throws InvalidInterfaceException |
|
683 | - * @throws InvalidArgumentException |
|
684 | - */ |
|
685 | - public function determineNestedConditionQueryParameters() |
|
686 | - { |
|
687 | - |
|
688 | - // so this param doesn't correspond to a field eh? |
|
689 | - if ($this->getContext()->isWriting()) { |
|
690 | - // always tell API clients about invalid parameters when they're creating data. Otherwise, |
|
691 | - // they are probably going to create invalid data |
|
692 | - throw new RestException( |
|
693 | - 'invalid_field', |
|
694 | - sprintf( |
|
695 | - /* translators: 1: variable name */ |
|
696 | - esc_html__('You have provided an invalid parameter: "%1$s"', 'event_espresso'), |
|
697 | - $this->getQueryParamKey() |
|
698 | - ) |
|
699 | - ); |
|
700 | - } |
|
701 | - // so it's not for a field, is it a logic query param key? |
|
702 | - if ($this->isLogicQueryParam()) { |
|
703 | - return ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
704 | - $this->getQueryParamValue(), |
|
705 | - $this->getContext()->getModel(), |
|
706 | - $this->getContext()->getRequestedVersion() |
|
707 | - ); |
|
708 | - } |
|
709 | - if (EED_Core_Rest_Api::debugMode()) { |
|
710 | - // only tell API clients they got it wrong if we're in debug mode |
|
711 | - // otherwise try our best ot fulfill their request by ignoring this invalid data |
|
712 | - throw new RestException( |
|
713 | - 'invalid_parameter', |
|
714 | - sprintf( |
|
715 | - /* translators: 1: variable name */ |
|
716 | - esc_html__( |
|
717 | - 'You provided an invalid parameter, with key "%1$s"', |
|
718 | - 'event_espresso' |
|
719 | - ), |
|
720 | - $this->getQueryParamKey() |
|
721 | - ), |
|
722 | - array( |
|
723 | - 'status' => 400, |
|
724 | - ) |
|
725 | - ); |
|
726 | - } |
|
727 | - return null; |
|
728 | - } |
|
31 | + private $query_param_key; |
|
32 | + private $query_param_value; |
|
33 | + /** |
|
34 | + * @var RestIncomingQueryParamContext |
|
35 | + */ |
|
36 | + private $context; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var EE_Model_Field_Base|null |
|
40 | + */ |
|
41 | + private $field; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string same as $query_param_key but has the * and anything after it removed |
|
45 | + */ |
|
46 | + private $query_param_key_sans_stars; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string for timezone or timezone offset |
|
50 | + */ |
|
51 | + private $timezone; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var boolean if the field in $query_param_key is for a GMT field (eg `EVT_modified_gmt`) |
|
55 | + */ |
|
56 | + private $is_gmt_field = false; |
|
57 | + |
|
58 | + /** |
|
59 | + * RestIncomingQueryParamMetadata constructor. |
|
60 | + * You probably want to call |
|
61 | + * @param string $query_param_key |
|
62 | + * @param string $query_param_value |
|
63 | + * @param RestIncomingQueryParamContext $context |
|
64 | + */ |
|
65 | + public function __construct($query_param_key, $query_param_value, RestIncomingQueryParamContext $context) |
|
66 | + { |
|
67 | + $this->query_param_key = $query_param_key; |
|
68 | + $this->query_param_value = $query_param_value; |
|
69 | + $this->context = $context; |
|
70 | + $this->determineFieldAndTimezone(); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Gets the query parameter key. This may have been modified (see setQueryParamValue()) |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + public function getQueryParamKey() |
|
78 | + { |
|
79 | + return $this->query_param_key; |
|
80 | + } |
|
81 | + |
|
82 | + /** |
|
83 | + * Modifies the query parameter key passed in (Eg this is done when rewriting the simplified specified operator REST |
|
84 | + * query parameters into the legacy structure) |
|
85 | + * @param string|array|int|float $query_param_value |
|
86 | + */ |
|
87 | + private function setQueryParamValue($query_param_value) |
|
88 | + { |
|
89 | + $this->query_param_value = $query_param_value; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Gets the original query parameter value passed in. |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + public function getQueryParamValue() |
|
97 | + { |
|
98 | + return $this->query_param_value; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Gets the context object. |
|
103 | + * @return RestIncomingQueryParamContext |
|
104 | + */ |
|
105 | + public function getContext() |
|
106 | + { |
|
107 | + return $this->context; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Sets the query parameter key. This may be used to rewrite a key into its non-GMT alternative. |
|
112 | + * @param string $query_param_key |
|
113 | + */ |
|
114 | + private function setQueryParamKey($query_param_key) |
|
115 | + { |
|
116 | + $this->query_param_key = $query_param_key; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Gets the field the query parameter key indicated. This may be null (in cases where the query parameter key |
|
121 | + * did not indicate a field, eg if it were `OR`). |
|
122 | + * @return EE_Model_Field_Base|null |
|
123 | + */ |
|
124 | + public function getField() |
|
125 | + { |
|
126 | + return $this->field; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Gets the query parameter key (with the star and everything afterwards removed). |
|
131 | + * @return string |
|
132 | + */ |
|
133 | + public function getQueryParamKeySansStars() |
|
134 | + { |
|
135 | + return $this->query_param_key_sans_stars; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Gets the timezone associated with this model (the site timezone, except for GMT datetime fields). |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function getTimezone() |
|
143 | + { |
|
144 | + return $this->timezone; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Returns whether or not this is a GMT field |
|
149 | + * @return boolean |
|
150 | + */ |
|
151 | + public function isGmtField() |
|
152 | + { |
|
153 | + return $this->is_gmt_field; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Sets the field indicated by the query parameter key (might be null). |
|
158 | + * @param EE_Model_Field_Base|null $field |
|
159 | + */ |
|
160 | + private function setField(EE_Model_Field_Base $field = null) |
|
161 | + { |
|
162 | + $this->field = $field; |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Sets the query parameter key-with-stars-removed. |
|
167 | + * @param string $query_param_key_sans_stars |
|
168 | + */ |
|
169 | + private function setQueryParamKeySansStars($query_param_key_sans_stars) |
|
170 | + { |
|
171 | + $this->query_param_key_sans_stars = $query_param_key_sans_stars; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Sets the timezone (this could be a timezeon offset string). |
|
176 | + * @param string $timezone |
|
177 | + */ |
|
178 | + private function setTimezone($timezone) |
|
179 | + { |
|
180 | + $this->timezone = $timezone; |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @param mixed $is_gmt_field |
|
185 | + */ |
|
186 | + private function setIsGmtField($is_gmt_field) |
|
187 | + { |
|
188 | + $this->is_gmt_field = $is_gmt_field; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Determines what field, query param name, and query param name without stars, and timezone to use. |
|
193 | + * @since 4.9.72.p |
|
194 | + * @type EE_Model_Field_Base $field |
|
195 | + * @return void { |
|
196 | + * @throws EE_Error |
|
197 | + * @throws InvalidDataTypeException |
|
198 | + * @throws InvalidInterfaceException |
|
199 | + * @throws InvalidArgumentException |
|
200 | + */ |
|
201 | + private function determineFieldAndTimezone() |
|
202 | + { |
|
203 | + $this->setQueryParamKeySansStars(ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
|
204 | + $this->getQueryParamKey() |
|
205 | + )); |
|
206 | + $this->setField(ModelDataTranslator::deduceFieldFromQueryParam( |
|
207 | + $this->getQueryParamKeySansStars(), |
|
208 | + $this->getContext()->getModel() |
|
209 | + )); |
|
210 | + // double-check is it a *_gmt field? |
|
211 | + if (!$this->getField() instanceof EE_Model_Field_Base |
|
212 | + && ModelDataTranslator::isGmtDateFieldName($this->getQueryParamKeySansStars()) |
|
213 | + ) { |
|
214 | + // yep, take off '_gmt', and find the field |
|
215 | + $this->setQueryParamKey(ModelDataTranslator::removeGmtFromFieldName($this->getQueryParamKeySansStars())); |
|
216 | + $this->setField(ModelDataTranslator::deduceFieldFromQueryParam( |
|
217 | + $this->getQueryParamKey(), |
|
218 | + $this->context->getModel() |
|
219 | + )); |
|
220 | + $this->setTimezone('UTC'); |
|
221 | + $this->setIsGmtField(true); |
|
222 | + } elseif ($this->getField() instanceof EE_Datetime_Field) { |
|
223 | + // so it's not a GMT field. Set the timezone on the model to the default |
|
224 | + $this->setTimezone(EEH_DTT_Helper::get_valid_timezone_string()); |
|
225 | + } else { |
|
226 | + // just keep using what's already set for the timezone |
|
227 | + $this->setTimezone($this->context->getModel()->get_timezone()); |
|
228 | + } |
|
229 | + $this->assertOnlyAdminCanReadPasswordFields(); |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * Throws an exception if a non-admin is trying to query by password. |
|
234 | + * @since $VID:$ |
|
235 | + * @throws RestException |
|
236 | + */ |
|
237 | + private function assertOnlyAdminCanReadPasswordFields() |
|
238 | + { |
|
239 | + if ($this->getField() instanceof EE_Password_Field |
|
240 | + && ! current_user_can(EE_Restriction_Generator_Base::get_default_restrictions_cap())) { |
|
241 | + // only full admins can query by password. sorry bub! |
|
242 | + throw new RestException( |
|
243 | + 'only_admins_can_query_by_password', |
|
244 | + // @codingStandardsIgnoreStart |
|
245 | + esc_html__('You attempted to filter by a password field without the needed privileges. Only a full admin is allowed to do that.', 'event_espresso'), |
|
246 | + // @codingStandardsIgnoreEnd |
|
247 | + array( |
|
248 | + 'status' => 403 |
|
249 | + ) |
|
250 | + ); |
|
251 | + } |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Given a ton of input, determines the value to use for the models. |
|
256 | + * @since 4.9.72.p |
|
257 | + * @return array|null |
|
258 | + * @throws DomainException |
|
259 | + * @throws EE_Error |
|
260 | + * @throws RestException |
|
261 | + * @throws DomainException |
|
262 | + */ |
|
263 | + public function determineConditionsQueryParameterValue() |
|
264 | + { |
|
265 | + if ($this->valueIsArrayDuringRead()) { |
|
266 | + return $this->determineModelValueGivenRestInputArray(); |
|
267 | + } |
|
268 | + return ModelDataTranslator::prepareFieldValueFromJson( |
|
269 | + $this->getField(), |
|
270 | + $this->getQueryParamValue(), |
|
271 | + $this->getContext()->getRequestedVersion(), |
|
272 | + $this->getTimezone() |
|
273 | + ); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * Given that the array value provided was itself an array, handles finding the correct value to pass to the model. |
|
278 | + * @since 4.9.72.p |
|
279 | + * @return array|null |
|
280 | + * @throws RestException |
|
281 | + */ |
|
282 | + private function determineModelValueGivenRestInputArray() |
|
283 | + { |
|
284 | + $this->transformSimplifiedSpecifiedOperatorSyntaxIntoStandardSyntax(); |
|
285 | + // did they specify an operator? |
|
286 | + if ($this->valueIsLegacySpecifiedOperator()) { |
|
287 | + $query_param_value = $this->getQueryParamValue(); |
|
288 | + $sub_array_key = $query_param_value[0]; |
|
289 | + $translated_value = array($sub_array_key); |
|
290 | + if ($this->operatorIsNAry($sub_array_key)) { |
|
291 | + $translated_value[] = $this->prepareValuesFromJson($query_param_value[1]); |
|
292 | + } elseif ($this->operatorIsTernary($sub_array_key)) { |
|
293 | + $translated_value[] = array( |
|
294 | + $this->prepareValuesFromJson($query_param_value[1][0]), |
|
295 | + $this->prepareValuesFromJson($query_param_value[1][1]) |
|
296 | + ); |
|
297 | + } elseif ($this->operatorIsLike($sub_array_key)) { |
|
298 | + // we want to leave this value mostly-as-is (eg don't force it to be a float |
|
299 | + // or a boolean or an enum value. Leave it as-is with wildcards etc) |
|
300 | + // but do verify it at least doesn't have any serialized data |
|
301 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]); |
|
302 | + $translated_value[] = $query_param_value[1]; |
|
303 | + } elseif ($this->operatorIsUnary($sub_array_key)) { |
|
304 | + // no arguments should have been provided, so don't look for any |
|
305 | + } elseif ($this->operatorisBinary($sub_array_key)) { |
|
306 | + // it's a valid operator, but none of the exceptions. Treat it normally. |
|
307 | + $translated_value[] = $this->prepareValuesFromJson($query_param_value[1]); |
|
308 | + } else { |
|
309 | + // so they provided a valid operator, but wrong number of arguments |
|
310 | + $this->throwWrongNumberOfArgsExceptionIfDebugging($sub_array_key); |
|
311 | + $translated_value = null; |
|
312 | + } |
|
313 | + } else { |
|
314 | + // so they didn't provide a valid operator |
|
315 | + // if we aren't in debug mode, then just try our best to fulfill the user's request |
|
316 | + $this->throwInvalidOperatorExceptionIfDebugging(); |
|
317 | + $translated_value = null; |
|
318 | + } |
|
319 | + return $translated_value; |
|
320 | + } |
|
321 | + |
|
322 | + /** |
|
323 | + * Returns if this request is a "read" request and the value provided was an array. |
|
324 | + * This will indicate is such things as `array('<', 123)` and `array('IN', array(1,2,3))` are acceptable or not. |
|
325 | + * @since 4.9.72.p |
|
326 | + * @return boolean |
|
327 | + */ |
|
328 | + private function valueIsArrayDuringRead() |
|
329 | + { |
|
330 | + return !$this->getContext()->isWriting() && is_array($this->getQueryParamValue()); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Returns if the value provided was an associative array (we should have already verified it's an array of some |
|
335 | + * sort). If the value is an associative array, it had better be in the simplified specified operator structure. |
|
336 | + * @since 4.9.72.p |
|
337 | + * @return boolean |
|
338 | + */ |
|
339 | + private function valueIsAssociativeArray() |
|
340 | + { |
|
341 | + return !EEH_Array::is_array_numerically_and_sequentially_indexed($this->getQueryParamValue()); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Checks if the array value is itself an array that fits into the simplified specified operator structure |
|
346 | + * (eg `array('!=' => 123)`). |
|
347 | + * @since 4.9.72.p |
|
348 | + * @return boolean |
|
349 | + */ |
|
350 | + private function valueIsSimplifiedSpecifiedOperator() |
|
351 | + { |
|
352 | + return count($this->getQueryParamValue()) === 1 |
|
353 | + && array_key_exists( |
|
354 | + key($this->getQueryParamValue()), |
|
355 | + $this->getContext()->getModel()->valid_operators() |
|
356 | + ); |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Throws an exception if the sub-value is an array (eg `array('!=' => array())`). It needs to just be a string, |
|
361 | + * of either comma-separated-values, or a JSON array. |
|
362 | + * @since 4.9.72.p |
|
363 | + * @param $sub_array_key |
|
364 | + * @param $sub_array_value |
|
365 | + * @throws RestException |
|
366 | + */ |
|
367 | + private function assertSubValueIsntArray($sub_array_key, $sub_array_value) |
|
368 | + { |
|
369 | + if (is_array($sub_array_value) && EED_Core_Rest_Api::debugMode()) { |
|
370 | + throw new RestException( |
|
371 | + 'csv_or_json_string_only', |
|
372 | + sprintf( |
|
373 | + /* translators: 1: variable name*/ |
|
374 | + esc_html__( |
|
375 | + 'The value provided for the operator "%1$s" should be comma-separated value string or a JSON array.', |
|
376 | + 'event_espresso' |
|
377 | + ), |
|
378 | + $sub_array_key |
|
379 | + ), |
|
380 | + array( |
|
381 | + 'status' => 400, |
|
382 | + ) |
|
383 | + ); |
|
384 | + } |
|
385 | + } |
|
386 | + |
|
387 | + /** |
|
388 | + * Determines if the sub-array key is an operator taking 3 or more operators. |
|
389 | + * @since 4.9.72.p |
|
390 | + * @param $sub_array_key |
|
391 | + * @return boolean |
|
392 | + */ |
|
393 | + private function subArrayKeyIsNonBinaryOperator($sub_array_key) |
|
394 | + { |
|
395 | + return array_key_exists( |
|
396 | + $sub_array_key, |
|
397 | + array_merge( |
|
398 | + $this->getContext()->getModel()->valid_in_style_operators(), |
|
399 | + $this->getContext()->getModel()->valid_between_style_operators() |
|
400 | + ) |
|
401 | + ); |
|
402 | + } |
|
403 | + |
|
404 | + /** |
|
405 | + * Given that the $sub_array_key is a string, checks if it's an operator taking only 1 argument. |
|
406 | + * @since 4.9.72.p |
|
407 | + * @param string $sub_array_key |
|
408 | + * @return boolean |
|
409 | + */ |
|
410 | + private function subArrayKeyIsUnaryOperator($sub_array_key) |
|
411 | + { |
|
412 | + return array_key_exists( |
|
413 | + $sub_array_key, |
|
414 | + $this->getContext()->getModel()->valid_null_style_operators() |
|
415 | + ); |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Parses the $sub_array_value string into an array (given it could either be a comma-separated-list or a JSON |
|
420 | + * array). eg `"1,2,3"` or `"[1,2,3]"` into `array(1,2,3)`. |
|
421 | + * @since 4.9.72.p |
|
422 | + * @param $sub_array_value |
|
423 | + * @return array|mixed|object |
|
424 | + */ |
|
425 | + private function extractQuickStyleSpecifiedOperatorValue($sub_array_value) |
|
426 | + { |
|
427 | + // the value should be JSON or CSV |
|
428 | + $values = json_decode($sub_array_value); |
|
429 | + if (!is_array($values)) { |
|
430 | + $values = array_filter( |
|
431 | + array_map( |
|
432 | + 'trim', |
|
433 | + explode( |
|
434 | + ',', |
|
435 | + $sub_array_value |
|
436 | + ) |
|
437 | + ) |
|
438 | + ); |
|
439 | + } |
|
440 | + return $values; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Throws an exception if the value isn't a simplified specified operator (only called when we expect that). |
|
445 | + * @since 4.9.72.p |
|
446 | + * @throws RestException |
|
447 | + */ |
|
448 | + private function assertSimplifiedSpecifiedOperator() |
|
449 | + { |
|
450 | + if (!$this->valueIsSimplifiedSpecifiedOperator() && EED_Core_Rest_Api::debugMode()) { |
|
451 | + throw new RestException( |
|
452 | + 'numerically_indexed_array_of_values_only', |
|
453 | + sprintf( |
|
454 | + /* translators: 1: variable name*/ |
|
455 | + esc_html__( |
|
456 | + 'The array provided for the parameter "%1$s" should be numerically indexed.', |
|
457 | + 'event_espresso' |
|
458 | + ), |
|
459 | + $this->getQueryParamKey() |
|
460 | + ), |
|
461 | + array( |
|
462 | + 'status' => 400, |
|
463 | + ) |
|
464 | + ); |
|
465 | + } |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * If query_param_value were in the simplified specific operator structure, change it into the legacy structure. |
|
470 | + * @since 4.9.72.p |
|
471 | + * @throws RestException |
|
472 | + */ |
|
473 | + private function transformSimplifiedSpecifiedOperatorSyntaxIntoStandardSyntax() |
|
474 | + { |
|
475 | + if ($this->valueIsAssociativeArray()) { |
|
476 | + $this->assertSimplifiedSpecifiedOperator(); |
|
477 | + $query_param_value = $this->getQueryParamValue(); |
|
478 | + $sub_array_value = reset($query_param_value); |
|
479 | + $sub_array_key = key($query_param_value); |
|
480 | + $this->assertSubValueIsntArray($sub_array_key, $sub_array_value); |
|
481 | + // they're doing something like "&where[EVT_ID][IN]=1,2,3" or "&where[EVT_ID][>]=5" |
|
482 | + if ($this->subArrayKeyIsNonBinaryOperator($sub_array_key)) { |
|
483 | + $this->setQueryParamValue(array( |
|
484 | + $sub_array_key, |
|
485 | + $this->extractQuickStyleSpecifiedOperatorValue($sub_array_value) |
|
486 | + )); |
|
487 | + } elseif ($this->subArrayKeyIsUnaryOperator($sub_array_key)) { |
|
488 | + $this->setQueryParamValue(array($sub_array_key)); |
|
489 | + } else { |
|
490 | + $this->setQueryParamValue(array($sub_array_key, $sub_array_value)); |
|
491 | + } |
|
492 | + } |
|
493 | + } |
|
494 | + |
|
495 | + /** |
|
496 | + * Returns true is the value is an array using the legacy structure to specify the operator. Eg `array('!=',123)`. |
|
497 | + * @since 4.9.72.p |
|
498 | + * @return boolean |
|
499 | + */ |
|
500 | + private function valueIsLegacySpecifiedOperator() |
|
501 | + { |
|
502 | + $valid_operators = $this->getContext()->getModel()->valid_operators(); |
|
503 | + $query_param_value = $this->getQueryParamValue(); |
|
504 | + return isset($query_param_value[0]) |
|
505 | + && isset($valid_operators[ $query_param_value[0] ]); |
|
506 | + } |
|
507 | + |
|
508 | + /** |
|
509 | + * Returns true if the value specified operator accepts arbitrary number of arguments, like "IN". |
|
510 | + * @since 4.9.72.p |
|
511 | + * @param $operator |
|
512 | + * @return boolean |
|
513 | + */ |
|
514 | + private function operatorIsNAry($operator) |
|
515 | + { |
|
516 | + $valueArray = $this->getQueryParamValue(); |
|
517 | + return array_key_exists( |
|
518 | + $operator, |
|
519 | + $this->getContext()->getModel()->valid_in_style_operators() |
|
520 | + ) |
|
521 | + && isset($valueArray[1]) |
|
522 | + && is_array($valueArray[1]) |
|
523 | + && !isset($valueArray[2]); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Returns true if the operator accepts 3 arguments (eg "BETWEEN"). |
|
528 | + * So we're looking for a value that looks like |
|
529 | + * `array('BETWEEN', array('2015-01-01T00:00:00', '2016-01-01T00:00:00'))`. |
|
530 | + * @since 4.9.72.p |
|
531 | + * @param $operator |
|
532 | + * @return boolean |
|
533 | + */ |
|
534 | + private function operatorIsTernary($operator) |
|
535 | + { |
|
536 | + $query_param_value = $this->getQueryParamValue(); |
|
537 | + return array_key_exists($operator, $this->getContext()->getModel()->valid_between_style_operators()) |
|
538 | + && isset($query_param_value[1]) |
|
539 | + && is_array($query_param_value[1]) |
|
540 | + && isset($query_param_value[1][0], $query_param_value[1][1]) |
|
541 | + && !isset($query_param_value[1][2]) |
|
542 | + && !isset($query_param_value[2]); |
|
543 | + } |
|
544 | + |
|
545 | + /** |
|
546 | + * Returns true if the operator is a similar to LIKE, indicating the value may have wildcards we should leave alone. |
|
547 | + * @since 4.9.72.p |
|
548 | + * @param $operator |
|
549 | + * @return boolean |
|
550 | + */ |
|
551 | + private function operatorIsLike($operator) |
|
552 | + { |
|
553 | + $query_param_value = $this->getQueryParamValue(); |
|
554 | + return array_key_exists($operator, $this->getContext()->getModel()->valid_like_style_operators()) |
|
555 | + && isset($query_param_value[1]) |
|
556 | + && !isset($query_param_value[2]); |
|
557 | + } |
|
558 | + |
|
559 | + /** |
|
560 | + * Returns true if the operator only takes one argument (eg it's like `IS NULL`). |
|
561 | + * @since 4.9.72.p |
|
562 | + * @param $operator |
|
563 | + * @return boolean |
|
564 | + */ |
|
565 | + private function operatorIsUnary($operator) |
|
566 | + { |
|
567 | + $query_param_value = $this->getQueryParamValue(); |
|
568 | + return array_key_exists($operator, $this->getContext()->getModel()->valid_null_style_operators()) |
|
569 | + && !isset($query_param_value[1]); |
|
570 | + } |
|
571 | + |
|
572 | + /** |
|
573 | + * Returns true if the operator specified is a binary opeator (eg `=`, `!=`) |
|
574 | + * @since 4.9.72.p |
|
575 | + * @param $operator |
|
576 | + * @return boolean |
|
577 | + */ |
|
578 | + private function operatorisBinary($operator) |
|
579 | + { |
|
580 | + $query_param_value = $this->getQueryParamValue(); |
|
581 | + $model = $this->getContext()->getModel(); |
|
582 | + return isset($query_param_value[1]) |
|
583 | + && !isset($query_param_value[2]) |
|
584 | + && !array_key_exists( |
|
585 | + $operator, |
|
586 | + array_merge( |
|
587 | + $model->valid_in_style_operators(), |
|
588 | + $model->valid_null_style_operators(), |
|
589 | + $model->valid_like_style_operators(), |
|
590 | + $model->valid_between_style_operators() |
|
591 | + ) |
|
592 | + ); |
|
593 | + } |
|
594 | + |
|
595 | + /** |
|
596 | + * If we're debugging, throws an exception saying that the wrong number of arguments was provided. |
|
597 | + * @since 4.9.72.p |
|
598 | + * @param $operator |
|
599 | + * @throws RestException |
|
600 | + */ |
|
601 | + private function throwWrongNumberOfArgsExceptionIfDebugging($operator) |
|
602 | + { |
|
603 | + if (EED_Core_Rest_Api::debugMode()) { |
|
604 | + throw new RestException( |
|
605 | + 'wrong_number_of_arguments', |
|
606 | + sprintf( |
|
607 | + esc_html__( |
|
608 | + 'The operator you provided, "%1$s" had the wrong number of arguments', |
|
609 | + 'event_espresso' |
|
610 | + ), |
|
611 | + $operator |
|
612 | + ), |
|
613 | + array( |
|
614 | + 'status' => 400, |
|
615 | + ) |
|
616 | + ); |
|
617 | + } |
|
618 | + } |
|
619 | + |
|
620 | + /** |
|
621 | + * Wrapper for ModelDataTranslator::prepareFieldValuesFromJson(), just a tad more DRY. |
|
622 | + * @since 4.9.72.p |
|
623 | + * @param $value |
|
624 | + * @return mixed |
|
625 | + * @throws RestException |
|
626 | + */ |
|
627 | + private function prepareValuesFromJson($value) |
|
628 | + { |
|
629 | + return ModelDataTranslator::prepareFieldValuesFromJson( |
|
630 | + $this->getField(), |
|
631 | + $value, |
|
632 | + $this->getContext()->getRequestedVersion(), |
|
633 | + $this->getTimezone() |
|
634 | + ); |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * Throws an exception if an invalid operator was specified and we're debugging. |
|
639 | + * @since 4.9.72.p |
|
640 | + * @throws RestException |
|
641 | + */ |
|
642 | + private function throwInvalidOperatorExceptionIfDebugging() |
|
643 | + { |
|
644 | + // so they didn't provide a valid operator |
|
645 | + if (EED_Core_Rest_Api::debugMode()) { |
|
646 | + throw new RestException( |
|
647 | + 'invalid_operator', |
|
648 | + sprintf( |
|
649 | + esc_html__( |
|
650 | + 'You provided an invalid parameter, with key "%1$s" and value "%2$s"', |
|
651 | + 'event_espresso' |
|
652 | + ), |
|
653 | + $this->getQueryParamKey(), |
|
654 | + $this->getQueryParamValue() |
|
655 | + ), |
|
656 | + array( |
|
657 | + 'status' => 400, |
|
658 | + ) |
|
659 | + ); |
|
660 | + } |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * Returns true if the query_param_key was a logic query parameter, eg `OR`, `AND`, `NOT`, `OR*`, etc. |
|
665 | + * @since 4.9.72.p |
|
666 | + * @return boolean |
|
667 | + */ |
|
668 | + private function isLogicQueryParam() |
|
669 | + { |
|
670 | + return in_array($this->getQueryParamKeySansStars(), $this->getContext()->getModel()->logic_query_param_keys()); |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + /** |
|
675 | + * If the query param isn't for a field, it must be a nested query parameter which requires different logic. |
|
676 | + * @since 4.9.72.p |
|
677 | + * @return array |
|
678 | + * @throws DomainException |
|
679 | + * @throws EE_Error |
|
680 | + * @throws RestException |
|
681 | + * @throws InvalidDataTypeException |
|
682 | + * @throws InvalidInterfaceException |
|
683 | + * @throws InvalidArgumentException |
|
684 | + */ |
|
685 | + public function determineNestedConditionQueryParameters() |
|
686 | + { |
|
687 | + |
|
688 | + // so this param doesn't correspond to a field eh? |
|
689 | + if ($this->getContext()->isWriting()) { |
|
690 | + // always tell API clients about invalid parameters when they're creating data. Otherwise, |
|
691 | + // they are probably going to create invalid data |
|
692 | + throw new RestException( |
|
693 | + 'invalid_field', |
|
694 | + sprintf( |
|
695 | + /* translators: 1: variable name */ |
|
696 | + esc_html__('You have provided an invalid parameter: "%1$s"', 'event_espresso'), |
|
697 | + $this->getQueryParamKey() |
|
698 | + ) |
|
699 | + ); |
|
700 | + } |
|
701 | + // so it's not for a field, is it a logic query param key? |
|
702 | + if ($this->isLogicQueryParam()) { |
|
703 | + return ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
704 | + $this->getQueryParamValue(), |
|
705 | + $this->getContext()->getModel(), |
|
706 | + $this->getContext()->getRequestedVersion() |
|
707 | + ); |
|
708 | + } |
|
709 | + if (EED_Core_Rest_Api::debugMode()) { |
|
710 | + // only tell API clients they got it wrong if we're in debug mode |
|
711 | + // otherwise try our best ot fulfill their request by ignoring this invalid data |
|
712 | + throw new RestException( |
|
713 | + 'invalid_parameter', |
|
714 | + sprintf( |
|
715 | + /* translators: 1: variable name */ |
|
716 | + esc_html__( |
|
717 | + 'You provided an invalid parameter, with key "%1$s"', |
|
718 | + 'event_espresso' |
|
719 | + ), |
|
720 | + $this->getQueryParamKey() |
|
721 | + ), |
|
722 | + array( |
|
723 | + 'status' => 400, |
|
724 | + ) |
|
725 | + ); |
|
726 | + } |
|
727 | + return null; |
|
728 | + } |
|
729 | 729 | } |
730 | 730 | // End of file RestQueryParamMetadata.php |
731 | 731 | // Location: EventEspresso\core\libraries\rest_api/RestQueryParamMetadata.php |
@@ -31,338 +31,338 @@ |
||
31 | 31 | { |
32 | 32 | |
33 | 33 | |
34 | - public function __construct() |
|
35 | - { |
|
36 | - parent::__construct(); |
|
37 | - EE_Registry::instance()->load_helper('Inflector'); |
|
38 | - } |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + parent::__construct(); |
|
37 | + EE_Registry::instance()->load_helper('Inflector'); |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
43 | - * |
|
44 | - * @param WP_REST_Request $request |
|
45 | - * @param string $version |
|
46 | - * @param string $model_name |
|
47 | - * @return WP_REST_Response|\WP_Error |
|
48 | - */ |
|
49 | - public static function handleRequestInsert(WP_REST_Request $request, $version, $model_name) |
|
50 | - { |
|
51 | - $controller = new Write(); |
|
52 | - try { |
|
53 | - $controller->setRequestedVersion($version); |
|
54 | - return $controller->sendResponse( |
|
55 | - $controller->insert( |
|
56 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
57 | - $request |
|
58 | - ) |
|
59 | - ); |
|
60 | - } catch (\Exception $e) { |
|
61 | - return $controller->sendResponse($e); |
|
62 | - } |
|
63 | - } |
|
41 | + /** |
|
42 | + * Handles requests to get all (or a filtered subset) of entities for a particular model |
|
43 | + * |
|
44 | + * @param WP_REST_Request $request |
|
45 | + * @param string $version |
|
46 | + * @param string $model_name |
|
47 | + * @return WP_REST_Response|\WP_Error |
|
48 | + */ |
|
49 | + public static function handleRequestInsert(WP_REST_Request $request, $version, $model_name) |
|
50 | + { |
|
51 | + $controller = new Write(); |
|
52 | + try { |
|
53 | + $controller->setRequestedVersion($version); |
|
54 | + return $controller->sendResponse( |
|
55 | + $controller->insert( |
|
56 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
57 | + $request |
|
58 | + ) |
|
59 | + ); |
|
60 | + } catch (\Exception $e) { |
|
61 | + return $controller->sendResponse($e); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * Handles a request from \WP_REST_Server to update an EE model |
|
68 | - * |
|
69 | - * @param WP_REST_Request $request |
|
70 | - * @param string $version |
|
71 | - * @param string $model_name |
|
72 | - * @return WP_REST_Response|\WP_Error |
|
73 | - */ |
|
74 | - public static function handleRequestUpdate(WP_REST_Request $request, $version, $model_name) |
|
75 | - { |
|
76 | - $controller = new Write(); |
|
77 | - try { |
|
78 | - $controller->setRequestedVersion($version); |
|
79 | - return $controller->sendResponse( |
|
80 | - $controller->update( |
|
81 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
82 | - $request |
|
83 | - ) |
|
84 | - ); |
|
85 | - } catch (\Exception $e) { |
|
86 | - return $controller->sendResponse($e); |
|
87 | - } |
|
88 | - } |
|
66 | + /** |
|
67 | + * Handles a request from \WP_REST_Server to update an EE model |
|
68 | + * |
|
69 | + * @param WP_REST_Request $request |
|
70 | + * @param string $version |
|
71 | + * @param string $model_name |
|
72 | + * @return WP_REST_Response|\WP_Error |
|
73 | + */ |
|
74 | + public static function handleRequestUpdate(WP_REST_Request $request, $version, $model_name) |
|
75 | + { |
|
76 | + $controller = new Write(); |
|
77 | + try { |
|
78 | + $controller->setRequestedVersion($version); |
|
79 | + return $controller->sendResponse( |
|
80 | + $controller->update( |
|
81 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
82 | + $request |
|
83 | + ) |
|
84 | + ); |
|
85 | + } catch (\Exception $e) { |
|
86 | + return $controller->sendResponse($e); |
|
87 | + } |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | - /** |
|
92 | - * Deletes a single model object and returns it. Unless |
|
93 | - * |
|
94 | - * @param WP_REST_Request $request |
|
95 | - * @param string $version |
|
96 | - * @param string $model_name |
|
97 | - * @return WP_REST_Response|\WP_Error |
|
98 | - */ |
|
99 | - public static function handleRequestDelete(WP_REST_Request $request, $version, $model_name) |
|
100 | - { |
|
101 | - $controller = new Write(); |
|
102 | - try { |
|
103 | - $controller->setRequestedVersion($version); |
|
104 | - return $controller->sendResponse( |
|
105 | - $controller->delete( |
|
106 | - $controller->getModelVersionInfo()->loadModel($model_name), |
|
107 | - $request |
|
108 | - ) |
|
109 | - ); |
|
110 | - } catch (\Exception $e) { |
|
111 | - return $controller->sendResponse($e); |
|
112 | - } |
|
113 | - } |
|
91 | + /** |
|
92 | + * Deletes a single model object and returns it. Unless |
|
93 | + * |
|
94 | + * @param WP_REST_Request $request |
|
95 | + * @param string $version |
|
96 | + * @param string $model_name |
|
97 | + * @return WP_REST_Response|\WP_Error |
|
98 | + */ |
|
99 | + public static function handleRequestDelete(WP_REST_Request $request, $version, $model_name) |
|
100 | + { |
|
101 | + $controller = new Write(); |
|
102 | + try { |
|
103 | + $controller->setRequestedVersion($version); |
|
104 | + return $controller->sendResponse( |
|
105 | + $controller->delete( |
|
106 | + $controller->getModelVersionInfo()->loadModel($model_name), |
|
107 | + $request |
|
108 | + ) |
|
109 | + ); |
|
110 | + } catch (\Exception $e) { |
|
111 | + return $controller->sendResponse($e); |
|
112 | + } |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Inserts a new model object according to the $request |
|
118 | - * |
|
119 | - * @param EEM_Base $model |
|
120 | - * @param WP_REST_Request $request |
|
121 | - * @return array |
|
122 | - * @throws EE_Error |
|
123 | - * @throws RestException |
|
124 | - */ |
|
125 | - public function insert(EEM_Base $model, WP_REST_Request $request) |
|
126 | - { |
|
127 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
|
128 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
129 | - if (! current_user_can($default_cap_to_check_for)) { |
|
130 | - throw new RestException( |
|
131 | - 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
132 | - sprintf( |
|
133 | - esc_html__( |
|
134 | - // @codingStandardsIgnoreStart |
|
135 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.', |
|
136 | - // @codingStandardsIgnoreEnd |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - $default_cap_to_check_for |
|
140 | - ), |
|
141 | - array('status' => 403) |
|
142 | - ); |
|
143 | - } |
|
144 | - $submitted_json_data = array_merge((array) $request->get_body_params(), (array) $request->get_json_params()); |
|
145 | - $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
146 | - $submitted_json_data, |
|
147 | - $model, |
|
148 | - $this->getModelVersionInfo()->requestedVersion(), |
|
149 | - true |
|
150 | - ); |
|
151 | - $model_obj = EE_Registry::instance()->load_class( |
|
152 | - $model->get_this_model_name(), |
|
153 | - array($model_data, $model->get_timezone()), |
|
154 | - false, |
|
155 | - false |
|
156 | - ); |
|
157 | - $model_obj->save(); |
|
158 | - $new_id = $model_obj->ID(); |
|
159 | - if (! $new_id) { |
|
160 | - throw new RestException( |
|
161 | - 'rest_insertion_failed', |
|
162 | - sprintf(__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
163 | - ); |
|
164 | - } |
|
165 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
166 | - } |
|
116 | + /** |
|
117 | + * Inserts a new model object according to the $request |
|
118 | + * |
|
119 | + * @param EEM_Base $model |
|
120 | + * @param WP_REST_Request $request |
|
121 | + * @return array |
|
122 | + * @throws EE_Error |
|
123 | + * @throws RestException |
|
124 | + */ |
|
125 | + public function insert(EEM_Base $model, WP_REST_Request $request) |
|
126 | + { |
|
127 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'create'); |
|
128 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
129 | + if (! current_user_can($default_cap_to_check_for)) { |
|
130 | + throw new RestException( |
|
131 | + 'rest_cannot_create_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
132 | + sprintf( |
|
133 | + esc_html__( |
|
134 | + // @codingStandardsIgnoreStart |
|
135 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to insert data into Event Espresso.', |
|
136 | + // @codingStandardsIgnoreEnd |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + $default_cap_to_check_for |
|
140 | + ), |
|
141 | + array('status' => 403) |
|
142 | + ); |
|
143 | + } |
|
144 | + $submitted_json_data = array_merge((array) $request->get_body_params(), (array) $request->get_json_params()); |
|
145 | + $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
146 | + $submitted_json_data, |
|
147 | + $model, |
|
148 | + $this->getModelVersionInfo()->requestedVersion(), |
|
149 | + true |
|
150 | + ); |
|
151 | + $model_obj = EE_Registry::instance()->load_class( |
|
152 | + $model->get_this_model_name(), |
|
153 | + array($model_data, $model->get_timezone()), |
|
154 | + false, |
|
155 | + false |
|
156 | + ); |
|
157 | + $model_obj->save(); |
|
158 | + $new_id = $model_obj->ID(); |
|
159 | + if (! $new_id) { |
|
160 | + throw new RestException( |
|
161 | + 'rest_insertion_failed', |
|
162 | + sprintf(__('Could not insert new %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
163 | + ); |
|
164 | + } |
|
165 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
166 | + } |
|
167 | 167 | |
168 | 168 | |
169 | - /** |
|
170 | - * Updates an existing model object according to the $request |
|
171 | - * |
|
172 | - * @param EEM_Base $model |
|
173 | - * @param WP_REST_Request $request |
|
174 | - * @return array |
|
175 | - * @throws EE_Error |
|
176 | - */ |
|
177 | - public function update(EEM_Base $model, WP_REST_Request $request) |
|
178 | - { |
|
179 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
180 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
181 | - if (! current_user_can($default_cap_to_check_for)) { |
|
182 | - throw new RestException( |
|
183 | - 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
184 | - sprintf( |
|
185 | - esc_html__( |
|
186 | - // @codingStandardsIgnoreStart |
|
187 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.', |
|
188 | - // @codingStandardsIgnoreEnd |
|
189 | - 'event_espresso' |
|
190 | - ), |
|
191 | - $default_cap_to_check_for |
|
192 | - ), |
|
193 | - array('status' => 403) |
|
194 | - ); |
|
195 | - } |
|
196 | - $obj_id = $request->get_param('id'); |
|
197 | - if (! $obj_id) { |
|
198 | - throw new RestException( |
|
199 | - 'rest_edit_failed', |
|
200 | - sprintf(__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
201 | - ); |
|
202 | - } |
|
203 | - $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
204 | - $this->getBodyParams($request), |
|
205 | - $model, |
|
206 | - $this->getModelVersionInfo()->requestedVersion(), |
|
207 | - true |
|
208 | - ); |
|
209 | - $model_obj = $model->get_one_by_ID($obj_id); |
|
210 | - if (! $model_obj instanceof EE_Base_Class) { |
|
211 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
212 | - throw new RestException( |
|
213 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
214 | - sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
215 | - array('status' => 404) |
|
216 | - ); |
|
217 | - } |
|
218 | - $model_obj->save($model_data); |
|
219 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
220 | - } |
|
169 | + /** |
|
170 | + * Updates an existing model object according to the $request |
|
171 | + * |
|
172 | + * @param EEM_Base $model |
|
173 | + * @param WP_REST_Request $request |
|
174 | + * @return array |
|
175 | + * @throws EE_Error |
|
176 | + */ |
|
177 | + public function update(EEM_Base $model, WP_REST_Request $request) |
|
178 | + { |
|
179 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_edit, 'edit'); |
|
180 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
181 | + if (! current_user_can($default_cap_to_check_for)) { |
|
182 | + throw new RestException( |
|
183 | + 'rest_cannot_edit_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
184 | + sprintf( |
|
185 | + esc_html__( |
|
186 | + // @codingStandardsIgnoreStart |
|
187 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to update data into Event Espresso.', |
|
188 | + // @codingStandardsIgnoreEnd |
|
189 | + 'event_espresso' |
|
190 | + ), |
|
191 | + $default_cap_to_check_for |
|
192 | + ), |
|
193 | + array('status' => 403) |
|
194 | + ); |
|
195 | + } |
|
196 | + $obj_id = $request->get_param('id'); |
|
197 | + if (! $obj_id) { |
|
198 | + throw new RestException( |
|
199 | + 'rest_edit_failed', |
|
200 | + sprintf(__('Could not edit %1$s', 'event_espresso'), $model->get_this_model_name()) |
|
201 | + ); |
|
202 | + } |
|
203 | + $model_data = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
204 | + $this->getBodyParams($request), |
|
205 | + $model, |
|
206 | + $this->getModelVersionInfo()->requestedVersion(), |
|
207 | + true |
|
208 | + ); |
|
209 | + $model_obj = $model->get_one_by_ID($obj_id); |
|
210 | + if (! $model_obj instanceof EE_Base_Class) { |
|
211 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
212 | + throw new RestException( |
|
213 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
214 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
215 | + array('status' => 404) |
|
216 | + ); |
|
217 | + } |
|
218 | + $model_obj->save($model_data); |
|
219 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
220 | + } |
|
221 | 221 | |
222 | 222 | |
223 | - /** |
|
224 | - * Updates an existing model object according to the $request |
|
225 | - * |
|
226 | - * @param EEM_Base $model |
|
227 | - * @param WP_REST_Request $request |
|
228 | - * @return array of either the soft-deleted item, or |
|
229 | - * @throws EE_Error |
|
230 | - */ |
|
231 | - public function delete(EEM_Base $model, WP_REST_Request $request) |
|
232 | - { |
|
233 | - Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
|
234 | - $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
235 | - if (! current_user_can($default_cap_to_check_for)) { |
|
236 | - throw new RestException( |
|
237 | - 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
238 | - sprintf( |
|
239 | - esc_html__( |
|
240 | - // @codingStandardsIgnoreStart |
|
241 | - 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.', |
|
242 | - // @codingStandardsIgnoreEnd |
|
243 | - 'event_espresso' |
|
244 | - ), |
|
245 | - $default_cap_to_check_for |
|
246 | - ), |
|
247 | - array('status' => 403) |
|
248 | - ); |
|
249 | - } |
|
250 | - $obj_id = $request->get_param('id'); |
|
251 | - // this is where we would apply more fine-grained caps |
|
252 | - $model_obj = $model->get_one_by_ID($obj_id); |
|
253 | - if (! $model_obj instanceof EE_Base_Class) { |
|
254 | - $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
255 | - throw new RestException( |
|
256 | - sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
257 | - sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
258 | - array('status' => 404) |
|
259 | - ); |
|
260 | - } |
|
261 | - $requested_permanent_delete = filter_var($request->get_param('force'), FILTER_VALIDATE_BOOLEAN); |
|
262 | - $requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN); |
|
263 | - if ($requested_permanent_delete) { |
|
264 | - $previous = $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
265 | - $deleted = (bool) $model->delete_permanently_by_ID($obj_id, $requested_allow_blocking); |
|
266 | - return array( |
|
267 | - 'deleted' => $deleted, |
|
268 | - 'previous' => $previous, |
|
269 | - ); |
|
270 | - } else { |
|
271 | - if ($model instanceof EEM_Soft_Delete_Base) { |
|
272 | - $model->delete_by_ID($obj_id, $requested_allow_blocking); |
|
273 | - return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
274 | - } else { |
|
275 | - throw new RestException( |
|
276 | - 'rest_trash_not_supported', |
|
277 | - 501, |
|
278 | - sprintf( |
|
279 | - esc_html__('%1$s do not support trashing. Set force=1 to delete.', 'event_espresso'), |
|
280 | - EEH_Inflector::pluralize($model->get_this_model_name()) |
|
281 | - ) |
|
282 | - ); |
|
283 | - } |
|
284 | - } |
|
285 | - } |
|
223 | + /** |
|
224 | + * Updates an existing model object according to the $request |
|
225 | + * |
|
226 | + * @param EEM_Base $model |
|
227 | + * @param WP_REST_Request $request |
|
228 | + * @return array of either the soft-deleted item, or |
|
229 | + * @throws EE_Error |
|
230 | + */ |
|
231 | + public function delete(EEM_Base $model, WP_REST_Request $request) |
|
232 | + { |
|
233 | + Capabilities::verifyAtLeastPartialAccessTo($model, EEM_Base::caps_delete, 'delete'); |
|
234 | + $default_cap_to_check_for = EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
|
235 | + if (! current_user_can($default_cap_to_check_for)) { |
|
236 | + throw new RestException( |
|
237 | + 'rest_cannot_delete_' . EEH_Inflector::pluralize_and_lower(($model->get_this_model_name())), |
|
238 | + sprintf( |
|
239 | + esc_html__( |
|
240 | + // @codingStandardsIgnoreStart |
|
241 | + 'For now, only those with the admin capability to "%1$s" are allowed to use the REST API to delete data into Event Espresso.', |
|
242 | + // @codingStandardsIgnoreEnd |
|
243 | + 'event_espresso' |
|
244 | + ), |
|
245 | + $default_cap_to_check_for |
|
246 | + ), |
|
247 | + array('status' => 403) |
|
248 | + ); |
|
249 | + } |
|
250 | + $obj_id = $request->get_param('id'); |
|
251 | + // this is where we would apply more fine-grained caps |
|
252 | + $model_obj = $model->get_one_by_ID($obj_id); |
|
253 | + if (! $model_obj instanceof EE_Base_Class) { |
|
254 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
255 | + throw new RestException( |
|
256 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
257 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
258 | + array('status' => 404) |
|
259 | + ); |
|
260 | + } |
|
261 | + $requested_permanent_delete = filter_var($request->get_param('force'), FILTER_VALIDATE_BOOLEAN); |
|
262 | + $requested_allow_blocking = filter_var($request->get_param('allow_blocking'), FILTER_VALIDATE_BOOLEAN); |
|
263 | + if ($requested_permanent_delete) { |
|
264 | + $previous = $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
265 | + $deleted = (bool) $model->delete_permanently_by_ID($obj_id, $requested_allow_blocking); |
|
266 | + return array( |
|
267 | + 'deleted' => $deleted, |
|
268 | + 'previous' => $previous, |
|
269 | + ); |
|
270 | + } else { |
|
271 | + if ($model instanceof EEM_Soft_Delete_Base) { |
|
272 | + $model->delete_by_ID($obj_id, $requested_allow_blocking); |
|
273 | + return $this->returnModelObjAsJsonResponse($model_obj, $request); |
|
274 | + } else { |
|
275 | + throw new RestException( |
|
276 | + 'rest_trash_not_supported', |
|
277 | + 501, |
|
278 | + sprintf( |
|
279 | + esc_html__('%1$s do not support trashing. Set force=1 to delete.', 'event_espresso'), |
|
280 | + EEH_Inflector::pluralize($model->get_this_model_name()) |
|
281 | + ) |
|
282 | + ); |
|
283 | + } |
|
284 | + } |
|
285 | + } |
|
286 | 286 | |
287 | 287 | |
288 | - /** |
|
289 | - * Returns an array ready to be converted into a JSON response, based solely on the model object |
|
290 | - * |
|
291 | - * @param EE_Base_Class $model_obj |
|
292 | - * @param WP_REST_Request $request |
|
293 | - * @return array ready for a response |
|
294 | - */ |
|
295 | - protected function returnModelObjAsJsonResponse(EE_Base_Class $model_obj, WP_REST_Request $request) |
|
296 | - { |
|
297 | - $model = $model_obj->get_model(); |
|
298 | - // create an array exactly like the wpdb results row, |
|
299 | - // so we can pass it to controllers/model/Read::create_entity_from_wpdb_result() |
|
300 | - $simulated_db_row = array(); |
|
301 | - foreach ($model->field_settings(true) as $field_name => $field_obj) { |
|
302 | - // we need to reconstruct the normal wpdb results, including the db-only fields |
|
303 | - // like a secondary table's primary key. The models expect those (but don't care what value they have) |
|
304 | - if ($field_obj instanceof EE_DB_Only_Field_Base) { |
|
305 | - $raw_value = true; |
|
306 | - } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
307 | - $raw_value = $model_obj->get_DateTime_object($field_name); |
|
308 | - } else { |
|
309 | - $raw_value = $model_obj->get_raw($field_name); |
|
310 | - } |
|
311 | - $simulated_db_row[ $field_obj->get_qualified_column() ] = $field_obj->prepare_for_use_in_db($raw_value); |
|
312 | - } |
|
313 | - $read_controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read'); |
|
314 | - $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
315 | - // the simulates request really doesn't need any info downstream |
|
316 | - $simulated_request = new WP_REST_Request('GET'); |
|
317 | - // set the caps context on the simulated according to the original request. |
|
318 | - switch ($request->get_method()) { |
|
319 | - case 'POST': |
|
320 | - case 'PUT': |
|
321 | - $caps_context = EEM_Base::caps_edit; |
|
322 | - break; |
|
323 | - case 'DELETE': |
|
324 | - $caps_context = EEM_Base::caps_delete; |
|
325 | - break; |
|
326 | - default: |
|
327 | - $caps_context = EEM_Base::caps_read_admin; |
|
328 | - } |
|
329 | - $simulated_request->set_param('caps', $caps_context); |
|
330 | - return $read_controller->createEntityFromWpdbResult( |
|
331 | - $model_obj->get_model(), |
|
332 | - $simulated_db_row, |
|
333 | - $simulated_request |
|
334 | - ); |
|
335 | - } |
|
288 | + /** |
|
289 | + * Returns an array ready to be converted into a JSON response, based solely on the model object |
|
290 | + * |
|
291 | + * @param EE_Base_Class $model_obj |
|
292 | + * @param WP_REST_Request $request |
|
293 | + * @return array ready for a response |
|
294 | + */ |
|
295 | + protected function returnModelObjAsJsonResponse(EE_Base_Class $model_obj, WP_REST_Request $request) |
|
296 | + { |
|
297 | + $model = $model_obj->get_model(); |
|
298 | + // create an array exactly like the wpdb results row, |
|
299 | + // so we can pass it to controllers/model/Read::create_entity_from_wpdb_result() |
|
300 | + $simulated_db_row = array(); |
|
301 | + foreach ($model->field_settings(true) as $field_name => $field_obj) { |
|
302 | + // we need to reconstruct the normal wpdb results, including the db-only fields |
|
303 | + // like a secondary table's primary key. The models expect those (but don't care what value they have) |
|
304 | + if ($field_obj instanceof EE_DB_Only_Field_Base) { |
|
305 | + $raw_value = true; |
|
306 | + } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
307 | + $raw_value = $model_obj->get_DateTime_object($field_name); |
|
308 | + } else { |
|
309 | + $raw_value = $model_obj->get_raw($field_name); |
|
310 | + } |
|
311 | + $simulated_db_row[ $field_obj->get_qualified_column() ] = $field_obj->prepare_for_use_in_db($raw_value); |
|
312 | + } |
|
313 | + $read_controller = LoaderFactory::getLoader()->getNew('EventEspresso\core\libraries\rest_api\controllers\model\Read'); |
|
314 | + $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
315 | + // the simulates request really doesn't need any info downstream |
|
316 | + $simulated_request = new WP_REST_Request('GET'); |
|
317 | + // set the caps context on the simulated according to the original request. |
|
318 | + switch ($request->get_method()) { |
|
319 | + case 'POST': |
|
320 | + case 'PUT': |
|
321 | + $caps_context = EEM_Base::caps_edit; |
|
322 | + break; |
|
323 | + case 'DELETE': |
|
324 | + $caps_context = EEM_Base::caps_delete; |
|
325 | + break; |
|
326 | + default: |
|
327 | + $caps_context = EEM_Base::caps_read_admin; |
|
328 | + } |
|
329 | + $simulated_request->set_param('caps', $caps_context); |
|
330 | + return $read_controller->createEntityFromWpdbResult( |
|
331 | + $model_obj->get_model(), |
|
332 | + $simulated_db_row, |
|
333 | + $simulated_request |
|
334 | + ); |
|
335 | + } |
|
336 | 336 | |
337 | 337 | |
338 | - /** |
|
339 | - * Gets the item affected by this request |
|
340 | - * |
|
341 | - * @param EEM_Base $model |
|
342 | - * @param WP_REST_Request $request |
|
343 | - * @param int|string $obj_id |
|
344 | - * @return \WP_Error|array |
|
345 | - */ |
|
346 | - protected function getOneBasedOnRequest(EEM_Base $model, WP_REST_Request $request, $obj_id) |
|
347 | - { |
|
348 | - $requested_version = $this->getRequestedVersion($request->get_route()); |
|
349 | - $get_request = new WP_REST_Request( |
|
350 | - 'GET', |
|
351 | - EED_Core_Rest_Api::ee_api_namespace |
|
352 | - . $requested_version |
|
353 | - . '/' |
|
354 | - . EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
355 | - . '/' |
|
356 | - . $obj_id |
|
357 | - ); |
|
358 | - $get_request->set_url_params( |
|
359 | - array( |
|
360 | - 'id' => $obj_id, |
|
361 | - 'include' => $request->get_param('include'), |
|
362 | - ) |
|
363 | - ); |
|
364 | - $read_controller = new Read(); |
|
365 | - $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
366 | - return $read_controller->getEntityFromModel($model, $get_request); |
|
367 | - } |
|
338 | + /** |
|
339 | + * Gets the item affected by this request |
|
340 | + * |
|
341 | + * @param EEM_Base $model |
|
342 | + * @param WP_REST_Request $request |
|
343 | + * @param int|string $obj_id |
|
344 | + * @return \WP_Error|array |
|
345 | + */ |
|
346 | + protected function getOneBasedOnRequest(EEM_Base $model, WP_REST_Request $request, $obj_id) |
|
347 | + { |
|
348 | + $requested_version = $this->getRequestedVersion($request->get_route()); |
|
349 | + $get_request = new WP_REST_Request( |
|
350 | + 'GET', |
|
351 | + EED_Core_Rest_Api::ee_api_namespace |
|
352 | + . $requested_version |
|
353 | + . '/' |
|
354 | + . EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
355 | + . '/' |
|
356 | + . $obj_id |
|
357 | + ); |
|
358 | + $get_request->set_url_params( |
|
359 | + array( |
|
360 | + 'id' => $obj_id, |
|
361 | + 'include' => $request->get_param('include'), |
|
362 | + ) |
|
363 | + ); |
|
364 | + $read_controller = new Read(); |
|
365 | + $read_controller->setRequestedVersion($this->getRequestedVersion()); |
|
366 | + return $read_controller->getEntityFromModel($model, $get_request); |
|
367 | + } |
|
368 | 368 | } |
@@ -12,430 +12,430 @@ |
||
12 | 12 | class EEM_Attendee extends EEM_CPT_Base |
13 | 13 | { |
14 | 14 | |
15 | - // private instance of the Attendee object |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance of the Attendee object |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * QST_system for questions are strings not integers now, |
|
20 | - * so these constants are deprecated. |
|
21 | - * Please instead use the EEM_Attendee::system_question_* constants |
|
22 | - * |
|
23 | - * @deprecated |
|
24 | - */ |
|
25 | - const fname_question_id = 1; |
|
18 | + /** |
|
19 | + * QST_system for questions are strings not integers now, |
|
20 | + * so these constants are deprecated. |
|
21 | + * Please instead use the EEM_Attendee::system_question_* constants |
|
22 | + * |
|
23 | + * @deprecated |
|
24 | + */ |
|
25 | + const fname_question_id = 1; |
|
26 | 26 | |
27 | - /** |
|
28 | - * @deprecated |
|
29 | - */ |
|
30 | - const lname_question_id = 2; |
|
27 | + /** |
|
28 | + * @deprecated |
|
29 | + */ |
|
30 | + const lname_question_id = 2; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @deprecated |
|
35 | - */ |
|
36 | - const email_question_id = 3; |
|
33 | + /** |
|
34 | + * @deprecated |
|
35 | + */ |
|
36 | + const email_question_id = 3; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @deprecated |
|
41 | - */ |
|
42 | - const address_question_id = 4; |
|
39 | + /** |
|
40 | + * @deprecated |
|
41 | + */ |
|
42 | + const address_question_id = 4; |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @deprecated |
|
47 | - */ |
|
48 | - const address2_question_id = 5; |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * @deprecated |
|
53 | - */ |
|
54 | - const city_question_id = 6; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @deprecated |
|
59 | - */ |
|
60 | - const state_question_id = 7; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * @deprecated |
|
65 | - */ |
|
66 | - const country_question_id = 8; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @deprecated |
|
71 | - */ |
|
72 | - const zip_question_id = 9; |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @deprecated |
|
77 | - */ |
|
78 | - const phone_question_id = 10; |
|
79 | - |
|
80 | - /** |
|
81 | - * When looking for questions that correspond to attendee fields, |
|
82 | - * look for the question with this QST_system value. |
|
83 | - * These replace the old constants like EEM_Attendee::*_question_id |
|
84 | - */ |
|
85 | - const system_question_fname = 'fname'; |
|
86 | - |
|
87 | - const system_question_lname = 'lname'; |
|
88 | - |
|
89 | - const system_question_email = 'email'; |
|
90 | - |
|
91 | - const system_question_address = 'address'; |
|
92 | - |
|
93 | - const system_question_address2 = 'address2'; |
|
94 | - |
|
95 | - const system_question_city = 'city'; |
|
96 | - |
|
97 | - const system_question_state = 'state'; |
|
98 | - |
|
99 | - const system_question_country = 'country'; |
|
100 | - |
|
101 | - const system_question_zip = 'zip'; |
|
102 | - |
|
103 | - const system_question_phone = 'phone'; |
|
104 | - |
|
105 | - /** |
|
106 | - * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
107 | - * also all the values of QST_system in the questions table, and values |
|
108 | - * are their corresponding Attendee field names |
|
109 | - * |
|
110 | - * @var array |
|
111 | - */ |
|
112 | - protected $_system_question_to_attendee_field_name = array( |
|
113 | - EEM_Attendee::system_question_fname => 'ATT_fname', |
|
114 | - EEM_Attendee::system_question_lname => 'ATT_lname', |
|
115 | - EEM_Attendee::system_question_email => 'ATT_email', |
|
116 | - EEM_Attendee::system_question_address => 'ATT_address', |
|
117 | - EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
118 | - EEM_Attendee::system_question_city => 'ATT_city', |
|
119 | - EEM_Attendee::system_question_state => 'STA_ID', |
|
120 | - EEM_Attendee::system_question_country => 'CNT_ISO', |
|
121 | - EEM_Attendee::system_question_zip => 'ATT_zip', |
|
122 | - EEM_Attendee::system_question_phone => 'ATT_phone', |
|
123 | - ); |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * EEM_Attendee constructor. |
|
129 | - * |
|
130 | - * @param null $timezone |
|
131 | - * @param ModelFieldFactory $model_field_factory |
|
132 | - * @throws EE_Error |
|
133 | - * @throws InvalidArgumentException |
|
134 | - */ |
|
135 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
136 | - { |
|
137 | - $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
138 | - $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
139 | - $this->_tables = array( |
|
140 | - 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
141 | - 'Attendee_Meta' => new EE_Secondary_Table( |
|
142 | - 'esp_attendee_meta', |
|
143 | - 'ATTM_ID', |
|
144 | - 'ATT_ID' |
|
145 | - ), |
|
146 | - ); |
|
147 | - $this->_fields = array( |
|
148 | - 'Attendee_CPT' => array( |
|
149 | - 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
150 | - 'ID', |
|
151 | - esc_html__('Attendee ID', 'event_espresso') |
|
152 | - ), |
|
153 | - 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
154 | - 'post_title', |
|
155 | - esc_html__('Attendee Full Name', 'event_espresso'), |
|
156 | - false, |
|
157 | - esc_html__('Unknown', 'event_espresso') |
|
158 | - ), |
|
159 | - 'ATT_bio' => $model_field_factory->createPostContentField( |
|
160 | - 'post_content', |
|
161 | - esc_html__('Attendee Biography', 'event_espresso'), |
|
162 | - false, |
|
163 | - esc_html__('No Biography Provided', 'event_espresso') |
|
164 | - ), |
|
165 | - 'ATT_slug' => $model_field_factory->createSlugField( |
|
166 | - 'post_name', |
|
167 | - esc_html__('Attendee URL Slug', 'event_espresso') |
|
168 | - ), |
|
169 | - 'ATT_created' => $model_field_factory->createDatetimeField( |
|
170 | - 'post_date', |
|
171 | - esc_html__('Time Attendee Created', 'event_espresso') |
|
172 | - ), |
|
173 | - 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
174 | - 'post_excerpt', |
|
175 | - esc_html__('Attendee Short Biography', 'event_espresso'), |
|
176 | - true, |
|
177 | - esc_html__('No Biography Provided', 'event_espresso') |
|
178 | - ), |
|
179 | - 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
180 | - 'post_modified', |
|
181 | - esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
182 | - ), |
|
183 | - 'ATT_author' => $model_field_factory->createWpUserField( |
|
184 | - 'post_author', |
|
185 | - esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
186 | - false |
|
187 | - ), |
|
188 | - 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
189 | - 'post_parent', |
|
190 | - esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
191 | - false, |
|
192 | - 0 |
|
193 | - ), |
|
194 | - 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
195 | - 'status' => $model_field_factory->createWpPostStatusField( |
|
196 | - 'post_status', |
|
197 | - esc_html__('Attendee Status', 'event_espresso'), |
|
198 | - false, |
|
199 | - 'publish' |
|
200 | - ), |
|
201 | - 'password' => new EE_Password_Field( |
|
202 | - 'post_password', |
|
203 | - __('Password', 'event_espresso'), |
|
204 | - false, |
|
205 | - '', |
|
206 | - array( |
|
207 | - 'ATT_bio', |
|
208 | - 'ATT_short_bio', |
|
209 | - 'ATT_address', |
|
210 | - 'ATT_address2', |
|
211 | - 'ATT_city', |
|
212 | - 'STA_ID', |
|
213 | - 'CNT_ISO', |
|
214 | - 'ATT_zip', |
|
215 | - 'ATT_email', |
|
216 | - 'ATT_phone' |
|
217 | - ) |
|
218 | - ) |
|
219 | - ), |
|
220 | - 'Attendee_Meta' => array( |
|
221 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
222 | - 'ATTM_ID', |
|
223 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
224 | - false |
|
225 | - ), |
|
226 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
227 | - 'ATT_ID', |
|
228 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
229 | - false |
|
230 | - ), |
|
231 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
232 | - 'ATT_fname', |
|
233 | - esc_html__('First Name', 'event_espresso') |
|
234 | - ), |
|
235 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
236 | - 'ATT_lname', |
|
237 | - esc_html__('Last Name', 'event_espresso') |
|
238 | - ), |
|
239 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
240 | - 'ATT_address', |
|
241 | - esc_html__('Address Part 1', 'event_espresso') |
|
242 | - ), |
|
243 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
244 | - 'ATT_address2', |
|
245 | - esc_html__('Address Part 2', 'event_espresso') |
|
246 | - ), |
|
247 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
248 | - 'ATT_city', |
|
249 | - esc_html__('City', 'event_espresso') |
|
250 | - ), |
|
251 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
252 | - 'STA_ID', |
|
253 | - esc_html__('State', 'event_espresso'), |
|
254 | - true, |
|
255 | - 0, |
|
256 | - 'State' |
|
257 | - ), |
|
258 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
259 | - 'CNT_ISO', |
|
260 | - esc_html__('Country', 'event_espresso'), |
|
261 | - true, |
|
262 | - '', |
|
263 | - 'Country' |
|
264 | - ), |
|
265 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
266 | - 'ATT_zip', |
|
267 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
268 | - ), |
|
269 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
270 | - 'ATT_email', |
|
271 | - esc_html__('Email Address', 'event_espresso') |
|
272 | - ), |
|
273 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
274 | - 'ATT_phone', |
|
275 | - esc_html__('Phone', 'event_espresso') |
|
276 | - ), |
|
277 | - ), |
|
278 | - ); |
|
279 | - $this->_model_relations = array( |
|
280 | - 'Registration' => new EE_Has_Many_Relation(), |
|
281 | - 'State' => new EE_Belongs_To_Relation(), |
|
282 | - 'Country' => new EE_Belongs_To_Relation(), |
|
283 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
284 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
285 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
286 | - // allow deletion of attendees even if they have messages in the queue for them. |
|
287 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
288 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
289 | - ); |
|
290 | - $this->_caps_slug = 'contacts'; |
|
291 | - $this->model_chain_to_password = ''; |
|
292 | - parent::__construct($timezone); |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
299 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
300 | - * |
|
301 | - * @param string $system_question_string |
|
302 | - * @return string|null if not found |
|
303 | - */ |
|
304 | - public function get_attendee_field_for_system_question($system_question_string) |
|
305 | - { |
|
306 | - return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
307 | - ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
308 | - : null; |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
315 | - * |
|
316 | - * @return array |
|
317 | - */ |
|
318 | - public function system_question_to_attendee_field_mapping() |
|
319 | - { |
|
320 | - return $this->_system_question_to_attendee_field_name; |
|
321 | - } |
|
322 | - |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
327 | - * |
|
328 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
329 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
330 | - * @throws EE_Error |
|
331 | - */ |
|
332 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
333 | - { |
|
334 | - return $this->get_all( |
|
335 | - array( |
|
336 | - array( |
|
337 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
338 | - ? $transaction_id_or_obj->ID() |
|
339 | - : $transaction_id_or_obj, |
|
340 | - ), |
|
341 | - ) |
|
342 | - ); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * retrieve a single attendee from db via their ID |
|
349 | - * |
|
350 | - * @param $ATT_ID |
|
351 | - * @return mixed array on success, FALSE on fail |
|
352 | - * @deprecated |
|
353 | - */ |
|
354 | - public function get_attendee_by_ID($ATT_ID = false) |
|
355 | - { |
|
356 | - // retrieve a particular EE_Attendee |
|
357 | - return $this->get_one_by_ID($ATT_ID); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * retrieve a single attendee from db via their ID |
|
364 | - * |
|
365 | - * @param array $where_cols_n_values |
|
366 | - * @return mixed array on success, FALSE on fail |
|
367 | - * @throws EE_Error |
|
368 | - */ |
|
369 | - public function get_attendee($where_cols_n_values = array()) |
|
370 | - { |
|
371 | - if (empty($where_cols_n_values)) { |
|
372 | - return false; |
|
373 | - } |
|
374 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
375 | - if (! empty($attendee)) { |
|
376 | - return array_shift($attendee); |
|
377 | - } |
|
378 | - return false; |
|
379 | - } |
|
380 | - |
|
381 | - |
|
382 | - |
|
383 | - /** |
|
384 | - * Search for an existing Attendee record in the DB |
|
385 | - * |
|
386 | - * @param array $where_cols_n_values |
|
387 | - * @return bool|mixed |
|
388 | - * @throws EE_Error |
|
389 | - */ |
|
390 | - public function find_existing_attendee($where_cols_n_values = null) |
|
391 | - { |
|
392 | - // search by combo of first and last names plus the email address |
|
393 | - $attendee_data_keys = array( |
|
394 | - 'ATT_fname' => $this->_ATT_fname, |
|
395 | - 'ATT_lname' => $this->_ATT_lname, |
|
396 | - 'ATT_email' => $this->_ATT_email, |
|
397 | - ); |
|
398 | - // no search params means attendee object already exists. |
|
399 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
400 | - ? $where_cols_n_values |
|
401 | - : $attendee_data_keys; |
|
402 | - $valid_data = true; |
|
403 | - // check for required values |
|
404 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
405 | - ? $valid_data |
|
406 | - : false; |
|
407 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
408 | - ? $valid_data |
|
409 | - : false; |
|
410 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
411 | - ? $valid_data |
|
412 | - : false; |
|
413 | - if ($valid_data) { |
|
414 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
415 | - if ($attendee instanceof EE_Attendee) { |
|
416 | - return $attendee; |
|
417 | - } |
|
418 | - } |
|
419 | - return false; |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Takes an incoming array of EE_Registration ids |
|
426 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
427 | - * |
|
428 | - * @since 4.3.0 |
|
429 | - * @param array $ids array of EE_Registration ids |
|
430 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
431 | - * @throws EE_Error |
|
432 | - */ |
|
433 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
434 | - { |
|
435 | - $ids = (array) $ids; |
|
436 | - $_where = array( |
|
437 | - 'Registration.REG_ID' => array('in', $ids), |
|
438 | - ); |
|
439 | - return $this->get_all(array($_where)); |
|
440 | - } |
|
45 | + /** |
|
46 | + * @deprecated |
|
47 | + */ |
|
48 | + const address2_question_id = 5; |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * @deprecated |
|
53 | + */ |
|
54 | + const city_question_id = 6; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @deprecated |
|
59 | + */ |
|
60 | + const state_question_id = 7; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * @deprecated |
|
65 | + */ |
|
66 | + const country_question_id = 8; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @deprecated |
|
71 | + */ |
|
72 | + const zip_question_id = 9; |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @deprecated |
|
77 | + */ |
|
78 | + const phone_question_id = 10; |
|
79 | + |
|
80 | + /** |
|
81 | + * When looking for questions that correspond to attendee fields, |
|
82 | + * look for the question with this QST_system value. |
|
83 | + * These replace the old constants like EEM_Attendee::*_question_id |
|
84 | + */ |
|
85 | + const system_question_fname = 'fname'; |
|
86 | + |
|
87 | + const system_question_lname = 'lname'; |
|
88 | + |
|
89 | + const system_question_email = 'email'; |
|
90 | + |
|
91 | + const system_question_address = 'address'; |
|
92 | + |
|
93 | + const system_question_address2 = 'address2'; |
|
94 | + |
|
95 | + const system_question_city = 'city'; |
|
96 | + |
|
97 | + const system_question_state = 'state'; |
|
98 | + |
|
99 | + const system_question_country = 'country'; |
|
100 | + |
|
101 | + const system_question_zip = 'zip'; |
|
102 | + |
|
103 | + const system_question_phone = 'phone'; |
|
104 | + |
|
105 | + /** |
|
106 | + * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
107 | + * also all the values of QST_system in the questions table, and values |
|
108 | + * are their corresponding Attendee field names |
|
109 | + * |
|
110 | + * @var array |
|
111 | + */ |
|
112 | + protected $_system_question_to_attendee_field_name = array( |
|
113 | + EEM_Attendee::system_question_fname => 'ATT_fname', |
|
114 | + EEM_Attendee::system_question_lname => 'ATT_lname', |
|
115 | + EEM_Attendee::system_question_email => 'ATT_email', |
|
116 | + EEM_Attendee::system_question_address => 'ATT_address', |
|
117 | + EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
118 | + EEM_Attendee::system_question_city => 'ATT_city', |
|
119 | + EEM_Attendee::system_question_state => 'STA_ID', |
|
120 | + EEM_Attendee::system_question_country => 'CNT_ISO', |
|
121 | + EEM_Attendee::system_question_zip => 'ATT_zip', |
|
122 | + EEM_Attendee::system_question_phone => 'ATT_phone', |
|
123 | + ); |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * EEM_Attendee constructor. |
|
129 | + * |
|
130 | + * @param null $timezone |
|
131 | + * @param ModelFieldFactory $model_field_factory |
|
132 | + * @throws EE_Error |
|
133 | + * @throws InvalidArgumentException |
|
134 | + */ |
|
135 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
136 | + { |
|
137 | + $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
138 | + $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
139 | + $this->_tables = array( |
|
140 | + 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
141 | + 'Attendee_Meta' => new EE_Secondary_Table( |
|
142 | + 'esp_attendee_meta', |
|
143 | + 'ATTM_ID', |
|
144 | + 'ATT_ID' |
|
145 | + ), |
|
146 | + ); |
|
147 | + $this->_fields = array( |
|
148 | + 'Attendee_CPT' => array( |
|
149 | + 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
150 | + 'ID', |
|
151 | + esc_html__('Attendee ID', 'event_espresso') |
|
152 | + ), |
|
153 | + 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
154 | + 'post_title', |
|
155 | + esc_html__('Attendee Full Name', 'event_espresso'), |
|
156 | + false, |
|
157 | + esc_html__('Unknown', 'event_espresso') |
|
158 | + ), |
|
159 | + 'ATT_bio' => $model_field_factory->createPostContentField( |
|
160 | + 'post_content', |
|
161 | + esc_html__('Attendee Biography', 'event_espresso'), |
|
162 | + false, |
|
163 | + esc_html__('No Biography Provided', 'event_espresso') |
|
164 | + ), |
|
165 | + 'ATT_slug' => $model_field_factory->createSlugField( |
|
166 | + 'post_name', |
|
167 | + esc_html__('Attendee URL Slug', 'event_espresso') |
|
168 | + ), |
|
169 | + 'ATT_created' => $model_field_factory->createDatetimeField( |
|
170 | + 'post_date', |
|
171 | + esc_html__('Time Attendee Created', 'event_espresso') |
|
172 | + ), |
|
173 | + 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
174 | + 'post_excerpt', |
|
175 | + esc_html__('Attendee Short Biography', 'event_espresso'), |
|
176 | + true, |
|
177 | + esc_html__('No Biography Provided', 'event_espresso') |
|
178 | + ), |
|
179 | + 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
180 | + 'post_modified', |
|
181 | + esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
182 | + ), |
|
183 | + 'ATT_author' => $model_field_factory->createWpUserField( |
|
184 | + 'post_author', |
|
185 | + esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
186 | + false |
|
187 | + ), |
|
188 | + 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
189 | + 'post_parent', |
|
190 | + esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
191 | + false, |
|
192 | + 0 |
|
193 | + ), |
|
194 | + 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
195 | + 'status' => $model_field_factory->createWpPostStatusField( |
|
196 | + 'post_status', |
|
197 | + esc_html__('Attendee Status', 'event_espresso'), |
|
198 | + false, |
|
199 | + 'publish' |
|
200 | + ), |
|
201 | + 'password' => new EE_Password_Field( |
|
202 | + 'post_password', |
|
203 | + __('Password', 'event_espresso'), |
|
204 | + false, |
|
205 | + '', |
|
206 | + array( |
|
207 | + 'ATT_bio', |
|
208 | + 'ATT_short_bio', |
|
209 | + 'ATT_address', |
|
210 | + 'ATT_address2', |
|
211 | + 'ATT_city', |
|
212 | + 'STA_ID', |
|
213 | + 'CNT_ISO', |
|
214 | + 'ATT_zip', |
|
215 | + 'ATT_email', |
|
216 | + 'ATT_phone' |
|
217 | + ) |
|
218 | + ) |
|
219 | + ), |
|
220 | + 'Attendee_Meta' => array( |
|
221 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
222 | + 'ATTM_ID', |
|
223 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
224 | + false |
|
225 | + ), |
|
226 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
227 | + 'ATT_ID', |
|
228 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
229 | + false |
|
230 | + ), |
|
231 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
232 | + 'ATT_fname', |
|
233 | + esc_html__('First Name', 'event_espresso') |
|
234 | + ), |
|
235 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
236 | + 'ATT_lname', |
|
237 | + esc_html__('Last Name', 'event_espresso') |
|
238 | + ), |
|
239 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
240 | + 'ATT_address', |
|
241 | + esc_html__('Address Part 1', 'event_espresso') |
|
242 | + ), |
|
243 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
244 | + 'ATT_address2', |
|
245 | + esc_html__('Address Part 2', 'event_espresso') |
|
246 | + ), |
|
247 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
248 | + 'ATT_city', |
|
249 | + esc_html__('City', 'event_espresso') |
|
250 | + ), |
|
251 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
252 | + 'STA_ID', |
|
253 | + esc_html__('State', 'event_espresso'), |
|
254 | + true, |
|
255 | + 0, |
|
256 | + 'State' |
|
257 | + ), |
|
258 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
259 | + 'CNT_ISO', |
|
260 | + esc_html__('Country', 'event_espresso'), |
|
261 | + true, |
|
262 | + '', |
|
263 | + 'Country' |
|
264 | + ), |
|
265 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
266 | + 'ATT_zip', |
|
267 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
268 | + ), |
|
269 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
270 | + 'ATT_email', |
|
271 | + esc_html__('Email Address', 'event_espresso') |
|
272 | + ), |
|
273 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
274 | + 'ATT_phone', |
|
275 | + esc_html__('Phone', 'event_espresso') |
|
276 | + ), |
|
277 | + ), |
|
278 | + ); |
|
279 | + $this->_model_relations = array( |
|
280 | + 'Registration' => new EE_Has_Many_Relation(), |
|
281 | + 'State' => new EE_Belongs_To_Relation(), |
|
282 | + 'Country' => new EE_Belongs_To_Relation(), |
|
283 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
284 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
285 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
286 | + // allow deletion of attendees even if they have messages in the queue for them. |
|
287 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
288 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
289 | + ); |
|
290 | + $this->_caps_slug = 'contacts'; |
|
291 | + $this->model_chain_to_password = ''; |
|
292 | + parent::__construct($timezone); |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
299 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
300 | + * |
|
301 | + * @param string $system_question_string |
|
302 | + * @return string|null if not found |
|
303 | + */ |
|
304 | + public function get_attendee_field_for_system_question($system_question_string) |
|
305 | + { |
|
306 | + return isset($this->_system_question_to_attendee_field_name[ $system_question_string ]) |
|
307 | + ? $this->_system_question_to_attendee_field_name[ $system_question_string ] |
|
308 | + : null; |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
315 | + * |
|
316 | + * @return array |
|
317 | + */ |
|
318 | + public function system_question_to_attendee_field_mapping() |
|
319 | + { |
|
320 | + return $this->_system_question_to_attendee_field_name; |
|
321 | + } |
|
322 | + |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
327 | + * |
|
328 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
329 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
330 | + * @throws EE_Error |
|
331 | + */ |
|
332 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
333 | + { |
|
334 | + return $this->get_all( |
|
335 | + array( |
|
336 | + array( |
|
337 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
338 | + ? $transaction_id_or_obj->ID() |
|
339 | + : $transaction_id_or_obj, |
|
340 | + ), |
|
341 | + ) |
|
342 | + ); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * retrieve a single attendee from db via their ID |
|
349 | + * |
|
350 | + * @param $ATT_ID |
|
351 | + * @return mixed array on success, FALSE on fail |
|
352 | + * @deprecated |
|
353 | + */ |
|
354 | + public function get_attendee_by_ID($ATT_ID = false) |
|
355 | + { |
|
356 | + // retrieve a particular EE_Attendee |
|
357 | + return $this->get_one_by_ID($ATT_ID); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * retrieve a single attendee from db via their ID |
|
364 | + * |
|
365 | + * @param array $where_cols_n_values |
|
366 | + * @return mixed array on success, FALSE on fail |
|
367 | + * @throws EE_Error |
|
368 | + */ |
|
369 | + public function get_attendee($where_cols_n_values = array()) |
|
370 | + { |
|
371 | + if (empty($where_cols_n_values)) { |
|
372 | + return false; |
|
373 | + } |
|
374 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
375 | + if (! empty($attendee)) { |
|
376 | + return array_shift($attendee); |
|
377 | + } |
|
378 | + return false; |
|
379 | + } |
|
380 | + |
|
381 | + |
|
382 | + |
|
383 | + /** |
|
384 | + * Search for an existing Attendee record in the DB |
|
385 | + * |
|
386 | + * @param array $where_cols_n_values |
|
387 | + * @return bool|mixed |
|
388 | + * @throws EE_Error |
|
389 | + */ |
|
390 | + public function find_existing_attendee($where_cols_n_values = null) |
|
391 | + { |
|
392 | + // search by combo of first and last names plus the email address |
|
393 | + $attendee_data_keys = array( |
|
394 | + 'ATT_fname' => $this->_ATT_fname, |
|
395 | + 'ATT_lname' => $this->_ATT_lname, |
|
396 | + 'ATT_email' => $this->_ATT_email, |
|
397 | + ); |
|
398 | + // no search params means attendee object already exists. |
|
399 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
400 | + ? $where_cols_n_values |
|
401 | + : $attendee_data_keys; |
|
402 | + $valid_data = true; |
|
403 | + // check for required values |
|
404 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
405 | + ? $valid_data |
|
406 | + : false; |
|
407 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
408 | + ? $valid_data |
|
409 | + : false; |
|
410 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
411 | + ? $valid_data |
|
412 | + : false; |
|
413 | + if ($valid_data) { |
|
414 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
415 | + if ($attendee instanceof EE_Attendee) { |
|
416 | + return $attendee; |
|
417 | + } |
|
418 | + } |
|
419 | + return false; |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Takes an incoming array of EE_Registration ids |
|
426 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
427 | + * |
|
428 | + * @since 4.3.0 |
|
429 | + * @param array $ids array of EE_Registration ids |
|
430 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
431 | + * @throws EE_Error |
|
432 | + */ |
|
433 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
434 | + { |
|
435 | + $ids = (array) $ids; |
|
436 | + $_where = array( |
|
437 | + 'Registration.REG_ID' => array('in', $ids), |
|
438 | + ); |
|
439 | + return $this->get_all(array($_where)); |
|
440 | + } |
|
441 | 441 | } |
@@ -12,41 +12,41 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - // private instance of the EEM_Datetime_Ticket object |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance of the EEM_Datetime_Ticket object |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * private constructor to prevent direct creation |
|
20 | - * @Constructor |
|
21 | - * @access private |
|
22 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - protected function __construct($timezone) |
|
26 | - { |
|
27 | - $this->singular_item = __('Datetime Ticket', 'event_espresso'); |
|
28 | - $this->plural_item = __('Datetime Tickets', 'event_espresso'); |
|
18 | + /** |
|
19 | + * private constructor to prevent direct creation |
|
20 | + * @Constructor |
|
21 | + * @access private |
|
22 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + protected function __construct($timezone) |
|
26 | + { |
|
27 | + $this->singular_item = __('Datetime Ticket', 'event_espresso'); |
|
28 | + $this->plural_item = __('Datetime Tickets', 'event_espresso'); |
|
29 | 29 | |
30 | - $this->_tables = array( |
|
31 | - 'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID') |
|
32 | - ); |
|
33 | - $this->_fields = array( |
|
34 | - 'Datetime_Ticket'=>array( |
|
35 | - 'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')), |
|
36 | - 'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'), |
|
37 | - 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket') |
|
38 | - )); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Ticket'=>new EE_Belongs_To_Relation(), |
|
41 | - 'Datetime'=>new EE_Belongs_To_Relation() |
|
42 | - ); |
|
43 | - // this model is generally available for reading |
|
44 | - $path_to_event = 'Datetime.Event'; |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | - $this->model_chain_to_password = $path_to_event; |
|
50 | - parent::__construct($timezone); |
|
51 | - } |
|
30 | + $this->_tables = array( |
|
31 | + 'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID') |
|
32 | + ); |
|
33 | + $this->_fields = array( |
|
34 | + 'Datetime_Ticket'=>array( |
|
35 | + 'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')), |
|
36 | + 'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'), |
|
37 | + 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket') |
|
38 | + )); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Ticket'=>new EE_Belongs_To_Relation(), |
|
41 | + 'Datetime'=>new EE_Belongs_To_Relation() |
|
42 | + ); |
|
43 | + // this model is generally available for reading |
|
44 | + $path_to_event = 'Datetime.Event'; |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | + $this->model_chain_to_password = $path_to_event; |
|
50 | + parent::__construct($timezone); |
|
51 | + } |
|
52 | 52 | } |
@@ -42,10 +42,10 @@ |
||
42 | 42 | ); |
43 | 43 | // this model is generally available for reading |
44 | 44 | $path_to_event = 'Datetime.Event'; |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | 49 | $this->model_chain_to_password = $path_to_event; |
50 | 50 | parent::__construct($timezone); |
51 | 51 | } |
@@ -9,233 +9,233 @@ |
||
9 | 9 | class EEM_Term_Relationship extends EEM_Base |
10 | 10 | { |
11 | 11 | |
12 | - // private instance of the Attendee object |
|
13 | - protected static $_instance = null; |
|
14 | - |
|
15 | - |
|
16 | - |
|
17 | - /** |
|
18 | - * EEM_Term_Relationship constructor. |
|
19 | - * |
|
20 | - * @param string $timezone |
|
21 | - */ |
|
22 | - protected function __construct($timezone = null) |
|
23 | - { |
|
24 | - $this->singular_item = __('Term Relationship', 'event_espresso'); |
|
25 | - $this->plural_item = __('Term Relationships', 'event_espresso'); |
|
26 | - $this->_tables = array( |
|
27 | - 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
28 | - ); |
|
29 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
30 | - $this->_fields = array( |
|
31 | - 'Term_Relationship' => array( |
|
32 | - 'object_id' => new EE_Foreign_Key_Int_Field( |
|
33 | - 'object_id', |
|
34 | - __('Object(Post) ID', 'event_espresso'), |
|
35 | - false, |
|
36 | - 0, |
|
37 | - $models_this_can_attach_to |
|
38 | - ), |
|
39 | - 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
40 | - 'term_taxonomy_id', |
|
41 | - __( |
|
42 | - 'Term (in context of a taxonomy) ID', |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - false, |
|
46 | - 0, |
|
47 | - 'Term_Taxonomy' |
|
48 | - ), |
|
49 | - 'term_order' => new EE_Integer_Field( |
|
50 | - 'term_order', |
|
51 | - __('Term Order', 'event_espresso'), |
|
52 | - false, |
|
53 | - 0 |
|
54 | - ), |
|
55 | - ), |
|
56 | - ); |
|
57 | - $this->_model_relations = array( |
|
58 | - 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
59 | - ); |
|
60 | - foreach ($models_this_can_attach_to as $model_name) { |
|
61 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
62 | - } |
|
63 | - $this->_wp_core_model = true; |
|
64 | - $this->_indexes = array( |
|
65 | - 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
66 | - ); |
|
67 | - $path_to_event_model = 'Event'; |
|
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | - $path_to_event_model |
|
70 | - ); |
|
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
73 | - $path_to_event_model |
|
74 | - ); |
|
75 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | - $path_to_event_model |
|
77 | - ); |
|
78 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
79 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
80 | - $path_to_event_model, |
|
81 | - EEM_Base::caps_edit |
|
82 | - ); |
|
83 | - $path_to_tax_model = 'Term_Taxonomy.'; |
|
84 | - // add cap restrictions for editing term relations to the "ee_assign_*" |
|
85 | - // and for deleting term relations too |
|
86 | - $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
87 | - foreach ($cap_contexts_affected as $cap_context_affected) { |
|
88 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
89 | - new EE_Default_Where_Conditions( |
|
90 | - array( |
|
91 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
92 | - '!=', |
|
93 | - 'espresso_event_categories', |
|
94 | - ), |
|
95 | - ) |
|
96 | - ); |
|
97 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
98 | - new EE_Default_Where_Conditions( |
|
99 | - array( |
|
100 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
101 | - '!=', |
|
102 | - 'espresso_venue_categories', |
|
103 | - ), |
|
104 | - ) |
|
105 | - ); |
|
106 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | - array( |
|
108 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | - ) |
|
110 | - ); |
|
111 | - } |
|
112 | - parent::__construct($timezone); |
|
113 | - add_filter( |
|
114 | - 'FHEE__Read__create_model_query_params', |
|
115 | - array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
116 | - 10, |
|
117 | - 3 |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Makes sure all term-taxonomy counts are correct |
|
124 | - * |
|
125 | - * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
126 | - * @global wpdb $wpdb |
|
127 | - * @return int the number of rows affected |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
131 | - { |
|
132 | - // because this uses a subquery and sometimes assigning to column to be another column's |
|
133 | - // value, we just write the SQL directly. |
|
134 | - global $wpdb; |
|
135 | - |
|
136 | - $query = " |
|
12 | + // private instance of the Attendee object |
|
13 | + protected static $_instance = null; |
|
14 | + |
|
15 | + |
|
16 | + |
|
17 | + /** |
|
18 | + * EEM_Term_Relationship constructor. |
|
19 | + * |
|
20 | + * @param string $timezone |
|
21 | + */ |
|
22 | + protected function __construct($timezone = null) |
|
23 | + { |
|
24 | + $this->singular_item = __('Term Relationship', 'event_espresso'); |
|
25 | + $this->plural_item = __('Term Relationships', 'event_espresso'); |
|
26 | + $this->_tables = array( |
|
27 | + 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
28 | + ); |
|
29 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
30 | + $this->_fields = array( |
|
31 | + 'Term_Relationship' => array( |
|
32 | + 'object_id' => new EE_Foreign_Key_Int_Field( |
|
33 | + 'object_id', |
|
34 | + __('Object(Post) ID', 'event_espresso'), |
|
35 | + false, |
|
36 | + 0, |
|
37 | + $models_this_can_attach_to |
|
38 | + ), |
|
39 | + 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
40 | + 'term_taxonomy_id', |
|
41 | + __( |
|
42 | + 'Term (in context of a taxonomy) ID', |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + false, |
|
46 | + 0, |
|
47 | + 'Term_Taxonomy' |
|
48 | + ), |
|
49 | + 'term_order' => new EE_Integer_Field( |
|
50 | + 'term_order', |
|
51 | + __('Term Order', 'event_espresso'), |
|
52 | + false, |
|
53 | + 0 |
|
54 | + ), |
|
55 | + ), |
|
56 | + ); |
|
57 | + $this->_model_relations = array( |
|
58 | + 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
59 | + ); |
|
60 | + foreach ($models_this_can_attach_to as $model_name) { |
|
61 | + $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
62 | + } |
|
63 | + $this->_wp_core_model = true; |
|
64 | + $this->_indexes = array( |
|
65 | + 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
66 | + ); |
|
67 | + $path_to_event_model = 'Event'; |
|
68 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | + $path_to_event_model |
|
70 | + ); |
|
71 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
73 | + $path_to_event_model |
|
74 | + ); |
|
75 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | + $path_to_event_model |
|
77 | + ); |
|
78 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
79 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
80 | + $path_to_event_model, |
|
81 | + EEM_Base::caps_edit |
|
82 | + ); |
|
83 | + $path_to_tax_model = 'Term_Taxonomy.'; |
|
84 | + // add cap restrictions for editing term relations to the "ee_assign_*" |
|
85 | + // and for deleting term relations too |
|
86 | + $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
87 | + foreach ($cap_contexts_affected as $cap_context_affected) { |
|
88 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
89 | + new EE_Default_Where_Conditions( |
|
90 | + array( |
|
91 | + $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
92 | + '!=', |
|
93 | + 'espresso_event_categories', |
|
94 | + ), |
|
95 | + ) |
|
96 | + ); |
|
97 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
98 | + new EE_Default_Where_Conditions( |
|
99 | + array( |
|
100 | + $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
101 | + '!=', |
|
102 | + 'espresso_venue_categories', |
|
103 | + ), |
|
104 | + ) |
|
105 | + ); |
|
106 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | + array( |
|
108 | + $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | + ) |
|
110 | + ); |
|
111 | + } |
|
112 | + parent::__construct($timezone); |
|
113 | + add_filter( |
|
114 | + 'FHEE__Read__create_model_query_params', |
|
115 | + array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
116 | + 10, |
|
117 | + 3 |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Makes sure all term-taxonomy counts are correct |
|
124 | + * |
|
125 | + * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
126 | + * @global wpdb $wpdb |
|
127 | + * @return int the number of rows affected |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
131 | + { |
|
132 | + // because this uses a subquery and sometimes assigning to column to be another column's |
|
133 | + // value, we just write the SQL directly. |
|
134 | + global $wpdb; |
|
135 | + |
|
136 | + $query = " |
|
137 | 137 | UPDATE {$wpdb->term_taxonomy} AS tt |
138 | 138 | SET count = ( |
139 | 139 | select count(*) as proper_count from {$wpdb->term_relationships} AS tr |
140 | 140 | WHERE tt.term_taxonomy_id = tr.term_taxonomy_id |
141 | 141 | )"; |
142 | 142 | |
143 | - if ($term_taxonomy_id) { |
|
144 | - $query .= ' WHERE tt.term_taxonomy_id = %d'; |
|
145 | - $query = $wpdb->prepare( |
|
146 | - $query, |
|
147 | - $term_taxonomy_id |
|
148 | - ); |
|
149 | - } |
|
150 | - $rows_affected = $this->_do_wpdb_query( |
|
151 | - 'query', |
|
152 | - array( |
|
153 | - $query, |
|
154 | - ) |
|
155 | - ); |
|
156 | - return $rows_affected; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
163 | - * inserting |
|
164 | - * |
|
165 | - * @param array $field_n_values @see EEM_Base::insert |
|
166 | - * @return boolean |
|
167 | - */ |
|
168 | - public function insert($field_n_values) |
|
169 | - { |
|
170 | - $return = parent::insert($field_n_values); |
|
171 | - if (isset($field_n_values['term_taxonomy_id'])) { |
|
172 | - $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
173 | - } |
|
174 | - return $return; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | - * all ok |
|
182 | - * |
|
183 | - * @param array $fields_n_values see EEM_Base::update |
|
184 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
185 | - * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
186 | - * in this model's entity map according to $fields_n_values that match |
|
187 | - * $query_params. This obviously has some overhead, so you can disable it |
|
188 | - * by setting this to FALSE, but be aware that model objects being used |
|
189 | - * could get out-of-sync with the database |
|
190 | - * @return int |
|
191 | - */ |
|
192 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
193 | - { |
|
194 | - $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
195 | - if ($count) { |
|
196 | - $this->update_term_taxonomy_counts(); |
|
197 | - } |
|
198 | - return $count; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Overrides parent so that after running this, we also double-check |
|
205 | - * the term taxonomy counts are up-to-date |
|
206 | - * |
|
207 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
208 | - * @param boolean $allow_blocking |
|
209 | - * @return int @see EEM_Base::delete |
|
210 | - */ |
|
211 | - public function delete($query_params, $allow_blocking = true) |
|
212 | - { |
|
213 | - $count = parent::delete($query_params, $allow_blocking); |
|
214 | - if ($count) { |
|
215 | - $this->update_term_taxonomy_counts(); |
|
216 | - } |
|
217 | - return $count; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * Makes sure that during REST API queries, we only return term relationships |
|
224 | - * for term taxonomies which should be shown in the rest api |
|
225 | - * |
|
226 | - * @param array $model_query_params |
|
227 | - * @param array $querystring_query_params |
|
228 | - * @param EEM_Base $model |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
232 | - { |
|
233 | - if ($model === EEM_Term_Relationship::instance()) { |
|
234 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
235 | - if (! empty($taxonomies)) { |
|
236 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
237 | - } |
|
238 | - } |
|
239 | - return $model_query_params; |
|
240 | - } |
|
143 | + if ($term_taxonomy_id) { |
|
144 | + $query .= ' WHERE tt.term_taxonomy_id = %d'; |
|
145 | + $query = $wpdb->prepare( |
|
146 | + $query, |
|
147 | + $term_taxonomy_id |
|
148 | + ); |
|
149 | + } |
|
150 | + $rows_affected = $this->_do_wpdb_query( |
|
151 | + 'query', |
|
152 | + array( |
|
153 | + $query, |
|
154 | + ) |
|
155 | + ); |
|
156 | + return $rows_affected; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
163 | + * inserting |
|
164 | + * |
|
165 | + * @param array $field_n_values @see EEM_Base::insert |
|
166 | + * @return boolean |
|
167 | + */ |
|
168 | + public function insert($field_n_values) |
|
169 | + { |
|
170 | + $return = parent::insert($field_n_values); |
|
171 | + if (isset($field_n_values['term_taxonomy_id'])) { |
|
172 | + $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
173 | + } |
|
174 | + return $return; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | + * all ok |
|
182 | + * |
|
183 | + * @param array $fields_n_values see EEM_Base::update |
|
184 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
185 | + * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
186 | + * in this model's entity map according to $fields_n_values that match |
|
187 | + * $query_params. This obviously has some overhead, so you can disable it |
|
188 | + * by setting this to FALSE, but be aware that model objects being used |
|
189 | + * could get out-of-sync with the database |
|
190 | + * @return int |
|
191 | + */ |
|
192 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
193 | + { |
|
194 | + $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
195 | + if ($count) { |
|
196 | + $this->update_term_taxonomy_counts(); |
|
197 | + } |
|
198 | + return $count; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Overrides parent so that after running this, we also double-check |
|
205 | + * the term taxonomy counts are up-to-date |
|
206 | + * |
|
207 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
208 | + * @param boolean $allow_blocking |
|
209 | + * @return int @see EEM_Base::delete |
|
210 | + */ |
|
211 | + public function delete($query_params, $allow_blocking = true) |
|
212 | + { |
|
213 | + $count = parent::delete($query_params, $allow_blocking); |
|
214 | + if ($count) { |
|
215 | + $this->update_term_taxonomy_counts(); |
|
216 | + } |
|
217 | + return $count; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * Makes sure that during REST API queries, we only return term relationships |
|
224 | + * for term taxonomies which should be shown in the rest api |
|
225 | + * |
|
226 | + * @param array $model_query_params |
|
227 | + * @param array $querystring_query_params |
|
228 | + * @param EEM_Base $model |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
232 | + { |
|
233 | + if ($model === EEM_Term_Relationship::instance()) { |
|
234 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
235 | + if (! empty($taxonomies)) { |
|
236 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
237 | + } |
|
238 | + } |
|
239 | + return $model_query_params; |
|
240 | + } |
|
241 | 241 | } |
@@ -58,24 +58,24 @@ discard block |
||
58 | 58 | 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
59 | 59 | ); |
60 | 60 | foreach ($models_this_can_attach_to as $model_name) { |
61 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
61 | + $this->_model_relations[$model_name] = new EE_Belongs_To_Relation(); |
|
62 | 62 | } |
63 | 63 | $this->_wp_core_model = true; |
64 | 64 | $this->_indexes = array( |
65 | 65 | 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
66 | 66 | ); |
67 | 67 | $path_to_event_model = 'Event'; |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | 69 | $path_to_event_model |
70 | 70 | ); |
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
71 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
72 | 72 | new EE_Restriction_Generator_Event_Related_Protected( |
73 | 73 | $path_to_event_model |
74 | 74 | ); |
75 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
75 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | 76 | $path_to_event_model |
77 | 77 | ); |
78 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
78 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
79 | 79 | new EE_Restriction_Generator_Event_Related_Protected( |
80 | 80 | $path_to_event_model, |
81 | 81 | EEM_Base::caps_edit |
@@ -85,27 +85,27 @@ discard block |
||
85 | 85 | // and for deleting term relations too |
86 | 86 | $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
87 | 87 | foreach ($cap_contexts_affected as $cap_context_affected) { |
88 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
88 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = |
|
89 | 89 | new EE_Default_Where_Conditions( |
90 | 90 | array( |
91 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
91 | + $path_to_tax_model.'taxonomy*ee_assign_event_category' => array( |
|
92 | 92 | '!=', |
93 | 93 | 'espresso_event_categories', |
94 | 94 | ), |
95 | 95 | ) |
96 | 96 | ); |
97 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
97 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = |
|
98 | 98 | new EE_Default_Where_Conditions( |
99 | 99 | array( |
100 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
100 | + $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array( |
|
101 | 101 | '!=', |
102 | 102 | 'espresso_venue_categories', |
103 | 103 | ), |
104 | 104 | ) |
105 | 105 | ); |
106 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
106 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | 107 | array( |
108 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
108 | + $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | 109 | ) |
110 | 110 | ); |
111 | 111 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | { |
233 | 233 | if ($model === EEM_Term_Relationship::instance()) { |
234 | 234 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
235 | - if (! empty($taxonomies)) { |
|
235 | + if ( ! empty($taxonomies)) { |
|
236 | 236 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
237 | 237 | } |
238 | 238 | } |
@@ -10,322 +10,322 @@ |
||
10 | 10 | class EEM_Ticket extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * private instance of the EEM_Ticket object |
|
15 | - * |
|
16 | - * @var EEM_Ticket $_instance |
|
17 | - */ |
|
18 | - protected static $_instance; |
|
13 | + /** |
|
14 | + * private instance of the EEM_Ticket object |
|
15 | + * |
|
16 | + * @var EEM_Ticket $_instance |
|
17 | + */ |
|
18 | + protected static $_instance; |
|
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * private constructor to prevent direct creation |
|
23 | - * |
|
24 | - * @Constructor |
|
25 | - * @access private |
|
26 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
27 | - * (and any incoming timezone data that gets saved). |
|
28 | - * Note this just sends the timezone info to the date time model field objects. |
|
29 | - * Default is NULL |
|
30 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
31 | - * @throws EE_Error |
|
32 | - */ |
|
33 | - protected function __construct($timezone) |
|
34 | - { |
|
35 | - $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
36 | - $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
37 | - $this->_tables = array( |
|
38 | - 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
39 | - ); |
|
40 | - $this->_fields = array( |
|
41 | - 'Ticket' => array( |
|
42 | - 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
43 | - 'TKT_ID', |
|
44 | - esc_html__('Ticket ID', 'event_espresso') |
|
45 | - ), |
|
46 | - 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
47 | - 'TTM_ID', |
|
48 | - esc_html__('Ticket Template ID', 'event_espresso'), |
|
49 | - false, |
|
50 | - 0, |
|
51 | - 'Ticket_Template' |
|
52 | - ), |
|
53 | - 'TKT_name' => new EE_Plain_Text_Field( |
|
54 | - 'TKT_name', |
|
55 | - esc_html__('Ticket Name', 'event_espresso'), |
|
56 | - false, |
|
57 | - '' |
|
58 | - ), |
|
59 | - 'TKT_description' => new EE_Post_Content_Field( |
|
60 | - 'TKT_description', |
|
61 | - esc_html__('Description of Ticket', 'event_espresso'), |
|
62 | - false, |
|
63 | - '' |
|
64 | - ), |
|
65 | - 'TKT_start_date' => new EE_Datetime_Field( |
|
66 | - 'TKT_start_date', |
|
67 | - esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
68 | - false, |
|
69 | - EE_Datetime_Field::now, |
|
70 | - $timezone |
|
71 | - ), |
|
72 | - 'TKT_end_date' => new EE_Datetime_Field( |
|
73 | - 'TKT_end_date', |
|
74 | - esc_html__('End time/date of Ticket', 'event_espresso'), |
|
75 | - false, |
|
76 | - EE_Datetime_Field::now, |
|
77 | - $timezone |
|
78 | - ), |
|
79 | - 'TKT_min' => new EE_Integer_Field( |
|
80 | - 'TKT_min', |
|
81 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
82 | - false, |
|
83 | - 0 |
|
84 | - ), |
|
85 | - 'TKT_max' => new EE_Infinite_Integer_Field( |
|
86 | - 'TKT_max', |
|
87 | - esc_html__( |
|
88 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - false, |
|
92 | - EE_INF |
|
93 | - ), |
|
94 | - 'TKT_price' => new EE_Money_Field( |
|
95 | - 'TKT_price', |
|
96 | - esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
97 | - false, |
|
98 | - 0 |
|
99 | - ), |
|
100 | - 'TKT_sold' => new EE_Integer_Field( |
|
101 | - 'TKT_sold', |
|
102 | - esc_html__('Number of this ticket sold', 'event_espresso'), |
|
103 | - false, |
|
104 | - 0 |
|
105 | - ), |
|
106 | - 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
107 | - 'TKT_qty', |
|
108 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
109 | - false, |
|
110 | - EE_INF |
|
111 | - ), |
|
112 | - 'TKT_reserved' => new EE_Integer_Field( |
|
113 | - 'TKT_reserved', |
|
114 | - esc_html__( |
|
115 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
116 | - 'event_espresso' |
|
117 | - ), |
|
118 | - false, |
|
119 | - 0 |
|
120 | - ), |
|
121 | - 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
122 | - 'TKT_uses', |
|
123 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
124 | - false, |
|
125 | - EE_INF |
|
126 | - ), |
|
127 | - 'TKT_required' => new EE_Boolean_Field( |
|
128 | - 'TKT_required', |
|
129 | - esc_html__( |
|
130 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
131 | - 'event_espresso' |
|
132 | - ), |
|
133 | - false, |
|
134 | - false |
|
135 | - ), |
|
136 | - 'TKT_taxable' => new EE_Boolean_Field( |
|
137 | - 'TKT_taxable', |
|
138 | - esc_html__( |
|
139 | - 'Flag indicating whether there is tax applied on this ticket', |
|
140 | - 'event_espresso' |
|
141 | - ), |
|
142 | - false, |
|
143 | - false |
|
144 | - ), |
|
145 | - 'TKT_is_default' => new EE_Boolean_Field( |
|
146 | - 'TKT_is_default', |
|
147 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
148 | - false, |
|
149 | - false |
|
150 | - ), |
|
151 | - 'TKT_order' => new EE_Integer_Field( |
|
152 | - 'TKT_order', |
|
153 | - esc_html__( |
|
154 | - 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
155 | - 'event_espresso' |
|
156 | - ), |
|
157 | - false, |
|
158 | - 0 |
|
159 | - ), |
|
160 | - 'TKT_row' => new EE_Integer_Field( |
|
161 | - 'TKT_row', |
|
162 | - esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
163 | - false, |
|
164 | - 0 |
|
165 | - ), |
|
166 | - 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
167 | - 'TKT_deleted', |
|
168 | - esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
169 | - false, |
|
170 | - false |
|
171 | - ), |
|
172 | - 'TKT_wp_user' => new EE_WP_User_Field( |
|
173 | - 'TKT_wp_user', |
|
174 | - esc_html__('Ticket Creator ID', 'event_espresso'), |
|
175 | - false |
|
176 | - ), |
|
177 | - 'TKT_parent' => new EE_Integer_Field( |
|
178 | - 'TKT_parent', |
|
179 | - esc_html__( |
|
180 | - 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
181 | - 'event_espresso' |
|
182 | - ), |
|
183 | - true, |
|
184 | - 0 |
|
185 | - ), |
|
186 | - ), |
|
187 | - ); |
|
188 | - $this->_model_relations = array( |
|
189 | - 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
190 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
191 | - 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
192 | - 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
193 | - 'Registration' => new EE_Has_Many_Relation(), |
|
194 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
195 | - ); |
|
196 | - // this model is generally available for reading |
|
197 | - $path_to_event = 'Datetime.Event'; |
|
198 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
199 | - 'TKT_is_default', |
|
200 | - $path_to_event |
|
201 | - ); |
|
202 | - // account for default tickets in the caps |
|
203 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
|
204 | - 'TKT_is_default', |
|
205 | - $path_to_event |
|
206 | - ); |
|
207 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
208 | - 'TKT_is_default', |
|
209 | - $path_to_event |
|
210 | - ); |
|
211 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
212 | - 'TKT_is_default', |
|
213 | - $path_to_event |
|
214 | - ); |
|
215 | - $this->model_chain_to_password = $path_to_event; |
|
216 | - parent::__construct($timezone); |
|
217 | - } |
|
21 | + /** |
|
22 | + * private constructor to prevent direct creation |
|
23 | + * |
|
24 | + * @Constructor |
|
25 | + * @access private |
|
26 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
27 | + * (and any incoming timezone data that gets saved). |
|
28 | + * Note this just sends the timezone info to the date time model field objects. |
|
29 | + * Default is NULL |
|
30 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
31 | + * @throws EE_Error |
|
32 | + */ |
|
33 | + protected function __construct($timezone) |
|
34 | + { |
|
35 | + $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
36 | + $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
37 | + $this->_tables = array( |
|
38 | + 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
39 | + ); |
|
40 | + $this->_fields = array( |
|
41 | + 'Ticket' => array( |
|
42 | + 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
43 | + 'TKT_ID', |
|
44 | + esc_html__('Ticket ID', 'event_espresso') |
|
45 | + ), |
|
46 | + 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
47 | + 'TTM_ID', |
|
48 | + esc_html__('Ticket Template ID', 'event_espresso'), |
|
49 | + false, |
|
50 | + 0, |
|
51 | + 'Ticket_Template' |
|
52 | + ), |
|
53 | + 'TKT_name' => new EE_Plain_Text_Field( |
|
54 | + 'TKT_name', |
|
55 | + esc_html__('Ticket Name', 'event_espresso'), |
|
56 | + false, |
|
57 | + '' |
|
58 | + ), |
|
59 | + 'TKT_description' => new EE_Post_Content_Field( |
|
60 | + 'TKT_description', |
|
61 | + esc_html__('Description of Ticket', 'event_espresso'), |
|
62 | + false, |
|
63 | + '' |
|
64 | + ), |
|
65 | + 'TKT_start_date' => new EE_Datetime_Field( |
|
66 | + 'TKT_start_date', |
|
67 | + esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
68 | + false, |
|
69 | + EE_Datetime_Field::now, |
|
70 | + $timezone |
|
71 | + ), |
|
72 | + 'TKT_end_date' => new EE_Datetime_Field( |
|
73 | + 'TKT_end_date', |
|
74 | + esc_html__('End time/date of Ticket', 'event_espresso'), |
|
75 | + false, |
|
76 | + EE_Datetime_Field::now, |
|
77 | + $timezone |
|
78 | + ), |
|
79 | + 'TKT_min' => new EE_Integer_Field( |
|
80 | + 'TKT_min', |
|
81 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
82 | + false, |
|
83 | + 0 |
|
84 | + ), |
|
85 | + 'TKT_max' => new EE_Infinite_Integer_Field( |
|
86 | + 'TKT_max', |
|
87 | + esc_html__( |
|
88 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + false, |
|
92 | + EE_INF |
|
93 | + ), |
|
94 | + 'TKT_price' => new EE_Money_Field( |
|
95 | + 'TKT_price', |
|
96 | + esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
97 | + false, |
|
98 | + 0 |
|
99 | + ), |
|
100 | + 'TKT_sold' => new EE_Integer_Field( |
|
101 | + 'TKT_sold', |
|
102 | + esc_html__('Number of this ticket sold', 'event_espresso'), |
|
103 | + false, |
|
104 | + 0 |
|
105 | + ), |
|
106 | + 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
107 | + 'TKT_qty', |
|
108 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
109 | + false, |
|
110 | + EE_INF |
|
111 | + ), |
|
112 | + 'TKT_reserved' => new EE_Integer_Field( |
|
113 | + 'TKT_reserved', |
|
114 | + esc_html__( |
|
115 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
116 | + 'event_espresso' |
|
117 | + ), |
|
118 | + false, |
|
119 | + 0 |
|
120 | + ), |
|
121 | + 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
122 | + 'TKT_uses', |
|
123 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
124 | + false, |
|
125 | + EE_INF |
|
126 | + ), |
|
127 | + 'TKT_required' => new EE_Boolean_Field( |
|
128 | + 'TKT_required', |
|
129 | + esc_html__( |
|
130 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
131 | + 'event_espresso' |
|
132 | + ), |
|
133 | + false, |
|
134 | + false |
|
135 | + ), |
|
136 | + 'TKT_taxable' => new EE_Boolean_Field( |
|
137 | + 'TKT_taxable', |
|
138 | + esc_html__( |
|
139 | + 'Flag indicating whether there is tax applied on this ticket', |
|
140 | + 'event_espresso' |
|
141 | + ), |
|
142 | + false, |
|
143 | + false |
|
144 | + ), |
|
145 | + 'TKT_is_default' => new EE_Boolean_Field( |
|
146 | + 'TKT_is_default', |
|
147 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
148 | + false, |
|
149 | + false |
|
150 | + ), |
|
151 | + 'TKT_order' => new EE_Integer_Field( |
|
152 | + 'TKT_order', |
|
153 | + esc_html__( |
|
154 | + 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
155 | + 'event_espresso' |
|
156 | + ), |
|
157 | + false, |
|
158 | + 0 |
|
159 | + ), |
|
160 | + 'TKT_row' => new EE_Integer_Field( |
|
161 | + 'TKT_row', |
|
162 | + esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
163 | + false, |
|
164 | + 0 |
|
165 | + ), |
|
166 | + 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
167 | + 'TKT_deleted', |
|
168 | + esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
169 | + false, |
|
170 | + false |
|
171 | + ), |
|
172 | + 'TKT_wp_user' => new EE_WP_User_Field( |
|
173 | + 'TKT_wp_user', |
|
174 | + esc_html__('Ticket Creator ID', 'event_espresso'), |
|
175 | + false |
|
176 | + ), |
|
177 | + 'TKT_parent' => new EE_Integer_Field( |
|
178 | + 'TKT_parent', |
|
179 | + esc_html__( |
|
180 | + 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
181 | + 'event_espresso' |
|
182 | + ), |
|
183 | + true, |
|
184 | + 0 |
|
185 | + ), |
|
186 | + ), |
|
187 | + ); |
|
188 | + $this->_model_relations = array( |
|
189 | + 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
190 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
191 | + 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
192 | + 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
193 | + 'Registration' => new EE_Has_Many_Relation(), |
|
194 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
195 | + ); |
|
196 | + // this model is generally available for reading |
|
197 | + $path_to_event = 'Datetime.Event'; |
|
198 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
199 | + 'TKT_is_default', |
|
200 | + $path_to_event |
|
201 | + ); |
|
202 | + // account for default tickets in the caps |
|
203 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
|
204 | + 'TKT_is_default', |
|
205 | + $path_to_event |
|
206 | + ); |
|
207 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
208 | + 'TKT_is_default', |
|
209 | + $path_to_event |
|
210 | + ); |
|
211 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
212 | + 'TKT_is_default', |
|
213 | + $path_to_event |
|
214 | + ); |
|
215 | + $this->model_chain_to_password = $path_to_event; |
|
216 | + parent::__construct($timezone); |
|
217 | + } |
|
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * This returns all tickets that are defaults from the db |
|
222 | - * |
|
223 | - * @return EE_Ticket[] |
|
224 | - * @throws EE_Error |
|
225 | - */ |
|
226 | - public function get_all_default_tickets() |
|
227 | - { |
|
228 | - /** @type EE_Ticket[] $tickets */ |
|
229 | - $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
230 | - // we need to set the start date and end date to today's date and the start of the default dtt |
|
231 | - return $this->_set_default_dates($tickets); |
|
232 | - } |
|
220 | + /** |
|
221 | + * This returns all tickets that are defaults from the db |
|
222 | + * |
|
223 | + * @return EE_Ticket[] |
|
224 | + * @throws EE_Error |
|
225 | + */ |
|
226 | + public function get_all_default_tickets() |
|
227 | + { |
|
228 | + /** @type EE_Ticket[] $tickets */ |
|
229 | + $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
230 | + // we need to set the start date and end date to today's date and the start of the default dtt |
|
231 | + return $this->_set_default_dates($tickets); |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - /** |
|
236 | - * sets up relevant start and end date for EE_Ticket (s) |
|
237 | - * |
|
238 | - * @param EE_Ticket[] $tickets |
|
239 | - * @return EE_Ticket[] |
|
240 | - * @throws EE_Error |
|
241 | - */ |
|
242 | - private function _set_default_dates($tickets) |
|
243 | - { |
|
244 | - foreach ($tickets as $ticket) { |
|
245 | - $ticket->set( |
|
246 | - 'TKT_start_date', |
|
247 | - (int) $this->current_time_for_query('TKT_start_date', true) |
|
248 | - ); |
|
249 | - $ticket->set( |
|
250 | - 'TKT_end_date', |
|
251 | - (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
252 | - ); |
|
253 | - $ticket->set_end_time( |
|
254 | - $this->convert_datetime_for_query( |
|
255 | - 'TKT_end_date', |
|
256 | - '11:59 pm', |
|
257 | - 'g:i a', |
|
258 | - $this->_timezone |
|
259 | - ) |
|
260 | - ); |
|
261 | - } |
|
262 | - return $tickets; |
|
263 | - } |
|
235 | + /** |
|
236 | + * sets up relevant start and end date for EE_Ticket (s) |
|
237 | + * |
|
238 | + * @param EE_Ticket[] $tickets |
|
239 | + * @return EE_Ticket[] |
|
240 | + * @throws EE_Error |
|
241 | + */ |
|
242 | + private function _set_default_dates($tickets) |
|
243 | + { |
|
244 | + foreach ($tickets as $ticket) { |
|
245 | + $ticket->set( |
|
246 | + 'TKT_start_date', |
|
247 | + (int) $this->current_time_for_query('TKT_start_date', true) |
|
248 | + ); |
|
249 | + $ticket->set( |
|
250 | + 'TKT_end_date', |
|
251 | + (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
252 | + ); |
|
253 | + $ticket->set_end_time( |
|
254 | + $this->convert_datetime_for_query( |
|
255 | + 'TKT_end_date', |
|
256 | + '11:59 pm', |
|
257 | + 'g:i a', |
|
258 | + $this->_timezone |
|
259 | + ) |
|
260 | + ); |
|
261 | + } |
|
262 | + return $tickets; |
|
263 | + } |
|
264 | 264 | |
265 | 265 | |
266 | - /** |
|
267 | - * Gets the total number of tickets available at a particular datetime (does |
|
268 | - * NOT take int account the datetime's spaces available) |
|
269 | - * |
|
270 | - * @param int $DTT_ID |
|
271 | - * @param array $query_params |
|
272 | - * @return int |
|
273 | - */ |
|
274 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
275 | - { |
|
276 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
277 | - } |
|
266 | + /** |
|
267 | + * Gets the total number of tickets available at a particular datetime (does |
|
268 | + * NOT take int account the datetime's spaces available) |
|
269 | + * |
|
270 | + * @param int $DTT_ID |
|
271 | + * @param array $query_params |
|
272 | + * @return int |
|
273 | + */ |
|
274 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
275 | + { |
|
276 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
277 | + } |
|
278 | 278 | |
279 | 279 | |
280 | - /** |
|
281 | - * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
282 | - * |
|
283 | - * @param EE_Ticket[] $tickets |
|
284 | - * @return void |
|
285 | - * @throws EE_Error |
|
286 | - */ |
|
287 | - public function update_tickets_sold($tickets) |
|
288 | - { |
|
289 | - foreach ($tickets as $ticket) { |
|
290 | - /* @var $ticket EE_Ticket */ |
|
291 | - $ticket->update_tickets_sold(); |
|
292 | - } |
|
293 | - } |
|
280 | + /** |
|
281 | + * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
282 | + * |
|
283 | + * @param EE_Ticket[] $tickets |
|
284 | + * @return void |
|
285 | + * @throws EE_Error |
|
286 | + */ |
|
287 | + public function update_tickets_sold($tickets) |
|
288 | + { |
|
289 | + foreach ($tickets as $ticket) { |
|
290 | + /* @var $ticket EE_Ticket */ |
|
291 | + $ticket->update_tickets_sold(); |
|
292 | + } |
|
293 | + } |
|
294 | 294 | |
295 | 295 | |
296 | - /** |
|
297 | - * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
298 | - * |
|
299 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
300 | - * @throws EE_Error |
|
301 | - */ |
|
302 | - public function get_tickets_with_reservations() |
|
303 | - { |
|
304 | - return $this->get_all( |
|
305 | - array( |
|
306 | - array( |
|
307 | - 'TKT_reserved' => array('>', 0), |
|
308 | - ), |
|
309 | - ) |
|
310 | - ); |
|
311 | - } |
|
296 | + /** |
|
297 | + * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
298 | + * |
|
299 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
300 | + * @throws EE_Error |
|
301 | + */ |
|
302 | + public function get_tickets_with_reservations() |
|
303 | + { |
|
304 | + return $this->get_all( |
|
305 | + array( |
|
306 | + array( |
|
307 | + 'TKT_reserved' => array('>', 0), |
|
308 | + ), |
|
309 | + ) |
|
310 | + ); |
|
311 | + } |
|
312 | 312 | |
313 | 313 | |
314 | - /** |
|
315 | - * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
316 | - * |
|
317 | - * @param array $ticket_IDs |
|
318 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
319 | - * @throws EE_Error |
|
320 | - */ |
|
321 | - public function get_tickets_with_IDs(array $ticket_IDs) |
|
322 | - { |
|
323 | - return $this->get_all( |
|
324 | - array( |
|
325 | - array( |
|
326 | - 'TKT_ID' => array('IN', $ticket_IDs), |
|
327 | - ), |
|
328 | - ) |
|
329 | - ); |
|
330 | - } |
|
314 | + /** |
|
315 | + * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
316 | + * |
|
317 | + * @param array $ticket_IDs |
|
318 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
319 | + * @throws EE_Error |
|
320 | + */ |
|
321 | + public function get_tickets_with_IDs(array $ticket_IDs) |
|
322 | + { |
|
323 | + return $this->get_all( |
|
324 | + array( |
|
325 | + array( |
|
326 | + 'TKT_ID' => array('IN', $ticket_IDs), |
|
327 | + ), |
|
328 | + ) |
|
329 | + ); |
|
330 | + } |
|
331 | 331 | } |
@@ -195,20 +195,20 @@ |
||
195 | 195 | ); |
196 | 196 | // this model is generally available for reading |
197 | 197 | $path_to_event = 'Datetime.Event'; |
198 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
|
198 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
199 | 199 | 'TKT_is_default', |
200 | 200 | $path_to_event |
201 | 201 | ); |
202 | 202 | // account for default tickets in the caps |
203 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
|
203 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
204 | 204 | 'TKT_is_default', |
205 | 205 | $path_to_event |
206 | 206 | ); |
207 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
|
207 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
208 | 208 | 'TKT_is_default', |
209 | 209 | $path_to_event |
210 | 210 | ); |
211 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
|
211 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
212 | 212 | 'TKT_is_default', |
213 | 213 | $path_to_event |
214 | 214 | ); |
@@ -13,899 +13,899 @@ |
||
13 | 13 | class EEM_Event extends EEM_CPT_Base |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
18 | - * event |
|
19 | - */ |
|
20 | - const sold_out = 'sold_out'; |
|
21 | - |
|
22 | - /** |
|
23 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
24 | - * date) |
|
25 | - */ |
|
26 | - const postponed = 'postponed'; |
|
27 | - |
|
28 | - /** |
|
29 | - * constant used by status(), indicating that the event will no longer occur |
|
30 | - */ |
|
31 | - const cancelled = 'cancelled'; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - protected static $_default_reg_status; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * This is the default for the additional limit field. |
|
42 | - * @var int |
|
43 | - */ |
|
44 | - protected static $_default_additional_limit = 10; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * private instance of the Event object |
|
49 | - * |
|
50 | - * @var EEM_Event |
|
51 | - */ |
|
52 | - protected static $_instance; |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
59 | - * |
|
60 | - * @param string $timezone |
|
61 | - * @throws \EE_Error |
|
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 | - ), |
|
265 | - ); |
|
266 | - $this->_model_relations = array( |
|
267 | - 'Registration' => new EE_Has_Many_Relation(), |
|
268 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
269 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
270 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
271 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
272 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
273 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
274 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
275 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
276 | - ); |
|
277 | - // this model is generally available for reading |
|
278 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
279 | - $this->model_chain_to_password = ''; |
|
280 | - parent::__construct($timezone); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @param string $default_reg_status |
|
287 | - */ |
|
288 | - public static function set_default_reg_status($default_reg_status) |
|
289 | - { |
|
290 | - self::$_default_reg_status = $default_reg_status; |
|
291 | - // if EEM_Event has already been instantiated, |
|
292 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
293 | - if (self::$_instance instanceof EEM_Event) { |
|
294 | - $default_reg_status = new EE_Enum_Text_Field( |
|
295 | - 'EVT_default_registration_status', |
|
296 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
297 | - false, |
|
298 | - $default_reg_status, |
|
299 | - EEM_Registration::reg_status_array() |
|
300 | - ); |
|
301 | - $default_reg_status->_construct_finalize( |
|
302 | - 'Event_Meta', |
|
303 | - 'EVT_default_registration_status', |
|
304 | - 'EEM_Event' |
|
305 | - ); |
|
306 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
307 | - } |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * Used to override the default for the additional limit field. |
|
313 | - * @param $additional_limit |
|
314 | - */ |
|
315 | - public static function set_default_additional_limit($additional_limit) |
|
316 | - { |
|
317 | - self::$_default_additional_limit = (int) $additional_limit; |
|
318 | - if (self::$_instance instanceof EEM_Event) { |
|
319 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
320 | - 'EVT_additional_limit', |
|
321 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
322 | - true, |
|
323 | - self::$_default_additional_limit |
|
324 | - ); |
|
325 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
326 | - 'Event_Meta', |
|
327 | - 'EVT_additional_limit', |
|
328 | - 'EEM_Event' |
|
329 | - ); |
|
330 | - } |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * Return what is currently set as the default additional limit for the event. |
|
336 | - * @return int |
|
337 | - */ |
|
338 | - public static function get_default_additional_limit() |
|
339 | - { |
|
340 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * get_question_groups |
|
346 | - * |
|
347 | - * @return array |
|
348 | - * @throws \EE_Error |
|
349 | - */ |
|
350 | - public function get_all_question_groups() |
|
351 | - { |
|
352 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
353 | - array( |
|
354 | - array('QSG_deleted' => false), |
|
355 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
356 | - ) |
|
357 | - ); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * get_question_groups |
|
364 | - * |
|
365 | - * @param int $EVT_ID |
|
366 | - * @return array|bool |
|
367 | - * @throws \EE_Error |
|
368 | - */ |
|
369 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
370 | - { |
|
371 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
372 | - EE_Error::add_error( |
|
373 | - esc_html__( |
|
374 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
375 | - 'event_espresso' |
|
376 | - ), |
|
377 | - __FILE__, |
|
378 | - __FUNCTION__, |
|
379 | - __LINE__ |
|
380 | - ); |
|
381 | - return false; |
|
382 | - } |
|
383 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
384 | - array( |
|
385 | - array('EVT_ID' => $EVT_ID), |
|
386 | - ) |
|
387 | - ); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * get_question_groups |
|
394 | - * |
|
395 | - * @param int $EVT_ID |
|
396 | - * @param boolean $for_primary_attendee |
|
397 | - * @return array|bool |
|
398 | - * @throws \EE_Error |
|
399 | - */ |
|
400 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
401 | - { |
|
402 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
403 | - EE_Error::add_error( |
|
404 | - esc_html__( |
|
405 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
406 | - 'event_espresso' |
|
407 | - ), |
|
408 | - __FILE__, |
|
409 | - __FUNCTION__, |
|
410 | - __LINE__ |
|
411 | - ); |
|
412 | - return false; |
|
413 | - } |
|
414 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
415 | - array( |
|
416 | - array( |
|
417 | - 'EVT_ID' => $EVT_ID, |
|
418 | - 'EQG_primary' => $for_primary_attendee, |
|
419 | - ), |
|
420 | - ) |
|
421 | - ); |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * get_question_groups |
|
428 | - * |
|
429 | - * @param int $EVT_ID |
|
430 | - * @param EE_Registration $registration |
|
431 | - * @return array|bool |
|
432 | - * @throws \EE_Error |
|
433 | - */ |
|
434 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
435 | - { |
|
436 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
437 | - EE_Error::add_error( |
|
438 | - esc_html__( |
|
439 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
440 | - 'event_espresso' |
|
441 | - ), |
|
442 | - __FILE__, |
|
443 | - __FUNCTION__, |
|
444 | - __LINE__ |
|
445 | - ); |
|
446 | - return false; |
|
447 | - } |
|
448 | - $where_params = array( |
|
449 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
450 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
451 | - 'QSG_deleted' => false, |
|
452 | - ); |
|
453 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
454 | - array( |
|
455 | - $where_params, |
|
456 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
457 | - ) |
|
458 | - ); |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * get_question_target_db_column |
|
465 | - * |
|
466 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
467 | - * @return array|bool |
|
468 | - * @throws \EE_Error |
|
469 | - */ |
|
470 | - public function get_questions_in_groups($QSG_IDs = '') |
|
471 | - { |
|
472 | - if (empty($QSG_IDs)) { |
|
473 | - EE_Error::add_error( |
|
474 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
475 | - __FILE__, |
|
476 | - __FUNCTION__, |
|
477 | - __LINE__ |
|
478 | - ); |
|
479 | - return false; |
|
480 | - } |
|
481 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
482 | - array( |
|
483 | - array( |
|
484 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
485 | - 'QST_deleted' => false, |
|
486 | - 'QST_admin_only' => is_admin(), |
|
487 | - ), |
|
488 | - 'order_by' => 'QST_order', |
|
489 | - ) |
|
490 | - ); |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * get_options_for_question |
|
497 | - * |
|
498 | - * @param string $QST_IDs csv list of $QST IDs |
|
499 | - * @return array|bool |
|
500 | - * @throws \EE_Error |
|
501 | - */ |
|
502 | - public function get_options_for_question($QST_IDs) |
|
503 | - { |
|
504 | - if (empty($QST_IDs)) { |
|
505 | - EE_Error::add_error( |
|
506 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
507 | - __FILE__, |
|
508 | - __FUNCTION__, |
|
509 | - __LINE__ |
|
510 | - ); |
|
511 | - return false; |
|
512 | - } |
|
513 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
514 | - array( |
|
515 | - array( |
|
516 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
517 | - 'QSO_deleted' => false, |
|
518 | - ), |
|
519 | - 'order_by' => 'QSO_ID', |
|
520 | - ) |
|
521 | - ); |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * Gets all events that are published |
|
532 | - * and have event start time earlier than now and an event end time later than now |
|
533 | - * |
|
534 | - * @param array $query_params An array of query params to further filter on |
|
535 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
536 | - * @param bool $count whether to return the count or not (default FALSE) |
|
537 | - * @return EE_Event[]|int |
|
538 | - * @throws \EE_Error |
|
539 | - */ |
|
540 | - public function get_active_events($query_params, $count = false) |
|
541 | - { |
|
542 | - if (array_key_exists(0, $query_params)) { |
|
543 | - $where_params = $query_params[0]; |
|
544 | - unset($query_params[0]); |
|
545 | - } else { |
|
546 | - $where_params = array(); |
|
547 | - } |
|
548 | - // if we have count make sure we don't include group by |
|
549 | - if ($count && isset($query_params['group_by'])) { |
|
550 | - unset($query_params['group_by']); |
|
551 | - } |
|
552 | - // let's add specific query_params for active_events |
|
553 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
554 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
555 | - // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
556 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
557 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
558 | - '<', |
|
559 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
560 | - ); |
|
561 | - } else { |
|
562 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
563 | - '<', |
|
564 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
565 | - ); |
|
566 | - } |
|
567 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
568 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
569 | - '>', |
|
570 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
571 | - ); |
|
572 | - } else { |
|
573 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
574 | - '>', |
|
575 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
576 | - ); |
|
577 | - } |
|
578 | - $query_params[0] = $where_params; |
|
579 | - // don't use $query_params with count() |
|
580 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
581 | - return $count |
|
582 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
583 | - : $this->get_all($query_params); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * get all events that are published and have an event start time later than now |
|
590 | - * |
|
591 | - * @param array $query_params An array of query params to further filter on |
|
592 | - * (Note that status and DTT_EVT_start will be overridden) |
|
593 | - * @param bool $count whether to return the count or not (default FALSE) |
|
594 | - * @return EE_Event[]|int |
|
595 | - * @throws \EE_Error |
|
596 | - */ |
|
597 | - public function get_upcoming_events($query_params, $count = false) |
|
598 | - { |
|
599 | - if (array_key_exists(0, $query_params)) { |
|
600 | - $where_params = $query_params[0]; |
|
601 | - unset($query_params[0]); |
|
602 | - } else { |
|
603 | - $where_params = array(); |
|
604 | - } |
|
605 | - // if we have count make sure we don't include group by |
|
606 | - if ($count && isset($query_params['group_by'])) { |
|
607 | - unset($query_params['group_by']); |
|
608 | - } |
|
609 | - // let's add specific query_params for active_events |
|
610 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
611 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
612 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
613 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
614 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
615 | - '>', |
|
616 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
617 | - ); |
|
618 | - } else { |
|
619 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
620 | - '>', |
|
621 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
622 | - ); |
|
623 | - } |
|
624 | - $query_params[0] = $where_params; |
|
625 | - // don't use $query_params with count() |
|
626 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
627 | - return $count |
|
628 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
629 | - : $this->get_all($query_params); |
|
630 | - } |
|
631 | - |
|
632 | - |
|
633 | - |
|
634 | - /** |
|
635 | - * Gets all events that are published |
|
636 | - * and have an event end time later than now |
|
637 | - * |
|
638 | - * @param array $query_params An array of query params to further filter on |
|
639 | - * (note that status and DTT_EVT_end will be overridden) |
|
640 | - * @param bool $count whether to return the count or not (default FALSE) |
|
641 | - * @return EE_Event[]|int |
|
642 | - * @throws \EE_Error |
|
643 | - */ |
|
644 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
645 | - { |
|
646 | - if (array_key_exists(0, $query_params)) { |
|
647 | - $where_params = $query_params[0]; |
|
648 | - unset($query_params[0]); |
|
649 | - } else { |
|
650 | - $where_params = array(); |
|
651 | - } |
|
652 | - // if we have count make sure we don't include group by |
|
653 | - if ($count && isset($query_params['group_by'])) { |
|
654 | - unset($query_params['group_by']); |
|
655 | - } |
|
656 | - // let's add specific query_params for active_events |
|
657 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
658 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
659 | - // add where params for DTT_EVT_end |
|
660 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
661 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
662 | - '>', |
|
663 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
664 | - ); |
|
665 | - } else { |
|
666 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
667 | - '>', |
|
668 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
669 | - ); |
|
670 | - } |
|
671 | - $query_params[0] = $where_params; |
|
672 | - // don't use $query_params with count() |
|
673 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
674 | - return $count |
|
675 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
676 | - : $this->get_all($query_params); |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * This only returns events that are expired. |
|
683 | - * They may still be published but all their datetimes have expired. |
|
684 | - * |
|
685 | - * @param array $query_params An array of query params to further filter on |
|
686 | - * (note that status and DTT_EVT_end will be overridden) |
|
687 | - * @param bool $count whether to return the count or not (default FALSE) |
|
688 | - * @return EE_Event[]|int |
|
689 | - * @throws \EE_Error |
|
690 | - */ |
|
691 | - public function get_expired_events($query_params, $count = false) |
|
692 | - { |
|
693 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
694 | - // if we have count make sure we don't include group by |
|
695 | - if ($count && isset($query_params['group_by'])) { |
|
696 | - unset($query_params['group_by']); |
|
697 | - } |
|
698 | - // let's add specific query_params for active_events |
|
699 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
700 | - if (isset($where_params['status'])) { |
|
701 | - unset($where_params['status']); |
|
702 | - } |
|
703 | - $exclude_query = $query_params; |
|
704 | - if (isset($exclude_query[0])) { |
|
705 | - unset($exclude_query[0]); |
|
706 | - } |
|
707 | - $exclude_query[0] = array( |
|
708 | - 'Datetime.DTT_EVT_end' => array( |
|
709 | - '>', |
|
710 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
711 | - ), |
|
712 | - ); |
|
713 | - // first get all events that have datetimes where its not expired. |
|
714 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
715 | - $event_ids = array_keys($event_ids); |
|
716 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
717 | - $and_condition = array( |
|
718 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
719 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
720 | - ); |
|
721 | - if (isset($where_params['OR'])) { |
|
722 | - $and_condition['OR'] = $where_params['OR']; |
|
723 | - unset($where_params['OR']); |
|
724 | - } |
|
725 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
726 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
727 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
728 | - } |
|
729 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
730 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
731 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
732 | - } |
|
733 | - // merge remaining $where params with the and conditions. |
|
734 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
735 | - $query_params[0] = $where_params; |
|
736 | - // don't use $query_params with count() |
|
737 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
738 | - return $count |
|
739 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
740 | - : $this->get_all($query_params); |
|
741 | - } |
|
742 | - |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * This basically just returns the events that do not have the publish status. |
|
747 | - * |
|
748 | - * @param array $query_params An array of query params to further filter on |
|
749 | - * (note that status will be overwritten) |
|
750 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
751 | - * @return EE_Event[]|int |
|
752 | - * @throws \EE_Error |
|
753 | - */ |
|
754 | - public function get_inactive_events($query_params, $count = false) |
|
755 | - { |
|
756 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
757 | - // let's add in specific query_params for inactive events. |
|
758 | - if (isset($where_params['status'])) { |
|
759 | - unset($where_params['status']); |
|
760 | - } |
|
761 | - // if we have count make sure we don't include group by |
|
762 | - if ($count && isset($query_params['group_by'])) { |
|
763 | - unset($query_params['group_by']); |
|
764 | - } |
|
765 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
766 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
767 | - if (isset($where_params['OR'])) { |
|
768 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
769 | - unset($where_params['OR']); |
|
770 | - } |
|
771 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
772 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
773 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
774 | - } |
|
775 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
776 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
777 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
778 | - } |
|
779 | - $query_params[0] = $where_params; |
|
780 | - // don't use $query_params with count() |
|
781 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
782 | - return $count |
|
783 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
784 | - : $this->get_all($query_params); |
|
785 | - } |
|
786 | - |
|
787 | - |
|
788 | - |
|
789 | - /** |
|
790 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
791 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
792 | - * attached to the event. See parent for param descriptions |
|
793 | - * |
|
794 | - * @param $id_or_obj |
|
795 | - * @param $other_model_id_or_obj |
|
796 | - * @param string $relationName |
|
797 | - * @param array $where_query |
|
798 | - * @return EE_Base_Class |
|
799 | - * @throws EE_Error |
|
800 | - */ |
|
801 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
802 | - { |
|
803 | - if ($relationName === 'Price') { |
|
804 | - // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
805 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
806 | - // if EVT_ID = 0, then this is a default |
|
807 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
808 | - // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
809 | - $prc_chk->set('PRC_ID', 0); |
|
810 | - } |
|
811 | - // run parent |
|
812 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
813 | - } |
|
814 | - // otherwise carry on as normal |
|
815 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
816 | - } |
|
817 | - |
|
818 | - |
|
819 | - |
|
820 | - /******************** DEPRECATED METHODS ********************/ |
|
821 | - |
|
822 | - |
|
823 | - |
|
824 | - /** |
|
825 | - * _get_question_target_db_column |
|
826 | - * |
|
827 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
828 | - * EE_Registration_Custom_Questions_Form located in |
|
829 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
830 | - * @access public |
|
831 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
832 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
833 | - * registration). |
|
834 | - * @throws EE_Error |
|
835 | - * @return array |
|
836 | - */ |
|
837 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
838 | - { |
|
839 | - if (empty($EVT_ID)) { |
|
840 | - throw new EE_Error(__( |
|
841 | - 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
842 | - 'event_espresso' |
|
843 | - )); |
|
844 | - } |
|
845 | - $questions = array(); |
|
846 | - // get all question groups for event |
|
847 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
848 | - if (! empty($qgs)) { |
|
849 | - foreach ($qgs as $qg) { |
|
850 | - $qsts = $qg->questions(); |
|
851 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
852 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
853 | - foreach ($qsts as $qst) { |
|
854 | - if ($qst->is_system_question()) { |
|
855 | - continue; |
|
856 | - } |
|
857 | - $answer = EEM_Answer::instance()->get_one(array( |
|
858 | - array( |
|
859 | - 'QST_ID' => $qst->ID(), |
|
860 | - 'REG_ID' => $registration->ID(), |
|
861 | - ), |
|
862 | - )); |
|
863 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
864 | - $qst_name = $qstn_id = $qst->ID(); |
|
865 | - $ans_id = $answer->ID(); |
|
866 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
867 | - $input_name = ''; |
|
868 | - $input_id = sanitize_key($qst->display_text()); |
|
869 | - $input_class = ''; |
|
870 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
871 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
872 | - . $input_name |
|
873 | - . $qst_name; |
|
874 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
875 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
876 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
877 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
878 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
879 | - // leave responses as-is, don't convert stuff into html entities please! |
|
880 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
881 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
882 | - $QSOs = $qst->options(true, $answer->value()); |
|
883 | - if (is_array($QSOs)) { |
|
884 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
885 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
886 | - } |
|
887 | - } |
|
888 | - } |
|
889 | - } |
|
890 | - } |
|
891 | - } |
|
892 | - return $questions; |
|
893 | - } |
|
894 | - |
|
895 | - |
|
896 | - /** |
|
897 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
898 | - * or an stdClass where each property is the name of a column, |
|
899 | - * @return EE_Base_Class |
|
900 | - * @throws \EE_Error |
|
901 | - */ |
|
902 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
903 | - { |
|
904 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
905 | - if ($classInstance instanceof EE_Event) { |
|
906 | - // events have their timezone defined in the DB, so use it immediately |
|
907 | - $this->set_timezone($classInstance->get_timezone()); |
|
908 | - } |
|
909 | - return $classInstance; |
|
910 | - } |
|
16 | + /** |
|
17 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
18 | + * event |
|
19 | + */ |
|
20 | + const sold_out = 'sold_out'; |
|
21 | + |
|
22 | + /** |
|
23 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
24 | + * date) |
|
25 | + */ |
|
26 | + const postponed = 'postponed'; |
|
27 | + |
|
28 | + /** |
|
29 | + * constant used by status(), indicating that the event will no longer occur |
|
30 | + */ |
|
31 | + const cancelled = 'cancelled'; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + protected static $_default_reg_status; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * This is the default for the additional limit field. |
|
42 | + * @var int |
|
43 | + */ |
|
44 | + protected static $_default_additional_limit = 10; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * private instance of the Event object |
|
49 | + * |
|
50 | + * @var EEM_Event |
|
51 | + */ |
|
52 | + protected static $_instance; |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
59 | + * |
|
60 | + * @param string $timezone |
|
61 | + * @throws \EE_Error |
|
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 | + ), |
|
265 | + ); |
|
266 | + $this->_model_relations = array( |
|
267 | + 'Registration' => new EE_Has_Many_Relation(), |
|
268 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
269 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
270 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
271 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
272 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
273 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
274 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
275 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
276 | + ); |
|
277 | + // this model is generally available for reading |
|
278 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
279 | + $this->model_chain_to_password = ''; |
|
280 | + parent::__construct($timezone); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @param string $default_reg_status |
|
287 | + */ |
|
288 | + public static function set_default_reg_status($default_reg_status) |
|
289 | + { |
|
290 | + self::$_default_reg_status = $default_reg_status; |
|
291 | + // if EEM_Event has already been instantiated, |
|
292 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
293 | + if (self::$_instance instanceof EEM_Event) { |
|
294 | + $default_reg_status = new EE_Enum_Text_Field( |
|
295 | + 'EVT_default_registration_status', |
|
296 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
297 | + false, |
|
298 | + $default_reg_status, |
|
299 | + EEM_Registration::reg_status_array() |
|
300 | + ); |
|
301 | + $default_reg_status->_construct_finalize( |
|
302 | + 'Event_Meta', |
|
303 | + 'EVT_default_registration_status', |
|
304 | + 'EEM_Event' |
|
305 | + ); |
|
306 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
307 | + } |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * Used to override the default for the additional limit field. |
|
313 | + * @param $additional_limit |
|
314 | + */ |
|
315 | + public static function set_default_additional_limit($additional_limit) |
|
316 | + { |
|
317 | + self::$_default_additional_limit = (int) $additional_limit; |
|
318 | + if (self::$_instance instanceof EEM_Event) { |
|
319 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
320 | + 'EVT_additional_limit', |
|
321 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
322 | + true, |
|
323 | + self::$_default_additional_limit |
|
324 | + ); |
|
325 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
326 | + 'Event_Meta', |
|
327 | + 'EVT_additional_limit', |
|
328 | + 'EEM_Event' |
|
329 | + ); |
|
330 | + } |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * Return what is currently set as the default additional limit for the event. |
|
336 | + * @return int |
|
337 | + */ |
|
338 | + public static function get_default_additional_limit() |
|
339 | + { |
|
340 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * get_question_groups |
|
346 | + * |
|
347 | + * @return array |
|
348 | + * @throws \EE_Error |
|
349 | + */ |
|
350 | + public function get_all_question_groups() |
|
351 | + { |
|
352 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
353 | + array( |
|
354 | + array('QSG_deleted' => false), |
|
355 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
356 | + ) |
|
357 | + ); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * get_question_groups |
|
364 | + * |
|
365 | + * @param int $EVT_ID |
|
366 | + * @return array|bool |
|
367 | + * @throws \EE_Error |
|
368 | + */ |
|
369 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
370 | + { |
|
371 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
372 | + EE_Error::add_error( |
|
373 | + esc_html__( |
|
374 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
375 | + 'event_espresso' |
|
376 | + ), |
|
377 | + __FILE__, |
|
378 | + __FUNCTION__, |
|
379 | + __LINE__ |
|
380 | + ); |
|
381 | + return false; |
|
382 | + } |
|
383 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
384 | + array( |
|
385 | + array('EVT_ID' => $EVT_ID), |
|
386 | + ) |
|
387 | + ); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * get_question_groups |
|
394 | + * |
|
395 | + * @param int $EVT_ID |
|
396 | + * @param boolean $for_primary_attendee |
|
397 | + * @return array|bool |
|
398 | + * @throws \EE_Error |
|
399 | + */ |
|
400 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
401 | + { |
|
402 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
403 | + EE_Error::add_error( |
|
404 | + esc_html__( |
|
405 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
406 | + 'event_espresso' |
|
407 | + ), |
|
408 | + __FILE__, |
|
409 | + __FUNCTION__, |
|
410 | + __LINE__ |
|
411 | + ); |
|
412 | + return false; |
|
413 | + } |
|
414 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
415 | + array( |
|
416 | + array( |
|
417 | + 'EVT_ID' => $EVT_ID, |
|
418 | + 'EQG_primary' => $for_primary_attendee, |
|
419 | + ), |
|
420 | + ) |
|
421 | + ); |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * get_question_groups |
|
428 | + * |
|
429 | + * @param int $EVT_ID |
|
430 | + * @param EE_Registration $registration |
|
431 | + * @return array|bool |
|
432 | + * @throws \EE_Error |
|
433 | + */ |
|
434 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
435 | + { |
|
436 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
437 | + EE_Error::add_error( |
|
438 | + esc_html__( |
|
439 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
440 | + 'event_espresso' |
|
441 | + ), |
|
442 | + __FILE__, |
|
443 | + __FUNCTION__, |
|
444 | + __LINE__ |
|
445 | + ); |
|
446 | + return false; |
|
447 | + } |
|
448 | + $where_params = array( |
|
449 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
450 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
451 | + 'QSG_deleted' => false, |
|
452 | + ); |
|
453 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
454 | + array( |
|
455 | + $where_params, |
|
456 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
457 | + ) |
|
458 | + ); |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * get_question_target_db_column |
|
465 | + * |
|
466 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
467 | + * @return array|bool |
|
468 | + * @throws \EE_Error |
|
469 | + */ |
|
470 | + public function get_questions_in_groups($QSG_IDs = '') |
|
471 | + { |
|
472 | + if (empty($QSG_IDs)) { |
|
473 | + EE_Error::add_error( |
|
474 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
475 | + __FILE__, |
|
476 | + __FUNCTION__, |
|
477 | + __LINE__ |
|
478 | + ); |
|
479 | + return false; |
|
480 | + } |
|
481 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
482 | + array( |
|
483 | + array( |
|
484 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
485 | + 'QST_deleted' => false, |
|
486 | + 'QST_admin_only' => is_admin(), |
|
487 | + ), |
|
488 | + 'order_by' => 'QST_order', |
|
489 | + ) |
|
490 | + ); |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * get_options_for_question |
|
497 | + * |
|
498 | + * @param string $QST_IDs csv list of $QST IDs |
|
499 | + * @return array|bool |
|
500 | + * @throws \EE_Error |
|
501 | + */ |
|
502 | + public function get_options_for_question($QST_IDs) |
|
503 | + { |
|
504 | + if (empty($QST_IDs)) { |
|
505 | + EE_Error::add_error( |
|
506 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
507 | + __FILE__, |
|
508 | + __FUNCTION__, |
|
509 | + __LINE__ |
|
510 | + ); |
|
511 | + return false; |
|
512 | + } |
|
513 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
514 | + array( |
|
515 | + array( |
|
516 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
517 | + 'QSO_deleted' => false, |
|
518 | + ), |
|
519 | + 'order_by' => 'QSO_ID', |
|
520 | + ) |
|
521 | + ); |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * Gets all events that are published |
|
532 | + * and have event start time earlier than now and an event end time later than now |
|
533 | + * |
|
534 | + * @param array $query_params An array of query params to further filter on |
|
535 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
536 | + * @param bool $count whether to return the count or not (default FALSE) |
|
537 | + * @return EE_Event[]|int |
|
538 | + * @throws \EE_Error |
|
539 | + */ |
|
540 | + public function get_active_events($query_params, $count = false) |
|
541 | + { |
|
542 | + if (array_key_exists(0, $query_params)) { |
|
543 | + $where_params = $query_params[0]; |
|
544 | + unset($query_params[0]); |
|
545 | + } else { |
|
546 | + $where_params = array(); |
|
547 | + } |
|
548 | + // if we have count make sure we don't include group by |
|
549 | + if ($count && isset($query_params['group_by'])) { |
|
550 | + unset($query_params['group_by']); |
|
551 | + } |
|
552 | + // let's add specific query_params for active_events |
|
553 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
554 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
555 | + // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
556 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
557 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
558 | + '<', |
|
559 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
560 | + ); |
|
561 | + } else { |
|
562 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
563 | + '<', |
|
564 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
565 | + ); |
|
566 | + } |
|
567 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
568 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
569 | + '>', |
|
570 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
571 | + ); |
|
572 | + } else { |
|
573 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
574 | + '>', |
|
575 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
576 | + ); |
|
577 | + } |
|
578 | + $query_params[0] = $where_params; |
|
579 | + // don't use $query_params with count() |
|
580 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
581 | + return $count |
|
582 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
583 | + : $this->get_all($query_params); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * get all events that are published and have an event start time later than now |
|
590 | + * |
|
591 | + * @param array $query_params An array of query params to further filter on |
|
592 | + * (Note that status and DTT_EVT_start will be overridden) |
|
593 | + * @param bool $count whether to return the count or not (default FALSE) |
|
594 | + * @return EE_Event[]|int |
|
595 | + * @throws \EE_Error |
|
596 | + */ |
|
597 | + public function get_upcoming_events($query_params, $count = false) |
|
598 | + { |
|
599 | + if (array_key_exists(0, $query_params)) { |
|
600 | + $where_params = $query_params[0]; |
|
601 | + unset($query_params[0]); |
|
602 | + } else { |
|
603 | + $where_params = array(); |
|
604 | + } |
|
605 | + // if we have count make sure we don't include group by |
|
606 | + if ($count && isset($query_params['group_by'])) { |
|
607 | + unset($query_params['group_by']); |
|
608 | + } |
|
609 | + // let's add specific query_params for active_events |
|
610 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
611 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
612 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
613 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
614 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
615 | + '>', |
|
616 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
617 | + ); |
|
618 | + } else { |
|
619 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
620 | + '>', |
|
621 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
622 | + ); |
|
623 | + } |
|
624 | + $query_params[0] = $where_params; |
|
625 | + // don't use $query_params with count() |
|
626 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
627 | + return $count |
|
628 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
629 | + : $this->get_all($query_params); |
|
630 | + } |
|
631 | + |
|
632 | + |
|
633 | + |
|
634 | + /** |
|
635 | + * Gets all events that are published |
|
636 | + * and have an event end time later than now |
|
637 | + * |
|
638 | + * @param array $query_params An array of query params to further filter on |
|
639 | + * (note that status and DTT_EVT_end will be overridden) |
|
640 | + * @param bool $count whether to return the count or not (default FALSE) |
|
641 | + * @return EE_Event[]|int |
|
642 | + * @throws \EE_Error |
|
643 | + */ |
|
644 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
645 | + { |
|
646 | + if (array_key_exists(0, $query_params)) { |
|
647 | + $where_params = $query_params[0]; |
|
648 | + unset($query_params[0]); |
|
649 | + } else { |
|
650 | + $where_params = array(); |
|
651 | + } |
|
652 | + // if we have count make sure we don't include group by |
|
653 | + if ($count && isset($query_params['group_by'])) { |
|
654 | + unset($query_params['group_by']); |
|
655 | + } |
|
656 | + // let's add specific query_params for active_events |
|
657 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
658 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
659 | + // add where params for DTT_EVT_end |
|
660 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
661 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
662 | + '>', |
|
663 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
664 | + ); |
|
665 | + } else { |
|
666 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
667 | + '>', |
|
668 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
669 | + ); |
|
670 | + } |
|
671 | + $query_params[0] = $where_params; |
|
672 | + // don't use $query_params with count() |
|
673 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
674 | + return $count |
|
675 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
676 | + : $this->get_all($query_params); |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * This only returns events that are expired. |
|
683 | + * They may still be published but all their datetimes have expired. |
|
684 | + * |
|
685 | + * @param array $query_params An array of query params to further filter on |
|
686 | + * (note that status and DTT_EVT_end will be overridden) |
|
687 | + * @param bool $count whether to return the count or not (default FALSE) |
|
688 | + * @return EE_Event[]|int |
|
689 | + * @throws \EE_Error |
|
690 | + */ |
|
691 | + public function get_expired_events($query_params, $count = false) |
|
692 | + { |
|
693 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
694 | + // if we have count make sure we don't include group by |
|
695 | + if ($count && isset($query_params['group_by'])) { |
|
696 | + unset($query_params['group_by']); |
|
697 | + } |
|
698 | + // let's add specific query_params for active_events |
|
699 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
700 | + if (isset($where_params['status'])) { |
|
701 | + unset($where_params['status']); |
|
702 | + } |
|
703 | + $exclude_query = $query_params; |
|
704 | + if (isset($exclude_query[0])) { |
|
705 | + unset($exclude_query[0]); |
|
706 | + } |
|
707 | + $exclude_query[0] = array( |
|
708 | + 'Datetime.DTT_EVT_end' => array( |
|
709 | + '>', |
|
710 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
711 | + ), |
|
712 | + ); |
|
713 | + // first get all events that have datetimes where its not expired. |
|
714 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
715 | + $event_ids = array_keys($event_ids); |
|
716 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
717 | + $and_condition = array( |
|
718 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
719 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
720 | + ); |
|
721 | + if (isset($where_params['OR'])) { |
|
722 | + $and_condition['OR'] = $where_params['OR']; |
|
723 | + unset($where_params['OR']); |
|
724 | + } |
|
725 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
726 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
727 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
728 | + } |
|
729 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
730 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
731 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
732 | + } |
|
733 | + // merge remaining $where params with the and conditions. |
|
734 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
735 | + $query_params[0] = $where_params; |
|
736 | + // don't use $query_params with count() |
|
737 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
738 | + return $count |
|
739 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
740 | + : $this->get_all($query_params); |
|
741 | + } |
|
742 | + |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * This basically just returns the events that do not have the publish status. |
|
747 | + * |
|
748 | + * @param array $query_params An array of query params to further filter on |
|
749 | + * (note that status will be overwritten) |
|
750 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
751 | + * @return EE_Event[]|int |
|
752 | + * @throws \EE_Error |
|
753 | + */ |
|
754 | + public function get_inactive_events($query_params, $count = false) |
|
755 | + { |
|
756 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
757 | + // let's add in specific query_params for inactive events. |
|
758 | + if (isset($where_params['status'])) { |
|
759 | + unset($where_params['status']); |
|
760 | + } |
|
761 | + // if we have count make sure we don't include group by |
|
762 | + if ($count && isset($query_params['group_by'])) { |
|
763 | + unset($query_params['group_by']); |
|
764 | + } |
|
765 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
766 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
767 | + if (isset($where_params['OR'])) { |
|
768 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
769 | + unset($where_params['OR']); |
|
770 | + } |
|
771 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
772 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
773 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
774 | + } |
|
775 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
776 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
777 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
778 | + } |
|
779 | + $query_params[0] = $where_params; |
|
780 | + // don't use $query_params with count() |
|
781 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
782 | + return $count |
|
783 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
784 | + : $this->get_all($query_params); |
|
785 | + } |
|
786 | + |
|
787 | + |
|
788 | + |
|
789 | + /** |
|
790 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
791 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
792 | + * attached to the event. See parent for param descriptions |
|
793 | + * |
|
794 | + * @param $id_or_obj |
|
795 | + * @param $other_model_id_or_obj |
|
796 | + * @param string $relationName |
|
797 | + * @param array $where_query |
|
798 | + * @return EE_Base_Class |
|
799 | + * @throws EE_Error |
|
800 | + */ |
|
801 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
802 | + { |
|
803 | + if ($relationName === 'Price') { |
|
804 | + // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
805 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
806 | + // if EVT_ID = 0, then this is a default |
|
807 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
808 | + // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
809 | + $prc_chk->set('PRC_ID', 0); |
|
810 | + } |
|
811 | + // run parent |
|
812 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
813 | + } |
|
814 | + // otherwise carry on as normal |
|
815 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
816 | + } |
|
817 | + |
|
818 | + |
|
819 | + |
|
820 | + /******************** DEPRECATED METHODS ********************/ |
|
821 | + |
|
822 | + |
|
823 | + |
|
824 | + /** |
|
825 | + * _get_question_target_db_column |
|
826 | + * |
|
827 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
828 | + * EE_Registration_Custom_Questions_Form located in |
|
829 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
830 | + * @access public |
|
831 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
832 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
833 | + * registration). |
|
834 | + * @throws EE_Error |
|
835 | + * @return array |
|
836 | + */ |
|
837 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
838 | + { |
|
839 | + if (empty($EVT_ID)) { |
|
840 | + throw new EE_Error(__( |
|
841 | + 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
842 | + 'event_espresso' |
|
843 | + )); |
|
844 | + } |
|
845 | + $questions = array(); |
|
846 | + // get all question groups for event |
|
847 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
848 | + if (! empty($qgs)) { |
|
849 | + foreach ($qgs as $qg) { |
|
850 | + $qsts = $qg->questions(); |
|
851 | + $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
852 | + $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
853 | + foreach ($qsts as $qst) { |
|
854 | + if ($qst->is_system_question()) { |
|
855 | + continue; |
|
856 | + } |
|
857 | + $answer = EEM_Answer::instance()->get_one(array( |
|
858 | + array( |
|
859 | + 'QST_ID' => $qst->ID(), |
|
860 | + 'REG_ID' => $registration->ID(), |
|
861 | + ), |
|
862 | + )); |
|
863 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
864 | + $qst_name = $qstn_id = $qst->ID(); |
|
865 | + $ans_id = $answer->ID(); |
|
866 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
867 | + $input_name = ''; |
|
868 | + $input_id = sanitize_key($qst->display_text()); |
|
869 | + $input_class = ''; |
|
870 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
871 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
872 | + . $input_name |
|
873 | + . $qst_name; |
|
874 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
875 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
876 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
877 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
878 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
879 | + // leave responses as-is, don't convert stuff into html entities please! |
|
880 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
881 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
882 | + $QSOs = $qst->options(true, $answer->value()); |
|
883 | + if (is_array($QSOs)) { |
|
884 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
885 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
886 | + } |
|
887 | + } |
|
888 | + } |
|
889 | + } |
|
890 | + } |
|
891 | + } |
|
892 | + return $questions; |
|
893 | + } |
|
894 | + |
|
895 | + |
|
896 | + /** |
|
897 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
898 | + * or an stdClass where each property is the name of a column, |
|
899 | + * @return EE_Base_Class |
|
900 | + * @throws \EE_Error |
|
901 | + */ |
|
902 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
903 | + { |
|
904 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
905 | + if ($classInstance instanceof EE_Event) { |
|
906 | + // events have their timezone defined in the DB, so use it immediately |
|
907 | + $this->set_timezone($classInstance->get_timezone()); |
|
908 | + } |
|
909 | + return $classInstance; |
|
910 | + } |
|
911 | 911 | } |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | 'WP_User' => new EE_Belongs_To_Relation(), |
276 | 276 | ); |
277 | 277 | // this model is generally available for reading |
278 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
278 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
279 | 279 | $this->model_chain_to_password = ''; |
280 | 280 | parent::__construct($timezone); |
281 | 281 | } |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | */ |
369 | 369 | public function get_all_event_question_groups($EVT_ID = 0) |
370 | 370 | { |
371 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
371 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
372 | 372 | EE_Error::add_error( |
373 | 373 | esc_html__( |
374 | 374 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | */ |
400 | 400 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
401 | 401 | { |
402 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
402 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
403 | 403 | EE_Error::add_error( |
404 | 404 | esc_html__( |
405 | 405 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | */ |
434 | 434 | public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
435 | 435 | { |
436 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
436 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
437 | 437 | EE_Error::add_error( |
438 | 438 | esc_html__( |
439 | 439 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -845,11 +845,11 @@ discard block |
||
845 | 845 | $questions = array(); |
846 | 846 | // get all question groups for event |
847 | 847 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
848 | - if (! empty($qgs)) { |
|
848 | + if ( ! empty($qgs)) { |
|
849 | 849 | foreach ($qgs as $qg) { |
850 | 850 | $qsts = $qg->questions(); |
851 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
852 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
851 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
852 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
853 | 853 | foreach ($qsts as $qst) { |
854 | 854 | if ($qst->is_system_question()) { |
855 | 855 | continue; |
@@ -863,26 +863,26 @@ discard block |
||
863 | 863 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
864 | 864 | $qst_name = $qstn_id = $qst->ID(); |
865 | 865 | $ans_id = $answer->ID(); |
866 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
866 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
867 | 867 | $input_name = ''; |
868 | 868 | $input_id = sanitize_key($qst->display_text()); |
869 | 869 | $input_class = ''; |
870 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
871 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
870 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
871 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
872 | 872 | . $input_name |
873 | 873 | . $qst_name; |
874 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
875 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
876 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
877 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
878 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
874 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
875 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
876 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
877 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
878 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
879 | 879 | // leave responses as-is, don't convert stuff into html entities please! |
880 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
880 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
881 | 881 | if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
882 | 882 | $QSOs = $qst->options(true, $answer->value()); |
883 | 883 | if (is_array($QSOs)) { |
884 | 884 | foreach ($QSOs as $QSO_ID => $QSO) { |
885 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
885 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
886 | 886 | } |
887 | 887 | } |
888 | 888 | } |