@@ -80,24 +80,24 @@ discard block |
||
80 | 80 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
81 | 81 | */ |
82 | 82 | $input_fields = []; |
83 | - if (! empty($this->args['where'])) { |
|
83 | + if ( ! empty($this->args['where'])) { |
|
84 | 84 | $input_fields = $this->sanitizeInputFields($this->args['where']); |
85 | 85 | |
86 | 86 | // Use the proper operator. |
87 | - if (! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) { |
|
87 | + if ( ! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) { |
|
88 | 88 | $input_fields['PRC_ID'] = ['in', $input_fields['PRC_ID']]; |
89 | 89 | } |
90 | - if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
90 | + if ( ! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
91 | 91 | $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
92 | 92 | } |
93 | - if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
93 | + if ( ! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
94 | 94 | $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']]; |
95 | 95 | } |
96 | - if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
96 | + if ( ! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
97 | 97 | $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']]; |
98 | 98 | } |
99 | 99 | // if event ID is passed but not a ticket ID |
100 | - if (! isset($input_fields['Ticket.TKT_ID']) && isset($input_fields['Event.EVT_ID'])) { |
|
100 | + if ( ! isset($input_fields['Ticket.TKT_ID']) && isset($input_fields['Event.EVT_ID'])) { |
|
101 | 101 | $event_id = $input_fields['Event.EVT_ID']; |
102 | 102 | // Ensure that this doesn't go to the query. |
103 | 103 | // After all there is no DB relation between event and price |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * Merge the input_fields with the default query_args |
134 | 134 | */ |
135 | - if (! empty($input_fields)) { |
|
135 | + if ( ! empty($input_fields)) { |
|
136 | 136 | $where_params = array_merge($where_params, $input_fields); |
137 | 137 | } |
138 | 138 | |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $default_prices_params = []; |
142 | 142 | |
143 | 143 | // If default ticket prices should be included. |
144 | - if (! empty($this->args['where']['includeDefaultTicketsPrices'])) { |
|
144 | + if ( ! empty($this->args['where']['includeDefaultTicketsPrices'])) { |
|
145 | 145 | $default_ticket_ids = EEM_Ticket::instance()->get_col([ |
146 | 146 | [ |
147 | 147 | 'TKT_is_default' => 1, |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ]); |
151 | 151 | |
152 | 152 | // if we have default tickets |
153 | - if (! empty($default_ticket_ids)) { |
|
153 | + if ( ! empty($default_ticket_ids)) { |
|
154 | 154 | $default_prices_params['OR'] = [ |
155 | 155 | 'Ticket.TKT_ID' => ['IN', $default_ticket_ids], |
156 | 156 | ]; |
@@ -158,14 +158,14 @@ discard block |
||
158 | 158 | } |
159 | 159 | |
160 | 160 | // If default prices should be included. |
161 | - if (! empty($this->args['where']['includeDefaultPrices'])) { |
|
161 | + if ( ! empty($this->args['where']['includeDefaultPrices'])) { |
|
162 | 162 | $default_prices_params['AND'] = [ |
163 | 163 | 'PRC_deleted' => 0, |
164 | 164 | 'PRC_is_default' => 1, |
165 | 165 | ]; |
166 | 166 | } |
167 | 167 | |
168 | - if (! empty($default_prices_params)) { |
|
168 | + if ( ! empty($default_prices_params)) { |
|
169 | 169 | if (empty($where_params)) { |
170 | 170 | $where_params['OR'] = $default_prices_params; |
171 | 171 | } else { |
@@ -17,219 +17,219 @@ |
||
17 | 17 | */ |
18 | 18 | class PriceConnectionResolver extends AbstractConnectionResolver |
19 | 19 | { |
20 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
21 | - public function get_loader_name(): string |
|
22 | - { |
|
23 | - return 'espresso_price'; |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * @return EEM_Price |
|
28 | - * @throws EE_Error |
|
29 | - * @throws InvalidArgumentException |
|
30 | - * @throws InvalidDataTypeException |
|
31 | - * @throws InvalidInterfaceException |
|
32 | - * @throws ReflectionException |
|
33 | - */ |
|
34 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | - public function get_query(): EEM_Price |
|
36 | - { |
|
37 | - return EEM_Price::instance(); |
|
38 | - } |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Return an array of item IDs from the query |
|
43 | - * |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
47 | - public function get_ids(): array |
|
48 | - { |
|
49 | - $results = $this->query->get_col($this->query_args); |
|
50 | - |
|
51 | - return ! empty($results) ? $results : []; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
57 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
58 | - * handle batch resolution of the posts. |
|
59 | - * |
|
60 | - * @return array |
|
61 | - * @throws EE_Error |
|
62 | - * @throws InvalidArgumentException |
|
63 | - * @throws ReflectionException |
|
64 | - * @throws InvalidDataTypeException |
|
65 | - * @throws InvalidInterfaceException |
|
66 | - */ |
|
67 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
68 | - public function get_query_args(): array |
|
69 | - { |
|
70 | - $where_params = []; |
|
71 | - $query_args = []; |
|
72 | - |
|
73 | - $query_args['limit'] = $this->getLimit(); |
|
74 | - |
|
75 | - // Avoid multiple entries by join. |
|
76 | - $query_args['group_by'] = 'PRC_ID'; |
|
77 | - |
|
78 | - $query_args['default_where_conditions'] = 'minimum'; |
|
79 | - |
|
80 | - /** |
|
81 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
82 | - */ |
|
83 | - $input_fields = []; |
|
84 | - if (! empty($this->args['where'])) { |
|
85 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
86 | - |
|
87 | - // Use the proper operator. |
|
88 | - if (! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) { |
|
89 | - $input_fields['PRC_ID'] = ['in', $input_fields['PRC_ID']]; |
|
90 | - } |
|
91 | - if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
92 | - $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
93 | - } |
|
94 | - if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
95 | - $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']]; |
|
96 | - } |
|
97 | - if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
98 | - $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']]; |
|
99 | - } |
|
100 | - // if event ID is passed but not a ticket ID |
|
101 | - if (! isset($input_fields['Ticket.TKT_ID']) && isset($input_fields['Event.EVT_ID'])) { |
|
102 | - $event_id = $input_fields['Event.EVT_ID']; |
|
103 | - // Ensure that this doesn't go to the query. |
|
104 | - // After all there is no DB relation between event and price |
|
105 | - unset($input_fields['Event.EVT_ID']); |
|
106 | - // get all the datetimeIds of the event |
|
107 | - $event_datetime_ids = EEM_Datetime::instance()->get_col([ |
|
108 | - [ |
|
109 | - 'EVT_ID' => $event_id, |
|
110 | - ], |
|
111 | - 'default_where_conditions' => 'minimum' |
|
112 | - ]); |
|
113 | - // get all the related ticket Ids |
|
114 | - $ticket_ids = EEM_Ticket::instance()->get_col([ |
|
115 | - [ |
|
116 | - 'Datetime.DTT_ID' => ['IN', $event_datetime_ids], |
|
117 | - ], |
|
118 | - 'default_where_conditions' => 'minimum' |
|
119 | - ]); |
|
120 | - |
|
121 | - // add tickets relation to the query |
|
122 | - $input_fields['Ticket.TKT_ID'] = ['IN', $ticket_ids]; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
128 | - */ |
|
129 | - if ($this->source instanceof EE_Ticket) { |
|
130 | - $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Merge the input_fields with the default query_args |
|
135 | - */ |
|
136 | - if (! empty($input_fields)) { |
|
137 | - $where_params = array_merge($where_params, $input_fields); |
|
138 | - } |
|
139 | - |
|
140 | - [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID'); |
|
141 | - |
|
142 | - $default_prices_params = []; |
|
143 | - |
|
144 | - // If default ticket prices should be included. |
|
145 | - if (! empty($this->args['where']['includeDefaultTicketsPrices'])) { |
|
146 | - $default_ticket_ids = EEM_Ticket::instance()->get_col([ |
|
147 | - [ |
|
148 | - 'TKT_is_default' => 1, |
|
149 | - ], |
|
150 | - 'default_where_conditions' => 'minimum' |
|
151 | - ]); |
|
152 | - |
|
153 | - // if we have default tickets |
|
154 | - if (! empty($default_ticket_ids)) { |
|
155 | - $default_prices_params['OR'] = [ |
|
156 | - 'Ticket.TKT_ID' => ['IN', $default_ticket_ids], |
|
157 | - ]; |
|
158 | - } |
|
159 | - } |
|
160 | - |
|
161 | - // If default prices should be included. |
|
162 | - if (! empty($this->args['where']['includeDefaultPrices'])) { |
|
163 | - $default_prices_params['AND'] = [ |
|
164 | - 'PRC_deleted' => 0, |
|
165 | - 'PRC_is_default' => 1, |
|
166 | - ]; |
|
167 | - } |
|
168 | - |
|
169 | - if (! empty($default_prices_params)) { |
|
170 | - if (empty($where_params)) { |
|
171 | - $where_params['OR'] = $default_prices_params; |
|
172 | - } else { |
|
173 | - $where_params = [ |
|
174 | - 'OR' => [ |
|
175 | - 'OR' => $default_prices_params, |
|
176 | - 'AND' => $where_params, |
|
177 | - ], |
|
178 | - ]; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - $where_params = apply_filters( |
|
183 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__price_where_params', |
|
184 | - $where_params, |
|
185 | - $this->source, |
|
186 | - $this->args |
|
187 | - ); |
|
188 | - |
|
189 | - $query_args[] = $where_params; |
|
190 | - |
|
191 | - /** |
|
192 | - * Return the $query_args |
|
193 | - */ |
|
194 | - return apply_filters( |
|
195 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__price_query_args', |
|
196 | - $query_args, |
|
197 | - $this->source, |
|
198 | - $this->args |
|
199 | - ); |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
205 | - * friendly keys. |
|
206 | - * |
|
207 | - * @param array $where_args |
|
208 | - * @return array |
|
209 | - */ |
|
210 | - public function sanitizeInputFields(array $where_args): array |
|
211 | - { |
|
212 | - $arg_mapping = [ |
|
213 | - 'in' => 'PRC_ID', |
|
214 | - 'idIn' => 'PRC_ID', |
|
215 | - 'isDefault' => 'PRC_is_default', |
|
216 | - 'event' => 'Event.EVT_ID', |
|
217 | - 'eventId' => 'Event.EVT_ID', // priority. |
|
218 | - 'ticket' => 'Ticket.TKT_ID', |
|
219 | - 'ticketIn' => 'Ticket.TKT_ID', |
|
220 | - 'ticketIdIn' => 'Ticket.TKT_ID', |
|
221 | - 'ticketId' => 'Ticket.TKT_ID', // priority. |
|
222 | - 'priceType' => 'Price_Type.PRT_ID', |
|
223 | - 'priceTypeIn' => 'Price_Type.PRT_ID', |
|
224 | - 'priceTypeIdIn' => 'Price_Type.PRT_ID', |
|
225 | - 'priceTypeId' => 'Price_Type.PRT_ID', // priority. |
|
226 | - 'priceBaseType' => 'Price_Type.PBT_ID', |
|
227 | - 'priceBaseTypeIn' => 'Price_Type.PBT_ID', |
|
228 | - ]; |
|
229 | - return $this->sanitizeWhereArgsForInputFields( |
|
230 | - $where_args, |
|
231 | - $arg_mapping, |
|
232 | - ['in', 'event', 'ticket', 'ticketIn', 'priceType', 'priceTypeIn'] |
|
233 | - ); |
|
234 | - } |
|
20 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
21 | + public function get_loader_name(): string |
|
22 | + { |
|
23 | + return 'espresso_price'; |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * @return EEM_Price |
|
28 | + * @throws EE_Error |
|
29 | + * @throws InvalidArgumentException |
|
30 | + * @throws InvalidDataTypeException |
|
31 | + * @throws InvalidInterfaceException |
|
32 | + * @throws ReflectionException |
|
33 | + */ |
|
34 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
35 | + public function get_query(): EEM_Price |
|
36 | + { |
|
37 | + return EEM_Price::instance(); |
|
38 | + } |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Return an array of item IDs from the query |
|
43 | + * |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
47 | + public function get_ids(): array |
|
48 | + { |
|
49 | + $results = $this->query->get_col($this->query_args); |
|
50 | + |
|
51 | + return ! empty($results) ? $results : []; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
57 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
58 | + * handle batch resolution of the posts. |
|
59 | + * |
|
60 | + * @return array |
|
61 | + * @throws EE_Error |
|
62 | + * @throws InvalidArgumentException |
|
63 | + * @throws ReflectionException |
|
64 | + * @throws InvalidDataTypeException |
|
65 | + * @throws InvalidInterfaceException |
|
66 | + */ |
|
67 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
68 | + public function get_query_args(): array |
|
69 | + { |
|
70 | + $where_params = []; |
|
71 | + $query_args = []; |
|
72 | + |
|
73 | + $query_args['limit'] = $this->getLimit(); |
|
74 | + |
|
75 | + // Avoid multiple entries by join. |
|
76 | + $query_args['group_by'] = 'PRC_ID'; |
|
77 | + |
|
78 | + $query_args['default_where_conditions'] = 'minimum'; |
|
79 | + |
|
80 | + /** |
|
81 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
82 | + */ |
|
83 | + $input_fields = []; |
|
84 | + if (! empty($this->args['where'])) { |
|
85 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
86 | + |
|
87 | + // Use the proper operator. |
|
88 | + if (! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) { |
|
89 | + $input_fields['PRC_ID'] = ['in', $input_fields['PRC_ID']]; |
|
90 | + } |
|
91 | + if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
92 | + $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
93 | + } |
|
94 | + if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
95 | + $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']]; |
|
96 | + } |
|
97 | + if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
98 | + $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']]; |
|
99 | + } |
|
100 | + // if event ID is passed but not a ticket ID |
|
101 | + if (! isset($input_fields['Ticket.TKT_ID']) && isset($input_fields['Event.EVT_ID'])) { |
|
102 | + $event_id = $input_fields['Event.EVT_ID']; |
|
103 | + // Ensure that this doesn't go to the query. |
|
104 | + // After all there is no DB relation between event and price |
|
105 | + unset($input_fields['Event.EVT_ID']); |
|
106 | + // get all the datetimeIds of the event |
|
107 | + $event_datetime_ids = EEM_Datetime::instance()->get_col([ |
|
108 | + [ |
|
109 | + 'EVT_ID' => $event_id, |
|
110 | + ], |
|
111 | + 'default_where_conditions' => 'minimum' |
|
112 | + ]); |
|
113 | + // get all the related ticket Ids |
|
114 | + $ticket_ids = EEM_Ticket::instance()->get_col([ |
|
115 | + [ |
|
116 | + 'Datetime.DTT_ID' => ['IN', $event_datetime_ids], |
|
117 | + ], |
|
118 | + 'default_where_conditions' => 'minimum' |
|
119 | + ]); |
|
120 | + |
|
121 | + // add tickets relation to the query |
|
122 | + $input_fields['Ticket.TKT_ID'] = ['IN', $ticket_ids]; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
128 | + */ |
|
129 | + if ($this->source instanceof EE_Ticket) { |
|
130 | + $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Merge the input_fields with the default query_args |
|
135 | + */ |
|
136 | + if (! empty($input_fields)) { |
|
137 | + $where_params = array_merge($where_params, $input_fields); |
|
138 | + } |
|
139 | + |
|
140 | + [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID'); |
|
141 | + |
|
142 | + $default_prices_params = []; |
|
143 | + |
|
144 | + // If default ticket prices should be included. |
|
145 | + if (! empty($this->args['where']['includeDefaultTicketsPrices'])) { |
|
146 | + $default_ticket_ids = EEM_Ticket::instance()->get_col([ |
|
147 | + [ |
|
148 | + 'TKT_is_default' => 1, |
|
149 | + ], |
|
150 | + 'default_where_conditions' => 'minimum' |
|
151 | + ]); |
|
152 | + |
|
153 | + // if we have default tickets |
|
154 | + if (! empty($default_ticket_ids)) { |
|
155 | + $default_prices_params['OR'] = [ |
|
156 | + 'Ticket.TKT_ID' => ['IN', $default_ticket_ids], |
|
157 | + ]; |
|
158 | + } |
|
159 | + } |
|
160 | + |
|
161 | + // If default prices should be included. |
|
162 | + if (! empty($this->args['where']['includeDefaultPrices'])) { |
|
163 | + $default_prices_params['AND'] = [ |
|
164 | + 'PRC_deleted' => 0, |
|
165 | + 'PRC_is_default' => 1, |
|
166 | + ]; |
|
167 | + } |
|
168 | + |
|
169 | + if (! empty($default_prices_params)) { |
|
170 | + if (empty($where_params)) { |
|
171 | + $where_params['OR'] = $default_prices_params; |
|
172 | + } else { |
|
173 | + $where_params = [ |
|
174 | + 'OR' => [ |
|
175 | + 'OR' => $default_prices_params, |
|
176 | + 'AND' => $where_params, |
|
177 | + ], |
|
178 | + ]; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + $where_params = apply_filters( |
|
183 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__price_where_params', |
|
184 | + $where_params, |
|
185 | + $this->source, |
|
186 | + $this->args |
|
187 | + ); |
|
188 | + |
|
189 | + $query_args[] = $where_params; |
|
190 | + |
|
191 | + /** |
|
192 | + * Return the $query_args |
|
193 | + */ |
|
194 | + return apply_filters( |
|
195 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__price_query_args', |
|
196 | + $query_args, |
|
197 | + $this->source, |
|
198 | + $this->args |
|
199 | + ); |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
205 | + * friendly keys. |
|
206 | + * |
|
207 | + * @param array $where_args |
|
208 | + * @return array |
|
209 | + */ |
|
210 | + public function sanitizeInputFields(array $where_args): array |
|
211 | + { |
|
212 | + $arg_mapping = [ |
|
213 | + 'in' => 'PRC_ID', |
|
214 | + 'idIn' => 'PRC_ID', |
|
215 | + 'isDefault' => 'PRC_is_default', |
|
216 | + 'event' => 'Event.EVT_ID', |
|
217 | + 'eventId' => 'Event.EVT_ID', // priority. |
|
218 | + 'ticket' => 'Ticket.TKT_ID', |
|
219 | + 'ticketIn' => 'Ticket.TKT_ID', |
|
220 | + 'ticketIdIn' => 'Ticket.TKT_ID', |
|
221 | + 'ticketId' => 'Ticket.TKT_ID', // priority. |
|
222 | + 'priceType' => 'Price_Type.PRT_ID', |
|
223 | + 'priceTypeIn' => 'Price_Type.PRT_ID', |
|
224 | + 'priceTypeIdIn' => 'Price_Type.PRT_ID', |
|
225 | + 'priceTypeId' => 'Price_Type.PRT_ID', // priority. |
|
226 | + 'priceBaseType' => 'Price_Type.PBT_ID', |
|
227 | + 'priceBaseTypeIn' => 'Price_Type.PBT_ID', |
|
228 | + ]; |
|
229 | + return $this->sanitizeWhereArgsForInputFields( |
|
230 | + $where_args, |
|
231 | + $arg_mapping, |
|
232 | + ['in', 'event', 'ticket', 'ticketIn', 'priceType', 'priceTypeIn'] |
|
233 | + ); |
|
234 | + } |
|
235 | 235 | } |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
79 | 79 | */ |
80 | 80 | $input_fields = []; |
81 | - if (! empty($this->args['where'])) { |
|
81 | + if ( ! empty($this->args['where'])) { |
|
82 | 82 | $input_fields = $this->sanitizeInputFields($this->args['where']); |
83 | 83 | |
84 | 84 | // Use the proper operator. |
85 | - if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) { |
|
85 | + if ( ! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) { |
|
86 | 86 | $input_fields['Datetime.DTT_ID'] = ['IN', $input_fields['Datetime.DTT_ID']]; |
87 | 87 | } |
88 | - if (! empty($input_fields['Datetime.EVT_ID']) && is_array($input_fields['Datetime.EVT_ID'])) { |
|
88 | + if ( ! empty($input_fields['Datetime.EVT_ID']) && is_array($input_fields['Datetime.EVT_ID'])) { |
|
89 | 89 | $input_fields['Datetime.EVT_ID'] = ['IN', $input_fields['Datetime.EVT_ID']]; |
90 | 90 | } |
91 | 91 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | /** |
101 | 101 | * Merge the input_fields with the default query_args |
102 | 102 | */ |
103 | - if (! empty($input_fields)) { |
|
103 | + if ( ! empty($input_fields)) { |
|
104 | 104 | $where_params = array_merge($where_params, $input_fields); |
105 | 105 | } |
106 | 106 | |
@@ -108,16 +108,16 @@ discard block |
||
108 | 108 | |
109 | 109 | $search = isset($this->args['where']) ? $this->getSearchKeywords($this->args['where']) : ''; |
110 | 110 | |
111 | - if (! empty($search)) { |
|
111 | + if ( ! empty($search)) { |
|
112 | 112 | // use OR operator to search in any of the fields |
113 | 113 | $where_params['OR'] = array( |
114 | - 'TKT_name' => array('LIKE', '%' . $search . '%'), |
|
115 | - 'TKT_description' => array('LIKE', '%' . $search . '%'), |
|
114 | + 'TKT_name' => array('LIKE', '%'.$search.'%'), |
|
115 | + 'TKT_description' => array('LIKE', '%'.$search.'%'), |
|
116 | 116 | ); |
117 | 117 | } |
118 | 118 | |
119 | 119 | // If default tickets should be included. |
120 | - if (! empty($this->args['where']['includeDefaultTickets'])) { |
|
120 | + if ( ! empty($this->args['where']['includeDefaultTickets'])) { |
|
121 | 121 | /** |
122 | 122 | * We need to get each ticket that |
123 | 123 | * - satisfies $where_params above |
@@ -15,178 +15,178 @@ |
||
15 | 15 | */ |
16 | 16 | class TicketConnectionResolver extends AbstractConnectionResolver |
17 | 17 | { |
18 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
19 | - public function get_loader_name(): string |
|
20 | - { |
|
21 | - return 'espresso_ticket'; |
|
22 | - } |
|
23 | - |
|
24 | - /** |
|
25 | - * @return EEM_Ticket |
|
26 | - * @throws EE_Error |
|
27 | - * @throws InvalidArgumentException |
|
28 | - * @throws InvalidDataTypeException |
|
29 | - * @throws InvalidInterfaceException |
|
30 | - * @throws ReflectionException |
|
31 | - */ |
|
32 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
33 | - public function get_query(): EEM_Ticket |
|
34 | - { |
|
35 | - return EEM_Ticket::instance(); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Return an array of item IDs from the query |
|
41 | - * |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
45 | - public function get_ids(): array |
|
46 | - { |
|
47 | - $results = $this->query->get_col($this->query_args); |
|
48 | - |
|
49 | - return ! empty($results) ? $results : []; |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
55 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
56 | - * handle batch resolution of the posts. |
|
57 | - * |
|
58 | - * @return array |
|
59 | - * @throws EE_Error |
|
60 | - * @throws InvalidArgumentException |
|
61 | - * @throws ReflectionException |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - */ |
|
65 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
66 | - public function get_query_args(): array |
|
67 | - { |
|
68 | - $where_params = ['TKT_deleted' => ['IN', [true, false]]]; |
|
69 | - $query_args = []; |
|
70 | - |
|
71 | - $query_args['limit'] = $this->getLimit(); |
|
72 | - |
|
73 | - // Avoid multiple entries by join. |
|
74 | - $query_args['group_by'] = 'TKT_ID'; |
|
75 | - |
|
76 | - $query_args['default_where_conditions'] = 'minimum'; |
|
77 | - |
|
78 | - /** |
|
79 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
80 | - */ |
|
81 | - $input_fields = []; |
|
82 | - if (! empty($this->args['where'])) { |
|
83 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
84 | - |
|
85 | - // Use the proper operator. |
|
86 | - if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) { |
|
87 | - $input_fields['Datetime.DTT_ID'] = ['IN', $input_fields['Datetime.DTT_ID']]; |
|
88 | - } |
|
89 | - if (! empty($input_fields['Datetime.EVT_ID']) && is_array($input_fields['Datetime.EVT_ID'])) { |
|
90 | - $input_fields['Datetime.EVT_ID'] = ['IN', $input_fields['Datetime.EVT_ID']]; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
96 | - */ |
|
97 | - if ($this->source instanceof EE_Datetime) { |
|
98 | - $where_params['Datetime.DTT_ID'] = $this->source->ID(); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Merge the input_fields with the default query_args |
|
103 | - */ |
|
104 | - if (! empty($input_fields)) { |
|
105 | - $where_params = array_merge($where_params, $input_fields); |
|
106 | - } |
|
107 | - |
|
108 | - [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'TKT_ID'); |
|
109 | - |
|
110 | - $search = isset($this->args['where']) ? $this->getSearchKeywords($this->args['where']) : ''; |
|
111 | - |
|
112 | - if (! empty($search)) { |
|
113 | - // use OR operator to search in any of the fields |
|
114 | - $where_params['OR'] = array( |
|
115 | - 'TKT_name' => array('LIKE', '%' . $search . '%'), |
|
116 | - 'TKT_description' => array('LIKE', '%' . $search . '%'), |
|
117 | - ); |
|
118 | - } |
|
119 | - |
|
120 | - // If default tickets should be included. |
|
121 | - if (! empty($this->args['where']['includeDefaultTickets'])) { |
|
122 | - /** |
|
123 | - * We need to get each ticket that |
|
124 | - * - satisfies $where_params above |
|
125 | - * OR |
|
126 | - * - it's a default ticket |
|
127 | - */ |
|
128 | - $where_params = [ |
|
129 | - 'OR' => [ |
|
130 | - // use extra OR instead of AND to avoid it getting overridden |
|
131 | - 'OR' => [ |
|
132 | - 'AND' => [ |
|
133 | - 'TKT_deleted' => ['IN', [true, false]], |
|
134 | - 'TKT_is_default' => 1, |
|
135 | - ] |
|
136 | - ], |
|
137 | - 'AND' => $where_params, |
|
138 | - ], |
|
139 | - ]; |
|
140 | - } |
|
141 | - |
|
142 | - $where_params = apply_filters( |
|
143 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__ticket_where_params', |
|
144 | - $where_params, |
|
145 | - $this->source, |
|
146 | - $this->args |
|
147 | - ); |
|
148 | - |
|
149 | - $query_args[] = $where_params; |
|
150 | - |
|
151 | - /** |
|
152 | - * Return the $query_args |
|
153 | - */ |
|
154 | - return apply_filters( |
|
155 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__ticket_query_args', |
|
156 | - $query_args, |
|
157 | - $this->source, |
|
158 | - $this->args |
|
159 | - ); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
165 | - * friendly keys. |
|
166 | - * |
|
167 | - * @param array $where_args |
|
168 | - * @return array |
|
169 | - */ |
|
170 | - public function sanitizeInputFields(array $where_args): array |
|
171 | - { |
|
172 | - $arg_mapping = [ |
|
173 | - 'event' => 'Datetime.EVT_ID', |
|
174 | - 'eventIn' => 'Datetime.EVT_ID', |
|
175 | - 'eventIdIn' => 'Datetime.EVT_ID', |
|
176 | - 'eventId' => 'Datetime.EVT_ID', // priority. |
|
177 | - 'datetime' => 'Datetime.DTT_ID', |
|
178 | - 'datetimeIn' => 'Datetime.DTT_ID', |
|
179 | - 'datetimeIdIn' => 'Datetime.DTT_ID', |
|
180 | - 'datetimeId' => 'Datetime.DTT_ID', // priority. |
|
181 | - 'isDefault' => 'TKT_is_default', |
|
182 | - 'isRequired' => 'TKT_required', |
|
183 | - 'isTaxable' => 'TKT_taxable', |
|
184 | - 'isTrashed' => 'TKT_deleted', |
|
185 | - ]; |
|
186 | - return $this->sanitizeWhereArgsForInputFields( |
|
187 | - $where_args, |
|
188 | - $arg_mapping, |
|
189 | - ['datetime', 'datetimeIn', 'event', 'eventIn'] |
|
190 | - ); |
|
191 | - } |
|
18 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
19 | + public function get_loader_name(): string |
|
20 | + { |
|
21 | + return 'espresso_ticket'; |
|
22 | + } |
|
23 | + |
|
24 | + /** |
|
25 | + * @return EEM_Ticket |
|
26 | + * @throws EE_Error |
|
27 | + * @throws InvalidArgumentException |
|
28 | + * @throws InvalidDataTypeException |
|
29 | + * @throws InvalidInterfaceException |
|
30 | + * @throws ReflectionException |
|
31 | + */ |
|
32 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
33 | + public function get_query(): EEM_Ticket |
|
34 | + { |
|
35 | + return EEM_Ticket::instance(); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Return an array of item IDs from the query |
|
41 | + * |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
45 | + public function get_ids(): array |
|
46 | + { |
|
47 | + $results = $this->query->get_col($this->query_args); |
|
48 | + |
|
49 | + return ! empty($results) ? $results : []; |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
55 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
56 | + * handle batch resolution of the posts. |
|
57 | + * |
|
58 | + * @return array |
|
59 | + * @throws EE_Error |
|
60 | + * @throws InvalidArgumentException |
|
61 | + * @throws ReflectionException |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + */ |
|
65 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
66 | + public function get_query_args(): array |
|
67 | + { |
|
68 | + $where_params = ['TKT_deleted' => ['IN', [true, false]]]; |
|
69 | + $query_args = []; |
|
70 | + |
|
71 | + $query_args['limit'] = $this->getLimit(); |
|
72 | + |
|
73 | + // Avoid multiple entries by join. |
|
74 | + $query_args['group_by'] = 'TKT_ID'; |
|
75 | + |
|
76 | + $query_args['default_where_conditions'] = 'minimum'; |
|
77 | + |
|
78 | + /** |
|
79 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
80 | + */ |
|
81 | + $input_fields = []; |
|
82 | + if (! empty($this->args['where'])) { |
|
83 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
84 | + |
|
85 | + // Use the proper operator. |
|
86 | + if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) { |
|
87 | + $input_fields['Datetime.DTT_ID'] = ['IN', $input_fields['Datetime.DTT_ID']]; |
|
88 | + } |
|
89 | + if (! empty($input_fields['Datetime.EVT_ID']) && is_array($input_fields['Datetime.EVT_ID'])) { |
|
90 | + $input_fields['Datetime.EVT_ID'] = ['IN', $input_fields['Datetime.EVT_ID']]; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
96 | + */ |
|
97 | + if ($this->source instanceof EE_Datetime) { |
|
98 | + $where_params['Datetime.DTT_ID'] = $this->source->ID(); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Merge the input_fields with the default query_args |
|
103 | + */ |
|
104 | + if (! empty($input_fields)) { |
|
105 | + $where_params = array_merge($where_params, $input_fields); |
|
106 | + } |
|
107 | + |
|
108 | + [$query_args, $where_params] = $this->mapOrderbyInputArgs($query_args, $where_params, 'TKT_ID'); |
|
109 | + |
|
110 | + $search = isset($this->args['where']) ? $this->getSearchKeywords($this->args['where']) : ''; |
|
111 | + |
|
112 | + if (! empty($search)) { |
|
113 | + // use OR operator to search in any of the fields |
|
114 | + $where_params['OR'] = array( |
|
115 | + 'TKT_name' => array('LIKE', '%' . $search . '%'), |
|
116 | + 'TKT_description' => array('LIKE', '%' . $search . '%'), |
|
117 | + ); |
|
118 | + } |
|
119 | + |
|
120 | + // If default tickets should be included. |
|
121 | + if (! empty($this->args['where']['includeDefaultTickets'])) { |
|
122 | + /** |
|
123 | + * We need to get each ticket that |
|
124 | + * - satisfies $where_params above |
|
125 | + * OR |
|
126 | + * - it's a default ticket |
|
127 | + */ |
|
128 | + $where_params = [ |
|
129 | + 'OR' => [ |
|
130 | + // use extra OR instead of AND to avoid it getting overridden |
|
131 | + 'OR' => [ |
|
132 | + 'AND' => [ |
|
133 | + 'TKT_deleted' => ['IN', [true, false]], |
|
134 | + 'TKT_is_default' => 1, |
|
135 | + ] |
|
136 | + ], |
|
137 | + 'AND' => $where_params, |
|
138 | + ], |
|
139 | + ]; |
|
140 | + } |
|
141 | + |
|
142 | + $where_params = apply_filters( |
|
143 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__ticket_where_params', |
|
144 | + $where_params, |
|
145 | + $this->source, |
|
146 | + $this->args |
|
147 | + ); |
|
148 | + |
|
149 | + $query_args[] = $where_params; |
|
150 | + |
|
151 | + /** |
|
152 | + * Return the $query_args |
|
153 | + */ |
|
154 | + return apply_filters( |
|
155 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__ticket_query_args', |
|
156 | + $query_args, |
|
157 | + $this->source, |
|
158 | + $this->args |
|
159 | + ); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
165 | + * friendly keys. |
|
166 | + * |
|
167 | + * @param array $where_args |
|
168 | + * @return array |
|
169 | + */ |
|
170 | + public function sanitizeInputFields(array $where_args): array |
|
171 | + { |
|
172 | + $arg_mapping = [ |
|
173 | + 'event' => 'Datetime.EVT_ID', |
|
174 | + 'eventIn' => 'Datetime.EVT_ID', |
|
175 | + 'eventIdIn' => 'Datetime.EVT_ID', |
|
176 | + 'eventId' => 'Datetime.EVT_ID', // priority. |
|
177 | + 'datetime' => 'Datetime.DTT_ID', |
|
178 | + 'datetimeIn' => 'Datetime.DTT_ID', |
|
179 | + 'datetimeIdIn' => 'Datetime.DTT_ID', |
|
180 | + 'datetimeId' => 'Datetime.DTT_ID', // priority. |
|
181 | + 'isDefault' => 'TKT_is_default', |
|
182 | + 'isRequired' => 'TKT_required', |
|
183 | + 'isTaxable' => 'TKT_taxable', |
|
184 | + 'isTrashed' => 'TKT_deleted', |
|
185 | + ]; |
|
186 | + return $this->sanitizeWhereArgsForInputFields( |
|
187 | + $where_args, |
|
188 | + $arg_mapping, |
|
189 | + ['datetime', 'datetimeIn', 'event', 'eventIn'] |
|
190 | + ); |
|
191 | + } |
|
192 | 192 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | */ |
68 | 68 | public function create(EE_Base_Class $entity): array |
69 | 69 | { |
70 | - if (! $entity instanceof EE_Ticket) { |
|
70 | + if ( ! $entity instanceof EE_Ticket) { |
|
71 | 71 | throw new InvalidEntityException($entity, 'EE_Ticket'); |
72 | 72 | } |
73 | 73 | $is_free = true; |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | $has_base_price, |
92 | 92 | $is_free |
93 | 93 | ); |
94 | - if (! $has_base_price) { |
|
94 | + if ( ! $has_base_price) { |
|
95 | 95 | $new_base_price = $this->createNewBasePrice($entity); |
96 | - $this->new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
96 | + $this->new_prices[$new_base_price->ID()] = $new_base_price; |
|
97 | 97 | } |
98 | 98 | $this->applyTaxes($entity, $is_free); |
99 | 99 | $ticket_total = $entity->get_ticket_total_with_taxes(true); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | private function applyTaxes(EE_Ticket $ticket, bool $is_free) |
115 | 115 | { |
116 | - if (! $is_free && $ticket->taxable() && ! empty($this->taxes)) { |
|
116 | + if ( ! $is_free && $ticket->taxable() && ! empty($this->taxes)) { |
|
117 | 117 | foreach ($this->taxes as $tax) { |
118 | 118 | // assign taxes but don't duplicate them because they operate globally |
119 | 119 | $ticket->set_taxable(true); |
@@ -162,12 +162,12 @@ discard block |
||
162 | 162 | $is_base_price = $default_price_clone->is_base_price(); |
163 | 163 | // add this price to ticket if it is a regular price modifier, ie: NOT a base price, |
164 | 164 | // OR if it IS a base price but this ticket does NOT already have a base price |
165 | - if (! $is_base_price || ! $has_base_price) { |
|
165 | + if ( ! $is_base_price || ! $has_base_price) { |
|
166 | 166 | $default_price_clone->set('PRC_ID', null); |
167 | 167 | $default_price_clone->set('PRC_is_default', false); |
168 | 168 | $default_price_clone->save(); |
169 | 169 | $default_price_clone->_add_relation_to($ticket, 'Ticket'); |
170 | - $this->new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
170 | + $this->new_prices[$default_price_clone->ID()] = $default_price_clone; |
|
171 | 171 | // then recheck that a base price has been set so that we don't add another one |
172 | 172 | $has_base_price = $is_base_price ? true : $has_base_price; |
173 | 173 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | ], |
193 | 193 | ] |
194 | 194 | ); |
195 | - if (! $base_price_type instanceof EE_Price_Type) { |
|
195 | + if ( ! $base_price_type instanceof EE_Price_Type) { |
|
196 | 196 | throw new RuntimeException( |
197 | 197 | esc_html__( |
198 | 198 | 'A valid base price type could not be retrieved from the database.', |
@@ -219,15 +219,15 @@ discard block |
||
219 | 219 | $default_prices = []; |
220 | 220 | if (is_array($prices)) { |
221 | 221 | foreach ($prices as $key => $price) { |
222 | - if (! $price instanceof EE_Price) { |
|
222 | + if ( ! $price instanceof EE_Price) { |
|
223 | 223 | throw new InvalidEntityException($price, 'EE_Price'); |
224 | 224 | } |
225 | 225 | // grab any taxes but don't do anything just yet |
226 | 226 | if ($price->is_tax()) { |
227 | - $this->taxes[ $price->ID() ] = $price; |
|
227 | + $this->taxes[$price->ID()] = $price; |
|
228 | 228 | continue; |
229 | 229 | } |
230 | - $default_prices[ $price->ID() ] = $price; |
|
230 | + $default_prices[$price->ID()] = $price; |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | return $default_prices; |
@@ -24,223 +24,223 @@ |
||
24 | 24 | */ |
25 | 25 | class DefaultPrices implements DefaultEntityGeneratorInterface |
26 | 26 | { |
27 | - /** |
|
28 | - * @var EEM_Price |
|
29 | - */ |
|
30 | - protected $price_model; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EEM_Price_Type |
|
34 | - */ |
|
35 | - protected $price_type_model; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Price[] |
|
39 | - */ |
|
40 | - protected $new_prices = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Price[] |
|
44 | - */ |
|
45 | - protected $taxes = []; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param EEM_Price $price_model |
|
50 | - * @param EEM_Price_Type $price_type_model |
|
51 | - */ |
|
52 | - public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model) |
|
53 | - { |
|
54 | - $this->price_model = $price_model; |
|
55 | - $this->price_type_model = $price_type_model; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @param EE_Ticket|EE_Base_Class $entity |
|
61 | - * @return EE_Price[] |
|
62 | - * @throws EE_Error |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - * @throws ReflectionException |
|
65 | - * @since 5.0.0.p |
|
66 | - */ |
|
67 | - public function create(EE_Base_Class $entity): array |
|
68 | - { |
|
69 | - if (! $entity instanceof EE_Ticket) { |
|
70 | - throw new InvalidEntityException($entity, 'EE_Ticket'); |
|
71 | - } |
|
72 | - $is_free = true; |
|
73 | - $has_base_price = false; |
|
74 | - $remove_existing_relations = true; |
|
75 | - // first, let's get all of the default taxes for the site |
|
76 | - $this->taxes = $this->price_model->getAllDefaultTaxes(); |
|
77 | - // then separate taxes from the other prices for the existing default ticket prices |
|
78 | - $default_prices = $this->separateTaxesFromOtherPrices($entity->prices()); |
|
79 | - // but if that's empty, then let's get the default global prices |
|
80 | - if (empty($default_prices)) { |
|
81 | - $default_global_prices = $this->price_model->get_all_default_prices(); |
|
82 | - $default_prices = $this->separateTaxesFromOtherPrices($default_global_prices); |
|
83 | - $remove_existing_relations = false; |
|
84 | - } |
|
85 | - // then clone and apply all of the default prices |
|
86 | - [$has_base_price, $is_free] = $this->cloneDefaultPrices( |
|
87 | - $entity, |
|
88 | - $default_prices, |
|
89 | - $remove_existing_relations, |
|
90 | - $has_base_price, |
|
91 | - $is_free |
|
92 | - ); |
|
93 | - if (! $has_base_price) { |
|
94 | - $new_base_price = $this->createNewBasePrice($entity); |
|
95 | - $this->new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
96 | - } |
|
97 | - $this->applyTaxes($entity, $is_free); |
|
98 | - $ticket_total = $entity->get_ticket_total_with_taxes(true); |
|
99 | - if ($ticket_total !== $entity->ticket_price()) { |
|
100 | - $entity->set_price($ticket_total); |
|
101 | - $entity->save(); |
|
102 | - } |
|
103 | - return $this->new_prices; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param EE_Ticket $ticket |
|
109 | - * @param bool $is_free |
|
110 | - * @throws EE_Error |
|
111 | - * @throws ReflectionException |
|
112 | - */ |
|
113 | - private function applyTaxes(EE_Ticket $ticket, bool $is_free) |
|
114 | - { |
|
115 | - if (! $is_free && $ticket->taxable() && ! empty($this->taxes)) { |
|
116 | - foreach ($this->taxes as $tax) { |
|
117 | - // assign taxes but don't duplicate them because they operate globally |
|
118 | - $ticket->set_taxable(true); |
|
119 | - $tax->_add_relation_to($ticket, 'Ticket'); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param EE_Ticket $ticket |
|
127 | - * @param EE_Price[] $default_prices |
|
128 | - * @param bool $remove_existing_relations |
|
129 | - * @param bool $has_base_price |
|
130 | - * @param bool $is_free |
|
131 | - * @return bool[] |
|
132 | - * @throws EE_Error |
|
133 | - * @throws ReflectionException |
|
134 | - */ |
|
135 | - private function cloneDefaultPrices( |
|
136 | - EE_Ticket $ticket, |
|
137 | - array $default_prices, |
|
138 | - bool $remove_existing_relations, |
|
139 | - bool $has_base_price, |
|
140 | - bool $is_free |
|
141 | - ): array { |
|
142 | - foreach ($default_prices as $default_price) { |
|
143 | - // duplicate the default price so that it does not get mutated |
|
144 | - $default_price_clone = clone $default_price; |
|
145 | - if ($remove_existing_relations) { |
|
146 | - $ticket->_remove_relation_to($default_price, 'Price'); |
|
147 | - } |
|
148 | - if ( |
|
149 | - ( |
|
150 | - // has non-zero base price |
|
151 | - $default_price_clone->is_base_price() |
|
152 | - && $default_price_clone->amount() > 0 |
|
153 | - ) |
|
154 | - || ( |
|
155 | - // or has fixed amount surcharge |
|
156 | - $default_price_clone->is_surcharge() |
|
157 | - && ! $default_price_clone->is_percent() |
|
158 | - ) |
|
159 | - ) { |
|
160 | - $is_free = false; |
|
161 | - } |
|
162 | - $is_base_price = $default_price_clone->is_base_price(); |
|
163 | - // add this price to ticket if it is a regular price modifier, ie: NOT a base price, |
|
164 | - // OR if it IS a base price but this ticket does NOT already have a base price |
|
165 | - if (! $is_base_price || ! $has_base_price) { |
|
166 | - $default_price_clone->set('PRC_ID', null); |
|
167 | - $default_price_clone->set('PRC_is_default', false); |
|
168 | - |
|
169 | - $order = $default_price_clone->get('PRC_order'); |
|
170 | - |
|
171 | - // enforce base price order to be 1 and 5 if the order is not set for a modifier |
|
172 | - $order = $is_base_price ? 1 : $order; |
|
173 | - $order = $order ?? 5; |
|
174 | - |
|
175 | - $default_price_clone->set('PRC_order', $order); |
|
176 | - |
|
177 | - $default_price_clone->save(); |
|
178 | - $default_price_clone->_add_relation_to($ticket, 'Ticket'); |
|
179 | - $this->new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
180 | - // then recheck that a base price has been set so that we don't add another one |
|
181 | - $has_base_price = $is_base_price ? true : $has_base_price; |
|
182 | - } |
|
183 | - } |
|
184 | - return [$has_base_price, $is_free]; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * @param EE_Ticket $ticket |
|
190 | - * @return EE_Price |
|
191 | - * @throws EE_Error |
|
192 | - * @throws ReflectionException |
|
193 | - */ |
|
194 | - private function createNewBasePrice(EE_Ticket $ticket): EE_Price |
|
195 | - { |
|
196 | - $new_base_price = $this->price_model->get_new_price(); |
|
197 | - $base_price_type = $this->price_type_model->get_one( |
|
198 | - [ |
|
199 | - [ |
|
200 | - 'PBT_ID' => EEM_Price_Type::base_type_base_price, |
|
201 | - ], |
|
202 | - ] |
|
203 | - ); |
|
204 | - if (! $base_price_type instanceof EE_Price_Type) { |
|
205 | - throw new RuntimeException( |
|
206 | - esc_html__( |
|
207 | - 'A valid base price type could not be retrieved from the database.', |
|
208 | - 'event_espresso' |
|
209 | - ) |
|
210 | - ); |
|
211 | - } |
|
212 | - $new_base_price->set('PRT_ID', $base_price_type->ID()); |
|
213 | - // set base price order to 1 |
|
214 | - $new_base_price->set('PRC_order', 1); |
|
215 | - $new_base_price->set('PRC_is_default', false); |
|
216 | - $new_base_price->save(); |
|
217 | - $new_base_price->_add_relation_to($ticket, 'Ticket'); |
|
218 | - return $new_base_price; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param array $prices |
|
224 | - * @return array |
|
225 | - * @throws EE_Error |
|
226 | - * @throws ReflectionException |
|
227 | - */ |
|
228 | - private function separateTaxesFromOtherPrices(array $prices = []): array |
|
229 | - { |
|
230 | - $default_prices = []; |
|
231 | - if (is_array($prices)) { |
|
232 | - foreach ($prices as $key => $price) { |
|
233 | - if (! $price instanceof EE_Price) { |
|
234 | - throw new InvalidEntityException($price, 'EE_Price'); |
|
235 | - } |
|
236 | - // grab any taxes but don't do anything just yet |
|
237 | - if ($price->is_tax()) { |
|
238 | - $this->taxes[ $price->ID() ] = $price; |
|
239 | - continue; |
|
240 | - } |
|
241 | - $default_prices[ $price->ID() ] = $price; |
|
242 | - } |
|
243 | - } |
|
244 | - return $default_prices; |
|
245 | - } |
|
27 | + /** |
|
28 | + * @var EEM_Price |
|
29 | + */ |
|
30 | + protected $price_model; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EEM_Price_Type |
|
34 | + */ |
|
35 | + protected $price_type_model; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Price[] |
|
39 | + */ |
|
40 | + protected $new_prices = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Price[] |
|
44 | + */ |
|
45 | + protected $taxes = []; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param EEM_Price $price_model |
|
50 | + * @param EEM_Price_Type $price_type_model |
|
51 | + */ |
|
52 | + public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model) |
|
53 | + { |
|
54 | + $this->price_model = $price_model; |
|
55 | + $this->price_type_model = $price_type_model; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @param EE_Ticket|EE_Base_Class $entity |
|
61 | + * @return EE_Price[] |
|
62 | + * @throws EE_Error |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + * @throws ReflectionException |
|
65 | + * @since 5.0.0.p |
|
66 | + */ |
|
67 | + public function create(EE_Base_Class $entity): array |
|
68 | + { |
|
69 | + if (! $entity instanceof EE_Ticket) { |
|
70 | + throw new InvalidEntityException($entity, 'EE_Ticket'); |
|
71 | + } |
|
72 | + $is_free = true; |
|
73 | + $has_base_price = false; |
|
74 | + $remove_existing_relations = true; |
|
75 | + // first, let's get all of the default taxes for the site |
|
76 | + $this->taxes = $this->price_model->getAllDefaultTaxes(); |
|
77 | + // then separate taxes from the other prices for the existing default ticket prices |
|
78 | + $default_prices = $this->separateTaxesFromOtherPrices($entity->prices()); |
|
79 | + // but if that's empty, then let's get the default global prices |
|
80 | + if (empty($default_prices)) { |
|
81 | + $default_global_prices = $this->price_model->get_all_default_prices(); |
|
82 | + $default_prices = $this->separateTaxesFromOtherPrices($default_global_prices); |
|
83 | + $remove_existing_relations = false; |
|
84 | + } |
|
85 | + // then clone and apply all of the default prices |
|
86 | + [$has_base_price, $is_free] = $this->cloneDefaultPrices( |
|
87 | + $entity, |
|
88 | + $default_prices, |
|
89 | + $remove_existing_relations, |
|
90 | + $has_base_price, |
|
91 | + $is_free |
|
92 | + ); |
|
93 | + if (! $has_base_price) { |
|
94 | + $new_base_price = $this->createNewBasePrice($entity); |
|
95 | + $this->new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
96 | + } |
|
97 | + $this->applyTaxes($entity, $is_free); |
|
98 | + $ticket_total = $entity->get_ticket_total_with_taxes(true); |
|
99 | + if ($ticket_total !== $entity->ticket_price()) { |
|
100 | + $entity->set_price($ticket_total); |
|
101 | + $entity->save(); |
|
102 | + } |
|
103 | + return $this->new_prices; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param EE_Ticket $ticket |
|
109 | + * @param bool $is_free |
|
110 | + * @throws EE_Error |
|
111 | + * @throws ReflectionException |
|
112 | + */ |
|
113 | + private function applyTaxes(EE_Ticket $ticket, bool $is_free) |
|
114 | + { |
|
115 | + if (! $is_free && $ticket->taxable() && ! empty($this->taxes)) { |
|
116 | + foreach ($this->taxes as $tax) { |
|
117 | + // assign taxes but don't duplicate them because they operate globally |
|
118 | + $ticket->set_taxable(true); |
|
119 | + $tax->_add_relation_to($ticket, 'Ticket'); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param EE_Ticket $ticket |
|
127 | + * @param EE_Price[] $default_prices |
|
128 | + * @param bool $remove_existing_relations |
|
129 | + * @param bool $has_base_price |
|
130 | + * @param bool $is_free |
|
131 | + * @return bool[] |
|
132 | + * @throws EE_Error |
|
133 | + * @throws ReflectionException |
|
134 | + */ |
|
135 | + private function cloneDefaultPrices( |
|
136 | + EE_Ticket $ticket, |
|
137 | + array $default_prices, |
|
138 | + bool $remove_existing_relations, |
|
139 | + bool $has_base_price, |
|
140 | + bool $is_free |
|
141 | + ): array { |
|
142 | + foreach ($default_prices as $default_price) { |
|
143 | + // duplicate the default price so that it does not get mutated |
|
144 | + $default_price_clone = clone $default_price; |
|
145 | + if ($remove_existing_relations) { |
|
146 | + $ticket->_remove_relation_to($default_price, 'Price'); |
|
147 | + } |
|
148 | + if ( |
|
149 | + ( |
|
150 | + // has non-zero base price |
|
151 | + $default_price_clone->is_base_price() |
|
152 | + && $default_price_clone->amount() > 0 |
|
153 | + ) |
|
154 | + || ( |
|
155 | + // or has fixed amount surcharge |
|
156 | + $default_price_clone->is_surcharge() |
|
157 | + && ! $default_price_clone->is_percent() |
|
158 | + ) |
|
159 | + ) { |
|
160 | + $is_free = false; |
|
161 | + } |
|
162 | + $is_base_price = $default_price_clone->is_base_price(); |
|
163 | + // add this price to ticket if it is a regular price modifier, ie: NOT a base price, |
|
164 | + // OR if it IS a base price but this ticket does NOT already have a base price |
|
165 | + if (! $is_base_price || ! $has_base_price) { |
|
166 | + $default_price_clone->set('PRC_ID', null); |
|
167 | + $default_price_clone->set('PRC_is_default', false); |
|
168 | + |
|
169 | + $order = $default_price_clone->get('PRC_order'); |
|
170 | + |
|
171 | + // enforce base price order to be 1 and 5 if the order is not set for a modifier |
|
172 | + $order = $is_base_price ? 1 : $order; |
|
173 | + $order = $order ?? 5; |
|
174 | + |
|
175 | + $default_price_clone->set('PRC_order', $order); |
|
176 | + |
|
177 | + $default_price_clone->save(); |
|
178 | + $default_price_clone->_add_relation_to($ticket, 'Ticket'); |
|
179 | + $this->new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
180 | + // then recheck that a base price has been set so that we don't add another one |
|
181 | + $has_base_price = $is_base_price ? true : $has_base_price; |
|
182 | + } |
|
183 | + } |
|
184 | + return [$has_base_price, $is_free]; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * @param EE_Ticket $ticket |
|
190 | + * @return EE_Price |
|
191 | + * @throws EE_Error |
|
192 | + * @throws ReflectionException |
|
193 | + */ |
|
194 | + private function createNewBasePrice(EE_Ticket $ticket): EE_Price |
|
195 | + { |
|
196 | + $new_base_price = $this->price_model->get_new_price(); |
|
197 | + $base_price_type = $this->price_type_model->get_one( |
|
198 | + [ |
|
199 | + [ |
|
200 | + 'PBT_ID' => EEM_Price_Type::base_type_base_price, |
|
201 | + ], |
|
202 | + ] |
|
203 | + ); |
|
204 | + if (! $base_price_type instanceof EE_Price_Type) { |
|
205 | + throw new RuntimeException( |
|
206 | + esc_html__( |
|
207 | + 'A valid base price type could not be retrieved from the database.', |
|
208 | + 'event_espresso' |
|
209 | + ) |
|
210 | + ); |
|
211 | + } |
|
212 | + $new_base_price->set('PRT_ID', $base_price_type->ID()); |
|
213 | + // set base price order to 1 |
|
214 | + $new_base_price->set('PRC_order', 1); |
|
215 | + $new_base_price->set('PRC_is_default', false); |
|
216 | + $new_base_price->save(); |
|
217 | + $new_base_price->_add_relation_to($ticket, 'Ticket'); |
|
218 | + return $new_base_price; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param array $prices |
|
224 | + * @return array |
|
225 | + * @throws EE_Error |
|
226 | + * @throws ReflectionException |
|
227 | + */ |
|
228 | + private function separateTaxesFromOtherPrices(array $prices = []): array |
|
229 | + { |
|
230 | + $default_prices = []; |
|
231 | + if (is_array($prices)) { |
|
232 | + foreach ($prices as $key => $price) { |
|
233 | + if (! $price instanceof EE_Price) { |
|
234 | + throw new InvalidEntityException($price, 'EE_Price'); |
|
235 | + } |
|
236 | + // grab any taxes but don't do anything just yet |
|
237 | + if ($price->is_tax()) { |
|
238 | + $this->taxes[ $price->ID() ] = $price; |
|
239 | + continue; |
|
240 | + } |
|
241 | + $default_prices[ $price->ID() ] = $price; |
|
242 | + } |
|
243 | + } |
|
244 | + return $default_prices; |
|
245 | + } |
|
246 | 246 | } |
@@ -110,13 +110,13 @@ |
||
110 | 110 | 'WP_User' => new EE_Belongs_To_Relation(), |
111 | 111 | ]; |
112 | 112 | // this model is generally available for reading |
113 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
113 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = |
|
114 | 114 | new EE_Restriction_Generator_Public(); |
115 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
115 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
116 | 116 | new EE_Restriction_Generator_Reg_Form('QSG_system'); |
117 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
117 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
118 | 118 | new EE_Restriction_Generator_Reg_Form('QSG_system'); |
119 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
119 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
120 | 120 | new EE_Restriction_Generator_Reg_Form('QSG_system'); |
121 | 121 | |
122 | 122 | parent::__construct($timezone); |
@@ -9,133 +9,133 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Question_Group extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | - const system_personal = 1; |
|
12 | + const system_personal = 1; |
|
13 | 13 | |
14 | - const system_address = 2; |
|
14 | + const system_address = 2; |
|
15 | 15 | |
16 | 16 | |
17 | - protected static ?EEM_Question_Group $_instance = null; |
|
17 | + protected static ?EEM_Question_Group $_instance = null; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * EEM_Question_Group constructor. |
|
22 | - * |
|
23 | - * @param string|null $timezone |
|
24 | - * @throws EE_Error |
|
25 | - */ |
|
26 | - protected function __construct(?string $timezone = '') |
|
27 | - { |
|
28 | - $this->singular_item = esc_html__('Question Group', 'event_espresso'); |
|
29 | - $this->plural_item = esc_html__('Question Groups', 'event_espresso'); |
|
20 | + /** |
|
21 | + * EEM_Question_Group constructor. |
|
22 | + * |
|
23 | + * @param string|null $timezone |
|
24 | + * @throws EE_Error |
|
25 | + */ |
|
26 | + protected function __construct(?string $timezone = '') |
|
27 | + { |
|
28 | + $this->singular_item = esc_html__('Question Group', 'event_espresso'); |
|
29 | + $this->plural_item = esc_html__('Question Groups', 'event_espresso'); |
|
30 | 30 | |
31 | - $this->_tables = [ |
|
32 | - 'Question_Group' => new EE_Primary_Table('esp_question_group', 'QSG_ID'), |
|
33 | - ]; |
|
34 | - $this->_fields = [ |
|
35 | - 'Question_Group' => [ |
|
36 | - 'QSG_ID' => new EE_Primary_Key_Int_Field( |
|
37 | - 'QSG_ID', |
|
38 | - esc_html__('Question Group ID', 'event_espresso') |
|
39 | - ), |
|
40 | - 'QSG_deleted' => new EE_Trashed_Flag_Field( |
|
41 | - 'QSG_deleted', |
|
42 | - esc_html__('Flag indicating this question group was deleted', 'event_espresso'), |
|
43 | - false, |
|
44 | - false |
|
45 | - ), |
|
46 | - 'QSG_desc' => new EE_Post_Content_Field( |
|
47 | - 'QSG_desc', |
|
48 | - esc_html__('Description of Question Group', 'event_espresso'), |
|
49 | - true, |
|
50 | - '' |
|
51 | - ), |
|
52 | - 'QSG_identifier' => new EE_Plain_Text_Field( |
|
53 | - 'QSG_identifier', |
|
54 | - esc_html__('Text ID for question Group', 'event_espresso'), |
|
55 | - false, |
|
56 | - '' |
|
57 | - ), |
|
58 | - 'QSG_name' => new EE_Plain_Text_Field( |
|
59 | - 'QSG_name', |
|
60 | - esc_html__('Question Group Name', 'event_espresso'), |
|
61 | - false, |
|
62 | - '' |
|
63 | - ), |
|
64 | - 'QSG_order' => new EE_Integer_Field( |
|
65 | - 'QSG_order', |
|
66 | - esc_html__('Order in which to show the question group', 'event_espresso'), |
|
67 | - true, |
|
68 | - 0 |
|
69 | - ), |
|
70 | - 'QSG_show_group_desc' => new EE_Boolean_Field( |
|
71 | - 'QSG_show_group_desc', |
|
72 | - esc_html__( |
|
73 | - 'Flag indicating whether to show the group\s description on the registration page', |
|
74 | - 'event_espresso' |
|
75 | - ), |
|
76 | - false, |
|
77 | - false |
|
78 | - ), |
|
79 | - 'QSG_show_group_name' => new EE_Boolean_Field( |
|
80 | - 'QSG_show_group_name', |
|
81 | - esc_html__( |
|
82 | - 'Flag indicating whether to show the group\'s name on the registration page', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - false, |
|
86 | - true |
|
87 | - ), |
|
88 | - 'QSG_system' => new EE_Integer_Field( |
|
89 | - 'QSG_system', |
|
90 | - esc_html__( |
|
91 | - 'Indicate IF this is a system group and if it is what system group it corresponds to.', |
|
92 | - 'event_espresso' |
|
93 | - ), |
|
94 | - false, |
|
95 | - 0 |
|
96 | - ), |
|
97 | - 'QSG_wp_user' => new EE_WP_User_Field( |
|
98 | - 'QSG_wp_user', |
|
99 | - esc_html__('Question Group Creator ID', 'event_espresso'), |
|
100 | - false |
|
101 | - ), |
|
102 | - ], |
|
103 | - ]; |
|
104 | - $this->_model_relations = [ |
|
105 | - 'Event' => new EE_HABTM_Relation('Event_Question_Group'), |
|
106 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
107 | - 'Question' => new EE_HABTM_Relation('Question_Group_Question'), |
|
108 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
109 | - ]; |
|
110 | - // this model is generally available for reading |
|
111 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
112 | - new EE_Restriction_Generator_Public(); |
|
113 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
114 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
115 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
116 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
117 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
118 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
31 | + $this->_tables = [ |
|
32 | + 'Question_Group' => new EE_Primary_Table('esp_question_group', 'QSG_ID'), |
|
33 | + ]; |
|
34 | + $this->_fields = [ |
|
35 | + 'Question_Group' => [ |
|
36 | + 'QSG_ID' => new EE_Primary_Key_Int_Field( |
|
37 | + 'QSG_ID', |
|
38 | + esc_html__('Question Group ID', 'event_espresso') |
|
39 | + ), |
|
40 | + 'QSG_deleted' => new EE_Trashed_Flag_Field( |
|
41 | + 'QSG_deleted', |
|
42 | + esc_html__('Flag indicating this question group was deleted', 'event_espresso'), |
|
43 | + false, |
|
44 | + false |
|
45 | + ), |
|
46 | + 'QSG_desc' => new EE_Post_Content_Field( |
|
47 | + 'QSG_desc', |
|
48 | + esc_html__('Description of Question Group', 'event_espresso'), |
|
49 | + true, |
|
50 | + '' |
|
51 | + ), |
|
52 | + 'QSG_identifier' => new EE_Plain_Text_Field( |
|
53 | + 'QSG_identifier', |
|
54 | + esc_html__('Text ID for question Group', 'event_espresso'), |
|
55 | + false, |
|
56 | + '' |
|
57 | + ), |
|
58 | + 'QSG_name' => new EE_Plain_Text_Field( |
|
59 | + 'QSG_name', |
|
60 | + esc_html__('Question Group Name', 'event_espresso'), |
|
61 | + false, |
|
62 | + '' |
|
63 | + ), |
|
64 | + 'QSG_order' => new EE_Integer_Field( |
|
65 | + 'QSG_order', |
|
66 | + esc_html__('Order in which to show the question group', 'event_espresso'), |
|
67 | + true, |
|
68 | + 0 |
|
69 | + ), |
|
70 | + 'QSG_show_group_desc' => new EE_Boolean_Field( |
|
71 | + 'QSG_show_group_desc', |
|
72 | + esc_html__( |
|
73 | + 'Flag indicating whether to show the group\s description on the registration page', |
|
74 | + 'event_espresso' |
|
75 | + ), |
|
76 | + false, |
|
77 | + false |
|
78 | + ), |
|
79 | + 'QSG_show_group_name' => new EE_Boolean_Field( |
|
80 | + 'QSG_show_group_name', |
|
81 | + esc_html__( |
|
82 | + 'Flag indicating whether to show the group\'s name on the registration page', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + false, |
|
86 | + true |
|
87 | + ), |
|
88 | + 'QSG_system' => new EE_Integer_Field( |
|
89 | + 'QSG_system', |
|
90 | + esc_html__( |
|
91 | + 'Indicate IF this is a system group and if it is what system group it corresponds to.', |
|
92 | + 'event_espresso' |
|
93 | + ), |
|
94 | + false, |
|
95 | + 0 |
|
96 | + ), |
|
97 | + 'QSG_wp_user' => new EE_WP_User_Field( |
|
98 | + 'QSG_wp_user', |
|
99 | + esc_html__('Question Group Creator ID', 'event_espresso'), |
|
100 | + false |
|
101 | + ), |
|
102 | + ], |
|
103 | + ]; |
|
104 | + $this->_model_relations = [ |
|
105 | + 'Event' => new EE_HABTM_Relation('Event_Question_Group'), |
|
106 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
107 | + 'Question' => new EE_HABTM_Relation('Question_Group_Question'), |
|
108 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
109 | + ]; |
|
110 | + // this model is generally available for reading |
|
111 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
112 | + new EE_Restriction_Generator_Public(); |
|
113 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
114 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
115 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
116 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
117 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
118 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
119 | 119 | |
120 | - parent::__construct($timezone); |
|
121 | - } |
|
120 | + parent::__construct($timezone); |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * searches the db for the question group with the latest question order and returns that value. |
|
126 | - * |
|
127 | - * @return int |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function get_latest_question_group_order(): int |
|
131 | - { |
|
132 | - $max = $this->_get_all_wpdb_results( |
|
133 | - [], |
|
134 | - ARRAY_A, |
|
135 | - [ |
|
136 | - 'max_order' => ["MAX(QSG_order)", "%d"], |
|
137 | - ] |
|
138 | - ); |
|
139 | - return $max[0]['max_order']; |
|
140 | - } |
|
124 | + /** |
|
125 | + * searches the db for the question group with the latest question order and returns that value. |
|
126 | + * |
|
127 | + * @return int |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function get_latest_question_group_order(): int |
|
131 | + { |
|
132 | + $max = $this->_get_all_wpdb_results( |
|
133 | + [], |
|
134 | + ARRAY_A, |
|
135 | + [ |
|
136 | + 'max_order' => ["MAX(QSG_order)", "%d"], |
|
137 | + ] |
|
138 | + ); |
|
139 | + return $max[0]['max_order']; |
|
140 | + } |
|
141 | 141 | } |
@@ -74,13 +74,13 @@ |
||
74 | 74 | $this->_model_chain_to_wp_user = 'Question'; |
75 | 75 | |
76 | 76 | // this model is generally available for reading |
77 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
77 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = |
|
78 | 78 | new EE_Restriction_Generator_Public(); |
79 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
79 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
80 | 80 | new EE_Restriction_Generator_Reg_Form('QSO_system'); |
81 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
81 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
82 | 82 | new EE_Restriction_Generator_Reg_Form('QSO_system'); |
83 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
83 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
84 | 84 | new EE_Restriction_Generator_Reg_Form('QSO_system'); |
85 | 85 | |
86 | 86 | parent::__construct($timezone); |
@@ -9,89 +9,89 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Question_Option extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | - protected static ?EEM_Question_Option $_instance = null; |
|
12 | + protected static ?EEM_Question_Option $_instance = null; |
|
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * @param string|null $timezone |
|
17 | - * @throws EE_Error |
|
18 | - */ |
|
19 | - protected function __construct(?string $timezone = '') |
|
20 | - { |
|
21 | - $this->singular_item = esc_html__('Question Option', 'event_espresso'); |
|
22 | - $this->plural_item = esc_html__('Question Options', 'event_espresso'); |
|
15 | + /** |
|
16 | + * @param string|null $timezone |
|
17 | + * @throws EE_Error |
|
18 | + */ |
|
19 | + protected function __construct(?string $timezone = '') |
|
20 | + { |
|
21 | + $this->singular_item = esc_html__('Question Option', 'event_espresso'); |
|
22 | + $this->plural_item = esc_html__('Question Options', 'event_espresso'); |
|
23 | 23 | |
24 | - $this->_tables = [ |
|
25 | - 'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'), |
|
26 | - ]; |
|
27 | - $this->_fields = [ |
|
28 | - 'Question_Option' => [ |
|
29 | - 'QSO_ID' => new EE_Primary_Key_Int_Field( |
|
30 | - 'QSO_ID', |
|
31 | - esc_html__('Question Option ID', 'event_espresso') |
|
32 | - ), |
|
33 | - 'QST_ID' => new EE_Foreign_Key_Int_Field( |
|
34 | - 'QST_ID', |
|
35 | - esc_html__('Question ID', 'event_espresso'), |
|
36 | - false, |
|
37 | - 0, |
|
38 | - 'Question' |
|
39 | - ), |
|
40 | - 'QSO_default' => new EE_Boolean_Field( |
|
41 | - 'QSO_default', |
|
42 | - esc_html__('Flag indicating this is the default option', 'event_espresso'), |
|
43 | - false, |
|
44 | - false |
|
45 | - ), |
|
46 | - 'QSO_deleted' => new EE_Trashed_Flag_Field( |
|
47 | - 'QSO_deleted', |
|
48 | - esc_html__('Flag indicating Option was trashed', 'event_espresso'), |
|
49 | - false, |
|
50 | - false |
|
51 | - ), |
|
52 | - 'QSO_desc' => new EE_Post_Content_Field( |
|
53 | - 'QSO_desc', |
|
54 | - esc_html__('Question Option Description', 'event_espresso'), |
|
55 | - false, |
|
56 | - '' |
|
57 | - ), |
|
58 | - 'QSO_order' => new EE_Integer_Field( |
|
59 | - 'QSO_order', |
|
60 | - esc_html__('Question Option Order', 'event_espresso'), |
|
61 | - false, |
|
62 | - 0 |
|
63 | - ), |
|
64 | - 'QSO_system' => new EE_Plain_Text_Field( |
|
65 | - 'QSO_system', |
|
66 | - esc_html__('Internal string ID for question option', 'event_espresso'), |
|
67 | - true, |
|
68 | - null |
|
69 | - ), |
|
70 | - 'QSO_value' => new EE_Plain_Text_Field( |
|
71 | - 'QSO_value', |
|
72 | - esc_html__("Question Option Value", "event_espresso"), |
|
73 | - false, |
|
74 | - '' |
|
75 | - ), |
|
76 | - ], |
|
77 | - ]; |
|
78 | - $this->_model_relations = [ |
|
79 | - 'Question' => new EE_Belongs_To_Relation(), |
|
80 | - ]; |
|
24 | + $this->_tables = [ |
|
25 | + 'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'), |
|
26 | + ]; |
|
27 | + $this->_fields = [ |
|
28 | + 'Question_Option' => [ |
|
29 | + 'QSO_ID' => new EE_Primary_Key_Int_Field( |
|
30 | + 'QSO_ID', |
|
31 | + esc_html__('Question Option ID', 'event_espresso') |
|
32 | + ), |
|
33 | + 'QST_ID' => new EE_Foreign_Key_Int_Field( |
|
34 | + 'QST_ID', |
|
35 | + esc_html__('Question ID', 'event_espresso'), |
|
36 | + false, |
|
37 | + 0, |
|
38 | + 'Question' |
|
39 | + ), |
|
40 | + 'QSO_default' => new EE_Boolean_Field( |
|
41 | + 'QSO_default', |
|
42 | + esc_html__('Flag indicating this is the default option', 'event_espresso'), |
|
43 | + false, |
|
44 | + false |
|
45 | + ), |
|
46 | + 'QSO_deleted' => new EE_Trashed_Flag_Field( |
|
47 | + 'QSO_deleted', |
|
48 | + esc_html__('Flag indicating Option was trashed', 'event_espresso'), |
|
49 | + false, |
|
50 | + false |
|
51 | + ), |
|
52 | + 'QSO_desc' => new EE_Post_Content_Field( |
|
53 | + 'QSO_desc', |
|
54 | + esc_html__('Question Option Description', 'event_espresso'), |
|
55 | + false, |
|
56 | + '' |
|
57 | + ), |
|
58 | + 'QSO_order' => new EE_Integer_Field( |
|
59 | + 'QSO_order', |
|
60 | + esc_html__('Question Option Order', 'event_espresso'), |
|
61 | + false, |
|
62 | + 0 |
|
63 | + ), |
|
64 | + 'QSO_system' => new EE_Plain_Text_Field( |
|
65 | + 'QSO_system', |
|
66 | + esc_html__('Internal string ID for question option', 'event_espresso'), |
|
67 | + true, |
|
68 | + null |
|
69 | + ), |
|
70 | + 'QSO_value' => new EE_Plain_Text_Field( |
|
71 | + 'QSO_value', |
|
72 | + esc_html__("Question Option Value", "event_espresso"), |
|
73 | + false, |
|
74 | + '' |
|
75 | + ), |
|
76 | + ], |
|
77 | + ]; |
|
78 | + $this->_model_relations = [ |
|
79 | + 'Question' => new EE_Belongs_To_Relation(), |
|
80 | + ]; |
|
81 | 81 | |
82 | - $this->_caps_slug = 'questions'; |
|
83 | - $this->_model_chain_to_wp_user = 'Question'; |
|
82 | + $this->_caps_slug = 'questions'; |
|
83 | + $this->_model_chain_to_wp_user = 'Question'; |
|
84 | 84 | |
85 | - // this model is generally available for reading |
|
86 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
87 | - new EE_Restriction_Generator_Public(); |
|
88 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
89 | - new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
90 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
91 | - new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
92 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
93 | - new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
85 | + // this model is generally available for reading |
|
86 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
87 | + new EE_Restriction_Generator_Public(); |
|
88 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
89 | + new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
90 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
91 | + new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
92 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
93 | + new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
94 | 94 | |
95 | - parent::__construct($timezone); |
|
96 | - } |
|
95 | + parent::__construct($timezone); |
|
96 | + } |
|
97 | 97 | } |
@@ -61,13 +61,13 @@ |
||
61 | 61 | $this->_model_chain_to_wp_user = 'Question_Group'; |
62 | 62 | |
63 | 63 | // this model is generally available for reading |
64 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
64 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = |
|
65 | 65 | new EE_Restriction_Generator_Public(); |
66 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
66 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
67 | 67 | new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
69 | 69 | new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
70 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
70 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
71 | 71 | new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
72 | 72 | |
73 | 73 | // use the caps for question groups |
@@ -13,67 +13,67 @@ |
||
13 | 13 | */ |
14 | 14 | class EEM_Question_Group_Question extends EEM_Base |
15 | 15 | { |
16 | - protected static ?EEM_Question_Group_Question $_instance = null; |
|
16 | + protected static ?EEM_Question_Group_Question $_instance = null; |
|
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @param string|null $timezone |
|
21 | - * @throws EE_Error |
|
22 | - */ |
|
23 | - protected function __construct(?string $timezone = '') |
|
24 | - { |
|
25 | - $this->singular_item = esc_html__('Question Group to Question Link', 'event_espresso'); |
|
26 | - $this->plural_item = esc_html__('Question Group to Question Links', 'event_espresso'); |
|
27 | - $this->_tables = [ |
|
28 | - 'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID'), |
|
29 | - ]; |
|
30 | - $this->_fields = [ |
|
31 | - 'Question_Group_Question' => [ |
|
32 | - 'QGQ_ID' => new EE_Primary_Key_Int_Field( |
|
33 | - 'QGQ_ID', |
|
34 | - esc_html__('Question Group to Question Link ID', 'event_espresso') |
|
35 | - ), |
|
36 | - 'QSG_ID' => new EE_Foreign_Key_Int_Field( |
|
37 | - 'QSG_ID', |
|
38 | - esc_html__('Question Group ID', 'event_espresso'), |
|
39 | - false, |
|
40 | - 0, |
|
41 | - 'Question_Group' |
|
42 | - ), |
|
43 | - 'QST_ID' => new EE_Foreign_Key_Int_Field( |
|
44 | - 'QST_ID', |
|
45 | - esc_html__('Question Id', 'event_espresso'), |
|
46 | - false, |
|
47 | - 0, |
|
48 | - 'Question' |
|
49 | - ), |
|
50 | - 'QGQ_order' => new EE_Integer_Field( |
|
51 | - 'QGQ_order', |
|
52 | - esc_html__('Question Group Question Order', 'event_espresso'), |
|
53 | - false, |
|
54 | - 0 |
|
55 | - ), |
|
56 | - ], |
|
57 | - ]; |
|
58 | - $this->_model_relations = [ |
|
59 | - 'Question_Group' => new EE_Belongs_To_Relation(), |
|
60 | - 'Question' => new EE_Belongs_To_Relation(), |
|
61 | - ]; |
|
19 | + /** |
|
20 | + * @param string|null $timezone |
|
21 | + * @throws EE_Error |
|
22 | + */ |
|
23 | + protected function __construct(?string $timezone = '') |
|
24 | + { |
|
25 | + $this->singular_item = esc_html__('Question Group to Question Link', 'event_espresso'); |
|
26 | + $this->plural_item = esc_html__('Question Group to Question Links', 'event_espresso'); |
|
27 | + $this->_tables = [ |
|
28 | + 'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID'), |
|
29 | + ]; |
|
30 | + $this->_fields = [ |
|
31 | + 'Question_Group_Question' => [ |
|
32 | + 'QGQ_ID' => new EE_Primary_Key_Int_Field( |
|
33 | + 'QGQ_ID', |
|
34 | + esc_html__('Question Group to Question Link ID', 'event_espresso') |
|
35 | + ), |
|
36 | + 'QSG_ID' => new EE_Foreign_Key_Int_Field( |
|
37 | + 'QSG_ID', |
|
38 | + esc_html__('Question Group ID', 'event_espresso'), |
|
39 | + false, |
|
40 | + 0, |
|
41 | + 'Question_Group' |
|
42 | + ), |
|
43 | + 'QST_ID' => new EE_Foreign_Key_Int_Field( |
|
44 | + 'QST_ID', |
|
45 | + esc_html__('Question Id', 'event_espresso'), |
|
46 | + false, |
|
47 | + 0, |
|
48 | + 'Question' |
|
49 | + ), |
|
50 | + 'QGQ_order' => new EE_Integer_Field( |
|
51 | + 'QGQ_order', |
|
52 | + esc_html__('Question Group Question Order', 'event_espresso'), |
|
53 | + false, |
|
54 | + 0 |
|
55 | + ), |
|
56 | + ], |
|
57 | + ]; |
|
58 | + $this->_model_relations = [ |
|
59 | + 'Question_Group' => new EE_Belongs_To_Relation(), |
|
60 | + 'Question' => new EE_Belongs_To_Relation(), |
|
61 | + ]; |
|
62 | 62 | |
63 | - $this->_model_chain_to_wp_user = 'Question_Group'; |
|
63 | + $this->_model_chain_to_wp_user = 'Question_Group'; |
|
64 | 64 | |
65 | - // this model is generally available for reading |
|
66 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
67 | - new EE_Restriction_Generator_Public(); |
|
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
69 | - new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
70 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
71 | - new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
72 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
73 | - new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
65 | + // this model is generally available for reading |
|
66 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
67 | + new EE_Restriction_Generator_Public(); |
|
68 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
69 | + new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
70 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
71 | + new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
72 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
73 | + new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
74 | 74 | |
75 | - // use the caps for question groups |
|
76 | - $this->_caps_slug = 'question_groups'; |
|
77 | - parent::__construct($timezone); |
|
78 | - } |
|
75 | + // use the caps for question groups |
|
76 | + $this->_caps_slug = 'question_groups'; |
|
77 | + parent::__construct($timezone); |
|
78 | + } |
|
79 | 79 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function model() |
84 | 84 | { |
85 | - if (! $this->_model instanceof EEM_Base) { |
|
85 | + if ( ! $this->_model instanceof EEM_Base) { |
|
86 | 86 | throw new EE_Error( |
87 | 87 | sprintf( |
88 | 88 | esc_html__( |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function action(): string |
108 | 108 | { |
109 | - if (! $this->_action) { |
|
109 | + if ( ! $this->_action) { |
|
110 | 110 | throw new EE_Error( |
111 | 111 | sprintf( |
112 | 112 | esc_html__( |
@@ -260,16 +260,16 @@ discard block |
||
260 | 260 | || strpos($path_to_event_model, 'Event') !== false |
261 | 261 | ) { |
262 | 262 | $where_conditions['OR*status'] = [ |
263 | - $path_to_event_model . 'status' => $published_value, |
|
263 | + $path_to_event_model.'status' => $published_value, |
|
264 | 264 | 'AND' => [ |
265 | - $path_to_event_model . |
|
265 | + $path_to_event_model. |
|
266 | 266 | 'Post_Meta.meta_key' => '_previous_event_status', |
267 | - $path_to_event_model . |
|
267 | + $path_to_event_model. |
|
268 | 268 | 'Post_Meta.meta_value' => $published_value, |
269 | 269 | ], |
270 | 270 | ]; |
271 | 271 | } else { |
272 | - $where_conditions[ $path_to_event_model . 'status' ] = |
|
272 | + $where_conditions[$path_to_event_model.'status'] = |
|
273 | 273 | $published_value; |
274 | 274 | } |
275 | 275 | return $where_conditions; |
@@ -36,242 +36,242 @@ |
||
36 | 36 | */ |
37 | 37 | abstract class EE_Restriction_Generator_Base |
38 | 38 | { |
39 | - /** |
|
40 | - * One of EEM_Base::valid_cap_contexts() |
|
41 | - * |
|
42 | - * @var string |
|
43 | - */ |
|
44 | - protected $_action; |
|
39 | + /** |
|
40 | + * One of EEM_Base::valid_cap_contexts() |
|
41 | + * |
|
42 | + * @var string |
|
43 | + */ |
|
44 | + protected $_action; |
|
45 | 45 | |
46 | - /** |
|
47 | - * The restrictions generated by this object. FALSE before any are made. |
|
48 | - * |
|
49 | - * @var EE_Default_Where_Conditions[] |
|
50 | - */ |
|
51 | - protected $_cap_restrictions_generated; |
|
46 | + /** |
|
47 | + * The restrictions generated by this object. FALSE before any are made. |
|
48 | + * |
|
49 | + * @var EE_Default_Where_Conditions[] |
|
50 | + */ |
|
51 | + protected $_cap_restrictions_generated; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Model for which restrictions are generated |
|
55 | - * |
|
56 | - * @var EEM_Base |
|
57 | - */ |
|
58 | - protected $_model; |
|
53 | + /** |
|
54 | + * Model for which restrictions are generated |
|
55 | + * |
|
56 | + * @var EEM_Base |
|
57 | + */ |
|
58 | + protected $_model; |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Puts the last necessary info onto the restriction generator class. This |
|
63 | - * is usually called by EEM_Base during its constructor, so child classes |
|
64 | - * don't have to always provide this info. |
|
65 | - * |
|
66 | - * @param EEM_Base $model |
|
67 | - * @param string $action |
|
68 | - */ |
|
69 | - public function _construct_finalize(EEM_Base $model, string $action) |
|
70 | - { |
|
71 | - $this->_model = $model; |
|
72 | - $this->_action = $action; |
|
73 | - } |
|
61 | + /** |
|
62 | + * Puts the last necessary info onto the restriction generator class. This |
|
63 | + * is usually called by EEM_Base during its constructor, so child classes |
|
64 | + * don't have to always provide this info. |
|
65 | + * |
|
66 | + * @param EEM_Base $model |
|
67 | + * @param string $action |
|
68 | + */ |
|
69 | + public function _construct_finalize(EEM_Base $model, string $action) |
|
70 | + { |
|
71 | + $this->_model = $model; |
|
72 | + $this->_action = $action; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * Returns the model set for this restriction generator |
|
78 | - * |
|
79 | - * @return EEM_Base|EEM_Soft_Delete_Base |
|
80 | - * @throws EE_Error |
|
81 | - */ |
|
82 | - public function model() |
|
83 | - { |
|
84 | - if (! $this->_model instanceof EEM_Base) { |
|
85 | - throw new EE_Error( |
|
86 | - sprintf( |
|
87 | - esc_html__( |
|
88 | - 'Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - get_class($this) |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - return $this->_model; |
|
96 | - } |
|
76 | + /** |
|
77 | + * Returns the model set for this restriction generator |
|
78 | + * |
|
79 | + * @return EEM_Base|EEM_Soft_Delete_Base |
|
80 | + * @throws EE_Error |
|
81 | + */ |
|
82 | + public function model() |
|
83 | + { |
|
84 | + if (! $this->_model instanceof EEM_Base) { |
|
85 | + throw new EE_Error( |
|
86 | + sprintf( |
|
87 | + esc_html__( |
|
88 | + 'Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + get_class($this) |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + return $this->_model; |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * Returns the action this restriction generator will generate restrictions |
|
101 | - * for. It should be one of EEM_Base::valid_cap_contexts() |
|
102 | - * |
|
103 | - * @return string |
|
104 | - * @throws EE_Error |
|
105 | - */ |
|
106 | - public function action(): string |
|
107 | - { |
|
108 | - if (! $this->_action) { |
|
109 | - throw new EE_Error( |
|
110 | - sprintf( |
|
111 | - esc_html__( |
|
112 | - 'Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', |
|
113 | - 'event_espresso' |
|
114 | - ), |
|
115 | - get_class($this) |
|
116 | - ) |
|
117 | - ); |
|
118 | - } |
|
119 | - return $this->_action; |
|
120 | - } |
|
99 | + /** |
|
100 | + * Returns the action this restriction generator will generate restrictions |
|
101 | + * for. It should be one of EEM_Base::valid_cap_contexts() |
|
102 | + * |
|
103 | + * @return string |
|
104 | + * @throws EE_Error |
|
105 | + */ |
|
106 | + public function action(): string |
|
107 | + { |
|
108 | + if (! $this->_action) { |
|
109 | + throw new EE_Error( |
|
110 | + sprintf( |
|
111 | + esc_html__( |
|
112 | + 'Cannot generate capability restrictions because model has not yet been set on the %s. Please ensure _construct_finalize() was called', |
|
113 | + 'event_espresso' |
|
114 | + ), |
|
115 | + get_class($this) |
|
116 | + ) |
|
117 | + ); |
|
118 | + } |
|
119 | + return $this->_action; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * Returns whether or not _construct_finalize() has been called on this |
|
125 | - * restriction generator object |
|
126 | - * |
|
127 | - * @return boolean |
|
128 | - */ |
|
129 | - public function construction_finalized(): bool |
|
130 | - { |
|
131 | - return $this->_model instanceof EEM_Base && $this->_action; |
|
132 | - } |
|
123 | + /** |
|
124 | + * Returns whether or not _construct_finalize() has been called on this |
|
125 | + * restriction generator object |
|
126 | + * |
|
127 | + * @return boolean |
|
128 | + */ |
|
129 | + public function construction_finalized(): bool |
|
130 | + { |
|
131 | + return $this->_model instanceof EEM_Base && $this->_action; |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | - /** |
|
136 | - * Gets the capability restrictions generated by this object. Caches them in |
|
137 | - * case they are required for subsequent requests |
|
138 | - * |
|
139 | - * @return array @see EEM_Base::_cap_restrictions |
|
140 | - */ |
|
141 | - public function generate_restrictions(): array |
|
142 | - { |
|
143 | - if ($this->_cap_restrictions_generated === null) { |
|
144 | - $this->_cap_restrictions_generated = apply_filters( |
|
145 | - 'FHEE__EE_Restriction_Generator_Base__generate_restrictions__first_time', |
|
146 | - $this->_generate_restrictions(), |
|
147 | - $this |
|
148 | - ); |
|
149 | - } |
|
150 | - return apply_filters( |
|
151 | - 'FHEE__EE_Restriction_Generator_Base__generate_restrictions__every_time', |
|
152 | - $this->_cap_restrictions_generated, |
|
153 | - $this |
|
154 | - ); |
|
155 | - } |
|
135 | + /** |
|
136 | + * Gets the capability restrictions generated by this object. Caches them in |
|
137 | + * case they are required for subsequent requests |
|
138 | + * |
|
139 | + * @return array @see EEM_Base::_cap_restrictions |
|
140 | + */ |
|
141 | + public function generate_restrictions(): array |
|
142 | + { |
|
143 | + if ($this->_cap_restrictions_generated === null) { |
|
144 | + $this->_cap_restrictions_generated = apply_filters( |
|
145 | + 'FHEE__EE_Restriction_Generator_Base__generate_restrictions__first_time', |
|
146 | + $this->_generate_restrictions(), |
|
147 | + $this |
|
148 | + ); |
|
149 | + } |
|
150 | + return apply_filters( |
|
151 | + 'FHEE__EE_Restriction_Generator_Base__generate_restrictions__every_time', |
|
152 | + $this->_cap_restrictions_generated, |
|
153 | + $this |
|
154 | + ); |
|
155 | + } |
|
156 | 156 | |
157 | 157 | |
158 | - /** |
|
159 | - * Provided with the model, and using global knowledge about what |
|
160 | - * capabilities exist, generates an array for use in one of the sub-arrays |
|
161 | - * in EEM_Base::_cap_restrictions, where keys are capability names, and |
|
162 | - * values are children of EE_Default_Where_Conditions |
|
163 | - * |
|
164 | - * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
165 | - * @see EEM_Base::_cap_restrictions |
|
166 | - */ |
|
167 | - abstract protected function _generate_restrictions(): array; |
|
158 | + /** |
|
159 | + * Provided with the model, and using global knowledge about what |
|
160 | + * capabilities exist, generates an array for use in one of the sub-arrays |
|
161 | + * in EEM_Base::_cap_restrictions, where keys are capability names, and |
|
162 | + * values are children of EE_Default_Where_Conditions |
|
163 | + * |
|
164 | + * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
165 | + * @see EEM_Base::_cap_restrictions |
|
166 | + */ |
|
167 | + abstract protected function _generate_restrictions(): array; |
|
168 | 168 | |
169 | 169 | |
170 | - /** |
|
171 | - * Whether or not this restriction generator has already done its job of |
|
172 | - * making restrictions and caching them on itself in case its asked later |
|
173 | - * |
|
174 | - * @return boolean |
|
175 | - */ |
|
176 | - public function has_generated_cap_restrictions(): bool |
|
177 | - { |
|
178 | - return $this->_cap_restrictions_generated !== null; |
|
179 | - } |
|
170 | + /** |
|
171 | + * Whether or not this restriction generator has already done its job of |
|
172 | + * making restrictions and caching them on itself in case its asked later |
|
173 | + * |
|
174 | + * @return boolean |
|
175 | + */ |
|
176 | + public function has_generated_cap_restrictions(): bool |
|
177 | + { |
|
178 | + return $this->_cap_restrictions_generated !== null; |
|
179 | + } |
|
180 | 180 | |
181 | 181 | |
182 | - /** |
|
183 | - * Given an action like 'edit' generates the cap name based off |
|
184 | - * the EEM_Base::_cap_slug, which for events would be 'events', to generate |
|
185 | - * the cap name like 'ee_edit_events'. If a $qualifier is passed, |
|
186 | - * |
|
187 | - * @param EEM_Base $model |
|
188 | - * @param string $action |
|
189 | - * @return string |
|
190 | - */ |
|
191 | - public static function get_cap_name(EEM_Base $model, string $action): string |
|
192 | - { |
|
193 | - $prefix = $model->is_wp_core_model() ? '' : 'ee_'; |
|
194 | - $cap_slug = $model->cap_slug(); |
|
195 | - return apply_filters( |
|
196 | - 'FHEE__EE_Restriction_Generator__get_cap_name', |
|
197 | - "{$prefix}{$action}_{$cap_slug}", |
|
198 | - $model, |
|
199 | - $action |
|
200 | - ); |
|
201 | - } |
|
182 | + /** |
|
183 | + * Given an action like 'edit' generates the cap name based off |
|
184 | + * the EEM_Base::_cap_slug, which for events would be 'events', to generate |
|
185 | + * the cap name like 'ee_edit_events'. If a $qualifier is passed, |
|
186 | + * |
|
187 | + * @param EEM_Base $model |
|
188 | + * @param string $action |
|
189 | + * @return string |
|
190 | + */ |
|
191 | + public static function get_cap_name(EEM_Base $model, string $action): string |
|
192 | + { |
|
193 | + $prefix = $model->is_wp_core_model() ? '' : 'ee_'; |
|
194 | + $cap_slug = $model->cap_slug(); |
|
195 | + return apply_filters( |
|
196 | + 'FHEE__EE_Restriction_Generator__get_cap_name', |
|
197 | + "{$prefix}{$action}_{$cap_slug}", |
|
198 | + $model, |
|
199 | + $action |
|
200 | + ); |
|
201 | + } |
|
202 | 202 | |
203 | 203 | |
204 | - /** |
|
205 | - * Checks if there is a cap for this model and this action |
|
206 | - * |
|
207 | - * @param EEM_Base $model |
|
208 | - * @param string $action |
|
209 | - * @return boolean |
|
210 | - * @throws EE_Error |
|
211 | - */ |
|
212 | - public static function is_cap(EEM_Base $model, string $action): bool |
|
213 | - { |
|
214 | - $caps_for_admin = EE_Registry::instance()->CAP->get_ee_capabilities(); |
|
215 | - return in_array(self::get_cap_name($model, $action), $caps_for_admin); |
|
216 | - } |
|
204 | + /** |
|
205 | + * Checks if there is a cap for this model and this action |
|
206 | + * |
|
207 | + * @param EEM_Base $model |
|
208 | + * @param string $action |
|
209 | + * @return boolean |
|
210 | + * @throws EE_Error |
|
211 | + */ |
|
212 | + public static function is_cap(EEM_Base $model, string $action): bool |
|
213 | + { |
|
214 | + $caps_for_admin = EE_Registry::instance()->CAP->get_ee_capabilities(); |
|
215 | + return in_array(self::get_cap_name($model, $action), $caps_for_admin); |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | - /** |
|
220 | - * Returns the default capability used to determine if the current user can |
|
221 | - * access something. |
|
222 | - * |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function get_default_restrictions_cap(): string |
|
226 | - { |
|
227 | - return apply_filters( |
|
228 | - 'FHEE__EE_Restriction_Generator_Base__default_restrictions_cap', |
|
229 | - 'manage_options' |
|
230 | - ); |
|
231 | - } |
|
219 | + /** |
|
220 | + * Returns the default capability used to determine if the current user can |
|
221 | + * access something. |
|
222 | + * |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function get_default_restrictions_cap(): string |
|
226 | + { |
|
227 | + return apply_filters( |
|
228 | + 'FHEE__EE_Restriction_Generator_Base__default_restrictions_cap', |
|
229 | + 'manage_options' |
|
230 | + ); |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * Gets WHERE conditions for the query that show the post model is |
|
236 | - * published, or that it's sold out and it was previously published |
|
237 | - * |
|
238 | - * @param array $where_conditions |
|
239 | - * @param boolean $check_if_published if true, will add conditions like |
|
240 | - * status=publish if false, will add |
|
241 | - * conditions like status!=private |
|
242 | - * @param string $path_to_event_model including the period at the end |
|
243 | - * @return array |
|
244 | - * @throws EE_Error |
|
245 | - */ |
|
246 | - protected function addPublishedPostConditions( |
|
247 | - $where_conditions = [], |
|
248 | - $check_if_published = true, |
|
249 | - $path_to_event_model = '' |
|
250 | - ): array { |
|
251 | - if ($check_if_published) { |
|
252 | - $published_value = 'publish'; |
|
253 | - } else { |
|
254 | - $published_value = ['!=', 'private']; |
|
255 | - } |
|
256 | - // only add a check for the previous event status |
|
257 | - // if the model is the event or it's related to the event model |
|
258 | - if ( |
|
259 | - $this->model() instanceof EEM_Event |
|
260 | - || strpos($path_to_event_model, 'Event') !== false |
|
261 | - ) { |
|
262 | - $where_conditions['OR*status'] = [ |
|
263 | - $path_to_event_model . 'status' => $published_value, |
|
264 | - 'AND' => [ |
|
265 | - $path_to_event_model . |
|
266 | - 'Post_Meta.meta_key' => '_previous_event_status', |
|
267 | - $path_to_event_model . |
|
268 | - 'Post_Meta.meta_value' => $published_value, |
|
269 | - ], |
|
270 | - ]; |
|
271 | - } else { |
|
272 | - $where_conditions[ $path_to_event_model . 'status' ] = |
|
273 | - $published_value; |
|
274 | - } |
|
275 | - return $where_conditions; |
|
276 | - } |
|
234 | + /** |
|
235 | + * Gets WHERE conditions for the query that show the post model is |
|
236 | + * published, or that it's sold out and it was previously published |
|
237 | + * |
|
238 | + * @param array $where_conditions |
|
239 | + * @param boolean $check_if_published if true, will add conditions like |
|
240 | + * status=publish if false, will add |
|
241 | + * conditions like status!=private |
|
242 | + * @param string $path_to_event_model including the period at the end |
|
243 | + * @return array |
|
244 | + * @throws EE_Error |
|
245 | + */ |
|
246 | + protected function addPublishedPostConditions( |
|
247 | + $where_conditions = [], |
|
248 | + $check_if_published = true, |
|
249 | + $path_to_event_model = '' |
|
250 | + ): array { |
|
251 | + if ($check_if_published) { |
|
252 | + $published_value = 'publish'; |
|
253 | + } else { |
|
254 | + $published_value = ['!=', 'private']; |
|
255 | + } |
|
256 | + // only add a check for the previous event status |
|
257 | + // if the model is the event or it's related to the event model |
|
258 | + if ( |
|
259 | + $this->model() instanceof EEM_Event |
|
260 | + || strpos($path_to_event_model, 'Event') !== false |
|
261 | + ) { |
|
262 | + $where_conditions['OR*status'] = [ |
|
263 | + $path_to_event_model . 'status' => $published_value, |
|
264 | + 'AND' => [ |
|
265 | + $path_to_event_model . |
|
266 | + 'Post_Meta.meta_key' => '_previous_event_status', |
|
267 | + $path_to_event_model . |
|
268 | + 'Post_Meta.meta_value' => $published_value, |
|
269 | + ], |
|
270 | + ]; |
|
271 | + } else { |
|
272 | + $where_conditions[ $path_to_event_model . 'status' ] = |
|
273 | + $published_value; |
|
274 | + } |
|
275 | + return $where_conditions; |
|
276 | + } |
|
277 | 277 | } |
@@ -52,21 +52,21 @@ |
||
52 | 52 | 'FHEE__EE_Restriction_Generator_Meta___generate_restrictions__blacklisted_meta_keys', |
53 | 53 | [] |
54 | 54 | ); |
55 | - $conditions = [ |
|
55 | + $conditions = [ |
|
56 | 56 | $this->_key_field_name => ['NOT_LIKE', "\\\\_%"], |
57 | 57 | // each slash is escaped because we are using double quotes, and |
58 | 58 | // stripslashes will be called on this because the models assume this is from user input |
59 | 59 | $this->_value_field_name => ['NOT_REGEXP', '^[aOs]:[\d]:.*$'], |
60 | 60 | ]; |
61 | - if (! empty($blacklisted_meta_keys)) { |
|
62 | - $conditions[ $this->_key_field_name . '*blacklisted' ] = |
|
61 | + if ( ! empty($blacklisted_meta_keys)) { |
|
62 | + $conditions[$this->_key_field_name.'*blacklisted'] = |
|
63 | 63 | ['NOT_IN', $blacklisted_meta_keys]; |
64 | 64 | } |
65 | - if (! empty($whitelisted_meta_keys)) { |
|
65 | + if ( ! empty($whitelisted_meta_keys)) { |
|
66 | 66 | $conditions = [ |
67 | 67 | 'OR*whitelisted-or-normal' => [ |
68 | 68 | 'AND' => $conditions, |
69 | - $this->_key_field_name . '*whitelisted' => [ |
|
69 | + $this->_key_field_name.'*whitelisted' => [ |
|
70 | 70 | 'IN', |
71 | 71 | $whitelisted_meta_keys, |
72 | 72 | ], |
@@ -11,75 +11,75 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Restriction_Generator_Meta extends EE_Restriction_Generator_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * @var string the name of the field containing the meta key |
|
16 | - */ |
|
17 | - protected $_key_field_name = null; |
|
14 | + /** |
|
15 | + * @var string the name of the field containing the meta key |
|
16 | + */ |
|
17 | + protected $_key_field_name = null; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var string the name of the field containing the meta value |
|
21 | - */ |
|
22 | - protected $_value_field_name = null; |
|
19 | + /** |
|
20 | + * @var string the name of the field containing the meta value |
|
21 | + */ |
|
22 | + protected $_value_field_name = null; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Accepts the name of the field that indicates whether or not an object is |
|
27 | - * a "system" one or not |
|
28 | - * |
|
29 | - * @param string $key_field_name |
|
30 | - * @param string $value_field_name |
|
31 | - */ |
|
32 | - public function __construct(string $key_field_name, string $value_field_name) |
|
33 | - { |
|
34 | - $this->_key_field_name = $key_field_name; |
|
35 | - $this->_value_field_name = $value_field_name; |
|
36 | - } |
|
25 | + /** |
|
26 | + * Accepts the name of the field that indicates whether or not an object is |
|
27 | + * a "system" one or not |
|
28 | + * |
|
29 | + * @param string $key_field_name |
|
30 | + * @param string $value_field_name |
|
31 | + */ |
|
32 | + public function __construct(string $key_field_name, string $value_field_name) |
|
33 | + { |
|
34 | + $this->_key_field_name = $key_field_name; |
|
35 | + $this->_value_field_name = $value_field_name; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
41 | - */ |
|
42 | - protected function _generate_restrictions(): array |
|
43 | - { |
|
44 | - $whitelisted_meta_keys = |
|
45 | - apply_filters( |
|
46 | - 'FHEE__EE_Restriction_Generator_Meta___generate_restrictions__whitelisted_meta_keys', |
|
47 | - [] |
|
48 | - ); |
|
49 | - $blacklisted_meta_keys = |
|
50 | - apply_filters( |
|
51 | - 'FHEE__EE_Restriction_Generator_Meta___generate_restrictions__blacklisted_meta_keys', |
|
52 | - [] |
|
53 | - ); |
|
54 | - $conditions = [ |
|
55 | - $this->_key_field_name => ['NOT_LIKE', "\\\\_%"], |
|
56 | - // each slash is escaped because we are using double quotes, and |
|
57 | - // stripslashes will be called on this because the models assume this is from user input |
|
58 | - $this->_value_field_name => ['NOT_REGEXP', '^[aOs]:[\d]:.*$'], |
|
59 | - ]; |
|
60 | - if (! empty($blacklisted_meta_keys)) { |
|
61 | - $conditions[ $this->_key_field_name . '*blacklisted' ] = |
|
62 | - ['NOT_IN', $blacklisted_meta_keys]; |
|
63 | - } |
|
64 | - if (! empty($whitelisted_meta_keys)) { |
|
65 | - $conditions = [ |
|
66 | - 'OR*whitelisted-or-normal' => [ |
|
67 | - 'AND' => $conditions, |
|
68 | - $this->_key_field_name . '*whitelisted' => [ |
|
69 | - 'IN', |
|
70 | - $whitelisted_meta_keys, |
|
71 | - ], |
|
72 | - ], |
|
73 | - ]; |
|
74 | - } |
|
75 | - return [ |
|
76 | - // only allow access to non-protected metas if they're an admin |
|
77 | - EE_Restriction_Generator_Base::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions(), |
|
78 | - // don't allow access to protected metas to anyone. |
|
79 | - // If they want that, don't apply caps to the query |
|
80 | - 'apply-to-all-queries-using-caps' => new EE_Default_Where_Conditions( |
|
81 | - $conditions |
|
82 | - ), |
|
83 | - ]; |
|
84 | - } |
|
39 | + /** |
|
40 | + * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
41 | + */ |
|
42 | + protected function _generate_restrictions(): array |
|
43 | + { |
|
44 | + $whitelisted_meta_keys = |
|
45 | + apply_filters( |
|
46 | + 'FHEE__EE_Restriction_Generator_Meta___generate_restrictions__whitelisted_meta_keys', |
|
47 | + [] |
|
48 | + ); |
|
49 | + $blacklisted_meta_keys = |
|
50 | + apply_filters( |
|
51 | + 'FHEE__EE_Restriction_Generator_Meta___generate_restrictions__blacklisted_meta_keys', |
|
52 | + [] |
|
53 | + ); |
|
54 | + $conditions = [ |
|
55 | + $this->_key_field_name => ['NOT_LIKE', "\\\\_%"], |
|
56 | + // each slash is escaped because we are using double quotes, and |
|
57 | + // stripslashes will be called on this because the models assume this is from user input |
|
58 | + $this->_value_field_name => ['NOT_REGEXP', '^[aOs]:[\d]:.*$'], |
|
59 | + ]; |
|
60 | + if (! empty($blacklisted_meta_keys)) { |
|
61 | + $conditions[ $this->_key_field_name . '*blacklisted' ] = |
|
62 | + ['NOT_IN', $blacklisted_meta_keys]; |
|
63 | + } |
|
64 | + if (! empty($whitelisted_meta_keys)) { |
|
65 | + $conditions = [ |
|
66 | + 'OR*whitelisted-or-normal' => [ |
|
67 | + 'AND' => $conditions, |
|
68 | + $this->_key_field_name . '*whitelisted' => [ |
|
69 | + 'IN', |
|
70 | + $whitelisted_meta_keys, |
|
71 | + ], |
|
72 | + ], |
|
73 | + ]; |
|
74 | + } |
|
75 | + return [ |
|
76 | + // only allow access to non-protected metas if they're an admin |
|
77 | + EE_Restriction_Generator_Base::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions(), |
|
78 | + // don't allow access to protected metas to anyone. |
|
79 | + // If they want that, don't apply caps to the query |
|
80 | + 'apply-to-all-queries-using-caps' => new EE_Default_Where_Conditions( |
|
81 | + $conditions |
|
82 | + ), |
|
83 | + ]; |
|
84 | + } |
|
85 | 85 | } |
@@ -45,14 +45,14 @@ discard block |
||
45 | 45 | protected function _generate_restrictions(): array |
46 | 46 | { |
47 | 47 | // if there are no standard caps for this model, then allow full access |
48 | - if (! $this->model()->cap_slug()) { |
|
48 | + if ( ! $this->model()->cap_slug()) { |
|
49 | 49 | return []; |
50 | 50 | } |
51 | 51 | |
52 | 52 | return [ |
53 | 53 | 'ee_manage_event_categories' => new EE_Default_Where_Conditions( |
54 | 54 | [ |
55 | - $this->_path_to_taxonomy_model . |
|
55 | + $this->_path_to_taxonomy_model. |
|
56 | 56 | 'taxonomy*no_ee_manage_event_categories' => [ |
57 | 57 | '!=', |
58 | 58 | 'espresso_event_categories', |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | ), |
62 | 62 | 'ee_manage_venue_categories' => new EE_Default_Where_Conditions( |
63 | 63 | [ |
64 | - $this->_path_to_taxonomy_model . |
|
64 | + $this->_path_to_taxonomy_model. |
|
65 | 65 | 'taxonomy*no_ee_manage_venue_categories' => [ |
66 | 66 | '!=', |
67 | 67 | 'espresso_venue_categories', |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | ), |
71 | 71 | 'ee_manage_event_types' => new EE_Default_Where_Conditions( |
72 | 72 | [ |
73 | - $this->_path_to_taxonomy_model . |
|
73 | + $this->_path_to_taxonomy_model. |
|
74 | 74 | 'taxonomy*ee_manage_event_types' => [ |
75 | 75 | '!=', |
76 | 76 | 'espresso_event_types' |
@@ -11,71 +11,71 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Restriction_Generator_Taxonomy_Protected extends EE_Restriction_Generator_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * Model chain/path to taxonomy model, |
|
16 | - * including the term_taxonomy model itself |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $_path_to_taxonomy_model; |
|
14 | + /** |
|
15 | + * Model chain/path to taxonomy model, |
|
16 | + * including the term_taxonomy model itself |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $_path_to_taxonomy_model; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $path_to_taxonomy_model Model chain/path to taxonomy |
|
25 | - * model, including the term_taxonomy |
|
26 | - * model itself |
|
27 | - */ |
|
28 | - public function __construct(string $path_to_taxonomy_model) |
|
29 | - { |
|
30 | - if ( |
|
31 | - $path_to_taxonomy_model !== '' && |
|
32 | - substr($path_to_taxonomy_model, -1, 1) != '.' |
|
33 | - ) { |
|
34 | - $path_to_taxonomy_model .= '.'; |
|
35 | - } |
|
36 | - $this->_path_to_taxonomy_model = $path_to_taxonomy_model; |
|
37 | - } |
|
23 | + /** |
|
24 | + * @param string $path_to_taxonomy_model Model chain/path to taxonomy |
|
25 | + * model, including the term_taxonomy |
|
26 | + * model itself |
|
27 | + */ |
|
28 | + public function __construct(string $path_to_taxonomy_model) |
|
29 | + { |
|
30 | + if ( |
|
31 | + $path_to_taxonomy_model !== '' && |
|
32 | + substr($path_to_taxonomy_model, -1, 1) != '.' |
|
33 | + ) { |
|
34 | + $path_to_taxonomy_model .= '.'; |
|
35 | + } |
|
36 | + $this->_path_to_taxonomy_model = $path_to_taxonomy_model; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
42 | - * @throws EE_Error |
|
43 | - */ |
|
44 | - protected function _generate_restrictions(): array |
|
45 | - { |
|
46 | - // if there are no standard caps for this model, then allow full access |
|
47 | - if (! $this->model()->cap_slug()) { |
|
48 | - return []; |
|
49 | - } |
|
40 | + /** |
|
41 | + * @return EE_Default_Where_Conditions[]|EE_Return_None_Where_Conditions[] |
|
42 | + * @throws EE_Error |
|
43 | + */ |
|
44 | + protected function _generate_restrictions(): array |
|
45 | + { |
|
46 | + // if there are no standard caps for this model, then allow full access |
|
47 | + if (! $this->model()->cap_slug()) { |
|
48 | + return []; |
|
49 | + } |
|
50 | 50 | |
51 | - return [ |
|
52 | - 'ee_manage_event_categories' => new EE_Default_Where_Conditions( |
|
53 | - [ |
|
54 | - $this->_path_to_taxonomy_model . |
|
55 | - 'taxonomy*no_ee_manage_event_categories' => [ |
|
56 | - '!=', |
|
57 | - 'espresso_event_categories', |
|
58 | - ], |
|
59 | - ] |
|
60 | - ), |
|
61 | - 'ee_manage_venue_categories' => new EE_Default_Where_Conditions( |
|
62 | - [ |
|
63 | - $this->_path_to_taxonomy_model . |
|
64 | - 'taxonomy*no_ee_manage_venue_categories' => [ |
|
65 | - '!=', |
|
66 | - 'espresso_venue_categories', |
|
67 | - ], |
|
68 | - ] |
|
69 | - ), |
|
70 | - 'ee_manage_event_types' => new EE_Default_Where_Conditions( |
|
71 | - [ |
|
72 | - $this->_path_to_taxonomy_model . |
|
73 | - 'taxonomy*ee_manage_event_types' => [ |
|
74 | - '!=', |
|
75 | - 'espresso_event_types' |
|
76 | - ] |
|
77 | - ] |
|
78 | - ), |
|
79 | - ]; |
|
80 | - } |
|
51 | + return [ |
|
52 | + 'ee_manage_event_categories' => new EE_Default_Where_Conditions( |
|
53 | + [ |
|
54 | + $this->_path_to_taxonomy_model . |
|
55 | + 'taxonomy*no_ee_manage_event_categories' => [ |
|
56 | + '!=', |
|
57 | + 'espresso_event_categories', |
|
58 | + ], |
|
59 | + ] |
|
60 | + ), |
|
61 | + 'ee_manage_venue_categories' => new EE_Default_Where_Conditions( |
|
62 | + [ |
|
63 | + $this->_path_to_taxonomy_model . |
|
64 | + 'taxonomy*no_ee_manage_venue_categories' => [ |
|
65 | + '!=', |
|
66 | + 'espresso_venue_categories', |
|
67 | + ], |
|
68 | + ] |
|
69 | + ), |
|
70 | + 'ee_manage_event_types' => new EE_Default_Where_Conditions( |
|
71 | + [ |
|
72 | + $this->_path_to_taxonomy_model . |
|
73 | + 'taxonomy*ee_manage_event_types' => [ |
|
74 | + '!=', |
|
75 | + 'espresso_event_types' |
|
76 | + ] |
|
77 | + ] |
|
78 | + ), |
|
79 | + ]; |
|
80 | + } |
|
81 | 81 | } |