@@ -32,266 +32,266 @@ |
||
32 | 32 | abstract class TypeBase implements TypeInterface |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var string $namespace The graphql namespace/prefix. |
|
37 | - */ |
|
38 | - protected $namespace = 'Espresso'; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var EEM_Base $model |
|
42 | - */ |
|
43 | - protected $model; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var string $name |
|
47 | - */ |
|
48 | - protected $name = ''; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string $description |
|
52 | - */ |
|
53 | - protected $description = ''; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var GraphQLFieldInterface[] $fields |
|
57 | - */ |
|
58 | - protected $fields = []; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var array $graphql_to_model_map |
|
62 | - */ |
|
63 | - protected $graphql_to_model_map = []; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var FieldResolver $field_resolver |
|
67 | - */ |
|
68 | - protected $field_resolver; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var bool $is_custom_post_type |
|
72 | - */ |
|
73 | - protected $is_custom_post_type = false; |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * TypeBase constructor. |
|
78 | - */ |
|
79 | - public function __construct() |
|
80 | - { |
|
81 | - $this->setFields($this->getFields()); |
|
82 | - $this->field_resolver = new FieldResolver( |
|
83 | - $this->model, |
|
84 | - $this->getFieldsForResolver() |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return GraphQLFieldInterface[] |
|
91 | - * @since $VID:$ |
|
92 | - */ |
|
93 | - abstract protected function getFields(); |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function name() |
|
100 | - { |
|
101 | - return $this->name; |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $name |
|
107 | - */ |
|
108 | - protected function setName($name) |
|
109 | - { |
|
110 | - $this->name = $name; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public function description() |
|
118 | - { |
|
119 | - return $this->description; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @param string $description |
|
125 | - */ |
|
126 | - protected function setDescription($description) |
|
127 | - { |
|
128 | - $this->description = $description; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return GraphQLFieldInterface[] |
|
134 | - * @since $VID:$ |
|
135 | - */ |
|
136 | - public function fields() |
|
137 | - { |
|
138 | - return (array) $this->fields; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param GraphQLFieldInterface[] $fields |
|
144 | - */ |
|
145 | - protected function setFields(array $fields) |
|
146 | - { |
|
147 | - foreach ($fields as $field) { |
|
148 | - if ($field instanceof GraphQLField) { |
|
149 | - $this->fields[] = $field; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Creates a key map for internal resolver. |
|
157 | - * |
|
158 | - * @return array |
|
159 | - * @since $VID:$ |
|
160 | - */ |
|
161 | - public function getFieldsForResolver() |
|
162 | - { |
|
163 | - $fields = []; |
|
164 | - foreach ($this->fields() as $field) { |
|
165 | - if ($field->useForOutput()) { |
|
166 | - $fields[ $field->name() ] = $field; |
|
167 | - } |
|
168 | - } |
|
169 | - return $fields; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public function isCustomPostType() |
|
177 | - { |
|
178 | - return $this->is_custom_post_type; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @param bool $is_custom_post_type |
|
184 | - */ |
|
185 | - protected function setIsCustomPostType($is_custom_post_type) |
|
186 | - { |
|
187 | - $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * @param int $value |
|
193 | - * @return int |
|
194 | - * @since $VID:$ |
|
195 | - */ |
|
196 | - public function parseInfiniteValue($value) |
|
197 | - { |
|
198 | - $value = trim($value); |
|
199 | - return $value === null |
|
200 | - || $value === '' |
|
201 | - || $value === '∞' |
|
202 | - || $value === 'INF' |
|
203 | - || $value === INF |
|
204 | - || $value === EE_INF |
|
205 | - || is_infinite((float) $value) |
|
206 | - ? -1 |
|
207 | - : $value; |
|
208 | - } |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * @param mixed $source |
|
213 | - * @return EE_Base_Class|null |
|
214 | - * @since $VID:$ |
|
215 | - */ |
|
216 | - private function getModel($source) |
|
217 | - { |
|
218 | - // If it comes from a custom connection |
|
219 | - // where the $source is already instantiated. |
|
220 | - if ($source instanceof EE_Base_Class) { |
|
221 | - return $source; |
|
222 | - } |
|
223 | - return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
229 | - * @param array $args The inputArgs on the field |
|
230 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
231 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
232 | - * @return string |
|
233 | - * @throws EE_Error |
|
234 | - * @throws InvalidDataTypeException |
|
235 | - * @throws InvalidInterfaceException |
|
236 | - * @throws UnexpectedEntityException |
|
237 | - * @throws UserError |
|
238 | - * @throws InvalidArgumentException |
|
239 | - * @throws ReflectionException |
|
240 | - * @since $VID:$ |
|
241 | - */ |
|
242 | - public function resolveField($source, $args, AppContext $context, ResolveInfo $info) |
|
243 | - { |
|
244 | - $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
245 | - |
|
246 | - return $this->field_resolver->resolve($source, $args, $context, $info); |
|
247 | - } |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param mixed $payload The payload returned after mutation |
|
252 | - * @param array $args The inputArgs on the field |
|
253 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
254 | - * @return string |
|
255 | - * @throws EE_Error |
|
256 | - * @throws InvalidDataTypeException |
|
257 | - * @throws InvalidInterfaceException |
|
258 | - * @throws UnexpectedEntityException |
|
259 | - * @throws UserError |
|
260 | - * @throws InvalidArgumentException |
|
261 | - * @throws ReflectionException |
|
262 | - * @since $VID:$ |
|
263 | - */ |
|
264 | - public function resolveFromPayload($payload, $args, AppContext $context) |
|
265 | - { |
|
266 | - if (empty($payload['id']) || ! absint($payload['id'])) { |
|
267 | - return null; |
|
268 | - } |
|
269 | - return $this->model->get_one_by_ID($payload['id']); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Prepares a datetime value in ISO8601/RFC3339 format. |
|
275 | - * It is assumed that the value of $datetime is in the format |
|
276 | - * returned by EE_Base_Class::get_format(). |
|
277 | - * |
|
278 | - * @param string $datetime The datetime value. |
|
279 | - * @param EE_Base_Class $source The source object. |
|
280 | - * @return string ISO8601/RFC3339 formatted datetime. |
|
281 | - * @throws InvalidDataTypeException |
|
282 | - * @throws InvalidInterfaceException |
|
283 | - * @throws InvalidArgumentException |
|
284 | - * @throws ReflectionException |
|
285 | - * @since $VID:$ |
|
286 | - */ |
|
287 | - public function formatDatetime($datetime, EE_Base_Class $source) |
|
288 | - { |
|
289 | - $format = $source->get_format(); |
|
290 | - // create date object based on local timezone |
|
291 | - $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
292 | - // change the timezone to UTC |
|
293 | - $datetime->setTimezone(new DateTimeZone('UTC')); |
|
294 | - |
|
295 | - return $datetime->format(DateTime::RFC3339); |
|
296 | - } |
|
35 | + /** |
|
36 | + * @var string $namespace The graphql namespace/prefix. |
|
37 | + */ |
|
38 | + protected $namespace = 'Espresso'; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var EEM_Base $model |
|
42 | + */ |
|
43 | + protected $model; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var string $name |
|
47 | + */ |
|
48 | + protected $name = ''; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string $description |
|
52 | + */ |
|
53 | + protected $description = ''; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var GraphQLFieldInterface[] $fields |
|
57 | + */ |
|
58 | + protected $fields = []; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var array $graphql_to_model_map |
|
62 | + */ |
|
63 | + protected $graphql_to_model_map = []; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var FieldResolver $field_resolver |
|
67 | + */ |
|
68 | + protected $field_resolver; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var bool $is_custom_post_type |
|
72 | + */ |
|
73 | + protected $is_custom_post_type = false; |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * TypeBase constructor. |
|
78 | + */ |
|
79 | + public function __construct() |
|
80 | + { |
|
81 | + $this->setFields($this->getFields()); |
|
82 | + $this->field_resolver = new FieldResolver( |
|
83 | + $this->model, |
|
84 | + $this->getFieldsForResolver() |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return GraphQLFieldInterface[] |
|
91 | + * @since $VID:$ |
|
92 | + */ |
|
93 | + abstract protected function getFields(); |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function name() |
|
100 | + { |
|
101 | + return $this->name; |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $name |
|
107 | + */ |
|
108 | + protected function setName($name) |
|
109 | + { |
|
110 | + $this->name = $name; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function description() |
|
118 | + { |
|
119 | + return $this->description; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @param string $description |
|
125 | + */ |
|
126 | + protected function setDescription($description) |
|
127 | + { |
|
128 | + $this->description = $description; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return GraphQLFieldInterface[] |
|
134 | + * @since $VID:$ |
|
135 | + */ |
|
136 | + public function fields() |
|
137 | + { |
|
138 | + return (array) $this->fields; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param GraphQLFieldInterface[] $fields |
|
144 | + */ |
|
145 | + protected function setFields(array $fields) |
|
146 | + { |
|
147 | + foreach ($fields as $field) { |
|
148 | + if ($field instanceof GraphQLField) { |
|
149 | + $this->fields[] = $field; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Creates a key map for internal resolver. |
|
157 | + * |
|
158 | + * @return array |
|
159 | + * @since $VID:$ |
|
160 | + */ |
|
161 | + public function getFieldsForResolver() |
|
162 | + { |
|
163 | + $fields = []; |
|
164 | + foreach ($this->fields() as $field) { |
|
165 | + if ($field->useForOutput()) { |
|
166 | + $fields[ $field->name() ] = $field; |
|
167 | + } |
|
168 | + } |
|
169 | + return $fields; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public function isCustomPostType() |
|
177 | + { |
|
178 | + return $this->is_custom_post_type; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @param bool $is_custom_post_type |
|
184 | + */ |
|
185 | + protected function setIsCustomPostType($is_custom_post_type) |
|
186 | + { |
|
187 | + $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * @param int $value |
|
193 | + * @return int |
|
194 | + * @since $VID:$ |
|
195 | + */ |
|
196 | + public function parseInfiniteValue($value) |
|
197 | + { |
|
198 | + $value = trim($value); |
|
199 | + return $value === null |
|
200 | + || $value === '' |
|
201 | + || $value === '∞' |
|
202 | + || $value === 'INF' |
|
203 | + || $value === INF |
|
204 | + || $value === EE_INF |
|
205 | + || is_infinite((float) $value) |
|
206 | + ? -1 |
|
207 | + : $value; |
|
208 | + } |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * @param mixed $source |
|
213 | + * @return EE_Base_Class|null |
|
214 | + * @since $VID:$ |
|
215 | + */ |
|
216 | + private function getModel($source) |
|
217 | + { |
|
218 | + // If it comes from a custom connection |
|
219 | + // where the $source is already instantiated. |
|
220 | + if ($source instanceof EE_Base_Class) { |
|
221 | + return $source; |
|
222 | + } |
|
223 | + return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
229 | + * @param array $args The inputArgs on the field |
|
230 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
231 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
232 | + * @return string |
|
233 | + * @throws EE_Error |
|
234 | + * @throws InvalidDataTypeException |
|
235 | + * @throws InvalidInterfaceException |
|
236 | + * @throws UnexpectedEntityException |
|
237 | + * @throws UserError |
|
238 | + * @throws InvalidArgumentException |
|
239 | + * @throws ReflectionException |
|
240 | + * @since $VID:$ |
|
241 | + */ |
|
242 | + public function resolveField($source, $args, AppContext $context, ResolveInfo $info) |
|
243 | + { |
|
244 | + $source = $source instanceof RootQuery ? $source : $this->getModel($source); |
|
245 | + |
|
246 | + return $this->field_resolver->resolve($source, $args, $context, $info); |
|
247 | + } |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param mixed $payload The payload returned after mutation |
|
252 | + * @param array $args The inputArgs on the field |
|
253 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
254 | + * @return string |
|
255 | + * @throws EE_Error |
|
256 | + * @throws InvalidDataTypeException |
|
257 | + * @throws InvalidInterfaceException |
|
258 | + * @throws UnexpectedEntityException |
|
259 | + * @throws UserError |
|
260 | + * @throws InvalidArgumentException |
|
261 | + * @throws ReflectionException |
|
262 | + * @since $VID:$ |
|
263 | + */ |
|
264 | + public function resolveFromPayload($payload, $args, AppContext $context) |
|
265 | + { |
|
266 | + if (empty($payload['id']) || ! absint($payload['id'])) { |
|
267 | + return null; |
|
268 | + } |
|
269 | + return $this->model->get_one_by_ID($payload['id']); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Prepares a datetime value in ISO8601/RFC3339 format. |
|
275 | + * It is assumed that the value of $datetime is in the format |
|
276 | + * returned by EE_Base_Class::get_format(). |
|
277 | + * |
|
278 | + * @param string $datetime The datetime value. |
|
279 | + * @param EE_Base_Class $source The source object. |
|
280 | + * @return string ISO8601/RFC3339 formatted datetime. |
|
281 | + * @throws InvalidDataTypeException |
|
282 | + * @throws InvalidInterfaceException |
|
283 | + * @throws InvalidArgumentException |
|
284 | + * @throws ReflectionException |
|
285 | + * @since $VID:$ |
|
286 | + */ |
|
287 | + public function formatDatetime($datetime, EE_Base_Class $source) |
|
288 | + { |
|
289 | + $format = $source->get_format(); |
|
290 | + // create date object based on local timezone |
|
291 | + $datetime = DateTime::createFromFormat($format, $datetime, new DateTimeZone($source->get_timezone())); |
|
292 | + // change the timezone to UTC |
|
293 | + $datetime->setTimezone(new DateTimeZone('UTC')); |
|
294 | + |
|
295 | + return $datetime->format(DateTime::RFC3339); |
|
296 | + } |
|
297 | 297 | } |
@@ -33,326 +33,326 @@ |
||
33 | 33 | class Ticket extends TypeBase |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * Ticket constructor. |
|
38 | - * |
|
39 | - * @param EEM_Ticket $ticket_model |
|
40 | - */ |
|
41 | - public function __construct(EEM_Ticket $ticket_model) |
|
42 | - { |
|
43 | - $this->model = $ticket_model; |
|
44 | - $this->setName($this->namespace . 'Ticket'); |
|
45 | - $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
|
46 | - $this->setIsCustomPostType(false); |
|
47 | - parent::__construct(); |
|
48 | - } |
|
36 | + /** |
|
37 | + * Ticket constructor. |
|
38 | + * |
|
39 | + * @param EEM_Ticket $ticket_model |
|
40 | + */ |
|
41 | + public function __construct(EEM_Ticket $ticket_model) |
|
42 | + { |
|
43 | + $this->model = $ticket_model; |
|
44 | + $this->setName($this->namespace . 'Ticket'); |
|
45 | + $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
|
46 | + $this->setIsCustomPostType(false); |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @return GraphQLFieldInterface[] |
|
53 | - * @since $VID:$ |
|
54 | - */ |
|
55 | - public function getFields() |
|
56 | - { |
|
57 | - return [ |
|
58 | - new GraphQLField( |
|
59 | - 'id', |
|
60 | - ['non_null' => 'ID'], |
|
61 | - null, |
|
62 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
63 | - ), |
|
64 | - new GraphQLOutputField( |
|
65 | - 'dbId', |
|
66 | - ['non_null' => 'Int'], |
|
67 | - 'ID', |
|
68 | - esc_html__('Ticket ID', 'event_espresso') |
|
69 | - ), |
|
70 | - new GraphQLInputField( |
|
71 | - 'datetimes', |
|
72 | - ['list_of' => 'ID'], |
|
73 | - null, |
|
74 | - sprintf( |
|
75 | - '%1$s %2$s', |
|
76 | - esc_html__('Globally unique IDs of the datetimes related to the ticket.', 'event_espresso'), |
|
77 | - esc_html__('Ignored if empty.', 'event_espresso') |
|
78 | - ) |
|
79 | - ), |
|
80 | - new GraphQLField( |
|
81 | - 'description', |
|
82 | - 'String', |
|
83 | - 'description', |
|
84 | - esc_html__('Description of Ticket', 'event_espresso') |
|
85 | - ), |
|
86 | - new GraphQLField( |
|
87 | - 'endDate', |
|
88 | - 'String', |
|
89 | - 'end_date', |
|
90 | - esc_html__('End date and time of the Ticket', 'event_espresso'), |
|
91 | - [$this, 'formatDatetime'] |
|
92 | - ), |
|
93 | - new GraphQLOutputField( |
|
94 | - 'event', |
|
95 | - $this->namespace . 'Event', |
|
96 | - null, |
|
97 | - esc_html__('Event of the ticket.', 'event_espresso') |
|
98 | - ), |
|
99 | - new GraphQLField( |
|
100 | - 'isDefault', |
|
101 | - 'Boolean', |
|
102 | - 'is_default', |
|
103 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso') |
|
104 | - ), |
|
105 | - new GraphQLOutputField( |
|
106 | - 'isFree', |
|
107 | - 'Boolean', |
|
108 | - 'is_free', |
|
109 | - esc_html__('Flag indicating whether the ticket is free.', 'event_espresso') |
|
110 | - ), |
|
111 | - new GraphQLField( |
|
112 | - 'isRequired', |
|
113 | - 'Boolean', |
|
114 | - 'required', |
|
115 | - esc_html__( |
|
116 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
117 | - 'event_espresso' |
|
118 | - ) |
|
119 | - ), |
|
120 | - new GraphQLOutputField( |
|
121 | - 'isSoldOut', |
|
122 | - 'Boolean', |
|
123 | - null, |
|
124 | - esc_html__('Flag indicating whether the ticket is sold out', 'event_espresso'), |
|
125 | - null, |
|
126 | - [$this, 'getIsSoldOut'] |
|
127 | - ), |
|
128 | - new GraphQLField( |
|
129 | - 'isTaxable', |
|
130 | - 'Boolean', |
|
131 | - 'taxable', |
|
132 | - esc_html__( |
|
133 | - 'Flag indicating whether there is tax applied on this ticket', |
|
134 | - 'event_espresso' |
|
135 | - ) |
|
136 | - ), |
|
137 | - new GraphQLField( |
|
138 | - 'isTrashed', |
|
139 | - 'Boolean', |
|
140 | - 'deleted', |
|
141 | - esc_html__('Flag indicating ticket has been trashed.', 'event_espresso') |
|
142 | - ), |
|
143 | - new GraphQLField( |
|
144 | - 'max', |
|
145 | - 'Int', |
|
146 | - 'max', |
|
147 | - esc_html__( |
|
148 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
149 | - 'event_espresso' |
|
150 | - ), |
|
151 | - [$this, 'parseInfiniteValue'] |
|
152 | - ), |
|
153 | - new GraphQLField( |
|
154 | - 'min', |
|
155 | - 'Int', |
|
156 | - 'min', |
|
157 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso') |
|
158 | - ), |
|
159 | - new GraphQLField( |
|
160 | - 'name', |
|
161 | - 'String', |
|
162 | - 'name', |
|
163 | - esc_html__('Ticket Name', 'event_espresso') |
|
164 | - ), |
|
165 | - new GraphQLField( |
|
166 | - 'order', |
|
167 | - 'Int', |
|
168 | - 'order', |
|
169 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
170 | - ), |
|
171 | - new GraphQLOutputField( |
|
172 | - 'parent', |
|
173 | - $this->name(), |
|
174 | - null, |
|
175 | - esc_html__('The parent ticket of the current ticket', 'event_espresso') |
|
176 | - ), |
|
177 | - new GraphQLInputField( |
|
178 | - 'parent', |
|
179 | - 'ID', |
|
180 | - null, |
|
181 | - esc_html__('The parent ticket ID', 'event_espresso') |
|
182 | - ), |
|
183 | - new GraphQLField( |
|
184 | - 'price', |
|
185 | - 'Float', |
|
186 | - 'price', |
|
187 | - esc_html__('Final calculated price for ticket', 'event_espresso') |
|
188 | - ), |
|
189 | - new GraphQLInputField( |
|
190 | - 'prices', |
|
191 | - ['list_of' => 'ID'], |
|
192 | - null, |
|
193 | - sprintf( |
|
194 | - '%1$s %2$s', |
|
195 | - esc_html__('Globally unique IDs of the prices related to the ticket.', 'event_espresso'), |
|
196 | - esc_html__('Ignored if empty.', 'event_espresso') |
|
197 | - ) |
|
198 | - ), |
|
199 | - new GraphQLField( |
|
200 | - 'quantity', |
|
201 | - 'Int', |
|
202 | - 'qty', |
|
203 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
204 | - [$this, 'parseInfiniteValue'] |
|
205 | - ), |
|
206 | - new GraphQLField( |
|
207 | - 'reserved', |
|
208 | - 'Int', |
|
209 | - 'reserved', |
|
210 | - esc_html__( |
|
211 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
212 | - 'event_espresso' |
|
213 | - ) |
|
214 | - ), |
|
215 | - new GraphQLField( |
|
216 | - 'reverseCalculate', |
|
217 | - 'Boolean', |
|
218 | - 'reverse_calculate', |
|
219 | - esc_html__( |
|
220 | - 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
221 | - 'event_espresso' |
|
222 | - ) |
|
223 | - ), |
|
224 | - new GraphQLField( |
|
225 | - 'row', |
|
226 | - 'Int', |
|
227 | - 'row', |
|
228 | - esc_html__('How tickets are displayed in the ui', 'event_espresso') |
|
229 | - ), |
|
230 | - new GraphQLField( |
|
231 | - 'sold', |
|
232 | - 'Int', |
|
233 | - 'sold', |
|
234 | - esc_html__('Number of this ticket sold', 'event_espresso') |
|
235 | - ), |
|
236 | - new GraphQLOutputField( |
|
237 | - 'status', |
|
238 | - $this->namespace . 'TicketStatusEnum', |
|
239 | - 'ticket_status', |
|
240 | - esc_html__('Ticket status', 'event_espresso') |
|
241 | - ), |
|
242 | - new GraphQLField( |
|
243 | - 'startDate', |
|
244 | - 'String', |
|
245 | - 'start_date', |
|
246 | - esc_html__('Start date and time of the Ticket', 'event_espresso'), |
|
247 | - [$this, 'formatDatetime'] |
|
248 | - ), |
|
249 | - new GraphQLField( |
|
250 | - 'uses', |
|
251 | - 'Int', |
|
252 | - 'uses', |
|
253 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
254 | - [$this, 'parseInfiniteValue'] |
|
255 | - ), |
|
256 | - new GraphQLOutputField( |
|
257 | - 'wpUser', |
|
258 | - 'User', |
|
259 | - null, |
|
260 | - esc_html__('Ticket Creator', 'event_espresso') |
|
261 | - ), |
|
262 | - new GraphQLInputField( |
|
263 | - 'wpUser', |
|
264 | - 'Int', |
|
265 | - null, |
|
266 | - esc_html__('Ticket Creator ID', 'event_espresso') |
|
267 | - ), |
|
268 | - ]; |
|
269 | - } |
|
51 | + /** |
|
52 | + * @return GraphQLFieldInterface[] |
|
53 | + * @since $VID:$ |
|
54 | + */ |
|
55 | + public function getFields() |
|
56 | + { |
|
57 | + return [ |
|
58 | + new GraphQLField( |
|
59 | + 'id', |
|
60 | + ['non_null' => 'ID'], |
|
61 | + null, |
|
62 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
63 | + ), |
|
64 | + new GraphQLOutputField( |
|
65 | + 'dbId', |
|
66 | + ['non_null' => 'Int'], |
|
67 | + 'ID', |
|
68 | + esc_html__('Ticket ID', 'event_espresso') |
|
69 | + ), |
|
70 | + new GraphQLInputField( |
|
71 | + 'datetimes', |
|
72 | + ['list_of' => 'ID'], |
|
73 | + null, |
|
74 | + sprintf( |
|
75 | + '%1$s %2$s', |
|
76 | + esc_html__('Globally unique IDs of the datetimes related to the ticket.', 'event_espresso'), |
|
77 | + esc_html__('Ignored if empty.', 'event_espresso') |
|
78 | + ) |
|
79 | + ), |
|
80 | + new GraphQLField( |
|
81 | + 'description', |
|
82 | + 'String', |
|
83 | + 'description', |
|
84 | + esc_html__('Description of Ticket', 'event_espresso') |
|
85 | + ), |
|
86 | + new GraphQLField( |
|
87 | + 'endDate', |
|
88 | + 'String', |
|
89 | + 'end_date', |
|
90 | + esc_html__('End date and time of the Ticket', 'event_espresso'), |
|
91 | + [$this, 'formatDatetime'] |
|
92 | + ), |
|
93 | + new GraphQLOutputField( |
|
94 | + 'event', |
|
95 | + $this->namespace . 'Event', |
|
96 | + null, |
|
97 | + esc_html__('Event of the ticket.', 'event_espresso') |
|
98 | + ), |
|
99 | + new GraphQLField( |
|
100 | + 'isDefault', |
|
101 | + 'Boolean', |
|
102 | + 'is_default', |
|
103 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso') |
|
104 | + ), |
|
105 | + new GraphQLOutputField( |
|
106 | + 'isFree', |
|
107 | + 'Boolean', |
|
108 | + 'is_free', |
|
109 | + esc_html__('Flag indicating whether the ticket is free.', 'event_espresso') |
|
110 | + ), |
|
111 | + new GraphQLField( |
|
112 | + 'isRequired', |
|
113 | + 'Boolean', |
|
114 | + 'required', |
|
115 | + esc_html__( |
|
116 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
117 | + 'event_espresso' |
|
118 | + ) |
|
119 | + ), |
|
120 | + new GraphQLOutputField( |
|
121 | + 'isSoldOut', |
|
122 | + 'Boolean', |
|
123 | + null, |
|
124 | + esc_html__('Flag indicating whether the ticket is sold out', 'event_espresso'), |
|
125 | + null, |
|
126 | + [$this, 'getIsSoldOut'] |
|
127 | + ), |
|
128 | + new GraphQLField( |
|
129 | + 'isTaxable', |
|
130 | + 'Boolean', |
|
131 | + 'taxable', |
|
132 | + esc_html__( |
|
133 | + 'Flag indicating whether there is tax applied on this ticket', |
|
134 | + 'event_espresso' |
|
135 | + ) |
|
136 | + ), |
|
137 | + new GraphQLField( |
|
138 | + 'isTrashed', |
|
139 | + 'Boolean', |
|
140 | + 'deleted', |
|
141 | + esc_html__('Flag indicating ticket has been trashed.', 'event_espresso') |
|
142 | + ), |
|
143 | + new GraphQLField( |
|
144 | + 'max', |
|
145 | + 'Int', |
|
146 | + 'max', |
|
147 | + esc_html__( |
|
148 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
149 | + 'event_espresso' |
|
150 | + ), |
|
151 | + [$this, 'parseInfiniteValue'] |
|
152 | + ), |
|
153 | + new GraphQLField( |
|
154 | + 'min', |
|
155 | + 'Int', |
|
156 | + 'min', |
|
157 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso') |
|
158 | + ), |
|
159 | + new GraphQLField( |
|
160 | + 'name', |
|
161 | + 'String', |
|
162 | + 'name', |
|
163 | + esc_html__('Ticket Name', 'event_espresso') |
|
164 | + ), |
|
165 | + new GraphQLField( |
|
166 | + 'order', |
|
167 | + 'Int', |
|
168 | + 'order', |
|
169 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
170 | + ), |
|
171 | + new GraphQLOutputField( |
|
172 | + 'parent', |
|
173 | + $this->name(), |
|
174 | + null, |
|
175 | + esc_html__('The parent ticket of the current ticket', 'event_espresso') |
|
176 | + ), |
|
177 | + new GraphQLInputField( |
|
178 | + 'parent', |
|
179 | + 'ID', |
|
180 | + null, |
|
181 | + esc_html__('The parent ticket ID', 'event_espresso') |
|
182 | + ), |
|
183 | + new GraphQLField( |
|
184 | + 'price', |
|
185 | + 'Float', |
|
186 | + 'price', |
|
187 | + esc_html__('Final calculated price for ticket', 'event_espresso') |
|
188 | + ), |
|
189 | + new GraphQLInputField( |
|
190 | + 'prices', |
|
191 | + ['list_of' => 'ID'], |
|
192 | + null, |
|
193 | + sprintf( |
|
194 | + '%1$s %2$s', |
|
195 | + esc_html__('Globally unique IDs of the prices related to the ticket.', 'event_espresso'), |
|
196 | + esc_html__('Ignored if empty.', 'event_espresso') |
|
197 | + ) |
|
198 | + ), |
|
199 | + new GraphQLField( |
|
200 | + 'quantity', |
|
201 | + 'Int', |
|
202 | + 'qty', |
|
203 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
204 | + [$this, 'parseInfiniteValue'] |
|
205 | + ), |
|
206 | + new GraphQLField( |
|
207 | + 'reserved', |
|
208 | + 'Int', |
|
209 | + 'reserved', |
|
210 | + esc_html__( |
|
211 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
212 | + 'event_espresso' |
|
213 | + ) |
|
214 | + ), |
|
215 | + new GraphQLField( |
|
216 | + 'reverseCalculate', |
|
217 | + 'Boolean', |
|
218 | + 'reverse_calculate', |
|
219 | + esc_html__( |
|
220 | + 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
221 | + 'event_espresso' |
|
222 | + ) |
|
223 | + ), |
|
224 | + new GraphQLField( |
|
225 | + 'row', |
|
226 | + 'Int', |
|
227 | + 'row', |
|
228 | + esc_html__('How tickets are displayed in the ui', 'event_espresso') |
|
229 | + ), |
|
230 | + new GraphQLField( |
|
231 | + 'sold', |
|
232 | + 'Int', |
|
233 | + 'sold', |
|
234 | + esc_html__('Number of this ticket sold', 'event_espresso') |
|
235 | + ), |
|
236 | + new GraphQLOutputField( |
|
237 | + 'status', |
|
238 | + $this->namespace . 'TicketStatusEnum', |
|
239 | + 'ticket_status', |
|
240 | + esc_html__('Ticket status', 'event_espresso') |
|
241 | + ), |
|
242 | + new GraphQLField( |
|
243 | + 'startDate', |
|
244 | + 'String', |
|
245 | + 'start_date', |
|
246 | + esc_html__('Start date and time of the Ticket', 'event_espresso'), |
|
247 | + [$this, 'formatDatetime'] |
|
248 | + ), |
|
249 | + new GraphQLField( |
|
250 | + 'uses', |
|
251 | + 'Int', |
|
252 | + 'uses', |
|
253 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
254 | + [$this, 'parseInfiniteValue'] |
|
255 | + ), |
|
256 | + new GraphQLOutputField( |
|
257 | + 'wpUser', |
|
258 | + 'User', |
|
259 | + null, |
|
260 | + esc_html__('Ticket Creator', 'event_espresso') |
|
261 | + ), |
|
262 | + new GraphQLInputField( |
|
263 | + 'wpUser', |
|
264 | + 'Int', |
|
265 | + null, |
|
266 | + esc_html__('Ticket Creator ID', 'event_espresso') |
|
267 | + ), |
|
268 | + ]; |
|
269 | + } |
|
270 | 270 | |
271 | 271 | |
272 | - /** |
|
273 | - * @param EE_Ticket $source The source that's passed down the GraphQL queries |
|
274 | - * @param array $args The inputArgs on the field |
|
275 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
276 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
277 | - * @return string |
|
278 | - * @throws Exception |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws InvalidDataTypeException |
|
281 | - * @throws InvalidInterfaceException |
|
282 | - * @throws ReflectionException |
|
283 | - * @throws UserError |
|
284 | - * @throws UnexpectedEntityException |
|
285 | - * @since $VID:$ |
|
286 | - */ |
|
287 | - public function getIsSoldOut(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info) |
|
288 | - { |
|
289 | - return $source->ticket_status() === EE_Ticket::sold_out; |
|
290 | - } |
|
272 | + /** |
|
273 | + * @param EE_Ticket $source The source that's passed down the GraphQL queries |
|
274 | + * @param array $args The inputArgs on the field |
|
275 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
276 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
277 | + * @return string |
|
278 | + * @throws Exception |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws InvalidDataTypeException |
|
281 | + * @throws InvalidInterfaceException |
|
282 | + * @throws ReflectionException |
|
283 | + * @throws UserError |
|
284 | + * @throws UnexpectedEntityException |
|
285 | + * @since $VID:$ |
|
286 | + */ |
|
287 | + public function getIsSoldOut(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info) |
|
288 | + { |
|
289 | + return $source->ticket_status() === EE_Ticket::sold_out; |
|
290 | + } |
|
291 | 291 | |
292 | 292 | |
293 | - /** |
|
294 | - * @param array $inputFields The mutation input fields. |
|
295 | - * @throws InvalidArgumentException |
|
296 | - * @throws ReflectionException |
|
297 | - * @since $VID:$ |
|
298 | - */ |
|
299 | - public function registerMutations(array $inputFields) |
|
300 | - { |
|
301 | - // Register mutation to update an entity. |
|
302 | - register_graphql_mutation( |
|
303 | - 'update' . $this->name(), |
|
304 | - [ |
|
305 | - 'inputFields' => $inputFields, |
|
306 | - 'outputFields' => [ |
|
307 | - lcfirst($this->name()) => [ |
|
308 | - 'type' => $this->name(), |
|
309 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
310 | - ], |
|
311 | - ], |
|
312 | - 'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this), |
|
313 | - ] |
|
314 | - ); |
|
315 | - // Register mutation to delete an entity. |
|
316 | - register_graphql_mutation( |
|
317 | - 'delete' . $this->name(), |
|
318 | - [ |
|
319 | - 'inputFields' => [ |
|
320 | - 'id' => $inputFields['id'], |
|
321 | - 'deletePermanently' => [ |
|
322 | - 'type' => 'Boolean', |
|
323 | - 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
324 | - ], |
|
325 | - ], |
|
326 | - 'outputFields' => [ |
|
327 | - lcfirst($this->name()) => [ |
|
328 | - 'type' => $this->name(), |
|
329 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
330 | - 'resolve' => static function ($payload) { |
|
331 | - $deleted = (object) $payload['deleted']; |
|
293 | + /** |
|
294 | + * @param array $inputFields The mutation input fields. |
|
295 | + * @throws InvalidArgumentException |
|
296 | + * @throws ReflectionException |
|
297 | + * @since $VID:$ |
|
298 | + */ |
|
299 | + public function registerMutations(array $inputFields) |
|
300 | + { |
|
301 | + // Register mutation to update an entity. |
|
302 | + register_graphql_mutation( |
|
303 | + 'update' . $this->name(), |
|
304 | + [ |
|
305 | + 'inputFields' => $inputFields, |
|
306 | + 'outputFields' => [ |
|
307 | + lcfirst($this->name()) => [ |
|
308 | + 'type' => $this->name(), |
|
309 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
310 | + ], |
|
311 | + ], |
|
312 | + 'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this), |
|
313 | + ] |
|
314 | + ); |
|
315 | + // Register mutation to delete an entity. |
|
316 | + register_graphql_mutation( |
|
317 | + 'delete' . $this->name(), |
|
318 | + [ |
|
319 | + 'inputFields' => [ |
|
320 | + 'id' => $inputFields['id'], |
|
321 | + 'deletePermanently' => [ |
|
322 | + 'type' => 'Boolean', |
|
323 | + 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
324 | + ], |
|
325 | + ], |
|
326 | + 'outputFields' => [ |
|
327 | + lcfirst($this->name()) => [ |
|
328 | + 'type' => $this->name(), |
|
329 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
330 | + 'resolve' => static function ($payload) { |
|
331 | + $deleted = (object) $payload['deleted']; |
|
332 | 332 | |
333 | - return ! empty($deleted) ? $deleted : null; |
|
334 | - }, |
|
335 | - ], |
|
336 | - ], |
|
337 | - 'mutateAndGetPayload' => TicketDelete::mutateAndGetPayload($this->model, $this), |
|
338 | - ] |
|
339 | - ); |
|
333 | + return ! empty($deleted) ? $deleted : null; |
|
334 | + }, |
|
335 | + ], |
|
336 | + ], |
|
337 | + 'mutateAndGetPayload' => TicketDelete::mutateAndGetPayload($this->model, $this), |
|
338 | + ] |
|
339 | + ); |
|
340 | 340 | |
341 | - // remove primary key from input. |
|
342 | - unset($inputFields['id']); |
|
343 | - // Register mutation to update an entity. |
|
344 | - register_graphql_mutation( |
|
345 | - 'create' . $this->name(), |
|
346 | - [ |
|
347 | - 'inputFields' => $inputFields, |
|
348 | - 'outputFields' => [ |
|
349 | - lcfirst($this->name()) => [ |
|
350 | - 'type' => $this->name(), |
|
351 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
352 | - ], |
|
353 | - ], |
|
354 | - 'mutateAndGetPayload' => TicketCreate::mutateAndGetPayload($this->model, $this), |
|
355 | - ] |
|
356 | - ); |
|
357 | - } |
|
341 | + // remove primary key from input. |
|
342 | + unset($inputFields['id']); |
|
343 | + // Register mutation to update an entity. |
|
344 | + register_graphql_mutation( |
|
345 | + 'create' . $this->name(), |
|
346 | + [ |
|
347 | + 'inputFields' => $inputFields, |
|
348 | + 'outputFields' => [ |
|
349 | + lcfirst($this->name()) => [ |
|
350 | + 'type' => $this->name(), |
|
351 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
352 | + ], |
|
353 | + ], |
|
354 | + 'mutateAndGetPayload' => TicketCreate::mutateAndGetPayload($this->model, $this), |
|
355 | + ] |
|
356 | + ); |
|
357 | + } |
|
358 | 358 | } |
@@ -25,209 +25,209 @@ |
||
25 | 25 | class Price extends TypeBase |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Price constructor. |
|
30 | - * |
|
31 | - * @param EEM_Price $price_model |
|
32 | - */ |
|
33 | - public function __construct(EEM_Price $price_model) |
|
34 | - { |
|
35 | - $this->model = $price_model; |
|
36 | - $this->setName($this->namespace . 'Price'); |
|
37 | - $this->setDescription(__('A price.', 'event_espresso')); |
|
38 | - $this->setIsCustomPostType(false); |
|
39 | - parent::__construct(); |
|
40 | - } |
|
28 | + /** |
|
29 | + * Price constructor. |
|
30 | + * |
|
31 | + * @param EEM_Price $price_model |
|
32 | + */ |
|
33 | + public function __construct(EEM_Price $price_model) |
|
34 | + { |
|
35 | + $this->model = $price_model; |
|
36 | + $this->setName($this->namespace . 'Price'); |
|
37 | + $this->setDescription(__('A price.', 'event_espresso')); |
|
38 | + $this->setIsCustomPostType(false); |
|
39 | + parent::__construct(); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @return GraphQLFieldInterface[] |
|
45 | - * @since $VID:$ |
|
46 | - */ |
|
47 | - public function getFields() |
|
48 | - { |
|
49 | - return [ |
|
50 | - new GraphQLField( |
|
51 | - 'id', |
|
52 | - ['non_null' => 'ID'], |
|
53 | - null, |
|
54 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | - ), |
|
56 | - new GraphQLOutputField( |
|
57 | - 'dbId', |
|
58 | - ['non_null' => 'Int'], |
|
59 | - 'ID', |
|
60 | - esc_html__('Price ID', 'event_espresso') |
|
61 | - ), |
|
62 | - new GraphQLField( |
|
63 | - 'amount', |
|
64 | - 'Float', |
|
65 | - 'amount', |
|
66 | - esc_html__('Price Amount', 'event_espresso') |
|
67 | - ), |
|
68 | - new GraphQLField( |
|
69 | - 'desc', |
|
70 | - 'String', |
|
71 | - 'desc', |
|
72 | - esc_html__('Price description', 'event_espresso') |
|
73 | - ), |
|
74 | - new GraphQLOutputField( |
|
75 | - 'isBasePrice', |
|
76 | - 'Boolean', |
|
77 | - 'is_base_price', |
|
78 | - esc_html__('Flag indicating price is a base price type.', 'event_espresso') |
|
79 | - ), |
|
80 | - new GraphQLField( |
|
81 | - 'isDefault', |
|
82 | - 'Boolean', |
|
83 | - 'is_default', |
|
84 | - esc_html__('Flag indicating price is the default one.', 'event_espresso') |
|
85 | - ), |
|
86 | - new GraphQLOutputField( |
|
87 | - 'isDiscount', |
|
88 | - 'Boolean', |
|
89 | - 'is_discount', |
|
90 | - esc_html__('Flag indicating price is a discount.', 'event_espresso') |
|
91 | - ), |
|
92 | - new GraphQLOutputField( |
|
93 | - 'isPercent', |
|
94 | - 'Boolean', |
|
95 | - 'is_percent', |
|
96 | - esc_html__('Flag indicating price is a percentage.', 'event_espresso') |
|
97 | - ), |
|
98 | - new GraphQLOutputField( |
|
99 | - 'isTax', |
|
100 | - 'Boolean', |
|
101 | - 'is_tax', |
|
102 | - esc_html__('Flag indicating price is a tax.', 'event_espresso') |
|
103 | - ), |
|
104 | - new GraphQLField( |
|
105 | - 'isTrashed', |
|
106 | - 'Boolean', |
|
107 | - 'deleted', |
|
108 | - esc_html__('Flag indicating price has been trashed.', 'event_espresso') |
|
109 | - ), |
|
110 | - new GraphQLField( |
|
111 | - 'name', |
|
112 | - 'String', |
|
113 | - 'name', |
|
114 | - esc_html__('Price Name', 'event_espresso') |
|
115 | - ), |
|
116 | - new GraphQLField( |
|
117 | - 'order', |
|
118 | - 'Int', |
|
119 | - 'order', |
|
120 | - esc_html__('Order of Application of Price.', 'event_espresso') |
|
121 | - ), |
|
122 | - new GraphQLField( |
|
123 | - 'overrides', |
|
124 | - 'Int', |
|
125 | - 'overrides', |
|
126 | - esc_html__('Price ID for a global Price that will be overridden by this Price.', 'event_espresso') |
|
127 | - ), |
|
128 | - new GraphQLOutputField( |
|
129 | - 'parent', |
|
130 | - $this->name(), |
|
131 | - null, |
|
132 | - esc_html__('The parent price of the current price', 'event_espresso') |
|
133 | - ), |
|
134 | - new GraphQLInputField( |
|
135 | - 'parent', |
|
136 | - 'ID', |
|
137 | - null, |
|
138 | - esc_html__('The parent price ID', 'event_espresso') |
|
139 | - ), |
|
140 | - new GraphQLOutputField( |
|
141 | - 'priceType', |
|
142 | - $this->namespace . 'PriceType', |
|
143 | - 'type_obj', |
|
144 | - esc_html__('The related price type object.', 'event_espresso') |
|
145 | - ), |
|
146 | - new GraphQLInputField( |
|
147 | - 'priceType', |
|
148 | - 'ID', |
|
149 | - null, |
|
150 | - esc_html__('The price type ID', 'event_espresso') |
|
151 | - ), |
|
152 | - new GraphQLOutputField( |
|
153 | - 'wpUser', |
|
154 | - 'User', |
|
155 | - null, |
|
156 | - esc_html__('Price Creator', 'event_espresso') |
|
157 | - ), |
|
158 | - new GraphQLInputField( |
|
159 | - 'wpUser', |
|
160 | - 'Int', |
|
161 | - null, |
|
162 | - esc_html__('Price Creator ID', 'event_espresso') |
|
163 | - ), |
|
164 | - ]; |
|
165 | - } |
|
43 | + /** |
|
44 | + * @return GraphQLFieldInterface[] |
|
45 | + * @since $VID:$ |
|
46 | + */ |
|
47 | + public function getFields() |
|
48 | + { |
|
49 | + return [ |
|
50 | + new GraphQLField( |
|
51 | + 'id', |
|
52 | + ['non_null' => 'ID'], |
|
53 | + null, |
|
54 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | + ), |
|
56 | + new GraphQLOutputField( |
|
57 | + 'dbId', |
|
58 | + ['non_null' => 'Int'], |
|
59 | + 'ID', |
|
60 | + esc_html__('Price ID', 'event_espresso') |
|
61 | + ), |
|
62 | + new GraphQLField( |
|
63 | + 'amount', |
|
64 | + 'Float', |
|
65 | + 'amount', |
|
66 | + esc_html__('Price Amount', 'event_espresso') |
|
67 | + ), |
|
68 | + new GraphQLField( |
|
69 | + 'desc', |
|
70 | + 'String', |
|
71 | + 'desc', |
|
72 | + esc_html__('Price description', 'event_espresso') |
|
73 | + ), |
|
74 | + new GraphQLOutputField( |
|
75 | + 'isBasePrice', |
|
76 | + 'Boolean', |
|
77 | + 'is_base_price', |
|
78 | + esc_html__('Flag indicating price is a base price type.', 'event_espresso') |
|
79 | + ), |
|
80 | + new GraphQLField( |
|
81 | + 'isDefault', |
|
82 | + 'Boolean', |
|
83 | + 'is_default', |
|
84 | + esc_html__('Flag indicating price is the default one.', 'event_espresso') |
|
85 | + ), |
|
86 | + new GraphQLOutputField( |
|
87 | + 'isDiscount', |
|
88 | + 'Boolean', |
|
89 | + 'is_discount', |
|
90 | + esc_html__('Flag indicating price is a discount.', 'event_espresso') |
|
91 | + ), |
|
92 | + new GraphQLOutputField( |
|
93 | + 'isPercent', |
|
94 | + 'Boolean', |
|
95 | + 'is_percent', |
|
96 | + esc_html__('Flag indicating price is a percentage.', 'event_espresso') |
|
97 | + ), |
|
98 | + new GraphQLOutputField( |
|
99 | + 'isTax', |
|
100 | + 'Boolean', |
|
101 | + 'is_tax', |
|
102 | + esc_html__('Flag indicating price is a tax.', 'event_espresso') |
|
103 | + ), |
|
104 | + new GraphQLField( |
|
105 | + 'isTrashed', |
|
106 | + 'Boolean', |
|
107 | + 'deleted', |
|
108 | + esc_html__('Flag indicating price has been trashed.', 'event_espresso') |
|
109 | + ), |
|
110 | + new GraphQLField( |
|
111 | + 'name', |
|
112 | + 'String', |
|
113 | + 'name', |
|
114 | + esc_html__('Price Name', 'event_espresso') |
|
115 | + ), |
|
116 | + new GraphQLField( |
|
117 | + 'order', |
|
118 | + 'Int', |
|
119 | + 'order', |
|
120 | + esc_html__('Order of Application of Price.', 'event_espresso') |
|
121 | + ), |
|
122 | + new GraphQLField( |
|
123 | + 'overrides', |
|
124 | + 'Int', |
|
125 | + 'overrides', |
|
126 | + esc_html__('Price ID for a global Price that will be overridden by this Price.', 'event_espresso') |
|
127 | + ), |
|
128 | + new GraphQLOutputField( |
|
129 | + 'parent', |
|
130 | + $this->name(), |
|
131 | + null, |
|
132 | + esc_html__('The parent price of the current price', 'event_espresso') |
|
133 | + ), |
|
134 | + new GraphQLInputField( |
|
135 | + 'parent', |
|
136 | + 'ID', |
|
137 | + null, |
|
138 | + esc_html__('The parent price ID', 'event_espresso') |
|
139 | + ), |
|
140 | + new GraphQLOutputField( |
|
141 | + 'priceType', |
|
142 | + $this->namespace . 'PriceType', |
|
143 | + 'type_obj', |
|
144 | + esc_html__('The related price type object.', 'event_espresso') |
|
145 | + ), |
|
146 | + new GraphQLInputField( |
|
147 | + 'priceType', |
|
148 | + 'ID', |
|
149 | + null, |
|
150 | + esc_html__('The price type ID', 'event_espresso') |
|
151 | + ), |
|
152 | + new GraphQLOutputField( |
|
153 | + 'wpUser', |
|
154 | + 'User', |
|
155 | + null, |
|
156 | + esc_html__('Price Creator', 'event_espresso') |
|
157 | + ), |
|
158 | + new GraphQLInputField( |
|
159 | + 'wpUser', |
|
160 | + 'Int', |
|
161 | + null, |
|
162 | + esc_html__('Price Creator ID', 'event_espresso') |
|
163 | + ), |
|
164 | + ]; |
|
165 | + } |
|
166 | 166 | |
167 | 167 | |
168 | - /** |
|
169 | - * @param array $inputFields The mutation input fields. |
|
170 | - * @throws InvalidArgumentException |
|
171 | - * @throws ReflectionException |
|
172 | - * @since $VID:$ |
|
173 | - */ |
|
174 | - public function registerMutations(array $inputFields) |
|
175 | - { |
|
176 | - // Register mutation to update an entity. |
|
177 | - register_graphql_mutation( |
|
178 | - 'update' . $this->name(), |
|
179 | - [ |
|
180 | - 'inputFields' => $inputFields, |
|
181 | - 'outputFields' => [ |
|
182 | - lcfirst($this->name()) => [ |
|
183 | - 'type' => $this->name(), |
|
184 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
185 | - ], |
|
186 | - ], |
|
187 | - 'mutateAndGetPayload' => PriceUpdate::mutateAndGetPayload($this->model, $this), |
|
188 | - ] |
|
189 | - ); |
|
190 | - // Register mutation to delete an entity. |
|
191 | - register_graphql_mutation( |
|
192 | - 'delete' . $this->name(), |
|
193 | - [ |
|
194 | - 'inputFields' => [ |
|
195 | - 'id' => $inputFields['id'], |
|
196 | - 'deletePermanently' => [ |
|
197 | - 'type' => 'Boolean', |
|
198 | - 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
199 | - ], |
|
200 | - ], |
|
201 | - 'outputFields' => [ |
|
202 | - lcfirst($this->name()) => [ |
|
203 | - 'type' => $this->name(), |
|
204 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
205 | - 'resolve' => static function ($payload) { |
|
206 | - $deleted = (object) $payload['deleted']; |
|
168 | + /** |
|
169 | + * @param array $inputFields The mutation input fields. |
|
170 | + * @throws InvalidArgumentException |
|
171 | + * @throws ReflectionException |
|
172 | + * @since $VID:$ |
|
173 | + */ |
|
174 | + public function registerMutations(array $inputFields) |
|
175 | + { |
|
176 | + // Register mutation to update an entity. |
|
177 | + register_graphql_mutation( |
|
178 | + 'update' . $this->name(), |
|
179 | + [ |
|
180 | + 'inputFields' => $inputFields, |
|
181 | + 'outputFields' => [ |
|
182 | + lcfirst($this->name()) => [ |
|
183 | + 'type' => $this->name(), |
|
184 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
185 | + ], |
|
186 | + ], |
|
187 | + 'mutateAndGetPayload' => PriceUpdate::mutateAndGetPayload($this->model, $this), |
|
188 | + ] |
|
189 | + ); |
|
190 | + // Register mutation to delete an entity. |
|
191 | + register_graphql_mutation( |
|
192 | + 'delete' . $this->name(), |
|
193 | + [ |
|
194 | + 'inputFields' => [ |
|
195 | + 'id' => $inputFields['id'], |
|
196 | + 'deletePermanently' => [ |
|
197 | + 'type' => 'Boolean', |
|
198 | + 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
199 | + ], |
|
200 | + ], |
|
201 | + 'outputFields' => [ |
|
202 | + lcfirst($this->name()) => [ |
|
203 | + 'type' => $this->name(), |
|
204 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
205 | + 'resolve' => static function ($payload) { |
|
206 | + $deleted = (object) $payload['deleted']; |
|
207 | 207 | |
208 | - return ! empty($deleted) ? $deleted : null; |
|
209 | - }, |
|
210 | - ], |
|
211 | - ], |
|
212 | - 'mutateAndGetPayload' => PriceDelete::mutateAndGetPayload($this->model, $this), |
|
213 | - ] |
|
214 | - ); |
|
208 | + return ! empty($deleted) ? $deleted : null; |
|
209 | + }, |
|
210 | + ], |
|
211 | + ], |
|
212 | + 'mutateAndGetPayload' => PriceDelete::mutateAndGetPayload($this->model, $this), |
|
213 | + ] |
|
214 | + ); |
|
215 | 215 | |
216 | - // remove primary key from input. |
|
217 | - unset($inputFields['id']); |
|
218 | - // Register mutation to update an entity. |
|
219 | - register_graphql_mutation( |
|
220 | - 'create' . $this->name(), |
|
221 | - [ |
|
222 | - 'inputFields' => $inputFields, |
|
223 | - 'outputFields' => [ |
|
224 | - lcfirst($this->name()) => [ |
|
225 | - 'type' => $this->name(), |
|
226 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
227 | - ], |
|
228 | - ], |
|
229 | - 'mutateAndGetPayload' => PriceCreate::mutateAndGetPayload($this->model, $this), |
|
230 | - ] |
|
231 | - ); |
|
232 | - } |
|
216 | + // remove primary key from input. |
|
217 | + unset($inputFields['id']); |
|
218 | + // Register mutation to update an entity. |
|
219 | + register_graphql_mutation( |
|
220 | + 'create' . $this->name(), |
|
221 | + [ |
|
222 | + 'inputFields' => $inputFields, |
|
223 | + 'outputFields' => [ |
|
224 | + lcfirst($this->name()) => [ |
|
225 | + 'type' => $this->name(), |
|
226 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
227 | + ], |
|
228 | + ], |
|
229 | + 'mutateAndGetPayload' => PriceCreate::mutateAndGetPayload($this->model, $this), |
|
230 | + ] |
|
231 | + ); |
|
232 | + } |
|
233 | 233 | } |
@@ -33,272 +33,272 @@ |
||
33 | 33 | class Datetime extends TypeBase |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * EventDate constructor. |
|
38 | - * |
|
39 | - * @param EEM_Datetime $datetime_model |
|
40 | - */ |
|
41 | - public function __construct(EEM_Datetime $datetime_model) |
|
42 | - { |
|
43 | - $this->model = $datetime_model; |
|
44 | - $this->setName($this->namespace . 'Datetime'); |
|
45 | - $this->setDescription(__('An event date', 'event_espresso')); |
|
46 | - $this->setIsCustomPostType(false); |
|
47 | - parent::__construct(); |
|
48 | - } |
|
36 | + /** |
|
37 | + * EventDate constructor. |
|
38 | + * |
|
39 | + * @param EEM_Datetime $datetime_model |
|
40 | + */ |
|
41 | + public function __construct(EEM_Datetime $datetime_model) |
|
42 | + { |
|
43 | + $this->model = $datetime_model; |
|
44 | + $this->setName($this->namespace . 'Datetime'); |
|
45 | + $this->setDescription(__('An event date', 'event_espresso')); |
|
46 | + $this->setIsCustomPostType(false); |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @return GraphQLFieldInterface[] |
|
53 | - * @since $VID:$ |
|
54 | - */ |
|
55 | - public function getFields() |
|
56 | - { |
|
57 | - return [ |
|
58 | - new GraphQLField( |
|
59 | - 'id', |
|
60 | - ['non_null' => 'ID'], |
|
61 | - null, |
|
62 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
63 | - ), |
|
64 | - new GraphQLOutputField( |
|
65 | - 'dbId', |
|
66 | - ['non_null' => 'Int'], |
|
67 | - 'ID', |
|
68 | - esc_html__('The datetime ID.', 'event_espresso') |
|
69 | - ), |
|
70 | - new GraphQLField( |
|
71 | - 'capacity', |
|
72 | - 'Int', |
|
73 | - 'reg_limit', |
|
74 | - esc_html__('Registration Limit for this time', 'event_espresso'), |
|
75 | - [$this, 'parseInfiniteValue'] |
|
76 | - ), |
|
77 | - new GraphQLField( |
|
78 | - 'description', |
|
79 | - 'String', |
|
80 | - 'description', |
|
81 | - esc_html__('Description for Datetime', 'event_espresso') |
|
82 | - ), |
|
83 | - new GraphQLField( |
|
84 | - 'endDate', |
|
85 | - 'String', |
|
86 | - 'end_date_and_time', |
|
87 | - esc_html__('End date and time of the Event', 'event_espresso'), |
|
88 | - [$this, 'formatDatetime'] |
|
89 | - ), |
|
90 | - new GraphQLOutputField( |
|
91 | - 'event', |
|
92 | - $this->namespace . 'Event', |
|
93 | - null, |
|
94 | - esc_html__('Event of the datetime.', 'event_espresso') |
|
95 | - ), |
|
96 | - new GraphQLInputField( |
|
97 | - 'event', |
|
98 | - 'ID', |
|
99 | - null, |
|
100 | - esc_html__('Globally unique event ID of the datetime.', 'event_espresso') |
|
101 | - ), |
|
102 | - new GraphQLInputField( |
|
103 | - 'eventId', |
|
104 | - 'Int', |
|
105 | - null, |
|
106 | - esc_html__('Event ID of the datetime.', 'event_espresso') |
|
107 | - ), |
|
108 | - new GraphQLOutputField( |
|
109 | - 'isActive', |
|
110 | - 'Boolean', |
|
111 | - 'is_active', |
|
112 | - esc_html__('Flag indicating datetime is active', 'event_espresso') |
|
113 | - ), |
|
114 | - new GraphQLOutputField( |
|
115 | - 'isExpired', |
|
116 | - 'Boolean', |
|
117 | - 'is_expired', |
|
118 | - esc_html__('Flag indicating datetime is expired or not', 'event_espresso') |
|
119 | - ), |
|
120 | - new GraphQLField( |
|
121 | - 'isPrimary', |
|
122 | - 'Boolean', |
|
123 | - 'is_primary', |
|
124 | - esc_html__('Flag indicating datetime is primary one for event', 'event_espresso') |
|
125 | - ), |
|
126 | - new GraphQLOutputField( |
|
127 | - 'isSoldOut', |
|
128 | - 'Boolean', |
|
129 | - 'sold_out', |
|
130 | - esc_html__( |
|
131 | - 'Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit', |
|
132 | - 'event_espresso' |
|
133 | - ) |
|
134 | - ), |
|
135 | - new GraphQLField( |
|
136 | - 'isTrashed', |
|
137 | - 'Boolean', |
|
138 | - null, |
|
139 | - esc_html__('Flag indicating datetime has been trashed.', 'event_espresso'), |
|
140 | - null, |
|
141 | - [$this, 'getIsTrashed'] |
|
142 | - ), |
|
143 | - new GraphQLOutputField( |
|
144 | - 'isUpcoming', |
|
145 | - 'Boolean', |
|
146 | - 'is_upcoming', |
|
147 | - esc_html__('Whether the date is upcoming', 'event_espresso') |
|
148 | - ), |
|
149 | - new GraphQLOutputField( |
|
150 | - 'length', |
|
151 | - 'Int', |
|
152 | - 'length', |
|
153 | - esc_html__('The length of the event (start to end time) in seconds', 'event_espresso') |
|
154 | - ), |
|
155 | - new GraphQLField( |
|
156 | - 'name', |
|
157 | - 'String', |
|
158 | - 'name', |
|
159 | - esc_html__('Datetime Name', 'event_espresso') |
|
160 | - ), |
|
161 | - new GraphQLField( |
|
162 | - 'order', |
|
163 | - 'Int', |
|
164 | - 'order', |
|
165 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
166 | - ), |
|
167 | - new GraphQLOutputField( |
|
168 | - 'parent', |
|
169 | - $this->name(), |
|
170 | - null, |
|
171 | - esc_html__('The parent datetime of the current datetime', 'event_espresso') |
|
172 | - ), |
|
173 | - new GraphQLInputField( |
|
174 | - 'parent', |
|
175 | - 'ID', |
|
176 | - null, |
|
177 | - esc_html__('The parent datetime ID', 'event_espresso') |
|
178 | - ), |
|
179 | - new GraphQLField( |
|
180 | - 'reserved', |
|
181 | - 'Int', |
|
182 | - 'reserved', |
|
183 | - esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso') |
|
184 | - ), |
|
185 | - new GraphQLField( |
|
186 | - 'startDate', |
|
187 | - 'String', |
|
188 | - 'start_date_and_time', |
|
189 | - esc_html__('Start date and time of the Event', 'event_espresso'), |
|
190 | - [$this, 'formatDatetime'] |
|
191 | - ), |
|
192 | - new GraphQLField( |
|
193 | - 'sold', |
|
194 | - 'Int', |
|
195 | - 'sold', |
|
196 | - esc_html__('How many sales for this Datetime that have occurred', 'event_espresso') |
|
197 | - ), |
|
198 | - new GraphQLOutputField( |
|
199 | - 'status', |
|
200 | - $this->namespace . 'DatetimeStatusEnum', |
|
201 | - 'get_active_status', |
|
202 | - esc_html__('Datetime status', 'event_espresso') |
|
203 | - ), |
|
204 | - new GraphQLInputField( |
|
205 | - 'tickets', |
|
206 | - ['list_of' => 'ID'], |
|
207 | - null, |
|
208 | - sprintf( |
|
209 | - '%1$s %2$s', |
|
210 | - esc_html__('Globally unique IDs of the tickets related to the datetime.', 'event_espresso'), |
|
211 | - esc_html__('Ignored if empty.', 'event_espresso') |
|
212 | - ) |
|
213 | - ), |
|
214 | - ]; |
|
215 | - } |
|
51 | + /** |
|
52 | + * @return GraphQLFieldInterface[] |
|
53 | + * @since $VID:$ |
|
54 | + */ |
|
55 | + public function getFields() |
|
56 | + { |
|
57 | + return [ |
|
58 | + new GraphQLField( |
|
59 | + 'id', |
|
60 | + ['non_null' => 'ID'], |
|
61 | + null, |
|
62 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
63 | + ), |
|
64 | + new GraphQLOutputField( |
|
65 | + 'dbId', |
|
66 | + ['non_null' => 'Int'], |
|
67 | + 'ID', |
|
68 | + esc_html__('The datetime ID.', 'event_espresso') |
|
69 | + ), |
|
70 | + new GraphQLField( |
|
71 | + 'capacity', |
|
72 | + 'Int', |
|
73 | + 'reg_limit', |
|
74 | + esc_html__('Registration Limit for this time', 'event_espresso'), |
|
75 | + [$this, 'parseInfiniteValue'] |
|
76 | + ), |
|
77 | + new GraphQLField( |
|
78 | + 'description', |
|
79 | + 'String', |
|
80 | + 'description', |
|
81 | + esc_html__('Description for Datetime', 'event_espresso') |
|
82 | + ), |
|
83 | + new GraphQLField( |
|
84 | + 'endDate', |
|
85 | + 'String', |
|
86 | + 'end_date_and_time', |
|
87 | + esc_html__('End date and time of the Event', 'event_espresso'), |
|
88 | + [$this, 'formatDatetime'] |
|
89 | + ), |
|
90 | + new GraphQLOutputField( |
|
91 | + 'event', |
|
92 | + $this->namespace . 'Event', |
|
93 | + null, |
|
94 | + esc_html__('Event of the datetime.', 'event_espresso') |
|
95 | + ), |
|
96 | + new GraphQLInputField( |
|
97 | + 'event', |
|
98 | + 'ID', |
|
99 | + null, |
|
100 | + esc_html__('Globally unique event ID of the datetime.', 'event_espresso') |
|
101 | + ), |
|
102 | + new GraphQLInputField( |
|
103 | + 'eventId', |
|
104 | + 'Int', |
|
105 | + null, |
|
106 | + esc_html__('Event ID of the datetime.', 'event_espresso') |
|
107 | + ), |
|
108 | + new GraphQLOutputField( |
|
109 | + 'isActive', |
|
110 | + 'Boolean', |
|
111 | + 'is_active', |
|
112 | + esc_html__('Flag indicating datetime is active', 'event_espresso') |
|
113 | + ), |
|
114 | + new GraphQLOutputField( |
|
115 | + 'isExpired', |
|
116 | + 'Boolean', |
|
117 | + 'is_expired', |
|
118 | + esc_html__('Flag indicating datetime is expired or not', 'event_espresso') |
|
119 | + ), |
|
120 | + new GraphQLField( |
|
121 | + 'isPrimary', |
|
122 | + 'Boolean', |
|
123 | + 'is_primary', |
|
124 | + esc_html__('Flag indicating datetime is primary one for event', 'event_espresso') |
|
125 | + ), |
|
126 | + new GraphQLOutputField( |
|
127 | + 'isSoldOut', |
|
128 | + 'Boolean', |
|
129 | + 'sold_out', |
|
130 | + esc_html__( |
|
131 | + 'Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit', |
|
132 | + 'event_espresso' |
|
133 | + ) |
|
134 | + ), |
|
135 | + new GraphQLField( |
|
136 | + 'isTrashed', |
|
137 | + 'Boolean', |
|
138 | + null, |
|
139 | + esc_html__('Flag indicating datetime has been trashed.', 'event_espresso'), |
|
140 | + null, |
|
141 | + [$this, 'getIsTrashed'] |
|
142 | + ), |
|
143 | + new GraphQLOutputField( |
|
144 | + 'isUpcoming', |
|
145 | + 'Boolean', |
|
146 | + 'is_upcoming', |
|
147 | + esc_html__('Whether the date is upcoming', 'event_espresso') |
|
148 | + ), |
|
149 | + new GraphQLOutputField( |
|
150 | + 'length', |
|
151 | + 'Int', |
|
152 | + 'length', |
|
153 | + esc_html__('The length of the event (start to end time) in seconds', 'event_espresso') |
|
154 | + ), |
|
155 | + new GraphQLField( |
|
156 | + 'name', |
|
157 | + 'String', |
|
158 | + 'name', |
|
159 | + esc_html__('Datetime Name', 'event_espresso') |
|
160 | + ), |
|
161 | + new GraphQLField( |
|
162 | + 'order', |
|
163 | + 'Int', |
|
164 | + 'order', |
|
165 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
166 | + ), |
|
167 | + new GraphQLOutputField( |
|
168 | + 'parent', |
|
169 | + $this->name(), |
|
170 | + null, |
|
171 | + esc_html__('The parent datetime of the current datetime', 'event_espresso') |
|
172 | + ), |
|
173 | + new GraphQLInputField( |
|
174 | + 'parent', |
|
175 | + 'ID', |
|
176 | + null, |
|
177 | + esc_html__('The parent datetime ID', 'event_espresso') |
|
178 | + ), |
|
179 | + new GraphQLField( |
|
180 | + 'reserved', |
|
181 | + 'Int', |
|
182 | + 'reserved', |
|
183 | + esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso') |
|
184 | + ), |
|
185 | + new GraphQLField( |
|
186 | + 'startDate', |
|
187 | + 'String', |
|
188 | + 'start_date_and_time', |
|
189 | + esc_html__('Start date and time of the Event', 'event_espresso'), |
|
190 | + [$this, 'formatDatetime'] |
|
191 | + ), |
|
192 | + new GraphQLField( |
|
193 | + 'sold', |
|
194 | + 'Int', |
|
195 | + 'sold', |
|
196 | + esc_html__('How many sales for this Datetime that have occurred', 'event_espresso') |
|
197 | + ), |
|
198 | + new GraphQLOutputField( |
|
199 | + 'status', |
|
200 | + $this->namespace . 'DatetimeStatusEnum', |
|
201 | + 'get_active_status', |
|
202 | + esc_html__('Datetime status', 'event_espresso') |
|
203 | + ), |
|
204 | + new GraphQLInputField( |
|
205 | + 'tickets', |
|
206 | + ['list_of' => 'ID'], |
|
207 | + null, |
|
208 | + sprintf( |
|
209 | + '%1$s %2$s', |
|
210 | + esc_html__('Globally unique IDs of the tickets related to the datetime.', 'event_espresso'), |
|
211 | + esc_html__('Ignored if empty.', 'event_espresso') |
|
212 | + ) |
|
213 | + ), |
|
214 | + ]; |
|
215 | + } |
|
216 | 216 | |
217 | 217 | |
218 | - /** |
|
219 | - * @param EE_Datetime $source The source that's passed down the GraphQL queries |
|
220 | - * @param array $args The inputArgs on the field |
|
221 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
222 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
223 | - * @return string |
|
224 | - * @throws Exception |
|
225 | - * @throws InvalidArgumentException |
|
226 | - * @throws InvalidDataTypeException |
|
227 | - * @throws InvalidInterfaceException |
|
228 | - * @throws ReflectionException |
|
229 | - * @throws UserError |
|
230 | - * @throws UnexpectedEntityException |
|
231 | - * @since $VID:$ |
|
232 | - */ |
|
233 | - public function getIsTrashed(EE_Datetime $source, array $args, AppContext $context, ResolveInfo $info) |
|
234 | - { |
|
235 | - return (bool) $source->get('DTT_deleted'); |
|
236 | - } |
|
218 | + /** |
|
219 | + * @param EE_Datetime $source The source that's passed down the GraphQL queries |
|
220 | + * @param array $args The inputArgs on the field |
|
221 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
222 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
223 | + * @return string |
|
224 | + * @throws Exception |
|
225 | + * @throws InvalidArgumentException |
|
226 | + * @throws InvalidDataTypeException |
|
227 | + * @throws InvalidInterfaceException |
|
228 | + * @throws ReflectionException |
|
229 | + * @throws UserError |
|
230 | + * @throws UnexpectedEntityException |
|
231 | + * @since $VID:$ |
|
232 | + */ |
|
233 | + public function getIsTrashed(EE_Datetime $source, array $args, AppContext $context, ResolveInfo $info) |
|
234 | + { |
|
235 | + return (bool) $source->get('DTT_deleted'); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | - /** |
|
240 | - * @param array $inputFields The mutation input fields. |
|
241 | - * @throws InvalidArgumentException |
|
242 | - * @throws ReflectionException |
|
243 | - * @since $VID:$ |
|
244 | - */ |
|
245 | - public function registerMutations(array $inputFields) |
|
246 | - { |
|
247 | - // Register mutation to update an entity. |
|
248 | - register_graphql_mutation( |
|
249 | - 'update' . $this->name(), |
|
250 | - [ |
|
251 | - 'inputFields' => $inputFields, |
|
252 | - 'outputFields' => [ |
|
253 | - lcfirst($this->name()) => [ |
|
254 | - 'type' => $this->name(), |
|
255 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
256 | - ], |
|
257 | - ], |
|
258 | - 'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this), |
|
259 | - ] |
|
260 | - ); |
|
261 | - // Register mutation to delete an entity. |
|
262 | - register_graphql_mutation( |
|
263 | - 'delete' . $this->name(), |
|
264 | - [ |
|
265 | - 'inputFields' => [ |
|
266 | - 'id' => $inputFields['id'], |
|
267 | - 'deletePermanently' => [ |
|
268 | - 'type' => 'Boolean', |
|
269 | - 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
270 | - ], |
|
271 | - ], |
|
272 | - 'outputFields' => [ |
|
273 | - lcfirst($this->name()) => [ |
|
274 | - 'type' => $this->name(), |
|
275 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
276 | - 'resolve' => static function ($payload) { |
|
277 | - $deleted = (object) $payload['deleted']; |
|
239 | + /** |
|
240 | + * @param array $inputFields The mutation input fields. |
|
241 | + * @throws InvalidArgumentException |
|
242 | + * @throws ReflectionException |
|
243 | + * @since $VID:$ |
|
244 | + */ |
|
245 | + public function registerMutations(array $inputFields) |
|
246 | + { |
|
247 | + // Register mutation to update an entity. |
|
248 | + register_graphql_mutation( |
|
249 | + 'update' . $this->name(), |
|
250 | + [ |
|
251 | + 'inputFields' => $inputFields, |
|
252 | + 'outputFields' => [ |
|
253 | + lcfirst($this->name()) => [ |
|
254 | + 'type' => $this->name(), |
|
255 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
256 | + ], |
|
257 | + ], |
|
258 | + 'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this), |
|
259 | + ] |
|
260 | + ); |
|
261 | + // Register mutation to delete an entity. |
|
262 | + register_graphql_mutation( |
|
263 | + 'delete' . $this->name(), |
|
264 | + [ |
|
265 | + 'inputFields' => [ |
|
266 | + 'id' => $inputFields['id'], |
|
267 | + 'deletePermanently' => [ |
|
268 | + 'type' => 'Boolean', |
|
269 | + 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
270 | + ], |
|
271 | + ], |
|
272 | + 'outputFields' => [ |
|
273 | + lcfirst($this->name()) => [ |
|
274 | + 'type' => $this->name(), |
|
275 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
276 | + 'resolve' => static function ($payload) { |
|
277 | + $deleted = (object) $payload['deleted']; |
|
278 | 278 | |
279 | - return ! empty($deleted) ? $deleted : null; |
|
280 | - }, |
|
281 | - ], |
|
282 | - ], |
|
283 | - 'mutateAndGetPayload' => DatetimeDelete::mutateAndGetPayload($this->model, $this), |
|
284 | - ] |
|
285 | - ); |
|
279 | + return ! empty($deleted) ? $deleted : null; |
|
280 | + }, |
|
281 | + ], |
|
282 | + ], |
|
283 | + 'mutateAndGetPayload' => DatetimeDelete::mutateAndGetPayload($this->model, $this), |
|
284 | + ] |
|
285 | + ); |
|
286 | 286 | |
287 | - // remove primary key from input. |
|
288 | - unset($inputFields['id']); |
|
289 | - // Register mutation to update an entity. |
|
290 | - register_graphql_mutation( |
|
291 | - 'create' . $this->name(), |
|
292 | - [ |
|
293 | - 'inputFields' => $inputFields, |
|
294 | - 'outputFields' => [ |
|
295 | - lcfirst($this->name()) => [ |
|
296 | - 'type' => $this->name(), |
|
297 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
298 | - ], |
|
299 | - ], |
|
300 | - 'mutateAndGetPayload' => DatetimeCreate::mutateAndGetPayload($this->model, $this), |
|
301 | - ] |
|
302 | - ); |
|
303 | - } |
|
287 | + // remove primary key from input. |
|
288 | + unset($inputFields['id']); |
|
289 | + // Register mutation to update an entity. |
|
290 | + register_graphql_mutation( |
|
291 | + 'create' . $this->name(), |
|
292 | + [ |
|
293 | + 'inputFields' => $inputFields, |
|
294 | + 'outputFields' => [ |
|
295 | + lcfirst($this->name()) => [ |
|
296 | + 'type' => $this->name(), |
|
297 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
298 | + ], |
|
299 | + ], |
|
300 | + 'mutateAndGetPayload' => DatetimeCreate::mutateAndGetPayload($this->model, $this), |
|
301 | + ] |
|
302 | + ); |
|
303 | + } |
|
304 | 304 | } |
@@ -27,193 +27,193 @@ |
||
27 | 27 | class TicketMutation |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Maps the GraphQL input to a format that the model functions can use |
|
32 | - * |
|
33 | - * @param array $input Data coming from the GraphQL mutation query input |
|
34 | - * @return array |
|
35 | - * @throws Exception |
|
36 | - */ |
|
37 | - public static function prepareFields(array $input) |
|
38 | - { |
|
39 | - $args = []; |
|
40 | - |
|
41 | - if (! empty($input['datetimes'])) { |
|
42 | - $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
43 | - } |
|
44 | - |
|
45 | - if (! empty($input['description'])) { |
|
46 | - $args['TKT_description'] = sanitize_text_field($input['description']); |
|
47 | - } |
|
48 | - |
|
49 | - if (! empty($input['endDate'])) { |
|
50 | - $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
51 | - } |
|
52 | - |
|
53 | - if (array_key_exists('isDefault', $input)) { |
|
54 | - $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
55 | - } |
|
56 | - |
|
57 | - if (array_key_exists('isRequired', $input)) { |
|
58 | - $args['TKT_required'] = (bool) $input['isRequired']; |
|
59 | - } |
|
60 | - |
|
61 | - if (array_key_exists('isTaxable', $input)) { |
|
62 | - $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
63 | - } |
|
64 | - |
|
65 | - if (array_key_exists('isTrashed', $input)) { |
|
66 | - $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
67 | - } |
|
68 | - |
|
69 | - if (array_key_exists('max', $input)) { |
|
70 | - $args['TKT_max'] = (int) $input['max']; |
|
71 | - } |
|
72 | - |
|
73 | - if (array_key_exists('min', $input)) { |
|
74 | - $args['TKT_min'] = (int) $input['min']; |
|
75 | - } |
|
76 | - |
|
77 | - if (! empty($input['name'])) { |
|
78 | - $args['TKT_name'] = sanitize_text_field($input['name']); |
|
79 | - } |
|
80 | - |
|
81 | - if (array_key_exists('order', $input)) { |
|
82 | - $args['TKT_order'] = (int) $input['order']; |
|
83 | - } |
|
84 | - |
|
85 | - if (! empty($input['parent'])) { |
|
86 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
87 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
88 | - } |
|
89 | - |
|
90 | - if (! empty($input['price'])) { |
|
91 | - $args['TKT_price'] = (float) $input['price']; |
|
92 | - } |
|
93 | - |
|
94 | - if (! empty($input['prices'])) { |
|
95 | - $args['prices'] = array_map('sanitize_text_field', (array) $input['prices']); |
|
96 | - } |
|
97 | - |
|
98 | - if (array_key_exists('quantity', $input)) { |
|
99 | - $args['TKT_qty'] = (int) $input['quantity']; |
|
100 | - } |
|
101 | - |
|
102 | - if (array_key_exists('reserved', $input)) { |
|
103 | - $args['TKT_reserved'] = (int) $input['reserved']; |
|
104 | - } |
|
105 | - |
|
106 | - if (array_key_exists('reverseCalculate', $input)) { |
|
107 | - $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
108 | - } |
|
109 | - |
|
110 | - if (array_key_exists('row', $input)) { |
|
111 | - $args['TKT_row'] = (int) $input['row']; |
|
112 | - } |
|
113 | - |
|
114 | - if (array_key_exists('sold', $input)) { |
|
115 | - $args['TKT_sold'] = (int) $input['sold']; |
|
116 | - } |
|
117 | - |
|
118 | - if (! empty($input['startDate'])) { |
|
119 | - $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
120 | - } |
|
121 | - |
|
122 | - if (array_key_exists('uses', $input)) { |
|
123 | - $args['TKT_uses'] = (int) $input['uses']; |
|
124 | - } |
|
125 | - |
|
126 | - if (! empty($input['wpUser'])) { |
|
127 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
128 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
129 | - } |
|
130 | - |
|
131 | - return $args; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Sets the related datetimes for the given ticket. |
|
137 | - * |
|
138 | - * @param EE_Ticket $entity The Ticket instance. |
|
139 | - * @param array $datetimes Array of datetime IDs to relate. |
|
140 | - * @throws EE_Error |
|
141 | - * @throws InvalidArgumentException |
|
142 | - * @throws InvalidDataTypeException |
|
143 | - * @throws InvalidInterfaceException |
|
144 | - * @throws ReflectionException |
|
145 | - */ |
|
146 | - public static function setRelatedDatetimes($entity, array $datetimes) |
|
147 | - { |
|
148 | - $relationName = 'Datetime'; |
|
149 | - // Remove all the existing related datetimes |
|
150 | - |
|
151 | - $entity->_remove_relations($relationName); |
|
152 | - // @todo replace loop with single query |
|
153 | - foreach ($datetimes as $ID) { |
|
154 | - $parts = Relay::fromGlobalId($ID); |
|
155 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
156 | - $entity->_add_relation_to( |
|
157 | - $parts['id'], |
|
158 | - $relationName |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Sets the related prices for the given ticket. |
|
167 | - * |
|
168 | - * @param EE_Ticket $entity The Ticket instance. |
|
169 | - * @param array $prices Array of entity IDs to relate. |
|
170 | - * @throws EE_Error |
|
171 | - * @throws InvalidArgumentException |
|
172 | - * @throws InvalidDataTypeException |
|
173 | - * @throws InvalidInterfaceException |
|
174 | - * @throws ReflectionException |
|
175 | - */ |
|
176 | - public static function setRelatedPrices($entity, array $prices) |
|
177 | - { |
|
178 | - $relationName = 'Price'; |
|
179 | - // Remove all the existing related entities |
|
180 | - $entity->_remove_relations($relationName); |
|
181 | - |
|
182 | - // @todo replace loop with single query |
|
183 | - foreach ($prices as $ID) { |
|
184 | - $parts = Relay::fromGlobalId($ID); |
|
185 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
186 | - $entity->_add_relation_to( |
|
187 | - $parts['id'], |
|
188 | - $relationName |
|
189 | - ); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @param EE_Ticket $ticket_entity |
|
197 | - * @param EEM_Ticket $ticket_model |
|
198 | - * @throws DomainException |
|
199 | - * @throws EE_Error |
|
200 | - * @throws InvalidArgumentException |
|
201 | - * @throws InvalidDataTypeException |
|
202 | - * @throws InvalidInterfaceException |
|
203 | - * @throws ModelConfigurationException |
|
204 | - * @throws ReflectionException |
|
205 | - * @throws RestException |
|
206 | - * @throws UnexpectedEntityException |
|
207 | - * @throws EE_Error |
|
208 | - * @since $VID:$ |
|
209 | - */ |
|
210 | - public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model) |
|
211 | - { |
|
212 | - $price_model = EEM_Price::instance(); |
|
213 | - $default_prices = $price_model->get_all_default_prices(); |
|
214 | - foreach ($default_prices as $default_price) { |
|
215 | - $default_price->save(); |
|
216 | - $default_price->_add_relation_to($ticket_entity, 'Ticket'); |
|
217 | - } |
|
218 | - } |
|
30 | + /** |
|
31 | + * Maps the GraphQL input to a format that the model functions can use |
|
32 | + * |
|
33 | + * @param array $input Data coming from the GraphQL mutation query input |
|
34 | + * @return array |
|
35 | + * @throws Exception |
|
36 | + */ |
|
37 | + public static function prepareFields(array $input) |
|
38 | + { |
|
39 | + $args = []; |
|
40 | + |
|
41 | + if (! empty($input['datetimes'])) { |
|
42 | + $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
43 | + } |
|
44 | + |
|
45 | + if (! empty($input['description'])) { |
|
46 | + $args['TKT_description'] = sanitize_text_field($input['description']); |
|
47 | + } |
|
48 | + |
|
49 | + if (! empty($input['endDate'])) { |
|
50 | + $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
51 | + } |
|
52 | + |
|
53 | + if (array_key_exists('isDefault', $input)) { |
|
54 | + $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
55 | + } |
|
56 | + |
|
57 | + if (array_key_exists('isRequired', $input)) { |
|
58 | + $args['TKT_required'] = (bool) $input['isRequired']; |
|
59 | + } |
|
60 | + |
|
61 | + if (array_key_exists('isTaxable', $input)) { |
|
62 | + $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
63 | + } |
|
64 | + |
|
65 | + if (array_key_exists('isTrashed', $input)) { |
|
66 | + $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
67 | + } |
|
68 | + |
|
69 | + if (array_key_exists('max', $input)) { |
|
70 | + $args['TKT_max'] = (int) $input['max']; |
|
71 | + } |
|
72 | + |
|
73 | + if (array_key_exists('min', $input)) { |
|
74 | + $args['TKT_min'] = (int) $input['min']; |
|
75 | + } |
|
76 | + |
|
77 | + if (! empty($input['name'])) { |
|
78 | + $args['TKT_name'] = sanitize_text_field($input['name']); |
|
79 | + } |
|
80 | + |
|
81 | + if (array_key_exists('order', $input)) { |
|
82 | + $args['TKT_order'] = (int) $input['order']; |
|
83 | + } |
|
84 | + |
|
85 | + if (! empty($input['parent'])) { |
|
86 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
87 | + $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
88 | + } |
|
89 | + |
|
90 | + if (! empty($input['price'])) { |
|
91 | + $args['TKT_price'] = (float) $input['price']; |
|
92 | + } |
|
93 | + |
|
94 | + if (! empty($input['prices'])) { |
|
95 | + $args['prices'] = array_map('sanitize_text_field', (array) $input['prices']); |
|
96 | + } |
|
97 | + |
|
98 | + if (array_key_exists('quantity', $input)) { |
|
99 | + $args['TKT_qty'] = (int) $input['quantity']; |
|
100 | + } |
|
101 | + |
|
102 | + if (array_key_exists('reserved', $input)) { |
|
103 | + $args['TKT_reserved'] = (int) $input['reserved']; |
|
104 | + } |
|
105 | + |
|
106 | + if (array_key_exists('reverseCalculate', $input)) { |
|
107 | + $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
108 | + } |
|
109 | + |
|
110 | + if (array_key_exists('row', $input)) { |
|
111 | + $args['TKT_row'] = (int) $input['row']; |
|
112 | + } |
|
113 | + |
|
114 | + if (array_key_exists('sold', $input)) { |
|
115 | + $args['TKT_sold'] = (int) $input['sold']; |
|
116 | + } |
|
117 | + |
|
118 | + if (! empty($input['startDate'])) { |
|
119 | + $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
120 | + } |
|
121 | + |
|
122 | + if (array_key_exists('uses', $input)) { |
|
123 | + $args['TKT_uses'] = (int) $input['uses']; |
|
124 | + } |
|
125 | + |
|
126 | + if (! empty($input['wpUser'])) { |
|
127 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
128 | + $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
129 | + } |
|
130 | + |
|
131 | + return $args; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Sets the related datetimes for the given ticket. |
|
137 | + * |
|
138 | + * @param EE_Ticket $entity The Ticket instance. |
|
139 | + * @param array $datetimes Array of datetime IDs to relate. |
|
140 | + * @throws EE_Error |
|
141 | + * @throws InvalidArgumentException |
|
142 | + * @throws InvalidDataTypeException |
|
143 | + * @throws InvalidInterfaceException |
|
144 | + * @throws ReflectionException |
|
145 | + */ |
|
146 | + public static function setRelatedDatetimes($entity, array $datetimes) |
|
147 | + { |
|
148 | + $relationName = 'Datetime'; |
|
149 | + // Remove all the existing related datetimes |
|
150 | + |
|
151 | + $entity->_remove_relations($relationName); |
|
152 | + // @todo replace loop with single query |
|
153 | + foreach ($datetimes as $ID) { |
|
154 | + $parts = Relay::fromGlobalId($ID); |
|
155 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
156 | + $entity->_add_relation_to( |
|
157 | + $parts['id'], |
|
158 | + $relationName |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Sets the related prices for the given ticket. |
|
167 | + * |
|
168 | + * @param EE_Ticket $entity The Ticket instance. |
|
169 | + * @param array $prices Array of entity IDs to relate. |
|
170 | + * @throws EE_Error |
|
171 | + * @throws InvalidArgumentException |
|
172 | + * @throws InvalidDataTypeException |
|
173 | + * @throws InvalidInterfaceException |
|
174 | + * @throws ReflectionException |
|
175 | + */ |
|
176 | + public static function setRelatedPrices($entity, array $prices) |
|
177 | + { |
|
178 | + $relationName = 'Price'; |
|
179 | + // Remove all the existing related entities |
|
180 | + $entity->_remove_relations($relationName); |
|
181 | + |
|
182 | + // @todo replace loop with single query |
|
183 | + foreach ($prices as $ID) { |
|
184 | + $parts = Relay::fromGlobalId($ID); |
|
185 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
186 | + $entity->_add_relation_to( |
|
187 | + $parts['id'], |
|
188 | + $relationName |
|
189 | + ); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @param EE_Ticket $ticket_entity |
|
197 | + * @param EEM_Ticket $ticket_model |
|
198 | + * @throws DomainException |
|
199 | + * @throws EE_Error |
|
200 | + * @throws InvalidArgumentException |
|
201 | + * @throws InvalidDataTypeException |
|
202 | + * @throws InvalidInterfaceException |
|
203 | + * @throws ModelConfigurationException |
|
204 | + * @throws ReflectionException |
|
205 | + * @throws RestException |
|
206 | + * @throws UnexpectedEntityException |
|
207 | + * @throws EE_Error |
|
208 | + * @since $VID:$ |
|
209 | + */ |
|
210 | + public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model) |
|
211 | + { |
|
212 | + $price_model = EEM_Price::instance(); |
|
213 | + $default_prices = $price_model->get_all_default_prices(); |
|
214 | + foreach ($default_prices as $default_price) { |
|
215 | + $default_price->save(); |
|
216 | + $default_price->_add_relation_to($ticket_entity, 'Ticket'); |
|
217 | + } |
|
218 | + } |
|
219 | 219 | } |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | { |
39 | 39 | $args = []; |
40 | 40 | |
41 | - if (! empty($input['datetimes'])) { |
|
41 | + if ( ! empty($input['datetimes'])) { |
|
42 | 42 | $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
43 | 43 | } |
44 | 44 | |
45 | - if (! empty($input['description'])) { |
|
45 | + if ( ! empty($input['description'])) { |
|
46 | 46 | $args['TKT_description'] = sanitize_text_field($input['description']); |
47 | 47 | } |
48 | 48 | |
49 | - if (! empty($input['endDate'])) { |
|
49 | + if ( ! empty($input['endDate'])) { |
|
50 | 50 | $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
51 | 51 | } |
52 | 52 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $args['TKT_min'] = (int) $input['min']; |
75 | 75 | } |
76 | 76 | |
77 | - if (! empty($input['name'])) { |
|
77 | + if ( ! empty($input['name'])) { |
|
78 | 78 | $args['TKT_name'] = sanitize_text_field($input['name']); |
79 | 79 | } |
80 | 80 | |
@@ -82,16 +82,16 @@ discard block |
||
82 | 82 | $args['TKT_order'] = (int) $input['order']; |
83 | 83 | } |
84 | 84 | |
85 | - if (! empty($input['parent'])) { |
|
85 | + if ( ! empty($input['parent'])) { |
|
86 | 86 | $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
87 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
87 | + $args['TKT_parent'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
88 | 88 | } |
89 | 89 | |
90 | - if (! empty($input['price'])) { |
|
90 | + if ( ! empty($input['price'])) { |
|
91 | 91 | $args['TKT_price'] = (float) $input['price']; |
92 | 92 | } |
93 | 93 | |
94 | - if (! empty($input['prices'])) { |
|
94 | + if ( ! empty($input['prices'])) { |
|
95 | 95 | $args['prices'] = array_map('sanitize_text_field', (array) $input['prices']); |
96 | 96 | } |
97 | 97 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $args['TKT_sold'] = (int) $input['sold']; |
116 | 116 | } |
117 | 117 | |
118 | - if (! empty($input['startDate'])) { |
|
118 | + if ( ! empty($input['startDate'])) { |
|
119 | 119 | $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
120 | 120 | } |
121 | 121 | |
@@ -123,9 +123,9 @@ discard block |
||
123 | 123 | $args['TKT_uses'] = (int) $input['uses']; |
124 | 124 | } |
125 | 125 | |
126 | - if (! empty($input['wpUser'])) { |
|
126 | + if ( ! empty($input['wpUser'])) { |
|
127 | 127 | $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
128 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
128 | + $args['TKT_wp_user'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | return $args; |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | // @todo replace loop with single query |
153 | 153 | foreach ($datetimes as $ID) { |
154 | 154 | $parts = Relay::fromGlobalId($ID); |
155 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
155 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
156 | 156 | $entity->_add_relation_to( |
157 | 157 | $parts['id'], |
158 | 158 | $relationName |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | // @todo replace loop with single query |
183 | 183 | foreach ($prices as $ID) { |
184 | 184 | $parts = Relay::fromGlobalId($ID); |
185 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
185 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
186 | 186 | $entity->_add_relation_to( |
187 | 187 | $parts['id'], |
188 | 188 | $relationName |
@@ -13,59 +13,59 @@ |
||
13 | 13 | class PriceMutation |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Maps the GraphQL input to a format that the model functions can use |
|
18 | - * |
|
19 | - * @param array $input Data coming from the GraphQL mutation query input |
|
20 | - * @return array |
|
21 | - */ |
|
22 | - public static function prepareFields(array $input) |
|
23 | - { |
|
24 | - $args = []; |
|
16 | + /** |
|
17 | + * Maps the GraphQL input to a format that the model functions can use |
|
18 | + * |
|
19 | + * @param array $input Data coming from the GraphQL mutation query input |
|
20 | + * @return array |
|
21 | + */ |
|
22 | + public static function prepareFields(array $input) |
|
23 | + { |
|
24 | + $args = []; |
|
25 | 25 | |
26 | - if (! empty($input['amount'])) { |
|
27 | - $args['PRC_amount'] = (float) $input['amount']; |
|
28 | - } |
|
26 | + if (! empty($input['amount'])) { |
|
27 | + $args['PRC_amount'] = (float) $input['amount']; |
|
28 | + } |
|
29 | 29 | |
30 | - if (! empty($input['desc'])) { |
|
31 | - $args['PRC_desc'] = sanitize_text_field($input['desc']); |
|
32 | - } |
|
30 | + if (! empty($input['desc'])) { |
|
31 | + $args['PRC_desc'] = sanitize_text_field($input['desc']); |
|
32 | + } |
|
33 | 33 | |
34 | - if (array_key_exists('isDefault', $input)) { |
|
35 | - $args['PRC_is_default'] = (bool) $input['isDefault']; |
|
36 | - } |
|
34 | + if (array_key_exists('isDefault', $input)) { |
|
35 | + $args['PRC_is_default'] = (bool) $input['isDefault']; |
|
36 | + } |
|
37 | 37 | |
38 | - if (array_key_exists('isTrashed', $input)) { |
|
39 | - $args['PRC_deleted'] = (bool) $input['isTrashed']; |
|
40 | - } |
|
38 | + if (array_key_exists('isTrashed', $input)) { |
|
39 | + $args['PRC_deleted'] = (bool) $input['isTrashed']; |
|
40 | + } |
|
41 | 41 | |
42 | - if (! empty($input['name'])) { |
|
43 | - $args['PRC_name'] = sanitize_text_field($input['name']); |
|
44 | - } |
|
42 | + if (! empty($input['name'])) { |
|
43 | + $args['PRC_name'] = sanitize_text_field($input['name']); |
|
44 | + } |
|
45 | 45 | |
46 | - if (! empty($input['order'])) { |
|
47 | - $args['PRC_order'] = (int) $input['order']; |
|
48 | - } |
|
46 | + if (! empty($input['order'])) { |
|
47 | + $args['PRC_order'] = (int) $input['order']; |
|
48 | + } |
|
49 | 49 | |
50 | - if (! empty($input['overrides'])) { |
|
51 | - $args['PRC_overrides'] = (int) $input['overrides']; |
|
52 | - } |
|
50 | + if (! empty($input['overrides'])) { |
|
51 | + $args['PRC_overrides'] = (int) $input['overrides']; |
|
52 | + } |
|
53 | 53 | |
54 | - if (! empty($input['parent'])) { |
|
55 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
56 | - $args['PRC_parent'] = ! empty($parts['id']) ? absint($parts['id']) : 0; |
|
57 | - } |
|
54 | + if (! empty($input['parent'])) { |
|
55 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
56 | + $args['PRC_parent'] = ! empty($parts['id']) ? absint($parts['id']) : 0; |
|
57 | + } |
|
58 | 58 | |
59 | - if (! empty($input['priceType'])) { |
|
60 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['priceType'])); |
|
61 | - $args['PRT_ID'] = ! empty($parts['id']) ? absint($parts['id']) : 0; |
|
62 | - } |
|
59 | + if (! empty($input['priceType'])) { |
|
60 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['priceType'])); |
|
61 | + $args['PRT_ID'] = ! empty($parts['id']) ? absint($parts['id']) : 0; |
|
62 | + } |
|
63 | 63 | |
64 | - if (! empty($input['wpUser'])) { |
|
65 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
66 | - $args['PRC_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
67 | - } |
|
64 | + if (! empty($input['wpUser'])) { |
|
65 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
66 | + $args['PRC_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
67 | + } |
|
68 | 68 | |
69 | - return $args; |
|
70 | - } |
|
69 | + return $args; |
|
70 | + } |
|
71 | 71 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | { |
24 | 24 | $args = []; |
25 | 25 | |
26 | - if (! empty($input['amount'])) { |
|
26 | + if ( ! empty($input['amount'])) { |
|
27 | 27 | $args['PRC_amount'] = (float) $input['amount']; |
28 | 28 | } |
29 | 29 | |
30 | - if (! empty($input['desc'])) { |
|
30 | + if ( ! empty($input['desc'])) { |
|
31 | 31 | $args['PRC_desc'] = sanitize_text_field($input['desc']); |
32 | 32 | } |
33 | 33 | |
@@ -39,31 +39,31 @@ discard block |
||
39 | 39 | $args['PRC_deleted'] = (bool) $input['isTrashed']; |
40 | 40 | } |
41 | 41 | |
42 | - if (! empty($input['name'])) { |
|
42 | + if ( ! empty($input['name'])) { |
|
43 | 43 | $args['PRC_name'] = sanitize_text_field($input['name']); |
44 | 44 | } |
45 | 45 | |
46 | - if (! empty($input['order'])) { |
|
46 | + if ( ! empty($input['order'])) { |
|
47 | 47 | $args['PRC_order'] = (int) $input['order']; |
48 | 48 | } |
49 | 49 | |
50 | - if (! empty($input['overrides'])) { |
|
50 | + if ( ! empty($input['overrides'])) { |
|
51 | 51 | $args['PRC_overrides'] = (int) $input['overrides']; |
52 | 52 | } |
53 | 53 | |
54 | - if (! empty($input['parent'])) { |
|
54 | + if ( ! empty($input['parent'])) { |
|
55 | 55 | $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
56 | 56 | $args['PRC_parent'] = ! empty($parts['id']) ? absint($parts['id']) : 0; |
57 | 57 | } |
58 | 58 | |
59 | - if (! empty($input['priceType'])) { |
|
59 | + if ( ! empty($input['priceType'])) { |
|
60 | 60 | $parts = Relay::fromGlobalId(sanitize_text_field($input['priceType'])); |
61 | 61 | $args['PRT_ID'] = ! empty($parts['id']) ? absint($parts['id']) : 0; |
62 | 62 | } |
63 | 63 | |
64 | - if (! empty($input['wpUser'])) { |
|
64 | + if ( ! empty($input['wpUser'])) { |
|
65 | 65 | $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
66 | - $args['PRC_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
66 | + $args['PRC_wp_user'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | return $args; |
@@ -21,102 +21,102 @@ |
||
21 | 21 | class DatetimeMutation |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * Maps the GraphQL input to a format that the model functions can use |
|
26 | - * |
|
27 | - * @param array $input Data coming from the GraphQL mutation query input |
|
28 | - * @return array |
|
29 | - * @throws Exception |
|
30 | - */ |
|
31 | - public static function prepareFields(array $input) |
|
32 | - { |
|
33 | - $args = []; |
|
34 | - |
|
35 | - if (array_key_exists('capacity', $input)) { |
|
36 | - $args['DTT_reg_limit'] = (int) $input['capacity']; |
|
37 | - } |
|
38 | - |
|
39 | - if (! empty($input['description'])) { |
|
40 | - $args['DTT_description'] = sanitize_text_field($input['description']); |
|
41 | - } |
|
42 | - |
|
43 | - if (! empty($input['endDate'])) { |
|
44 | - $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
45 | - } |
|
46 | - |
|
47 | - if (! empty($input['eventId'])) { |
|
48 | - $args['EVT_ID'] = absint($input['eventId']); |
|
49 | - } elseif (! empty($input['event'])) { |
|
50 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
|
51 | - $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
52 | - } |
|
53 | - |
|
54 | - if (array_key_exists('isPrimary', $input)) { |
|
55 | - $args['DTT_is_primary'] = (bool) $input['isPrimary']; |
|
56 | - } |
|
57 | - |
|
58 | - if (array_key_exists('isTrashed', $input)) { |
|
59 | - $args['DTT_deleted'] = (bool) $input['isTrashed']; |
|
60 | - } |
|
61 | - |
|
62 | - if (! empty($input['name'])) { |
|
63 | - $args['DTT_name'] = sanitize_text_field($input['name']); |
|
64 | - } |
|
65 | - |
|
66 | - if (array_key_exists('order', $input)) { |
|
67 | - $args['DTT_order'] = (int) $input['order']; |
|
68 | - } |
|
69 | - |
|
70 | - if (! empty($input['parent'])) { |
|
71 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
72 | - $args['DTT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
73 | - } |
|
74 | - |
|
75 | - if (array_key_exists('reserved', $input)) { |
|
76 | - $args['DTT_reserved'] = (int) $input['reserved']; |
|
77 | - } |
|
78 | - |
|
79 | - if (array_key_exists('sold', $input)) { |
|
80 | - $args['DTT_sold'] = (int) $input['sold']; |
|
81 | - } |
|
82 | - |
|
83 | - if (! empty($input['startDate'])) { |
|
84 | - $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
85 | - } |
|
86 | - |
|
87 | - if (! empty($input['tickets'])) { |
|
88 | - $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
|
89 | - } |
|
90 | - |
|
91 | - return $args; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Sets the related tickets for the given datetime. |
|
97 | - * |
|
98 | - * @param EE_Datetime $entity The datetime instance. |
|
99 | - * @param array $tickets Array of ticket IDs to relate. |
|
100 | - * @throws EE_Error |
|
101 | - * @throws InvalidDataTypeException |
|
102 | - * @throws InvalidInterfaceException |
|
103 | - * @throws InvalidArgumentException |
|
104 | - * @throws ReflectionException |
|
105 | - */ |
|
106 | - public static function setRelatedTickets($entity, array $tickets) |
|
107 | - { |
|
108 | - $relationName = 'Ticket'; |
|
109 | - // Remove all the existing related tickets |
|
110 | - $entity->_remove_relations($relationName); |
|
111 | - |
|
112 | - foreach ($tickets as $ID) { |
|
113 | - $parts = Relay::fromGlobalId($ID); |
|
114 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
115 | - $entity->_add_relation_to( |
|
116 | - $parts['id'], |
|
117 | - $relationName |
|
118 | - ); |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
24 | + /** |
|
25 | + * Maps the GraphQL input to a format that the model functions can use |
|
26 | + * |
|
27 | + * @param array $input Data coming from the GraphQL mutation query input |
|
28 | + * @return array |
|
29 | + * @throws Exception |
|
30 | + */ |
|
31 | + public static function prepareFields(array $input) |
|
32 | + { |
|
33 | + $args = []; |
|
34 | + |
|
35 | + if (array_key_exists('capacity', $input)) { |
|
36 | + $args['DTT_reg_limit'] = (int) $input['capacity']; |
|
37 | + } |
|
38 | + |
|
39 | + if (! empty($input['description'])) { |
|
40 | + $args['DTT_description'] = sanitize_text_field($input['description']); |
|
41 | + } |
|
42 | + |
|
43 | + if (! empty($input['endDate'])) { |
|
44 | + $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
45 | + } |
|
46 | + |
|
47 | + if (! empty($input['eventId'])) { |
|
48 | + $args['EVT_ID'] = absint($input['eventId']); |
|
49 | + } elseif (! empty($input['event'])) { |
|
50 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
|
51 | + $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
52 | + } |
|
53 | + |
|
54 | + if (array_key_exists('isPrimary', $input)) { |
|
55 | + $args['DTT_is_primary'] = (bool) $input['isPrimary']; |
|
56 | + } |
|
57 | + |
|
58 | + if (array_key_exists('isTrashed', $input)) { |
|
59 | + $args['DTT_deleted'] = (bool) $input['isTrashed']; |
|
60 | + } |
|
61 | + |
|
62 | + if (! empty($input['name'])) { |
|
63 | + $args['DTT_name'] = sanitize_text_field($input['name']); |
|
64 | + } |
|
65 | + |
|
66 | + if (array_key_exists('order', $input)) { |
|
67 | + $args['DTT_order'] = (int) $input['order']; |
|
68 | + } |
|
69 | + |
|
70 | + if (! empty($input['parent'])) { |
|
71 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
72 | + $args['DTT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
73 | + } |
|
74 | + |
|
75 | + if (array_key_exists('reserved', $input)) { |
|
76 | + $args['DTT_reserved'] = (int) $input['reserved']; |
|
77 | + } |
|
78 | + |
|
79 | + if (array_key_exists('sold', $input)) { |
|
80 | + $args['DTT_sold'] = (int) $input['sold']; |
|
81 | + } |
|
82 | + |
|
83 | + if (! empty($input['startDate'])) { |
|
84 | + $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
85 | + } |
|
86 | + |
|
87 | + if (! empty($input['tickets'])) { |
|
88 | + $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
|
89 | + } |
|
90 | + |
|
91 | + return $args; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Sets the related tickets for the given datetime. |
|
97 | + * |
|
98 | + * @param EE_Datetime $entity The datetime instance. |
|
99 | + * @param array $tickets Array of ticket IDs to relate. |
|
100 | + * @throws EE_Error |
|
101 | + * @throws InvalidDataTypeException |
|
102 | + * @throws InvalidInterfaceException |
|
103 | + * @throws InvalidArgumentException |
|
104 | + * @throws ReflectionException |
|
105 | + */ |
|
106 | + public static function setRelatedTickets($entity, array $tickets) |
|
107 | + { |
|
108 | + $relationName = 'Ticket'; |
|
109 | + // Remove all the existing related tickets |
|
110 | + $entity->_remove_relations($relationName); |
|
111 | + |
|
112 | + foreach ($tickets as $ID) { |
|
113 | + $parts = Relay::fromGlobalId($ID); |
|
114 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
115 | + $entity->_add_relation_to( |
|
116 | + $parts['id'], |
|
117 | + $relationName |
|
118 | + ); |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | 122 | } |
@@ -36,19 +36,19 @@ discard block |
||
36 | 36 | $args['DTT_reg_limit'] = (int) $input['capacity']; |
37 | 37 | } |
38 | 38 | |
39 | - if (! empty($input['description'])) { |
|
39 | + if ( ! empty($input['description'])) { |
|
40 | 40 | $args['DTT_description'] = sanitize_text_field($input['description']); |
41 | 41 | } |
42 | 42 | |
43 | - if (! empty($input['endDate'])) { |
|
43 | + if ( ! empty($input['endDate'])) { |
|
44 | 44 | $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
45 | 45 | } |
46 | 46 | |
47 | - if (! empty($input['eventId'])) { |
|
47 | + if ( ! empty($input['eventId'])) { |
|
48 | 48 | $args['EVT_ID'] = absint($input['eventId']); |
49 | - } elseif (! empty($input['event'])) { |
|
49 | + } elseif ( ! empty($input['event'])) { |
|
50 | 50 | $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
51 | - $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
51 | + $args['EVT_ID'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | if (array_key_exists('isPrimary', $input)) { |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | $args['DTT_deleted'] = (bool) $input['isTrashed']; |
60 | 60 | } |
61 | 61 | |
62 | - if (! empty($input['name'])) { |
|
62 | + if ( ! empty($input['name'])) { |
|
63 | 63 | $args['DTT_name'] = sanitize_text_field($input['name']); |
64 | 64 | } |
65 | 65 | |
@@ -67,9 +67,9 @@ discard block |
||
67 | 67 | $args['DTT_order'] = (int) $input['order']; |
68 | 68 | } |
69 | 69 | |
70 | - if (! empty($input['parent'])) { |
|
70 | + if ( ! empty($input['parent'])) { |
|
71 | 71 | $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
72 | - $args['DTT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
72 | + $args['DTT_parent'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | if (array_key_exists('reserved', $input)) { |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | $args['DTT_sold'] = (int) $input['sold']; |
81 | 81 | } |
82 | 82 | |
83 | - if (! empty($input['startDate'])) { |
|
83 | + if ( ! empty($input['startDate'])) { |
|
84 | 84 | $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
85 | 85 | } |
86 | 86 | |
87 | - if (! empty($input['tickets'])) { |
|
87 | + if ( ! empty($input['tickets'])) { |
|
88 | 88 | $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
89 | 89 | } |
90 | 90 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | |
112 | 112 | foreach ($tickets as $ID) { |
113 | 113 | $parts = Relay::fromGlobalId($ID); |
114 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
114 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
115 | 115 | $entity->_add_relation_to( |
116 | 116 | $parts['id'], |
117 | 117 | $relationName |