@@ -7,13 +7,9 @@ |
||
7 | 7 | use EEM_Price; |
8 | 8 | use EEM_Ticket; |
9 | 9 | use EE_Ticket; |
10 | -use EventEspresso\core\domain\services\assets\EspressoEditorAssetManager; |
|
11 | -use EventEspresso\core\domain\services\converters\RestApiSpoofer; |
|
12 | 10 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
13 | 11 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
14 | 12 | use EventEspresso\core\exceptions\ModelConfigurationException; |
15 | -use EventEspresso\core\exceptions\RestPasswordIncorrectException; |
|
16 | -use EventEspresso\core\exceptions\RestPasswordRequiredException; |
|
17 | 13 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
18 | 14 | use EventEspresso\core\libraries\rest_api\RestException; |
19 | 15 | use InvalidArgumentException; |
@@ -28,120 +28,120 @@ |
||
28 | 28 | class TicketMutation |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Maps the GraphQL input to a format that the model functions can use |
|
33 | - * |
|
34 | - * @param array $input Data coming from the GraphQL mutation query input |
|
35 | - * @return array |
|
36 | - */ |
|
37 | - public static function prepareFields(array $input) |
|
38 | - { |
|
39 | - |
|
40 | - $args = []; |
|
41 | - |
|
42 | - if (! empty($input['name'])) { |
|
43 | - $args['TKT_name'] = sanitize_text_field($input['name']); |
|
44 | - } |
|
45 | - |
|
46 | - if (! empty($input['description'])) { |
|
47 | - $args['TKT_description'] = sanitize_text_field($input['description']); |
|
48 | - } |
|
49 | - |
|
50 | - if (! empty($input['price'])) { |
|
51 | - $args['TKT_price'] = floatval($input['price']); |
|
52 | - } |
|
53 | - |
|
54 | - if (! empty($input['startDate'])) { |
|
55 | - $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
56 | - } |
|
57 | - |
|
58 | - if (! empty($input['endDate'])) { |
|
59 | - $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
60 | - } |
|
61 | - |
|
62 | - if (! empty($input['datetimes'])) { |
|
63 | - $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
64 | - } |
|
65 | - |
|
66 | - if (! empty($input['prices'])) { |
|
67 | - $args['prices'] = array_map('sanitize_text_field', (array) $input['prices']); |
|
68 | - } |
|
69 | - |
|
70 | - // Likewise the other fields... |
|
71 | - |
|
72 | - return $args; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Sets the related datetimes for the given ticket. |
|
77 | - * |
|
78 | - * @param EE_Ticket $entity The Ticket instance. |
|
79 | - * @param array $datetimes Array of datetime IDs to relate. |
|
80 | - */ |
|
81 | - public static function setRelatedDatetimes($entity, array $datetimes) |
|
82 | - { |
|
83 | - $relationName = 'Datetime'; |
|
84 | - // Remove all the existing related datetimes |
|
85 | - |
|
86 | - $entity->_remove_relations($relationName); |
|
87 | - // @todo replace loop with single query |
|
88 | - foreach ($datetimes as $ID) { |
|
89 | - $parts = Relay::fromGlobalId($ID); |
|
90 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
91 | - $entity->_add_relation_to( |
|
92 | - $parts['id'], |
|
93 | - $relationName |
|
94 | - ); |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Sets the related prices for the given ticket. |
|
101 | - * |
|
102 | - * @param EE_Ticket $entity The Ticket instance. |
|
103 | - * @param array $prices Array of entity IDs to relate. |
|
104 | - */ |
|
105 | - public static function setRelatedPrices($entity, array $prices) |
|
106 | - { |
|
107 | - $relationName = 'Price'; |
|
108 | - // Remove all the existing related entities |
|
109 | - $entity->_remove_relations($relationName); |
|
110 | - |
|
111 | - // @todo replace loop with single query |
|
112 | - foreach ($prices as $ID) { |
|
113 | - $parts = Relay::fromGlobalId($ID); |
|
114 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
115 | - $entity->_add_relation_to( |
|
116 | - $parts['id'], |
|
117 | - $relationName |
|
118 | - ); |
|
119 | - } |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @param EE_Ticket $ticket_entity |
|
126 | - * @param EEM_Ticket $ticket_model |
|
127 | - * @throws DomainException |
|
128 | - * @throws EE_Error |
|
129 | - * @throws InvalidArgumentException |
|
130 | - * @throws InvalidDataTypeException |
|
131 | - * @throws InvalidInterfaceException |
|
132 | - * @throws ModelConfigurationException |
|
133 | - * @throws ReflectionException |
|
134 | - * @throws RestException |
|
135 | - * @throws UnexpectedEntityException |
|
136 | - * @since $VID:$ |
|
137 | - */ |
|
138 | - public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model) |
|
139 | - { |
|
140 | - $price_model = EEM_Price::instance(); |
|
141 | - $default_prices = $price_model->get_all_default_prices(); |
|
142 | - foreach ($default_prices as $default_price) { |
|
143 | - $default_price->save(); |
|
144 | - $default_price->_add_relation_to($ticket_entity, 'Ticket'); |
|
145 | - } |
|
146 | - } |
|
31 | + /** |
|
32 | + * Maps the GraphQL input to a format that the model functions can use |
|
33 | + * |
|
34 | + * @param array $input Data coming from the GraphQL mutation query input |
|
35 | + * @return array |
|
36 | + */ |
|
37 | + public static function prepareFields(array $input) |
|
38 | + { |
|
39 | + |
|
40 | + $args = []; |
|
41 | + |
|
42 | + if (! empty($input['name'])) { |
|
43 | + $args['TKT_name'] = sanitize_text_field($input['name']); |
|
44 | + } |
|
45 | + |
|
46 | + if (! empty($input['description'])) { |
|
47 | + $args['TKT_description'] = sanitize_text_field($input['description']); |
|
48 | + } |
|
49 | + |
|
50 | + if (! empty($input['price'])) { |
|
51 | + $args['TKT_price'] = floatval($input['price']); |
|
52 | + } |
|
53 | + |
|
54 | + if (! empty($input['startDate'])) { |
|
55 | + $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
56 | + } |
|
57 | + |
|
58 | + if (! empty($input['endDate'])) { |
|
59 | + $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
60 | + } |
|
61 | + |
|
62 | + if (! empty($input['datetimes'])) { |
|
63 | + $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
64 | + } |
|
65 | + |
|
66 | + if (! empty($input['prices'])) { |
|
67 | + $args['prices'] = array_map('sanitize_text_field', (array) $input['prices']); |
|
68 | + } |
|
69 | + |
|
70 | + // Likewise the other fields... |
|
71 | + |
|
72 | + return $args; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Sets the related datetimes for the given ticket. |
|
77 | + * |
|
78 | + * @param EE_Ticket $entity The Ticket instance. |
|
79 | + * @param array $datetimes Array of datetime IDs to relate. |
|
80 | + */ |
|
81 | + public static function setRelatedDatetimes($entity, array $datetimes) |
|
82 | + { |
|
83 | + $relationName = 'Datetime'; |
|
84 | + // Remove all the existing related datetimes |
|
85 | + |
|
86 | + $entity->_remove_relations($relationName); |
|
87 | + // @todo replace loop with single query |
|
88 | + foreach ($datetimes as $ID) { |
|
89 | + $parts = Relay::fromGlobalId($ID); |
|
90 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
91 | + $entity->_add_relation_to( |
|
92 | + $parts['id'], |
|
93 | + $relationName |
|
94 | + ); |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Sets the related prices for the given ticket. |
|
101 | + * |
|
102 | + * @param EE_Ticket $entity The Ticket instance. |
|
103 | + * @param array $prices Array of entity IDs to relate. |
|
104 | + */ |
|
105 | + public static function setRelatedPrices($entity, array $prices) |
|
106 | + { |
|
107 | + $relationName = 'Price'; |
|
108 | + // Remove all the existing related entities |
|
109 | + $entity->_remove_relations($relationName); |
|
110 | + |
|
111 | + // @todo replace loop with single query |
|
112 | + foreach ($prices as $ID) { |
|
113 | + $parts = Relay::fromGlobalId($ID); |
|
114 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
115 | + $entity->_add_relation_to( |
|
116 | + $parts['id'], |
|
117 | + $relationName |
|
118 | + ); |
|
119 | + } |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @param EE_Ticket $ticket_entity |
|
126 | + * @param EEM_Ticket $ticket_model |
|
127 | + * @throws DomainException |
|
128 | + * @throws EE_Error |
|
129 | + * @throws InvalidArgumentException |
|
130 | + * @throws InvalidDataTypeException |
|
131 | + * @throws InvalidInterfaceException |
|
132 | + * @throws ModelConfigurationException |
|
133 | + * @throws ReflectionException |
|
134 | + * @throws RestException |
|
135 | + * @throws UnexpectedEntityException |
|
136 | + * @since $VID:$ |
|
137 | + */ |
|
138 | + public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model) |
|
139 | + { |
|
140 | + $price_model = EEM_Price::instance(); |
|
141 | + $default_prices = $price_model->get_all_default_prices(); |
|
142 | + foreach ($default_prices as $default_price) { |
|
143 | + $default_price->save(); |
|
144 | + $default_price->_add_relation_to($ticket_entity, 'Ticket'); |
|
145 | + } |
|
146 | + } |
|
147 | 147 | } |
@@ -20,78 +20,78 @@ |
||
20 | 20 | class TicketCreate |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * Defines the mutation data modification closure. |
|
25 | - * |
|
26 | - * @param EEM_Ticket $model |
|
27 | - * @param Ticket $type |
|
28 | - * @return callable |
|
29 | - */ |
|
30 | - public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
31 | - { |
|
32 | - /** |
|
33 | - * Creates an entity. |
|
34 | - * |
|
35 | - * @param array $input The input for the mutation |
|
36 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
37 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
38 | - * @return array |
|
39 | - * @throws UserError |
|
40 | - * @throws ReflectionException |
|
41 | - * @throws InvalidArgumentException |
|
42 | - * @throws InvalidInterfaceException |
|
43 | - * @throws InvalidDataTypeException |
|
44 | - * @throws EE_Error |
|
45 | - */ |
|
46 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
23 | + /** |
|
24 | + * Defines the mutation data modification closure. |
|
25 | + * |
|
26 | + * @param EEM_Ticket $model |
|
27 | + * @param Ticket $type |
|
28 | + * @return callable |
|
29 | + */ |
|
30 | + public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
31 | + { |
|
32 | + /** |
|
33 | + * Creates an entity. |
|
34 | + * |
|
35 | + * @param array $input The input for the mutation |
|
36 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
37 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
38 | + * @return array |
|
39 | + * @throws UserError |
|
40 | + * @throws ReflectionException |
|
41 | + * @throws InvalidArgumentException |
|
42 | + * @throws InvalidInterfaceException |
|
43 | + * @throws InvalidDataTypeException |
|
44 | + * @throws EE_Error |
|
45 | + */ |
|
46 | + return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
47 | 47 | |
48 | - /** |
|
49 | - * Stop now if a user isn't allowed to create an entity. |
|
50 | - */ |
|
51 | - if (! current_user_can('ee_edit_events')) { |
|
52 | - // translators: the %1$s is the name of the object being mutated |
|
53 | - throw new UserError( |
|
54 | - sprintf(esc_html__('Sorry, you are not allowed to create %1$s', 'event_espresso'), $type->name()) |
|
55 | - ); |
|
56 | - } |
|
48 | + /** |
|
49 | + * Stop now if a user isn't allowed to create an entity. |
|
50 | + */ |
|
51 | + if (! current_user_can('ee_edit_events')) { |
|
52 | + // translators: the %1$s is the name of the object being mutated |
|
53 | + throw new UserError( |
|
54 | + sprintf(esc_html__('Sorry, you are not allowed to create %1$s', 'event_espresso'), $type->name()) |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | |
58 | - $datetimes = []; |
|
59 | - $prices = []; |
|
58 | + $datetimes = []; |
|
59 | + $prices = []; |
|
60 | 60 | |
61 | - $args = TicketMutation::prepareFields($input); |
|
61 | + $args = TicketMutation::prepareFields($input); |
|
62 | 62 | |
63 | - if (isset($args['datetimes'])) { |
|
64 | - $datetimes = $args['datetimes']; |
|
65 | - unset($args['datetimes']); |
|
66 | - } |
|
67 | - if (isset($args['prices'])) { |
|
68 | - $prices = $args['prices']; |
|
69 | - unset($args['prices']); |
|
70 | - } |
|
63 | + if (isset($args['datetimes'])) { |
|
64 | + $datetimes = $args['datetimes']; |
|
65 | + unset($args['datetimes']); |
|
66 | + } |
|
67 | + if (isset($args['prices'])) { |
|
68 | + $prices = $args['prices']; |
|
69 | + unset($args['prices']); |
|
70 | + } |
|
71 | 71 | |
72 | - $entity = EE_Ticket::new_instance($args); |
|
73 | - $id = $entity->save(); |
|
72 | + $entity = EE_Ticket::new_instance($args); |
|
73 | + $id = $entity->save(); |
|
74 | 74 | |
75 | - if (empty($id)) { |
|
76 | - throw new UserError(esc_html__( |
|
77 | - 'The object failed to create but no error was provided', |
|
78 | - 'event_espresso' |
|
79 | - )); |
|
80 | - } |
|
75 | + if (empty($id)) { |
|
76 | + throw new UserError(esc_html__( |
|
77 | + 'The object failed to create but no error was provided', |
|
78 | + 'event_espresso' |
|
79 | + )); |
|
80 | + } |
|
81 | 81 | |
82 | - if (! empty($datetimes)) { |
|
83 | - TicketMutation::setRelatedDatetimes($entity, $datetimes); |
|
84 | - } |
|
85 | - // if prices are passed. |
|
86 | - if (! empty($prices)) { |
|
87 | - TicketMutation::setRelatedPrices($entity, $prices); |
|
88 | - } else { |
|
89 | - TicketMutation::addDefaultPrices($entity, $model); |
|
90 | - } |
|
82 | + if (! empty($datetimes)) { |
|
83 | + TicketMutation::setRelatedDatetimes($entity, $datetimes); |
|
84 | + } |
|
85 | + // if prices are passed. |
|
86 | + if (! empty($prices)) { |
|
87 | + TicketMutation::setRelatedPrices($entity, $prices); |
|
88 | + } else { |
|
89 | + TicketMutation::addDefaultPrices($entity, $model); |
|
90 | + } |
|
91 | 91 | |
92 | - return [ |
|
93 | - 'id' => $id, |
|
94 | - ]; |
|
95 | - }; |
|
96 | - } |
|
92 | + return [ |
|
93 | + 'id' => $id, |
|
94 | + ]; |
|
95 | + }; |
|
96 | + } |
|
97 | 97 | } |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | * @throws InvalidDataTypeException |
44 | 44 | * @throws EE_Error |
45 | 45 | */ |
46 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
46 | + return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
47 | 47 | |
48 | 48 | /** |
49 | 49 | * Stop now if a user isn't allowed to create an entity. |
50 | 50 | */ |
51 | - if (! current_user_can('ee_edit_events')) { |
|
51 | + if ( ! current_user_can('ee_edit_events')) { |
|
52 | 52 | // translators: the %1$s is the name of the object being mutated |
53 | 53 | throw new UserError( |
54 | 54 | sprintf(esc_html__('Sorry, you are not allowed to create %1$s', 'event_espresso'), $type->name()) |
@@ -79,11 +79,11 @@ discard block |
||
79 | 79 | )); |
80 | 80 | } |
81 | 81 | |
82 | - if (! empty($datetimes)) { |
|
82 | + if ( ! empty($datetimes)) { |
|
83 | 83 | TicketMutation::setRelatedDatetimes($entity, $datetimes); |
84 | 84 | } |
85 | 85 | // if prices are passed. |
86 | - if (! empty($prices)) { |
|
86 | + if ( ! empty($prices)) { |
|
87 | 87 | TicketMutation::setRelatedPrices($entity, $prices); |
88 | 88 | } else { |
89 | 89 | TicketMutation::addDefaultPrices($entity, $model); |