@@ -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 | } |
@@ -18,188 +18,188 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class DatetimeConnectionResolver extends AbstractConnectionResolver |
| 20 | 20 | { |
| 21 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 22 | - public function get_loader_name() |
|
| 23 | - { |
|
| 24 | - return 'espresso_datetime'; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @return EEM_Datetime |
|
| 29 | - * @throws EE_Error |
|
| 30 | - * @throws InvalidArgumentException |
|
| 31 | - * @throws InvalidDataTypeException |
|
| 32 | - * @throws InvalidInterfaceException |
|
| 33 | - */ |
|
| 34 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 35 | - public function get_query() |
|
| 36 | - { |
|
| 37 | - return EEM_Datetime::instance(); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Return an array of item IDs from the query |
|
| 42 | - * |
|
| 43 | - * @return array |
|
| 44 | - */ |
|
| 45 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 46 | - public function get_ids() |
|
| 47 | - { |
|
| 48 | - $results = $this->query->get_col($this->query_args); |
|
| 49 | - |
|
| 50 | - return ! empty($results) ? $results : []; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Determine whether the Query should execute. If it's determined that the query should |
|
| 55 | - * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 56 | - * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 57 | - * |
|
| 58 | - * Return false to prevent the query from executing. |
|
| 59 | - * |
|
| 60 | - * @return bool |
|
| 61 | - */ |
|
| 62 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 63 | - public function should_execute() |
|
| 64 | - { |
|
| 65 | - if (false === $this->should_execute) { |
|
| 66 | - return false; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - return $this->should_execute; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
| 74 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
| 75 | - * handle batch resolution of the posts. |
|
| 76 | - * |
|
| 77 | - * @return array |
|
| 78 | - * @throws EE_Error |
|
| 79 | - * @throws InvalidArgumentException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 84 | - public function get_query_args() |
|
| 85 | - { |
|
| 86 | - $where_params = ['DTT_deleted' => ['IN', [true, false]]]; |
|
| 87 | - $query_args = []; |
|
| 88 | - |
|
| 89 | - $query_args['limit'] = $this->getLimit(); |
|
| 90 | - |
|
| 91 | - // Avoid multiple entries by join. |
|
| 92 | - $query_args['group_by'] = 'DTT_ID'; |
|
| 93 | - |
|
| 94 | - $query_args['default_where_conditions'] = 'minimum'; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
| 98 | - */ |
|
| 99 | - $input_fields = []; |
|
| 100 | - if (! empty($this->args['where'])) { |
|
| 101 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
| 102 | - |
|
| 103 | - // Use the proper operator. |
|
| 104 | - if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) { |
|
| 105 | - $input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']]; |
|
| 106 | - } |
|
| 107 | - if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
| 108 | - $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
| 114 | - * |
|
| 115 | - * For example, if we're querying for datetime as a field of event query, this will automatically |
|
| 116 | - * set the query to pull datetimes that belong to that event. |
|
| 117 | - * We can set more cases for other source types. |
|
| 118 | - */ |
|
| 119 | - if (is_object($this->source)) { |
|
| 120 | - switch (true) { |
|
| 121 | - // It's surely an event |
|
| 122 | - case $this->source instanceof Post: |
|
| 123 | - $where_params['EVT_ID'] = $this->source->ID; |
|
| 124 | - break; |
|
| 125 | - case $this->source instanceof EE_Event: |
|
| 126 | - $where_params['EVT_ID'] = $this->source->ID(); |
|
| 127 | - break; |
|
| 128 | - case $this->source instanceof EE_Ticket: |
|
| 129 | - $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
| 130 | - break; |
|
| 131 | - case $this->source instanceof EE_Checkin: |
|
| 132 | - $where_params['Checkin.CHK_ID'] = $this->source->ID(); |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Merge the input_fields with the default query_args |
|
| 139 | - */ |
|
| 140 | - if (! empty($input_fields)) { |
|
| 141 | - $where_params = array_merge($where_params, $input_fields); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID'); |
|
| 145 | - |
|
| 146 | - if (! empty($this->args['where']['upcoming'])) { |
|
| 147 | - $where_params['DTT_EVT_start'] = array( |
|
| 148 | - '>', |
|
| 149 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - if (! empty($this->args['where']['active'])) { |
|
| 154 | - $where_params['DTT_EVT_start'] = array( |
|
| 155 | - '<', |
|
| 156 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 157 | - ); |
|
| 158 | - $where_params['DTT_EVT_end'] = array( |
|
| 159 | - '>', |
|
| 160 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 161 | - ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if (! empty($this->args['where']['expired'])) { |
|
| 165 | - $where_params['DTT_EVT_end'] = array( |
|
| 166 | - '<', |
|
| 167 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 168 | - ); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $query_args[] = $where_params; |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Return the $query_args |
|
| 175 | - */ |
|
| 176 | - return $query_args; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - |
|
| 180 | - /** |
|
| 181 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 182 | - * friendly keys. |
|
| 183 | - * |
|
| 184 | - * @param array $where_args |
|
| 185 | - * @return array |
|
| 186 | - */ |
|
| 187 | - public function sanitizeInputFields(array $where_args) |
|
| 188 | - { |
|
| 189 | - $arg_mapping = [ |
|
| 190 | - 'event' => 'EVT_ID', |
|
| 191 | - 'eventIn' => 'EVT_ID', |
|
| 192 | - 'eventId' => 'EVT_ID', |
|
| 193 | - 'eventIdIn' => 'EVT_ID', |
|
| 194 | - 'ticket' => 'Ticket.TKT_ID', |
|
| 195 | - 'ticketIn' => 'Ticket.TKT_ID', |
|
| 196 | - 'ticketId' => 'Ticket.TKT_ID', |
|
| 197 | - 'ticketIdIn' => 'Ticket.TKT_ID', |
|
| 198 | - ]; |
|
| 199 | - return $this->sanitizeWhereArgsForInputFields( |
|
| 200 | - $where_args, |
|
| 201 | - $arg_mapping, |
|
| 202 | - ['event', 'eventIn', 'ticket', 'ticketIn'] |
|
| 203 | - ); |
|
| 204 | - } |
|
| 21 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 22 | + public function get_loader_name() |
|
| 23 | + { |
|
| 24 | + return 'espresso_datetime'; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @return EEM_Datetime |
|
| 29 | + * @throws EE_Error |
|
| 30 | + * @throws InvalidArgumentException |
|
| 31 | + * @throws InvalidDataTypeException |
|
| 32 | + * @throws InvalidInterfaceException |
|
| 33 | + */ |
|
| 34 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 35 | + public function get_query() |
|
| 36 | + { |
|
| 37 | + return EEM_Datetime::instance(); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Return an array of item IDs from the query |
|
| 42 | + * |
|
| 43 | + * @return array |
|
| 44 | + */ |
|
| 45 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 46 | + public function get_ids() |
|
| 47 | + { |
|
| 48 | + $results = $this->query->get_col($this->query_args); |
|
| 49 | + |
|
| 50 | + return ! empty($results) ? $results : []; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Determine whether the Query should execute. If it's determined that the query should |
|
| 55 | + * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 56 | + * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 57 | + * |
|
| 58 | + * Return false to prevent the query from executing. |
|
| 59 | + * |
|
| 60 | + * @return bool |
|
| 61 | + */ |
|
| 62 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 63 | + public function should_execute() |
|
| 64 | + { |
|
| 65 | + if (false === $this->should_execute) { |
|
| 66 | + return false; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + return $this->should_execute; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
| 74 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
| 75 | + * handle batch resolution of the posts. |
|
| 76 | + * |
|
| 77 | + * @return array |
|
| 78 | + * @throws EE_Error |
|
| 79 | + * @throws InvalidArgumentException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 84 | + public function get_query_args() |
|
| 85 | + { |
|
| 86 | + $where_params = ['DTT_deleted' => ['IN', [true, false]]]; |
|
| 87 | + $query_args = []; |
|
| 88 | + |
|
| 89 | + $query_args['limit'] = $this->getLimit(); |
|
| 90 | + |
|
| 91 | + // Avoid multiple entries by join. |
|
| 92 | + $query_args['group_by'] = 'DTT_ID'; |
|
| 93 | + |
|
| 94 | + $query_args['default_where_conditions'] = 'minimum'; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
| 98 | + */ |
|
| 99 | + $input_fields = []; |
|
| 100 | + if (! empty($this->args['where'])) { |
|
| 101 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
| 102 | + |
|
| 103 | + // Use the proper operator. |
|
| 104 | + if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) { |
|
| 105 | + $input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']]; |
|
| 106 | + } |
|
| 107 | + if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
| 108 | + $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
| 114 | + * |
|
| 115 | + * For example, if we're querying for datetime as a field of event query, this will automatically |
|
| 116 | + * set the query to pull datetimes that belong to that event. |
|
| 117 | + * We can set more cases for other source types. |
|
| 118 | + */ |
|
| 119 | + if (is_object($this->source)) { |
|
| 120 | + switch (true) { |
|
| 121 | + // It's surely an event |
|
| 122 | + case $this->source instanceof Post: |
|
| 123 | + $where_params['EVT_ID'] = $this->source->ID; |
|
| 124 | + break; |
|
| 125 | + case $this->source instanceof EE_Event: |
|
| 126 | + $where_params['EVT_ID'] = $this->source->ID(); |
|
| 127 | + break; |
|
| 128 | + case $this->source instanceof EE_Ticket: |
|
| 129 | + $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
| 130 | + break; |
|
| 131 | + case $this->source instanceof EE_Checkin: |
|
| 132 | + $where_params['Checkin.CHK_ID'] = $this->source->ID(); |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Merge the input_fields with the default query_args |
|
| 139 | + */ |
|
| 140 | + if (! empty($input_fields)) { |
|
| 141 | + $where_params = array_merge($where_params, $input_fields); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID'); |
|
| 145 | + |
|
| 146 | + if (! empty($this->args['where']['upcoming'])) { |
|
| 147 | + $where_params['DTT_EVT_start'] = array( |
|
| 148 | + '>', |
|
| 149 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if (! empty($this->args['where']['active'])) { |
|
| 154 | + $where_params['DTT_EVT_start'] = array( |
|
| 155 | + '<', |
|
| 156 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start') |
|
| 157 | + ); |
|
| 158 | + $where_params['DTT_EVT_end'] = array( |
|
| 159 | + '>', |
|
| 160 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 161 | + ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if (! empty($this->args['where']['expired'])) { |
|
| 165 | + $where_params['DTT_EVT_end'] = array( |
|
| 166 | + '<', |
|
| 167 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end') |
|
| 168 | + ); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $query_args[] = $where_params; |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Return the $query_args |
|
| 175 | + */ |
|
| 176 | + return $query_args; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + |
|
| 180 | + /** |
|
| 181 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 182 | + * friendly keys. |
|
| 183 | + * |
|
| 184 | + * @param array $where_args |
|
| 185 | + * @return array |
|
| 186 | + */ |
|
| 187 | + public function sanitizeInputFields(array $where_args) |
|
| 188 | + { |
|
| 189 | + $arg_mapping = [ |
|
| 190 | + 'event' => 'EVT_ID', |
|
| 191 | + 'eventIn' => 'EVT_ID', |
|
| 192 | + 'eventId' => 'EVT_ID', |
|
| 193 | + 'eventIdIn' => 'EVT_ID', |
|
| 194 | + 'ticket' => 'Ticket.TKT_ID', |
|
| 195 | + 'ticketIn' => 'Ticket.TKT_ID', |
|
| 196 | + 'ticketId' => 'Ticket.TKT_ID', |
|
| 197 | + 'ticketIdIn' => 'Ticket.TKT_ID', |
|
| 198 | + ]; |
|
| 199 | + return $this->sanitizeWhereArgsForInputFields( |
|
| 200 | + $where_args, |
|
| 201 | + $arg_mapping, |
|
| 202 | + ['event', 'eventIn', 'ticket', 'ticketIn'] |
|
| 203 | + ); |
|
| 204 | + } |
|
| 205 | 205 | } |
@@ -15,153 +15,153 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class PriceConnectionResolver extends AbstractConnectionResolver |
| 17 | 17 | { |
| 18 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 19 | - public function get_loader_name() |
|
| 20 | - { |
|
| 21 | - return 'espresso_price'; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @return EEM_Price |
|
| 26 | - * @throws EE_Error |
|
| 27 | - * @throws InvalidArgumentException |
|
| 28 | - * @throws InvalidDataTypeException |
|
| 29 | - * @throws InvalidInterfaceException |
|
| 30 | - */ |
|
| 31 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 32 | - public function get_query() |
|
| 33 | - { |
|
| 34 | - return EEM_Price::instance(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Return an array of item IDs from the query |
|
| 40 | - * |
|
| 41 | - * @return array |
|
| 42 | - */ |
|
| 43 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 44 | - public function get_ids() |
|
| 45 | - { |
|
| 46 | - $results = $this->query->get_col($this->query_args); |
|
| 47 | - |
|
| 48 | - return ! empty($results) ? $results : []; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Determine whether the Query should execute. If it's determined that the query should |
|
| 54 | - * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 55 | - * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 56 | - * Return false to prevent the query from executing. |
|
| 57 | - * |
|
| 58 | - * @return bool |
|
| 59 | - */ |
|
| 60 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 61 | - public function should_execute() |
|
| 62 | - { |
|
| 63 | - if ($this->should_execute === false) { |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $this->should_execute; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
| 73 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
| 74 | - * handle batch resolution of the posts. |
|
| 75 | - * |
|
| 76 | - * @return array |
|
| 77 | - * @throws EE_Error |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - * @throws ReflectionException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 84 | - public function get_query_args() |
|
| 85 | - { |
|
| 86 | - $where_params = []; |
|
| 87 | - $query_args = []; |
|
| 88 | - |
|
| 89 | - $query_args['limit'] = $this->getLimit(); |
|
| 90 | - |
|
| 91 | - // Avoid multiple entries by join. |
|
| 92 | - $query_args['group_by'] = 'PRC_ID'; |
|
| 93 | - |
|
| 94 | - $query_args['default_where_conditions'] = 'minimum'; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
| 98 | - */ |
|
| 99 | - $input_fields = []; |
|
| 100 | - if (! empty($this->args['where'])) { |
|
| 101 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
| 102 | - |
|
| 103 | - // Use the proper operator. |
|
| 104 | - if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
| 105 | - $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
| 106 | - } |
|
| 107 | - if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
| 108 | - $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']]; |
|
| 109 | - } |
|
| 110 | - if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
| 111 | - $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']]; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
| 117 | - */ |
|
| 118 | - if ($this->source instanceof EE_Ticket) { |
|
| 119 | - $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Merge the input_fields with the default query_args |
|
| 124 | - */ |
|
| 125 | - if (! empty($input_fields)) { |
|
| 126 | - $where_params = array_merge($where_params, $input_fields); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID'); |
|
| 130 | - |
|
| 131 | - $query_args[] = $where_params; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Return the $query_args |
|
| 135 | - */ |
|
| 136 | - return $query_args; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 142 | - * friendly keys. |
|
| 143 | - * |
|
| 144 | - * @param array $where_args |
|
| 145 | - * @return array |
|
| 146 | - */ |
|
| 147 | - public function sanitizeInputFields(array $where_args) |
|
| 148 | - { |
|
| 149 | - $arg_mapping = [ |
|
| 150 | - 'ticket' => 'Ticket.TKT_ID', |
|
| 151 | - 'ticketIn' => 'Ticket.TKT_ID', |
|
| 152 | - 'ticketIdIn' => 'Ticket.TKT_ID', |
|
| 153 | - 'ticketId' => 'Ticket.TKT_ID', // priority. |
|
| 154 | - 'priceType' => 'Price_Type.PRT_ID', |
|
| 155 | - 'priceTypeIn' => 'Price_Type.PRT_ID', |
|
| 156 | - 'priceTypeIdIn' => 'Price_Type.PRT_ID', |
|
| 157 | - 'priceTypeId' => 'Price_Type.PRT_ID', // priority. |
|
| 158 | - 'priceBaseType' => 'Price_Type.PBT_ID', |
|
| 159 | - 'priceBaseTypeIn' => 'Price_Type.PBT_ID', |
|
| 160 | - ]; |
|
| 161 | - return $this->sanitizeWhereArgsForInputFields( |
|
| 162 | - $where_args, |
|
| 163 | - $arg_mapping, |
|
| 164 | - ['ticket', 'ticketIn', 'priceType', 'priceTypeIn'] |
|
| 165 | - ); |
|
| 166 | - } |
|
| 18 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 19 | + public function get_loader_name() |
|
| 20 | + { |
|
| 21 | + return 'espresso_price'; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @return EEM_Price |
|
| 26 | + * @throws EE_Error |
|
| 27 | + * @throws InvalidArgumentException |
|
| 28 | + * @throws InvalidDataTypeException |
|
| 29 | + * @throws InvalidInterfaceException |
|
| 30 | + */ |
|
| 31 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 32 | + public function get_query() |
|
| 33 | + { |
|
| 34 | + return EEM_Price::instance(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Return an array of item IDs from the query |
|
| 40 | + * |
|
| 41 | + * @return array |
|
| 42 | + */ |
|
| 43 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 44 | + public function get_ids() |
|
| 45 | + { |
|
| 46 | + $results = $this->query->get_col($this->query_args); |
|
| 47 | + |
|
| 48 | + return ! empty($results) ? $results : []; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Determine whether the Query should execute. If it's determined that the query should |
|
| 54 | + * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 55 | + * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 56 | + * Return false to prevent the query from executing. |
|
| 57 | + * |
|
| 58 | + * @return bool |
|
| 59 | + */ |
|
| 60 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 61 | + public function should_execute() |
|
| 62 | + { |
|
| 63 | + if ($this->should_execute === false) { |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $this->should_execute; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
| 73 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
| 74 | + * handle batch resolution of the posts. |
|
| 75 | + * |
|
| 76 | + * @return array |
|
| 77 | + * @throws EE_Error |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + * @throws ReflectionException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 84 | + public function get_query_args() |
|
| 85 | + { |
|
| 86 | + $where_params = []; |
|
| 87 | + $query_args = []; |
|
| 88 | + |
|
| 89 | + $query_args['limit'] = $this->getLimit(); |
|
| 90 | + |
|
| 91 | + // Avoid multiple entries by join. |
|
| 92 | + $query_args['group_by'] = 'PRC_ID'; |
|
| 93 | + |
|
| 94 | + $query_args['default_where_conditions'] = 'minimum'; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
| 98 | + */ |
|
| 99 | + $input_fields = []; |
|
| 100 | + if (! empty($this->args['where'])) { |
|
| 101 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
| 102 | + |
|
| 103 | + // Use the proper operator. |
|
| 104 | + if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
| 105 | + $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
| 106 | + } |
|
| 107 | + if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
| 108 | + $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']]; |
|
| 109 | + } |
|
| 110 | + if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
| 111 | + $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']]; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
| 117 | + */ |
|
| 118 | + if ($this->source instanceof EE_Ticket) { |
|
| 119 | + $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Merge the input_fields with the default query_args |
|
| 124 | + */ |
|
| 125 | + if (! empty($input_fields)) { |
|
| 126 | + $where_params = array_merge($where_params, $input_fields); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID'); |
|
| 130 | + |
|
| 131 | + $query_args[] = $where_params; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Return the $query_args |
|
| 135 | + */ |
|
| 136 | + return $query_args; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 142 | + * friendly keys. |
|
| 143 | + * |
|
| 144 | + * @param array $where_args |
|
| 145 | + * @return array |
|
| 146 | + */ |
|
| 147 | + public function sanitizeInputFields(array $where_args) |
|
| 148 | + { |
|
| 149 | + $arg_mapping = [ |
|
| 150 | + 'ticket' => 'Ticket.TKT_ID', |
|
| 151 | + 'ticketIn' => 'Ticket.TKT_ID', |
|
| 152 | + 'ticketIdIn' => 'Ticket.TKT_ID', |
|
| 153 | + 'ticketId' => 'Ticket.TKT_ID', // priority. |
|
| 154 | + 'priceType' => 'Price_Type.PRT_ID', |
|
| 155 | + 'priceTypeIn' => 'Price_Type.PRT_ID', |
|
| 156 | + 'priceTypeIdIn' => 'Price_Type.PRT_ID', |
|
| 157 | + 'priceTypeId' => 'Price_Type.PRT_ID', // priority. |
|
| 158 | + 'priceBaseType' => 'Price_Type.PBT_ID', |
|
| 159 | + 'priceBaseTypeIn' => 'Price_Type.PBT_ID', |
|
| 160 | + ]; |
|
| 161 | + return $this->sanitizeWhereArgsForInputFields( |
|
| 162 | + $where_args, |
|
| 163 | + $arg_mapping, |
|
| 164 | + ['ticket', 'ticketIn', 'priceType', 'priceTypeIn'] |
|
| 165 | + ); |
|
| 166 | + } |
|
| 167 | 167 | } |
@@ -15,141 +15,141 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class TicketConnectionResolver extends AbstractConnectionResolver |
| 17 | 17 | { |
| 18 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 19 | - public function get_loader_name() |
|
| 20 | - { |
|
| 21 | - return 'espresso_ticket'; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @return EEM_Ticket |
|
| 26 | - * @throws EE_Error |
|
| 27 | - * @throws InvalidArgumentException |
|
| 28 | - * @throws InvalidDataTypeException |
|
| 29 | - * @throws InvalidInterfaceException |
|
| 30 | - */ |
|
| 31 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 32 | - public function get_query() |
|
| 33 | - { |
|
| 34 | - return EEM_Ticket::instance(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Return an array of item IDs from the query |
|
| 40 | - * |
|
| 41 | - * @return array |
|
| 42 | - */ |
|
| 43 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 44 | - public function get_ids() |
|
| 45 | - { |
|
| 46 | - $results = $this->query->get_col($this->query_args); |
|
| 47 | - |
|
| 48 | - return ! empty($results) ? $results : []; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Determine whether the Query should execute. If it's determined that the query should |
|
| 54 | - * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 55 | - * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 56 | - * Return false to prevent the query from executing. |
|
| 57 | - * |
|
| 58 | - * @return bool |
|
| 59 | - */ |
|
| 60 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 61 | - public function should_execute() |
|
| 62 | - { |
|
| 63 | - if (false === $this->should_execute) { |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $this->should_execute; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
| 73 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
| 74 | - * handle batch resolution of the posts. |
|
| 75 | - * |
|
| 76 | - * @return array |
|
| 77 | - * @throws EE_Error |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - * @throws ReflectionException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 84 | - public function get_query_args() |
|
| 85 | - { |
|
| 86 | - $where_params = ['TKT_deleted' => ['IN', [true, false]]]; |
|
| 87 | - $query_args = []; |
|
| 88 | - |
|
| 89 | - $query_args['limit'] = $this->getLimit(); |
|
| 90 | - |
|
| 91 | - // Avoid multiple entries by join. |
|
| 92 | - $query_args['group_by'] = 'TKT_ID'; |
|
| 93 | - |
|
| 94 | - $query_args['default_where_conditions'] = 'minimum'; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
| 98 | - */ |
|
| 99 | - $input_fields = []; |
|
| 100 | - if (! empty($this->args['where'])) { |
|
| 101 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
| 102 | - |
|
| 103 | - // Use the proper operator. |
|
| 104 | - if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) { |
|
| 105 | - $input_fields['Datetime.DTT_ID'] = ['in', $input_fields['Datetime.DTT_ID']]; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
| 111 | - */ |
|
| 112 | - if ($this->source instanceof EE_Datetime) { |
|
| 113 | - $where_params['Datetime.DTT_ID'] = $this->source->ID(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Merge the input_fields with the default query_args |
|
| 118 | - */ |
|
| 119 | - if (! empty($input_fields)) { |
|
| 120 | - $where_params = array_merge($where_params, $input_fields); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'TKT_ID'); |
|
| 124 | - |
|
| 125 | - $query_args[] = $where_params; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Return the $query_args |
|
| 129 | - */ |
|
| 130 | - return $query_args; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 136 | - * friendly keys. |
|
| 137 | - * |
|
| 138 | - * @param array $where_args |
|
| 139 | - * @return array |
|
| 140 | - */ |
|
| 141 | - public function sanitizeInputFields(array $where_args) |
|
| 142 | - { |
|
| 143 | - $arg_mapping = [ |
|
| 144 | - 'datetime' => 'Datetime.DTT_ID', |
|
| 145 | - 'datetimeIn' => 'Datetime.DTT_ID', |
|
| 146 | - 'datetimeIdIn' => 'Datetime.DTT_ID', |
|
| 147 | - 'datetimeId' => 'Datetime.DTT_ID', // priority. |
|
| 148 | - ]; |
|
| 149 | - return $this->sanitizeWhereArgsForInputFields( |
|
| 150 | - $where_args, |
|
| 151 | - $arg_mapping, |
|
| 152 | - ['datetime', 'datetimeIn'] |
|
| 153 | - ); |
|
| 154 | - } |
|
| 18 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 19 | + public function get_loader_name() |
|
| 20 | + { |
|
| 21 | + return 'espresso_ticket'; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @return EEM_Ticket |
|
| 26 | + * @throws EE_Error |
|
| 27 | + * @throws InvalidArgumentException |
|
| 28 | + * @throws InvalidDataTypeException |
|
| 29 | + * @throws InvalidInterfaceException |
|
| 30 | + */ |
|
| 31 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 32 | + public function get_query() |
|
| 33 | + { |
|
| 34 | + return EEM_Ticket::instance(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Return an array of item IDs from the query |
|
| 40 | + * |
|
| 41 | + * @return array |
|
| 42 | + */ |
|
| 43 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 44 | + public function get_ids() |
|
| 45 | + { |
|
| 46 | + $results = $this->query->get_col($this->query_args); |
|
| 47 | + |
|
| 48 | + return ! empty($results) ? $results : []; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Determine whether the Query should execute. If it's determined that the query should |
|
| 54 | + * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 55 | + * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 56 | + * Return false to prevent the query from executing. |
|
| 57 | + * |
|
| 58 | + * @return bool |
|
| 59 | + */ |
|
| 60 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 61 | + public function should_execute() |
|
| 62 | + { |
|
| 63 | + if (false === $this->should_execute) { |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $this->should_execute; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
| 73 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
| 74 | + * handle batch resolution of the posts. |
|
| 75 | + * |
|
| 76 | + * @return array |
|
| 77 | + * @throws EE_Error |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + * @throws ReflectionException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 84 | + public function get_query_args() |
|
| 85 | + { |
|
| 86 | + $where_params = ['TKT_deleted' => ['IN', [true, false]]]; |
|
| 87 | + $query_args = []; |
|
| 88 | + |
|
| 89 | + $query_args['limit'] = $this->getLimit(); |
|
| 90 | + |
|
| 91 | + // Avoid multiple entries by join. |
|
| 92 | + $query_args['group_by'] = 'TKT_ID'; |
|
| 93 | + |
|
| 94 | + $query_args['default_where_conditions'] = 'minimum'; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
| 98 | + */ |
|
| 99 | + $input_fields = []; |
|
| 100 | + if (! empty($this->args['where'])) { |
|
| 101 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
| 102 | + |
|
| 103 | + // Use the proper operator. |
|
| 104 | + if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) { |
|
| 105 | + $input_fields['Datetime.DTT_ID'] = ['in', $input_fields['Datetime.DTT_ID']]; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
| 111 | + */ |
|
| 112 | + if ($this->source instanceof EE_Datetime) { |
|
| 113 | + $where_params['Datetime.DTT_ID'] = $this->source->ID(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Merge the input_fields with the default query_args |
|
| 118 | + */ |
|
| 119 | + if (! empty($input_fields)) { |
|
| 120 | + $where_params = array_merge($where_params, $input_fields); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'TKT_ID'); |
|
| 124 | + |
|
| 125 | + $query_args[] = $where_params; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Return the $query_args |
|
| 129 | + */ |
|
| 130 | + return $query_args; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 136 | + * friendly keys. |
|
| 137 | + * |
|
| 138 | + * @param array $where_args |
|
| 139 | + * @return array |
|
| 140 | + */ |
|
| 141 | + public function sanitizeInputFields(array $where_args) |
|
| 142 | + { |
|
| 143 | + $arg_mapping = [ |
|
| 144 | + 'datetime' => 'Datetime.DTT_ID', |
|
| 145 | + 'datetimeIn' => 'Datetime.DTT_ID', |
|
| 146 | + 'datetimeIdIn' => 'Datetime.DTT_ID', |
|
| 147 | + 'datetimeId' => 'Datetime.DTT_ID', // priority. |
|
| 148 | + ]; |
|
| 149 | + return $this->sanitizeWhereArgsForInputFields( |
|
| 150 | + $where_args, |
|
| 151 | + $arg_mapping, |
|
| 152 | + ['datetime', 'datetimeIn'] |
|
| 153 | + ); |
|
| 154 | + } |
|
| 155 | 155 | } |