@@ -12,7 +12,6 @@ |
||
12 | 12 | use InvalidArgumentException; |
13 | 13 | use WPGraphQL\Data\Connection\AbstractConnectionResolver; |
14 | 14 | use WPGraphQL\Model\Post; |
15 | -use WPGraphQL\Types; |
|
16 | 15 | |
17 | 16 | /** |
18 | 17 | * Class DatetimeConnectionResolver |
@@ -21,207 +21,207 @@ |
||
21 | 21 | class DatetimeConnectionResolver extends AbstractConnectionResolver |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @return EEM_Datetime |
|
26 | - * @throws EE_Error |
|
27 | - * @throws InvalidArgumentException |
|
28 | - * @throws InvalidDataTypeException |
|
29 | - * @throws InvalidInterfaceException |
|
30 | - */ |
|
31 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | - public function get_query() |
|
33 | - { |
|
34 | - return EEM_Datetime::instance(); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Return an array of items from the query |
|
39 | - * |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | - public function get_items() |
|
44 | - { |
|
45 | - $results = $this->query->get_col($this->query_args); |
|
46 | - |
|
47 | - return ! empty($results) ? $results : []; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * Determine whether the Query should execute. If it's determined that the query should |
|
52 | - * not be run based on context such as, but not limited to, who the user is, where in the |
|
53 | - * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
54 | - * |
|
55 | - * Return false to prevent the query from executing. |
|
56 | - * |
|
57 | - * @return bool |
|
58 | - */ |
|
59 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
60 | - public function should_execute() |
|
61 | - { |
|
62 | - if (false === $this->should_execute) { |
|
63 | - return false; |
|
64 | - } |
|
65 | - |
|
66 | - return $this->should_execute; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
71 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
72 | - * handle batch resolution of the posts. |
|
73 | - * |
|
74 | - * @return array |
|
75 | - */ |
|
76 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
77 | - public function get_query_args() |
|
78 | - { |
|
79 | - $where_params = []; |
|
80 | - $query_args = []; |
|
81 | - /** |
|
82 | - * Prepare for later use |
|
83 | - */ |
|
84 | - $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
85 | - $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
86 | - |
|
87 | - /** |
|
88 | - * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
|
89 | - */ |
|
90 | - $query_args['limit'] = min( |
|
91 | - max(absint($first), absint($last), 10), |
|
92 | - $this->query_amount |
|
93 | - ) + 1; |
|
94 | - |
|
95 | - /** |
|
96 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
97 | - */ |
|
98 | - $input_fields = []; |
|
99 | - if (! empty($this->args['where'])) { |
|
100 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
105 | - * |
|
106 | - * For example, if we're querying for datetime as a field of event query, this will automatically |
|
107 | - * set the query to pull datetimes that belong to that event. |
|
108 | - * We can set more cases for other source types. |
|
109 | - */ |
|
110 | - if (is_object($this->source)) { |
|
111 | - switch (true) { |
|
112 | - // It's surely an event |
|
113 | - case $this->source instanceof Post: |
|
114 | - $where_params['EVT_ID'] = $this->source->ID; |
|
115 | - break; |
|
116 | - case $this->source instanceof EE_Event: |
|
117 | - $where_params['EVT_ID'] = $this->source->ID(); |
|
118 | - break; |
|
119 | - case $this->source instanceof EE_Ticket: |
|
120 | - $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
121 | - break; |
|
122 | - case $this->source instanceof EE_Checkin: |
|
123 | - $where_params['Checkin.CHK_ID'] = $this->source->ID(); |
|
124 | - break; |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Merge the input_fields with the default query_args |
|
130 | - */ |
|
131 | - if (! empty($input_fields)) { |
|
132 | - $where_params = array_merge($where_params, $input_fields); |
|
133 | - } |
|
134 | - |
|
135 | - // ID of the offset datetime. |
|
136 | - $offset = $this->get_offset(); |
|
137 | - |
|
138 | - /** |
|
139 | - * Map the orderby inputArgs to the WP_Query |
|
140 | - */ |
|
141 | - if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
142 | - $query_args['order_by'] = []; |
|
143 | - foreach ($this->args['where']['orderby'] as $orderby_input) { |
|
144 | - $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
145 | - } |
|
146 | - } elseif ($offset) { |
|
147 | - $compare = ! empty($last) ? '<' : '>'; |
|
148 | - $where_params['DTT_ID'] = array($compare, $offset); |
|
149 | - } |
|
150 | - |
|
151 | - if (! empty($this->args['where']['upcoming'])) { |
|
152 | - $where_params['DTT_EVT_start'] = array( |
|
153 | - '>', |
|
154 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - if (! empty($this->args['where']['active'])) { |
|
159 | - $where_params['DTT_EVT_start'] = array( |
|
160 | - '<', |
|
161 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
162 | - ); |
|
163 | - $where_params['DTT_EVT_end'] = array( |
|
164 | - '>', |
|
165 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
166 | - ); |
|
167 | - } |
|
168 | - |
|
169 | - if (! empty($this->args['where']['expired'])) { |
|
170 | - $where_params['DTT_EVT_end'] = array( |
|
171 | - '<', |
|
172 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
173 | - ); |
|
174 | - } |
|
175 | - |
|
176 | - $query_args[] = $where_params; |
|
24 | + /** |
|
25 | + * @return EEM_Datetime |
|
26 | + * @throws EE_Error |
|
27 | + * @throws InvalidArgumentException |
|
28 | + * @throws InvalidDataTypeException |
|
29 | + * @throws InvalidInterfaceException |
|
30 | + */ |
|
31 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
32 | + public function get_query() |
|
33 | + { |
|
34 | + return EEM_Datetime::instance(); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Return an array of items from the query |
|
39 | + * |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | + public function get_items() |
|
44 | + { |
|
45 | + $results = $this->query->get_col($this->query_args); |
|
46 | + |
|
47 | + return ! empty($results) ? $results : []; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * Determine whether the Query should execute. If it's determined that the query should |
|
52 | + * not be run based on context such as, but not limited to, who the user is, where in the |
|
53 | + * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
54 | + * |
|
55 | + * Return false to prevent the query from executing. |
|
56 | + * |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
60 | + public function should_execute() |
|
61 | + { |
|
62 | + if (false === $this->should_execute) { |
|
63 | + return false; |
|
64 | + } |
|
65 | + |
|
66 | + return $this->should_execute; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
71 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
72 | + * handle batch resolution of the posts. |
|
73 | + * |
|
74 | + * @return array |
|
75 | + */ |
|
76 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
77 | + public function get_query_args() |
|
78 | + { |
|
79 | + $where_params = []; |
|
80 | + $query_args = []; |
|
81 | + /** |
|
82 | + * Prepare for later use |
|
83 | + */ |
|
84 | + $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
85 | + $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
86 | + |
|
87 | + /** |
|
88 | + * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
|
89 | + */ |
|
90 | + $query_args['limit'] = min( |
|
91 | + max(absint($first), absint($last), 10), |
|
92 | + $this->query_amount |
|
93 | + ) + 1; |
|
94 | + |
|
95 | + /** |
|
96 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
97 | + */ |
|
98 | + $input_fields = []; |
|
99 | + if (! empty($this->args['where'])) { |
|
100 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
105 | + * |
|
106 | + * For example, if we're querying for datetime as a field of event query, this will automatically |
|
107 | + * set the query to pull datetimes that belong to that event. |
|
108 | + * We can set more cases for other source types. |
|
109 | + */ |
|
110 | + if (is_object($this->source)) { |
|
111 | + switch (true) { |
|
112 | + // It's surely an event |
|
113 | + case $this->source instanceof Post: |
|
114 | + $where_params['EVT_ID'] = $this->source->ID; |
|
115 | + break; |
|
116 | + case $this->source instanceof EE_Event: |
|
117 | + $where_params['EVT_ID'] = $this->source->ID(); |
|
118 | + break; |
|
119 | + case $this->source instanceof EE_Ticket: |
|
120 | + $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
121 | + break; |
|
122 | + case $this->source instanceof EE_Checkin: |
|
123 | + $where_params['Checkin.CHK_ID'] = $this->source->ID(); |
|
124 | + break; |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Merge the input_fields with the default query_args |
|
130 | + */ |
|
131 | + if (! empty($input_fields)) { |
|
132 | + $where_params = array_merge($where_params, $input_fields); |
|
133 | + } |
|
134 | + |
|
135 | + // ID of the offset datetime. |
|
136 | + $offset = $this->get_offset(); |
|
137 | + |
|
138 | + /** |
|
139 | + * Map the orderby inputArgs to the WP_Query |
|
140 | + */ |
|
141 | + if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
142 | + $query_args['order_by'] = []; |
|
143 | + foreach ($this->args['where']['orderby'] as $orderby_input) { |
|
144 | + $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
145 | + } |
|
146 | + } elseif ($offset) { |
|
147 | + $compare = ! empty($last) ? '<' : '>'; |
|
148 | + $where_params['DTT_ID'] = array($compare, $offset); |
|
149 | + } |
|
150 | + |
|
151 | + if (! empty($this->args['where']['upcoming'])) { |
|
152 | + $where_params['DTT_EVT_start'] = array( |
|
153 | + '>', |
|
154 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + if (! empty($this->args['where']['active'])) { |
|
159 | + $where_params['DTT_EVT_start'] = array( |
|
160 | + '<', |
|
161 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
162 | + ); |
|
163 | + $where_params['DTT_EVT_end'] = array( |
|
164 | + '>', |
|
165 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
166 | + ); |
|
167 | + } |
|
168 | + |
|
169 | + if (! empty($this->args['where']['expired'])) { |
|
170 | + $where_params['DTT_EVT_end'] = array( |
|
171 | + '<', |
|
172 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
173 | + ); |
|
174 | + } |
|
175 | + |
|
176 | + $query_args[] = $where_params; |
|
177 | 177 | |
178 | - /** |
|
179 | - * Return the $query_args |
|
180 | - */ |
|
181 | - return $query_args; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
187 | - * friendly keys. |
|
188 | - * |
|
189 | - * @param array $where_args |
|
190 | - * @return array |
|
191 | - */ |
|
192 | - public function sanitizeInputFields(array $where_args) |
|
193 | - { |
|
194 | - $arg_mapping = [ |
|
195 | - 'eventId' => 'EVT_ID', |
|
196 | - 'ticketId' => 'Ticket.TKT_ID', |
|
197 | - ]; |
|
198 | - |
|
199 | - $query_args = []; |
|
200 | - |
|
201 | - foreach ($where_args as $arg => $value) { |
|
202 | - if (! array_key_exists($arg, $arg_mapping)) { |
|
203 | - continue; |
|
204 | - } |
|
205 | - |
|
206 | - if (is_array($value) && ! empty($value)) { |
|
207 | - $value = array_map( |
|
208 | - function ($value) { |
|
209 | - if (is_string($value)) { |
|
210 | - $value = sanitize_text_field($value); |
|
211 | - } |
|
212 | - return $value; |
|
213 | - }, |
|
214 | - $value |
|
215 | - ); |
|
216 | - } elseif (is_string($value)) { |
|
217 | - $value = sanitize_text_field($value); |
|
218 | - } |
|
219 | - $query_args[ $arg_mapping[ $arg ] ] = $value; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Return the Query Args |
|
224 | - */ |
|
225 | - return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
226 | - } |
|
178 | + /** |
|
179 | + * Return the $query_args |
|
180 | + */ |
|
181 | + return $query_args; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
187 | + * friendly keys. |
|
188 | + * |
|
189 | + * @param array $where_args |
|
190 | + * @return array |
|
191 | + */ |
|
192 | + public function sanitizeInputFields(array $where_args) |
|
193 | + { |
|
194 | + $arg_mapping = [ |
|
195 | + 'eventId' => 'EVT_ID', |
|
196 | + 'ticketId' => 'Ticket.TKT_ID', |
|
197 | + ]; |
|
198 | + |
|
199 | + $query_args = []; |
|
200 | + |
|
201 | + foreach ($where_args as $arg => $value) { |
|
202 | + if (! array_key_exists($arg, $arg_mapping)) { |
|
203 | + continue; |
|
204 | + } |
|
205 | + |
|
206 | + if (is_array($value) && ! empty($value)) { |
|
207 | + $value = array_map( |
|
208 | + function ($value) { |
|
209 | + if (is_string($value)) { |
|
210 | + $value = sanitize_text_field($value); |
|
211 | + } |
|
212 | + return $value; |
|
213 | + }, |
|
214 | + $value |
|
215 | + ); |
|
216 | + } elseif (is_string($value)) { |
|
217 | + $value = sanitize_text_field($value); |
|
218 | + } |
|
219 | + $query_args[ $arg_mapping[ $arg ] ] = $value; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Return the Query Args |
|
224 | + */ |
|
225 | + return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
226 | + } |
|
227 | 227 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
97 | 97 | */ |
98 | 98 | $input_fields = []; |
99 | - if (! empty($this->args['where'])) { |
|
99 | + if ( ! empty($this->args['where'])) { |
|
100 | 100 | $input_fields = $this->sanitizeInputFields($this->args['where']); |
101 | 101 | } |
102 | 102 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | /** |
129 | 129 | * Merge the input_fields with the default query_args |
130 | 130 | */ |
131 | - if (! empty($input_fields)) { |
|
131 | + if ( ! empty($input_fields)) { |
|
132 | 132 | $where_params = array_merge($where_params, $input_fields); |
133 | 133 | } |
134 | 134 | |
@@ -138,24 +138,24 @@ discard block |
||
138 | 138 | /** |
139 | 139 | * Map the orderby inputArgs to the WP_Query |
140 | 140 | */ |
141 | - if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
141 | + if ( ! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
142 | 142 | $query_args['order_by'] = []; |
143 | 143 | foreach ($this->args['where']['orderby'] as $orderby_input) { |
144 | - $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
144 | + $query_args['order_by'][$orderby_input['field']] = $orderby_input['order']; |
|
145 | 145 | } |
146 | 146 | } elseif ($offset) { |
147 | 147 | $compare = ! empty($last) ? '<' : '>'; |
148 | 148 | $where_params['DTT_ID'] = array($compare, $offset); |
149 | 149 | } |
150 | 150 | |
151 | - if (! empty($this->args['where']['upcoming'])) { |
|
151 | + if ( ! empty($this->args['where']['upcoming'])) { |
|
152 | 152 | $where_params['DTT_EVT_start'] = array( |
153 | 153 | '>', |
154 | 154 | EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
155 | 155 | ); |
156 | 156 | } |
157 | 157 | |
158 | - if (! empty($this->args['where']['active'])) { |
|
158 | + if ( ! empty($this->args['where']['active'])) { |
|
159 | 159 | $where_params['DTT_EVT_start'] = array( |
160 | 160 | '<', |
161 | 161 | EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | ); |
167 | 167 | } |
168 | 168 | |
169 | - if (! empty($this->args['where']['expired'])) { |
|
169 | + if ( ! empty($this->args['where']['expired'])) { |
|
170 | 170 | $where_params['DTT_EVT_end'] = array( |
171 | 171 | '<', |
172 | 172 | EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
@@ -199,13 +199,13 @@ discard block |
||
199 | 199 | $query_args = []; |
200 | 200 | |
201 | 201 | foreach ($where_args as $arg => $value) { |
202 | - if (! array_key_exists($arg, $arg_mapping)) { |
|
202 | + if ( ! array_key_exists($arg, $arg_mapping)) { |
|
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | |
206 | 206 | if (is_array($value) && ! empty($value)) { |
207 | 207 | $value = array_map( |
208 | - function ($value) { |
|
208 | + function($value) { |
|
209 | 209 | if (is_string($value)) { |
210 | 210 | $value = sanitize_text_field($value); |
211 | 211 | } |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | } elseif (is_string($value)) { |
217 | 217 | $value = sanitize_text_field($value); |
218 | 218 | } |
219 | - $query_args[ $arg_mapping[ $arg ] ] = $value; |
|
219 | + $query_args[$arg_mapping[$arg]] = $value; |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
@@ -17,139 +17,139 @@ |
||
17 | 17 | class VenueConnectionResolver extends AbstractConnectionResolver |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @return EEM_Venue |
|
22 | - * @throws EE_Error |
|
23 | - * @throws InvalidArgumentException |
|
24 | - * @throws InvalidDataTypeException |
|
25 | - * @throws InvalidInterfaceException |
|
26 | - */ |
|
27 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
28 | - public function get_query() |
|
29 | - { |
|
30 | - return EEM_Venue::instance(); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Return an array of items from the query |
|
36 | - * |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
40 | - public function get_items() |
|
41 | - { |
|
42 | - $results = $this->query->get_col($this->query_args); |
|
43 | - |
|
44 | - return ! empty($results) ? $results : []; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Determine whether the Query should execute. If it's determined that the query should |
|
50 | - * not be run based on context such as, but not limited to, who the user is, where in the |
|
51 | - * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
52 | - * Return false to prevent the query from executing. |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
57 | - public function should_execute() |
|
58 | - { |
|
59 | - if (false === $this->should_execute) { |
|
60 | - return false; |
|
61 | - } |
|
62 | - |
|
63 | - return $this->should_execute; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
69 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
70 | - * handle batch resolution of the posts. |
|
71 | - * |
|
72 | - * @return array |
|
73 | - */ |
|
74 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
75 | - public function get_query_args() |
|
76 | - { |
|
77 | - $query_args = []; |
|
78 | - |
|
79 | - /** |
|
80 | - * Prepare for later use |
|
81 | - */ |
|
82 | - $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
83 | - $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
84 | - |
|
85 | - /** |
|
86 | - * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
|
87 | - */ |
|
88 | - $query_args['limit'] = min( |
|
89 | - max(absint($first), absint($last), 10), |
|
90 | - $this->query_amount |
|
91 | - ) + 1; |
|
92 | - |
|
93 | - /** |
|
94 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
95 | - */ |
|
96 | - $input_fields = []; |
|
97 | - if (! empty($this->args['where'])) { |
|
98 | - $input_fields = $this->sanitize_input_fields($this->args['where']); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
103 | - * For example, if we're querying for datetime as a field of event query, this will automatically |
|
104 | - * set the query to pull datetimes that belong to that event. |
|
105 | - * We can set more cases for other source types. |
|
106 | - */ |
|
107 | - if (is_object($this->source)) { |
|
108 | - switch (true) { |
|
109 | - // Assumed to be an event |
|
110 | - case $this->source instanceof Post: |
|
111 | - $query_args[] = ['Event.EVT_ID' => $this->source->ID]; |
|
112 | - break; |
|
113 | - case $this->source instanceof EE_Event: |
|
114 | - $query_args[] = ['Event.EVT_ID' => $this->source->ID()]; |
|
115 | - break; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Merge the input_fields with the default query_args |
|
121 | - */ |
|
122 | - if (! empty($input_fields)) { |
|
123 | - $query_args = array_merge($query_args, $input_fields); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Return the $query_args |
|
128 | - */ |
|
129 | - return $query_args; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query |
|
135 | - * friendly keys. There's probably a cleaner/more dynamic way to approach this, but |
|
136 | - * this was quick. I'd be down to explore more dynamic ways to map this, but for |
|
137 | - * now this gets the job done. |
|
138 | - * |
|
139 | - * @param array $query_args |
|
140 | - * @return array |
|
141 | - */ |
|
142 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
143 | - public function sanitize_input_fields(array $query_args) |
|
144 | - { |
|
145 | - $arg_mapping = [ |
|
146 | - 'orderBy' => 'order_by', |
|
147 | - 'order' => 'order', |
|
148 | - ]; |
|
149 | - |
|
150 | - /** |
|
151 | - * Return the Query Args |
|
152 | - */ |
|
153 | - return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
154 | - } |
|
20 | + /** |
|
21 | + * @return EEM_Venue |
|
22 | + * @throws EE_Error |
|
23 | + * @throws InvalidArgumentException |
|
24 | + * @throws InvalidDataTypeException |
|
25 | + * @throws InvalidInterfaceException |
|
26 | + */ |
|
27 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
28 | + public function get_query() |
|
29 | + { |
|
30 | + return EEM_Venue::instance(); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Return an array of items from the query |
|
36 | + * |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
40 | + public function get_items() |
|
41 | + { |
|
42 | + $results = $this->query->get_col($this->query_args); |
|
43 | + |
|
44 | + return ! empty($results) ? $results : []; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Determine whether the Query should execute. If it's determined that the query should |
|
50 | + * not be run based on context such as, but not limited to, who the user is, where in the |
|
51 | + * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
52 | + * Return false to prevent the query from executing. |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
57 | + public function should_execute() |
|
58 | + { |
|
59 | + if (false === $this->should_execute) { |
|
60 | + return false; |
|
61 | + } |
|
62 | + |
|
63 | + return $this->should_execute; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
69 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
70 | + * handle batch resolution of the posts. |
|
71 | + * |
|
72 | + * @return array |
|
73 | + */ |
|
74 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
75 | + public function get_query_args() |
|
76 | + { |
|
77 | + $query_args = []; |
|
78 | + |
|
79 | + /** |
|
80 | + * Prepare for later use |
|
81 | + */ |
|
82 | + $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
83 | + $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
84 | + |
|
85 | + /** |
|
86 | + * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
|
87 | + */ |
|
88 | + $query_args['limit'] = min( |
|
89 | + max(absint($first), absint($last), 10), |
|
90 | + $this->query_amount |
|
91 | + ) + 1; |
|
92 | + |
|
93 | + /** |
|
94 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
95 | + */ |
|
96 | + $input_fields = []; |
|
97 | + if (! empty($this->args['where'])) { |
|
98 | + $input_fields = $this->sanitize_input_fields($this->args['where']); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
103 | + * For example, if we're querying for datetime as a field of event query, this will automatically |
|
104 | + * set the query to pull datetimes that belong to that event. |
|
105 | + * We can set more cases for other source types. |
|
106 | + */ |
|
107 | + if (is_object($this->source)) { |
|
108 | + switch (true) { |
|
109 | + // Assumed to be an event |
|
110 | + case $this->source instanceof Post: |
|
111 | + $query_args[] = ['Event.EVT_ID' => $this->source->ID]; |
|
112 | + break; |
|
113 | + case $this->source instanceof EE_Event: |
|
114 | + $query_args[] = ['Event.EVT_ID' => $this->source->ID()]; |
|
115 | + break; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Merge the input_fields with the default query_args |
|
121 | + */ |
|
122 | + if (! empty($input_fields)) { |
|
123 | + $query_args = array_merge($query_args, $input_fields); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Return the $query_args |
|
128 | + */ |
|
129 | + return $query_args; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query |
|
135 | + * friendly keys. There's probably a cleaner/more dynamic way to approach this, but |
|
136 | + * this was quick. I'd be down to explore more dynamic ways to map this, but for |
|
137 | + * now this gets the job done. |
|
138 | + * |
|
139 | + * @param array $query_args |
|
140 | + * @return array |
|
141 | + */ |
|
142 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
143 | + public function sanitize_input_fields(array $query_args) |
|
144 | + { |
|
145 | + $arg_mapping = [ |
|
146 | + 'orderBy' => 'order_by', |
|
147 | + 'order' => 'order', |
|
148 | + ]; |
|
149 | + |
|
150 | + /** |
|
151 | + * Return the Query Args |
|
152 | + */ |
|
153 | + return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
154 | + } |
|
155 | 155 | } |
@@ -17,170 +17,170 @@ |
||
17 | 17 | class TicketConnectionResolver extends AbstractConnectionResolver |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @return EEM_Ticket |
|
22 | - * @throws EE_Error |
|
23 | - * @throws InvalidArgumentException |
|
24 | - * @throws InvalidDataTypeException |
|
25 | - * @throws InvalidInterfaceException |
|
26 | - */ |
|
27 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
28 | - public function get_query() |
|
29 | - { |
|
30 | - return EEM_Ticket::instance(); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Return an array of items from the query |
|
36 | - * |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
40 | - public function get_items() |
|
41 | - { |
|
42 | - $results = $this->query->get_col($this->query_args); |
|
43 | - |
|
44 | - return ! empty($results) ? $results : []; |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Determine whether the Query should execute. If it's determined that the query should |
|
50 | - * not be run based on context such as, but not limited to, who the user is, where in the |
|
51 | - * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
52 | - * Return false to prevent the query from executing. |
|
53 | - * |
|
54 | - * @return bool |
|
55 | - */ |
|
56 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
57 | - public function should_execute() |
|
58 | - { |
|
59 | - if (false === $this->should_execute) { |
|
60 | - return false; |
|
61 | - } |
|
62 | - |
|
63 | - return $this->should_execute; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
69 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
70 | - * handle batch resolution of the posts. |
|
71 | - * |
|
72 | - * @return array |
|
73 | - * @throws EE_Error |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws ReflectionException |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - */ |
|
79 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
80 | - public function get_query_args() |
|
81 | - { |
|
82 | - $where_params = []; |
|
83 | - $query_args = []; |
|
84 | - /** |
|
85 | - * Prepare for later use |
|
86 | - */ |
|
87 | - $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
88 | - $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
89 | - |
|
90 | - /** |
|
91 | - * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
|
92 | - */ |
|
93 | - $query_args['limit'] = min( |
|
94 | - max(absint($first), absint($last), 10), |
|
95 | - $this->query_amount |
|
96 | - ) + 1; |
|
97 | - |
|
98 | - /** |
|
99 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
100 | - */ |
|
101 | - $input_fields = []; |
|
102 | - if (! empty($this->args['where'])) { |
|
103 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
108 | - */ |
|
109 | - if ($this->source instanceof EE_Datetime) { |
|
110 | - $where_params['Datetime.DTT_ID'] = $this->source->ID(); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Merge the input_fields with the default query_args |
|
115 | - */ |
|
116 | - if (! empty($input_fields)) { |
|
117 | - $where_params = array_merge($where_params, $input_fields); |
|
118 | - } |
|
119 | - |
|
120 | - // ID of the offset datetime. |
|
121 | - $offset = $this->get_offset(); |
|
122 | - |
|
123 | - /** |
|
124 | - * Map the orderby inputArgs to the WP_Query |
|
125 | - */ |
|
126 | - if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
127 | - $query_args['order_by'] = []; |
|
128 | - foreach ($this->args['where']['orderby'] as $orderby_input) { |
|
129 | - $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
130 | - } |
|
131 | - } elseif ($offset) { |
|
132 | - $compare = ! empty($last) ? '<' : '>'; |
|
133 | - $where_params['TKT_ID'] = array($compare, $offset); |
|
134 | - } |
|
135 | - |
|
136 | - $query_args[] = $where_params; |
|
137 | - |
|
138 | - /** |
|
139 | - * Return the $query_args |
|
140 | - */ |
|
141 | - return $query_args; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
147 | - * friendly keys. |
|
148 | - * |
|
149 | - * @param array $where_args |
|
150 | - * @return array |
|
151 | - */ |
|
152 | - public function sanitizeInputFields(array $where_args) |
|
153 | - { |
|
154 | - $arg_mapping = [ |
|
155 | - 'datetimeId' => 'Datetime.DTT_ID', |
|
156 | - ]; |
|
157 | - |
|
158 | - $query_args = []; |
|
159 | - |
|
160 | - foreach ($where_args as $arg => $value) { |
|
161 | - if (! array_key_exists($arg, $arg_mapping)) { |
|
162 | - continue; |
|
163 | - } |
|
164 | - |
|
165 | - if (is_array($value) && ! empty($value)) { |
|
166 | - $value = array_map( |
|
167 | - function ($value) { |
|
168 | - if (is_string($value)) { |
|
169 | - $value = sanitize_text_field($value); |
|
170 | - } |
|
171 | - return $value; |
|
172 | - }, |
|
173 | - $value |
|
174 | - ); |
|
175 | - } elseif (is_string($value)) { |
|
176 | - $value = sanitize_text_field($value); |
|
177 | - } |
|
178 | - $query_args[ $arg_mapping[ $arg ] ] = $value; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Return the Query Args |
|
183 | - */ |
|
184 | - return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
185 | - } |
|
20 | + /** |
|
21 | + * @return EEM_Ticket |
|
22 | + * @throws EE_Error |
|
23 | + * @throws InvalidArgumentException |
|
24 | + * @throws InvalidDataTypeException |
|
25 | + * @throws InvalidInterfaceException |
|
26 | + */ |
|
27 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
28 | + public function get_query() |
|
29 | + { |
|
30 | + return EEM_Ticket::instance(); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Return an array of items from the query |
|
36 | + * |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
40 | + public function get_items() |
|
41 | + { |
|
42 | + $results = $this->query->get_col($this->query_args); |
|
43 | + |
|
44 | + return ! empty($results) ? $results : []; |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Determine whether the Query should execute. If it's determined that the query should |
|
50 | + * not be run based on context such as, but not limited to, who the user is, where in the |
|
51 | + * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
52 | + * Return false to prevent the query from executing. |
|
53 | + * |
|
54 | + * @return bool |
|
55 | + */ |
|
56 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
57 | + public function should_execute() |
|
58 | + { |
|
59 | + if (false === $this->should_execute) { |
|
60 | + return false; |
|
61 | + } |
|
62 | + |
|
63 | + return $this->should_execute; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
69 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
70 | + * handle batch resolution of the posts. |
|
71 | + * |
|
72 | + * @return array |
|
73 | + * @throws EE_Error |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws ReflectionException |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + */ |
|
79 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
80 | + public function get_query_args() |
|
81 | + { |
|
82 | + $where_params = []; |
|
83 | + $query_args = []; |
|
84 | + /** |
|
85 | + * Prepare for later use |
|
86 | + */ |
|
87 | + $last = ! empty($this->args['last']) ? $this->args['last'] : null; |
|
88 | + $first = ! empty($this->args['first']) ? $this->args['first'] : null; |
|
89 | + |
|
90 | + /** |
|
91 | + * Set limit the highest value of $first and $last, with a (filterable) max of 100 |
|
92 | + */ |
|
93 | + $query_args['limit'] = min( |
|
94 | + max(absint($first), absint($last), 10), |
|
95 | + $this->query_amount |
|
96 | + ) + 1; |
|
97 | + |
|
98 | + /** |
|
99 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
100 | + */ |
|
101 | + $input_fields = []; |
|
102 | + if (! empty($this->args['where'])) { |
|
103 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
108 | + */ |
|
109 | + if ($this->source instanceof EE_Datetime) { |
|
110 | + $where_params['Datetime.DTT_ID'] = $this->source->ID(); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Merge the input_fields with the default query_args |
|
115 | + */ |
|
116 | + if (! empty($input_fields)) { |
|
117 | + $where_params = array_merge($where_params, $input_fields); |
|
118 | + } |
|
119 | + |
|
120 | + // ID of the offset datetime. |
|
121 | + $offset = $this->get_offset(); |
|
122 | + |
|
123 | + /** |
|
124 | + * Map the orderby inputArgs to the WP_Query |
|
125 | + */ |
|
126 | + if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
127 | + $query_args['order_by'] = []; |
|
128 | + foreach ($this->args['where']['orderby'] as $orderby_input) { |
|
129 | + $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
130 | + } |
|
131 | + } elseif ($offset) { |
|
132 | + $compare = ! empty($last) ? '<' : '>'; |
|
133 | + $where_params['TKT_ID'] = array($compare, $offset); |
|
134 | + } |
|
135 | + |
|
136 | + $query_args[] = $where_params; |
|
137 | + |
|
138 | + /** |
|
139 | + * Return the $query_args |
|
140 | + */ |
|
141 | + return $query_args; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
147 | + * friendly keys. |
|
148 | + * |
|
149 | + * @param array $where_args |
|
150 | + * @return array |
|
151 | + */ |
|
152 | + public function sanitizeInputFields(array $where_args) |
|
153 | + { |
|
154 | + $arg_mapping = [ |
|
155 | + 'datetimeId' => 'Datetime.DTT_ID', |
|
156 | + ]; |
|
157 | + |
|
158 | + $query_args = []; |
|
159 | + |
|
160 | + foreach ($where_args as $arg => $value) { |
|
161 | + if (! array_key_exists($arg, $arg_mapping)) { |
|
162 | + continue; |
|
163 | + } |
|
164 | + |
|
165 | + if (is_array($value) && ! empty($value)) { |
|
166 | + $value = array_map( |
|
167 | + function ($value) { |
|
168 | + if (is_string($value)) { |
|
169 | + $value = sanitize_text_field($value); |
|
170 | + } |
|
171 | + return $value; |
|
172 | + }, |
|
173 | + $value |
|
174 | + ); |
|
175 | + } elseif (is_string($value)) { |
|
176 | + $value = sanitize_text_field($value); |
|
177 | + } |
|
178 | + $query_args[ $arg_mapping[ $arg ] ] = $value; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Return the Query Args |
|
183 | + */ |
|
184 | + return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
185 | + } |
|
186 | 186 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
100 | 100 | */ |
101 | 101 | $input_fields = []; |
102 | - if (! empty($this->args['where'])) { |
|
102 | + if ( ! empty($this->args['where'])) { |
|
103 | 103 | $input_fields = $this->sanitizeInputFields($this->args['where']); |
104 | 104 | } |
105 | 105 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | /** |
114 | 114 | * Merge the input_fields with the default query_args |
115 | 115 | */ |
116 | - if (! empty($input_fields)) { |
|
116 | + if ( ! empty($input_fields)) { |
|
117 | 117 | $where_params = array_merge($where_params, $input_fields); |
118 | 118 | } |
119 | 119 | |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | /** |
124 | 124 | * Map the orderby inputArgs to the WP_Query |
125 | 125 | */ |
126 | - if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
126 | + if ( ! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
127 | 127 | $query_args['order_by'] = []; |
128 | 128 | foreach ($this->args['where']['orderby'] as $orderby_input) { |
129 | - $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
129 | + $query_args['order_by'][$orderby_input['field']] = $orderby_input['order']; |
|
130 | 130 | } |
131 | 131 | } elseif ($offset) { |
132 | 132 | $compare = ! empty($last) ? '<' : '>'; |
@@ -158,13 +158,13 @@ discard block |
||
158 | 158 | $query_args = []; |
159 | 159 | |
160 | 160 | foreach ($where_args as $arg => $value) { |
161 | - if (! array_key_exists($arg, $arg_mapping)) { |
|
161 | + if ( ! array_key_exists($arg, $arg_mapping)) { |
|
162 | 162 | continue; |
163 | 163 | } |
164 | 164 | |
165 | 165 | if (is_array($value) && ! empty($value)) { |
166 | 166 | $value = array_map( |
167 | - function ($value) { |
|
167 | + function($value) { |
|
168 | 168 | if (is_string($value)) { |
169 | 169 | $value = sanitize_text_field($value); |
170 | 170 | } |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | } elseif (is_string($value)) { |
176 | 176 | $value = sanitize_text_field($value); |
177 | 177 | } |
178 | - $query_args[ $arg_mapping[ $arg ] ] = $value; |
|
178 | + $query_args[$arg_mapping[$arg]] = $value; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | /** |
@@ -15,32 +15,32 @@ |
||
15 | 15 | class DatetimesConnectionOrderbyEnum extends EnumBase |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * DatetimesConnectionOrderbyEnum constructor. |
|
20 | - */ |
|
21 | - public function __construct() |
|
22 | - { |
|
23 | - $this->setName('DatetimesConnectionOrderbyEnum'); |
|
24 | - $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
25 | - parent::__construct(); |
|
26 | - } |
|
18 | + /** |
|
19 | + * DatetimesConnectionOrderbyEnum constructor. |
|
20 | + */ |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + $this->setName('DatetimesConnectionOrderbyEnum'); |
|
24 | + $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @return array |
|
31 | - * @since $VID:$ |
|
32 | - */ |
|
33 | - protected function getValues() |
|
34 | - { |
|
35 | - return [ |
|
36 | - 'NAME' => [ |
|
37 | - 'value' => 'DTT_name', |
|
38 | - 'description' => esc_html__('Order by name', 'event_espresso'), |
|
39 | - ], |
|
40 | - 'START_DATE' => [ |
|
41 | - 'value' => 'DTT_EVT_start', |
|
42 | - 'description' => esc_html__('Order by start date', 'event_espresso'), |
|
43 | - ], |
|
44 | - ]; |
|
45 | - } |
|
29 | + /** |
|
30 | + * @return array |
|
31 | + * @since $VID:$ |
|
32 | + */ |
|
33 | + protected function getValues() |
|
34 | + { |
|
35 | + return [ |
|
36 | + 'NAME' => [ |
|
37 | + 'value' => 'DTT_name', |
|
38 | + 'description' => esc_html__('Order by name', 'event_espresso'), |
|
39 | + ], |
|
40 | + 'START_DATE' => [ |
|
41 | + 'value' => 'DTT_EVT_start', |
|
42 | + 'description' => esc_html__('Order by start date', 'event_espresso'), |
|
43 | + ], |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | } |
@@ -15,32 +15,32 @@ |
||
15 | 15 | class TicketsConnectionOrderbyEnum extends EnumBase |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * TicketsConnectionOrderbyEnum constructor. |
|
20 | - */ |
|
21 | - public function __construct() |
|
22 | - { |
|
23 | - $this->setName('TicketsConnectionOrderbyEnum'); |
|
24 | - $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
25 | - parent::__construct(); |
|
26 | - } |
|
18 | + /** |
|
19 | + * TicketsConnectionOrderbyEnum constructor. |
|
20 | + */ |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + $this->setName('TicketsConnectionOrderbyEnum'); |
|
24 | + $this->setDescription(esc_html__('Field to order the connection by', 'event_espresso')); |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @return array |
|
31 | - * @since $VID:$ |
|
32 | - */ |
|
33 | - protected function getValues() |
|
34 | - { |
|
35 | - return [ |
|
36 | - 'NAME' => [ |
|
37 | - 'value' => 'TKT_name', |
|
38 | - 'description' => esc_html__('Order by name', 'event_espresso'), |
|
39 | - ], |
|
40 | - 'START_DATE' => [ |
|
41 | - 'value' => 'TKT_start_date', |
|
42 | - 'description' => esc_html__('Order by start date', 'event_espresso'), |
|
43 | - ], |
|
44 | - ]; |
|
45 | - } |
|
29 | + /** |
|
30 | + * @return array |
|
31 | + * @since $VID:$ |
|
32 | + */ |
|
33 | + protected function getValues() |
|
34 | + { |
|
35 | + return [ |
|
36 | + 'NAME' => [ |
|
37 | + 'value' => 'TKT_name', |
|
38 | + 'description' => esc_html__('Order by name', 'event_espresso'), |
|
39 | + ], |
|
40 | + 'START_DATE' => [ |
|
41 | + 'value' => 'TKT_start_date', |
|
42 | + 'description' => esc_html__('Order by start date', 'event_espresso'), |
|
43 | + ], |
|
44 | + ]; |
|
45 | + } |
|
46 | 46 | } |
@@ -19,32 +19,32 @@ |
||
19 | 19 | class DatetimesConnectionOrderbyInput extends InputBase |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * DatetimesConnectionOrderbyInput constructor. |
|
24 | - */ |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->setName('DatetimesConnectionOrderbyInput'); |
|
28 | - $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
|
29 | - parent::__construct(); |
|
30 | - } |
|
22 | + /** |
|
23 | + * DatetimesConnectionOrderbyInput constructor. |
|
24 | + */ |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->setName('DatetimesConnectionOrderbyInput'); |
|
28 | + $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
|
29 | + parent::__construct(); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @return GraphQLFieldInterface[] |
|
35 | - * @since $VID:$ |
|
36 | - */ |
|
37 | - protected function getFields() |
|
38 | - { |
|
39 | - return [ |
|
40 | - new GraphQLField( |
|
41 | - 'field', |
|
42 | - ['non_null' => 'DatetimesConnectionOrderbyEnum'] |
|
43 | - ), |
|
44 | - new GraphQLField( |
|
45 | - 'order', |
|
46 | - 'OrderEnum' |
|
47 | - ), |
|
48 | - ]; |
|
49 | - } |
|
33 | + /** |
|
34 | + * @return GraphQLFieldInterface[] |
|
35 | + * @since $VID:$ |
|
36 | + */ |
|
37 | + protected function getFields() |
|
38 | + { |
|
39 | + return [ |
|
40 | + new GraphQLField( |
|
41 | + 'field', |
|
42 | + ['non_null' => 'DatetimesConnectionOrderbyEnum'] |
|
43 | + ), |
|
44 | + new GraphQLField( |
|
45 | + 'order', |
|
46 | + 'OrderEnum' |
|
47 | + ), |
|
48 | + ]; |
|
49 | + } |
|
50 | 50 | } |
@@ -19,32 +19,32 @@ |
||
19 | 19 | class TicketsConnectionOrderbyInput extends InputBase |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * TicketsConnectionOrderbyInput constructor. |
|
24 | - */ |
|
25 | - public function __construct() |
|
26 | - { |
|
27 | - $this->setName('TicketsConnectionOrderbyInput'); |
|
28 | - $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
|
29 | - parent::__construct(); |
|
30 | - } |
|
22 | + /** |
|
23 | + * TicketsConnectionOrderbyInput constructor. |
|
24 | + */ |
|
25 | + public function __construct() |
|
26 | + { |
|
27 | + $this->setName('TicketsConnectionOrderbyInput'); |
|
28 | + $this->setDescription(esc_html__('Options for ordering the connection', 'event_espresso')); |
|
29 | + parent::__construct(); |
|
30 | + } |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * @return GraphQLFieldInterface[] |
|
35 | - * @since $VID:$ |
|
36 | - */ |
|
37 | - protected function getFields() |
|
38 | - { |
|
39 | - return [ |
|
40 | - new GraphQLField( |
|
41 | - 'field', |
|
42 | - ['non_null' => 'TicketsConnectionOrderbyEnum'] |
|
43 | - ), |
|
44 | - new GraphQLField( |
|
45 | - 'order', |
|
46 | - 'OrderEnum' |
|
47 | - ), |
|
48 | - ]; |
|
49 | - } |
|
33 | + /** |
|
34 | + * @return GraphQLFieldInterface[] |
|
35 | + * @since $VID:$ |
|
36 | + */ |
|
37 | + protected function getFields() |
|
38 | + { |
|
39 | + return [ |
|
40 | + new GraphQLField( |
|
41 | + 'field', |
|
42 | + ['non_null' => 'TicketsConnectionOrderbyEnum'] |
|
43 | + ), |
|
44 | + new GraphQLField( |
|
45 | + 'order', |
|
46 | + 'OrderEnum' |
|
47 | + ), |
|
48 | + ]; |
|
49 | + } |
|
50 | 50 | } |
@@ -19,93 +19,93 @@ |
||
19 | 19 | class DatetimeTicketsConnection implements ConnectionInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var EEM_Ticket $model |
|
24 | - */ |
|
25 | - protected $model; |
|
22 | + /** |
|
23 | + * @var EEM_Ticket $model |
|
24 | + */ |
|
25 | + protected $model; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * DatetimeConnection constructor. |
|
30 | - * |
|
31 | - * @param EEM_Ticket $model |
|
32 | - */ |
|
33 | - public function __construct(EEM_Ticket $model) |
|
34 | - { |
|
35 | - $this->model = $model; |
|
36 | - } |
|
28 | + /** |
|
29 | + * DatetimeConnection constructor. |
|
30 | + * |
|
31 | + * @param EEM_Ticket $model |
|
32 | + */ |
|
33 | + public function __construct(EEM_Ticket $model) |
|
34 | + { |
|
35 | + $this->model = $model; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @return array |
|
41 | - * @since $VID:$ |
|
42 | - */ |
|
43 | - public function config() |
|
44 | - { |
|
45 | - return [ |
|
46 | - 'fromType' => 'Datetime', |
|
47 | - 'toType' => 'Ticket', |
|
48 | - 'fromFieldName' => 'tickets', |
|
49 | - 'connectionTypeName' => 'DatetimeTicketsConnection', |
|
50 | - 'connectionArgs' => self::get_connection_args(), |
|
51 | - 'resolve' => [$this, 'resolveConnection'], |
|
52 | - 'resolveNode' => [$this, 'resolveNode'] |
|
53 | - ]; |
|
54 | - } |
|
39 | + /** |
|
40 | + * @return array |
|
41 | + * @since $VID:$ |
|
42 | + */ |
|
43 | + public function config() |
|
44 | + { |
|
45 | + return [ |
|
46 | + 'fromType' => 'Datetime', |
|
47 | + 'toType' => 'Ticket', |
|
48 | + 'fromFieldName' => 'tickets', |
|
49 | + 'connectionTypeName' => 'DatetimeTicketsConnection', |
|
50 | + 'connectionArgs' => self::get_connection_args(), |
|
51 | + 'resolve' => [$this, 'resolveConnection'], |
|
52 | + 'resolveNode' => [$this, 'resolveNode'] |
|
53 | + ]; |
|
54 | + } |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * @param $entity |
|
59 | - * @param $args |
|
60 | - * @param $context |
|
61 | - * @param $info |
|
62 | - * @return array |
|
63 | - * @throws Exception |
|
64 | - * @since $VID:$ |
|
65 | - */ |
|
66 | - public function resolveConnection($entity, $args, $context, $info) |
|
67 | - { |
|
68 | - $resolver = new TicketConnectionResolver($entity, $args, $context, $info); |
|
69 | - return $resolver->get_connection(); |
|
70 | - } |
|
57 | + /** |
|
58 | + * @param $entity |
|
59 | + * @param $args |
|
60 | + * @param $context |
|
61 | + * @param $info |
|
62 | + * @return array |
|
63 | + * @throws Exception |
|
64 | + * @since $VID:$ |
|
65 | + */ |
|
66 | + public function resolveConnection($entity, $args, $context, $info) |
|
67 | + { |
|
68 | + $resolver = new TicketConnectionResolver($entity, $args, $context, $info); |
|
69 | + return $resolver->get_connection(); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * @param $id |
|
75 | - * @param $args |
|
76 | - * @param $context |
|
77 | - * @param $info |
|
78 | - * @return EE_Base_Class |
|
79 | - * @since $VID:$ |
|
80 | - */ |
|
81 | - public function resolveNode($id, $args, $context, $info) |
|
82 | - { |
|
83 | - return $this->model->get_one_by_ID($id); |
|
84 | - } |
|
73 | + /** |
|
74 | + * @param $id |
|
75 | + * @param $args |
|
76 | + * @param $context |
|
77 | + * @param $info |
|
78 | + * @return EE_Base_Class |
|
79 | + * @since $VID:$ |
|
80 | + */ |
|
81 | + public function resolveNode($id, $args, $context, $info) |
|
82 | + { |
|
83 | + return $this->model->get_one_by_ID($id); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Given an optional array of args, this returns the args to be used in the connection |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @param array $args The args to modify the defaults |
|
91 | - * |
|
92 | - * @return array |
|
93 | - */ |
|
94 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
95 | - public static function get_connection_args($args = []) |
|
96 | - { |
|
97 | - return array_merge( |
|
98 | - [ |
|
99 | - 'orderby' => [ |
|
100 | - 'type' => ['list_of' => 'TicketsConnectionOrderbyInput'], |
|
101 | - 'description' => esc_html__('What paramater to use to order the objects by.', 'event_espresso'), |
|
102 | - ], |
|
103 | - 'datetimeId' => [ |
|
104 | - 'type' => 'Int', |
|
105 | - 'description' => esc_html__('Datetime ID of the ticket.', 'event_espresso'), |
|
106 | - ], |
|
107 | - ], |
|
108 | - $args |
|
109 | - ); |
|
110 | - } |
|
86 | + /** |
|
87 | + * Given an optional array of args, this returns the args to be used in the connection |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @param array $args The args to modify the defaults |
|
91 | + * |
|
92 | + * @return array |
|
93 | + */ |
|
94 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
95 | + public static function get_connection_args($args = []) |
|
96 | + { |
|
97 | + return array_merge( |
|
98 | + [ |
|
99 | + 'orderby' => [ |
|
100 | + 'type' => ['list_of' => 'TicketsConnectionOrderbyInput'], |
|
101 | + 'description' => esc_html__('What paramater to use to order the objects by.', 'event_espresso'), |
|
102 | + ], |
|
103 | + 'datetimeId' => [ |
|
104 | + 'type' => 'Int', |
|
105 | + 'description' => esc_html__('Datetime ID of the ticket.', 'event_espresso'), |
|
106 | + ], |
|
107 | + ], |
|
108 | + $args |
|
109 | + ); |
|
110 | + } |
|
111 | 111 | } |
@@ -20,67 +20,67 @@ |
||
20 | 20 | class TicketDatetimesConnection implements ConnectionInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var EEM_Datetime $model |
|
25 | - */ |
|
26 | - protected $model; |
|
23 | + /** |
|
24 | + * @var EEM_Datetime $model |
|
25 | + */ |
|
26 | + protected $model; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * DatetimeConnection constructor. |
|
31 | - * |
|
32 | - * @param EEM_Datetime $model |
|
33 | - */ |
|
34 | - public function __construct(EEM_Datetime $model) |
|
35 | - { |
|
36 | - $this->model = $model; |
|
37 | - } |
|
29 | + /** |
|
30 | + * DatetimeConnection constructor. |
|
31 | + * |
|
32 | + * @param EEM_Datetime $model |
|
33 | + */ |
|
34 | + public function __construct(EEM_Datetime $model) |
|
35 | + { |
|
36 | + $this->model = $model; |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @return array |
|
42 | - * @since $VID:$ |
|
43 | - */ |
|
44 | - public function config() |
|
45 | - { |
|
46 | - return [ |
|
47 | - 'fromType' => 'Ticket', |
|
48 | - 'toType' => 'Datetime', |
|
49 | - 'fromFieldName' => 'datetimes', |
|
50 | - 'connectionTypeName' => 'TicketDatetimesConnection', |
|
51 | - 'connectionArgs' => EventDatetimesConnection::get_connection_args(), |
|
52 | - 'resolve' => [$this, 'resolveConnection'], |
|
53 | - 'resolveNode' => [$this, 'resolveNode'], |
|
54 | - ]; |
|
55 | - } |
|
40 | + /** |
|
41 | + * @return array |
|
42 | + * @since $VID:$ |
|
43 | + */ |
|
44 | + public function config() |
|
45 | + { |
|
46 | + return [ |
|
47 | + 'fromType' => 'Ticket', |
|
48 | + 'toType' => 'Datetime', |
|
49 | + 'fromFieldName' => 'datetimes', |
|
50 | + 'connectionTypeName' => 'TicketDatetimesConnection', |
|
51 | + 'connectionArgs' => EventDatetimesConnection::get_connection_args(), |
|
52 | + 'resolve' => [$this, 'resolveConnection'], |
|
53 | + 'resolveNode' => [$this, 'resolveNode'], |
|
54 | + ]; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * @param $entity |
|
60 | - * @param $args |
|
61 | - * @param $context |
|
62 | - * @param $info |
|
63 | - * @return array |
|
64 | - * @throws Exception |
|
65 | - * @since $VID:$ |
|
66 | - */ |
|
67 | - public function resolveConnection($entity, $args, $context, $info) |
|
68 | - { |
|
69 | - $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info); |
|
70 | - return $resolver->get_connection(); |
|
71 | - } |
|
58 | + /** |
|
59 | + * @param $entity |
|
60 | + * @param $args |
|
61 | + * @param $context |
|
62 | + * @param $info |
|
63 | + * @return array |
|
64 | + * @throws Exception |
|
65 | + * @since $VID:$ |
|
66 | + */ |
|
67 | + public function resolveConnection($entity, $args, $context, $info) |
|
68 | + { |
|
69 | + $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info); |
|
70 | + return $resolver->get_connection(); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | - /** |
|
75 | - * @param $id |
|
76 | - * @param $args |
|
77 | - * @param $context |
|
78 | - * @param $info |
|
79 | - * @return EE_Base_Class |
|
80 | - * @since $VID:$ |
|
81 | - */ |
|
82 | - public function resolveNode($id, $args, $context, $info) |
|
83 | - { |
|
84 | - return $this->model->get_one_by_ID($id); |
|
85 | - } |
|
74 | + /** |
|
75 | + * @param $id |
|
76 | + * @param $args |
|
77 | + * @param $context |
|
78 | + * @param $info |
|
79 | + * @return EE_Base_Class |
|
80 | + * @since $VID:$ |
|
81 | + */ |
|
82 | + public function resolveNode($id, $args, $context, $info) |
|
83 | + { |
|
84 | + return $this->model->get_one_by_ID($id); |
|
85 | + } |
|
86 | 86 | } |