@@ -24,223 +24,223 @@ |
||
24 | 24 | */ |
25 | 25 | class DefaultPrices implements DefaultEntityGeneratorInterface |
26 | 26 | { |
27 | - /** |
|
28 | - * @var EEM_Price |
|
29 | - */ |
|
30 | - protected $price_model; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EEM_Price_Type |
|
34 | - */ |
|
35 | - protected $price_type_model; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Price[] |
|
39 | - */ |
|
40 | - protected $new_prices = []; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Price[] |
|
44 | - */ |
|
45 | - protected $taxes = []; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param EEM_Price $price_model |
|
50 | - * @param EEM_Price_Type $price_type_model |
|
51 | - */ |
|
52 | - public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model) |
|
53 | - { |
|
54 | - $this->price_model = $price_model; |
|
55 | - $this->price_type_model = $price_type_model; |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @param EE_Ticket|EE_Base_Class $entity |
|
61 | - * @return EE_Price[] |
|
62 | - * @throws EE_Error |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - * @throws ReflectionException |
|
65 | - * @since 5.0.0.p |
|
66 | - */ |
|
67 | - public function create(EE_Base_Class $entity): array |
|
68 | - { |
|
69 | - if (! $entity instanceof EE_Ticket) { |
|
70 | - throw new InvalidEntityException($entity, 'EE_Ticket'); |
|
71 | - } |
|
72 | - $is_free = true; |
|
73 | - $has_base_price = false; |
|
74 | - $remove_existing_relations = true; |
|
75 | - // first, let's get all of the default taxes for the site |
|
76 | - $this->taxes = $this->price_model->getAllDefaultTaxes(); |
|
77 | - // then separate taxes from the other prices for the existing default ticket prices |
|
78 | - $default_prices = $this->separateTaxesFromOtherPrices($entity->prices()); |
|
79 | - // but if that's empty, then let's get the default global prices |
|
80 | - if (empty($default_prices)) { |
|
81 | - $default_global_prices = $this->price_model->get_all_default_prices(); |
|
82 | - $default_prices = $this->separateTaxesFromOtherPrices($default_global_prices); |
|
83 | - $remove_existing_relations = false; |
|
84 | - } |
|
85 | - // then clone and apply all of the default prices |
|
86 | - [$has_base_price, $is_free] = $this->cloneDefaultPrices( |
|
87 | - $entity, |
|
88 | - $default_prices, |
|
89 | - $remove_existing_relations, |
|
90 | - $has_base_price, |
|
91 | - $is_free |
|
92 | - ); |
|
93 | - if (! $has_base_price) { |
|
94 | - $new_base_price = $this->createNewBasePrice($entity); |
|
95 | - $this->new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
96 | - } |
|
97 | - $this->applyTaxes($entity, $is_free); |
|
98 | - $ticket_total = $entity->get_ticket_total_with_taxes(true); |
|
99 | - if ($ticket_total !== $entity->ticket_price()) { |
|
100 | - $entity->set_price($ticket_total); |
|
101 | - $entity->save(); |
|
102 | - } |
|
103 | - return $this->new_prices; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * @param EE_Ticket $ticket |
|
109 | - * @param bool $is_free |
|
110 | - * @throws EE_Error |
|
111 | - * @throws ReflectionException |
|
112 | - */ |
|
113 | - private function applyTaxes(EE_Ticket $ticket, bool $is_free) |
|
114 | - { |
|
115 | - if (! $is_free && $ticket->taxable() && ! empty($this->taxes)) { |
|
116 | - foreach ($this->taxes as $tax) { |
|
117 | - // assign taxes but don't duplicate them because they operate globally |
|
118 | - $ticket->set_taxable(true); |
|
119 | - $tax->_add_relation_to($ticket, 'Ticket'); |
|
120 | - } |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @param EE_Ticket $ticket |
|
127 | - * @param EE_Price[] $default_prices |
|
128 | - * @param bool $remove_existing_relations |
|
129 | - * @param bool $has_base_price |
|
130 | - * @param bool $is_free |
|
131 | - * @return bool[] |
|
132 | - * @throws EE_Error |
|
133 | - * @throws ReflectionException |
|
134 | - */ |
|
135 | - private function cloneDefaultPrices( |
|
136 | - EE_Ticket $ticket, |
|
137 | - array $default_prices, |
|
138 | - bool $remove_existing_relations, |
|
139 | - bool $has_base_price, |
|
140 | - bool $is_free |
|
141 | - ): array { |
|
142 | - foreach ($default_prices as $default_price) { |
|
143 | - // duplicate the default price so that it does not get mutated |
|
144 | - $default_price_clone = clone $default_price; |
|
145 | - if ($remove_existing_relations) { |
|
146 | - $ticket->_remove_relation_to($default_price, 'Price'); |
|
147 | - } |
|
148 | - if ( |
|
149 | - ( |
|
150 | - // has non-zero base price |
|
151 | - $default_price_clone->is_base_price() |
|
152 | - && $default_price_clone->amount() > 0 |
|
153 | - ) |
|
154 | - || ( |
|
155 | - // or has fixed amount surcharge |
|
156 | - $default_price_clone->is_surcharge() |
|
157 | - && ! $default_price_clone->is_percent() |
|
158 | - ) |
|
159 | - ) { |
|
160 | - $is_free = false; |
|
161 | - } |
|
162 | - $is_base_price = $default_price_clone->is_base_price(); |
|
163 | - // add this price to ticket if it is a regular price modifier, ie: NOT a base price, |
|
164 | - // OR if it IS a base price but this ticket does NOT already have a base price |
|
165 | - if (! $is_base_price || ! $has_base_price) { |
|
166 | - $default_price_clone->set('PRC_ID', null); |
|
167 | - $default_price_clone->set('PRC_is_default', false); |
|
168 | - |
|
169 | - $order = $default_price_clone->get('PRC_order'); |
|
170 | - |
|
171 | - // enforce base price order to be 1 and 5 if the order is not set for a modifier |
|
172 | - $order = $is_base_price ? 1 : $order; |
|
173 | - $order = $order ?? 5; |
|
174 | - |
|
175 | - $default_price_clone->set('PRC_order', $order); |
|
176 | - |
|
177 | - $default_price_clone->save(); |
|
178 | - $default_price_clone->_add_relation_to($ticket, 'Ticket'); |
|
179 | - $this->new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
180 | - // then recheck that a base price has been set so that we don't add another one |
|
181 | - $has_base_price = $is_base_price ? true : $has_base_price; |
|
182 | - } |
|
183 | - } |
|
184 | - return [$has_base_price, $is_free]; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * @param EE_Ticket $ticket |
|
190 | - * @return EE_Price |
|
191 | - * @throws EE_Error |
|
192 | - * @throws ReflectionException |
|
193 | - */ |
|
194 | - private function createNewBasePrice(EE_Ticket $ticket): EE_Price |
|
195 | - { |
|
196 | - $new_base_price = $this->price_model->get_new_price(); |
|
197 | - $base_price_type = $this->price_type_model->get_one( |
|
198 | - [ |
|
199 | - [ |
|
200 | - 'PBT_ID' => EEM_Price_Type::base_type_base_price, |
|
201 | - ], |
|
202 | - ] |
|
203 | - ); |
|
204 | - if (! $base_price_type instanceof EE_Price_Type) { |
|
205 | - throw new RuntimeException( |
|
206 | - esc_html__( |
|
207 | - 'A valid base price type could not be retrieved from the database.', |
|
208 | - 'event_espresso' |
|
209 | - ) |
|
210 | - ); |
|
211 | - } |
|
212 | - $new_base_price->set('PRT_ID', $base_price_type->ID()); |
|
213 | - // set base price order to 1 |
|
214 | - $new_base_price->set('PRC_order', 1); |
|
215 | - $new_base_price->set('PRC_is_default', false); |
|
216 | - $new_base_price->save(); |
|
217 | - $new_base_price->_add_relation_to($ticket, 'Ticket'); |
|
218 | - return $new_base_price; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * @param array $prices |
|
224 | - * @return array |
|
225 | - * @throws EE_Error |
|
226 | - * @throws ReflectionException |
|
227 | - */ |
|
228 | - private function separateTaxesFromOtherPrices(array $prices = []): array |
|
229 | - { |
|
230 | - $default_prices = []; |
|
231 | - if (is_array($prices)) { |
|
232 | - foreach ($prices as $key => $price) { |
|
233 | - if (! $price instanceof EE_Price) { |
|
234 | - throw new InvalidEntityException($price, 'EE_Price'); |
|
235 | - } |
|
236 | - // grab any taxes but don't do anything just yet |
|
237 | - if ($price->is_tax()) { |
|
238 | - $this->taxes[ $price->ID() ] = $price; |
|
239 | - continue; |
|
240 | - } |
|
241 | - $default_prices[ $price->ID() ] = $price; |
|
242 | - } |
|
243 | - } |
|
244 | - return $default_prices; |
|
245 | - } |
|
27 | + /** |
|
28 | + * @var EEM_Price |
|
29 | + */ |
|
30 | + protected $price_model; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EEM_Price_Type |
|
34 | + */ |
|
35 | + protected $price_type_model; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Price[] |
|
39 | + */ |
|
40 | + protected $new_prices = []; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Price[] |
|
44 | + */ |
|
45 | + protected $taxes = []; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param EEM_Price $price_model |
|
50 | + * @param EEM_Price_Type $price_type_model |
|
51 | + */ |
|
52 | + public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model) |
|
53 | + { |
|
54 | + $this->price_model = $price_model; |
|
55 | + $this->price_type_model = $price_type_model; |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @param EE_Ticket|EE_Base_Class $entity |
|
61 | + * @return EE_Price[] |
|
62 | + * @throws EE_Error |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + * @throws ReflectionException |
|
65 | + * @since 5.0.0.p |
|
66 | + */ |
|
67 | + public function create(EE_Base_Class $entity): array |
|
68 | + { |
|
69 | + if (! $entity instanceof EE_Ticket) { |
|
70 | + throw new InvalidEntityException($entity, 'EE_Ticket'); |
|
71 | + } |
|
72 | + $is_free = true; |
|
73 | + $has_base_price = false; |
|
74 | + $remove_existing_relations = true; |
|
75 | + // first, let's get all of the default taxes for the site |
|
76 | + $this->taxes = $this->price_model->getAllDefaultTaxes(); |
|
77 | + // then separate taxes from the other prices for the existing default ticket prices |
|
78 | + $default_prices = $this->separateTaxesFromOtherPrices($entity->prices()); |
|
79 | + // but if that's empty, then let's get the default global prices |
|
80 | + if (empty($default_prices)) { |
|
81 | + $default_global_prices = $this->price_model->get_all_default_prices(); |
|
82 | + $default_prices = $this->separateTaxesFromOtherPrices($default_global_prices); |
|
83 | + $remove_existing_relations = false; |
|
84 | + } |
|
85 | + // then clone and apply all of the default prices |
|
86 | + [$has_base_price, $is_free] = $this->cloneDefaultPrices( |
|
87 | + $entity, |
|
88 | + $default_prices, |
|
89 | + $remove_existing_relations, |
|
90 | + $has_base_price, |
|
91 | + $is_free |
|
92 | + ); |
|
93 | + if (! $has_base_price) { |
|
94 | + $new_base_price = $this->createNewBasePrice($entity); |
|
95 | + $this->new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
96 | + } |
|
97 | + $this->applyTaxes($entity, $is_free); |
|
98 | + $ticket_total = $entity->get_ticket_total_with_taxes(true); |
|
99 | + if ($ticket_total !== $entity->ticket_price()) { |
|
100 | + $entity->set_price($ticket_total); |
|
101 | + $entity->save(); |
|
102 | + } |
|
103 | + return $this->new_prices; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * @param EE_Ticket $ticket |
|
109 | + * @param bool $is_free |
|
110 | + * @throws EE_Error |
|
111 | + * @throws ReflectionException |
|
112 | + */ |
|
113 | + private function applyTaxes(EE_Ticket $ticket, bool $is_free) |
|
114 | + { |
|
115 | + if (! $is_free && $ticket->taxable() && ! empty($this->taxes)) { |
|
116 | + foreach ($this->taxes as $tax) { |
|
117 | + // assign taxes but don't duplicate them because they operate globally |
|
118 | + $ticket->set_taxable(true); |
|
119 | + $tax->_add_relation_to($ticket, 'Ticket'); |
|
120 | + } |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @param EE_Ticket $ticket |
|
127 | + * @param EE_Price[] $default_prices |
|
128 | + * @param bool $remove_existing_relations |
|
129 | + * @param bool $has_base_price |
|
130 | + * @param bool $is_free |
|
131 | + * @return bool[] |
|
132 | + * @throws EE_Error |
|
133 | + * @throws ReflectionException |
|
134 | + */ |
|
135 | + private function cloneDefaultPrices( |
|
136 | + EE_Ticket $ticket, |
|
137 | + array $default_prices, |
|
138 | + bool $remove_existing_relations, |
|
139 | + bool $has_base_price, |
|
140 | + bool $is_free |
|
141 | + ): array { |
|
142 | + foreach ($default_prices as $default_price) { |
|
143 | + // duplicate the default price so that it does not get mutated |
|
144 | + $default_price_clone = clone $default_price; |
|
145 | + if ($remove_existing_relations) { |
|
146 | + $ticket->_remove_relation_to($default_price, 'Price'); |
|
147 | + } |
|
148 | + if ( |
|
149 | + ( |
|
150 | + // has non-zero base price |
|
151 | + $default_price_clone->is_base_price() |
|
152 | + && $default_price_clone->amount() > 0 |
|
153 | + ) |
|
154 | + || ( |
|
155 | + // or has fixed amount surcharge |
|
156 | + $default_price_clone->is_surcharge() |
|
157 | + && ! $default_price_clone->is_percent() |
|
158 | + ) |
|
159 | + ) { |
|
160 | + $is_free = false; |
|
161 | + } |
|
162 | + $is_base_price = $default_price_clone->is_base_price(); |
|
163 | + // add this price to ticket if it is a regular price modifier, ie: NOT a base price, |
|
164 | + // OR if it IS a base price but this ticket does NOT already have a base price |
|
165 | + if (! $is_base_price || ! $has_base_price) { |
|
166 | + $default_price_clone->set('PRC_ID', null); |
|
167 | + $default_price_clone->set('PRC_is_default', false); |
|
168 | + |
|
169 | + $order = $default_price_clone->get('PRC_order'); |
|
170 | + |
|
171 | + // enforce base price order to be 1 and 5 if the order is not set for a modifier |
|
172 | + $order = $is_base_price ? 1 : $order; |
|
173 | + $order = $order ?? 5; |
|
174 | + |
|
175 | + $default_price_clone->set('PRC_order', $order); |
|
176 | + |
|
177 | + $default_price_clone->save(); |
|
178 | + $default_price_clone->_add_relation_to($ticket, 'Ticket'); |
|
179 | + $this->new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
180 | + // then recheck that a base price has been set so that we don't add another one |
|
181 | + $has_base_price = $is_base_price ? true : $has_base_price; |
|
182 | + } |
|
183 | + } |
|
184 | + return [$has_base_price, $is_free]; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * @param EE_Ticket $ticket |
|
190 | + * @return EE_Price |
|
191 | + * @throws EE_Error |
|
192 | + * @throws ReflectionException |
|
193 | + */ |
|
194 | + private function createNewBasePrice(EE_Ticket $ticket): EE_Price |
|
195 | + { |
|
196 | + $new_base_price = $this->price_model->get_new_price(); |
|
197 | + $base_price_type = $this->price_type_model->get_one( |
|
198 | + [ |
|
199 | + [ |
|
200 | + 'PBT_ID' => EEM_Price_Type::base_type_base_price, |
|
201 | + ], |
|
202 | + ] |
|
203 | + ); |
|
204 | + if (! $base_price_type instanceof EE_Price_Type) { |
|
205 | + throw new RuntimeException( |
|
206 | + esc_html__( |
|
207 | + 'A valid base price type could not be retrieved from the database.', |
|
208 | + 'event_espresso' |
|
209 | + ) |
|
210 | + ); |
|
211 | + } |
|
212 | + $new_base_price->set('PRT_ID', $base_price_type->ID()); |
|
213 | + // set base price order to 1 |
|
214 | + $new_base_price->set('PRC_order', 1); |
|
215 | + $new_base_price->set('PRC_is_default', false); |
|
216 | + $new_base_price->save(); |
|
217 | + $new_base_price->_add_relation_to($ticket, 'Ticket'); |
|
218 | + return $new_base_price; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * @param array $prices |
|
224 | + * @return array |
|
225 | + * @throws EE_Error |
|
226 | + * @throws ReflectionException |
|
227 | + */ |
|
228 | + private function separateTaxesFromOtherPrices(array $prices = []): array |
|
229 | + { |
|
230 | + $default_prices = []; |
|
231 | + if (is_array($prices)) { |
|
232 | + foreach ($prices as $key => $price) { |
|
233 | + if (! $price instanceof EE_Price) { |
|
234 | + throw new InvalidEntityException($price, 'EE_Price'); |
|
235 | + } |
|
236 | + // grab any taxes but don't do anything just yet |
|
237 | + if ($price->is_tax()) { |
|
238 | + $this->taxes[ $price->ID() ] = $price; |
|
239 | + continue; |
|
240 | + } |
|
241 | + $default_prices[ $price->ID() ] = $price; |
|
242 | + } |
|
243 | + } |
|
244 | + return $default_prices; |
|
245 | + } |
|
246 | 246 | } |
@@ -21,64 +21,64 @@ |
||
21 | 21 | */ |
22 | 22 | class DefaultTickets implements DefaultEntityGeneratorInterface |
23 | 23 | { |
24 | - /** |
|
25 | - * @var DefaultPrices $default_prices |
|
26 | - */ |
|
27 | - protected $default_prices; |
|
24 | + /** |
|
25 | + * @var DefaultPrices $default_prices |
|
26 | + */ |
|
27 | + protected $default_prices; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var EEM_Ticket $ticket_model |
|
31 | - */ |
|
32 | - protected $ticket_model; |
|
29 | + /** |
|
30 | + * @var EEM_Ticket $ticket_model |
|
31 | + */ |
|
32 | + protected $ticket_model; |
|
33 | 33 | |
34 | 34 | |
35 | - /** |
|
36 | - * @param DefaultPrices $default_prices |
|
37 | - * @param EEM_Ticket $ticket_model |
|
38 | - */ |
|
39 | - public function __construct(DefaultPrices $default_prices, EEM_Ticket $ticket_model) |
|
40 | - { |
|
41 | - $this->default_prices = $default_prices; |
|
42 | - $this->ticket_model = $ticket_model; |
|
43 | - } |
|
35 | + /** |
|
36 | + * @param DefaultPrices $default_prices |
|
37 | + * @param EEM_Ticket $ticket_model |
|
38 | + */ |
|
39 | + public function __construct(DefaultPrices $default_prices, EEM_Ticket $ticket_model) |
|
40 | + { |
|
41 | + $this->default_prices = $default_prices; |
|
42 | + $this->ticket_model = $ticket_model; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @param EE_Datetime|EE_Base_Class $entity |
|
48 | - * @return EE_Ticket[] |
|
49 | - * @throws EE_Error |
|
50 | - * @throws InvalidEntityException |
|
51 | - * @throws ReflectionException |
|
52 | - * @since 5.0.0.p |
|
53 | - */ |
|
54 | - public function create(EE_Base_Class $entity): array |
|
55 | - { |
|
56 | - if (! $entity instanceof EE_Datetime) { |
|
57 | - throw new InvalidEntityException($entity, 'EE_Datetime'); |
|
58 | - } |
|
59 | - $new_tickets = []; |
|
60 | - $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
61 | - foreach ($default_tickets as $default_ticket) { |
|
62 | - if (! $default_ticket instanceof EE_Ticket) { |
|
63 | - throw new InvalidEntityException($default_ticket, 'EE_Ticket'); |
|
64 | - } |
|
65 | - $existing_default_prices = $default_ticket->prices(); |
|
66 | - // clone ticket, strip out ID, then save to get a new ID |
|
67 | - $default_ticket_clone = clone $default_ticket; |
|
68 | - $default_ticket_clone->set('TKT_ID', null); |
|
69 | - $default_ticket_clone->set('TKT_is_default', false); |
|
70 | - $default_ticket_clone->save(); |
|
71 | - $default_ticket_clone->_add_relation_to($entity, 'Datetime'); |
|
72 | - // temporarily adding relations to existing prices, but these will be cloned and removed |
|
73 | - // when passed to DefaultPrices::create() below so that they the clones can be freely mutated |
|
74 | - foreach ($existing_default_prices as $existing_default_price) { |
|
75 | - if ($existing_default_price instanceof EE_Price) { |
|
76 | - $existing_default_price->_add_relation_to($default_ticket_clone, 'Ticket'); |
|
77 | - } |
|
78 | - } |
|
79 | - $this->default_prices->create($default_ticket_clone); |
|
80 | - $new_tickets[ $default_ticket_clone->ID() ] = $default_ticket_clone; |
|
81 | - } |
|
82 | - return $new_tickets; |
|
83 | - } |
|
46 | + /** |
|
47 | + * @param EE_Datetime|EE_Base_Class $entity |
|
48 | + * @return EE_Ticket[] |
|
49 | + * @throws EE_Error |
|
50 | + * @throws InvalidEntityException |
|
51 | + * @throws ReflectionException |
|
52 | + * @since 5.0.0.p |
|
53 | + */ |
|
54 | + public function create(EE_Base_Class $entity): array |
|
55 | + { |
|
56 | + if (! $entity instanceof EE_Datetime) { |
|
57 | + throw new InvalidEntityException($entity, 'EE_Datetime'); |
|
58 | + } |
|
59 | + $new_tickets = []; |
|
60 | + $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
61 | + foreach ($default_tickets as $default_ticket) { |
|
62 | + if (! $default_ticket instanceof EE_Ticket) { |
|
63 | + throw new InvalidEntityException($default_ticket, 'EE_Ticket'); |
|
64 | + } |
|
65 | + $existing_default_prices = $default_ticket->prices(); |
|
66 | + // clone ticket, strip out ID, then save to get a new ID |
|
67 | + $default_ticket_clone = clone $default_ticket; |
|
68 | + $default_ticket_clone->set('TKT_ID', null); |
|
69 | + $default_ticket_clone->set('TKT_is_default', false); |
|
70 | + $default_ticket_clone->save(); |
|
71 | + $default_ticket_clone->_add_relation_to($entity, 'Datetime'); |
|
72 | + // temporarily adding relations to existing prices, but these will be cloned and removed |
|
73 | + // when passed to DefaultPrices::create() below so that they the clones can be freely mutated |
|
74 | + foreach ($existing_default_prices as $existing_default_price) { |
|
75 | + if ($existing_default_price instanceof EE_Price) { |
|
76 | + $existing_default_price->_add_relation_to($default_ticket_clone, 'Ticket'); |
|
77 | + } |
|
78 | + } |
|
79 | + $this->default_prices->create($default_ticket_clone); |
|
80 | + $new_tickets[ $default_ticket_clone->ID() ] = $default_ticket_clone; |
|
81 | + } |
|
82 | + return $new_tickets; |
|
83 | + } |
|
84 | 84 | } |
@@ -20,56 +20,56 @@ |
||
20 | 20 | */ |
21 | 21 | class DefaultDatetimes implements DefaultEntityGeneratorInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * @var DefaultTickets $default_tickets |
|
25 | - */ |
|
26 | - protected $default_tickets; |
|
23 | + /** |
|
24 | + * @var DefaultTickets $default_tickets |
|
25 | + */ |
|
26 | + protected $default_tickets; |
|
27 | 27 | |
28 | - /** |
|
29 | - * @var EEM_Datetime $datetime_model |
|
30 | - */ |
|
31 | - protected $datetime_model; |
|
28 | + /** |
|
29 | + * @var EEM_Datetime $datetime_model |
|
30 | + */ |
|
31 | + protected $datetime_model; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @param DefaultTickets $default_tickets |
|
35 | - * @param EEM_Datetime $datetime_model |
|
36 | - */ |
|
37 | - public function __construct(DefaultTickets $default_tickets, EEM_Datetime $datetime_model) |
|
38 | - { |
|
39 | - $this->default_tickets = $default_tickets; |
|
40 | - $this->datetime_model = $datetime_model; |
|
41 | - } |
|
33 | + /** |
|
34 | + * @param DefaultTickets $default_tickets |
|
35 | + * @param EEM_Datetime $datetime_model |
|
36 | + */ |
|
37 | + public function __construct(DefaultTickets $default_tickets, EEM_Datetime $datetime_model) |
|
38 | + { |
|
39 | + $this->default_tickets = $default_tickets; |
|
40 | + $this->datetime_model = $datetime_model; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param EE_Event|EE_Base_Class $entity |
|
46 | - * @return EE_Datetime[] |
|
47 | - * @throws EE_Error |
|
48 | - * @throws InvalidEntityException |
|
49 | - * @throws ReflectionException |
|
50 | - * @since 5.0.0.p |
|
51 | - */ |
|
52 | - public function create(EE_Base_Class $entity): array |
|
53 | - { |
|
54 | - if (! $entity instanceof EE_Event) { |
|
55 | - throw new InvalidEntityException($entity, 'EE_Event'); |
|
56 | - } |
|
57 | - $default_dates = []; |
|
58 | - $blank_dates = $this->datetime_model->create_new_blank_datetime(); |
|
59 | - if (is_array($blank_dates)) { |
|
60 | - foreach ($blank_dates as $blank_date) { |
|
61 | - if (! $blank_date instanceof EE_Datetime) { |
|
62 | - throw new InvalidEntityException($blank_date, 'EE_Datetime'); |
|
63 | - } |
|
64 | - // clone date, strip out ID, then save to get a new ID |
|
65 | - $default_date = clone $blank_date; |
|
66 | - $default_date->set('DTT_ID', null); |
|
67 | - $default_date->save(); |
|
68 | - $default_date->_add_relation_to($entity->ID(), 'Event'); |
|
69 | - $this->default_tickets->create($default_date); |
|
70 | - $default_dates[ $default_date->ID() ] = $default_date; |
|
71 | - } |
|
72 | - } |
|
73 | - return $default_dates; |
|
74 | - } |
|
44 | + /** |
|
45 | + * @param EE_Event|EE_Base_Class $entity |
|
46 | + * @return EE_Datetime[] |
|
47 | + * @throws EE_Error |
|
48 | + * @throws InvalidEntityException |
|
49 | + * @throws ReflectionException |
|
50 | + * @since 5.0.0.p |
|
51 | + */ |
|
52 | + public function create(EE_Base_Class $entity): array |
|
53 | + { |
|
54 | + if (! $entity instanceof EE_Event) { |
|
55 | + throw new InvalidEntityException($entity, 'EE_Event'); |
|
56 | + } |
|
57 | + $default_dates = []; |
|
58 | + $blank_dates = $this->datetime_model->create_new_blank_datetime(); |
|
59 | + if (is_array($blank_dates)) { |
|
60 | + foreach ($blank_dates as $blank_date) { |
|
61 | + if (! $blank_date instanceof EE_Datetime) { |
|
62 | + throw new InvalidEntityException($blank_date, 'EE_Datetime'); |
|
63 | + } |
|
64 | + // clone date, strip out ID, then save to get a new ID |
|
65 | + $default_date = clone $blank_date; |
|
66 | + $default_date->set('DTT_ID', null); |
|
67 | + $default_date->save(); |
|
68 | + $default_date->_add_relation_to($entity->ID(), 'Event'); |
|
69 | + $this->default_tickets->create($default_date); |
|
70 | + $default_dates[ $default_date->ID() ] = $default_date; |
|
71 | + } |
|
72 | + } |
|
73 | + return $default_dates; |
|
74 | + } |
|
75 | 75 | } |
@@ -16,12 +16,12 @@ |
||
16 | 16 | */ |
17 | 17 | interface DefaultEntityGeneratorInterface |
18 | 18 | { |
19 | - /** |
|
20 | - * @param EE_Base_Class $entity |
|
21 | - * @return EE_Base_Class[] |
|
22 | - * @throws EE_Error |
|
23 | - * @throws ReflectionException |
|
24 | - * @since 5.0.0.p |
|
25 | - */ |
|
26 | - public function create(EE_Base_Class $entity): array; |
|
19 | + /** |
|
20 | + * @param EE_Base_Class $entity |
|
21 | + * @return EE_Base_Class[] |
|
22 | + * @throws EE_Error |
|
23 | + * @throws ReflectionException |
|
24 | + * @since 5.0.0.p |
|
25 | + */ |
|
26 | + public function create(EE_Base_Class $entity): array; |
|
27 | 27 | } |
@@ -26,191 +26,191 @@ |
||
26 | 26 | */ |
27 | 27 | class FormSection extends TypeBase |
28 | 28 | { |
29 | - /** |
|
30 | - * FormSection constructor. |
|
31 | - * |
|
32 | - * @param EEM_Form_Section $form_section_model |
|
33 | - */ |
|
34 | - public function __construct(EEM_Form_Section $form_section_model) |
|
35 | - { |
|
36 | - $this->setName($this->namespace . 'FormSection'); |
|
37 | - $this->setDescription(__('A form section', 'event_espresso')); |
|
38 | - $this->setIsCustomPostType(false); |
|
29 | + /** |
|
30 | + * FormSection constructor. |
|
31 | + * |
|
32 | + * @param EEM_Form_Section $form_section_model |
|
33 | + */ |
|
34 | + public function __construct(EEM_Form_Section $form_section_model) |
|
35 | + { |
|
36 | + $this->setName($this->namespace . 'FormSection'); |
|
37 | + $this->setDescription(__('A form section', 'event_espresso')); |
|
38 | + $this->setIsCustomPostType(false); |
|
39 | 39 | |
40 | - parent::__construct($form_section_model); |
|
41 | - } |
|
40 | + parent::__construct($form_section_model); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @return GraphQLFieldInterface[] |
|
46 | - */ |
|
47 | - public function getFields(): array |
|
48 | - { |
|
49 | - $fields = [ |
|
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 GraphQLField( |
|
57 | - 'appliesTo', |
|
58 | - $this->namespace . 'FormSectionAppliesToEnum', |
|
59 | - 'appliesTo', |
|
60 | - esc_html__('Form user type that this form section should be presented to.', 'event_espresso') |
|
61 | - ), |
|
62 | - new GraphQLField( |
|
63 | - 'attributes', |
|
64 | - 'String', |
|
65 | - 'attributes', |
|
66 | - esc_html__( |
|
67 | - 'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.', |
|
68 | - 'event_espresso' |
|
69 | - ), |
|
70 | - [$this, 'toJson'] |
|
71 | - ), |
|
72 | - new GraphQLField( |
|
73 | - 'belongsTo', |
|
74 | - 'String', |
|
75 | - 'belongsTo', |
|
76 | - esc_html__('UUID or ID of related entity this form section belongs to.', 'event_espresso') |
|
77 | - ), |
|
78 | - new GraphQLOutputField( |
|
79 | - 'isActive', |
|
80 | - 'Boolean', |
|
81 | - 'isActive', |
|
82 | - esc_html__('Flag indicating whether the section is active.', 'event_espresso') |
|
83 | - ), |
|
84 | - new GraphQLOutputField( |
|
85 | - 'isArchived', |
|
86 | - 'Boolean', |
|
87 | - 'isArchived', |
|
88 | - esc_html__('Flag indicating whether the section is archived.', 'event_espresso') |
|
89 | - ), |
|
90 | - new GraphQLOutputField( |
|
91 | - 'isDefault', |
|
92 | - 'Boolean', |
|
93 | - 'isDefault', |
|
94 | - esc_html__('Flag indicating whether the section is a default one.', 'event_espresso') |
|
95 | - ), |
|
96 | - new GraphQLOutputField( |
|
97 | - 'isShared', |
|
98 | - 'Boolean', |
|
99 | - 'isShared', |
|
100 | - esc_html__('Flag indicating whether the section is a shared one.', 'event_espresso') |
|
101 | - ), |
|
102 | - new GraphQLOutputField( |
|
103 | - 'isTrashed', |
|
104 | - 'Boolean', |
|
105 | - 'isTrashed', |
|
106 | - esc_html__('Flag indicating whether the section is trashed.', 'event_espresso') |
|
107 | - ), |
|
108 | - new GraphQLField( |
|
109 | - 'label', |
|
110 | - 'String', |
|
111 | - 'label', |
|
112 | - esc_html__( |
|
113 | - 'JSON string of properties pertaining to a form section\'s label.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - [$this, 'toJson'] |
|
117 | - ), |
|
118 | - new GraphQLField( |
|
119 | - 'order', |
|
120 | - 'Int', |
|
121 | - 'order', |
|
122 | - esc_html__('Order in which form section appears in a form.', 'event_espresso') |
|
123 | - ), |
|
124 | - new GraphQLField( |
|
125 | - 'status', |
|
126 | - $this->namespace . 'FormStatusEnum', |
|
127 | - 'status', |
|
128 | - esc_html__( |
|
129 | - 'Whether form section is active, archived, shared, trashed, or used as a default on new forms.', |
|
130 | - 'event_espresso' |
|
131 | - ) |
|
132 | - ), |
|
133 | - new GraphQLOutputField( |
|
134 | - 'wpUser', |
|
135 | - 'User', |
|
136 | - null, |
|
137 | - esc_html__('WP User that created this form section.', 'event_espresso') |
|
138 | - ), |
|
139 | - new GraphQLInputField( |
|
140 | - 'wpUser', |
|
141 | - 'ID', |
|
142 | - null, |
|
143 | - esc_html__('ID of the WP User that created the form section.', 'event_espresso') |
|
144 | - ), |
|
145 | - ]; |
|
44 | + /** |
|
45 | + * @return GraphQLFieldInterface[] |
|
46 | + */ |
|
47 | + public function getFields(): array |
|
48 | + { |
|
49 | + $fields = [ |
|
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 GraphQLField( |
|
57 | + 'appliesTo', |
|
58 | + $this->namespace . 'FormSectionAppliesToEnum', |
|
59 | + 'appliesTo', |
|
60 | + esc_html__('Form user type that this form section should be presented to.', 'event_espresso') |
|
61 | + ), |
|
62 | + new GraphQLField( |
|
63 | + 'attributes', |
|
64 | + 'String', |
|
65 | + 'attributes', |
|
66 | + esc_html__( |
|
67 | + 'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.', |
|
68 | + 'event_espresso' |
|
69 | + ), |
|
70 | + [$this, 'toJson'] |
|
71 | + ), |
|
72 | + new GraphQLField( |
|
73 | + 'belongsTo', |
|
74 | + 'String', |
|
75 | + 'belongsTo', |
|
76 | + esc_html__('UUID or ID of related entity this form section belongs to.', 'event_espresso') |
|
77 | + ), |
|
78 | + new GraphQLOutputField( |
|
79 | + 'isActive', |
|
80 | + 'Boolean', |
|
81 | + 'isActive', |
|
82 | + esc_html__('Flag indicating whether the section is active.', 'event_espresso') |
|
83 | + ), |
|
84 | + new GraphQLOutputField( |
|
85 | + 'isArchived', |
|
86 | + 'Boolean', |
|
87 | + 'isArchived', |
|
88 | + esc_html__('Flag indicating whether the section is archived.', 'event_espresso') |
|
89 | + ), |
|
90 | + new GraphQLOutputField( |
|
91 | + 'isDefault', |
|
92 | + 'Boolean', |
|
93 | + 'isDefault', |
|
94 | + esc_html__('Flag indicating whether the section is a default one.', 'event_espresso') |
|
95 | + ), |
|
96 | + new GraphQLOutputField( |
|
97 | + 'isShared', |
|
98 | + 'Boolean', |
|
99 | + 'isShared', |
|
100 | + esc_html__('Flag indicating whether the section is a shared one.', 'event_espresso') |
|
101 | + ), |
|
102 | + new GraphQLOutputField( |
|
103 | + 'isTrashed', |
|
104 | + 'Boolean', |
|
105 | + 'isTrashed', |
|
106 | + esc_html__('Flag indicating whether the section is trashed.', 'event_espresso') |
|
107 | + ), |
|
108 | + new GraphQLField( |
|
109 | + 'label', |
|
110 | + 'String', |
|
111 | + 'label', |
|
112 | + esc_html__( |
|
113 | + 'JSON string of properties pertaining to a form section\'s label.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + [$this, 'toJson'] |
|
117 | + ), |
|
118 | + new GraphQLField( |
|
119 | + 'order', |
|
120 | + 'Int', |
|
121 | + 'order', |
|
122 | + esc_html__('Order in which form section appears in a form.', 'event_espresso') |
|
123 | + ), |
|
124 | + new GraphQLField( |
|
125 | + 'status', |
|
126 | + $this->namespace . 'FormStatusEnum', |
|
127 | + 'status', |
|
128 | + esc_html__( |
|
129 | + 'Whether form section is active, archived, shared, trashed, or used as a default on new forms.', |
|
130 | + 'event_espresso' |
|
131 | + ) |
|
132 | + ), |
|
133 | + new GraphQLOutputField( |
|
134 | + 'wpUser', |
|
135 | + 'User', |
|
136 | + null, |
|
137 | + esc_html__('WP User that created this form section.', 'event_espresso') |
|
138 | + ), |
|
139 | + new GraphQLInputField( |
|
140 | + 'wpUser', |
|
141 | + 'ID', |
|
142 | + null, |
|
143 | + esc_html__('ID of the WP User that created the form section.', 'event_espresso') |
|
144 | + ), |
|
145 | + ]; |
|
146 | 146 | |
147 | - return apply_filters( |
|
148 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__form_section_fields', |
|
149 | - $fields, |
|
150 | - $this->name, |
|
151 | - $this->model |
|
152 | - ); |
|
153 | - } |
|
147 | + return apply_filters( |
|
148 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__form_section_fields', |
|
149 | + $fields, |
|
150 | + $this->name, |
|
151 | + $this->model |
|
152 | + ); |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * @param array $inputFields The mutation input fields. |
|
158 | - * @throws InvalidArgumentException |
|
159 | - * @throws ReflectionException |
|
160 | - * @throws Exception |
|
161 | - * @since 5.0.0.p |
|
162 | - */ |
|
163 | - public function registerMutations(array $inputFields) |
|
164 | - { |
|
165 | - // Register mutation to update an entity. |
|
166 | - register_graphql_mutation( |
|
167 | - 'update' . $this->name(), |
|
168 | - [ |
|
169 | - 'inputFields' => $inputFields, |
|
170 | - 'outputFields' => [ |
|
171 | - lcfirst($this->name()) => [ |
|
172 | - 'type' => $this->name(), |
|
173 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
174 | - ], |
|
175 | - ], |
|
176 | - 'mutateAndGetPayload' => FormSectionUpdate::mutateAndGetPayload($this->model), |
|
177 | - ] |
|
178 | - ); |
|
179 | - // Register mutation to delete an entity. |
|
180 | - register_graphql_mutation( |
|
181 | - 'delete' . $this->name(), |
|
182 | - [ |
|
183 | - 'inputFields' => [ |
|
184 | - 'id' => $inputFields['id'], |
|
185 | - ], |
|
186 | - 'outputFields' => [ |
|
187 | - lcfirst($this->name()) => [ |
|
188 | - 'type' => $this->name(), |
|
189 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
190 | - 'resolve' => static function ($payload) { |
|
191 | - $deleted = (object) $payload['deleted']; |
|
156 | + /** |
|
157 | + * @param array $inputFields The mutation input fields. |
|
158 | + * @throws InvalidArgumentException |
|
159 | + * @throws ReflectionException |
|
160 | + * @throws Exception |
|
161 | + * @since 5.0.0.p |
|
162 | + */ |
|
163 | + public function registerMutations(array $inputFields) |
|
164 | + { |
|
165 | + // Register mutation to update an entity. |
|
166 | + register_graphql_mutation( |
|
167 | + 'update' . $this->name(), |
|
168 | + [ |
|
169 | + 'inputFields' => $inputFields, |
|
170 | + 'outputFields' => [ |
|
171 | + lcfirst($this->name()) => [ |
|
172 | + 'type' => $this->name(), |
|
173 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
174 | + ], |
|
175 | + ], |
|
176 | + 'mutateAndGetPayload' => FormSectionUpdate::mutateAndGetPayload($this->model), |
|
177 | + ] |
|
178 | + ); |
|
179 | + // Register mutation to delete an entity. |
|
180 | + register_graphql_mutation( |
|
181 | + 'delete' . $this->name(), |
|
182 | + [ |
|
183 | + 'inputFields' => [ |
|
184 | + 'id' => $inputFields['id'], |
|
185 | + ], |
|
186 | + 'outputFields' => [ |
|
187 | + lcfirst($this->name()) => [ |
|
188 | + 'type' => $this->name(), |
|
189 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
190 | + 'resolve' => static function ($payload) { |
|
191 | + $deleted = (object) $payload['deleted']; |
|
192 | 192 | |
193 | - return ! empty($deleted) ? $deleted : null; |
|
194 | - }, |
|
195 | - ], |
|
196 | - ], |
|
197 | - 'mutateAndGetPayload' => FormSectionDelete::mutateAndGetPayload($this->model), |
|
198 | - ] |
|
199 | - ); |
|
193 | + return ! empty($deleted) ? $deleted : null; |
|
194 | + }, |
|
195 | + ], |
|
196 | + ], |
|
197 | + 'mutateAndGetPayload' => FormSectionDelete::mutateAndGetPayload($this->model), |
|
198 | + ] |
|
199 | + ); |
|
200 | 200 | |
201 | - // Register mutation to update an entity. |
|
202 | - register_graphql_mutation( |
|
203 | - 'create' . $this->name(), |
|
204 | - [ |
|
205 | - 'inputFields' => $inputFields, |
|
206 | - 'outputFields' => [ |
|
207 | - lcfirst($this->name()) => [ |
|
208 | - 'type' => $this->name(), |
|
209 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
210 | - ], |
|
211 | - ], |
|
212 | - 'mutateAndGetPayload' => FormSectionCreate::mutateAndGetPayload($this->model), |
|
213 | - ] |
|
214 | - ); |
|
215 | - } |
|
201 | + // Register mutation to update an entity. |
|
202 | + register_graphql_mutation( |
|
203 | + 'create' . $this->name(), |
|
204 | + [ |
|
205 | + 'inputFields' => $inputFields, |
|
206 | + 'outputFields' => [ |
|
207 | + lcfirst($this->name()) => [ |
|
208 | + 'type' => $this->name(), |
|
209 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
210 | + ], |
|
211 | + ], |
|
212 | + 'mutateAndGetPayload' => FormSectionCreate::mutateAndGetPayload($this->model), |
|
213 | + ] |
|
214 | + ); |
|
215 | + } |
|
216 | 216 | } |
@@ -26,210 +26,210 @@ |
||
26 | 26 | */ |
27 | 27 | class FormElement extends TypeBase |
28 | 28 | { |
29 | - /** |
|
30 | - * FormElement constructor. |
|
31 | - * |
|
32 | - * @param EEM_Form_Element $form_element_model |
|
33 | - */ |
|
34 | - public function __construct(EEM_Form_Element $form_element_model) |
|
35 | - { |
|
36 | - $this->setName($this->namespace . 'FormElement'); |
|
37 | - $this->setDescription(__('A form element', 'event_espresso')); |
|
38 | - $this->setIsCustomPostType(false); |
|
29 | + /** |
|
30 | + * FormElement constructor. |
|
31 | + * |
|
32 | + * @param EEM_Form_Element $form_element_model |
|
33 | + */ |
|
34 | + public function __construct(EEM_Form_Element $form_element_model) |
|
35 | + { |
|
36 | + $this->setName($this->namespace . 'FormElement'); |
|
37 | + $this->setDescription(__('A form element', 'event_espresso')); |
|
38 | + $this->setIsCustomPostType(false); |
|
39 | 39 | |
40 | - parent::__construct($form_element_model); |
|
41 | - } |
|
40 | + parent::__construct($form_element_model); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @return GraphQLFieldInterface[] |
|
46 | - */ |
|
47 | - public function getFields(): array |
|
48 | - { |
|
49 | - $fields = [ |
|
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 GraphQLField( |
|
57 | - 'adminOnly', |
|
58 | - 'Boolean', |
|
59 | - 'adminOnly', |
|
60 | - esc_html__( |
|
61 | - 'Whether or not the element is only displayed in the admin. If false, input will appear in public forms', |
|
62 | - 'event_espresso' |
|
63 | - ) |
|
64 | - ), |
|
65 | - new GraphQLField( |
|
66 | - 'attributes', |
|
67 | - 'String', |
|
68 | - 'attributes', |
|
69 | - esc_html__( |
|
70 | - 'JSON string of HTML attributes such as class, max, min, placeholder, type, etc.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - [$this, 'toJson'] |
|
74 | - ), |
|
75 | - new GraphQLField( |
|
76 | - 'belongsTo', |
|
77 | - 'String', |
|
78 | - 'belongsTo', |
|
79 | - esc_html__('UUID of parent form section this form element belongs to.', 'event_espresso') |
|
80 | - ), |
|
81 | - new GraphQLField( |
|
82 | - 'helpText', |
|
83 | - 'String', |
|
84 | - 'helpText', |
|
85 | - esc_html__( |
|
86 | - "JSON string of properties pertaining to any help text required for an input.", |
|
87 | - 'event_espresso' |
|
88 | - ), |
|
89 | - [$this, 'toJson'] |
|
90 | - ), |
|
91 | - new GraphQLField( |
|
92 | - 'label', |
|
93 | - 'String', |
|
94 | - 'label', |
|
95 | - esc_html__( |
|
96 | - 'JSON string of properties pertaining to an element\'s label.', |
|
97 | - 'event_espresso' |
|
98 | - ), |
|
99 | - [$this, 'toJson'] |
|
100 | - ), |
|
101 | - new GraphQLField( |
|
102 | - 'mapsTo', |
|
103 | - 'String', |
|
104 | - 'mapsTo', |
|
105 | - esc_html__("Model and Fields name that this element maps to; ex: Attendee.email", 'event_espresso') |
|
106 | - ), |
|
107 | - new GraphQLField( |
|
108 | - 'options', |
|
109 | - 'String', |
|
110 | - 'options', |
|
111 | - esc_html__( |
|
112 | - "JSON string of options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc.", |
|
113 | - 'event_espresso' |
|
114 | - ), |
|
115 | - [$this, 'toJson'] |
|
116 | - ), |
|
117 | - new GraphQLField( |
|
118 | - 'order', |
|
119 | - 'Int', |
|
120 | - 'order', |
|
121 | - esc_html__('Order in which form element appears in a form.', 'event_espresso') |
|
122 | - ), |
|
123 | - new GraphQLField( |
|
124 | - 'required', |
|
125 | - 'String', |
|
126 | - 'required', |
|
127 | - esc_html__( |
|
128 | - "properties pertaining to an input\'s required status and the validation text to display.", |
|
129 | - 'event_espresso' |
|
130 | - ), |
|
131 | - [$this, 'toJson'] |
|
132 | - ), |
|
133 | - new GraphQLField( |
|
134 | - 'status', |
|
135 | - $this->namespace . 'FormStatusEnum', |
|
136 | - 'status', |
|
137 | - esc_html__( |
|
138 | - 'Whether form element is active, archived, trashed, or used as a default on new forms.', |
|
139 | - 'event_espresso' |
|
140 | - ) |
|
141 | - ), |
|
142 | - new GraphQLField( |
|
143 | - 'type', |
|
144 | - $this->namespace . 'ElementTypeEnum', |
|
145 | - 'type', |
|
146 | - esc_html__('Form element type.', 'event_espresso') |
|
147 | - ), |
|
148 | - new GraphQLOutputField( |
|
149 | - 'wpUser', |
|
150 | - 'User', |
|
151 | - null, |
|
152 | - esc_html__('WP User that created this form element.', 'event_espresso') |
|
153 | - ), |
|
154 | - new GraphQLInputField( |
|
155 | - 'wpUser', |
|
156 | - 'ID', |
|
157 | - null, |
|
158 | - esc_html__('ID of the WP User that created the form element.', 'event_espresso') |
|
159 | - ), |
|
160 | - ]; |
|
44 | + /** |
|
45 | + * @return GraphQLFieldInterface[] |
|
46 | + */ |
|
47 | + public function getFields(): array |
|
48 | + { |
|
49 | + $fields = [ |
|
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 GraphQLField( |
|
57 | + 'adminOnly', |
|
58 | + 'Boolean', |
|
59 | + 'adminOnly', |
|
60 | + esc_html__( |
|
61 | + 'Whether or not the element is only displayed in the admin. If false, input will appear in public forms', |
|
62 | + 'event_espresso' |
|
63 | + ) |
|
64 | + ), |
|
65 | + new GraphQLField( |
|
66 | + 'attributes', |
|
67 | + 'String', |
|
68 | + 'attributes', |
|
69 | + esc_html__( |
|
70 | + 'JSON string of HTML attributes such as class, max, min, placeholder, type, etc.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + [$this, 'toJson'] |
|
74 | + ), |
|
75 | + new GraphQLField( |
|
76 | + 'belongsTo', |
|
77 | + 'String', |
|
78 | + 'belongsTo', |
|
79 | + esc_html__('UUID of parent form section this form element belongs to.', 'event_espresso') |
|
80 | + ), |
|
81 | + new GraphQLField( |
|
82 | + 'helpText', |
|
83 | + 'String', |
|
84 | + 'helpText', |
|
85 | + esc_html__( |
|
86 | + "JSON string of properties pertaining to any help text required for an input.", |
|
87 | + 'event_espresso' |
|
88 | + ), |
|
89 | + [$this, 'toJson'] |
|
90 | + ), |
|
91 | + new GraphQLField( |
|
92 | + 'label', |
|
93 | + 'String', |
|
94 | + 'label', |
|
95 | + esc_html__( |
|
96 | + 'JSON string of properties pertaining to an element\'s label.', |
|
97 | + 'event_espresso' |
|
98 | + ), |
|
99 | + [$this, 'toJson'] |
|
100 | + ), |
|
101 | + new GraphQLField( |
|
102 | + 'mapsTo', |
|
103 | + 'String', |
|
104 | + 'mapsTo', |
|
105 | + esc_html__("Model and Fields name that this element maps to; ex: Attendee.email", 'event_espresso') |
|
106 | + ), |
|
107 | + new GraphQLField( |
|
108 | + 'options', |
|
109 | + 'String', |
|
110 | + 'options', |
|
111 | + esc_html__( |
|
112 | + "JSON string of options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc.", |
|
113 | + 'event_espresso' |
|
114 | + ), |
|
115 | + [$this, 'toJson'] |
|
116 | + ), |
|
117 | + new GraphQLField( |
|
118 | + 'order', |
|
119 | + 'Int', |
|
120 | + 'order', |
|
121 | + esc_html__('Order in which form element appears in a form.', 'event_espresso') |
|
122 | + ), |
|
123 | + new GraphQLField( |
|
124 | + 'required', |
|
125 | + 'String', |
|
126 | + 'required', |
|
127 | + esc_html__( |
|
128 | + "properties pertaining to an input\'s required status and the validation text to display.", |
|
129 | + 'event_espresso' |
|
130 | + ), |
|
131 | + [$this, 'toJson'] |
|
132 | + ), |
|
133 | + new GraphQLField( |
|
134 | + 'status', |
|
135 | + $this->namespace . 'FormStatusEnum', |
|
136 | + 'status', |
|
137 | + esc_html__( |
|
138 | + 'Whether form element is active, archived, trashed, or used as a default on new forms.', |
|
139 | + 'event_espresso' |
|
140 | + ) |
|
141 | + ), |
|
142 | + new GraphQLField( |
|
143 | + 'type', |
|
144 | + $this->namespace . 'ElementTypeEnum', |
|
145 | + 'type', |
|
146 | + esc_html__('Form element type.', 'event_espresso') |
|
147 | + ), |
|
148 | + new GraphQLOutputField( |
|
149 | + 'wpUser', |
|
150 | + 'User', |
|
151 | + null, |
|
152 | + esc_html__('WP User that created this form element.', 'event_espresso') |
|
153 | + ), |
|
154 | + new GraphQLInputField( |
|
155 | + 'wpUser', |
|
156 | + 'ID', |
|
157 | + null, |
|
158 | + esc_html__('ID of the WP User that created the form element.', 'event_espresso') |
|
159 | + ), |
|
160 | + ]; |
|
161 | 161 | |
162 | - return apply_filters( |
|
163 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__form_element_fields', |
|
164 | - $fields, |
|
165 | - $this->name, |
|
166 | - $this->model |
|
167 | - ); |
|
168 | - } |
|
162 | + return apply_filters( |
|
163 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__form_element_fields', |
|
164 | + $fields, |
|
165 | + $this->name, |
|
166 | + $this->model |
|
167 | + ); |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * @param array $inputFields The mutation input fields. |
|
173 | - * @throws InvalidArgumentException |
|
174 | - * @throws ReflectionException |
|
175 | - * @throws Exception |
|
176 | - * @since 5.0.0.p |
|
177 | - */ |
|
178 | - public function registerMutations(array $inputFields) |
|
179 | - { |
|
180 | - // Register mutation to update an entity. |
|
181 | - register_graphql_mutation( |
|
182 | - 'update' . $this->name(), |
|
183 | - [ |
|
184 | - 'inputFields' => $inputFields, |
|
185 | - 'outputFields' => [ |
|
186 | - lcfirst($this->name()) => [ |
|
187 | - 'type' => $this->name(), |
|
188 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
189 | - ], |
|
190 | - ], |
|
191 | - 'mutateAndGetPayload' => FormElementUpdate::mutateAndGetPayload($this->model), |
|
192 | - ] |
|
193 | - ); |
|
194 | - // Register mutation to delete an entity. |
|
195 | - register_graphql_mutation( |
|
196 | - 'delete' . $this->name(), |
|
197 | - [ |
|
198 | - 'inputFields' => [ |
|
199 | - 'id' => $inputFields['id'], |
|
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']; |
|
171 | + /** |
|
172 | + * @param array $inputFields The mutation input fields. |
|
173 | + * @throws InvalidArgumentException |
|
174 | + * @throws ReflectionException |
|
175 | + * @throws Exception |
|
176 | + * @since 5.0.0.p |
|
177 | + */ |
|
178 | + public function registerMutations(array $inputFields) |
|
179 | + { |
|
180 | + // Register mutation to update an entity. |
|
181 | + register_graphql_mutation( |
|
182 | + 'update' . $this->name(), |
|
183 | + [ |
|
184 | + 'inputFields' => $inputFields, |
|
185 | + 'outputFields' => [ |
|
186 | + lcfirst($this->name()) => [ |
|
187 | + 'type' => $this->name(), |
|
188 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
189 | + ], |
|
190 | + ], |
|
191 | + 'mutateAndGetPayload' => FormElementUpdate::mutateAndGetPayload($this->model), |
|
192 | + ] |
|
193 | + ); |
|
194 | + // Register mutation to delete an entity. |
|
195 | + register_graphql_mutation( |
|
196 | + 'delete' . $this->name(), |
|
197 | + [ |
|
198 | + 'inputFields' => [ |
|
199 | + 'id' => $inputFields['id'], |
|
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' => FormElementDelete::mutateAndGetPayload($this->model), |
|
213 | - ] |
|
214 | - ); |
|
208 | + return ! empty($deleted) ? $deleted : null; |
|
209 | + }, |
|
210 | + ], |
|
211 | + ], |
|
212 | + 'mutateAndGetPayload' => FormElementDelete::mutateAndGetPayload($this->model), |
|
213 | + ] |
|
214 | + ); |
|
215 | 215 | |
216 | - // Make element 'type' a required field for create mutations |
|
217 | - // Yes it's "['type']['type']" |
@@ -31,171 +31,171 @@ |
||
31 | 31 | */ |
32 | 32 | class RootQuery extends TypeBase |
33 | 33 | { |
34 | - /** |
|
35 | - * RootQuery constructor. |
|
36 | - */ |
|
37 | - public function __construct() |
|
38 | - { |
|
39 | - $this->setName('RootQuery'); |
|
40 | - $this->setIsCustomPostType(true); |
|
41 | - parent::__construct(); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return GraphQLFieldInterface[] |
|
47 | - */ |
|
48 | - public function getFields(): array |
|
49 | - { |
|
50 | - return [ |
|
51 | - new GraphQLOutputField( |
|
52 | - lcfirst($this->namespace) . 'EventRelations', |
|
53 | - 'String', |
|
54 | - null, |
|
55 | - esc_html__('JSON encoded relational data of the models', 'event_espresso'), |
|
56 | - null, |
|
57 | - [$this, 'getEventRelationalData'], |
|
58 | - [], |
|
59 | - [ |
|
60 | - 'eventId' => [ |
|
61 | - 'type' => ['non_null' => 'Int'], |
|
62 | - 'description' => esc_html__('The event ID to get the relational data for.', 'event_espresso'), |
|
63 | - ], |
|
64 | - ] |
|
65 | - ), |
|
66 | - new GraphQLOutputField( |
|
67 | - lcfirst($this->namespace) . 'Datetime', |
|
68 | - $this->namespace . 'Datetime', |
|
69 | - null, |
|
70 | - esc_html__('A datetime', 'event_espresso'), |
|
71 | - null, |
|
72 | - [$this, 'getDatetime'], |
|
73 | - [], |
|
74 | - [ |
|
75 | - 'id' => [ |
|
76 | - 'type' => [ |
|
77 | - 'non_null' => 'ID', |
|
78 | - ], |
|
79 | - 'description' => esc_html__('The globally unique identifier of the datetime.', 'event_espresso'), |
|
80 | - ], |
|
81 | - ] |
|
82 | - ), |
|
83 | - new GraphQLOutputField( |
|
84 | - lcfirst($this->namespace) . 'Ticket', |
|
85 | - $this->namespace . 'Ticket', |
|
86 | - null, |
|
87 | - esc_html__('A ticket', 'event_espresso'), |
|
88 | - null, |
|
89 | - [$this, 'getTicket'], |
|
90 | - [], |
|
91 | - [ |
|
92 | - 'id' => [ |
|
93 | - 'type' => [ |
|
94 | - 'non_null' => 'ID', |
|
95 | - ], |
|
96 | - 'description' => esc_html__('The globally unique identifier of the ticket.', 'event_espresso'), |
|
97 | - ], |
|
98 | - ] |
|
99 | - ), |
|
100 | - ]; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
106 | - * @param array $args The inputArgs on the field |
|
107 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
108 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
109 | - * @return string |
|
110 | - * @throws Exception |
|
111 | - * @throws InvalidArgumentException |
|
112 | - * @throws InvalidDataTypeException |
|
113 | - * @throws InvalidInterfaceException |
|
114 | - * @throws UserError |
|
115 | - * @throws UnexpectedEntityException |
|
116 | - * @since 5.0.0.p |
|
117 | - */ |
|
118 | - public function getEventRelationalData($source, array $args, AppContext $context, ResolveInfo $info): string |
|
119 | - { |
|
120 | - /** |
|
121 | - * Throw an exception if there's no event ID |
|
122 | - */ |
|
123 | - if (empty($args['eventId']) || ! absint($args['eventId'])) { |
|
124 | - throw new UserError(esc_html__( |
|
125 | - 'No event ID was provided to get the relational data for', |
|
126 | - 'event_espresso' |
|
127 | - )); |
|
128 | - } |
|
129 | - |
|
130 | - $eventId = absint($args['eventId']); |
|
131 | - /** @var EventEntityRelations $event_entity_relations */ |
|
132 | - $event_entity_relations = LoaderFactory::getLoader()->getShared( |
|
133 | - 'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations' |
|
134 | - ); |
|
135 | - return json_encode($event_entity_relations->getData($eventId)); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
141 | - * @param array $args The inputArgs on the field |
|
142 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
143 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
144 | - * @return string |
|
145 | - * @throws Exception |
|
146 | - * @throws InvalidArgumentException |
|
147 | - * @throws InvalidDataTypeException |
|
148 | - * @throws InvalidInterfaceException |
|
149 | - * @throws UserError |
|
150 | - * @throws UnexpectedEntityException |
|
151 | - * @since 5.0.0.p |
|
152 | - */ |
|
153 | - public function getDatetime($source, array $args, AppContext $context, ResolveInfo $info): EE_Datetime |
|
154 | - { |
|
155 | - $parts = Relay::fromGlobalId(sanitize_text_field($args['id'])); |
|
156 | - |
|
157 | - /** |
|
158 | - * Throw an exception if there's no ID |
|
159 | - */ |
|
160 | - if (empty($parts['id'])) { |
|
161 | - throw new UserError(esc_html__( |
|
162 | - 'A missing or invalid ID was received.', |
|
163 | - 'event_espresso' |
|
164 | - )); |
|
165 | - } |
|
166 | - |
|
167 | - return EEM_Datetime::instance()->get_one_by_ID(absint($parts['id'])); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
173 | - * @param array $args The inputArgs on the field |
|
174 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
175 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
176 | - * @return string |
|
177 | - * @throws Exception |
|
178 | - * @throws InvalidArgumentException |
|
179 | - * @throws InvalidDataTypeException |
|
180 | - * @throws InvalidInterfaceException |
|
181 | - * @throws UserError |
|
182 | - * @throws UnexpectedEntityException |
|
183 | - * @since 5.0.0.p |
|
184 | - */ |
|
185 | - public function getTicket($source, array $args, AppContext $context, ResolveInfo $info): EE_Ticket |
|
186 | - { |
|
187 | - $parts = Relay::fromGlobalId(sanitize_text_field($args['id'])); |
|
188 | - |
|
189 | - /** |
|
190 | - * Throw an exception if there's no ID |
|
191 | - */ |
|
192 | - if (empty($parts['id'])) { |
|
193 | - throw new UserError(esc_html__( |
|
194 | - 'A missing or invalid ID was received.', |
|
195 | - 'event_espresso' |
|
196 | - )); |
|
197 | - } |
|
198 | - |
|
199 | - return EEM_Ticket::instance()->get_one_by_ID(absint($parts['id'])); |
|
200 | - } |
|
34 | + /** |
|
35 | + * RootQuery constructor. |
|
36 | + */ |
|
37 | + public function __construct() |
|
38 | + { |
|
39 | + $this->setName('RootQuery'); |
|
40 | + $this->setIsCustomPostType(true); |
|
41 | + parent::__construct(); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return GraphQLFieldInterface[] |
|
47 | + */ |
|
48 | + public function getFields(): array |
|
49 | + { |
|
50 | + return [ |
|
51 | + new GraphQLOutputField( |
|
52 | + lcfirst($this->namespace) . 'EventRelations', |
|
53 | + 'String', |
|
54 | + null, |
|
55 | + esc_html__('JSON encoded relational data of the models', 'event_espresso'), |
|
56 | + null, |
|
57 | + [$this, 'getEventRelationalData'], |
|
58 | + [], |
|
59 | + [ |
|
60 | + 'eventId' => [ |
|
61 | + 'type' => ['non_null' => 'Int'], |
|
62 | + 'description' => esc_html__('The event ID to get the relational data for.', 'event_espresso'), |
|
63 | + ], |
|
64 | + ] |
|
65 | + ), |
|
66 | + new GraphQLOutputField( |
|
67 | + lcfirst($this->namespace) . 'Datetime', |
|
68 | + $this->namespace . 'Datetime', |
|
69 | + null, |
|
70 | + esc_html__('A datetime', 'event_espresso'), |
|
71 | + null, |
|
72 | + [$this, 'getDatetime'], |
|
73 | + [], |
|
74 | + [ |
|
75 | + 'id' => [ |
|
76 | + 'type' => [ |
|
77 | + 'non_null' => 'ID', |
|
78 | + ], |
|
79 | + 'description' => esc_html__('The globally unique identifier of the datetime.', 'event_espresso'), |
|
80 | + ], |
|
81 | + ] |
|
82 | + ), |
|
83 | + new GraphQLOutputField( |
|
84 | + lcfirst($this->namespace) . 'Ticket', |
|
85 | + $this->namespace . 'Ticket', |
|
86 | + null, |
|
87 | + esc_html__('A ticket', 'event_espresso'), |
|
88 | + null, |
|
89 | + [$this, 'getTicket'], |
|
90 | + [], |
|
91 | + [ |
|
92 | + 'id' => [ |
|
93 | + 'type' => [ |
|
94 | + 'non_null' => 'ID', |
|
95 | + ], |
|
96 | + 'description' => esc_html__('The globally unique identifier of the ticket.', 'event_espresso'), |
|
97 | + ], |
|
98 | + ] |
|
99 | + ), |
|
100 | + ]; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
106 | + * @param array $args The inputArgs on the field |
|
107 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
108 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
109 | + * @return string |
|
110 | + * @throws Exception |
|
111 | + * @throws InvalidArgumentException |
|
112 | + * @throws InvalidDataTypeException |
|
113 | + * @throws InvalidInterfaceException |
|
114 | + * @throws UserError |
|
115 | + * @throws UnexpectedEntityException |
|
116 | + * @since 5.0.0.p |
|
117 | + */ |
|
118 | + public function getEventRelationalData($source, array $args, AppContext $context, ResolveInfo $info): string |
|
119 | + { |
|
120 | + /** |
|
121 | + * Throw an exception if there's no event ID |
|
122 | + */ |
|
123 | + if (empty($args['eventId']) || ! absint($args['eventId'])) { |
|
124 | + throw new UserError(esc_html__( |
|
125 | + 'No event ID was provided to get the relational data for', |
|
126 | + 'event_espresso' |
|
127 | + )); |
|
128 | + } |
|
129 | + |
|
130 | + $eventId = absint($args['eventId']); |
|
131 | + /** @var EventEntityRelations $event_entity_relations */ |
|
132 | + $event_entity_relations = LoaderFactory::getLoader()->getShared( |
|
133 | + 'EventEspresso\core\domain\services\admin\events\editor\EventEntityRelations' |
|
134 | + ); |
|
135 | + return json_encode($event_entity_relations->getData($eventId)); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
141 | + * @param array $args The inputArgs on the field |
|
142 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
143 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
144 | + * @return string |
|
145 | + * @throws Exception |
|
146 | + * @throws InvalidArgumentException |
|
147 | + * @throws InvalidDataTypeException |
|
148 | + * @throws InvalidInterfaceException |
|
149 | + * @throws UserError |
|
150 | + * @throws UnexpectedEntityException |
|
151 | + * @since 5.0.0.p |
|
152 | + */ |
|
153 | + public function getDatetime($source, array $args, AppContext $context, ResolveInfo $info): EE_Datetime |
|
154 | + { |
|
155 | + $parts = Relay::fromGlobalId(sanitize_text_field($args['id'])); |
|
156 | + |
|
157 | + /** |
|
158 | + * Throw an exception if there's no ID |
|
159 | + */ |
|
160 | + if (empty($parts['id'])) { |
|
161 | + throw new UserError(esc_html__( |
|
162 | + 'A missing or invalid ID was received.', |
|
163 | + 'event_espresso' |
|
164 | + )); |
|
165 | + } |
|
166 | + |
|
167 | + return EEM_Datetime::instance()->get_one_by_ID(absint($parts['id'])); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
173 | + * @param array $args The inputArgs on the field |
|
174 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
175 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
176 | + * @return string |
|
177 | + * @throws Exception |
|
178 | + * @throws InvalidArgumentException |
|
179 | + * @throws InvalidDataTypeException |
|
180 | + * @throws InvalidInterfaceException |
|
181 | + * @throws UserError |
|
182 | + * @throws UnexpectedEntityException |
|
183 | + * @since 5.0.0.p |
|
184 | + */ |
|
185 | + public function getTicket($source, array $args, AppContext $context, ResolveInfo $info): EE_Ticket |
|
186 | + { |
|
187 | + $parts = Relay::fromGlobalId(sanitize_text_field($args['id'])); |
|
188 | + |
|
189 | + /** |
|
190 | + * Throw an exception if there's no ID |
|
191 | + */ |
|
192 | + if (empty($parts['id'])) { |
|
193 | + throw new UserError(esc_html__( |
|
194 | + 'A missing or invalid ID was received.', |
|
195 | + 'event_espresso' |
|
196 | + )); |
|
197 | + } |
|
198 | + |
|
199 | + return EEM_Ticket::instance()->get_one_by_ID(absint($parts['id'])); |
|
200 | + } |
|
201 | 201 | } |
@@ -35,421 +35,421 @@ |
||
35 | 35 | */ |
36 | 36 | class Ticket extends TypeBase |
37 | 37 | { |
38 | - /** |
|
39 | - * Ticket constructor. |
|
40 | - * |
|
41 | - * @param EEM_Ticket $ticket_model |
|
42 | - */ |
|
43 | - public function __construct(EEM_Ticket $ticket_model) |
|
44 | - { |
|
45 | - $this->setName($this->namespace . 'Ticket'); |
|
46 | - $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
|
47 | - $this->setIsCustomPostType(false); |
|
48 | - parent::__construct($ticket_model); |
|
49 | - } |
|
38 | + /** |
|
39 | + * Ticket constructor. |
|
40 | + * |
|
41 | + * @param EEM_Ticket $ticket_model |
|
42 | + */ |
|
43 | + public function __construct(EEM_Ticket $ticket_model) |
|
44 | + { |
|
45 | + $this->setName($this->namespace . 'Ticket'); |
|
46 | + $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
|
47 | + $this->setIsCustomPostType(false); |
|
48 | + parent::__construct($ticket_model); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * @return GraphQLFieldInterface[] |
|
54 | - */ |
|
55 | - public function getFields(): array |
|
56 | - { |
|
57 | - $fields = [ |
|
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 GraphQLOutputField( |
|
71 | - 'cacheId', |
|
72 | - ['non_null' => 'String'], |
|
73 | - null, |
|
74 | - esc_html__('The cache ID of the object.', 'event_espresso') |
|
75 | - ), |
|
76 | - new GraphQLInputField( |
|
77 | - 'datetimes', |
|
78 | - ['list_of' => 'ID'], |
|
79 | - null, |
|
80 | - sprintf( |
|
81 | - '%1$s %2$s', |
|
82 | - esc_html__('Globally unique IDs of the datetimes related to the ticket.', 'event_espresso'), |
|
83 | - esc_html__('Ignored if empty.', 'event_espresso') |
|
84 | - ) |
|
85 | - ), |
|
86 | - new GraphQLField( |
|
87 | - 'description', |
|
88 | - 'String', |
|
89 | - 'description', |
|
90 | - esc_html__('Description of Ticket', 'event_espresso') |
|
91 | - ), |
|
92 | - new GraphQLField( |
|
93 | - 'endDate', |
|
94 | - 'String', |
|
95 | - 'end_date', |
|
96 | - esc_html__('End date and time of the Ticket', 'event_espresso'), |
|
97 | - [$this, 'formatDatetime'] |
|
98 | - ), |
|
99 | - new GraphQLOutputField( |
|
100 | - 'event', |
|
101 | - $this->namespace . 'Event', |
|
102 | - null, |
|
103 | - esc_html__('Event of the ticket.', 'event_espresso') |
|
104 | - ), |
|
105 | - new GraphQLField( |
|
106 | - 'isDefault', |
|
107 | - 'Boolean', |
|
108 | - 'is_default', |
|
109 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso') |
|
110 | - ), |
|
111 | - new GraphQLOutputField( |
|
112 | - 'isExpired', |
|
113 | - 'Boolean', |
|
114 | - 'is_expired', |
|
115 | - esc_html__('Flag indicating ticket is no longer available because its available dates have expired', 'event_espresso') |
|
116 | - ), |
|
117 | - new GraphQLOutputField( |
|
118 | - 'isFree', |
|
119 | - 'Boolean', |
|
120 | - 'is_free', |
|
121 | - esc_html__('Flag indicating whether the ticket is free.', 'event_espresso') |
|
122 | - ), |
|
123 | - new GraphQLOutputField( |
|
124 | - 'isOnSale', |
|
125 | - 'Boolean', |
|
126 | - 'is_on_sale', |
|
127 | - esc_html__('Flag indicating ticket ticket is on sale or not', 'event_espresso') |
|
128 | - ), |
|
129 | - new GraphQLOutputField( |
|
130 | - 'isPending', |
|
131 | - 'Boolean', |
|
132 | - 'is_pending', |
|
133 | - esc_html__('Flag indicating ticket is yet to go on sale or not', 'event_espresso') |
|
134 | - ), |
|
135 | - new GraphQLField( |
|
136 | - 'isRequired', |
|
137 | - 'Boolean', |
|
138 | - 'required', |
|
139 | - esc_html__( |
|
140 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
141 | - 'event_espresso' |
|
142 | - ) |
|
143 | - ), |
|
144 | - new GraphQLOutputField( |
|
145 | - 'isSoldOut', |
|
146 | - 'Boolean', |
|
147 | - null, |
|
148 | - esc_html__('Flag indicating whether the ticket is sold out', 'event_espresso'), |
|
149 | - null, |
|
150 | - [$this, 'getIsSoldOut'] |
|
151 | - ), |
|
152 | - new GraphQLField( |
|
153 | - 'isTaxable', |
|
154 | - 'Boolean', |
|
155 | - 'taxable', |
|
156 | - esc_html__( |
|
157 | - 'Flag indicating whether there is tax applied on this ticket', |
|
158 | - 'event_espresso' |
|
159 | - ) |
|
160 | - ), |
|
161 | - new GraphQLField( |
|
162 | - 'isTrashed', |
|
163 | - 'Boolean', |
|
164 | - 'deleted', |
|
165 | - esc_html__('Flag indicating ticket has been trashed.', 'event_espresso') |
|
166 | - ), |
|
167 | - new GraphQLField( |
|
168 | - 'max', |
|
169 | - 'Int', |
|
170 | - 'max', |
|
171 | - esc_html__( |
|
172 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
173 | - 'event_espresso' |
|
174 | - ), |
|
175 | - [$this, 'parseInfiniteValue'] |
|
176 | - ), |
|
177 | - new GraphQLField( |
|
178 | - 'min', |
|
179 | - 'Int', |
|
180 | - 'min', |
|
181 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso') |
|
182 | - ), |
|
183 | - new GraphQLField( |
|
184 | - 'name', |
|
185 | - 'String', |
|
186 | - 'name', |
|
187 | - esc_html__('Ticket Name', 'event_espresso') |
|
188 | - ), |
|
189 | - new GraphQLField( |
|
190 | - 'order', |
|
191 | - 'Int', |
|
192 | - 'order', |
|
193 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
194 | - ), |
|
195 | - new GraphQLOutputField( |
|
196 | - 'parent', |
|
197 | - $this->name(), |
|
198 | - null, |
|
199 | - esc_html__('The parent ticket of the current ticket', 'event_espresso') |
|
200 | - ), |
|
201 | - new GraphQLInputField( |
|
202 | - 'parent', |
|
203 | - 'ID', |
|
204 | - null, |
|
205 | - esc_html__('The parent ticket ID', 'event_espresso') |
|
206 | - ), |
|
207 | - new GraphQLField( |
|
208 | - 'price', |
|
209 | - 'Float', |
|
210 | - 'price', |
|
211 | - esc_html__('Final calculated price for ticket', 'event_espresso') |
|
212 | - ), |
|
213 | - new GraphQLInputField( |
|
214 | - 'prices', |
|
215 | - ['list_of' => 'ID'], |
|
216 | - null, |
|
217 | - sprintf( |
|
218 | - '%1$s %2$s', |
|
219 | - esc_html__('Globally unique IDs of the prices related to the ticket.', 'event_espresso'), |
|
220 | - esc_html__('Ignored if empty.', 'event_espresso') |
|
221 | - ) |
|
222 | - ), |
|
223 | - new GraphQLField( |
|
224 | - 'quantity', |
|
225 | - 'Int', |
|
226 | - 'qty', |
|
227 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
228 | - [$this, 'parseInfiniteValue'] |
|
229 | - ), |
|
230 | - new GraphQLOutputField( |
|
231 | - 'registrationCount', |
|
232 | - 'Int', |
|
233 | - null, |
|
234 | - esc_html__('Number of registrations for the ticket', 'event_espresso'), |
|
235 | - null, |
|
236 | - [$this, 'getRegistrationCount'] |
|
237 | - ), |
|
238 | - new GraphQLField( |
|
239 | - 'reserved', |
|
240 | - 'Int', |
|
241 | - 'reserved', |
|
242 | - esc_html__( |
|
243 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
244 | - 'event_espresso' |
|
245 | - ) |
|
246 | - ), |
|
247 | - new GraphQLField( |
|
248 | - 'reverseCalculate', |
|
249 | - 'Boolean', |
|
250 | - 'reverse_calculate', |
|
251 | - esc_html__( |
|
252 | - 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
253 | - 'event_espresso' |
|
254 | - ) |
|
255 | - ), |
|
256 | - new GraphQLField( |
|
257 | - 'row', |
|
258 | - 'Int', |
|
259 | - 'row', |
|
260 | - esc_html__('How tickets are displayed in the ui', 'event_espresso') |
|
261 | - ), |
|
262 | - new GraphQLField( |
|
263 | - 'sold', |
|
264 | - 'Int', |
|
265 | - 'sold', |
|
266 | - esc_html__('Number of this ticket sold', 'event_espresso') |
|
267 | - ), |
|
268 | - new GraphQLOutputField( |
|
269 | - 'status', |
|
270 | - $this->namespace . 'TicketStatusEnum', |
|
271 | - 'ticket_status', |
|
272 | - esc_html__('Ticket status', 'event_espresso') |
|
273 | - ), |
|
274 | - new GraphQLField( |
|
275 | - 'startDate', |
|
276 | - 'String', |
|
277 | - 'start_date', |
|
278 | - esc_html__('Start date and time of the Ticket', 'event_espresso'), |
|
279 | - [$this, 'formatDatetime'] |
|
280 | - ), |
|
281 | - new GraphQLField( |
|
282 | - 'uses', |
|
283 | - 'Int', |
|
284 | - 'uses', |
|
285 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
286 | - [$this, 'parseInfiniteValue'] |
|
287 | - ), |
|
288 | - new GraphQLField( |
|
289 | - 'visibility', |
|
290 | - $this->namespace . 'TicketVisibilityEnum', |
|
291 | - 'visibility', |
|
292 | - esc_html__('Where the ticket can be viewed throughout the UI', 'event_espresso') |
|
293 | - ), |
|
294 | - new GraphQLOutputField( |
|
295 | - 'wpUser', |
|
296 | - 'User', |
|
297 | - null, |
|
298 | - esc_html__('Ticket Creator', 'event_espresso') |
|
299 | - ), |
|
300 | - new GraphQLOutputField( |
|
301 | - 'userId', |
|
302 | - 'ID', |
|
303 | - null, |
|
304 | - esc_html__('Ticket Creator ID', 'event_espresso') |
|
305 | - ), |
|
306 | - new GraphQLInputField( |
|
307 | - 'wpUser', |
|
308 | - 'Int', |
|
309 | - null, |
|
310 | - esc_html__('Ticket Creator ID', 'event_espresso') |
|
311 | - ), |
|
312 | - ]; |
|
52 | + /** |
|
53 | + * @return GraphQLFieldInterface[] |
|
54 | + */ |
|
55 | + public function getFields(): array |
|
56 | + { |
|
57 | + $fields = [ |
|
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 GraphQLOutputField( |
|
71 | + 'cacheId', |
|
72 | + ['non_null' => 'String'], |
|
73 | + null, |
|
74 | + esc_html__('The cache ID of the object.', 'event_espresso') |
|
75 | + ), |
|
76 | + new GraphQLInputField( |
|
77 | + 'datetimes', |
|
78 | + ['list_of' => 'ID'], |
|
79 | + null, |
|
80 | + sprintf( |
|
81 | + '%1$s %2$s', |
|
82 | + esc_html__('Globally unique IDs of the datetimes related to the ticket.', 'event_espresso'), |
|
83 | + esc_html__('Ignored if empty.', 'event_espresso') |
|
84 | + ) |
|
85 | + ), |
|
86 | + new GraphQLField( |
|
87 | + 'description', |
|
88 | + 'String', |
|
89 | + 'description', |
|
90 | + esc_html__('Description of Ticket', 'event_espresso') |
|
91 | + ), |
|
92 | + new GraphQLField( |
|
93 | + 'endDate', |
|
94 | + 'String', |
|
95 | + 'end_date', |
|
96 | + esc_html__('End date and time of the Ticket', 'event_espresso'), |
|
97 | + [$this, 'formatDatetime'] |
|
98 | + ), |
|
99 | + new GraphQLOutputField( |
|
100 | + 'event', |
|
101 | + $this->namespace . 'Event', |
|
102 | + null, |
|
103 | + esc_html__('Event of the ticket.', 'event_espresso') |
|
104 | + ), |
|
105 | + new GraphQLField( |
|
106 | + 'isDefault', |
|
107 | + 'Boolean', |
|
108 | + 'is_default', |
|
109 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso') |
|
110 | + ), |
|
111 | + new GraphQLOutputField( |
|
112 | + 'isExpired', |
|
113 | + 'Boolean', |
|
114 | + 'is_expired', |
|
115 | + esc_html__('Flag indicating ticket is no longer available because its available dates have expired', 'event_espresso') |
|
116 | + ), |
|
117 | + new GraphQLOutputField( |
|
118 | + 'isFree', |
|
119 | + 'Boolean', |
|
120 | + 'is_free', |
|
121 | + esc_html__('Flag indicating whether the ticket is free.', 'event_espresso') |
|
122 | + ), |
|
123 | + new GraphQLOutputField( |
|
124 | + 'isOnSale', |
|
125 | + 'Boolean', |
|
126 | + 'is_on_sale', |
|
127 | + esc_html__('Flag indicating ticket ticket is on sale or not', 'event_espresso') |
|
128 | + ), |
|
129 | + new GraphQLOutputField( |
|
130 | + 'isPending', |
|
131 | + 'Boolean', |
|
132 | + 'is_pending', |
|
133 | + esc_html__('Flag indicating ticket is yet to go on sale or not', 'event_espresso') |
|
134 | + ), |
|
135 | + new GraphQLField( |
|
136 | + 'isRequired', |
|
137 | + 'Boolean', |
|
138 | + 'required', |
|
139 | + esc_html__( |
|
140 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
141 | + 'event_espresso' |
|
142 | + ) |
|
143 | + ), |
|
144 | + new GraphQLOutputField( |
|
145 | + 'isSoldOut', |
|
146 | + 'Boolean', |
|
147 | + null, |
|
148 | + esc_html__('Flag indicating whether the ticket is sold out', 'event_espresso'), |
|
149 | + null, |
|
150 | + [$this, 'getIsSoldOut'] |
|
151 | + ), |
|
152 | + new GraphQLField( |
|
153 | + 'isTaxable', |
|
154 | + 'Boolean', |
|
155 | + 'taxable', |
|
156 | + esc_html__( |
|
157 | + 'Flag indicating whether there is tax applied on this ticket', |
|
158 | + 'event_espresso' |
|
159 | + ) |
|
160 | + ), |
|
161 | + new GraphQLField( |
|
162 | + 'isTrashed', |
|
163 | + 'Boolean', |
|
164 | + 'deleted', |
|
165 | + esc_html__('Flag indicating ticket has been trashed.', 'event_espresso') |
|
166 | + ), |
|
167 | + new GraphQLField( |
|
168 | + 'max', |
|
169 | + 'Int', |
|
170 | + 'max', |
|
171 | + esc_html__( |
|
172 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
173 | + 'event_espresso' |
|
174 | + ), |
|
175 | + [$this, 'parseInfiniteValue'] |
|
176 | + ), |
|
177 | + new GraphQLField( |
|
178 | + 'min', |
|
179 | + 'Int', |
|
180 | + 'min', |
|
181 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso') |
|
182 | + ), |
|
183 | + new GraphQLField( |
|
184 | + 'name', |
|
185 | + 'String', |
|
186 | + 'name', |
|
187 | + esc_html__('Ticket Name', 'event_espresso') |
|
188 | + ), |
|
189 | + new GraphQLField( |
|
190 | + 'order', |
|
191 | + 'Int', |
|
192 | + 'order', |
|
193 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
194 | + ), |
|
195 | + new GraphQLOutputField( |
|
196 | + 'parent', |
|
197 | + $this->name(), |
|
198 | + null, |
|
199 | + esc_html__('The parent ticket of the current ticket', 'event_espresso') |
|
200 | + ), |
|
201 | + new GraphQLInputField( |
|
202 | + 'parent', |
|
203 | + 'ID', |
|
204 | + null, |
|
205 | + esc_html__('The parent ticket ID', 'event_espresso') |
|
206 | + ), |
|
207 | + new GraphQLField( |
|
208 | + 'price', |
|
209 | + 'Float', |
|
210 | + 'price', |
|
211 | + esc_html__('Final calculated price for ticket', 'event_espresso') |
|
212 | + ), |
|
213 | + new GraphQLInputField( |
|
214 | + 'prices', |
|
215 | + ['list_of' => 'ID'], |
|
216 | + null, |
|
217 | + sprintf( |
|
218 | + '%1$s %2$s', |
|
219 | + esc_html__('Globally unique IDs of the prices related to the ticket.', 'event_espresso'), |
|
220 | + esc_html__('Ignored if empty.', 'event_espresso') |
|
221 | + ) |
|
222 | + ), |
|
223 | + new GraphQLField( |
|
224 | + 'quantity', |
|
225 | + 'Int', |
|
226 | + 'qty', |
|
227 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
228 | + [$this, 'parseInfiniteValue'] |
|
229 | + ), |
|
230 | + new GraphQLOutputField( |
|
231 | + 'registrationCount', |
|
232 | + 'Int', |
|
233 | + null, |
|
234 | + esc_html__('Number of registrations for the ticket', 'event_espresso'), |
|
235 | + null, |
|
236 | + [$this, 'getRegistrationCount'] |
|
237 | + ), |
|
238 | + new GraphQLField( |
|
239 | + 'reserved', |
|
240 | + 'Int', |
|
241 | + 'reserved', |
|
242 | + esc_html__( |
|
243 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
244 | + 'event_espresso' |
|
245 | + ) |
|
246 | + ), |
|
247 | + new GraphQLField( |
|
248 | + 'reverseCalculate', |
|
249 | + 'Boolean', |
|
250 | + 'reverse_calculate', |
|
251 | + esc_html__( |
|
252 | + 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
253 | + 'event_espresso' |
|
254 | + ) |
|
255 | + ), |
|
256 | + new GraphQLField( |
|
257 | + 'row', |
|
258 | + 'Int', |
|
259 | + 'row', |
|
260 | + esc_html__('How tickets are displayed in the ui', 'event_espresso') |
|
261 | + ), |
|
262 | + new GraphQLField( |
|
263 | + 'sold', |
|
264 | + 'Int', |
|
265 | + 'sold', |
|
266 | + esc_html__('Number of this ticket sold', 'event_espresso') |
|
267 | + ), |
|
268 | + new GraphQLOutputField( |
|
269 | + 'status', |
|
270 | + $this->namespace . 'TicketStatusEnum', |
|
271 | + 'ticket_status', |
|
272 | + esc_html__('Ticket status', 'event_espresso') |
|
273 | + ), |
|
274 | + new GraphQLField( |
|
275 | + 'startDate', |
|
276 | + 'String', |
|
277 | + 'start_date', |
|
278 | + esc_html__('Start date and time of the Ticket', 'event_espresso'), |
|
279 | + [$this, 'formatDatetime'] |
|
280 | + ), |
|
281 | + new GraphQLField( |
|
282 | + 'uses', |
|
283 | + 'Int', |
|
284 | + 'uses', |
|
285 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
286 | + [$this, 'parseInfiniteValue'] |
|
287 | + ), |
|
288 | + new GraphQLField( |
|
289 | + 'visibility', |
|
290 | + $this->namespace . 'TicketVisibilityEnum', |
|
291 | + 'visibility', |
|
292 | + esc_html__('Where the ticket can be viewed throughout the UI', 'event_espresso') |
|
293 | + ), |
|
294 | + new GraphQLOutputField( |
|
295 | + 'wpUser', |
|
296 | + 'User', |
|
297 | + null, |
|
298 | + esc_html__('Ticket Creator', 'event_espresso') |
|
299 | + ), |
|
300 | + new GraphQLOutputField( |
|
301 | + 'userId', |
|
302 | + 'ID', |
|
303 | + null, |
|
304 | + esc_html__('Ticket Creator ID', 'event_espresso') |
|
305 | + ), |
|
306 | + new GraphQLInputField( |
|
307 | + 'wpUser', |
|
308 | + 'Int', |
|
309 | + null, |
|
310 | + esc_html__('Ticket Creator ID', 'event_espresso') |
|
311 | + ), |
|
312 | + ]; |
|
313 | 313 | |
314 | - return apply_filters( |
|
315 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__ticket_fields', |
|
316 | - $fields, |
|
317 | - $this->name, |
|
318 | - $this->model |
|
319 | - ); |
|
320 | - } |
|
314 | + return apply_filters( |
|
315 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__ticket_fields', |
|
316 | + $fields, |
|
317 | + $this->name, |
|
318 | + $this->model |
|
319 | + ); |
|
320 | + } |
|
321 | 321 | |
322 | 322 | |
323 | - /** |
|
324 | - * @param EE_Ticket $source The source that's passed down the GraphQL queries |
|
325 | - * @param array $args The inputArgs on the field |
|
326 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
327 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
328 | - * @return bool |
|
329 | - * @throws Exception |
|
330 | - * @throws InvalidArgumentException |
|
331 | - * @throws InvalidDataTypeException |
|
332 | - * @throws InvalidInterfaceException |
|
333 | - * @throws ReflectionException |
|
334 | - * @throws UserError |
|
335 | - * @throws UnexpectedEntityException |
|
336 | - * @since 5.0.0.p |
|
337 | - */ |
|
338 | - public function getIsSoldOut(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info): bool |
|
339 | - { |
|
340 | - return $source->ticket_status() === EE_Ticket::sold_out; |
|
341 | - } |
|
323 | + /** |
|
324 | + * @param EE_Ticket $source The source that's passed down the GraphQL queries |
|
325 | + * @param array $args The inputArgs on the field |
|
326 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
327 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
328 | + * @return bool |
|
329 | + * @throws Exception |
|
330 | + * @throws InvalidArgumentException |
|
331 | + * @throws InvalidDataTypeException |
|
332 | + * @throws InvalidInterfaceException |
|
333 | + * @throws ReflectionException |
|
334 | + * @throws UserError |
|
335 | + * @throws UnexpectedEntityException |
|
336 | + * @since 5.0.0.p |
|
337 | + */ |
|
338 | + public function getIsSoldOut(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info): bool |
|
339 | + { |
|
340 | + return $source->ticket_status() === EE_Ticket::sold_out; |
|
341 | + } |
|
342 | 342 | |
343 | 343 | |
344 | - /** |
|
345 | - * @param EE_Ticket $source The source that's passed down the GraphQL queries |
|
346 | - * @param array $args The inputArgs on the field |
|
347 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
348 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
349 | - * @return bool |
|
350 | - * @throws Exception |
|
351 | - * @throws InvalidArgumentException |
|
352 | - * @throws InvalidDataTypeException |
|
353 | - * @throws InvalidInterfaceException |
|
354 | - * @throws ReflectionException |
|
355 | - * @throws UserError |
|
356 | - * @throws UnexpectedEntityException |
|
357 | - * @since 5.0.0.p |
|
358 | - */ |
|
359 | - public function getRegistrationCount(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info): int |
|
360 | - { |
|
361 | - $active_reg_statuses = EEM_Registration::active_reg_statuses(); |
|
362 | - return $source->count_registrations( |
|
363 | - [ |
|
364 | - [ |
|
365 | - 'STS_ID' => ['IN', $active_reg_statuses], |
|
366 | - 'REG_deleted' => 0, |
|
367 | - ] |
|
368 | - ] |
|
369 | - ); |
|
370 | - } |
|
344 | + /** |
|
345 | + * @param EE_Ticket $source The source that's passed down the GraphQL queries |
|
346 | + * @param array $args The inputArgs on the field |
|
347 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
348 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
349 | + * @return bool |
|
350 | + * @throws Exception |
|
351 | + * @throws InvalidArgumentException |
|
352 | + * @throws InvalidDataTypeException |
|
353 | + * @throws InvalidInterfaceException |
|
354 | + * @throws ReflectionException |
|
355 | + * @throws UserError |
|
356 | + * @throws UnexpectedEntityException |
|
357 | + * @since 5.0.0.p |
|
358 | + */ |
|
359 | + public function getRegistrationCount(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info): int |
|
360 | + { |
|
361 | + $active_reg_statuses = EEM_Registration::active_reg_statuses(); |
|
362 | + return $source->count_registrations( |
|
363 | + [ |
|
364 | + [ |
|
365 | + 'STS_ID' => ['IN', $active_reg_statuses], |
|
366 | + 'REG_deleted' => 0, |
|
367 | + ] |
|
368 | + ] |
|
369 | + ); |
|
370 | + } |
|
371 | 371 | |
372 | 372 | |
373 | - /** |
|
374 | - * @param array $inputFields The mutation input fields. |
|
375 | - * @throws InvalidArgumentException |
|
376 | - * @throws ReflectionException |
|
377 | - * @throws Exception |
|
378 | - */ |
|
379 | - public function registerMutations(array $inputFields) |
|
380 | - { |
|
381 | - register_graphql_input_type( |
|
382 | - 'Update' . $this->name() . 'BaseInput', |
|
383 | - [ |
|
384 | - 'fields' => $inputFields, |
|
385 | - ] |
|
386 | - ); |
|
387 | - // Register mutation to update an entity. |
|
388 | - register_graphql_mutation( |
|
389 | - 'update' . $this->name(), |
|
390 | - [ |
|
391 | - 'inputFields' => $inputFields, |
|
392 | - 'outputFields' => [ |
|
393 | - lcfirst($this->name()) => [ |
|
394 | - 'type' => $this->name(), |
|
395 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
396 | - ], |
|
397 | - ], |
|
398 | - 'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this), |
|
399 | - ] |
|
400 | - ); |
|
401 | - $base_input = 'Update' . $this->name() . 'BaseInput'; |
|
402 | - // Register mutation to update an entity. |
|
403 | - register_graphql_mutation( |
|
404 | - 'bulkUpdate' . $this->name(), |
|
405 | - array_merge( |
|
406 | - Datetime::bulkUpdateBaseConfig($base_input), |
|
407 | - [ |
|
408 | - 'mutateAndGetPayload' => TicketBulkUpdate::mutateAndGetPayload($this->model, $this), |
|
409 | - ] |
|
410 | - ) |
|
411 | - ); |
|
412 | - // Register mutation to delete an entity. |
|
413 | - register_graphql_mutation( |
|
414 | - 'delete' . $this->name(), |
|
415 | - [ |
|
416 | - 'inputFields' => [ |
|
417 | - 'id' => $inputFields['id'], |
|
418 | - 'deletePermanently' => [ |
|
419 | - 'type' => 'Boolean', |
|
420 | - 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
421 | - ], |
|
422 | - ], |
|
423 | - 'outputFields' => [ |
|
424 | - lcfirst($this->name()) => [ |
|
425 | - 'type' => $this->name(), |
|
426 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
427 | - 'resolve' => static function ($payload) { |
|
428 | - $deleted = (object) $payload['deleted']; |
|
373 | + /** |
|
374 | + * @param array $inputFields The mutation input fields. |
|
375 | + * @throws InvalidArgumentException |
|
376 | + * @throws ReflectionException |
|
377 | + * @throws Exception |
|
378 | + */ |
|
379 | + public function registerMutations(array $inputFields) |
|
380 | + { |
|
381 | + register_graphql_input_type( |
|
382 | + 'Update' . $this->name() . 'BaseInput', |
|
383 | + [ |
|
384 | + 'fields' => $inputFields, |
|
385 | + ] |
|
386 | + ); |
|
387 | + // Register mutation to update an entity. |
|
388 | + register_graphql_mutation( |
|
389 | + 'update' . $this->name(), |
|
390 | + [ |
|
391 | + 'inputFields' => $inputFields, |
|
392 | + 'outputFields' => [ |
|
393 | + lcfirst($this->name()) => [ |
|
394 | + 'type' => $this->name(), |
|
395 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
396 | + ], |
|
397 | + ], |
|
398 | + 'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this), |
|
399 | + ] |
|
400 | + ); |
|
401 | + $base_input = 'Update' . $this->name() . 'BaseInput'; |
|
402 | + // Register mutation to update an entity. |
|
403 | + register_graphql_mutation( |
|
404 | + 'bulkUpdate' . $this->name(), |
|
405 | + array_merge( |
|
406 | + Datetime::bulkUpdateBaseConfig($base_input), |
|
407 | + [ |
|
408 | + 'mutateAndGetPayload' => TicketBulkUpdate::mutateAndGetPayload($this->model, $this), |
|
409 | + ] |
|
410 | + ) |
|
411 | + ); |
|
412 | + // Register mutation to delete an entity. |
|
413 | + register_graphql_mutation( |
|
414 | + 'delete' . $this->name(), |
|
415 | + [ |
|
416 | + 'inputFields' => [ |
|
417 | + 'id' => $inputFields['id'], |
|
418 | + 'deletePermanently' => [ |
|
419 | + 'type' => 'Boolean', |
|
420 | + 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
421 | + ], |
|
422 | + ], |
|
423 | + 'outputFields' => [ |
|
424 | + lcfirst($this->name()) => [ |
|
425 | + 'type' => $this->name(), |
|
426 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
427 | + 'resolve' => static function ($payload) { |
|
428 | + $deleted = (object) $payload['deleted']; |
|
429 | 429 | |
430 | - return ! empty($deleted) ? $deleted : null; |
|
431 | - }, |
|
432 | - ], |
|
433 | - ], |
|
434 | - 'mutateAndGetPayload' => TicketDelete::mutateAndGetPayload($this->model, $this), |
|
435 | - ] |
|
436 | - ); |
|
430 | + return ! empty($deleted) ? $deleted : null; |
|
431 | + }, |
|
432 | + ], |
|
433 | + ], |
|
434 | + 'mutateAndGetPayload' => TicketDelete::mutateAndGetPayload($this->model, $this), |
|
435 | + ] |
|
436 | + ); |
|
437 | 437 | |
438 | - // remove primary key from input. |
|
439 | - unset($inputFields['id']); |
|
440 | - // Register mutation to update an entity. |
|
441 | - register_graphql_mutation( |
|
442 | - 'create' . $this->name(), |
|
443 | - [ |
|
444 | - 'inputFields' => $inputFields, |
|
445 | - 'outputFields' => [ |
|
446 | - lcfirst($this->name()) => [ |
|
447 | - 'type' => $this->name(), |
|
448 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
449 | - ], |
|
450 | - ], |
|
451 | - 'mutateAndGetPayload' => TicketCreate::mutateAndGetPayload($this->model, $this), |
|
452 | - ] |
|
453 | - ); |
|
454 | - } |
|
438 | + // remove primary key from input. |
|
439 | + unset($inputFields['id']); |
|
440 | + // Register mutation to update an entity. |
|
441 | + register_graphql_mutation( |
|
442 | + 'create' . $this->name(), |
|
443 | + [ |
|
444 | + 'inputFields' => $inputFields, |
|
445 | + 'outputFields' => [ |
|
446 | + lcfirst($this->name()) => [ |
|
447 | + 'type' => $this->name(), |
|
448 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
449 | + ], |
|
450 | + ], |
|
451 | + 'mutateAndGetPayload' => TicketCreate::mutateAndGetPayload($this->model, $this), |
|
452 | + ] |
|
453 | + ); |
|
454 | + } |
|
455 | 455 | } |
@@ -24,225 +24,225 @@ |
||
24 | 24 | */ |
25 | 25 | class Event extends TypeBase |
26 | 26 | { |
27 | - /** |
|
28 | - * Event constructor. |
|
29 | - * |
|
30 | - * @param EEM_Event $event_model |
|
31 | - */ |
|
32 | - public function __construct(EEM_Event $event_model) |
|
33 | - { |
|
34 | - $this->setName($this->namespace . 'Event'); |
|
35 | - $this->setIsCustomPostType(true); |
|
36 | - parent::__construct($event_model); |
|
37 | - } |
|
27 | + /** |
|
28 | + * Event constructor. |
|
29 | + * |
|
30 | + * @param EEM_Event $event_model |
|
31 | + */ |
|
32 | + public function __construct(EEM_Event $event_model) |
|
33 | + { |
|
34 | + $this->setName($this->namespace . 'Event'); |
|
35 | + $this->setIsCustomPostType(true); |
|
36 | + parent::__construct($event_model); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @return GraphQLFieldInterface[] |
|
42 | - */ |
|
43 | - public function getFields(): array |
|
44 | - { |
|
45 | - return apply_filters( |
|
46 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__event_fields', |
|
47 | - [ |
|
48 | - new GraphQLField( |
|
49 | - 'allowDonations', |
|
50 | - 'Boolean', |
|
51 | - 'donations', |
|
52 | - esc_html__('Accept Donations?', 'event_espresso') |
|
53 | - ), |
|
54 | - new GraphQLField( |
|
55 | - 'allowOverflow', |
|
56 | - 'Boolean', |
|
57 | - 'allow_overflow', |
|
58 | - esc_html__('Enable Wait List for Event', 'event_espresso') |
|
59 | - ), |
|
60 | - new GraphQLField( |
|
61 | - 'altRegPage', |
|
62 | - 'String', |
|
63 | - 'external_url', |
|
64 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso') |
|
65 | - ), |
|
66 | - new GraphQLOutputField( |
|
67 | - 'cacheId', |
|
68 | - ['non_null' => 'String'], |
|
69 | - null, |
|
70 | - esc_html__('The cache ID of the object.', 'event_espresso') |
|
71 | - ), |
|
72 | - new GraphQLField( |
|
73 | - 'created', |
|
74 | - 'String', |
|
75 | - 'created', |
|
76 | - esc_html__('Date/Time Event Created', 'event_espresso') |
|
77 | - ), |
|
78 | - new GraphQLOutputField( |
|
79 | - 'dbId', |
|
80 | - ['non_null' => 'Int'], |
|
81 | - 'ID', |
|
82 | - esc_html__('The event ID.', 'event_espresso') |
|
83 | - ), |
|
84 | - new GraphQLField( |
|
85 | - 'defaultRegStatus', |
|
86 | - $this->namespace . 'RegistrationStatusEnum', |
|
87 | - 'default_registration_status', |
|
88 | - esc_html__('Default Event Registration Status', 'event_espresso') |
|
89 | - ), |
|
90 | - new GraphQLField( |
|
91 | - 'description', |
|
92 | - 'String', |
|
93 | - 'description', |
|
94 | - esc_html__('Event Description', 'event_espresso') |
|
95 | - ), |
|
96 | - new GraphQLField( |
|
97 | - 'displayDescription', |
|
98 | - 'Boolean', |
|
99 | - 'display_description', |
|
100 | - esc_html__('Display Description Flag', 'event_espresso') |
|
101 | - ), |
|
102 | - new GraphQLField( |
|
103 | - 'displayTicketSelector', |
|
104 | - 'Boolean', |
|
105 | - 'display_ticket_selector', |
|
106 | - esc_html__('Display Ticket Selector Flag', 'event_espresso') |
|
107 | - ), |
|
108 | - new GraphQLOutputField( |
|
109 | - 'isActive', |
|
110 | - 'Boolean', |
|
111 | - 'is_active', |
|
112 | - esc_html__('Flag indicating event is active', 'event_espresso') |
|
113 | - ), |
|
114 | - new GraphQLOutputField( |
|
115 | - 'isCancelled', |
|
116 | - 'Boolean', |
|
117 | - 'is_cancelled', |
|
118 | - esc_html__('Flag indicating whether the event is marked as cancelled', 'event_espresso') |
|
119 | - ), |
|
120 | - new GraphQLOutputField( |
|
121 | - 'isExpired', |
|
122 | - 'Boolean', |
|
123 | - 'is_expired', |
|
124 | - esc_html__('Flag indicating event is expired or not', 'event_espresso') |
|
125 | - ), |
|
126 | - new GraphQLOutputField( |
|
127 | - 'isInactive', |
|
128 | - 'Boolean', |
|
129 | - 'is_inactive', |
|
130 | - esc_html__('Flag indicating event is inactive', 'event_espresso') |
|
131 | - ), |
|
132 | - new GraphQLOutputField( |
|
133 | - 'isPostponed', |
|
134 | - 'Boolean', |
|
135 | - 'is_postponed', |
|
136 | - esc_html__('Flag indicating whether the event is marked as postponed', 'event_espresso') |
|
137 | - ), |
|
138 | - new GraphQLOutputField( |
|
139 | - 'isSoldOut', |
|
140 | - 'Boolean', |
|
141 | - 'is_sold_out', |
|
142 | - esc_html__( |
|
143 | - 'Flag indicating whether the tickets sold for the event, met or exceed the registration limit', |
|
144 | - 'event_espresso' |
|
145 | - ) |
|
146 | - ), |
|
147 | - new GraphQLOutputField( |
|
148 | - 'isUpcoming', |
|
149 | - 'Boolean', |
|
150 | - 'is_upcoming', |
|
151 | - esc_html__('Whether the event is upcoming', 'event_espresso') |
|
152 | - ), |
|
153 | - new GraphQLInputField( |
|
154 | - 'manager', |
|
155 | - 'String', |
|
156 | - null, |
|
157 | - esc_html__('Globally unique event ID for the event manager', 'event_espresso') |
|
158 | - ), |
|
159 | - new GraphQLOutputField( |
|
160 | - 'manager', |
|
161 | - 'User', |
|
162 | - null, |
|
163 | - esc_html__('Event Manager', 'event_espresso') |
|
164 | - ), |
|
165 | - new GraphQLField( |
|
166 | - 'maxRegistrations', |
|
167 | - 'Int', |
|
168 | - 'additional_limit', |
|
169 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso') |
|
170 | - ), |
|
171 | - new GraphQLField( |
|
172 | - 'memberOnly', |
|
173 | - 'Boolean', |
|
174 | - 'member_only', |
|
175 | - esc_html__('Member-Only Event Flag', 'event_espresso') |
|
176 | - ), |
|
177 | - new GraphQLField( |
|
178 | - 'name', |
|
179 | - 'String', |
|
180 | - 'name', |
|
181 | - esc_html__('Event Name', 'event_espresso') |
|
182 | - ), |
|
183 | - new GraphQLField( |
|
184 | - 'order', |
|
185 | - 'Int', |
|
186 | - 'order', |
|
187 | - esc_html__('Event Menu Order', 'event_espresso') |
|
188 | - ), |
|
189 | - new GraphQLField( |
|
190 | - 'phoneNumber', |
|
191 | - 'String', |
|
192 | - 'phone', |
|
193 | - esc_html__('Event Phone Number', 'event_espresso') |
|
194 | - ), |
|
195 | - new GraphQLField( |
|
196 | - 'shortDescription', |
|
197 | - 'String', |
|
198 | - 'short_description', |
|
199 | - esc_html__('Event Short Description', 'event_espresso') |
|
200 | - ), |
|
201 | - new GraphQLField( |
|
202 | - 'timezoneString', |
|
203 | - 'String', |
|
204 | - 'timezone_string', |
|
205 | - esc_html__('Timezone (name) for Event times', 'event_espresso') |
|
206 | - ), |
|
207 | - new GraphQLField( |
|
208 | - 'visibleOn', |
|
209 | - 'String', |
|
210 | - 'visible_on', |
|
211 | - esc_html__('Event Visible Date', 'event_espresso') |
|
212 | - ), |
|
213 | - new GraphQLField( |
|
214 | - 'venue', |
|
215 | - 'String', |
|
216 | - null, |
|
217 | - esc_html__('Event venue ID', 'event_espresso'), |
|
218 | - null, |
|
219 | - function (EE_Event $source) { |
|
220 | - $venue_ID = $source->venue_ID(); |
|
221 | - return $venue_ID |
|
222 | - // Since venue is a CPT, $type will be 'post' |
|
223 | - ? Relay::toGlobalId('post', $venue_ID) |
|
224 | - : null; |
|
225 | - } |
|
226 | - ), |
|
227 | - ], |
|
228 | - $this->name, |
|
229 | - $this->model |
|
230 | - ); |
|
231 | - } |
|
40 | + /** |
|
41 | + * @return GraphQLFieldInterface[] |
|
42 | + */ |
|
43 | + public function getFields(): array |
|
44 | + { |
|
45 | + return apply_filters( |
|
46 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__event_fields', |
|
47 | + [ |
|
48 | + new GraphQLField( |
|
49 | + 'allowDonations', |
|
50 | + 'Boolean', |
|
51 | + 'donations', |
|
52 | + esc_html__('Accept Donations?', 'event_espresso') |
|
53 | + ), |
|
54 | + new GraphQLField( |
|
55 | + 'allowOverflow', |
|
56 | + 'Boolean', |
|
57 | + 'allow_overflow', |
|
58 | + esc_html__('Enable Wait List for Event', 'event_espresso') |
|
59 | + ), |
|
60 | + new GraphQLField( |
|
61 | + 'altRegPage', |
|
62 | + 'String', |
|
63 | + 'external_url', |
|
64 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso') |
|
65 | + ), |
|
66 | + new GraphQLOutputField( |
|
67 | + 'cacheId', |
|
68 | + ['non_null' => 'String'], |
|
69 | + null, |
|
70 | + esc_html__('The cache ID of the object.', 'event_espresso') |
|
71 | + ), |
|
72 | + new GraphQLField( |
|
73 | + 'created', |
|
74 | + 'String', |
|
75 | + 'created', |
|
76 | + esc_html__('Date/Time Event Created', 'event_espresso') |
|
77 | + ), |
|
78 | + new GraphQLOutputField( |
|
79 | + 'dbId', |
|
80 | + ['non_null' => 'Int'], |
|
81 | + 'ID', |
|
82 | + esc_html__('The event ID.', 'event_espresso') |
|
83 | + ), |
|
84 | + new GraphQLField( |
|
85 | + 'defaultRegStatus', |
|
86 | + $this->namespace . 'RegistrationStatusEnum', |
|
87 | + 'default_registration_status', |
|
88 | + esc_html__('Default Event Registration Status', 'event_espresso') |
|
89 | + ), |
|
90 | + new GraphQLField( |
|
91 | + 'description', |
|
92 | + 'String', |
|
93 | + 'description', |
|
94 | + esc_html__('Event Description', 'event_espresso') |
|
95 | + ), |
|
96 | + new GraphQLField( |
|
97 | + 'displayDescription', |
|
98 | + 'Boolean', |
|
99 | + 'display_description', |
|
100 | + esc_html__('Display Description Flag', 'event_espresso') |
|
101 | + ), |
|
102 | + new GraphQLField( |
|
103 | + 'displayTicketSelector', |
|
104 | + 'Boolean', |
|
105 | + 'display_ticket_selector', |
|
106 | + esc_html__('Display Ticket Selector Flag', 'event_espresso') |
|
107 | + ), |
|
108 | + new GraphQLOutputField( |
|
109 | + 'isActive', |
|
110 | + 'Boolean', |
|
111 | + 'is_active', |
|
112 | + esc_html__('Flag indicating event is active', 'event_espresso') |
|
113 | + ), |
|
114 | + new GraphQLOutputField( |
|
115 | + 'isCancelled', |
|
116 | + 'Boolean', |
|
117 | + 'is_cancelled', |
|
118 | + esc_html__('Flag indicating whether the event is marked as cancelled', 'event_espresso') |
|
119 | + ), |
|
120 | + new GraphQLOutputField( |
|
121 | + 'isExpired', |
|
122 | + 'Boolean', |
|
123 | + 'is_expired', |
|
124 | + esc_html__('Flag indicating event is expired or not', 'event_espresso') |
|
125 | + ), |
|
126 | + new GraphQLOutputField( |
|
127 | + 'isInactive', |
|
128 | + 'Boolean', |
|
129 | + 'is_inactive', |
|
130 | + esc_html__('Flag indicating event is inactive', 'event_espresso') |
|
131 | + ), |
|
132 | + new GraphQLOutputField( |
|
133 | + 'isPostponed', |
|
134 | + 'Boolean', |
|
135 | + 'is_postponed', |
|
136 | + esc_html__('Flag indicating whether the event is marked as postponed', 'event_espresso') |
|
137 | + ), |
|
138 | + new GraphQLOutputField( |
|
139 | + 'isSoldOut', |
|
140 | + 'Boolean', |
|
141 | + 'is_sold_out', |
|
142 | + esc_html__( |
|
143 | + 'Flag indicating whether the tickets sold for the event, met or exceed the registration limit', |
|
144 | + 'event_espresso' |
|
145 | + ) |
|
146 | + ), |
|
147 | + new GraphQLOutputField( |
|
148 | + 'isUpcoming', |
|
149 | + 'Boolean', |
|
150 | + 'is_upcoming', |
|
151 | + esc_html__('Whether the event is upcoming', 'event_espresso') |
|
152 | + ), |
|
153 | + new GraphQLInputField( |
|
154 | + 'manager', |
|
155 | + 'String', |
|
156 | + null, |
|
157 | + esc_html__('Globally unique event ID for the event manager', 'event_espresso') |
|
158 | + ), |
|
159 | + new GraphQLOutputField( |
|
160 | + 'manager', |
|
161 | + 'User', |
|
162 | + null, |
|
163 | + esc_html__('Event Manager', 'event_espresso') |
|
164 | + ), |
|
165 | + new GraphQLField( |
|
166 | + 'maxRegistrations', |
|
167 | + 'Int', |
|
168 | + 'additional_limit', |
|
169 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso') |
|
170 | + ), |
|
171 | + new GraphQLField( |
|
172 | + 'memberOnly', |
|
173 | + 'Boolean', |
|
174 | + 'member_only', |
|
175 | + esc_html__('Member-Only Event Flag', 'event_espresso') |
|
176 | + ), |
|
177 | + new GraphQLField( |
|
178 | + 'name', |
|
179 | + 'String', |
|
180 | + 'name', |
|
181 | + esc_html__('Event Name', 'event_espresso') |
|
182 | + ), |
|
183 | + new GraphQLField( |
|
184 | + 'order', |
|
185 | + 'Int', |
|
186 | + 'order', |
|
187 | + esc_html__('Event Menu Order', 'event_espresso') |
|
188 | + ), |
|
189 | + new GraphQLField( |
|
190 | + 'phoneNumber', |
|
191 | + 'String', |
|
192 | + 'phone', |
|
193 | + esc_html__('Event Phone Number', 'event_espresso') |
|
194 | + ), |
|
195 | + new GraphQLField( |
|
196 | + 'shortDescription', |
|
197 | + 'String', |
|
198 | + 'short_description', |
|
199 | + esc_html__('Event Short Description', 'event_espresso') |
|
200 | + ), |
|
201 | + new GraphQLField( |
|
202 | + 'timezoneString', |
|
203 | + 'String', |
|
204 | + 'timezone_string', |
|
205 | + esc_html__('Timezone (name) for Event times', 'event_espresso') |
|
206 | + ), |
|
207 | + new GraphQLField( |
|
208 | + 'visibleOn', |
|
209 | + 'String', |
|
210 | + 'visible_on', |
|
211 | + esc_html__('Event Visible Date', 'event_espresso') |
|
212 | + ), |
|
213 | + new GraphQLField( |
|
214 | + 'venue', |
|
215 | + 'String', |
|
216 | + null, |
|
217 | + esc_html__('Event venue ID', 'event_espresso'), |
|
218 | + null, |
|
219 | + function (EE_Event $source) { |
|
220 | + $venue_ID = $source->venue_ID(); |
|
221 | + return $venue_ID |
|
222 | + // Since venue is a CPT, $type will be 'post' |
|
223 | + ? Relay::toGlobalId('post', $venue_ID) |
|
224 | + : null; |
|
225 | + } |
|
226 | + ), |
|
227 | + ], |
|
228 | + $this->name, |
|
229 | + $this->model |
|
230 | + ); |
|
231 | + } |
|
232 | 232 | |
233 | 233 | |
234 | - /** |
|
235 | - * Extends the existing WP GraphQL mutations. |
|
236 | - * |
|
237 | - * @since 5.0.0.p |
|
238 | - */ |
|
239 | - public function extendMutations() |
|
240 | - { |
|
241 | - add_action( |
|
242 | - 'graphql_post_object_mutation_update_additional_data', |
|
243 | - EventUpdate::mutateFields($this->model, $this), |
|
244 | - 10, |
|
245 | - 6 |
|
246 | - ); |
|
247 | - } |
|
234 | + /** |
|
235 | + * Extends the existing WP GraphQL mutations. |
|
236 | + * |
|
237 | + * @since 5.0.0.p |
|
238 | + */ |
|
239 | + public function extendMutations() |
|
240 | + { |
|
241 | + add_action( |
|
242 | + 'graphql_post_object_mutation_update_additional_data', |
|
243 | + EventUpdate::mutateFields($this->model, $this), |
|
244 | + 10, |
|
245 | + 6 |
|
246 | + ); |
|
247 | + } |
|
248 | 248 | } |