@@ -25,7 +25,7 @@ |
||
| 25 | 25 | * |
| 26 | 26 | * @param EEM_Price $model |
| 27 | 27 | * @param Price $type |
| 28 | - * @return callable |
|
| 28 | + * @return \Closure |
|
| 29 | 29 | */ |
| 30 | 30 | public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
| 31 | 31 | { |
@@ -13,45 +13,45 @@ |
||
| 13 | 13 | class PriceUpdate extends EntityMutator |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Defines the mutation data modification closure. |
|
| 18 | - * |
|
| 19 | - * @param EEM_Price $model |
|
| 20 | - * @param Price $type |
|
| 21 | - * @return callable |
|
| 22 | - */ |
|
| 23 | - public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
| 24 | - { |
|
| 25 | - /** |
|
| 26 | - * Updates 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 | - /** @var EE_Price $entity */ |
|
| 36 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
| 16 | + /** |
|
| 17 | + * Defines the mutation data modification closure. |
|
| 18 | + * |
|
| 19 | + * @param EEM_Price $model |
|
| 20 | + * @param Price $type |
|
| 21 | + * @return callable |
|
| 22 | + */ |
|
| 23 | + public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
| 24 | + { |
|
| 25 | + /** |
|
| 26 | + * Updates 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 | + /** @var EE_Price $entity */ |
|
| 36 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
| 37 | 37 | |
| 38 | - $args = PriceMutation::prepareFields($input); |
|
| 38 | + $args = PriceMutation::prepareFields($input); |
|
| 39 | 39 | |
| 40 | - // Update the entity |
|
| 41 | - $entity->save($args); |
|
| 42 | - } catch (Exception $exception) { |
|
| 43 | - EntityMutator::handleExceptions( |
|
| 44 | - $exception, |
|
| 45 | - esc_html__( |
|
| 46 | - 'The price could not be updated because of the following error(s)', |
|
| 47 | - 'event_espresso' |
|
| 48 | - ) |
|
| 49 | - ); |
|
| 50 | - } |
|
| 40 | + // Update the entity |
|
| 41 | + $entity->save($args); |
|
| 42 | + } catch (Exception $exception) { |
|
| 43 | + EntityMutator::handleExceptions( |
|
| 44 | + $exception, |
|
| 45 | + esc_html__( |
|
| 46 | + 'The price could not be updated because of the following error(s)', |
|
| 47 | + 'event_espresso' |
|
| 48 | + ) |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return [ |
|
| 53 | - 'id' => $entity->ID(), |
|
| 54 | - ]; |
|
| 55 | - }; |
|
| 56 | - } |
|
| 52 | + return [ |
|
| 53 | + 'id' => $entity->ID(), |
|
| 54 | + ]; |
|
| 55 | + }; |
|
| 56 | + } |
|
| 57 | 57 | } |
@@ -30,7 +30,7 @@ |
||
| 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 | /** @var EE_Price $entity */ |
| 36 | 36 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | |
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | - * @return GraphQLFieldInterface[] |
|
| 52 | + * @return GraphQLField[] |
|
| 53 | 53 | * @since $VID:$ |
| 54 | 54 | */ |
| 55 | 55 | public function getFields() |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | * @param array $args The inputArgs on the field |
| 221 | 221 | * @param AppContext $context The AppContext passed down the GraphQL tree |
| 222 | 222 | * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
| 223 | - * @return string |
|
| 223 | + * @return boolean |
|
| 224 | 224 | * @throws Exception |
| 225 | 225 | * @throws InvalidArgumentException |
| 226 | 226 | * @throws InvalidDataTypeException |
@@ -6,7 +6,6 @@ |
||
| 6 | 6 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
| 7 | 7 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
| 8 | 8 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
| 9 | - |
|
| 10 | 9 | use EE_Datetime; |
| 11 | 10 | use EEM_Datetime; |
| 12 | 11 | use EventEspresso\core\services\graphql\fields\GraphQLFieldInterface; |
@@ -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 | } |
@@ -21,157 +21,157 @@ |
||
| 21 | 21 | abstract class EntityMutator |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param EEM_Base $model |
|
| 26 | - * @param integer $ID |
|
| 27 | - * @param string $capability |
|
| 28 | - * @return EE_Base_Class |
|
| 29 | - * @throws OutOfBoundsException |
|
| 30 | - * @throws UserError |
|
| 31 | - * @since $VID:$ |
|
| 32 | - */ |
|
| 33 | - protected static function getEntityFromID(EEM_Base $model, $ID, $capability = 'ee_edit_events') |
|
| 34 | - { |
|
| 35 | - EntityMutator::checkPermissions($model, $capability); |
|
| 36 | - return EntityMutator::getEntity($model, $ID); |
|
| 37 | - } |
|
| 24 | + /** |
|
| 25 | + * @param EEM_Base $model |
|
| 26 | + * @param integer $ID |
|
| 27 | + * @param string $capability |
|
| 28 | + * @return EE_Base_Class |
|
| 29 | + * @throws OutOfBoundsException |
|
| 30 | + * @throws UserError |
|
| 31 | + * @since $VID:$ |
|
| 32 | + */ |
|
| 33 | + protected static function getEntityFromID(EEM_Base $model, $ID, $capability = 'ee_edit_events') |
|
| 34 | + { |
|
| 35 | + EntityMutator::checkPermissions($model, $capability); |
|
| 36 | + return EntityMutator::getEntity($model, $ID); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param EEM_Base $model |
|
| 41 | - * @param array $input |
|
| 42 | - * @param string $capability |
|
| 43 | - * @return EE_Base_Class |
|
| 44 | - * @throws OutOfBoundsException |
|
| 45 | - * @throws UserError |
|
| 46 | - * @since $VID:$ |
|
| 47 | - */ |
|
| 48 | - protected static function getEntityFromInputData(EEM_Base $model, array $input, $capability = 'ee_edit_events') |
|
| 49 | - { |
|
| 50 | - EntityMutator::checkPermissions($model, $capability); |
|
| 51 | - $ID = EntityMutator::getEntityIDFromGlobalId($model, $input); |
|
| 52 | - return EntityMutator::getEntity($model, $ID); |
|
| 53 | - } |
|
| 39 | + /** |
|
| 40 | + * @param EEM_Base $model |
|
| 41 | + * @param array $input |
|
| 42 | + * @param string $capability |
|
| 43 | + * @return EE_Base_Class |
|
| 44 | + * @throws OutOfBoundsException |
|
| 45 | + * @throws UserError |
|
| 46 | + * @since $VID:$ |
|
| 47 | + */ |
|
| 48 | + protected static function getEntityFromInputData(EEM_Base $model, array $input, $capability = 'ee_edit_events') |
|
| 49 | + { |
|
| 50 | + EntityMutator::checkPermissions($model, $capability); |
|
| 51 | + $ID = EntityMutator::getEntityIDFromGlobalId($model, $input); |
|
| 52 | + return EntityMutator::getEntity($model, $ID); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param EEM_Base $model |
|
| 58 | - * @param string $capability |
|
| 59 | - * @throws UserError |
|
| 60 | - * @since $VID:$ |
|
| 61 | - */ |
|
| 62 | - protected static function checkPermissions(EEM_Base $model, $capability = 'ee_edit_events') |
|
| 63 | - { |
|
| 64 | - /** |
|
| 65 | - * Stop now if a user isn't allowed to execute mutation |
|
| 66 | - */ |
|
| 67 | - if (! current_user_can($capability)) { |
|
| 68 | - $model_name = $model->get_this_model_name(); |
|
| 69 | - $message = sprintf( |
|
| 70 | - esc_html_x( |
|
| 71 | - 'We\'re sorry but you do not have the required permissions to execute %1$s mutations!', |
|
| 72 | - 'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!', |
|
| 73 | - 'event_espresso' |
|
| 74 | - ), |
|
| 75 | - strtolower($model_name) |
|
| 76 | - ); |
|
| 77 | - throw new UserError($message); |
|
| 78 | - } |
|
| 79 | - } |
|
| 56 | + /** |
|
| 57 | + * @param EEM_Base $model |
|
| 58 | + * @param string $capability |
|
| 59 | + * @throws UserError |
|
| 60 | + * @since $VID:$ |
|
| 61 | + */ |
|
| 62 | + protected static function checkPermissions(EEM_Base $model, $capability = 'ee_edit_events') |
|
| 63 | + { |
|
| 64 | + /** |
|
| 65 | + * Stop now if a user isn't allowed to execute mutation |
|
| 66 | + */ |
|
| 67 | + if (! current_user_can($capability)) { |
|
| 68 | + $model_name = $model->get_this_model_name(); |
|
| 69 | + $message = sprintf( |
|
| 70 | + esc_html_x( |
|
| 71 | + 'We\'re sorry but you do not have the required permissions to execute %1$s mutations!', |
|
| 72 | + 'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!', |
|
| 73 | + 'event_espresso' |
|
| 74 | + ), |
|
| 75 | + strtolower($model_name) |
|
| 76 | + ); |
|
| 77 | + throw new UserError($message); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @param EEM_Base $model |
|
| 83 | - * @param array $input |
|
| 84 | - * @return int |
|
| 85 | - * @throws OutOfBoundsException |
|
| 86 | - * @since $VID:$ |
|
| 87 | - */ |
|
| 88 | - protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input) |
|
| 89 | - { |
|
| 90 | - $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
| 91 | - $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
| 92 | - if ($id > 0) { |
|
| 93 | - return $id; |
|
| 94 | - } |
|
| 95 | - // no ID? throw an exception |
|
| 96 | - $model_name = $model->get_this_model_name(); |
|
| 97 | - throw new OutOfBoundsException( |
|
| 98 | - sprintf( |
|
| 99 | - esc_html_x( |
|
| 100 | - 'A missing or invalid %1$s ID was received.', |
|
| 101 | - 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
| 102 | - 'event_espresso' |
|
| 103 | - ), |
|
| 104 | - strtolower($model_name) |
|
| 105 | - ) |
|
| 106 | - ); |
|
| 107 | - } |
|
| 81 | + /** |
|
| 82 | + * @param EEM_Base $model |
|
| 83 | + * @param array $input |
|
| 84 | + * @return int |
|
| 85 | + * @throws OutOfBoundsException |
|
| 86 | + * @since $VID:$ |
|
| 87 | + */ |
|
| 88 | + protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input) |
|
| 89 | + { |
|
| 90 | + $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
| 91 | + $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
| 92 | + if ($id > 0) { |
|
| 93 | + return $id; |
|
| 94 | + } |
|
| 95 | + // no ID? throw an exception |
|
| 96 | + $model_name = $model->get_this_model_name(); |
|
| 97 | + throw new OutOfBoundsException( |
|
| 98 | + sprintf( |
|
| 99 | + esc_html_x( |
|
| 100 | + 'A missing or invalid %1$s ID was received.', |
|
| 101 | + 'A missing or invalid entity(datetime/ticket/etc) ID was received.', |
|
| 102 | + 'event_espresso' |
|
| 103 | + ), |
|
| 104 | + strtolower($model_name) |
|
| 105 | + ) |
|
| 106 | + ); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * @param EEM_Base $model |
|
| 112 | - * @param int $ID |
|
| 113 | - * @return EE_Base_Class |
|
| 114 | - * @throws OutOfBoundsException |
|
| 115 | - * @since $VID:$ |
|
| 116 | - */ |
|
| 117 | - protected static function getEntity(EEM_Base $model, $ID = 0) |
|
| 118 | - { |
|
| 119 | - $entity = $model->get_one_by_ID($ID); |
|
| 120 | - $model_name = $model->get_this_model_name(); |
|
| 121 | - $class_name = 'EE_' . $model_name; |
|
| 122 | - if ($entity instanceof $class_name) { |
|
| 123 | - return $entity; |
|
| 124 | - } |
|
| 125 | - // OOPS!!! invalid entity |
|
| 126 | - throw new OutOfBoundsException( |
|
| 127 | - sprintf( |
|
| 128 | - esc_html_x( |
|
| 129 | - 'A valid %1$s could not be retrieved from the database.', |
|
| 130 | - 'A valid entity(datetime/ticket/etc) could not be found in the database.', |
|
| 131 | - 'event_espresso' |
|
| 132 | - ), |
|
| 133 | - strtolower($model_name) |
|
| 134 | - ) |
|
| 135 | - ); |
|
| 136 | - } |
|
| 110 | + /** |
|
| 111 | + * @param EEM_Base $model |
|
| 112 | + * @param int $ID |
|
| 113 | + * @return EE_Base_Class |
|
| 114 | + * @throws OutOfBoundsException |
|
| 115 | + * @since $VID:$ |
|
| 116 | + */ |
|
| 117 | + protected static function getEntity(EEM_Base $model, $ID = 0) |
|
| 118 | + { |
|
| 119 | + $entity = $model->get_one_by_ID($ID); |
|
| 120 | + $model_name = $model->get_this_model_name(); |
|
| 121 | + $class_name = 'EE_' . $model_name; |
|
| 122 | + if ($entity instanceof $class_name) { |
|
| 123 | + return $entity; |
|
| 124 | + } |
|
| 125 | + // OOPS!!! invalid entity |
|
| 126 | + throw new OutOfBoundsException( |
|
| 127 | + sprintf( |
|
| 128 | + esc_html_x( |
|
| 129 | + 'A valid %1$s could not be retrieved from the database.', |
|
| 130 | + 'A valid entity(datetime/ticket/etc) could not be found in the database.', |
|
| 131 | + 'event_espresso' |
|
| 132 | + ), |
|
| 133 | + strtolower($model_name) |
|
| 134 | + ) |
|
| 135 | + ); |
|
| 136 | + } |
|
| 137 | 137 | |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * @param $results |
|
| 141 | - * @param string $message |
|
| 142 | - * @throws RuntimeException |
|
| 143 | - * @since $VID:$ |
|
| 144 | - */ |
|
| 145 | - protected static function validateResults($results, $message = '') |
|
| 146 | - { |
|
| 147 | - if (empty($results)) { |
|
| 148 | - $message = $message !== '' |
|
| 149 | - ? $message |
|
| 150 | - : esc_html__( |
|
| 151 | - 'An unknown error occurred. Please check your server\'s error logs for more information', |
|
| 152 | - 'event_espresso' |
|
| 153 | - ); |
|
| 154 | - throw new RuntimeException($message); |
|
| 155 | - } |
|
| 156 | - } |
|
| 139 | + /** |
|
| 140 | + * @param $results |
|
| 141 | + * @param string $message |
|
| 142 | + * @throws RuntimeException |
|
| 143 | + * @since $VID:$ |
|
| 144 | + */ |
|
| 145 | + protected static function validateResults($results, $message = '') |
|
| 146 | + { |
|
| 147 | + if (empty($results)) { |
|
| 148 | + $message = $message !== '' |
|
| 149 | + ? $message |
|
| 150 | + : esc_html__( |
|
| 151 | + 'An unknown error occurred. Please check your server\'s error logs for more information', |
|
| 152 | + 'event_espresso' |
|
| 153 | + ); |
|
| 154 | + throw new RuntimeException($message); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | 158 | |
| 159 | - /** |
|
| 160 | - * @param Exception $exception |
|
| 161 | - * @param string $message_prefix |
|
| 162 | - * @throws RuntimeException |
|
| 163 | - * @since $VID:$ |
|
| 164 | - */ |
|
| 165 | - protected static function handleExceptions(Exception $exception, $message_prefix = '') |
|
| 166 | - { |
|
| 167 | - $message_prefix = $message_prefix !== '' |
|
| 168 | - ? $message_prefix |
|
| 169 | - : esc_html__( |
|
| 170 | - 'The mutation could not be executed because of the following error(s)', |
|
| 171 | - 'event_espresso' |
|
| 172 | - ); |
|
| 173 | - throw new RuntimeException( |
|
| 174 | - sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage()) |
|
| 175 | - ); |
|
| 176 | - } |
|
| 159 | + /** |
|
| 160 | + * @param Exception $exception |
|
| 161 | + * @param string $message_prefix |
|
| 162 | + * @throws RuntimeException |
|
| 163 | + * @since $VID:$ |
|
| 164 | + */ |
|
| 165 | + protected static function handleExceptions(Exception $exception, $message_prefix = '') |
|
| 166 | + { |
|
| 167 | + $message_prefix = $message_prefix !== '' |
|
| 168 | + ? $message_prefix |
|
| 169 | + : esc_html__( |
|
| 170 | + 'The mutation could not be executed because of the following error(s)', |
|
| 171 | + 'event_espresso' |
|
| 172 | + ); |
|
| 173 | + throw new RuntimeException( |
|
| 174 | + sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage()) |
|
| 175 | + ); |
|
| 176 | + } |
|
| 177 | 177 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * Stop now if a user isn't allowed to execute mutation |
| 66 | 66 | */ |
| 67 | - if (! current_user_can($capability)) { |
|
| 67 | + if ( ! current_user_can($capability)) { |
|
| 68 | 68 | $model_name = $model->get_this_model_name(); |
| 69 | 69 | $message = sprintf( |
| 70 | 70 | esc_html_x( |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | $entity = $model->get_one_by_ID($ID); |
| 120 | 120 | $model_name = $model->get_this_model_name(); |
| 121 | - $class_name = 'EE_' . $model_name; |
|
| 121 | + $class_name = 'EE_'.$model_name; |
|
| 122 | 122 | if ($entity instanceof $class_name) { |
| 123 | 123 | return $entity; |
| 124 | 124 | } |