@@ -13,64 +13,64 @@ |
||
| 13 | 13 | class TicketUpdate 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 | - * 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_Ticket $entity */ |
|
| 36 | - $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
| 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 | + * 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_Ticket $entity */ |
|
| 36 | + $entity = EntityMutator::getEntityFromInputData($model, $input); |
|
| 37 | 37 | |
| 38 | - $datetimes = []; |
|
| 39 | - $prices = null; |
|
| 38 | + $datetimes = []; |
|
| 39 | + $prices = null; |
|
| 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 (array_key_exists('prices', $args)) { |
|
| 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 (array_key_exists('prices', $args)) { |
|
| 48 | + $prices = $args['prices']; |
|
| 49 | + unset($args['prices']); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $entity->save($args); |
|
| 52 | + $entity->save($args); |
|
| 53 | 53 | |
| 54 | - if (! empty($datetimes)) { |
|
| 55 | - TicketMutation::setRelatedDatetimes($entity, $datetimes); |
|
| 56 | - } |
|
| 57 | - // if prices array is passed. |
|
| 58 | - if (is_array($prices)) { |
|
| 59 | - TicketMutation::setRelatedPrices($entity, $prices); |
|
| 60 | - } |
|
| 61 | - } catch (Exception $exception) { |
|
| 62 | - EntityMutator::handleExceptions( |
|
| 63 | - $exception, |
|
| 64 | - esc_html__( |
|
| 65 | - 'The ticket could not be deleted because of the following error(s)', |
|
| 66 | - 'event_espresso' |
|
| 67 | - ) |
|
| 68 | - ); |
|
| 69 | - } |
|
| 54 | + if (! empty($datetimes)) { |
|
| 55 | + TicketMutation::setRelatedDatetimes($entity, $datetimes); |
|
| 56 | + } |
|
| 57 | + // if prices array is passed. |
|
| 58 | + if (is_array($prices)) { |
|
| 59 | + TicketMutation::setRelatedPrices($entity, $prices); |
|
| 60 | + } |
|
| 61 | + } catch (Exception $exception) { |
|
| 62 | + EntityMutator::handleExceptions( |
|
| 63 | + $exception, |
|
| 64 | + esc_html__( |
|
| 65 | + 'The ticket could not be deleted because of the following error(s)', |
|
| 66 | + 'event_espresso' |
|
| 67 | + ) |
|
| 68 | + ); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return [ |
|
| 72 | - 'id' => $entity->ID(), |
|
| 73 | - ]; |
|
| 74 | - }; |
|
| 75 | - } |
|
| 71 | + return [ |
|
| 72 | + 'id' => $entity->ID(), |
|
| 73 | + ]; |
|
| 74 | + }; |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -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 | /** @var EE_Ticket $entity */ |
| 36 | 36 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | |
| 52 | 52 | $entity->save($args); |
| 53 | 53 | |
| 54 | - if (! empty($datetimes)) { |
|
| 54 | + if ( ! empty($datetimes)) { |
|
| 55 | 55 | TicketMutation::setRelatedDatetimes($entity, $datetimes); |
| 56 | 56 | } |
| 57 | 57 | // if prices array is passed. |
@@ -24,189 +24,189 @@ |
||
| 24 | 24 | class TicketMutation |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Maps the GraphQL input to a format that the model functions can use |
|
| 29 | - * |
|
| 30 | - * @param array $input Data coming from the GraphQL mutation query input |
|
| 31 | - * @return array |
|
| 32 | - * @throws Exception |
|
| 33 | - */ |
|
| 34 | - public static function prepareFields(array $input) |
|
| 35 | - { |
|
| 36 | - $args = []; |
|
| 37 | - |
|
| 38 | - if (! empty($input['datetimes'])) { |
|
| 39 | - $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - if (! empty($input['description'])) { |
|
| 43 | - $args['TKT_description'] = sanitize_text_field($input['description']); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (! empty($input['endDate'])) { |
|
| 47 | - $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (array_key_exists('isDefault', $input)) { |
|
| 51 | - $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (array_key_exists('isRequired', $input)) { |
|
| 55 | - $args['TKT_required'] = (bool) $input['isRequired']; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (array_key_exists('isTaxable', $input)) { |
|
| 59 | - $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - if (array_key_exists('isTrashed', $input)) { |
|
| 63 | - $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - if (array_key_exists('max', $input)) { |
|
| 67 | - $args['TKT_max'] = (int) $input['max']; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (array_key_exists('min', $input)) { |
|
| 71 | - $args['TKT_min'] = (int) $input['min']; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if (! empty($input['name'])) { |
|
| 75 | - $args['TKT_name'] = sanitize_text_field($input['name']); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if (array_key_exists('order', $input)) { |
|
| 79 | - $args['TKT_order'] = (int) $input['order']; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if (! empty($input['parent'])) { |
|
| 83 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
| 84 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // price can be 0 |
|
| 88 | - if (array_key_exists('price', $input)) { |
|
| 89 | - $args['TKT_price'] = (float) $input['price']; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // prices can be an empty array when all prices are deleted |
|
| 93 | - if (array_key_exists('prices', $input) && is_array($input['prices'])) { |
|
| 94 | - $args['prices'] = array_map('sanitize_text_field', $input['prices']); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (array_key_exists('quantity', $input)) { |
|
| 98 | - $args['TKT_qty'] = (int) $input['quantity']; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if (array_key_exists('reserved', $input)) { |
|
| 102 | - $args['TKT_reserved'] = (int) $input['reserved']; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - if (array_key_exists('reverseCalculate', $input)) { |
|
| 106 | - $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if (array_key_exists('row', $input)) { |
|
| 110 | - $args['TKT_row'] = (int) $input['row']; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if (array_key_exists('sold', $input)) { |
|
| 114 | - $args['TKT_sold'] = (int) $input['sold']; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if (! empty($input['startDate'])) { |
|
| 118 | - $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if (array_key_exists('uses', $input)) { |
|
| 122 | - $args['TKT_uses'] = (int) $input['uses']; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (! empty($input['wpUser'])) { |
|
| 126 | - $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
| 127 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return $args; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Sets the related datetimes for the given ticket. |
|
| 136 | - * |
|
| 137 | - * @param EE_Ticket $entity The Ticket instance. |
|
| 138 | - * @param array $datetimes Array of datetime IDs to relate. |
|
| 139 | - * @throws EE_Error |
|
| 140 | - * @throws InvalidArgumentException |
|
| 141 | - * @throws InvalidDataTypeException |
|
| 142 | - * @throws InvalidInterfaceException |
|
| 143 | - * @throws ReflectionException |
|
| 144 | - */ |
|
| 145 | - public static function setRelatedDatetimes($entity, array $datetimes) |
|
| 146 | - { |
|
| 147 | - $relationName = 'Datetime'; |
|
| 148 | - // Remove all the existing related datetimes |
|
| 149 | - |
|
| 150 | - $entity->_remove_relations($relationName); |
|
| 151 | - // @todo replace loop with single query |
|
| 152 | - foreach ($datetimes as $ID) { |
|
| 153 | - $parts = Relay::fromGlobalId($ID); |
|
| 154 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
| 155 | - $entity->_add_relation_to( |
|
| 156 | - $parts['id'], |
|
| 157 | - $relationName |
|
| 158 | - ); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Sets the related prices for the given ticket. |
|
| 166 | - * |
|
| 167 | - * @param EE_Ticket $entity The Ticket instance. |
|
| 168 | - * @param array $prices Array of entity IDs to relate. |
|
| 169 | - * @throws EE_Error |
|
| 170 | - * @throws InvalidArgumentException |
|
| 171 | - * @throws InvalidDataTypeException |
|
| 172 | - * @throws InvalidInterfaceException |
|
| 173 | - * @throws ReflectionException |
|
| 174 | - */ |
|
| 175 | - public static function setRelatedPrices($entity, array $prices) |
|
| 176 | - { |
|
| 177 | - $relationName = 'Price'; |
|
| 178 | - // Remove all the existing related entities |
|
| 179 | - $entity->_remove_relations($relationName); |
|
| 180 | - |
|
| 181 | - // @todo replace loop with single query |
|
| 182 | - foreach ($prices as $ID) { |
|
| 183 | - $parts = Relay::fromGlobalId($ID); |
|
| 184 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
| 185 | - $entity->_add_relation_to( |
|
| 186 | - $parts['id'], |
|
| 187 | - $relationName |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @param EE_Ticket $ticket_entity |
|
| 196 | - * @param EEM_Ticket $ticket_model |
|
| 197 | - * @throws EE_Error |
|
| 198 | - * @throws InvalidArgumentException |
|
| 199 | - * @throws InvalidDataTypeException |
|
| 200 | - * @throws InvalidInterfaceException |
|
| 201 | - * @throws ReflectionException |
|
| 202 | - * @since $VID:$ |
|
| 203 | - */ |
|
| 204 | - public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model) |
|
| 205 | - { |
|
| 206 | - /** @var DefaultPrices $default_prices */ |
|
| 207 | - $default_prices = LoaderFactory::getLoader()->getShared( |
|
| 208 | - 'EventEspresso\core\domain\services\admin\entities\DefaultPrices' |
|
| 209 | - ); |
|
| 210 | - $default_prices->create($ticket_entity); |
|
| 211 | - } |
|
| 27 | + /** |
|
| 28 | + * Maps the GraphQL input to a format that the model functions can use |
|
| 29 | + * |
|
| 30 | + * @param array $input Data coming from the GraphQL mutation query input |
|
| 31 | + * @return array |
|
| 32 | + * @throws Exception |
|
| 33 | + */ |
|
| 34 | + public static function prepareFields(array $input) |
|
| 35 | + { |
|
| 36 | + $args = []; |
|
| 37 | + |
|
| 38 | + if (! empty($input['datetimes'])) { |
|
| 39 | + $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + if (! empty($input['description'])) { |
|
| 43 | + $args['TKT_description'] = sanitize_text_field($input['description']); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (! empty($input['endDate'])) { |
|
| 47 | + $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (array_key_exists('isDefault', $input)) { |
|
| 51 | + $args['TKT_is_default'] = (bool) $input['isDefault']; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (array_key_exists('isRequired', $input)) { |
|
| 55 | + $args['TKT_required'] = (bool) $input['isRequired']; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (array_key_exists('isTaxable', $input)) { |
|
| 59 | + $args['TKT_taxable'] = (bool) $input['isTaxable']; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + if (array_key_exists('isTrashed', $input)) { |
|
| 63 | + $args['TKT_deleted'] = (bool) $input['isTrashed']; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + if (array_key_exists('max', $input)) { |
|
| 67 | + $args['TKT_max'] = (int) $input['max']; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (array_key_exists('min', $input)) { |
|
| 71 | + $args['TKT_min'] = (int) $input['min']; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if (! empty($input['name'])) { |
|
| 75 | + $args['TKT_name'] = sanitize_text_field($input['name']); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if (array_key_exists('order', $input)) { |
|
| 79 | + $args['TKT_order'] = (int) $input['order']; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if (! empty($input['parent'])) { |
|
| 83 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
|
| 84 | + $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // price can be 0 |
|
| 88 | + if (array_key_exists('price', $input)) { |
|
| 89 | + $args['TKT_price'] = (float) $input['price']; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // prices can be an empty array when all prices are deleted |
|
| 93 | + if (array_key_exists('prices', $input) && is_array($input['prices'])) { |
|
| 94 | + $args['prices'] = array_map('sanitize_text_field', $input['prices']); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (array_key_exists('quantity', $input)) { |
|
| 98 | + $args['TKT_qty'] = (int) $input['quantity']; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if (array_key_exists('reserved', $input)) { |
|
| 102 | + $args['TKT_reserved'] = (int) $input['reserved']; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + if (array_key_exists('reverseCalculate', $input)) { |
|
| 106 | + $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate']; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if (array_key_exists('row', $input)) { |
|
| 110 | + $args['TKT_row'] = (int) $input['row']; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if (array_key_exists('sold', $input)) { |
|
| 114 | + $args['TKT_sold'] = (int) $input['sold']; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if (! empty($input['startDate'])) { |
|
| 118 | + $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if (array_key_exists('uses', $input)) { |
|
| 122 | + $args['TKT_uses'] = (int) $input['uses']; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (! empty($input['wpUser'])) { |
|
| 126 | + $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
|
| 127 | + $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return $args; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Sets the related datetimes for the given ticket. |
|
| 136 | + * |
|
| 137 | + * @param EE_Ticket $entity The Ticket instance. |
|
| 138 | + * @param array $datetimes Array of datetime IDs to relate. |
|
| 139 | + * @throws EE_Error |
|
| 140 | + * @throws InvalidArgumentException |
|
| 141 | + * @throws InvalidDataTypeException |
|
| 142 | + * @throws InvalidInterfaceException |
|
| 143 | + * @throws ReflectionException |
|
| 144 | + */ |
|
| 145 | + public static function setRelatedDatetimes($entity, array $datetimes) |
|
| 146 | + { |
|
| 147 | + $relationName = 'Datetime'; |
|
| 148 | + // Remove all the existing related datetimes |
|
| 149 | + |
|
| 150 | + $entity->_remove_relations($relationName); |
|
| 151 | + // @todo replace loop with single query |
|
| 152 | + foreach ($datetimes as $ID) { |
|
| 153 | + $parts = Relay::fromGlobalId($ID); |
|
| 154 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
| 155 | + $entity->_add_relation_to( |
|
| 156 | + $parts['id'], |
|
| 157 | + $relationName |
|
| 158 | + ); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Sets the related prices for the given ticket. |
|
| 166 | + * |
|
| 167 | + * @param EE_Ticket $entity The Ticket instance. |
|
| 168 | + * @param array $prices Array of entity IDs to relate. |
|
| 169 | + * @throws EE_Error |
|
| 170 | + * @throws InvalidArgumentException |
|
| 171 | + * @throws InvalidDataTypeException |
|
| 172 | + * @throws InvalidInterfaceException |
|
| 173 | + * @throws ReflectionException |
|
| 174 | + */ |
|
| 175 | + public static function setRelatedPrices($entity, array $prices) |
|
| 176 | + { |
|
| 177 | + $relationName = 'Price'; |
|
| 178 | + // Remove all the existing related entities |
|
| 179 | + $entity->_remove_relations($relationName); |
|
| 180 | + |
|
| 181 | + // @todo replace loop with single query |
|
| 182 | + foreach ($prices as $ID) { |
|
| 183 | + $parts = Relay::fromGlobalId($ID); |
|
| 184 | + if (! empty($parts['id']) && absint($parts['id'])) { |
|
| 185 | + $entity->_add_relation_to( |
|
| 186 | + $parts['id'], |
|
| 187 | + $relationName |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @param EE_Ticket $ticket_entity |
|
| 196 | + * @param EEM_Ticket $ticket_model |
|
| 197 | + * @throws EE_Error |
|
| 198 | + * @throws InvalidArgumentException |
|
| 199 | + * @throws InvalidDataTypeException |
|
| 200 | + * @throws InvalidInterfaceException |
|
| 201 | + * @throws ReflectionException |
|
| 202 | + * @since $VID:$ |
|
| 203 | + */ |
|
| 204 | + public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model) |
|
| 205 | + { |
|
| 206 | + /** @var DefaultPrices $default_prices */ |
|
| 207 | + $default_prices = LoaderFactory::getLoader()->getShared( |
|
| 208 | + 'EventEspresso\core\domain\services\admin\entities\DefaultPrices' |
|
| 209 | + ); |
|
| 210 | + $default_prices->create($ticket_entity); |
|
| 211 | + } |
|
| 212 | 212 | } |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | $args = []; |
| 37 | 37 | |
| 38 | - if (! empty($input['datetimes'])) { |
|
| 38 | + if ( ! empty($input['datetimes'])) { |
|
| 39 | 39 | $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']); |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - if (! empty($input['description'])) { |
|
| 42 | + if ( ! empty($input['description'])) { |
|
| 43 | 43 | $args['TKT_description'] = sanitize_text_field($input['description']); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - if (! empty($input['endDate'])) { |
|
| 46 | + if ( ! empty($input['endDate'])) { |
|
| 47 | 47 | $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate'])); |
| 48 | 48 | } |
| 49 | 49 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | $args['TKT_min'] = (int) $input['min']; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - if (! empty($input['name'])) { |
|
| 74 | + if ( ! empty($input['name'])) { |
|
| 75 | 75 | $args['TKT_name'] = sanitize_text_field($input['name']); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | $args['TKT_order'] = (int) $input['order']; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if (! empty($input['parent'])) { |
|
| 82 | + if ( ! empty($input['parent'])) { |
|
| 83 | 83 | $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
| 84 | - $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
| 84 | + $args['TKT_parent'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // price can be 0 |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $args['TKT_sold'] = (int) $input['sold']; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - if (! empty($input['startDate'])) { |
|
| 117 | + if ( ! empty($input['startDate'])) { |
|
| 118 | 118 | $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate'])); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | $args['TKT_uses'] = (int) $input['uses']; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if (! empty($input['wpUser'])) { |
|
| 125 | + if ( ! empty($input['wpUser'])) { |
|
| 126 | 126 | $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
| 127 | - $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
| 127 | + $args['TKT_wp_user'] = ( ! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | return $args; |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | // @todo replace loop with single query |
| 152 | 152 | foreach ($datetimes as $ID) { |
| 153 | 153 | $parts = Relay::fromGlobalId($ID); |
| 154 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
| 154 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
| 155 | 155 | $entity->_add_relation_to( |
| 156 | 156 | $parts['id'], |
| 157 | 157 | $relationName |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | // @todo replace loop with single query |
| 182 | 182 | foreach ($prices as $ID) { |
| 183 | 183 | $parts = Relay::fromGlobalId($ID); |
| 184 | - if (! empty($parts['id']) && absint($parts['id'])) { |
|
| 184 | + if ( ! empty($parts['id']) && absint($parts['id'])) { |
|
| 185 | 185 | $entity->_add_relation_to( |
| 186 | 186 | $parts['id'], |
| 187 | 187 | $relationName |