@@ -2,7 +2,6 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace EventEspresso\core\domain\services\graphql\data\mutations; |
4 | 4 | |
5 | -use DomainException; |
|
6 | 5 | use EE_Error; |
7 | 6 | use Exception; |
8 | 7 | use GraphQLRelay\Relay; |
@@ -12,9 +11,6 @@ discard block |
||
12 | 11 | use EE_Ticket; |
13 | 12 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
14 | 13 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
15 | -use EventEspresso\core\exceptions\ModelConfigurationException; |
|
16 | -use EventEspresso\core\exceptions\UnexpectedEntityException; |
|
17 | -use EventEspresso\core\libraries\rest_api\RestException; |
|
18 | 14 | use InvalidArgumentException; |
19 | 15 | use ReflectionException; |
20 | 16 |
@@ -27,188 +27,188 @@ |
||
27 | 27 | class TicketMutation |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Maps the GraphQL input to a format that the model functions can use |
|
32 | - * |
|
33 | - * @param array $input Data coming from the GraphQL mutation query input |
|
34 | - * @return array |
|
35 | - * @throws Exception |
|
36 | - */ |
|
37 | - public static function prepareFields(array $input) |
|
38 | - { |
|
39 | - $args = []; |
|
40 | - |
|
41 | - if (! empty($input['datetimes'])) { |
|
42 | - $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
43 | - } |
|
44 | - |
|
45 | - if (! empty($input['description'])) { |
|
46 | - $args['TKT_description'] = sanitize_text_field($input['description']); |
|
47 | - } |
|
48 | - |
|
49 | - if (! empty($input['endDate'])) { |
|
50 | - $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
51 | - } |
|
52 | - |
|
53 | - if (array_key_exists('isDefault', $input)) { |
|
54 | - $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
55 | - } |
|
56 | - |
|
57 | - if (array_key_exists('isRequired', $input)) { |
|
58 | - $args['TKT_required'] = (bool) $input['isRequired']; |
|
59 | - } |
|
60 | - |
|
61 | - if (array_key_exists('isTaxable', $input)) { |
|
62 | - $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
63 | - } |
|
64 | - |
|
65 | - if (array_key_exists('isTrashed', $input)) { |
|
66 | - $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
67 | - } |
|
68 | - |
|
69 | - if (array_key_exists('max', $input)) { |
|
70 | - $args['TKT_max'] = (int) $input['max']; |
|
71 | - } |
|
72 | - |
|
73 | - if (array_key_exists('min', $input)) { |
|
74 | - $args['TKT_min'] = (int) $input['min']; |
|
75 | - } |
|
76 | - |
|
77 | - if (! empty($input['name'])) { |
|
78 | - $args['TKT_name'] = sanitize_text_field($input['name']); |
|
79 | - } |
|
80 | - |
|
81 | - if (array_key_exists('order', $input)) { |
|
82 | - $args['TKT_order'] = (int) $input['order']; |
|
83 | - } |
|
84 | - |
|
85 | - if (! empty($input['parent'])) { |
|
86 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
87 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
88 | - } |
|
89 | - |
|
90 | - if (! empty($input['price'])) { |
|
91 | - $args['TKT_price'] = (float) $input['price']; |
|
92 | - } |
|
93 | - |
|
94 | - if (! empty($input['prices'])) { |
|
95 | - $args['prices'] = array_map('sanitize_text_field', (array) $input['prices']); |
|
96 | - } |
|
97 | - |
|
98 | - if (array_key_exists('quantity', $input)) { |
|
99 | - $args['TKT_qty'] = (int) $input['quantity']; |
|
100 | - } |
|
101 | - |
|
102 | - if (array_key_exists('reserved', $input)) { |
|
103 | - $args['TKT_reserved'] = (int) $input['reserved']; |
|
104 | - } |
|
105 | - |
|
106 | - if (array_key_exists('reverseCalculate', $input)) { |
|
107 | - $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
108 | - } |
|
109 | - |
|
110 | - if (array_key_exists('row', $input)) { |
|
111 | - $args['TKT_row'] = (int) $input['row']; |
|
112 | - } |
|
113 | - |
|
114 | - if (array_key_exists('sold', $input)) { |
|
115 | - $args['TKT_sold'] = (int) $input['sold']; |
|
116 | - } |
|
117 | - |
|
118 | - if (! empty($input['startDate'])) { |
|
119 | - $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
120 | - } |
|
121 | - |
|
122 | - if (array_key_exists('uses', $input)) { |
|
123 | - $args['TKT_uses'] = (int) $input['uses']; |
|
124 | - } |
|
125 | - |
|
126 | - if (! empty($input['wpUser'])) { |
|
127 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
128 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
129 | - } |
|
130 | - |
|
131 | - return $args; |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * Sets the related datetimes for the given ticket. |
|
137 | - * |
|
138 | - * @param EE_Ticket $entity The Ticket instance. |
|
139 | - * @param array $datetimes Array of datetime IDs to relate. |
|
140 | - * @throws EE_Error |
|
141 | - * @throws InvalidArgumentException |
|
142 | - * @throws InvalidDataTypeException |
|
143 | - * @throws InvalidInterfaceException |
|
144 | - * @throws ReflectionException |
|
145 | - */ |
|
146 | - public static function setRelatedDatetimes($entity, array $datetimes) |
|
147 | - { |
|
148 | - $relationName = 'Datetime'; |
|
149 | - // Remove all the existing related datetimes |
|
150 | - |
|
151 | - $entity->_remove_relations($relationName); |
|
152 | - // @todo replace loop with single query |
|
153 | - foreach ($datetimes as $ID) { |
|
154 | - $parts = Relay::fromGlobalId($ID); |
|
155 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
156 | - $entity->_add_relation_to( |
|
157 | - $parts['id'], |
|
158 | - $relationName |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * Sets the related prices for the given ticket. |
|
167 | - * |
|
168 | - * @param EE_Ticket $entity The Ticket instance. |
|
169 | - * @param array $prices Array of entity IDs to relate. |
|
170 | - * @throws EE_Error |
|
171 | - * @throws InvalidArgumentException |
|
172 | - * @throws InvalidDataTypeException |
|
173 | - * @throws InvalidInterfaceException |
|
174 | - * @throws ReflectionException |
|
175 | - */ |
|
176 | - public static function setRelatedPrices($entity, array $prices) |
|
177 | - { |
|
178 | - $relationName = 'Price'; |
|
179 | - // Remove all the existing related entities |
|
180 | - $entity->_remove_relations($relationName); |
|
181 | - |
|
182 | - // @todo replace loop with single query |
|
183 | - foreach ($prices as $ID) { |
|
184 | - $parts = Relay::fromGlobalId($ID); |
|
185 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
186 | - $entity->_add_relation_to( |
|
187 | - $parts['id'], |
|
188 | - $relationName |
|
189 | - ); |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @param EE_Ticket $ticket_entity |
|
197 | - * @param EEM_Ticket $ticket_model |
|
198 | - * @throws EE_Error |
|
199 | - * @throws InvalidArgumentException |
|
200 | - * @throws InvalidDataTypeException |
|
201 | - * @throws InvalidInterfaceException |
|
202 | - * @throws ReflectionException |
|
203 | - * @since $VID:$ |
|
204 | - */ |
|
205 | - public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model) |
|
206 | - { |
|
207 | - $price_model = EEM_Price::instance(); |
|
208 | - $default_prices = $price_model->get_all_default_prices(); |
|
209 | - foreach ($default_prices as $default_price) { |
|
210 | - $default_price->save(); |
|
211 | - $default_price->_add_relation_to($ticket_entity, 'Ticket'); |
|
212 | - } |
|
213 | - } |
|
30 | + /** |
|
31 | + * Maps the GraphQL input to a format that the model functions can use |
|
32 | + * |
|
33 | + * @param array $input Data coming from the GraphQL mutation query input |
|
34 | + * @return array |
|
35 | + * @throws Exception |
|
36 | + */ |
|
37 | + public static function prepareFields(array $input) |
|
38 | + { |
|
39 | + $args = []; |
|
40 | + |
|
41 | + if (! empty($input['datetimes'])) { |
|
42 | + $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
43 | + } |
|
44 | + |
|
45 | + if (! empty($input['description'])) { |
|
46 | + $args['TKT_description'] = sanitize_text_field($input['description']); |
|
47 | + } |
|
48 | + |
|
49 | + if (! empty($input['endDate'])) { |
|
50 | + $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
51 | + } |
|
52 | + |
|
53 | + if (array_key_exists('isDefault', $input)) { |
|
54 | + $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
55 | + } |
|
56 | + |
|
57 | + if (array_key_exists('isRequired', $input)) { |
|
58 | + $args['TKT_required'] = (bool) $input['isRequired']; |
|
59 | + } |
|
60 | + |
|
61 | + if (array_key_exists('isTaxable', $input)) { |
|
62 | + $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
63 | + } |
|
64 | + |
|
65 | + if (array_key_exists('isTrashed', $input)) { |
|
66 | + $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
67 | + } |
|
68 | + |
|
69 | + if (array_key_exists('max', $input)) { |
|
70 | + $args['TKT_max'] = (int) $input['max']; |
|
71 | + } |
|
72 | + |
|
73 | + if (array_key_exists('min', $input)) { |
|
74 | + $args['TKT_min'] = (int) $input['min']; |
|
75 | + } |
|
76 | + |
|
77 | + if (! empty($input['name'])) { |
|
78 | + $args['TKT_name'] = sanitize_text_field($input['name']); |
|
79 | + } |
|
80 | + |
|
81 | + if (array_key_exists('order', $input)) { |
|
82 | + $args['TKT_order'] = (int) $input['order']; |
|
83 | + } |
|
84 | + |
|
85 | + if (! empty($input['parent'])) { |
|
86 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
87 | + $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
88 | + } |
|
89 | + |
|
90 | + if (! empty($input['price'])) { |
|
91 | + $args['TKT_price'] = (float) $input['price']; |
|
92 | + } |
|
93 | + |
|
94 | + if (! empty($input['prices'])) { |
|
95 | + $args['prices'] = array_map('sanitize_text_field', (array) $input['prices']); |
|
96 | + } |
|
97 | + |
|
98 | + if (array_key_exists('quantity', $input)) { |
|
99 | + $args['TKT_qty'] = (int) $input['quantity']; |
|
100 | + } |
|
101 | + |
|
102 | + if (array_key_exists('reserved', $input)) { |
|
103 | + $args['TKT_reserved'] = (int) $input['reserved']; |
|
104 | + } |
|
105 | + |
|
106 | + if (array_key_exists('reverseCalculate', $input)) { |
|
107 | + $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
108 | + } |
|
109 | + |
|
110 | + if (array_key_exists('row', $input)) { |
|
111 | + $args['TKT_row'] = (int) $input['row']; |
|
112 | + } |
|
113 | + |
|
114 | + if (array_key_exists('sold', $input)) { |
|
115 | + $args['TKT_sold'] = (int) $input['sold']; |
|
116 | + } |
|
117 | + |
|
118 | + if (! empty($input['startDate'])) { |
|
119 | + $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
120 | + } |
|
121 | + |
|
122 | + if (array_key_exists('uses', $input)) { |
|
123 | + $args['TKT_uses'] = (int) $input['uses']; |
|
124 | + } |
|
125 | + |
|
126 | + if (! empty($input['wpUser'])) { |
|
127 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
128 | + $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
129 | + } |
|
130 | + |
|
131 | + return $args; |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * Sets the related datetimes for the given ticket. |
|
137 | + * |
|
138 | + * @param EE_Ticket $entity The Ticket instance. |
|
139 | + * @param array $datetimes Array of datetime IDs to relate. |
|
140 | + * @throws EE_Error |
|
141 | + * @throws InvalidArgumentException |
|
142 | + * @throws InvalidDataTypeException |
|
143 | + * @throws InvalidInterfaceException |
|
144 | + * @throws ReflectionException |
|
145 | + */ |
|
146 | + public static function setRelatedDatetimes($entity, array $datetimes) |
|
147 | + { |
|
148 | + $relationName = 'Datetime'; |
|
149 | + // Remove all the existing related datetimes |
|
150 | + |
|
151 | + $entity->_remove_relations($relationName); |
|
152 | + // @todo replace loop with single query |
|
153 | + foreach ($datetimes as $ID) { |
|
154 | + $parts = Relay::fromGlobalId($ID); |
|
155 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
156 | + $entity->_add_relation_to( |
|
157 | + $parts['id'], |
|
158 | + $relationName |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * Sets the related prices for the given ticket. |
|
167 | + * |
|
168 | + * @param EE_Ticket $entity The Ticket instance. |
|
169 | + * @param array $prices Array of entity IDs to relate. |
|
170 | + * @throws EE_Error |
|
171 | + * @throws InvalidArgumentException |
|
172 | + * @throws InvalidDataTypeException |
|
173 | + * @throws InvalidInterfaceException |
|
174 | + * @throws ReflectionException |
|
175 | + */ |
|
176 | + public static function setRelatedPrices($entity, array $prices) |
|
177 | + { |
|
178 | + $relationName = 'Price'; |
|
179 | + // Remove all the existing related entities |
|
180 | + $entity->_remove_relations($relationName); |
|
181 | + |
|
182 | + // @todo replace loop with single query |
|
183 | + foreach ($prices as $ID) { |
|
184 | + $parts = Relay::fromGlobalId($ID); |
|
185 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
186 | + $entity->_add_relation_to( |
|
187 | + $parts['id'], |
|
188 | + $relationName |
|
189 | + ); |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @param EE_Ticket $ticket_entity |
|
197 | + * @param EEM_Ticket $ticket_model |
|
198 | + * @throws EE_Error |
|
199 | + * @throws InvalidArgumentException |
|
200 | + * @throws InvalidDataTypeException |
|
201 | + * @throws InvalidInterfaceException |
|
202 | + * @throws ReflectionException |
|
203 | + * @since $VID:$ |
|
204 | + */ |
|
205 | + public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model) |
|
206 | + { |
|
207 | + $price_model = EEM_Price::instance(); |
|
208 | + $default_prices = $price_model->get_all_default_prices(); |
|
209 | + foreach ($default_prices as $default_price) { |
|
210 | + $default_price->save(); |
|
211 | + $default_price->_add_relation_to($ticket_entity, 'Ticket'); |
|
212 | + } |
|
213 | + } |
|
214 | 214 | } |
@@ -37,128 +37,128 @@ |
||
37 | 37 | * @since 4.0 |
38 | 38 | */ |
39 | 39 | if (function_exists('espresso_version')) { |
40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | - /** |
|
42 | - * espresso_duplicate_plugin_error |
|
43 | - * displays if more than one version of EE is activated at the same time |
|
44 | - */ |
|
45 | - function espresso_duplicate_plugin_error() |
|
46 | - { |
|
47 | - ?> |
|
40 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + /** |
|
42 | + * espresso_duplicate_plugin_error |
|
43 | + * displays if more than one version of EE is activated at the same time |
|
44 | + */ |
|
45 | + function espresso_duplicate_plugin_error() |
|
46 | + { |
|
47 | + ?> |
|
48 | 48 | <div class="error"> |
49 | 49 | <p> |
50 | 50 | <?php |
51 | - echo esc_html__( |
|
52 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | - 'event_espresso' |
|
54 | - ); ?> |
|
51 | + echo esc_html__( |
|
52 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
53 | + 'event_espresso' |
|
54 | + ); ?> |
|
55 | 55 | </p> |
56 | 56 | </div> |
57 | 57 | <?php |
58 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | - } |
|
60 | - } |
|
61 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
58 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
59 | + } |
|
60 | + } |
|
61 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | 62 | } else { |
63 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | - /** |
|
66 | - * espresso_minimum_php_version_error |
|
67 | - * |
|
68 | - * @return void |
|
69 | - */ |
|
70 | - function espresso_minimum_php_version_error() |
|
71 | - { |
|
72 | - ?> |
|
63 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
64 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | + /** |
|
66 | + * espresso_minimum_php_version_error |
|
67 | + * |
|
68 | + * @return void |
|
69 | + */ |
|
70 | + function espresso_minimum_php_version_error() |
|
71 | + { |
|
72 | + ?> |
|
73 | 73 | <div class="error"> |
74 | 74 | <p> |
75 | 75 | <?php |
76 | - printf( |
|
77 | - esc_html__( |
|
78 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | - 'event_espresso' |
|
80 | - ), |
|
81 | - EE_MIN_PHP_VER_REQUIRED, |
|
82 | - PHP_VERSION, |
|
83 | - '<br/>', |
|
84 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
85 | - ); |
|
86 | - ?> |
|
76 | + printf( |
|
77 | + esc_html__( |
|
78 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
79 | + 'event_espresso' |
|
80 | + ), |
|
81 | + EE_MIN_PHP_VER_REQUIRED, |
|
82 | + PHP_VERSION, |
|
83 | + '<br/>', |
|
84 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
85 | + ); |
|
86 | + ?> |
|
87 | 87 | </p> |
88 | 88 | </div> |
89 | 89 | <?php |
90 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | - } |
|
90 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
91 | + } |
|
92 | 92 | |
93 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | - } else { |
|
95 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.10.5.rc.000'); |
|
105 | - } |
|
93 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
94 | + } else { |
|
95 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.10.5.rc.000'); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * espresso_plugin_activation |
|
109 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
110 | - */ |
|
111 | - function espresso_plugin_activation() |
|
112 | - { |
|
113 | - update_option('ee_espresso_activation', true); |
|
107 | + /** |
|
108 | + * espresso_plugin_activation |
|
109 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
110 | + */ |
|
111 | + function espresso_plugin_activation() |
|
112 | + { |
|
113 | + update_option('ee_espresso_activation', true); |
|
114 | 114 | |
115 | - // Run WP GraphQL activation callback |
|
116 | - if (PHP_VERSION_ID < 70000) { |
|
117 | - return; |
|
118 | - } |
|
119 | - if (! class_exists('WPGraphQL')) { |
|
120 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
121 | - } |
|
122 | - graphql_init()->activate(); |
|
123 | - } |
|
115 | + // Run WP GraphQL activation callback |
|
116 | + if (PHP_VERSION_ID < 70000) { |
|
117 | + return; |
|
118 | + } |
|
119 | + if (! class_exists('WPGraphQL')) { |
|
120 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
121 | + } |
|
122 | + graphql_init()->activate(); |
|
123 | + } |
|
124 | 124 | |
125 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
125 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
126 | 126 | |
127 | - /** |
|
128 | - * espresso_plugin_deactivation |
|
129 | - */ |
|
130 | - function espresso_plugin_deactivation() |
|
131 | - { |
|
132 | - // Run WP GraphQL deactivation callback |
|
133 | - if (PHP_VERSION_ID < 70000) { |
|
134 | - return; |
|
135 | - } |
|
136 | - if (! class_exists('WPGraphQL')) { |
|
137 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
138 | - } |
|
139 | - graphql_init()->deactivate(); |
|
140 | - } |
|
141 | - register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
127 | + /** |
|
128 | + * espresso_plugin_deactivation |
|
129 | + */ |
|
130 | + function espresso_plugin_deactivation() |
|
131 | + { |
|
132 | + // Run WP GraphQL deactivation callback |
|
133 | + if (PHP_VERSION_ID < 70000) { |
|
134 | + return; |
|
135 | + } |
|
136 | + if (! class_exists('WPGraphQL')) { |
|
137 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
138 | + } |
|
139 | + graphql_init()->deactivate(); |
|
140 | + } |
|
141 | + register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
|
142 | 142 | |
143 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
144 | - bootstrap_espresso(); |
|
145 | - } |
|
143 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
144 | + bootstrap_espresso(); |
|
145 | + } |
|
146 | 146 | } |
147 | 147 | if (! function_exists('espresso_deactivate_plugin')) { |
148 | - /** |
|
149 | - * deactivate_plugin |
|
150 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
151 | - * |
|
152 | - * @access public |
|
153 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
154 | - * @return void |
|
155 | - */ |
|
156 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
157 | - { |
|
158 | - if (! function_exists('deactivate_plugins')) { |
|
159 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
160 | - } |
|
161 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
162 | - deactivate_plugins($plugin_basename); |
|
163 | - } |
|
148 | + /** |
|
149 | + * deactivate_plugin |
|
150 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
151 | + * |
|
152 | + * @access public |
|
153 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
154 | + * @return void |
|
155 | + */ |
|
156 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
157 | + { |
|
158 | + if (! function_exists('deactivate_plugins')) { |
|
159 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
160 | + } |
|
161 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
162 | + deactivate_plugins($plugin_basename); |
|
163 | + } |
|
164 | 164 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * @since 4.0 |
38 | 38 | */ |
39 | 39 | if (function_exists('espresso_version')) { |
40 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
40 | + if ( ! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | 41 | /** |
42 | 42 | * espresso_duplicate_plugin_error |
43 | 43 | * displays if more than one version of EE is activated at the same time |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
62 | 62 | } else { |
63 | 63 | define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
64 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
64 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
65 | 65 | /** |
66 | 66 | * espresso_minimum_php_version_error |
67 | 67 | * |
@@ -116,8 +116,8 @@ discard block |
||
116 | 116 | if (PHP_VERSION_ID < 70000) { |
117 | 117 | return; |
118 | 118 | } |
119 | - if (! class_exists('WPGraphQL')) { |
|
120 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
119 | + if ( ! class_exists('WPGraphQL')) { |
|
120 | + require_once EE_THIRD_PARTY.'wp-graphql/wp-graphql.php'; |
|
121 | 121 | } |
122 | 122 | graphql_init()->activate(); |
123 | 123 | } |
@@ -133,18 +133,18 @@ discard block |
||
133 | 133 | if (PHP_VERSION_ID < 70000) { |
134 | 134 | return; |
135 | 135 | } |
136 | - if (! class_exists('WPGraphQL')) { |
|
137 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
136 | + if ( ! class_exists('WPGraphQL')) { |
|
137 | + require_once EE_THIRD_PARTY.'wp-graphql/wp-graphql.php'; |
|
138 | 138 | } |
139 | 139 | graphql_init()->deactivate(); |
140 | 140 | } |
141 | 141 | register_deactivation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_deactivation'); |
142 | 142 | |
143 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
143 | + require_once __DIR__.'/core/bootstrap_espresso.php'; |
|
144 | 144 | bootstrap_espresso(); |
145 | 145 | } |
146 | 146 | } |
147 | -if (! function_exists('espresso_deactivate_plugin')) { |
|
147 | +if ( ! function_exists('espresso_deactivate_plugin')) { |
|
148 | 148 | /** |
149 | 149 | * deactivate_plugin |
150 | 150 | * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
@@ -155,8 +155,8 @@ discard block |
||
155 | 155 | */ |
156 | 156 | function espresso_deactivate_plugin($plugin_basename = '') |
157 | 157 | { |
158 | - if (! function_exists('deactivate_plugins')) { |
|
159 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
158 | + if ( ! function_exists('deactivate_plugins')) { |
|
159 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
160 | 160 | } |
161 | 161 | unset($_GET['activate'], $_REQUEST['activate']); |
162 | 162 | deactivate_plugins($plugin_basename); |
@@ -35,213 +35,213 @@ discard block |
||
35 | 35 | class AdvancedEditorData |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * @var string $namespace The graphql namespace/prefix. |
|
40 | - */ |
|
41 | - protected $namespace = 'Espresso'; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var EE_Event |
|
45 | - */ |
|
46 | - protected $event; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var EE_Admin_Config |
|
50 | - */ |
|
51 | - protected $admin_config; |
|
52 | - /** |
|
53 | - * @var EEM_Datetime $datetime_model |
|
54 | - */ |
|
55 | - protected $datetime_model; |
|
56 | - /** |
|
57 | - * @var EEM_Price $price_model |
|
58 | - */ |
|
59 | - protected $price_model; |
|
60 | - /** |
|
61 | - * @var EEM_Ticket $ticket_model |
|
62 | - */ |
|
63 | - protected $ticket_model; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * AdvancedEditorAdminForm constructor. |
|
68 | - * |
|
69 | - * @param EE_Event $event |
|
70 | - * @param EE_Admin_Config $admin_config |
|
71 | - * @param EEM_Datetime $datetime_model |
|
72 | - * @param EEM_Price $price_model |
|
73 | - * @param EEM_Ticket $ticket_model |
|
74 | - */ |
|
75 | - public function __construct( |
|
76 | - EE_Event $event, |
|
77 | - EE_Admin_Config $admin_config, |
|
78 | - EEM_Datetime $datetime_model, |
|
79 | - EEM_Price $price_model, |
|
80 | - EEM_Ticket $ticket_model |
|
81 | - ) { |
|
82 | - $this->event = $event; |
|
83 | - $this->admin_config = $admin_config; |
|
84 | - $this->datetime_model = $datetime_model; |
|
85 | - $this->price_model = $price_model; |
|
86 | - $this->ticket_model = $ticket_model; |
|
87 | - add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @throws EE_Error |
|
93 | - * @throws InvalidArgumentException |
|
94 | - * @throws InvalidDataTypeException |
|
95 | - * @throws InvalidInterfaceException |
|
96 | - * @throws ModelConfigurationException |
|
97 | - * @throws ReflectionException |
|
98 | - * @throws UnexpectedEntityException |
|
99 | - * @throws DomainException |
|
100 | - * @since $VID:$ |
|
101 | - */ |
|
102 | - public function loadScriptsStyles() |
|
103 | - { |
|
104 | - if ($this->admin_config->useAdvancedEditor()) { |
|
105 | - $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
|
106 | - if (! $eventId) { |
|
107 | - global $post; |
|
108 | - $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
|
109 | - $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
|
110 | - ? $post->ID |
|
111 | - : $eventId; |
|
112 | - } |
|
113 | - if ($eventId) { |
|
114 | - $data = $this->getEditorData($eventId); |
|
115 | - $data = wp_json_encode($data); |
|
116 | - add_action( |
|
117 | - 'admin_footer', |
|
118 | - static function () use ($data) { |
|
119 | - wp_add_inline_script( |
|
120 | - EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
|
121 | - " |
|
38 | + /** |
|
39 | + * @var string $namespace The graphql namespace/prefix. |
|
40 | + */ |
|
41 | + protected $namespace = 'Espresso'; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var EE_Event |
|
45 | + */ |
|
46 | + protected $event; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var EE_Admin_Config |
|
50 | + */ |
|
51 | + protected $admin_config; |
|
52 | + /** |
|
53 | + * @var EEM_Datetime $datetime_model |
|
54 | + */ |
|
55 | + protected $datetime_model; |
|
56 | + /** |
|
57 | + * @var EEM_Price $price_model |
|
58 | + */ |
|
59 | + protected $price_model; |
|
60 | + /** |
|
61 | + * @var EEM_Ticket $ticket_model |
|
62 | + */ |
|
63 | + protected $ticket_model; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * AdvancedEditorAdminForm constructor. |
|
68 | + * |
|
69 | + * @param EE_Event $event |
|
70 | + * @param EE_Admin_Config $admin_config |
|
71 | + * @param EEM_Datetime $datetime_model |
|
72 | + * @param EEM_Price $price_model |
|
73 | + * @param EEM_Ticket $ticket_model |
|
74 | + */ |
|
75 | + public function __construct( |
|
76 | + EE_Event $event, |
|
77 | + EE_Admin_Config $admin_config, |
|
78 | + EEM_Datetime $datetime_model, |
|
79 | + EEM_Price $price_model, |
|
80 | + EEM_Ticket $ticket_model |
|
81 | + ) { |
|
82 | + $this->event = $event; |
|
83 | + $this->admin_config = $admin_config; |
|
84 | + $this->datetime_model = $datetime_model; |
|
85 | + $this->price_model = $price_model; |
|
86 | + $this->ticket_model = $ticket_model; |
|
87 | + add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @throws EE_Error |
|
93 | + * @throws InvalidArgumentException |
|
94 | + * @throws InvalidDataTypeException |
|
95 | + * @throws InvalidInterfaceException |
|
96 | + * @throws ModelConfigurationException |
|
97 | + * @throws ReflectionException |
|
98 | + * @throws UnexpectedEntityException |
|
99 | + * @throws DomainException |
|
100 | + * @since $VID:$ |
|
101 | + */ |
|
102 | + public function loadScriptsStyles() |
|
103 | + { |
|
104 | + if ($this->admin_config->useAdvancedEditor()) { |
|
105 | + $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
|
106 | + if (! $eventId) { |
|
107 | + global $post; |
|
108 | + $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
|
109 | + $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
|
110 | + ? $post->ID |
|
111 | + : $eventId; |
|
112 | + } |
|
113 | + if ($eventId) { |
|
114 | + $data = $this->getEditorData($eventId); |
|
115 | + $data = wp_json_encode($data); |
|
116 | + add_action( |
|
117 | + 'admin_footer', |
|
118 | + static function () use ($data) { |
|
119 | + wp_add_inline_script( |
|
120 | + EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
|
121 | + " |
|
122 | 122 | var eeEditorData={$data}; |
123 | 123 | ", |
124 | - 'before' |
|
125 | - ); |
|
126 | - } |
|
127 | - ); |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @param int $eventId |
|
135 | - * @return array |
|
136 | - * @throws EE_Error |
|
137 | - * @throws InvalidDataTypeException |
|
138 | - * @throws InvalidInterfaceException |
|
139 | - * @throws ModelConfigurationException |
|
140 | - * @throws UnexpectedEntityException |
|
141 | - * @throws InvalidArgumentException |
|
142 | - * @throws ReflectionException |
|
143 | - * @throws DomainException |
|
144 | - * @since $VID:$ |
|
145 | - */ |
|
146 | - protected function getEditorData($eventId) |
|
147 | - { |
|
148 | - $event = $this->getEventGraphQLData($eventId); |
|
149 | - $event['dbId'] = $eventId; |
|
150 | - |
|
151 | - $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
152 | - $graphqlEndpoint = esc_url($graphqlEndpoint); |
|
153 | - |
|
154 | - $currentUser = $this->getGraphQLCurrentUser(); |
|
155 | - |
|
156 | - $generalSettings = $this->getGraphQLGeneralSettings(); |
|
157 | - |
|
158 | - $i18n = self::getJedLocaleData('event_espresso'); |
|
159 | - |
|
160 | - $assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
161 | - |
|
162 | - return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl'); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param int $eventId |
|
168 | - * @return array |
|
169 | - * @since $VID:$ |
|
170 | - */ |
|
171 | - protected function getEventGraphQLData($eventId) |
|
172 | - { |
|
173 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
174 | - |
|
175 | - if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
176 | - $this->addDefaultEntities($eventId); |
|
177 | - $datetimes = $this->getGraphQLDatetimes($eventId); |
|
178 | - } |
|
179 | - |
|
180 | - if (! empty($datetimes['nodes'])) { |
|
181 | - $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
182 | - |
|
183 | - if (! empty($datetimeIn)) { |
|
184 | - $tickets = $this->getGraphQLTickets($datetimeIn); |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - if (! empty($tickets['nodes'])) { |
|
189 | - $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
190 | - |
|
191 | - if (! empty($ticketIn)) { |
|
192 | - $prices = $this->getGraphQLPrices($ticketIn); |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - $priceTypes = $this->getGraphQLPriceTypes(); |
|
197 | - |
|
198 | - $relations = $this->getRelationalData($eventId); |
|
199 | - |
|
200 | - return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * @param int $eventId |
|
205 | - * @throws DomainException |
|
206 | - * @throws EE_Error |
|
207 | - * @throws InvalidArgumentException |
|
208 | - * @throws InvalidDataTypeException |
|
209 | - * @throws InvalidInterfaceException |
|
210 | - * @throws ModelConfigurationException |
|
211 | - * @throws ReflectionException |
|
212 | - * @throws UnexpectedEntityException |
|
213 | - * @since $VID:$ |
|
214 | - */ |
|
215 | - protected function addDefaultEntities($eventId) |
|
216 | - { |
|
217 | - $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
218 | - if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
219 | - $default_date = $default_dates[0]; |
|
220 | - $default_date->save(); |
|
221 | - $default_date->_add_relation_to($eventId, 'Event'); |
|
222 | - $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
223 | - $default_prices = $this->price_model->get_all_default_prices(); |
|
224 | - foreach ($default_tickets as $default_ticket) { |
|
225 | - $default_ticket->save(); |
|
226 | - $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
227 | - foreach ($default_prices as $default_price) { |
|
228 | - $default_price->save(); |
|
229 | - $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
230 | - } |
|
231 | - } |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @param int $eventId |
|
238 | - * @return array|null |
|
239 | - * @since $VID:$ |
|
240 | - */ |
|
241 | - protected function getGraphQLDatetimes($eventId) |
|
242 | - { |
|
243 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
244 | - $query = <<<QUERY |
|
124 | + 'before' |
|
125 | + ); |
|
126 | + } |
|
127 | + ); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @param int $eventId |
|
135 | + * @return array |
|
136 | + * @throws EE_Error |
|
137 | + * @throws InvalidDataTypeException |
|
138 | + * @throws InvalidInterfaceException |
|
139 | + * @throws ModelConfigurationException |
|
140 | + * @throws UnexpectedEntityException |
|
141 | + * @throws InvalidArgumentException |
|
142 | + * @throws ReflectionException |
|
143 | + * @throws DomainException |
|
144 | + * @since $VID:$ |
|
145 | + */ |
|
146 | + protected function getEditorData($eventId) |
|
147 | + { |
|
148 | + $event = $this->getEventGraphQLData($eventId); |
|
149 | + $event['dbId'] = $eventId; |
|
150 | + |
|
151 | + $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
152 | + $graphqlEndpoint = esc_url($graphqlEndpoint); |
|
153 | + |
|
154 | + $currentUser = $this->getGraphQLCurrentUser(); |
|
155 | + |
|
156 | + $generalSettings = $this->getGraphQLGeneralSettings(); |
|
157 | + |
|
158 | + $i18n = self::getJedLocaleData('event_espresso'); |
|
159 | + |
|
160 | + $assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
161 | + |
|
162 | + return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl'); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param int $eventId |
|
168 | + * @return array |
|
169 | + * @since $VID:$ |
|
170 | + */ |
|
171 | + protected function getEventGraphQLData($eventId) |
|
172 | + { |
|
173 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
174 | + |
|
175 | + if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
176 | + $this->addDefaultEntities($eventId); |
|
177 | + $datetimes = $this->getGraphQLDatetimes($eventId); |
|
178 | + } |
|
179 | + |
|
180 | + if (! empty($datetimes['nodes'])) { |
|
181 | + $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
182 | + |
|
183 | + if (! empty($datetimeIn)) { |
|
184 | + $tickets = $this->getGraphQLTickets($datetimeIn); |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + if (! empty($tickets['nodes'])) { |
|
189 | + $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
190 | + |
|
191 | + if (! empty($ticketIn)) { |
|
192 | + $prices = $this->getGraphQLPrices($ticketIn); |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + $priceTypes = $this->getGraphQLPriceTypes(); |
|
197 | + |
|
198 | + $relations = $this->getRelationalData($eventId); |
|
199 | + |
|
200 | + return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * @param int $eventId |
|
205 | + * @throws DomainException |
|
206 | + * @throws EE_Error |
|
207 | + * @throws InvalidArgumentException |
|
208 | + * @throws InvalidDataTypeException |
|
209 | + * @throws InvalidInterfaceException |
|
210 | + * @throws ModelConfigurationException |
|
211 | + * @throws ReflectionException |
|
212 | + * @throws UnexpectedEntityException |
|
213 | + * @since $VID:$ |
|
214 | + */ |
|
215 | + protected function addDefaultEntities($eventId) |
|
216 | + { |
|
217 | + $default_dates = $this->datetime_model->create_new_blank_datetime(); |
|
218 | + if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) { |
|
219 | + $default_date = $default_dates[0]; |
|
220 | + $default_date->save(); |
|
221 | + $default_date->_add_relation_to($eventId, 'Event'); |
|
222 | + $default_tickets = $this->ticket_model->get_all_default_tickets(); |
|
223 | + $default_prices = $this->price_model->get_all_default_prices(); |
|
224 | + foreach ($default_tickets as $default_ticket) { |
|
225 | + $default_ticket->save(); |
|
226 | + $default_ticket->_add_relation_to($default_date, 'Datetime'); |
|
227 | + foreach ($default_prices as $default_price) { |
|
228 | + $default_price->save(); |
|
229 | + $default_price->_add_relation_to($default_ticket, 'Ticket'); |
|
230 | + } |
|
231 | + } |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @param int $eventId |
|
238 | + * @return array|null |
|
239 | + * @since $VID:$ |
|
240 | + */ |
|
241 | + protected function getGraphQLDatetimes($eventId) |
|
242 | + { |
|
243 | + $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
244 | + $query = <<<QUERY |
|
245 | 245 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
246 | 246 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
247 | 247 | nodes { |
@@ -270,31 +270,31 @@ discard block |
||
270 | 270 | } |
271 | 271 | } |
272 | 272 | QUERY; |
273 | - $data = [ |
|
274 | - 'operation_name' => 'GET_DATETIMES', |
|
275 | - 'variables' => [ |
|
276 | - 'first' => 100, |
|
277 | - 'where' => [ |
|
278 | - 'eventId' => $eventId, |
|
279 | - ], |
|
280 | - ], |
|
281 | - 'query' => $query, |
|
282 | - ]; |
|
283 | - |
|
284 | - $responseData = $this->makeGraphQLRequest($data); |
|
285 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * @param array $datetimeIn |
|
291 | - * @return array|null |
|
292 | - * @since $VID:$ |
|
293 | - */ |
|
294 | - protected function getGraphQLTickets(array $datetimeIn) |
|
295 | - { |
|
296 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
297 | - $query = <<<QUERY |
|
273 | + $data = [ |
|
274 | + 'operation_name' => 'GET_DATETIMES', |
|
275 | + 'variables' => [ |
|
276 | + 'first' => 100, |
|
277 | + 'where' => [ |
|
278 | + 'eventId' => $eventId, |
|
279 | + ], |
|
280 | + ], |
|
281 | + 'query' => $query, |
|
282 | + ]; |
|
283 | + |
|
284 | + $responseData = $this->makeGraphQLRequest($data); |
|
285 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * @param array $datetimeIn |
|
291 | + * @return array|null |
|
292 | + * @since $VID:$ |
|
293 | + */ |
|
294 | + protected function getGraphQLTickets(array $datetimeIn) |
|
295 | + { |
|
296 | + $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
297 | + $query = <<<QUERY |
|
298 | 298 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
299 | 299 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
300 | 300 | nodes { |
@@ -330,31 +330,31 @@ discard block |
||
330 | 330 | } |
331 | 331 | } |
332 | 332 | QUERY; |
333 | - $data = [ |
|
334 | - 'operation_name' => 'GET_TICKETS', |
|
335 | - 'variables' => [ |
|
336 | - 'first' => 100, |
|
337 | - 'where' => [ |
|
338 | - 'datetimeIn' => $datetimeIn, |
|
339 | - ], |
|
340 | - ], |
|
341 | - 'query' => $query, |
|
342 | - ]; |
|
343 | - |
|
344 | - $responseData = $this->makeGraphQLRequest($data); |
|
345 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @param array $ticketIn |
|
351 | - * @return array|null |
|
352 | - * @since $VID:$ |
|
353 | - */ |
|
354 | - protected function getGraphQLPrices(array $ticketIn) |
|
355 | - { |
|
356 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
357 | - $query = <<<QUERY |
|
333 | + $data = [ |
|
334 | + 'operation_name' => 'GET_TICKETS', |
|
335 | + 'variables' => [ |
|
336 | + 'first' => 100, |
|
337 | + 'where' => [ |
|
338 | + 'datetimeIn' => $datetimeIn, |
|
339 | + ], |
|
340 | + ], |
|
341 | + 'query' => $query, |
|
342 | + ]; |
|
343 | + |
|
344 | + $responseData = $this->makeGraphQLRequest($data); |
|
345 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @param array $ticketIn |
|
351 | + * @return array|null |
|
352 | + * @since $VID:$ |
|
353 | + */ |
|
354 | + protected function getGraphQLPrices(array $ticketIn) |
|
355 | + { |
|
356 | + $field_key = lcfirst($this->namespace) . 'Prices'; |
|
357 | + $query = <<<QUERY |
|
358 | 358 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
359 | 359 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
360 | 360 | nodes { |
@@ -378,30 +378,30 @@ discard block |
||
378 | 378 | } |
379 | 379 | } |
380 | 380 | QUERY; |
381 | - $data = [ |
|
382 | - 'operation_name' => 'GET_PRICES', |
|
383 | - 'variables' => [ |
|
384 | - 'first' => 100, |
|
385 | - 'where' => [ |
|
386 | - 'ticketIn' => $ticketIn, |
|
387 | - ], |
|
388 | - ], |
|
389 | - 'query' => $query, |
|
390 | - ]; |
|
391 | - |
|
392 | - $responseData = $this->makeGraphQLRequest($data); |
|
393 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * @return array|null |
|
399 | - * @since $VID:$ |
|
400 | - */ |
|
401 | - protected function getGraphQLPriceTypes() |
|
402 | - { |
|
403 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
404 | - $query = <<<QUERY |
|
381 | + $data = [ |
|
382 | + 'operation_name' => 'GET_PRICES', |
|
383 | + 'variables' => [ |
|
384 | + 'first' => 100, |
|
385 | + 'where' => [ |
|
386 | + 'ticketIn' => $ticketIn, |
|
387 | + ], |
|
388 | + ], |
|
389 | + 'query' => $query, |
|
390 | + ]; |
|
391 | + |
|
392 | + $responseData = $this->makeGraphQLRequest($data); |
|
393 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * @return array|null |
|
399 | + * @since $VID:$ |
|
400 | + */ |
|
401 | + protected function getGraphQLPriceTypes() |
|
402 | + { |
|
403 | + $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
404 | + $query = <<<QUERY |
|
405 | 405 | query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
406 | 406 | {$field_key}(first: \$first, last: \$last) { |
407 | 407 | nodes { |
@@ -422,27 +422,27 @@ discard block |
||
422 | 422 | } |
423 | 423 | } |
424 | 424 | QUERY; |
425 | - $data = [ |
|
426 | - 'operation_name' => 'GET_PRICE_TYPES', |
|
427 | - 'variables' => [ |
|
428 | - 'first' => 100, |
|
429 | - ], |
|
430 | - 'query' => $query, |
|
431 | - ]; |
|
432 | - |
|
433 | - $responseData = $this->makeGraphQLRequest($data); |
|
434 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * @return array|null |
|
440 | - * @since $VID:$ |
|
441 | - */ |
|
442 | - protected function getGraphQLCurrentUser() |
|
443 | - { |
|
444 | - $field_key = 'viewer'; |
|
445 | - $query = <<<QUERY |
|
425 | + $data = [ |
|
426 | + 'operation_name' => 'GET_PRICE_TYPES', |
|
427 | + 'variables' => [ |
|
428 | + 'first' => 100, |
|
429 | + ], |
|
430 | + 'query' => $query, |
|
431 | + ]; |
|
432 | + |
|
433 | + $responseData = $this->makeGraphQLRequest($data); |
|
434 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * @return array|null |
|
440 | + * @since $VID:$ |
|
441 | + */ |
|
442 | + protected function getGraphQLCurrentUser() |
|
443 | + { |
|
444 | + $field_key = 'viewer'; |
|
445 | + $query = <<<QUERY |
|
446 | 446 | query GET_CURRENT_USER { |
447 | 447 | {$field_key} { |
448 | 448 | description |
@@ -460,24 +460,24 @@ discard block |
||
460 | 460 | } |
461 | 461 | } |
462 | 462 | QUERY; |
463 | - $data = [ |
|
464 | - 'operation_name' => 'GET_CURRENT_USER', |
|
465 | - 'query' => $query, |
|
466 | - ]; |
|
467 | - |
|
468 | - $responseData = $this->makeGraphQLRequest($data); |
|
469 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - /** |
|
474 | - * @return array|null |
|
475 | - * @since $VID:$ |
|
476 | - */ |
|
477 | - protected function getGraphQLGeneralSettings() |
|
478 | - { |
|
479 | - $field_key = 'generalSettings'; |
|
480 | - $query = <<<QUERY |
|
463 | + $data = [ |
|
464 | + 'operation_name' => 'GET_CURRENT_USER', |
|
465 | + 'query' => $query, |
|
466 | + ]; |
|
467 | + |
|
468 | + $responseData = $this->makeGraphQLRequest($data); |
|
469 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + /** |
|
474 | + * @return array|null |
|
475 | + * @since $VID:$ |
|
476 | + */ |
|
477 | + protected function getGraphQLGeneralSettings() |
|
478 | + { |
|
479 | + $field_key = 'generalSettings'; |
|
480 | + $query = <<<QUERY |
|
481 | 481 | query GET_GENERAL_SETTINGS { |
482 | 482 | {$field_key} { |
483 | 483 | dateFormat |
@@ -487,185 +487,185 @@ discard block |
||
487 | 487 | } |
488 | 488 | } |
489 | 489 | QUERY; |
490 | - $data = [ |
|
491 | - 'operation_name' => 'GET_CURRENT_USER', |
|
492 | - 'query' => $query, |
|
493 | - ]; |
|
494 | - |
|
495 | - $responseData = $this->makeGraphQLRequest($data); |
|
496 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @param array $data |
|
502 | - * @return array |
|
503 | - * @since $VID:$ |
|
504 | - */ |
|
505 | - protected function makeGraphQLRequest($data) |
|
506 | - { |
|
507 | - try { |
|
508 | - $response = graphql($data); |
|
509 | - if (!empty($response['data'])) { |
|
510 | - return $response['data']; |
|
511 | - } |
|
512 | - return null; |
|
513 | - } catch (\Exception $e) { |
|
514 | - // do something with the errors thrown |
|
515 | - return null; |
|
516 | - } |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
522 | - * @param array $args The inputArgs on the field |
|
523 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
524 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
525 | - * @return string |
|
526 | - * @throws EE_Error |
|
527 | - * @throws Exception |
|
528 | - * @throws InvalidArgumentException |
|
529 | - * @throws InvalidDataTypeException |
|
530 | - * @throws InvalidInterfaceException |
|
531 | - * @throws ReflectionException |
|
532 | - * @throws UserError |
|
533 | - * @throws UnexpectedEntityException |
|
534 | - * @since $VID:$ |
|
535 | - */ |
|
536 | - public static function getRelationalData($eventId) |
|
537 | - { |
|
538 | - $data = [ |
|
539 | - 'datetimes' => [], |
|
540 | - 'tickets' => [], |
|
541 | - 'prices' => [], |
|
542 | - ]; |
|
543 | - |
|
544 | - $eem_datetime = EEM_Datetime::instance(); |
|
545 | - $eem_ticket = EEM_Ticket::instance(); |
|
546 | - $eem_price = EEM_Price::instance(); |
|
547 | - $eem_price_type = EEM_Price_Type::instance(); |
|
548 | - |
|
549 | - // PROCESS DATETIMES |
|
550 | - $related_models = [ |
|
551 | - 'tickets' => $eem_ticket, |
|
552 | - ]; |
|
553 | - // Get the IDs of event datetimes. |
|
554 | - $datetimeIds = $eem_datetime->get_col([ |
|
555 | - [ |
|
556 | - 'EVT_ID' => $eventId, |
|
557 | - ], |
|
558 | - 'default_where_conditions' => 'minimum', |
|
559 | - ]); |
|
560 | - foreach ($datetimeIds as $datetimeId) { |
|
561 | - $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
|
562 | - foreach ($related_models as $key => $model) { |
|
563 | - // Get the IDs of related entities for the datetime ID. |
|
564 | - $Ids = $model->get_col([ |
|
565 | - [ |
|
566 | - 'Datetime.DTT_ID' => $datetimeId, |
|
567 | - ], |
|
568 | - 'default_where_conditions' => 'minimum', |
|
569 | - ]); |
|
570 | - $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
571 | - } |
|
572 | - } |
|
573 | - |
|
574 | - // PROCESS TICKETS |
|
575 | - $related_models = [ |
|
576 | - 'datetimes' => $eem_datetime, |
|
577 | - 'prices' => $eem_price, |
|
578 | - ]; |
|
579 | - // Get the IDs of all datetime tickets. |
|
580 | - $ticketIds = $eem_ticket->get_col([ |
|
581 | - [ |
|
582 | - 'Datetime.DTT_ID' => ['IN', $datetimeIds], |
|
583 | - ], |
|
584 | - 'default_where_conditions' => 'minimum', |
|
585 | - ]); |
|
586 | - foreach ($ticketIds as $ticketId) { |
|
587 | - $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
588 | - |
|
589 | - foreach ($related_models as $key => $model) { |
|
590 | - // Get the IDs of related entities for the ticket ID. |
|
591 | - $Ids = $model->get_col([ |
|
592 | - [ |
|
593 | - 'Ticket.TKT_ID' => $ticketId, |
|
594 | - ], |
|
595 | - 'default_where_conditions' => 'minimum', |
|
596 | - ]); |
|
597 | - $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
598 | - } |
|
599 | - } |
|
600 | - |
|
601 | - // PROCESS PRICES |
|
602 | - $related_models = [ |
|
603 | - 'tickets' => $eem_ticket, |
|
604 | - 'priceTypes' => $eem_price_type, |
|
605 | - ]; |
|
606 | - // Get the IDs of all ticket prices. |
|
607 | - $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['IN', $ticketIds]]]); |
|
608 | - foreach ($priceIds as $priceId) { |
|
609 | - $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
610 | - |
|
611 | - foreach ($related_models as $key => $model) { |
|
612 | - // Get the IDs of related entities for the price ID. |
|
613 | - $Ids = $model->get_col([ |
|
614 | - [ |
|
615 | - 'Price.PRC_ID' => $priceId, |
|
616 | - ], |
|
617 | - 'default_where_conditions' => 'minimum', |
|
618 | - ]); |
|
619 | - $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
620 | - } |
|
621 | - } |
|
622 | - |
|
623 | - return $data; |
|
624 | - } |
|
625 | - |
|
626 | - /** |
|
627 | - * Convert the DB ID into GID |
|
628 | - * |
|
629 | - * @param string $type |
|
630 | - * @param int|int[] $ID |
|
631 | - * @return mixed |
|
632 | - */ |
|
633 | - public static function convertToGlobalId($type, $ID) |
|
634 | - { |
|
635 | - if (is_array($ID)) { |
|
636 | - return array_map(function ($id) use ($type) { |
|
637 | - return self::convertToGlobalId($type, $id); |
|
638 | - }, $ID); |
|
639 | - } |
|
640 | - return Relay::toGlobalId($type, $ID); |
|
641 | - } |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * Returns Jed-formatted localization data. |
|
646 | - * |
|
647 | - * @param string $domain Translation domain. |
|
648 | - * @return array |
|
649 | - */ |
|
650 | - public static function getJedLocaleData($domain) |
|
651 | - { |
|
652 | - $translations = get_translations_for_domain($domain); |
|
653 | - |
|
654 | - $locale = array( |
|
655 | - '' => array( |
|
656 | - 'domain' => $domain, |
|
657 | - 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
658 | - ), |
|
659 | - ); |
|
660 | - |
|
661 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
662 | - $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
663 | - } |
|
664 | - |
|
665 | - foreach ($translations->entries as $msgid => $entry) { |
|
666 | - $locale[ $msgid ] = $entry->translations; |
|
667 | - } |
|
668 | - |
|
669 | - return $locale; |
|
670 | - } |
|
490 | + $data = [ |
|
491 | + 'operation_name' => 'GET_CURRENT_USER', |
|
492 | + 'query' => $query, |
|
493 | + ]; |
|
494 | + |
|
495 | + $responseData = $this->makeGraphQLRequest($data); |
|
496 | + return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @param array $data |
|
502 | + * @return array |
|
503 | + * @since $VID:$ |
|
504 | + */ |
|
505 | + protected function makeGraphQLRequest($data) |
|
506 | + { |
|
507 | + try { |
|
508 | + $response = graphql($data); |
|
509 | + if (!empty($response['data'])) { |
|
510 | + return $response['data']; |
|
511 | + } |
|
512 | + return null; |
|
513 | + } catch (\Exception $e) { |
|
514 | + // do something with the errors thrown |
|
515 | + return null; |
|
516 | + } |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
522 | + * @param array $args The inputArgs on the field |
|
523 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
524 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
525 | + * @return string |
|
526 | + * @throws EE_Error |
|
527 | + * @throws Exception |
|
528 | + * @throws InvalidArgumentException |
|
529 | + * @throws InvalidDataTypeException |
|
530 | + * @throws InvalidInterfaceException |
|
531 | + * @throws ReflectionException |
|
532 | + * @throws UserError |
|
533 | + * @throws UnexpectedEntityException |
|
534 | + * @since $VID:$ |
|
535 | + */ |
|
536 | + public static function getRelationalData($eventId) |
|
537 | + { |
|
538 | + $data = [ |
|
539 | + 'datetimes' => [], |
|
540 | + 'tickets' => [], |
|
541 | + 'prices' => [], |
|
542 | + ]; |
|
543 | + |
|
544 | + $eem_datetime = EEM_Datetime::instance(); |
|
545 | + $eem_ticket = EEM_Ticket::instance(); |
|
546 | + $eem_price = EEM_Price::instance(); |
|
547 | + $eem_price_type = EEM_Price_Type::instance(); |
|
548 | + |
|
549 | + // PROCESS DATETIMES |
|
550 | + $related_models = [ |
|
551 | + 'tickets' => $eem_ticket, |
|
552 | + ]; |
|
553 | + // Get the IDs of event datetimes. |
|
554 | + $datetimeIds = $eem_datetime->get_col([ |
|
555 | + [ |
|
556 | + 'EVT_ID' => $eventId, |
|
557 | + ], |
|
558 | + 'default_where_conditions' => 'minimum', |
|
559 | + ]); |
|
560 | + foreach ($datetimeIds as $datetimeId) { |
|
561 | + $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId); |
|
562 | + foreach ($related_models as $key => $model) { |
|
563 | + // Get the IDs of related entities for the datetime ID. |
|
564 | + $Ids = $model->get_col([ |
|
565 | + [ |
|
566 | + 'Datetime.DTT_ID' => $datetimeId, |
|
567 | + ], |
|
568 | + 'default_where_conditions' => 'minimum', |
|
569 | + ]); |
|
570 | + $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
571 | + } |
|
572 | + } |
|
573 | + |
|
574 | + // PROCESS TICKETS |
|
575 | + $related_models = [ |
|
576 | + 'datetimes' => $eem_datetime, |
|
577 | + 'prices' => $eem_price, |
|
578 | + ]; |
|
579 | + // Get the IDs of all datetime tickets. |
|
580 | + $ticketIds = $eem_ticket->get_col([ |
|
581 | + [ |
|
582 | + 'Datetime.DTT_ID' => ['IN', $datetimeIds], |
|
583 | + ], |
|
584 | + 'default_where_conditions' => 'minimum', |
|
585 | + ]); |
|
586 | + foreach ($ticketIds as $ticketId) { |
|
587 | + $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId); |
|
588 | + |
|
589 | + foreach ($related_models as $key => $model) { |
|
590 | + // Get the IDs of related entities for the ticket ID. |
|
591 | + $Ids = $model->get_col([ |
|
592 | + [ |
|
593 | + 'Ticket.TKT_ID' => $ticketId, |
|
594 | + ], |
|
595 | + 'default_where_conditions' => 'minimum', |
|
596 | + ]); |
|
597 | + $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
598 | + } |
|
599 | + } |
|
600 | + |
|
601 | + // PROCESS PRICES |
|
602 | + $related_models = [ |
|
603 | + 'tickets' => $eem_ticket, |
|
604 | + 'priceTypes' => $eem_price_type, |
|
605 | + ]; |
|
606 | + // Get the IDs of all ticket prices. |
|
607 | + $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['IN', $ticketIds]]]); |
|
608 | + foreach ($priceIds as $priceId) { |
|
609 | + $GID = self::convertToGlobalId($eem_price->item_name(), $priceId); |
|
610 | + |
|
611 | + foreach ($related_models as $key => $model) { |
|
612 | + // Get the IDs of related entities for the price ID. |
|
613 | + $Ids = $model->get_col([ |
|
614 | + [ |
|
615 | + 'Price.PRC_ID' => $priceId, |
|
616 | + ], |
|
617 | + 'default_where_conditions' => 'minimum', |
|
618 | + ]); |
|
619 | + $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
620 | + } |
|
621 | + } |
|
622 | + |
|
623 | + return $data; |
|
624 | + } |
|
625 | + |
|
626 | + /** |
|
627 | + * Convert the DB ID into GID |
|
628 | + * |
|
629 | + * @param string $type |
|
630 | + * @param int|int[] $ID |
|
631 | + * @return mixed |
|
632 | + */ |
|
633 | + public static function convertToGlobalId($type, $ID) |
|
634 | + { |
|
635 | + if (is_array($ID)) { |
|
636 | + return array_map(function ($id) use ($type) { |
|
637 | + return self::convertToGlobalId($type, $id); |
|
638 | + }, $ID); |
|
639 | + } |
|
640 | + return Relay::toGlobalId($type, $ID); |
|
641 | + } |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * Returns Jed-formatted localization data. |
|
646 | + * |
|
647 | + * @param string $domain Translation domain. |
|
648 | + * @return array |
|
649 | + */ |
|
650 | + public static function getJedLocaleData($domain) |
|
651 | + { |
|
652 | + $translations = get_translations_for_domain($domain); |
|
653 | + |
|
654 | + $locale = array( |
|
655 | + '' => array( |
|
656 | + 'domain' => $domain, |
|
657 | + 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
658 | + ), |
|
659 | + ); |
|
660 | + |
|
661 | + if (! empty($translations->headers['Plural-Forms'])) { |
|
662 | + $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
663 | + } |
|
664 | + |
|
665 | + foreach ($translations->entries as $msgid => $entry) { |
|
666 | + $locale[ $msgid ] = $entry->translations; |
|
667 | + } |
|
668 | + |
|
669 | + return $locale; |
|
670 | + } |
|
671 | 671 | } |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | { |
104 | 104 | if ($this->admin_config->useAdvancedEditor()) { |
105 | 105 | $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0; |
106 | - if (! $eventId) { |
|
106 | + if ( ! $eventId) { |
|
107 | 107 | global $post; |
108 | 108 | $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0; |
109 | 109 | $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events' |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | $data = wp_json_encode($data); |
116 | 116 | add_action( |
117 | 117 | 'admin_footer', |
118 | - static function () use ($data) { |
|
118 | + static function() use ($data) { |
|
119 | 119 | wp_add_inline_script( |
120 | 120 | EspressoEditorAssetManager::JS_HANDLE_EDITOR, |
121 | 121 | " |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | $event = $this->getEventGraphQLData($eventId); |
149 | 149 | $event['dbId'] = $eventId; |
150 | 150 | |
151 | - $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : ''; |
|
151 | + $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()).Router::$route : ''; |
|
152 | 152 | $graphqlEndpoint = esc_url($graphqlEndpoint); |
153 | 153 | |
154 | 154 | $currentUser = $this->getGraphQLCurrentUser(); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | $i18n = self::getJedLocaleData('event_espresso'); |
159 | 159 | |
160 | - $assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/'; |
|
160 | + $assetsUrl = EE_PLUGIN_DIR_URL.'assets/dist/'; |
|
161 | 161 | |
162 | 162 | return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl'); |
163 | 163 | } |
@@ -177,18 +177,18 @@ discard block |
||
177 | 177 | $datetimes = $this->getGraphQLDatetimes($eventId); |
178 | 178 | } |
179 | 179 | |
180 | - if (! empty($datetimes['nodes'])) { |
|
180 | + if ( ! empty($datetimes['nodes'])) { |
|
181 | 181 | $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
182 | 182 | |
183 | - if (! empty($datetimeIn)) { |
|
183 | + if ( ! empty($datetimeIn)) { |
|
184 | 184 | $tickets = $this->getGraphQLTickets($datetimeIn); |
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
188 | - if (! empty($tickets['nodes'])) { |
|
188 | + if ( ! empty($tickets['nodes'])) { |
|
189 | 189 | $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
190 | 190 | |
191 | - if (! empty($ticketIn)) { |
|
191 | + if ( ! empty($ticketIn)) { |
|
192 | 192 | $prices = $this->getGraphQLPrices($ticketIn); |
193 | 193 | } |
194 | 194 | } |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | protected function getGraphQLDatetimes($eventId) |
242 | 242 | { |
243 | - $field_key = lcfirst($this->namespace) . 'Datetimes'; |
|
243 | + $field_key = lcfirst($this->namespace).'Datetimes'; |
|
244 | 244 | $query = <<<QUERY |
245 | 245 | query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
246 | 246 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | ]; |
283 | 283 | |
284 | 284 | $responseData = $this->makeGraphQLRequest($data); |
285 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
285 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | */ |
294 | 294 | protected function getGraphQLTickets(array $datetimeIn) |
295 | 295 | { |
296 | - $field_key = lcfirst($this->namespace) . 'Tickets'; |
|
296 | + $field_key = lcfirst($this->namespace).'Tickets'; |
|
297 | 297 | $query = <<<QUERY |
298 | 298 | query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) { |
299 | 299 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | ]; |
343 | 343 | |
344 | 344 | $responseData = $this->makeGraphQLRequest($data); |
345 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
345 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | */ |
354 | 354 | protected function getGraphQLPrices(array $ticketIn) |
355 | 355 | { |
356 | - $field_key = lcfirst($this->namespace) . 'Prices'; |
|
356 | + $field_key = lcfirst($this->namespace).'Prices'; |
|
357 | 357 | $query = <<<QUERY |
358 | 358 | query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) { |
359 | 359 | {$field_key}(where: \$where, first: \$first, last: \$last) { |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | ]; |
391 | 391 | |
392 | 392 | $responseData = $this->makeGraphQLRequest($data); |
393 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
393 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | */ |
401 | 401 | protected function getGraphQLPriceTypes() |
402 | 402 | { |
403 | - $field_key = lcfirst($this->namespace) . 'PriceTypes'; |
|
403 | + $field_key = lcfirst($this->namespace).'PriceTypes'; |
|
404 | 404 | $query = <<<QUERY |
405 | 405 | query GET_PRICE_TYPES(\$first: Int, \$last: Int ) { |
406 | 406 | {$field_key}(first: \$first, last: \$last) { |
@@ -431,7 +431,7 @@ discard block |
||
431 | 431 | ]; |
432 | 432 | |
433 | 433 | $responseData = $this->makeGraphQLRequest($data); |
434 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
434 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
435 | 435 | } |
436 | 436 | |
437 | 437 | |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | ]; |
467 | 467 | |
468 | 468 | $responseData = $this->makeGraphQLRequest($data); |
469 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
469 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | ]; |
494 | 494 | |
495 | 495 | $responseData = $this->makeGraphQLRequest($data); |
496 | - return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null; |
|
496 | + return ! empty($responseData[$field_key]) ? $responseData[$field_key] : null; |
|
497 | 497 | } |
498 | 498 | |
499 | 499 | |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | { |
507 | 507 | try { |
508 | 508 | $response = graphql($data); |
509 | - if (!empty($response['data'])) { |
|
509 | + if ( ! empty($response['data'])) { |
|
510 | 510 | return $response['data']; |
511 | 511 | } |
512 | 512 | return null; |
@@ -567,7 +567,7 @@ discard block |
||
567 | 567 | ], |
568 | 568 | 'default_where_conditions' => 'minimum', |
569 | 569 | ]); |
570 | - $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
570 | + $data['datetimes'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
571 | 571 | } |
572 | 572 | } |
573 | 573 | |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | ], |
595 | 595 | 'default_where_conditions' => 'minimum', |
596 | 596 | ]); |
597 | - $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
597 | + $data['tickets'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
598 | 598 | } |
599 | 599 | } |
600 | 600 | |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | ], |
617 | 617 | 'default_where_conditions' => 'minimum', |
618 | 618 | ]); |
619 | - $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
619 | + $data['prices'][$GID][$key] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids); |
|
620 | 620 | } |
621 | 621 | } |
622 | 622 | |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | public static function convertToGlobalId($type, $ID) |
634 | 634 | { |
635 | 635 | if (is_array($ID)) { |
636 | - return array_map(function ($id) use ($type) { |
|
636 | + return array_map(function($id) use ($type) { |
|
637 | 637 | return self::convertToGlobalId($type, $id); |
638 | 638 | }, $ID); |
639 | 639 | } |
@@ -658,12 +658,12 @@ discard block |
||
658 | 658 | ), |
659 | 659 | ); |
660 | 660 | |
661 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
661 | + if ( ! empty($translations->headers['Plural-Forms'])) { |
|
662 | 662 | $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
663 | 663 | } |
664 | 664 | |
665 | 665 | foreach ($translations->entries as $msgid => $entry) { |
666 | - $locale[ $msgid ] = $entry->translations; |
|
666 | + $locale[$msgid] = $entry->translations; |
|
667 | 667 | } |
668 | 668 | |
669 | 669 | return $locale; |
@@ -13,69 +13,69 @@ |
||
13 | 13 | class TicketCreate extends EntityMutator |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Defines the mutation data modification closure. |
|
18 | - * |
|
19 | - * @param EEM_Ticket $model |
|
20 | - * @param Ticket $type |
|
21 | - * @return callable |
|
22 | - */ |
|
23 | - public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
24 | - { |
|
25 | - /** |
|
26 | - * Creates an entity. |
|
27 | - * |
|
28 | - * @param array $input The input for the mutation |
|
29 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | - try { |
|
16 | + /** |
|
17 | + * Defines the mutation data modification closure. |
|
18 | + * |
|
19 | + * @param EEM_Ticket $model |
|
20 | + * @param Ticket $type |
|
21 | + * @return callable |
|
22 | + */ |
|
23 | + public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
24 | + { |
|
25 | + /** |
|
26 | + * Creates an entity. |
|
27 | + * |
|
28 | + * @param array $input The input for the mutation |
|
29 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | + try { |
|
35 | 35 | |
36 | - EntityMutator::checkPermissions($model); |
|
36 | + EntityMutator::checkPermissions($model); |
|
37 | 37 | |
38 | - $datetimes = []; |
|
39 | - $prices = []; |
|
38 | + $datetimes = []; |
|
39 | + $prices = []; |
|
40 | 40 | |
41 | - $args = TicketMutation::prepareFields($input); |
|
41 | + $args = TicketMutation::prepareFields($input); |
|
42 | 42 | |
43 | - if (isset($args['datetimes'])) { |
|
44 | - $datetimes = $args['datetimes']; |
|
45 | - unset($args['datetimes']); |
|
46 | - } |
|
47 | - if (isset($args['prices'])) { |
|
48 | - $prices = $args['prices']; |
|
49 | - unset($args['prices']); |
|
50 | - } |
|
43 | + if (isset($args['datetimes'])) { |
|
44 | + $datetimes = $args['datetimes']; |
|
45 | + unset($args['datetimes']); |
|
46 | + } |
|
47 | + if (isset($args['prices'])) { |
|
48 | + $prices = $args['prices']; |
|
49 | + unset($args['prices']); |
|
50 | + } |
|
51 | 51 | |
52 | - $entity = EE_Ticket::new_instance($args); |
|
53 | - $id = $entity->save(); |
|
54 | - EntityMutator::validateResults($id); |
|
52 | + $entity = EE_Ticket::new_instance($args); |
|
53 | + $id = $entity->save(); |
|
54 | + EntityMutator::validateResults($id); |
|
55 | 55 | |
56 | - if (! empty($datetimes)) { |
|
57 | - TicketMutation::setRelatedDatetimes($entity, $datetimes); |
|
58 | - } |
|
59 | - // if prices are passed. |
|
60 | - if (! empty($prices)) { |
|
61 | - TicketMutation::setRelatedPrices($entity, $prices); |
|
62 | - } else { |
|
63 | - TicketMutation::addDefaultPrices($entity, $model); |
|
64 | - } |
|
56 | + if (! empty($datetimes)) { |
|
57 | + TicketMutation::setRelatedDatetimes($entity, $datetimes); |
|
58 | + } |
|
59 | + // if prices are passed. |
|
60 | + if (! empty($prices)) { |
|
61 | + TicketMutation::setRelatedPrices($entity, $prices); |
|
62 | + } else { |
|
63 | + TicketMutation::addDefaultPrices($entity, $model); |
|
64 | + } |
|
65 | 65 | |
66 | - } catch (Exception $exception) { |
|
67 | - return EntityMutator::FormatException( |
|
68 | - $exception, |
|
69 | - esc_html__( |
|
70 | - 'The ticket could not be created because of the following error(s)', |
|
71 | - 'event_espresso' |
|
72 | - ) |
|
73 | - ); |
|
74 | - } |
|
66 | + } catch (Exception $exception) { |
|
67 | + return EntityMutator::FormatException( |
|
68 | + $exception, |
|
69 | + esc_html__( |
|
70 | + 'The ticket could not be created because of the following error(s)', |
|
71 | + 'event_espresso' |
|
72 | + ) |
|
73 | + ); |
|
74 | + } |
|
75 | 75 | |
76 | - return [ |
|
77 | - 'id' => $id, |
|
78 | - ]; |
|
79 | - }; |
|
80 | - } |
|
76 | + return [ |
|
77 | + 'id' => $id, |
|
78 | + ]; |
|
79 | + }; |
|
80 | + } |
|
81 | 81 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
33 | + return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | 34 | try { |
35 | 35 | |
36 | 36 | EntityMutator::checkPermissions($model); |
@@ -53,11 +53,11 @@ discard block |
||
53 | 53 | $id = $entity->save(); |
54 | 54 | EntityMutator::validateResults($id); |
55 | 55 | |
56 | - if (! empty($datetimes)) { |
|
56 | + if ( ! empty($datetimes)) { |
|
57 | 57 | TicketMutation::setRelatedDatetimes($entity, $datetimes); |
58 | 58 | } |
59 | 59 | // if prices are passed. |
60 | - if (! empty($prices)) { |
|
60 | + if ( ! empty($prices)) { |
|
61 | 61 | TicketMutation::setRelatedPrices($entity, $prices); |
62 | 62 | } else { |
63 | 63 | TicketMutation::addDefaultPrices($entity, $model); |
@@ -13,57 +13,57 @@ |
||
13 | 13 | class DatetimeCreate extends EntityMutator |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * Defines the mutation data modification closure. |
|
18 | - * |
|
19 | - * @param EEM_Datetime $model |
|
20 | - * @param Datetime $type |
|
21 | - * @return callable |
|
22 | - */ |
|
23 | - public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
24 | - { |
|
25 | - /** |
|
26 | - * Creates an entity. |
|
27 | - * |
|
28 | - * @param array $input The input for the mutation |
|
29 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | - try { |
|
16 | + /** |
|
17 | + * Defines the mutation data modification closure. |
|
18 | + * |
|
19 | + * @param EEM_Datetime $model |
|
20 | + * @param Datetime $type |
|
21 | + * @return callable |
|
22 | + */ |
|
23 | + public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
24 | + { |
|
25 | + /** |
|
26 | + * Creates an entity. |
|
27 | + * |
|
28 | + * @param array $input The input for the mutation |
|
29 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
30 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | + try { |
|
35 | 35 | |
36 | - EntityMutator::checkPermissions($model); |
|
36 | + EntityMutator::checkPermissions($model); |
|
37 | 37 | |
38 | - $tickets = []; |
|
39 | - $args = DatetimeMutation::prepareFields($input); |
|
38 | + $tickets = []; |
|
39 | + $args = DatetimeMutation::prepareFields($input); |
|
40 | 40 | |
41 | - if (isset($args['tickets'])) { |
|
42 | - $tickets = $args['tickets']; |
|
43 | - unset($args['tickets']); |
|
44 | - } |
|
41 | + if (isset($args['tickets'])) { |
|
42 | + $tickets = $args['tickets']; |
|
43 | + unset($args['tickets']); |
|
44 | + } |
|
45 | 45 | |
46 | - $entity = EE_Datetime::new_instance($args); |
|
47 | - $id = $entity->save(); |
|
48 | - EntityMutator::validateResults($id); |
|
46 | + $entity = EE_Datetime::new_instance($args); |
|
47 | + $id = $entity->save(); |
|
48 | + EntityMutator::validateResults($id); |
|
49 | 49 | |
50 | - if (! empty($tickets)) { |
|
51 | - DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
52 | - } |
|
50 | + if (! empty($tickets)) { |
|
51 | + DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
52 | + } |
|
53 | 53 | |
54 | - } catch (Exception $exception) { |
|
55 | - return EntityMutator::FormatException( |
|
56 | - $exception, |
|
57 | - esc_html__( |
|
58 | - 'The datetime could not be created because of the following error(s)', |
|
59 | - 'event_espresso' |
|
60 | - ) |
|
61 | - ); |
|
62 | - } |
|
54 | + } catch (Exception $exception) { |
|
55 | + return EntityMutator::FormatException( |
|
56 | + $exception, |
|
57 | + esc_html__( |
|
58 | + 'The datetime could not be created because of the following error(s)', |
|
59 | + 'event_espresso' |
|
60 | + ) |
|
61 | + ); |
|
62 | + } |
|
63 | 63 | |
64 | - return [ |
|
65 | - 'id' => $id, |
|
66 | - ]; |
|
67 | - }; |
|
68 | - } |
|
64 | + return [ |
|
65 | + 'id' => $id, |
|
66 | + ]; |
|
67 | + }; |
|
68 | + } |
|
69 | 69 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
33 | + return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | 34 | try { |
35 | 35 | |
36 | 36 | EntityMutator::checkPermissions($model); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $id = $entity->save(); |
48 | 48 | EntityMutator::validateResults($id); |
49 | 49 | |
50 | - if (! empty($tickets)) { |
|
50 | + if ( ! empty($tickets)) { |
|
51 | 51 | DatetimeMutation::setRelatedTickets($entity, $tickets); |
52 | 52 | } |
53 | 53 |
@@ -14,62 +14,62 @@ |
||
14 | 14 | class VenueUpdate extends EntityMutator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Venue $model |
|
21 | - * @param Venue $type |
|
22 | - * @return callable |
|
23 | - */ |
|
24 | - public static function mutateFields(EEM_Venue $model, Venue $type) |
|
25 | - { |
|
26 | - /** |
|
27 | - * Update additional data related to the entity. |
|
28 | - * |
|
29 | - * @param int $id The ID of the postObject being mutated |
|
30 | - * @param array $input The input for the mutation |
|
31 | - * @param WP_Post_Type $post_type_object The Post Type Object for the type of post being mutated |
|
32 | - * @param string $mutation_name The name of the mutation (ex: create, update, delete) |
|
33 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
34 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
35 | - * @return array|void |
|
36 | - */ |
|
37 | - return static function ( |
|
38 | - $id, |
|
39 | - array $input, |
|
40 | - WP_Post_Type $post_type_object, |
|
41 | - $mutation_name, |
|
42 | - AppContext $context, |
|
43 | - ResolveInfo $info |
|
44 | - ) use ( |
|
45 | - $model, |
|
46 | - $type |
|
47 | - ) { |
|
48 | - try { |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Venue $model |
|
21 | + * @param Venue $type |
|
22 | + * @return callable |
|
23 | + */ |
|
24 | + public static function mutateFields(EEM_Venue $model, Venue $type) |
|
25 | + { |
|
26 | + /** |
|
27 | + * Update additional data related to the entity. |
|
28 | + * |
|
29 | + * @param int $id The ID of the postObject being mutated |
|
30 | + * @param array $input The input for the mutation |
|
31 | + * @param WP_Post_Type $post_type_object The Post Type Object for the type of post being mutated |
|
32 | + * @param string $mutation_name The name of the mutation (ex: create, update, delete) |
|
33 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
34 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
35 | + * @return array|void |
|
36 | + */ |
|
37 | + return static function ( |
|
38 | + $id, |
|
39 | + array $input, |
|
40 | + WP_Post_Type $post_type_object, |
|
41 | + $mutation_name, |
|
42 | + AppContext $context, |
|
43 | + ResolveInfo $info |
|
44 | + ) use ( |
|
45 | + $model, |
|
46 | + $type |
|
47 | + ) { |
|
48 | + try { |
|
49 | 49 | |
50 | - // Make sure we are dealing with the right entity. |
|
51 | - if (! property_exists($post_type_object, 'graphql_single_name') |
|
52 | - || $post_type_object->graphql_single_name !== $type->name() |
|
53 | - ) { |
|
54 | - return; |
|
55 | - } |
|
50 | + // Make sure we are dealing with the right entity. |
|
51 | + if (! property_exists($post_type_object, 'graphql_single_name') |
|
52 | + || $post_type_object->graphql_single_name !== $type->name() |
|
53 | + ) { |
|
54 | + return; |
|
55 | + } |
|
56 | 56 | |
57 | - /** @var EE_Venue $entity */ |
|
58 | - $entity = EntityMutator::getEntityFromID($model, $id); |
|
59 | - $args = VenueMutation::prepareFields($input, $mutation_name); |
|
57 | + /** @var EE_Venue $entity */ |
|
58 | + $entity = EntityMutator::getEntityFromID($model, $id); |
|
59 | + $args = VenueMutation::prepareFields($input, $mutation_name); |
|
60 | 60 | |
61 | - // Update the entity |
|
62 | - $entity->save($args); |
|
61 | + // Update the entity |
|
62 | + $entity->save($args); |
|
63 | 63 | |
64 | - } catch (Exception $exception) { |
|
65 | - return EntityMutator::FormatException( |
|
66 | - $exception, |
|
67 | - esc_html__( |
|
68 | - 'The datetime could not be updated because of the following error(s)', |
|
69 | - 'event_espresso' |
|
70 | - ) |
|
71 | - ); |
|
72 | - } |
|
73 | - }; |
|
74 | - } |
|
64 | + } catch (Exception $exception) { |
|
65 | + return EntityMutator::FormatException( |
|
66 | + $exception, |
|
67 | + esc_html__( |
|
68 | + 'The datetime could not be updated because of the following error(s)', |
|
69 | + 'event_espresso' |
|
70 | + ) |
|
71 | + ); |
|
72 | + } |
|
73 | + }; |
|
74 | + } |
|
75 | 75 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
35 | 35 | * @return array|void |
36 | 36 | */ |
37 | - return static function ( |
|
37 | + return static function( |
|
38 | 38 | $id, |
39 | 39 | array $input, |
40 | 40 | WP_Post_Type $post_type_object, |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | try { |
49 | 49 | |
50 | 50 | // Make sure we are dealing with the right entity. |
51 | - if (! property_exists($post_type_object, 'graphql_single_name') |
|
51 | + if ( ! property_exists($post_type_object, 'graphql_single_name') |
|
52 | 52 | || $post_type_object->graphql_single_name !== $type->name() |
53 | 53 | ) { |
54 | 54 | return; |
@@ -12,45 +12,45 @@ |
||
12 | 12 | class PriceDelete extends EntityMutator |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Defines the mutation data modification closure. |
|
17 | - * |
|
18 | - * @param EEM_Price $model |
|
19 | - * @param Price $type |
|
20 | - * @return callable |
|
21 | - */ |
|
22 | - public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
23 | - { |
|
24 | - /** |
|
25 | - * Deletes an entity. |
|
26 | - * |
|
27 | - * @param array $input The input for the mutation |
|
28 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
29 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
30 | - * @return array |
|
31 | - */ |
|
32 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
33 | - try { |
|
15 | + /** |
|
16 | + * Defines the mutation data modification closure. |
|
17 | + * |
|
18 | + * @param EEM_Price $model |
|
19 | + * @param Price $type |
|
20 | + * @return callable |
|
21 | + */ |
|
22 | + public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
23 | + { |
|
24 | + /** |
|
25 | + * Deletes an entity. |
|
26 | + * |
|
27 | + * @param array $input The input for the mutation |
|
28 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
29 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
30 | + * @return array |
|
31 | + */ |
|
32 | + return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
33 | + try { |
|
34 | 34 | |
35 | - /** @var EE_Price $entity */ |
|
36 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
37 | - // Delete the entity |
|
38 | - $result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete(); |
|
39 | - EntityMutator::validateResults($result); |
|
35 | + /** @var EE_Price $entity */ |
|
36 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
37 | + // Delete the entity |
|
38 | + $result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete(); |
|
39 | + EntityMutator::validateResults($result); |
|
40 | 40 | |
41 | - } catch (Exception $exception) { |
|
42 | - return EntityMutator::FormatException( |
|
43 | - $exception, |
|
44 | - esc_html__( |
|
45 | - 'The price could not be deleted because of the following error(s)', |
|
46 | - 'event_espresso' |
|
47 | - ) |
|
48 | - ); |
|
49 | - } |
|
41 | + } catch (Exception $exception) { |
|
42 | + return EntityMutator::FormatException( |
|
43 | + $exception, |
|
44 | + esc_html__( |
|
45 | + 'The price could not be deleted because of the following error(s)', |
|
46 | + 'event_espresso' |
|
47 | + ) |
|
48 | + ); |
|
49 | + } |
|
50 | 50 | |
51 | - return [ |
|
52 | - 'deleted' => $entity, |
|
53 | - ]; |
|
54 | - }; |
|
55 | - } |
|
51 | + return [ |
|
52 | + 'deleted' => $entity, |
|
53 | + ]; |
|
54 | + }; |
|
55 | + } |
|
56 | 56 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
30 | 30 | * @return array |
31 | 31 | */ |
32 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
32 | + return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
33 | 33 | try { |
34 | 34 | |
35 | 35 | /** @var EE_Price $entity */ |
@@ -14,54 +14,54 @@ |
||
14 | 14 | class PriceCreate extends EntityMutator |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * Defines the mutation data modification closure. |
|
19 | - * |
|
20 | - * @param EEM_Price $model |
|
21 | - * @param Price $type |
|
22 | - * @return callable |
|
23 | - */ |
|
24 | - public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
25 | - { |
|
26 | - /** |
|
27 | - * Creates an entity. |
|
28 | - * |
|
29 | - * @param array $input The input for the mutation |
|
30 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
31 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
35 | - try { |
|
17 | + /** |
|
18 | + * Defines the mutation data modification closure. |
|
19 | + * |
|
20 | + * @param EEM_Price $model |
|
21 | + * @param Price $type |
|
22 | + * @return callable |
|
23 | + */ |
|
24 | + public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
25 | + { |
|
26 | + /** |
|
27 | + * Creates an entity. |
|
28 | + * |
|
29 | + * @param array $input The input for the mutation |
|
30 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
31 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
35 | + try { |
|
36 | 36 | |
37 | - EntityMutator::checkPermissions($model); |
|
37 | + EntityMutator::checkPermissions($model); |
|
38 | 38 | |
39 | - $args = PriceMutation::prepareFields($input); |
|
39 | + $args = PriceMutation::prepareFields($input); |
|
40 | 40 | |
41 | - if (empty($args['PRT_ID'])) { |
|
42 | - // translators: the placeholder is the name of the field. |
|
43 | - throw new UserError( |
|
44 | - sprintf(esc_html__('A valid %1$s must be passed.', 'event_espresso'), 'priceType') |
|
45 | - ); |
|
46 | - } |
|
41 | + if (empty($args['PRT_ID'])) { |
|
42 | + // translators: the placeholder is the name of the field. |
|
43 | + throw new UserError( |
|
44 | + sprintf(esc_html__('A valid %1$s must be passed.', 'event_espresso'), 'priceType') |
|
45 | + ); |
|
46 | + } |
|
47 | 47 | |
48 | - $entity = EE_Price::new_instance($args); |
|
49 | - $id = $entity->save(); |
|
50 | - EntityMutator::validateResults($id); |
|
48 | + $entity = EE_Price::new_instance($args); |
|
49 | + $id = $entity->save(); |
|
50 | + EntityMutator::validateResults($id); |
|
51 | 51 | |
52 | - } catch (Exception $exception) { |
|
53 | - return EntityMutator::FormatException( |
|
54 | - $exception, |
|
55 | - esc_html__( |
|
56 | - 'The price could not be created because of the following error(s)', |
|
57 | - 'event_espresso' |
|
58 | - ) |
|
59 | - ); |
|
60 | - } |
|
52 | + } catch (Exception $exception) { |
|
53 | + return EntityMutator::FormatException( |
|
54 | + $exception, |
|
55 | + esc_html__( |
|
56 | + 'The price could not be created because of the following error(s)', |
|
57 | + 'event_espresso' |
|
58 | + ) |
|
59 | + ); |
|
60 | + } |
|
61 | 61 | |
62 | - return [ |
|
63 | - 'id' => $id, |
|
64 | - ]; |
|
65 | - }; |
|
66 | - } |
|
62 | + return [ |
|
63 | + 'id' => $id, |
|
64 | + ]; |
|
65 | + }; |
|
66 | + } |
|
67 | 67 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
32 | 32 | * @return array |
33 | 33 | */ |
34 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
34 | + return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
35 | 35 | try { |
36 | 36 | |
37 | 37 | EntityMutator::checkPermissions($model); |
@@ -23,159 +23,159 @@ |
||
23 | 23 | abstract class EntityMutator |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @param EEM_Base $model |
|
28 | - * @param integer $ID |
|
29 | - * @param string $capability |
|
30 | - * @return EE_Base_Class |
|
31 | - * @throws OutOfBoundsException |
|
32 | - * @throws UserError |
|
33 | - * @since $VID:$ |
|
34 | - */ |
|
35 | - protected static function getEntityFromID(EEM_Base $model, $ID, $capability = 'ee_edit_events') |
|
36 | - { |
|
37 | - EntityMutator::checkPermissions($model, $capability); |
|
38 | - return EntityMutator::getEntity($model, $ID); |
|
39 | - } |
|
26 | + /** |
|
27 | + * @param EEM_Base $model |
|
28 | + * @param integer $ID |
|
29 | + * @param string $capability |
|
30 | + * @return EE_Base_Class |
|
31 | + * @throws OutOfBoundsException |
|
32 | + * @throws UserError |
|
33 | + * @since $VID:$ |
|
34 | + */ |
|
35 | + protected static function getEntityFromID(EEM_Base $model, $ID, $capability = 'ee_edit_events') |
|
36 | + { |
|
37 | + EntityMutator::checkPermissions($model, $capability); |
|
38 | + return EntityMutator::getEntity($model, $ID); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param EEM_Base $model |
|
43 | - * @param array $input |
|
44 | - * @param string $capability |
|
45 | - * @return EE_Base_Class |
|
46 | - * @throws OutOfBoundsException |
|
47 | - * @throws UserError |
|
48 | - * @since $VID:$ |
|
49 | - */ |
|
50 | - protected static function getEntityFromInputData(EEM_Base $model, array $input, $capability = 'ee_edit_events') |
|
51 | - { |
|
52 | - EntityMutator::checkPermissions($model, $capability); |
|
53 | - $ID = EntityMutator::getEntityIDFromGlobalId($model, $input); |
|
54 | - return EntityMutator::getEntity($model, $ID); |
|
55 | - } |
|
41 | + /** |
|
42 | + * @param EEM_Base $model |
|
43 | + * @param array $input |
|
44 | + * @param string $capability |
|
45 | + * @return EE_Base_Class |
|
46 | + * @throws OutOfBoundsException |
|
47 | + * @throws UserError |
|
48 | + * @since $VID:$ |
|
49 | + */ |
|
50 | + protected static function getEntityFromInputData(EEM_Base $model, array $input, $capability = 'ee_edit_events') |
|
51 | + { |
|
52 | + EntityMutator::checkPermissions($model, $capability); |
|
53 | + $ID = EntityMutator::getEntityIDFromGlobalId($model, $input); |
|
54 | + return EntityMutator::getEntity($model, $ID); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * @param EEM_Base $model |
|
60 | - * @param string $capability |
|
61 | - * @throws UserError |
|
62 | - * @since $VID:$ |
|
63 | - */ |
|
64 | - protected static function checkPermissions(EEM_Base $model, $capability = 'ee_edit_events') |
|
65 | - { |
|
66 | - /** |
|
67 | - * Stop now if a user isn't allowed to execute mutation |
|
68 | - */ |
|
69 | - if (! current_user_can($capability)) { |
|
70 | - $model_name = $model->get_this_model_name(); |
|
71 | - $message = sprintf( |
|
72 | - esc_html_x( |
|
73 | - 'We\'re sorry but you do not have the required permissions to execute %1$s mutations!', |
|
74 | - 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - strtolower($model_name) |
|
78 | - ); |
|
79 | - throw new UserError($message); |
|
80 | - } |
|
81 | - } |
|
58 | + /** |
|
59 | + * @param EEM_Base $model |
|
60 | + * @param string $capability |
|
61 | + * @throws UserError |
|
62 | + * @since $VID:$ |
|
63 | + */ |
|
64 | + protected static function checkPermissions(EEM_Base $model, $capability = 'ee_edit_events') |
|
65 | + { |
|
66 | + /** |
|
67 | + * Stop now if a user isn't allowed to execute mutation |
|
68 | + */ |
|
69 | + if (! current_user_can($capability)) { |
|
70 | + $model_name = $model->get_this_model_name(); |
|
71 | + $message = sprintf( |
|
72 | + esc_html_x( |
|
73 | + 'We\'re sorry but you do not have the required permissions to execute %1$s mutations!', |
|
74 | + 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + strtolower($model_name) |
|
78 | + ); |
|
79 | + throw new UserError($message); |
|
80 | + } |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * @param EEM_Base $model |
|
85 | - * @param array $input |
|
86 | - * @return int |
|
87 | - * @throws OutOfBoundsException |
|
88 | - * @since $VID:$ |
|
89 | - */ |
|
90 | - protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input) { |
|
91 | - $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
92 | - $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
93 | - if ($id > 0) { |
|
94 | - return $id; |
|
95 | - } |
|
96 | - // no ID? throw an exception |
|
97 | - $model_name = $model->get_this_model_name(); |
|
98 | - throw new OutOfBoundsException( |
|
99 | - sprintf( |
|
100 | - esc_html_x( |
|
101 | - 'A missing or invalid %1$s ID was received.', |
|
102 | - 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
103 | - 'event_espresso' |
|
104 | - ), |
|
105 | - strtolower($model_name) |
|
106 | - ) |
|
107 | - ); |
|
108 | - } |
|
83 | + /** |
|
84 | + * @param EEM_Base $model |
|
85 | + * @param array $input |
|
86 | + * @return int |
|
87 | + * @throws OutOfBoundsException |
|
88 | + * @since $VID:$ |
|
89 | + */ |
|
90 | + protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input) { |
|
91 | + $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
92 | + $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
93 | + if ($id > 0) { |
|
94 | + return $id; |
|
95 | + } |
|
96 | + // no ID? throw an exception |
|
97 | + $model_name = $model->get_this_model_name(); |
|
98 | + throw new OutOfBoundsException( |
|
99 | + sprintf( |
|
100 | + esc_html_x( |
|
101 | + 'A missing or invalid %1$s ID was received.', |
|
102 | + 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
103 | + 'event_espresso' |
|
104 | + ), |
|
105 | + strtolower($model_name) |
|
106 | + ) |
|
107 | + ); |
|
108 | + } |
|
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * @param EEM_Base $model |
|
113 | - * @param int $ID |
|
114 | - * @return EE_Base_Class |
|
115 | - * @throws OutOfBoundsException |
|
116 | - * @since $VID:$ |
|
117 | - */ |
|
118 | - protected static function getEntity(EEM_Base $model, $ID = 0) |
|
119 | - { |
|
120 | - $entity = $model->get_one_by_ID($ID); |
|
121 | - $model_name = $model->get_this_model_name(); |
|
122 | - $class_name = 'EE_' . $model_name; |
|
123 | - if ($entity instanceof $class_name) { |
|
124 | - return $entity; |
|
125 | - } |
|
126 | - // OOPS!!! invalid entity |
|
127 | - throw new OutOfBoundsException( |
|
128 | - sprintf( |
|
129 | - esc_html_x( |
|
130 | - 'A valid %1$s could not be retrieved from the database.', |
|
131 | - 'A valid entity(datetime/ticket/etc) could not be found in the database.', |
|
132 | - 'event_espresso' |
|
133 | - ), |
|
134 | - strtolower($model_name) |
|
135 | - ) |
|
136 | - ); |
|
137 | - } |
|
111 | + /** |
|
112 | + * @param EEM_Base $model |
|
113 | + * @param int $ID |
|
114 | + * @return EE_Base_Class |
|
115 | + * @throws OutOfBoundsException |
|
116 | + * @since $VID:$ |
|
117 | + */ |
|
118 | + protected static function getEntity(EEM_Base $model, $ID = 0) |
|
119 | + { |
|
120 | + $entity = $model->get_one_by_ID($ID); |
|
121 | + $model_name = $model->get_this_model_name(); |
|
122 | + $class_name = 'EE_' . $model_name; |
|
123 | + if ($entity instanceof $class_name) { |
|
124 | + return $entity; |
|
125 | + } |
|
126 | + // OOPS!!! invalid entity |
|
127 | + throw new OutOfBoundsException( |
|
128 | + sprintf( |
|
129 | + esc_html_x( |
|
130 | + 'A valid %1$s could not be retrieved from the database.', |
|
131 | + 'A valid entity(datetime/ticket/etc) could not be found in the database.', |
|
132 | + 'event_espresso' |
|
133 | + ), |
|
134 | + strtolower($model_name) |
|
135 | + ) |
|
136 | + ); |
|
137 | + } |
|
138 | 138 | |
139 | 139 | |
140 | - /** |
|
141 | - * @param $results |
|
142 | - * @param string $message |
|
143 | - * @throws RuntimeException |
|
144 | - * @since $VID:$ |
|
145 | - */ |
|
146 | - protected static function validateResults($results, $message = '') |
|
147 | - { |
|
148 | - if (empty($results)) { |
|
149 | - $message = $message !== '' |
|
150 | - ? $message |
|
151 | - : esc_html__( |
|
152 | - 'An unknown error occurred. Please check your server\'s error logs for more information', |
|
153 | - 'event_espresso' |
|
154 | - ); |
|
155 | - throw new RuntimeException($message); |
|
156 | - } |
|
157 | - } |
|
140 | + /** |
|
141 | + * @param $results |
|
142 | + * @param string $message |
|
143 | + * @throws RuntimeException |
|
144 | + * @since $VID:$ |
|
145 | + */ |
|
146 | + protected static function validateResults($results, $message = '') |
|
147 | + { |
|
148 | + if (empty($results)) { |
|
149 | + $message = $message !== '' |
|
150 | + ? $message |
|
151 | + : esc_html__( |
|
152 | + 'An unknown error occurred. Please check your server\'s error logs for more information', |
|
153 | + 'event_espresso' |
|
154 | + ); |
|
155 | + throw new RuntimeException($message); |
|
156 | + } |
|
157 | + } |
|
158 | 158 | |
159 | 159 | |
160 | - /** |
|
161 | - * @param Exception $exception |
|
162 | - * @param string $message_prefix |
|
163 | - * @return array |
|
164 | - * @throws Throwable |
|
165 | - * @since $VID:$ |
|
166 | - */ |
|
167 | - protected static function FormatException(Exception $exception, $message_prefix = '') |
|
168 | - { |
|
169 | - $message_prefix = $message_prefix !== '' |
|
170 | - ? $message_prefix |
|
171 | - : esc_html__( |
|
172 | - 'The mutation could not be executed because of the following error(s)', |
|
173 | - 'event_espresso' |
|
174 | - ); |
|
175 | - return FormattedError::createFromException( |
|
176 | - new RuntimeException( |
|
177 | - sprintf('%1$s: %2$s',$message_prefix, $exception->getMessage()) |
|
178 | - ) |
|
179 | - ); |
|
180 | - } |
|
160 | + /** |
|
161 | + * @param Exception $exception |
|
162 | + * @param string $message_prefix |
|
163 | + * @return array |
|
164 | + * @throws Throwable |
|
165 | + * @since $VID:$ |
|
166 | + */ |
|
167 | + protected static function FormatException(Exception $exception, $message_prefix = '') |
|
168 | + { |
|
169 | + $message_prefix = $message_prefix !== '' |
|
170 | + ? $message_prefix |
|
171 | + : esc_html__( |
|
172 | + 'The mutation could not be executed because of the following error(s)', |
|
173 | + 'event_espresso' |
|
174 | + ); |
|
175 | + return FormattedError::createFromException( |
|
176 | + new RuntimeException( |
|
177 | + sprintf('%1$s: %2$s',$message_prefix, $exception->getMessage()) |
|
178 | + ) |
|
179 | + ); |
|
180 | + } |
|
181 | 181 | } |
182 | 182 | \ No newline at end of file |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | /** |
67 | 67 | * Stop now if a user isn't allowed to execute mutation |
68 | 68 | */ |
69 | - if (! current_user_can($capability)) { |
|
69 | + if ( ! current_user_can($capability)) { |
|
70 | 70 | $model_name = $model->get_this_model_name(); |
71 | 71 | $message = sprintf( |
72 | 72 | esc_html_x( |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | { |
120 | 120 | $entity = $model->get_one_by_ID($ID); |
121 | 121 | $model_name = $model->get_this_model_name(); |
122 | - $class_name = 'EE_' . $model_name; |
|
122 | + $class_name = 'EE_'.$model_name; |
|
123 | 123 | if ($entity instanceof $class_name) { |
124 | 124 | return $entity; |
125 | 125 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | ); |
175 | 175 | return FormattedError::createFromException( |
176 | 176 | new RuntimeException( |
177 | - sprintf('%1$s: %2$s',$message_prefix, $exception->getMessage()) |
|
177 | + sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage()) |
|
178 | 178 | ) |
179 | 179 | ); |
180 | 180 | } |