@@ -25,126 +25,126 @@ |
||
| 25 | 25 | class DefaultPrices implements DefaultEntityGeneratorInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var EEM_Price $price_model |
|
| 30 | - */ |
|
| 31 | - protected $price_model; |
|
| 28 | + /** |
|
| 29 | + * @var EEM_Price $price_model |
|
| 30 | + */ |
|
| 31 | + protected $price_model; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var EEM_Price_Type $price_type_model |
|
| 35 | - */ |
|
| 36 | - protected $price_type_model; |
|
| 33 | + /** |
|
| 34 | + * @var EEM_Price_Type $price_type_model |
|
| 35 | + */ |
|
| 36 | + protected $price_type_model; |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param EEM_Price $price_model |
|
| 41 | - * @param EEM_Price_Type $price_type_model |
|
| 42 | - */ |
|
| 43 | - public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model) |
|
| 44 | - { |
|
| 45 | - $this->price_model = $price_model; |
|
| 46 | - $this->price_type_model = $price_type_model; |
|
| 47 | - } |
|
| 39 | + /** |
|
| 40 | + * @param EEM_Price $price_model |
|
| 41 | + * @param EEM_Price_Type $price_type_model |
|
| 42 | + */ |
|
| 43 | + public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model) |
|
| 44 | + { |
|
| 45 | + $this->price_model = $price_model; |
|
| 46 | + $this->price_type_model = $price_type_model; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param EE_Ticket|EE_Base_Class $entity |
|
| 52 | - * @return EE_Price[] |
|
| 53 | - * @throws EE_Error |
|
| 54 | - * @throws InvalidInterfaceException |
|
| 55 | - * @throws ReflectionException |
|
| 56 | - * @since $VID:$ |
|
| 57 | - */ |
|
| 58 | - public function create(EE_Base_Class $entity) |
|
| 59 | - { |
|
| 60 | - if (! $entity instanceof EE_Ticket) { |
|
| 61 | - throw new InvalidEntityException($entity, 'EE_Ticket'); |
|
| 62 | - } |
|
| 63 | - $taxes = []; |
|
| 64 | - $new_prices = []; |
|
| 65 | - $is_free = true; |
|
| 66 | - $has_base_price = false; |
|
| 67 | - $default_prices = $this->price_model->get_all_default_prices(false, true); |
|
| 68 | - if (is_array($default_prices)) { |
|
| 69 | - foreach ($default_prices as $default_price) { |
|
| 70 | - if (! $default_price instanceof EE_Price) { |
|
| 71 | - throw new InvalidEntityException($default_price, 'EE_Price'); |
|
| 72 | - } |
|
| 73 | - // grab any taxes but don't do anything just yet |
|
| 74 | - if ($default_price->is_tax()) { |
|
| 75 | - $taxes[] = $default_price; |
|
| 76 | - continue; |
|
| 77 | - } |
|
| 78 | - // duplicate the default price so that it does not get mutated |
|
| 79 | - /** @var EE_Price $default_price_clone */ |
|
| 80 | - $default_price_clone = clone $default_price; |
|
| 81 | - if (( |
|
| 82 | - // has non-zero base price |
|
| 83 | - $default_price_clone->is_base_price() |
|
| 84 | - && $default_price_clone->amount() > 0 |
|
| 85 | - ) ||( |
|
| 86 | - // or has fixed amount surcharge |
|
| 87 | - $default_price_clone->is_surcharge() |
|
| 88 | - && ! $default_price_clone->is_percent() |
|
| 89 | - )) { |
|
| 90 | - $is_free = false; |
|
| 91 | - } |
|
| 92 | - $default_price_clone->set('PRC_ID', null); |
|
| 93 | - $default_price_clone->set('PRC_is_default', false); |
|
| 94 | - $default_price_clone->save(); |
|
| 95 | - $default_price_clone->_add_relation_to($entity, 'Ticket'); |
|
| 96 | - // verify that a base price has been set |
|
| 97 | - $has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price; |
|
| 98 | - $new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - if (! $is_free && ! empty($taxes)) { |
|
| 102 | - foreach ($taxes as $tax) { |
|
| 103 | - // assign taxes but don't duplicate them because they operate globally |
|
| 104 | - $entity->set_taxable(true); |
|
| 105 | - $tax->_add_relation_to($entity, 'Ticket'); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - if (! $has_base_price) { |
|
| 109 | - $new_base_price = $this->createNewBasePrice($entity); |
|
| 110 | - $new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
| 111 | - } |
|
| 112 | - $ticket_total = $entity->get_ticket_total_with_taxes(true); |
|
| 113 | - if ($ticket_total !== $entity->ticket_price()) { |
|
| 114 | - $entity->set_price($ticket_total); |
|
| 115 | - $entity->save(); |
|
| 116 | - } |
|
| 117 | - return $new_prices; |
|
| 118 | - } |
|
| 50 | + /** |
|
| 51 | + * @param EE_Ticket|EE_Base_Class $entity |
|
| 52 | + * @return EE_Price[] |
|
| 53 | + * @throws EE_Error |
|
| 54 | + * @throws InvalidInterfaceException |
|
| 55 | + * @throws ReflectionException |
|
| 56 | + * @since $VID:$ |
|
| 57 | + */ |
|
| 58 | + public function create(EE_Base_Class $entity) |
|
| 59 | + { |
|
| 60 | + if (! $entity instanceof EE_Ticket) { |
|
| 61 | + throw new InvalidEntityException($entity, 'EE_Ticket'); |
|
| 62 | + } |
|
| 63 | + $taxes = []; |
|
| 64 | + $new_prices = []; |
|
| 65 | + $is_free = true; |
|
| 66 | + $has_base_price = false; |
|
| 67 | + $default_prices = $this->price_model->get_all_default_prices(false, true); |
|
| 68 | + if (is_array($default_prices)) { |
|
| 69 | + foreach ($default_prices as $default_price) { |
|
| 70 | + if (! $default_price instanceof EE_Price) { |
|
| 71 | + throw new InvalidEntityException($default_price, 'EE_Price'); |
|
| 72 | + } |
|
| 73 | + // grab any taxes but don't do anything just yet |
|
| 74 | + if ($default_price->is_tax()) { |
|
| 75 | + $taxes[] = $default_price; |
|
| 76 | + continue; |
|
| 77 | + } |
|
| 78 | + // duplicate the default price so that it does not get mutated |
|
| 79 | + /** @var EE_Price $default_price_clone */ |
|
| 80 | + $default_price_clone = clone $default_price; |
|
| 81 | + if (( |
|
| 82 | + // has non-zero base price |
|
| 83 | + $default_price_clone->is_base_price() |
|
| 84 | + && $default_price_clone->amount() > 0 |
|
| 85 | + ) ||( |
|
| 86 | + // or has fixed amount surcharge |
|
| 87 | + $default_price_clone->is_surcharge() |
|
| 88 | + && ! $default_price_clone->is_percent() |
|
| 89 | + )) { |
|
| 90 | + $is_free = false; |
|
| 91 | + } |
|
| 92 | + $default_price_clone->set('PRC_ID', null); |
|
| 93 | + $default_price_clone->set('PRC_is_default', false); |
|
| 94 | + $default_price_clone->save(); |
|
| 95 | + $default_price_clone->_add_relation_to($entity, 'Ticket'); |
|
| 96 | + // verify that a base price has been set |
|
| 97 | + $has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price; |
|
| 98 | + $new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + if (! $is_free && ! empty($taxes)) { |
|
| 102 | + foreach ($taxes as $tax) { |
|
| 103 | + // assign taxes but don't duplicate them because they operate globally |
|
| 104 | + $entity->set_taxable(true); |
|
| 105 | + $tax->_add_relation_to($entity, 'Ticket'); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + if (! $has_base_price) { |
|
| 109 | + $new_base_price = $this->createNewBasePrice($entity); |
|
| 110 | + $new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
| 111 | + } |
|
| 112 | + $ticket_total = $entity->get_ticket_total_with_taxes(true); |
|
| 113 | + if ($ticket_total !== $entity->ticket_price()) { |
|
| 114 | + $entity->set_price($ticket_total); |
|
| 115 | + $entity->save(); |
|
| 116 | + } |
|
| 117 | + return $new_prices; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * @param EE_Ticket $ticket |
|
| 123 | - * @return EE_Price |
|
| 124 | - * @throws EE_Error |
|
| 125 | - * @throws ReflectionException |
|
| 126 | - * @since $VID:$ |
|
| 127 | - */ |
|
| 128 | - protected function createNewBasePrice(EE_Ticket $ticket) |
|
| 129 | - { |
|
| 130 | - $new_base_price = $this->price_model->get_new_price(); |
|
| 131 | - $base_price_type = $this->price_type_model->get_one([ |
|
| 132 | - [ |
|
| 133 | - 'PBT_ID' => EEM_Price_Type::base_type_base_price |
|
| 134 | - ] |
|
| 135 | - ]); |
|
| 136 | - if (! $base_price_type instanceof EE_Price_Type) { |
|
| 137 | - throw new RuntimeException( |
|
| 138 | - esc_html__( |
|
| 139 | - 'A valid base price type could not be retrieved from the database.', |
|
| 140 | - 'event_espresso' |
|
| 141 | - ) |
|
| 142 | - ); |
|
| 143 | - } |
|
| 144 | - $new_base_price->set('PRT_ID', $base_price_type->ID()); |
|
| 145 | - $new_base_price->set('PRC_is_default', false); |
|
| 146 | - $new_base_price->save(); |
|
| 147 | - $new_base_price->_add_relation_to($ticket, 'Ticket'); |
|
| 148 | - return $new_base_price; |
|
| 149 | - } |
|
| 121 | + /** |
|
| 122 | + * @param EE_Ticket $ticket |
|
| 123 | + * @return EE_Price |
|
| 124 | + * @throws EE_Error |
|
| 125 | + * @throws ReflectionException |
|
| 126 | + * @since $VID:$ |
|
| 127 | + */ |
|
| 128 | + protected function createNewBasePrice(EE_Ticket $ticket) |
|
| 129 | + { |
|
| 130 | + $new_base_price = $this->price_model->get_new_price(); |
|
| 131 | + $base_price_type = $this->price_type_model->get_one([ |
|
| 132 | + [ |
|
| 133 | + 'PBT_ID' => EEM_Price_Type::base_type_base_price |
|
| 134 | + ] |
|
| 135 | + ]); |
|
| 136 | + if (! $base_price_type instanceof EE_Price_Type) { |
|
| 137 | + throw new RuntimeException( |
|
| 138 | + esc_html__( |
|
| 139 | + 'A valid base price type could not be retrieved from the database.', |
|
| 140 | + 'event_espresso' |
|
| 141 | + ) |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | + $new_base_price->set('PRT_ID', $base_price_type->ID()); |
|
| 145 | + $new_base_price->set('PRC_is_default', false); |
|
| 146 | + $new_base_price->save(); |
|
| 147 | + $new_base_price->_add_relation_to($ticket, 'Ticket'); |
|
| 148 | + return $new_base_price; |
|
| 149 | + } |
|
| 150 | 150 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function create(EE_Base_Class $entity) |
| 59 | 59 | { |
| 60 | - if (! $entity instanceof EE_Ticket) { |
|
| 60 | + if ( ! $entity instanceof EE_Ticket) { |
|
| 61 | 61 | throw new InvalidEntityException($entity, 'EE_Ticket'); |
| 62 | 62 | } |
| 63 | 63 | $taxes = []; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $default_prices = $this->price_model->get_all_default_prices(false, true); |
| 68 | 68 | if (is_array($default_prices)) { |
| 69 | 69 | foreach ($default_prices as $default_price) { |
| 70 | - if (! $default_price instanceof EE_Price) { |
|
| 70 | + if ( ! $default_price instanceof EE_Price) { |
|
| 71 | 71 | throw new InvalidEntityException($default_price, 'EE_Price'); |
| 72 | 72 | } |
| 73 | 73 | // grab any taxes but don't do anything just yet |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | // has non-zero base price |
| 83 | 83 | $default_price_clone->is_base_price() |
| 84 | 84 | && $default_price_clone->amount() > 0 |
| 85 | - ) ||( |
|
| 85 | + ) || ( |
|
| 86 | 86 | // or has fixed amount surcharge |
| 87 | 87 | $default_price_clone->is_surcharge() |
| 88 | 88 | && ! $default_price_clone->is_percent() |
@@ -95,19 +95,19 @@ discard block |
||
| 95 | 95 | $default_price_clone->_add_relation_to($entity, 'Ticket'); |
| 96 | 96 | // verify that a base price has been set |
| 97 | 97 | $has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price; |
| 98 | - $new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
| 98 | + $new_prices[$default_price_clone->ID()] = $default_price_clone; |
|
| 99 | 99 | } |
| 100 | 100 | } |
| 101 | - if (! $is_free && ! empty($taxes)) { |
|
| 101 | + if ( ! $is_free && ! empty($taxes)) { |
|
| 102 | 102 | foreach ($taxes as $tax) { |
| 103 | 103 | // assign taxes but don't duplicate them because they operate globally |
| 104 | 104 | $entity->set_taxable(true); |
| 105 | 105 | $tax->_add_relation_to($entity, 'Ticket'); |
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | - if (! $has_base_price) { |
|
| 108 | + if ( ! $has_base_price) { |
|
| 109 | 109 | $new_base_price = $this->createNewBasePrice($entity); |
| 110 | - $new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
| 110 | + $new_prices[$new_base_price->ID()] = $new_base_price; |
|
| 111 | 111 | } |
| 112 | 112 | $ticket_total = $entity->get_ticket_total_with_taxes(true); |
| 113 | 113 | if ($ticket_total !== $entity->ticket_price()) { |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | 'PBT_ID' => EEM_Price_Type::base_type_base_price |
| 134 | 134 | ] |
| 135 | 135 | ]); |
| 136 | - if (! $base_price_type instanceof EE_Price_Type) { |
|
| 136 | + if ( ! $base_price_type instanceof EE_Price_Type) { |
|
| 137 | 137 | throw new RuntimeException( |
| 138 | 138 | esc_html__( |
| 139 | 139 | 'A valid base price type could not be retrieved from the database.', |
@@ -8,17 +8,17 @@ |
||
| 8 | 8 | class DatetimeBulkUpdate extends EntityMutator |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Defines the mutation data modification closure. |
|
| 13 | - * |
|
| 14 | - * @param EEM_Datetime $model |
|
| 15 | - * @param Datetime $type |
|
| 16 | - * @return callable |
|
| 17 | - */ |
|
| 18 | - public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
| 19 | - { |
|
| 20 | - $entityMutator = DatetimeUpdate::mutateAndGetPayload($model, $type); |
|
| 21 | - $bulkMutator = new BulkEntityMutator($entityMutator); |
|
| 22 | - return array($bulkMutator, 'updateEntities'); |
|
| 23 | - } |
|
| 11 | + /** |
|
| 12 | + * Defines the mutation data modification closure. |
|
| 13 | + * |
|
| 14 | + * @param EEM_Datetime $model |
|
| 15 | + * @param Datetime $type |
|
| 16 | + * @return callable |
|
| 17 | + */ |
|
| 18 | + public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
| 19 | + { |
|
| 20 | + $entityMutator = DatetimeUpdate::mutateAndGetPayload($model, $type); |
|
| 21 | + $bulkMutator = new BulkEntityMutator($entityMutator); |
|
| 22 | + return array($bulkMutator, 'updateEntities'); |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -10,69 +10,69 @@ |
||
| 10 | 10 | class BulkEntityMutator extends EntityMutator |
| 11 | 11 | { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * @var callable $entity_mutator . |
|
| 15 | - */ |
|
| 16 | - protected $entity_mutator; |
|
| 13 | + /** |
|
| 14 | + * @var callable $entity_mutator . |
|
| 15 | + */ |
|
| 16 | + protected $entity_mutator; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * BulkEntityMutator constructor. |
|
| 20 | - * |
|
| 21 | - * @param array $entity_mutator The mutator for an entity. |
|
| 22 | - */ |
|
| 23 | - public function __construct(callable $entity_mutator) |
|
| 24 | - { |
|
| 25 | - $this->entity_mutator = $entity_mutator; |
|
| 26 | - } |
|
| 27 | - /** |
|
| 28 | - * Bulk updates entities. |
|
| 29 | - * |
|
| 30 | - * @param array $input The input for the mutation |
|
| 31 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
| 32 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - public function updateEntities($input, AppContext $context, ResolveInfo $info) |
|
| 36 | - { |
|
| 18 | + /** |
|
| 19 | + * BulkEntityMutator constructor. |
|
| 20 | + * |
|
| 21 | + * @param array $entity_mutator The mutator for an entity. |
|
| 22 | + */ |
|
| 23 | + public function __construct(callable $entity_mutator) |
|
| 24 | + { |
|
| 25 | + $this->entity_mutator = $entity_mutator; |
|
| 26 | + } |
|
| 27 | + /** |
|
| 28 | + * Bulk updates entities. |
|
| 29 | + * |
|
| 30 | + * @param array $input The input for the mutation |
|
| 31 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
| 32 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + public function updateEntities($input, AppContext $context, ResolveInfo $info) |
|
| 36 | + { |
|
| 37 | 37 | |
| 38 | - $updated = []; |
|
| 39 | - $failed = []; |
|
| 40 | - // TODO Add meaningful error messages for every failure. |
|
| 41 | - // $errors = []; |
|
| 38 | + $updated = []; |
|
| 39 | + $failed = []; |
|
| 40 | + // TODO Add meaningful error messages for every failure. |
|
| 41 | + // $errors = []; |
|
| 42 | 42 | |
| 43 | - try { |
|
| 44 | - if (empty($input['uniqueInputs']) || !is_array($input['uniqueInputs'])) { |
|
| 45 | - throw new OutOfBoundsException( |
|
| 46 | - esc_html__('A valid input was not provided.', 'event_espresso') |
|
| 47 | - ); |
|
| 48 | - } |
|
| 43 | + try { |
|
| 44 | + if (empty($input['uniqueInputs']) || !is_array($input['uniqueInputs'])) { |
|
| 45 | + throw new OutOfBoundsException( |
|
| 46 | + esc_html__('A valid input was not provided.', 'event_espresso') |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - $sharedInput = ! empty($input['sharedInput']) ? $input['sharedInput'] : []; |
|
| 50 | + $sharedInput = ! empty($input['sharedInput']) ? $input['sharedInput'] : []; |
|
| 51 | 51 | |
| 52 | - foreach ($input['uniqueInputs'] as $uniqueInput) { |
|
| 53 | - try { |
|
| 54 | - // values in $uniqueInput will override those in $sharedInput |
|
| 55 | - $finalInput = array_merge($sharedInput, $uniqueInput); |
|
| 56 | - // mutate the individual entity. |
|
| 57 | - $mutator = $this->entity_mutator; |
|
| 58 | - $mutator($finalInput, $context, $info); |
|
| 59 | - // we are here it means the update was successful. |
|
| 60 | - $updated[] = $uniqueInput['id']; |
|
| 61 | - } catch (Exception $e) { |
|
| 62 | - // sorry mate, couldn't help you :( |
|
| 63 | - $failed[] = $uniqueInput['id']; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } catch (Exception $exception) { |
|
| 67 | - EntityMutator::handleExceptions( |
|
| 68 | - $exception, |
|
| 69 | - esc_html__( |
|
| 70 | - 'Could not perform the update because of the following error(s)', |
|
| 71 | - 'event_espresso' |
|
| 72 | - ) |
|
| 73 | - ); |
|
| 74 | - } |
|
| 52 | + foreach ($input['uniqueInputs'] as $uniqueInput) { |
|
| 53 | + try { |
|
| 54 | + // values in $uniqueInput will override those in $sharedInput |
|
| 55 | + $finalInput = array_merge($sharedInput, $uniqueInput); |
|
| 56 | + // mutate the individual entity. |
|
| 57 | + $mutator = $this->entity_mutator; |
|
| 58 | + $mutator($finalInput, $context, $info); |
|
| 59 | + // we are here it means the update was successful. |
|
| 60 | + $updated[] = $uniqueInput['id']; |
|
| 61 | + } catch (Exception $e) { |
|
| 62 | + // sorry mate, couldn't help you :( |
|
| 63 | + $failed[] = $uniqueInput['id']; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } catch (Exception $exception) { |
|
| 67 | + EntityMutator::handleExceptions( |
|
| 68 | + $exception, |
|
| 69 | + esc_html__( |
|
| 70 | + 'Could not perform the update because of the following error(s)', |
|
| 71 | + 'event_espresso' |
|
| 72 | + ) |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - return compact('updated', 'failed'); |
|
| 77 | - } |
|
| 76 | + return compact('updated', 'failed'); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | // $errors = []; |
| 42 | 42 | |
| 43 | 43 | try { |
| 44 | - if (empty($input['uniqueInputs']) || !is_array($input['uniqueInputs'])) { |
|
| 44 | + if (empty($input['uniqueInputs']) || ! is_array($input['uniqueInputs'])) { |
|
| 45 | 45 | throw new OutOfBoundsException( |
| 46 | 46 | esc_html__('A valid input was not provided.', 'event_espresso') |
| 47 | 47 | ); |
@@ -8,17 +8,17 @@ |
||
| 8 | 8 | class TicketBulkUpdate extends EntityMutator |
| 9 | 9 | { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * Defines the mutation data modification closure. |
|
| 13 | - * |
|
| 14 | - * @param EEM_Ticket $model |
|
| 15 | - * @param Ticket $type |
|
| 16 | - * @return callable |
|
| 17 | - */ |
|
| 18 | - public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
| 19 | - { |
|
| 20 | - $entityMutator = TicketUpdate::mutateAndGetPayload($model, $type); |
|
| 21 | - $bulkMutator = new BulkEntityMutator($entityMutator); |
|
| 22 | - return array($bulkMutator, 'updateEntities'); |
|
| 23 | - } |
|
| 11 | + /** |
|
| 12 | + * Defines the mutation data modification closure. |
|
| 13 | + * |
|
| 14 | + * @param EEM_Ticket $model |
|
| 15 | + * @param Ticket $type |
|
| 16 | + * @return callable |
|
| 17 | + */ |
|
| 18 | + public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
| 19 | + { |
|
| 20 | + $entityMutator = TicketUpdate::mutateAndGetPayload($model, $type); |
|
| 21 | + $bulkMutator = new BulkEntityMutator($entityMutator); |
|
| 22 | + return array($bulkMutator, 'updateEntities'); |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -35,378 +35,378 @@ |
||
| 35 | 35 | class Datetime extends TypeBase |
| 36 | 36 | { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * EventDate constructor. |
|
| 40 | - * |
|
| 41 | - * @param EEM_Datetime $datetime_model |
|
| 42 | - */ |
|
| 43 | - public function __construct(EEM_Datetime $datetime_model) |
|
| 44 | - { |
|
| 45 | - $this->model = $datetime_model; |
|
| 46 | - $this->setName($this->namespace . 'Datetime'); |
|
| 47 | - $this->setDescription(__('An event date', 'event_espresso')); |
|
| 48 | - $this->setIsCustomPostType(false); |
|
| 49 | - parent::__construct(); |
|
| 50 | - } |
|
| 38 | + /** |
|
| 39 | + * EventDate constructor. |
|
| 40 | + * |
|
| 41 | + * @param EEM_Datetime $datetime_model |
|
| 42 | + */ |
|
| 43 | + public function __construct(EEM_Datetime $datetime_model) |
|
| 44 | + { |
|
| 45 | + $this->model = $datetime_model; |
|
| 46 | + $this->setName($this->namespace . 'Datetime'); |
|
| 47 | + $this->setDescription(__('An event date', 'event_espresso')); |
|
| 48 | + $this->setIsCustomPostType(false); |
|
| 49 | + parent::__construct(); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @return GraphQLFieldInterface[] |
|
| 55 | - * @since $VID:$ |
|
| 56 | - */ |
|
| 57 | - public function getFields() |
|
| 58 | - { |
|
| 59 | - $fields = [ |
|
| 60 | - new GraphQLField( |
|
| 61 | - 'id', |
|
| 62 | - ['non_null' => 'ID'], |
|
| 63 | - null, |
|
| 64 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
| 65 | - ), |
|
| 66 | - new GraphQLOutputField( |
|
| 67 | - 'dbId', |
|
| 68 | - ['non_null' => 'Int'], |
|
| 69 | - 'ID', |
|
| 70 | - esc_html__('The datetime ID.', 'event_espresso') |
|
| 71 | - ), |
|
| 72 | - new GraphQLOutputField( |
|
| 73 | - 'cacheId', |
|
| 74 | - ['non_null' => 'String'], |
|
| 75 | - null, |
|
| 76 | - esc_html__('The cache ID of the object.', 'event_espresso') |
|
| 77 | - ), |
|
| 78 | - new GraphQLField( |
|
| 79 | - 'capacity', |
|
| 80 | - 'Int', |
|
| 81 | - 'reg_limit', |
|
| 82 | - esc_html__('Registration Limit for this time', 'event_espresso'), |
|
| 83 | - [$this, 'parseInfiniteValue'] |
|
| 84 | - ), |
|
| 85 | - new GraphQLField( |
|
| 86 | - 'description', |
|
| 87 | - 'String', |
|
| 88 | - 'description', |
|
| 89 | - esc_html__('Description for Datetime', 'event_espresso') |
|
| 90 | - ), |
|
| 91 | - new GraphQLField( |
|
| 92 | - 'endDate', |
|
| 93 | - 'String', |
|
| 94 | - 'end_date_and_time', |
|
| 95 | - esc_html__('End date and time of the Event', 'event_espresso'), |
|
| 96 | - [$this, 'formatDatetime'] |
|
| 97 | - ), |
|
| 98 | - new GraphQLOutputField( |
|
| 99 | - 'event', |
|
| 100 | - $this->namespace . 'Event', |
|
| 101 | - null, |
|
| 102 | - esc_html__('Event of the datetime.', 'event_espresso') |
|
| 103 | - ), |
|
| 104 | - new GraphQLInputField( |
|
| 105 | - 'event', |
|
| 106 | - 'ID', |
|
| 107 | - null, |
|
| 108 | - esc_html__('Globally unique event ID of the datetime.', 'event_espresso') |
|
| 109 | - ), |
|
| 110 | - new GraphQLInputField( |
|
| 111 | - 'eventId', |
|
| 112 | - 'Int', |
|
| 113 | - null, |
|
| 114 | - esc_html__('Event ID of the datetime.', 'event_espresso') |
|
| 115 | - ), |
|
| 116 | - new GraphQLOutputField( |
|
| 117 | - 'isActive', |
|
| 118 | - 'Boolean', |
|
| 119 | - 'is_active', |
|
| 120 | - esc_html__('Flag indicating datetime is active', 'event_espresso') |
|
| 121 | - ), |
|
| 122 | - new GraphQLOutputField( |
|
| 123 | - 'isExpired', |
|
| 124 | - 'Boolean', |
|
| 125 | - 'is_expired', |
|
| 126 | - esc_html__('Flag indicating datetime is expired or not', 'event_espresso') |
|
| 127 | - ), |
|
| 128 | - new GraphQLField( |
|
| 129 | - 'isPrimary', |
|
| 130 | - 'Boolean', |
|
| 131 | - 'is_primary', |
|
| 132 | - esc_html__('Flag indicating datetime is primary one for event', 'event_espresso') |
|
| 133 | - ), |
|
| 134 | - new GraphQLOutputField( |
|
| 135 | - 'isSoldOut', |
|
| 136 | - 'Boolean', |
|
| 137 | - 'sold_out', |
|
| 138 | - esc_html__( |
|
| 139 | - 'Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit', |
|
| 140 | - 'event_espresso' |
|
| 141 | - ) |
|
| 142 | - ), |
|
| 143 | - new GraphQLField( |
|
| 144 | - 'isTrashed', |
|
| 145 | - 'Boolean', |
|
| 146 | - null, |
|
| 147 | - esc_html__('Flag indicating datetime has been trashed.', 'event_espresso'), |
|
| 148 | - null, |
|
| 149 | - [$this, 'getIsTrashed'] |
|
| 150 | - ), |
|
| 151 | - new GraphQLOutputField( |
|
| 152 | - 'isUpcoming', |
|
| 153 | - 'Boolean', |
|
| 154 | - 'is_upcoming', |
|
| 155 | - esc_html__('Whether the date is upcoming', 'event_espresso') |
|
| 156 | - ), |
|
| 157 | - new GraphQLOutputField( |
|
| 158 | - 'length', |
|
| 159 | - 'Int', |
|
| 160 | - 'length', |
|
| 161 | - esc_html__('The length of the event (start to end time) in seconds', 'event_espresso') |
|
| 162 | - ), |
|
| 163 | - new GraphQLField( |
|
| 164 | - 'name', |
|
| 165 | - 'String', |
|
| 166 | - 'name', |
|
| 167 | - esc_html__('Datetime Name', 'event_espresso') |
|
| 168 | - ), |
|
| 169 | - new GraphQLField( |
|
| 170 | - 'order', |
|
| 171 | - 'Int', |
|
| 172 | - 'order', |
|
| 173 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
| 174 | - ), |
|
| 175 | - new GraphQLOutputField( |
|
| 176 | - 'parent', |
|
| 177 | - $this->name(), |
|
| 178 | - null, |
|
| 179 | - esc_html__('The parent datetime of the current datetime', 'event_espresso') |
|
| 180 | - ), |
|
| 181 | - new GraphQLInputField( |
|
| 182 | - 'parent', |
|
| 183 | - 'ID', |
|
| 184 | - null, |
|
| 185 | - esc_html__('The parent datetime ID', 'event_espresso') |
|
| 186 | - ), |
|
| 187 | - new GraphQLField( |
|
| 188 | - 'reserved', |
|
| 189 | - 'Int', |
|
| 190 | - 'reserved', |
|
| 191 | - esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso') |
|
| 192 | - ), |
|
| 193 | - new GraphQLField( |
|
| 194 | - 'startDate', |
|
| 195 | - 'String', |
|
| 196 | - 'start_date_and_time', |
|
| 197 | - esc_html__('Start date and time of the Event', 'event_espresso'), |
|
| 198 | - [$this, 'formatDatetime'] |
|
| 199 | - ), |
|
| 200 | - new GraphQLField( |
|
| 201 | - 'sold', |
|
| 202 | - 'Int', |
|
| 203 | - 'sold', |
|
| 204 | - esc_html__('How many sales for this Datetime that have occurred', 'event_espresso') |
|
| 205 | - ), |
|
| 206 | - new GraphQLOutputField( |
|
| 207 | - 'status', |
|
| 208 | - $this->namespace . 'DatetimeStatusEnum', |
|
| 209 | - 'get_active_status', |
|
| 210 | - esc_html__('Datetime status', 'event_espresso') |
|
| 211 | - ), |
|
| 212 | - new GraphQLInputField( |
|
| 213 | - 'tickets', |
|
| 214 | - ['list_of' => 'ID'], |
|
| 215 | - null, |
|
| 216 | - sprintf( |
|
| 217 | - '%1$s %2$s', |
|
| 218 | - esc_html__('Globally unique IDs of the tickets related to the datetime.', 'event_espresso'), |
|
| 219 | - esc_html__('Ignored if empty.', 'event_espresso') |
|
| 220 | - ) |
|
| 221 | - ), |
|
| 222 | - ]; |
|
| 53 | + /** |
|
| 54 | + * @return GraphQLFieldInterface[] |
|
| 55 | + * @since $VID:$ |
|
| 56 | + */ |
|
| 57 | + public function getFields() |
|
| 58 | + { |
|
| 59 | + $fields = [ |
|
| 60 | + new GraphQLField( |
|
| 61 | + 'id', |
|
| 62 | + ['non_null' => 'ID'], |
|
| 63 | + null, |
|
| 64 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
| 65 | + ), |
|
| 66 | + new GraphQLOutputField( |
|
| 67 | + 'dbId', |
|
| 68 | + ['non_null' => 'Int'], |
|
| 69 | + 'ID', |
|
| 70 | + esc_html__('The datetime ID.', 'event_espresso') |
|
| 71 | + ), |
|
| 72 | + new GraphQLOutputField( |
|
| 73 | + 'cacheId', |
|
| 74 | + ['non_null' => 'String'], |
|
| 75 | + null, |
|
| 76 | + esc_html__('The cache ID of the object.', 'event_espresso') |
|
| 77 | + ), |
|
| 78 | + new GraphQLField( |
|
| 79 | + 'capacity', |
|
| 80 | + 'Int', |
|
| 81 | + 'reg_limit', |
|
| 82 | + esc_html__('Registration Limit for this time', 'event_espresso'), |
|
| 83 | + [$this, 'parseInfiniteValue'] |
|
| 84 | + ), |
|
| 85 | + new GraphQLField( |
|
| 86 | + 'description', |
|
| 87 | + 'String', |
|
| 88 | + 'description', |
|
| 89 | + esc_html__('Description for Datetime', 'event_espresso') |
|
| 90 | + ), |
|
| 91 | + new GraphQLField( |
|
| 92 | + 'endDate', |
|
| 93 | + 'String', |
|
| 94 | + 'end_date_and_time', |
|
| 95 | + esc_html__('End date and time of the Event', 'event_espresso'), |
|
| 96 | + [$this, 'formatDatetime'] |
|
| 97 | + ), |
|
| 98 | + new GraphQLOutputField( |
|
| 99 | + 'event', |
|
| 100 | + $this->namespace . 'Event', |
|
| 101 | + null, |
|
| 102 | + esc_html__('Event of the datetime.', 'event_espresso') |
|
| 103 | + ), |
|
| 104 | + new GraphQLInputField( |
|
| 105 | + 'event', |
|
| 106 | + 'ID', |
|
| 107 | + null, |
|
| 108 | + esc_html__('Globally unique event ID of the datetime.', 'event_espresso') |
|
| 109 | + ), |
|
| 110 | + new GraphQLInputField( |
|
| 111 | + 'eventId', |
|
| 112 | + 'Int', |
|
| 113 | + null, |
|
| 114 | + esc_html__('Event ID of the datetime.', 'event_espresso') |
|
| 115 | + ), |
|
| 116 | + new GraphQLOutputField( |
|
| 117 | + 'isActive', |
|
| 118 | + 'Boolean', |
|
| 119 | + 'is_active', |
|
| 120 | + esc_html__('Flag indicating datetime is active', 'event_espresso') |
|
| 121 | + ), |
|
| 122 | + new GraphQLOutputField( |
|
| 123 | + 'isExpired', |
|
| 124 | + 'Boolean', |
|
| 125 | + 'is_expired', |
|
| 126 | + esc_html__('Flag indicating datetime is expired or not', 'event_espresso') |
|
| 127 | + ), |
|
| 128 | + new GraphQLField( |
|
| 129 | + 'isPrimary', |
|
| 130 | + 'Boolean', |
|
| 131 | + 'is_primary', |
|
| 132 | + esc_html__('Flag indicating datetime is primary one for event', 'event_espresso') |
|
| 133 | + ), |
|
| 134 | + new GraphQLOutputField( |
|
| 135 | + 'isSoldOut', |
|
| 136 | + 'Boolean', |
|
| 137 | + 'sold_out', |
|
| 138 | + esc_html__( |
|
| 139 | + 'Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit', |
|
| 140 | + 'event_espresso' |
|
| 141 | + ) |
|
| 142 | + ), |
|
| 143 | + new GraphQLField( |
|
| 144 | + 'isTrashed', |
|
| 145 | + 'Boolean', |
|
| 146 | + null, |
|
| 147 | + esc_html__('Flag indicating datetime has been trashed.', 'event_espresso'), |
|
| 148 | + null, |
|
| 149 | + [$this, 'getIsTrashed'] |
|
| 150 | + ), |
|
| 151 | + new GraphQLOutputField( |
|
| 152 | + 'isUpcoming', |
|
| 153 | + 'Boolean', |
|
| 154 | + 'is_upcoming', |
|
| 155 | + esc_html__('Whether the date is upcoming', 'event_espresso') |
|
| 156 | + ), |
|
| 157 | + new GraphQLOutputField( |
|
| 158 | + 'length', |
|
| 159 | + 'Int', |
|
| 160 | + 'length', |
|
| 161 | + esc_html__('The length of the event (start to end time) in seconds', 'event_espresso') |
|
| 162 | + ), |
|
| 163 | + new GraphQLField( |
|
| 164 | + 'name', |
|
| 165 | + 'String', |
|
| 166 | + 'name', |
|
| 167 | + esc_html__('Datetime Name', 'event_espresso') |
|
| 168 | + ), |
|
| 169 | + new GraphQLField( |
|
| 170 | + 'order', |
|
| 171 | + 'Int', |
|
| 172 | + 'order', |
|
| 173 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
| 174 | + ), |
|
| 175 | + new GraphQLOutputField( |
|
| 176 | + 'parent', |
|
| 177 | + $this->name(), |
|
| 178 | + null, |
|
| 179 | + esc_html__('The parent datetime of the current datetime', 'event_espresso') |
|
| 180 | + ), |
|
| 181 | + new GraphQLInputField( |
|
| 182 | + 'parent', |
|
| 183 | + 'ID', |
|
| 184 | + null, |
|
| 185 | + esc_html__('The parent datetime ID', 'event_espresso') |
|
| 186 | + ), |
|
| 187 | + new GraphQLField( |
|
| 188 | + 'reserved', |
|
| 189 | + 'Int', |
|
| 190 | + 'reserved', |
|
| 191 | + esc_html__('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso') |
|
| 192 | + ), |
|
| 193 | + new GraphQLField( |
|
| 194 | + 'startDate', |
|
| 195 | + 'String', |
|
| 196 | + 'start_date_and_time', |
|
| 197 | + esc_html__('Start date and time of the Event', 'event_espresso'), |
|
| 198 | + [$this, 'formatDatetime'] |
|
| 199 | + ), |
|
| 200 | + new GraphQLField( |
|
| 201 | + 'sold', |
|
| 202 | + 'Int', |
|
| 203 | + 'sold', |
|
| 204 | + esc_html__('How many sales for this Datetime that have occurred', 'event_espresso') |
|
| 205 | + ), |
|
| 206 | + new GraphQLOutputField( |
|
| 207 | + 'status', |
|
| 208 | + $this->namespace . 'DatetimeStatusEnum', |
|
| 209 | + 'get_active_status', |
|
| 210 | + esc_html__('Datetime status', 'event_espresso') |
|
| 211 | + ), |
|
| 212 | + new GraphQLInputField( |
|
| 213 | + 'tickets', |
|
| 214 | + ['list_of' => 'ID'], |
|
| 215 | + null, |
|
| 216 | + sprintf( |
|
| 217 | + '%1$s %2$s', |
|
| 218 | + esc_html__('Globally unique IDs of the tickets related to the datetime.', 'event_espresso'), |
|
| 219 | + esc_html__('Ignored if empty.', 'event_espresso') |
|
| 220 | + ) |
|
| 221 | + ), |
|
| 222 | + ]; |
|
| 223 | 223 | |
| 224 | - return apply_filters( |
|
| 225 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__datetime_fields', |
|
| 226 | - $fields, |
|
| 227 | - $this->name, |
|
| 228 | - $this->model |
|
| 229 | - ); |
|
| 230 | - } |
|
| 224 | + return apply_filters( |
|
| 225 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__datetime_fields', |
|
| 226 | + $fields, |
|
| 227 | + $this->name, |
|
| 228 | + $this->model |
|
| 229 | + ); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * @param EE_Datetime $source The source that's passed down the GraphQL queries |
|
| 235 | - * @param array $args The inputArgs on the field |
|
| 236 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 237 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 238 | - * @return string |
|
| 239 | - * @throws Exception |
|
| 240 | - * @throws InvalidArgumentException |
|
| 241 | - * @throws InvalidDataTypeException |
|
| 242 | - * @throws InvalidInterfaceException |
|
| 243 | - * @throws ReflectionException |
|
| 244 | - * @throws UserError |
|
| 245 | - * @throws UnexpectedEntityException |
|
| 246 | - * @since $VID:$ |
|
| 247 | - */ |
|
| 248 | - public function getIsTrashed(EE_Datetime $source, array $args, AppContext $context, ResolveInfo $info) |
|
| 249 | - { |
|
| 250 | - return (bool) $source->get('DTT_deleted'); |
|
| 251 | - } |
|
| 233 | + /** |
|
| 234 | + * @param EE_Datetime $source The source that's passed down the GraphQL queries |
|
| 235 | + * @param array $args The inputArgs on the field |
|
| 236 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 237 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 238 | + * @return string |
|
| 239 | + * @throws Exception |
|
| 240 | + * @throws InvalidArgumentException |
|
| 241 | + * @throws InvalidDataTypeException |
|
| 242 | + * @throws InvalidInterfaceException |
|
| 243 | + * @throws ReflectionException |
|
| 244 | + * @throws UserError |
|
| 245 | + * @throws UnexpectedEntityException |
|
| 246 | + * @since $VID:$ |
|
| 247 | + */ |
|
| 248 | + public function getIsTrashed(EE_Datetime $source, array $args, AppContext $context, ResolveInfo $info) |
|
| 249 | + { |
|
| 250 | + return (bool) $source->get('DTT_deleted'); |
|
| 251 | + } |
|
| 252 | 252 | |
| 253 | - /** |
|
| 254 | - * Return the base mutation config for bulk update. |
|
| 255 | - * |
|
| 256 | - * @param string $base_input |
|
| 257 | - * @return array |
|
| 258 | - */ |
|
| 259 | - public static function bulkUpdateBaseConfig($base_input) |
|
| 260 | - { |
|
| 261 | - return [ |
|
| 262 | - 'inputFields' => [ |
|
| 263 | - /** |
|
| 264 | - * represents the input that is unique for each entity |
|
| 265 | - * e.g. dates may be unique for dateimes and tickets |
|
| 266 | - */ |
|
| 267 | - 'uniqueInputs' => [ |
|
| 268 | - 'type' => [ |
|
| 269 | - 'non_null' => ['list_of' => $base_input], |
|
| 270 | - ], |
|
| 271 | - 'description' => esc_html__( |
|
| 272 | - 'List of unique inputs for each entity in bulk update', |
|
| 273 | - 'event_espresso' |
|
| 274 | - ), |
|
| 275 | - ], |
|
| 276 | - /** |
|
| 277 | - * represents the common input for all entities |
|
| 278 | - * e.g. capacity or quantity may be same for all dates/tickets |
|
| 279 | - */ |
|
| 280 | - 'sharedInput' => [ |
|
| 281 | - 'type' => $base_input, |
|
| 282 | - 'description' => esc_html__( |
|
| 283 | - 'Shared input for all entities in bulk update', |
|
| 284 | - 'event_espresso' |
|
| 285 | - ), |
|
| 286 | - ], |
|
| 287 | - ], |
|
| 288 | - 'outputFields' => [ |
|
| 289 | - 'updated' => [ |
|
| 290 | - 'type' => ['list_of' => 'ID'], |
|
| 291 | - ], |
|
| 292 | - 'failed' => [ |
|
| 293 | - 'type' => ['list_of' => 'ID'], |
|
| 294 | - ], |
|
| 295 | - ], |
|
| 296 | - ]; |
|
| 297 | - } |
|
| 253 | + /** |
|
| 254 | + * Return the base mutation config for bulk update. |
|
| 255 | + * |
|
| 256 | + * @param string $base_input |
|
| 257 | + * @return array |
|
| 258 | + */ |
|
| 259 | + public static function bulkUpdateBaseConfig($base_input) |
|
| 260 | + { |
|
| 261 | + return [ |
|
| 262 | + 'inputFields' => [ |
|
| 263 | + /** |
|
| 264 | + * represents the input that is unique for each entity |
|
| 265 | + * e.g. dates may be unique for dateimes and tickets |
|
| 266 | + */ |
|
| 267 | + 'uniqueInputs' => [ |
|
| 268 | + 'type' => [ |
|
| 269 | + 'non_null' => ['list_of' => $base_input], |
|
| 270 | + ], |
|
| 271 | + 'description' => esc_html__( |
|
| 272 | + 'List of unique inputs for each entity in bulk update', |
|
| 273 | + 'event_espresso' |
|
| 274 | + ), |
|
| 275 | + ], |
|
| 276 | + /** |
|
| 277 | + * represents the common input for all entities |
|
| 278 | + * e.g. capacity or quantity may be same for all dates/tickets |
|
| 279 | + */ |
|
| 280 | + 'sharedInput' => [ |
|
| 281 | + 'type' => $base_input, |
|
| 282 | + 'description' => esc_html__( |
|
| 283 | + 'Shared input for all entities in bulk update', |
|
| 284 | + 'event_espresso' |
|
| 285 | + ), |
|
| 286 | + ], |
|
| 287 | + ], |
|
| 288 | + 'outputFields' => [ |
|
| 289 | + 'updated' => [ |
|
| 290 | + 'type' => ['list_of' => 'ID'], |
|
| 291 | + ], |
|
| 292 | + 'failed' => [ |
|
| 293 | + 'type' => ['list_of' => 'ID'], |
|
| 294 | + ], |
|
| 295 | + ], |
|
| 296 | + ]; |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | 299 | |
| 300 | - /** |
|
| 301 | - * @param array $inputFields The mutation input fields. |
|
| 302 | - * @throws InvalidArgumentException |
|
| 303 | - * @throws ReflectionException |
|
| 304 | - * @since $VID:$ |
|
| 305 | - */ |
|
| 306 | - public function registerMutations(array $inputFields) |
|
| 307 | - { |
|
| 308 | - register_graphql_input_type( |
|
| 309 | - 'Update' . $this->name() . 'BaseInput', |
|
| 310 | - [ |
|
| 311 | - 'fields' => $inputFields, |
|
| 312 | - ] |
|
| 313 | - ); |
|
| 314 | - // Register mutation to update an entity. |
|
| 315 | - register_graphql_mutation( |
|
| 316 | - 'update' . $this->name(), |
|
| 317 | - [ |
|
| 318 | - 'inputFields' => $inputFields, |
|
| 319 | - 'outputFields' => [ |
|
| 320 | - lcfirst($this->name()) => [ |
|
| 321 | - 'type' => $this->name(), |
|
| 322 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
| 323 | - ], |
|
| 324 | - ], |
|
| 325 | - 'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this), |
|
| 326 | - ] |
|
| 327 | - ); |
|
| 328 | - $base_input = 'Update' . $this->name() . 'BaseInput'; |
|
| 329 | - // Register mutation to update an entity. |
|
| 330 | - register_graphql_mutation( |
|
| 331 | - 'bulkUpdate' . $this->name(), |
|
| 332 | - array_merge( |
|
| 333 | - Datetime::bulkUpdateBaseConfig($base_input), |
|
| 334 | - [ |
|
| 335 | - 'mutateAndGetPayload' => DatetimeBulkUpdate::mutateAndGetPayload($this->model, $this), |
|
| 336 | - ] |
|
| 337 | - ) |
|
| 338 | - ); |
|
| 339 | - // Register mutation to delete an entity. |
|
| 340 | - register_graphql_mutation( |
|
| 341 | - 'delete' . $this->name(), |
|
| 342 | - [ |
|
| 343 | - 'inputFields' => [ |
|
| 344 | - 'id' => $inputFields['id'], |
|
| 345 | - 'deletePermanently' => [ |
|
| 346 | - 'type' => 'Boolean', |
|
| 347 | - 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
| 348 | - ], |
|
| 349 | - ], |
|
| 350 | - 'outputFields' => [ |
|
| 351 | - lcfirst($this->name()) => [ |
|
| 352 | - 'type' => $this->name(), |
|
| 353 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
| 354 | - 'resolve' => static function ($payload) { |
|
| 355 | - $deleted = (object) $payload['deleted']; |
|
| 300 | + /** |
|
| 301 | + * @param array $inputFields The mutation input fields. |
|
| 302 | + * @throws InvalidArgumentException |
|
| 303 | + * @throws ReflectionException |
|
| 304 | + * @since $VID:$ |
|
| 305 | + */ |
|
| 306 | + public function registerMutations(array $inputFields) |
|
| 307 | + { |
|
| 308 | + register_graphql_input_type( |
|
| 309 | + 'Update' . $this->name() . 'BaseInput', |
|
| 310 | + [ |
|
| 311 | + 'fields' => $inputFields, |
|
| 312 | + ] |
|
| 313 | + ); |
|
| 314 | + // Register mutation to update an entity. |
|
| 315 | + register_graphql_mutation( |
|
| 316 | + 'update' . $this->name(), |
|
| 317 | + [ |
|
| 318 | + 'inputFields' => $inputFields, |
|
| 319 | + 'outputFields' => [ |
|
| 320 | + lcfirst($this->name()) => [ |
|
| 321 | + 'type' => $this->name(), |
|
| 322 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
| 323 | + ], |
|
| 324 | + ], |
|
| 325 | + 'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this), |
|
| 326 | + ] |
|
| 327 | + ); |
|
| 328 | + $base_input = 'Update' . $this->name() . 'BaseInput'; |
|
| 329 | + // Register mutation to update an entity. |
|
| 330 | + register_graphql_mutation( |
|
| 331 | + 'bulkUpdate' . $this->name(), |
|
| 332 | + array_merge( |
|
| 333 | + Datetime::bulkUpdateBaseConfig($base_input), |
|
| 334 | + [ |
|
| 335 | + 'mutateAndGetPayload' => DatetimeBulkUpdate::mutateAndGetPayload($this->model, $this), |
|
| 336 | + ] |
|
| 337 | + ) |
|
| 338 | + ); |
|
| 339 | + // Register mutation to delete an entity. |
|
| 340 | + register_graphql_mutation( |
|
| 341 | + 'delete' . $this->name(), |
|
| 342 | + [ |
|
| 343 | + 'inputFields' => [ |
|
| 344 | + 'id' => $inputFields['id'], |
|
| 345 | + 'deletePermanently' => [ |
|
| 346 | + 'type' => 'Boolean', |
|
| 347 | + 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
| 348 | + ], |
|
| 349 | + ], |
|
| 350 | + 'outputFields' => [ |
|
| 351 | + lcfirst($this->name()) => [ |
|
| 352 | + 'type' => $this->name(), |
|
| 353 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
| 354 | + 'resolve' => static function ($payload) { |
|
| 355 | + $deleted = (object) $payload['deleted']; |
|
| 356 | 356 | |
| 357 | - return ! empty($deleted) ? $deleted : null; |
|
| 358 | - }, |
|
| 359 | - ], |
|
| 360 | - ], |
|
| 361 | - 'mutateAndGetPayload' => DatetimeDelete::mutateAndGetPayload($this->model, $this), |
|
| 362 | - ] |
|
| 363 | - ); |
|
| 357 | + return ! empty($deleted) ? $deleted : null; |
|
| 358 | + }, |
|
| 359 | + ], |
|
| 360 | + ], |
|
| 361 | + 'mutateAndGetPayload' => DatetimeDelete::mutateAndGetPayload($this->model, $this), |
|
| 362 | + ] |
|
| 363 | + ); |
|
| 364 | 364 | |
| 365 | - // remove primary key from input. |
|
| 366 | - unset($inputFields['id']); |
|
| 367 | - // Register mutation to update an entity. |
|
| 368 | - register_graphql_mutation( |
|
| 369 | - 'create' . $this->name(), |
|
| 370 | - [ |
|
| 371 | - 'inputFields' => $inputFields, |
|
| 372 | - 'outputFields' => [ |
|
| 373 | - lcfirst($this->name()) => [ |
|
| 374 | - 'type' => $this->name(), |
|
| 375 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
| 376 | - ], |
|
| 377 | - ], |
|
| 378 | - 'mutateAndGetPayload' => DatetimeCreate::mutateAndGetPayload($this->model, $this), |
|
| 379 | - ] |
|
| 380 | - ); |
|
| 365 | + // remove primary key from input. |
|
| 366 | + unset($inputFields['id']); |
|
| 367 | + // Register mutation to update an entity. |
|
| 368 | + register_graphql_mutation( |
|
| 369 | + 'create' . $this->name(), |
|
| 370 | + [ |
|
| 371 | + 'inputFields' => $inputFields, |
|
| 372 | + 'outputFields' => [ |
|
| 373 | + lcfirst($this->name()) => [ |
|
| 374 | + 'type' => $this->name(), |
|
| 375 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
| 376 | + ], |
|
| 377 | + ], |
|
| 378 | + 'mutateAndGetPayload' => DatetimeCreate::mutateAndGetPayload($this->model, $this), |
|
| 379 | + ] |
|
| 380 | + ); |
|
| 381 | 381 | |
| 382 | - // Register mutation to update an entity. |
|
| 383 | - register_graphql_mutation( |
|
| 384 | - 'reorder' . $this->namespace . 'Entities', |
|
| 385 | - [ |
|
| 386 | - 'inputFields' => [ |
|
| 387 | - 'entityIds' => [ |
|
| 388 | - 'type' => [ |
|
| 389 | - 'non_null' => ['list_of' => 'ID'], |
|
| 390 | - ], |
|
| 391 | - 'description' => esc_html__('The reordered list of entity GUIDs.', 'event_espresso'), |
|
| 392 | - ], |
|
| 393 | - 'entityType' => [ |
|
| 394 | - 'type' => [ |
|
| 395 | - 'non_null' => $this->namespace . 'ModelNameEnum', |
|
| 396 | - ], |
|
| 397 | - 'description' => esc_html__('The entity type for the IDs', 'event_espresso'), |
|
| 398 | - ], |
|
| 399 | - ], |
|
| 400 | - 'outputFields' => [ |
|
| 401 | - 'ok' => [ |
|
| 402 | - 'type' => 'Boolean', |
|
| 403 | - 'resolve' => function ($payload) { |
|
| 404 | - return (bool) $payload['ok']; |
|
| 405 | - }, |
|
| 406 | - ], |
|
| 407 | - ], |
|
| 408 | - 'mutateAndGetPayload' => EntityReorder::mutateAndGetPayload(), |
|
| 409 | - ] |
|
| 410 | - ); |
|
| 411 | - } |
|
| 382 | + // Register mutation to update an entity. |
|
| 383 | + register_graphql_mutation( |
|
| 384 | + 'reorder' . $this->namespace . 'Entities', |
|
| 385 | + [ |
|
| 386 | + 'inputFields' => [ |
|
| 387 | + 'entityIds' => [ |
|
| 388 | + 'type' => [ |
|
| 389 | + 'non_null' => ['list_of' => 'ID'], |
|
| 390 | + ], |
|
| 391 | + 'description' => esc_html__('The reordered list of entity GUIDs.', 'event_espresso'), |
|
| 392 | + ], |
|
| 393 | + 'entityType' => [ |
|
| 394 | + 'type' => [ |
|
| 395 | + 'non_null' => $this->namespace . 'ModelNameEnum', |
|
| 396 | + ], |
|
| 397 | + 'description' => esc_html__('The entity type for the IDs', 'event_espresso'), |
|
| 398 | + ], |
|
| 399 | + ], |
|
| 400 | + 'outputFields' => [ |
|
| 401 | + 'ok' => [ |
|
| 402 | + 'type' => 'Boolean', |
|
| 403 | + 'resolve' => function ($payload) { |
|
| 404 | + return (bool) $payload['ok']; |
|
| 405 | + }, |
|
| 406 | + ], |
|
| 407 | + ], |
|
| 408 | + 'mutateAndGetPayload' => EntityReorder::mutateAndGetPayload(), |
|
| 409 | + ] |
|
| 410 | + ); |
|
| 411 | + } |
|
| 412 | 412 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | public function __construct(EEM_Datetime $datetime_model) |
| 44 | 44 | { |
| 45 | 45 | $this->model = $datetime_model; |
| 46 | - $this->setName($this->namespace . 'Datetime'); |
|
| 46 | + $this->setName($this->namespace.'Datetime'); |
|
| 47 | 47 | $this->setDescription(__('An event date', 'event_espresso')); |
| 48 | 48 | $this->setIsCustomPostType(false); |
| 49 | 49 | parent::__construct(); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | ), |
| 98 | 98 | new GraphQLOutputField( |
| 99 | 99 | 'event', |
| 100 | - $this->namespace . 'Event', |
|
| 100 | + $this->namespace.'Event', |
|
| 101 | 101 | null, |
| 102 | 102 | esc_html__('Event of the datetime.', 'event_espresso') |
| 103 | 103 | ), |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | ), |
| 206 | 206 | new GraphQLOutputField( |
| 207 | 207 | 'status', |
| 208 | - $this->namespace . 'DatetimeStatusEnum', |
|
| 208 | + $this->namespace.'DatetimeStatusEnum', |
|
| 209 | 209 | 'get_active_status', |
| 210 | 210 | esc_html__('Datetime status', 'event_espresso') |
| 211 | 211 | ), |
@@ -306,14 +306,14 @@ discard block |
||
| 306 | 306 | public function registerMutations(array $inputFields) |
| 307 | 307 | { |
| 308 | 308 | register_graphql_input_type( |
| 309 | - 'Update' . $this->name() . 'BaseInput', |
|
| 309 | + 'Update'.$this->name().'BaseInput', |
|
| 310 | 310 | [ |
| 311 | 311 | 'fields' => $inputFields, |
| 312 | 312 | ] |
| 313 | 313 | ); |
| 314 | 314 | // Register mutation to update an entity. |
| 315 | 315 | register_graphql_mutation( |
| 316 | - 'update' . $this->name(), |
|
| 316 | + 'update'.$this->name(), |
|
| 317 | 317 | [ |
| 318 | 318 | 'inputFields' => $inputFields, |
| 319 | 319 | 'outputFields' => [ |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | 'mutateAndGetPayload' => DatetimeUpdate::mutateAndGetPayload($this->model, $this), |
| 326 | 326 | ] |
| 327 | 327 | ); |
| 328 | - $base_input = 'Update' . $this->name() . 'BaseInput'; |
|
| 328 | + $base_input = 'Update'.$this->name().'BaseInput'; |
|
| 329 | 329 | // Register mutation to update an entity. |
| 330 | 330 | register_graphql_mutation( |
| 331 | - 'bulkUpdate' . $this->name(), |
|
| 331 | + 'bulkUpdate'.$this->name(), |
|
| 332 | 332 | array_merge( |
| 333 | 333 | Datetime::bulkUpdateBaseConfig($base_input), |
| 334 | 334 | [ |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | ); |
| 339 | 339 | // Register mutation to delete an entity. |
| 340 | 340 | register_graphql_mutation( |
| 341 | - 'delete' . $this->name(), |
|
| 341 | + 'delete'.$this->name(), |
|
| 342 | 342 | [ |
| 343 | 343 | 'inputFields' => [ |
| 344 | 344 | 'id' => $inputFields['id'], |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | lcfirst($this->name()) => [ |
| 352 | 352 | 'type' => $this->name(), |
| 353 | 353 | 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
| 354 | - 'resolve' => static function ($payload) { |
|
| 354 | + 'resolve' => static function($payload) { |
|
| 355 | 355 | $deleted = (object) $payload['deleted']; |
| 356 | 356 | |
| 357 | 357 | return ! empty($deleted) ? $deleted : null; |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | unset($inputFields['id']); |
| 367 | 367 | // Register mutation to update an entity. |
| 368 | 368 | register_graphql_mutation( |
| 369 | - 'create' . $this->name(), |
|
| 369 | + 'create'.$this->name(), |
|
| 370 | 370 | [ |
| 371 | 371 | 'inputFields' => $inputFields, |
| 372 | 372 | 'outputFields' => [ |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | |
| 382 | 382 | // Register mutation to update an entity. |
| 383 | 383 | register_graphql_mutation( |
| 384 | - 'reorder' . $this->namespace . 'Entities', |
|
| 384 | + 'reorder'.$this->namespace.'Entities', |
|
| 385 | 385 | [ |
| 386 | 386 | 'inputFields' => [ |
| 387 | 387 | 'entityIds' => [ |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | ], |
| 393 | 393 | 'entityType' => [ |
| 394 | 394 | 'type' => [ |
| 395 | - 'non_null' => $this->namespace . 'ModelNameEnum', |
|
| 395 | + 'non_null' => $this->namespace.'ModelNameEnum', |
|
| 396 | 396 | ], |
| 397 | 397 | 'description' => esc_html__('The entity type for the IDs', 'event_espresso'), |
| 398 | 398 | ], |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | 'outputFields' => [ |
| 401 | 401 | 'ok' => [ |
| 402 | 402 | 'type' => 'Boolean', |
| 403 | - 'resolve' => function ($payload) { |
|
| 403 | + 'resolve' => function($payload) { |
|
| 404 | 404 | return (bool) $payload['ok']; |
| 405 | 405 | }, |
| 406 | 406 | ], |
@@ -34,380 +34,380 @@ |
||
| 34 | 34 | class Ticket extends TypeBase |
| 35 | 35 | { |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Ticket constructor. |
|
| 39 | - * |
|
| 40 | - * @param EEM_Ticket $ticket_model |
|
| 41 | - */ |
|
| 42 | - public function __construct(EEM_Ticket $ticket_model) |
|
| 43 | - { |
|
| 44 | - $this->model = $ticket_model; |
|
| 45 | - $this->setName($this->namespace . 'Ticket'); |
|
| 46 | - $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
|
| 47 | - $this->setIsCustomPostType(false); |
|
| 48 | - parent::__construct(); |
|
| 49 | - } |
|
| 37 | + /** |
|
| 38 | + * Ticket constructor. |
|
| 39 | + * |
|
| 40 | + * @param EEM_Ticket $ticket_model |
|
| 41 | + */ |
|
| 42 | + public function __construct(EEM_Ticket $ticket_model) |
|
| 43 | + { |
|
| 44 | + $this->model = $ticket_model; |
|
| 45 | + $this->setName($this->namespace . 'Ticket'); |
|
| 46 | + $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
|
| 47 | + $this->setIsCustomPostType(false); |
|
| 48 | + parent::__construct(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @return GraphQLFieldInterface[] |
|
| 54 | - * @since $VID:$ |
|
| 55 | - */ |
|
| 56 | - public function getFields() |
|
| 57 | - { |
|
| 58 | - $fields = [ |
|
| 59 | - new GraphQLField( |
|
| 60 | - 'id', |
|
| 61 | - ['non_null' => 'ID'], |
|
| 62 | - null, |
|
| 63 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
| 64 | - ), |
|
| 65 | - new GraphQLOutputField( |
|
| 66 | - 'dbId', |
|
| 67 | - ['non_null' => 'Int'], |
|
| 68 | - 'ID', |
|
| 69 | - esc_html__('Ticket ID', 'event_espresso') |
|
| 70 | - ), |
|
| 71 | - new GraphQLOutputField( |
|
| 72 | - 'cacheId', |
|
| 73 | - ['non_null' => 'String'], |
|
| 74 | - null, |
|
| 75 | - esc_html__('The cache ID of the object.', 'event_espresso') |
|
| 76 | - ), |
|
| 77 | - new GraphQLInputField( |
|
| 78 | - 'datetimes', |
|
| 79 | - ['list_of' => 'ID'], |
|
| 80 | - null, |
|
| 81 | - sprintf( |
|
| 82 | - '%1$s %2$s', |
|
| 83 | - esc_html__('Globally unique IDs of the datetimes related to the ticket.', 'event_espresso'), |
|
| 84 | - esc_html__('Ignored if empty.', 'event_espresso') |
|
| 85 | - ) |
|
| 86 | - ), |
|
| 87 | - new GraphQLField( |
|
| 88 | - 'description', |
|
| 89 | - 'String', |
|
| 90 | - 'description', |
|
| 91 | - esc_html__('Description of Ticket', 'event_espresso') |
|
| 92 | - ), |
|
| 93 | - new GraphQLField( |
|
| 94 | - 'endDate', |
|
| 95 | - 'String', |
|
| 96 | - 'end_date', |
|
| 97 | - esc_html__('End date and time of the Ticket', 'event_espresso'), |
|
| 98 | - [$this, 'formatDatetime'] |
|
| 99 | - ), |
|
| 100 | - new GraphQLOutputField( |
|
| 101 | - 'event', |
|
| 102 | - $this->namespace . 'Event', |
|
| 103 | - null, |
|
| 104 | - esc_html__('Event of the ticket.', 'event_espresso') |
|
| 105 | - ), |
|
| 106 | - new GraphQLField( |
|
| 107 | - 'isDefault', |
|
| 108 | - 'Boolean', |
|
| 109 | - 'is_default', |
|
| 110 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso') |
|
| 111 | - ), |
|
| 112 | - new GraphQLOutputField( |
|
| 113 | - 'isExpired', |
|
| 114 | - 'Boolean', |
|
| 115 | - 'is_expired', |
|
| 116 | - esc_html__('Flag indicating ticket is no longer available because its available dates have expired', 'event_espresso') |
|
| 117 | - ), |
|
| 118 | - new GraphQLOutputField( |
|
| 119 | - 'isFree', |
|
| 120 | - 'Boolean', |
|
| 121 | - 'is_free', |
|
| 122 | - esc_html__('Flag indicating whether the ticket is free.', 'event_espresso') |
|
| 123 | - ), |
|
| 124 | - new GraphQLOutputField( |
|
| 125 | - 'isOnSale', |
|
| 126 | - 'Boolean', |
|
| 127 | - 'is_on_sale', |
|
| 128 | - esc_html__('Flag indicating ticket ticket is on sale or not', 'event_espresso') |
|
| 129 | - ), |
|
| 130 | - new GraphQLOutputField( |
|
| 131 | - 'isPending', |
|
| 132 | - 'Boolean', |
|
| 133 | - 'is_pending', |
|
| 134 | - esc_html__('Flag indicating ticket is yet to go on sale or not', 'event_espresso') |
|
| 135 | - ), |
|
| 136 | - new GraphQLField( |
|
| 137 | - 'isRequired', |
|
| 138 | - 'Boolean', |
|
| 139 | - 'required', |
|
| 140 | - esc_html__( |
|
| 141 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
| 142 | - 'event_espresso' |
|
| 143 | - ) |
|
| 144 | - ), |
|
| 145 | - new GraphQLOutputField( |
|
| 146 | - 'isSoldOut', |
|
| 147 | - 'Boolean', |
|
| 148 | - null, |
|
| 149 | - esc_html__('Flag indicating whether the ticket is sold out', 'event_espresso'), |
|
| 150 | - null, |
|
| 151 | - [$this, 'getIsSoldOut'] |
|
| 152 | - ), |
|
| 153 | - new GraphQLField( |
|
| 154 | - 'isTaxable', |
|
| 155 | - 'Boolean', |
|
| 156 | - 'taxable', |
|
| 157 | - esc_html__( |
|
| 158 | - 'Flag indicating whether there is tax applied on this ticket', |
|
| 159 | - 'event_espresso' |
|
| 160 | - ) |
|
| 161 | - ), |
|
| 162 | - new GraphQLField( |
|
| 163 | - 'isTrashed', |
|
| 164 | - 'Boolean', |
|
| 165 | - 'deleted', |
|
| 166 | - esc_html__('Flag indicating ticket has been trashed.', 'event_espresso') |
|
| 167 | - ), |
|
| 168 | - new GraphQLField( |
|
| 169 | - 'max', |
|
| 170 | - 'Int', |
|
| 171 | - 'max', |
|
| 172 | - esc_html__( |
|
| 173 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
| 174 | - 'event_espresso' |
|
| 175 | - ), |
|
| 176 | - [$this, 'parseInfiniteValue'] |
|
| 177 | - ), |
|
| 178 | - new GraphQLField( |
|
| 179 | - 'min', |
|
| 180 | - 'Int', |
|
| 181 | - 'min', |
|
| 182 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso') |
|
| 183 | - ), |
|
| 184 | - new GraphQLField( |
|
| 185 | - 'name', |
|
| 186 | - 'String', |
|
| 187 | - 'name', |
|
| 188 | - esc_html__('Ticket Name', 'event_espresso') |
|
| 189 | - ), |
|
| 190 | - new GraphQLField( |
|
| 191 | - 'order', |
|
| 192 | - 'Int', |
|
| 193 | - 'order', |
|
| 194 | - esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
| 195 | - ), |
|
| 196 | - new GraphQLOutputField( |
|
| 197 | - 'parent', |
|
| 198 | - $this->name(), |
|
| 199 | - null, |
|
| 200 | - esc_html__('The parent ticket of the current ticket', 'event_espresso') |
|
| 201 | - ), |
|
| 202 | - new GraphQLInputField( |
|
| 203 | - 'parent', |
|
| 204 | - 'ID', |
|
| 205 | - null, |
|
| 206 | - esc_html__('The parent ticket ID', 'event_espresso') |
|
| 207 | - ), |
|
| 208 | - new GraphQLField( |
|
| 209 | - 'price', |
|
| 210 | - 'Float', |
|
| 211 | - 'price', |
|
| 212 | - esc_html__('Final calculated price for ticket', 'event_espresso') |
|
| 213 | - ), |
|
| 214 | - new GraphQLInputField( |
|
| 215 | - 'prices', |
|
| 216 | - ['list_of' => 'ID'], |
|
| 217 | - null, |
|
| 218 | - sprintf( |
|
| 219 | - '%1$s %2$s', |
|
| 220 | - esc_html__('Globally unique IDs of the prices related to the ticket.', 'event_espresso'), |
|
| 221 | - esc_html__('Ignored if empty.', 'event_espresso') |
|
| 222 | - ) |
|
| 223 | - ), |
|
| 224 | - new GraphQLField( |
|
| 225 | - 'quantity', |
|
| 226 | - 'Int', |
|
| 227 | - 'qty', |
|
| 228 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
| 229 | - [$this, 'parseInfiniteValue'] |
|
| 230 | - ), |
|
| 231 | - new GraphQLOutputField( |
|
| 232 | - 'registrationCount', |
|
| 233 | - 'Int', |
|
| 234 | - 'count_registrations', |
|
| 235 | - esc_html__('Number of registrations for the ticket', 'event_espresso') |
|
| 236 | - ), |
|
| 237 | - new GraphQLField( |
|
| 238 | - 'reserved', |
|
| 239 | - 'Int', |
|
| 240 | - 'reserved', |
|
| 241 | - esc_html__( |
|
| 242 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
| 243 | - 'event_espresso' |
|
| 244 | - ) |
|
| 245 | - ), |
|
| 246 | - new GraphQLField( |
|
| 247 | - 'reverseCalculate', |
|
| 248 | - 'Boolean', |
|
| 249 | - 'reverse_calculate', |
|
| 250 | - esc_html__( |
|
| 251 | - 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
| 252 | - 'event_espresso' |
|
| 253 | - ) |
|
| 254 | - ), |
|
| 255 | - new GraphQLField( |
|
| 256 | - 'row', |
|
| 257 | - 'Int', |
|
| 258 | - 'row', |
|
| 259 | - esc_html__('How tickets are displayed in the ui', 'event_espresso') |
|
| 260 | - ), |
|
| 261 | - new GraphQLField( |
|
| 262 | - 'sold', |
|
| 263 | - 'Int', |
|
| 264 | - 'sold', |
|
| 265 | - esc_html__('Number of this ticket sold', 'event_espresso') |
|
| 266 | - ), |
|
| 267 | - new GraphQLOutputField( |
|
| 268 | - 'status', |
|
| 269 | - $this->namespace . 'TicketStatusEnum', |
|
| 270 | - 'ticket_status', |
|
| 271 | - esc_html__('Ticket status', 'event_espresso') |
|
| 272 | - ), |
|
| 273 | - new GraphQLField( |
|
| 274 | - 'startDate', |
|
| 275 | - 'String', |
|
| 276 | - 'start_date', |
|
| 277 | - esc_html__('Start date and time of the Ticket', 'event_espresso'), |
|
| 278 | - [$this, 'formatDatetime'] |
|
| 279 | - ), |
|
| 280 | - new GraphQLField( |
|
| 281 | - 'uses', |
|
| 282 | - 'Int', |
|
| 283 | - 'uses', |
|
| 284 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
| 285 | - [$this, 'parseInfiniteValue'] |
|
| 286 | - ), |
|
| 287 | - new GraphQLOutputField( |
|
| 288 | - 'wpUser', |
|
| 289 | - 'User', |
|
| 290 | - null, |
|
| 291 | - esc_html__('Ticket Creator', 'event_espresso') |
|
| 292 | - ), |
|
| 293 | - new GraphQLInputField( |
|
| 294 | - 'wpUser', |
|
| 295 | - 'Int', |
|
| 296 | - null, |
|
| 297 | - esc_html__('Ticket Creator ID', 'event_espresso') |
|
| 298 | - ), |
|
| 299 | - ]; |
|
| 52 | + /** |
|
| 53 | + * @return GraphQLFieldInterface[] |
|
| 54 | + * @since $VID:$ |
|
| 55 | + */ |
|
| 56 | + public function getFields() |
|
| 57 | + { |
|
| 58 | + $fields = [ |
|
| 59 | + new GraphQLField( |
|
| 60 | + 'id', |
|
| 61 | + ['non_null' => 'ID'], |
|
| 62 | + null, |
|
| 63 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
| 64 | + ), |
|
| 65 | + new GraphQLOutputField( |
|
| 66 | + 'dbId', |
|
| 67 | + ['non_null' => 'Int'], |
|
| 68 | + 'ID', |
|
| 69 | + esc_html__('Ticket ID', 'event_espresso') |
|
| 70 | + ), |
|
| 71 | + new GraphQLOutputField( |
|
| 72 | + 'cacheId', |
|
| 73 | + ['non_null' => 'String'], |
|
| 74 | + null, |
|
| 75 | + esc_html__('The cache ID of the object.', 'event_espresso') |
|
| 76 | + ), |
|
| 77 | + new GraphQLInputField( |
|
| 78 | + 'datetimes', |
|
| 79 | + ['list_of' => 'ID'], |
|
| 80 | + null, |
|
| 81 | + sprintf( |
|
| 82 | + '%1$s %2$s', |
|
| 83 | + esc_html__('Globally unique IDs of the datetimes related to the ticket.', 'event_espresso'), |
|
| 84 | + esc_html__('Ignored if empty.', 'event_espresso') |
|
| 85 | + ) |
|
| 86 | + ), |
|
| 87 | + new GraphQLField( |
|
| 88 | + 'description', |
|
| 89 | + 'String', |
|
| 90 | + 'description', |
|
| 91 | + esc_html__('Description of Ticket', 'event_espresso') |
|
| 92 | + ), |
|
| 93 | + new GraphQLField( |
|
| 94 | + 'endDate', |
|
| 95 | + 'String', |
|
| 96 | + 'end_date', |
|
| 97 | + esc_html__('End date and time of the Ticket', 'event_espresso'), |
|
| 98 | + [$this, 'formatDatetime'] |
|
| 99 | + ), |
|
| 100 | + new GraphQLOutputField( |
|
| 101 | + 'event', |
|
| 102 | + $this->namespace . 'Event', |
|
| 103 | + null, |
|
| 104 | + esc_html__('Event of the ticket.', 'event_espresso') |
|
| 105 | + ), |
|
| 106 | + new GraphQLField( |
|
| 107 | + 'isDefault', |
|
| 108 | + 'Boolean', |
|
| 109 | + 'is_default', |
|
| 110 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso') |
|
| 111 | + ), |
|
| 112 | + new GraphQLOutputField( |
|
| 113 | + 'isExpired', |
|
| 114 | + 'Boolean', |
|
| 115 | + 'is_expired', |
|
| 116 | + esc_html__('Flag indicating ticket is no longer available because its available dates have expired', 'event_espresso') |
|
| 117 | + ), |
|
| 118 | + new GraphQLOutputField( |
|
| 119 | + 'isFree', |
|
| 120 | + 'Boolean', |
|
| 121 | + 'is_free', |
|
| 122 | + esc_html__('Flag indicating whether the ticket is free.', 'event_espresso') |
|
| 123 | + ), |
|
| 124 | + new GraphQLOutputField( |
|
| 125 | + 'isOnSale', |
|
| 126 | + 'Boolean', |
|
| 127 | + 'is_on_sale', |
|
| 128 | + esc_html__('Flag indicating ticket ticket is on sale or not', 'event_espresso') |
|
| 129 | + ), |
|
| 130 | + new GraphQLOutputField( |
|
| 131 | + 'isPending', |
|
| 132 | + 'Boolean', |
|
| 133 | + 'is_pending', |
|
| 134 | + esc_html__('Flag indicating ticket is yet to go on sale or not', 'event_espresso') |
|
| 135 | + ), |
|
| 136 | + new GraphQLField( |
|
| 137 | + 'isRequired', |
|
| 138 | + 'Boolean', |
|
| 139 | + 'required', |
|
| 140 | + esc_html__( |
|
| 141 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
| 142 | + 'event_espresso' |
|
| 143 | + ) |
|
| 144 | + ), |
|
| 145 | + new GraphQLOutputField( |
|
| 146 | + 'isSoldOut', |
|
| 147 | + 'Boolean', |
|
| 148 | + null, |
|
| 149 | + esc_html__('Flag indicating whether the ticket is sold out', 'event_espresso'), |
|
| 150 | + null, |
|
| 151 | + [$this, 'getIsSoldOut'] |
|
| 152 | + ), |
|
| 153 | + new GraphQLField( |
|
| 154 | + 'isTaxable', |
|
| 155 | + 'Boolean', |
|
| 156 | + 'taxable', |
|
| 157 | + esc_html__( |
|
| 158 | + 'Flag indicating whether there is tax applied on this ticket', |
|
| 159 | + 'event_espresso' |
|
| 160 | + ) |
|
| 161 | + ), |
|
| 162 | + new GraphQLField( |
|
| 163 | + 'isTrashed', |
|
| 164 | + 'Boolean', |
|
| 165 | + 'deleted', |
|
| 166 | + esc_html__('Flag indicating ticket has been trashed.', 'event_espresso') |
|
| 167 | + ), |
|
| 168 | + new GraphQLField( |
|
| 169 | + 'max', |
|
| 170 | + 'Int', |
|
| 171 | + 'max', |
|
| 172 | + esc_html__( |
|
| 173 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
| 174 | + 'event_espresso' |
|
| 175 | + ), |
|
| 176 | + [$this, 'parseInfiniteValue'] |
|
| 177 | + ), |
|
| 178 | + new GraphQLField( |
|
| 179 | + 'min', |
|
| 180 | + 'Int', |
|
| 181 | + 'min', |
|
| 182 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso') |
|
| 183 | + ), |
|
| 184 | + new GraphQLField( |
|
| 185 | + 'name', |
|
| 186 | + 'String', |
|
| 187 | + 'name', |
|
| 188 | + esc_html__('Ticket Name', 'event_espresso') |
|
| 189 | + ), |
|
| 190 | + new GraphQLField( |
|
| 191 | + 'order', |
|
| 192 | + 'Int', |
|
| 193 | + 'order', |
|
| 194 | + esc_html__('The order in which the Datetime is displayed', 'event_espresso') |
|
| 195 | + ), |
|
| 196 | + new GraphQLOutputField( |
|
| 197 | + 'parent', |
|
| 198 | + $this->name(), |
|
| 199 | + null, |
|
| 200 | + esc_html__('The parent ticket of the current ticket', 'event_espresso') |
|
| 201 | + ), |
|
| 202 | + new GraphQLInputField( |
|
| 203 | + 'parent', |
|
| 204 | + 'ID', |
|
| 205 | + null, |
|
| 206 | + esc_html__('The parent ticket ID', 'event_espresso') |
|
| 207 | + ), |
|
| 208 | + new GraphQLField( |
|
| 209 | + 'price', |
|
| 210 | + 'Float', |
|
| 211 | + 'price', |
|
| 212 | + esc_html__('Final calculated price for ticket', 'event_espresso') |
|
| 213 | + ), |
|
| 214 | + new GraphQLInputField( |
|
| 215 | + 'prices', |
|
| 216 | + ['list_of' => 'ID'], |
|
| 217 | + null, |
|
| 218 | + sprintf( |
|
| 219 | + '%1$s %2$s', |
|
| 220 | + esc_html__('Globally unique IDs of the prices related to the ticket.', 'event_espresso'), |
|
| 221 | + esc_html__('Ignored if empty.', 'event_espresso') |
|
| 222 | + ) |
|
| 223 | + ), |
|
| 224 | + new GraphQLField( |
|
| 225 | + 'quantity', |
|
| 226 | + 'Int', |
|
| 227 | + 'qty', |
|
| 228 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
| 229 | + [$this, 'parseInfiniteValue'] |
|
| 230 | + ), |
|
| 231 | + new GraphQLOutputField( |
|
| 232 | + 'registrationCount', |
|
| 233 | + 'Int', |
|
| 234 | + 'count_registrations', |
|
| 235 | + esc_html__('Number of registrations for the ticket', 'event_espresso') |
|
| 236 | + ), |
|
| 237 | + new GraphQLField( |
|
| 238 | + 'reserved', |
|
| 239 | + 'Int', |
|
| 240 | + 'reserved', |
|
| 241 | + esc_html__( |
|
| 242 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
| 243 | + 'event_espresso' |
|
| 244 | + ) |
|
| 245 | + ), |
|
| 246 | + new GraphQLField( |
|
| 247 | + 'reverseCalculate', |
|
| 248 | + 'Boolean', |
|
| 249 | + 'reverse_calculate', |
|
| 250 | + esc_html__( |
|
| 251 | + 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
|
| 252 | + 'event_espresso' |
|
| 253 | + ) |
|
| 254 | + ), |
|
| 255 | + new GraphQLField( |
|
| 256 | + 'row', |
|
| 257 | + 'Int', |
|
| 258 | + 'row', |
|
| 259 | + esc_html__('How tickets are displayed in the ui', 'event_espresso') |
|
| 260 | + ), |
|
| 261 | + new GraphQLField( |
|
| 262 | + 'sold', |
|
| 263 | + 'Int', |
|
| 264 | + 'sold', |
|
| 265 | + esc_html__('Number of this ticket sold', 'event_espresso') |
|
| 266 | + ), |
|
| 267 | + new GraphQLOutputField( |
|
| 268 | + 'status', |
|
| 269 | + $this->namespace . 'TicketStatusEnum', |
|
| 270 | + 'ticket_status', |
|
| 271 | + esc_html__('Ticket status', 'event_espresso') |
|
| 272 | + ), |
|
| 273 | + new GraphQLField( |
|
| 274 | + 'startDate', |
|
| 275 | + 'String', |
|
| 276 | + 'start_date', |
|
| 277 | + esc_html__('Start date and time of the Ticket', 'event_espresso'), |
|
| 278 | + [$this, 'formatDatetime'] |
|
| 279 | + ), |
|
| 280 | + new GraphQLField( |
|
| 281 | + 'uses', |
|
| 282 | + 'Int', |
|
| 283 | + 'uses', |
|
| 284 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
| 285 | + [$this, 'parseInfiniteValue'] |
|
| 286 | + ), |
|
| 287 | + new GraphQLOutputField( |
|
| 288 | + 'wpUser', |
|
| 289 | + 'User', |
|
| 290 | + null, |
|
| 291 | + esc_html__('Ticket Creator', 'event_espresso') |
|
| 292 | + ), |
|
| 293 | + new GraphQLInputField( |
|
| 294 | + 'wpUser', |
|
| 295 | + 'Int', |
|
| 296 | + null, |
|
| 297 | + esc_html__('Ticket Creator ID', 'event_espresso') |
|
| 298 | + ), |
|
| 299 | + ]; |
|
| 300 | 300 | |
| 301 | - return apply_filters( |
|
| 302 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__ticket_fields', |
|
| 303 | - $fields, |
|
| 304 | - $this->name, |
|
| 305 | - $this->model |
|
| 306 | - ); |
|
| 307 | - } |
|
| 301 | + return apply_filters( |
|
| 302 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__ticket_fields', |
|
| 303 | + $fields, |
|
| 304 | + $this->name, |
|
| 305 | + $this->model |
|
| 306 | + ); |
|
| 307 | + } |
|
| 308 | 308 | |
| 309 | 309 | |
| 310 | - /** |
|
| 311 | - * @param EE_Ticket $source The source that's passed down the GraphQL queries |
|
| 312 | - * @param array $args The inputArgs on the field |
|
| 313 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 314 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 315 | - * @return string |
|
| 316 | - * @throws Exception |
|
| 317 | - * @throws InvalidArgumentException |
|
| 318 | - * @throws InvalidDataTypeException |
|
| 319 | - * @throws InvalidInterfaceException |
|
| 320 | - * @throws ReflectionException |
|
| 321 | - * @throws UserError |
|
| 322 | - * @throws UnexpectedEntityException |
|
| 323 | - * @since $VID:$ |
|
| 324 | - */ |
|
| 325 | - public function getIsSoldOut(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info) |
|
| 326 | - { |
|
| 327 | - return $source->ticket_status() === EE_Ticket::sold_out; |
|
| 328 | - } |
|
| 310 | + /** |
|
| 311 | + * @param EE_Ticket $source The source that's passed down the GraphQL queries |
|
| 312 | + * @param array $args The inputArgs on the field |
|
| 313 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
| 314 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
| 315 | + * @return string |
|
| 316 | + * @throws Exception |
|
| 317 | + * @throws InvalidArgumentException |
|
| 318 | + * @throws InvalidDataTypeException |
|
| 319 | + * @throws InvalidInterfaceException |
|
| 320 | + * @throws ReflectionException |
|
| 321 | + * @throws UserError |
|
| 322 | + * @throws UnexpectedEntityException |
|
| 323 | + * @since $VID:$ |
|
| 324 | + */ |
|
| 325 | + public function getIsSoldOut(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info) |
|
| 326 | + { |
|
| 327 | + return $source->ticket_status() === EE_Ticket::sold_out; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * @param array $inputFields The mutation input fields. |
|
| 333 | - * @throws InvalidArgumentException |
|
| 334 | - * @throws ReflectionException |
|
| 335 | - * @since $VID:$ |
|
| 336 | - */ |
|
| 337 | - public function registerMutations(array $inputFields) |
|
| 338 | - { |
|
| 339 | - register_graphql_input_type( |
|
| 340 | - 'Update' . $this->name() . 'BaseInput', |
|
| 341 | - [ |
|
| 342 | - 'fields' => $inputFields, |
|
| 343 | - ] |
|
| 344 | - ); |
|
| 345 | - // Register mutation to update an entity. |
|
| 346 | - register_graphql_mutation( |
|
| 347 | - 'update' . $this->name(), |
|
| 348 | - [ |
|
| 349 | - 'inputFields' => $inputFields, |
|
| 350 | - 'outputFields' => [ |
|
| 351 | - lcfirst($this->name()) => [ |
|
| 352 | - 'type' => $this->name(), |
|
| 353 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
| 354 | - ], |
|
| 355 | - ], |
|
| 356 | - 'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this), |
|
| 357 | - ] |
|
| 358 | - ); |
|
| 359 | - $base_input = 'Update' . $this->name() . 'BaseInput'; |
|
| 360 | - // Register mutation to update an entity. |
|
| 361 | - register_graphql_mutation( |
|
| 362 | - 'bulkUpdate' . $this->name(), |
|
| 363 | - array_merge( |
|
| 364 | - Datetime::bulkUpdateBaseConfig($base_input), |
|
| 365 | - [ |
|
| 366 | - 'mutateAndGetPayload' => TicketBulkUpdate::mutateAndGetPayload($this->model, $this), |
|
| 367 | - ] |
|
| 368 | - ) |
|
| 369 | - ); |
|
| 370 | - // Register mutation to delete an entity. |
|
| 371 | - register_graphql_mutation( |
|
| 372 | - 'delete' . $this->name(), |
|
| 373 | - [ |
|
| 374 | - 'inputFields' => [ |
|
| 375 | - 'id' => $inputFields['id'], |
|
| 376 | - 'deletePermanently' => [ |
|
| 377 | - 'type' => 'Boolean', |
|
| 378 | - 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
| 379 | - ], |
|
| 380 | - ], |
|
| 381 | - 'outputFields' => [ |
|
| 382 | - lcfirst($this->name()) => [ |
|
| 383 | - 'type' => $this->name(), |
|
| 384 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
| 385 | - 'resolve' => static function ($payload) { |
|
| 386 | - $deleted = (object) $payload['deleted']; |
|
| 331 | + /** |
|
| 332 | + * @param array $inputFields The mutation input fields. |
|
| 333 | + * @throws InvalidArgumentException |
|
| 334 | + * @throws ReflectionException |
|
| 335 | + * @since $VID:$ |
|
| 336 | + */ |
|
| 337 | + public function registerMutations(array $inputFields) |
|
| 338 | + { |
|
| 339 | + register_graphql_input_type( |
|
| 340 | + 'Update' . $this->name() . 'BaseInput', |
|
| 341 | + [ |
|
| 342 | + 'fields' => $inputFields, |
|
| 343 | + ] |
|
| 344 | + ); |
|
| 345 | + // Register mutation to update an entity. |
|
| 346 | + register_graphql_mutation( |
|
| 347 | + 'update' . $this->name(), |
|
| 348 | + [ |
|
| 349 | + 'inputFields' => $inputFields, |
|
| 350 | + 'outputFields' => [ |
|
| 351 | + lcfirst($this->name()) => [ |
|
| 352 | + 'type' => $this->name(), |
|
| 353 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
| 354 | + ], |
|
| 355 | + ], |
|
| 356 | + 'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this), |
|
| 357 | + ] |
|
| 358 | + ); |
|
| 359 | + $base_input = 'Update' . $this->name() . 'BaseInput'; |
|
| 360 | + // Register mutation to update an entity. |
|
| 361 | + register_graphql_mutation( |
|
| 362 | + 'bulkUpdate' . $this->name(), |
|
| 363 | + array_merge( |
|
| 364 | + Datetime::bulkUpdateBaseConfig($base_input), |
|
| 365 | + [ |
|
| 366 | + 'mutateAndGetPayload' => TicketBulkUpdate::mutateAndGetPayload($this->model, $this), |
|
| 367 | + ] |
|
| 368 | + ) |
|
| 369 | + ); |
|
| 370 | + // Register mutation to delete an entity. |
|
| 371 | + register_graphql_mutation( |
|
| 372 | + 'delete' . $this->name(), |
|
| 373 | + [ |
|
| 374 | + 'inputFields' => [ |
|
| 375 | + 'id' => $inputFields['id'], |
|
| 376 | + 'deletePermanently' => [ |
|
| 377 | + 'type' => 'Boolean', |
|
| 378 | + 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
| 379 | + ], |
|
| 380 | + ], |
|
| 381 | + 'outputFields' => [ |
|
| 382 | + lcfirst($this->name()) => [ |
|
| 383 | + 'type' => $this->name(), |
|
| 384 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
| 385 | + 'resolve' => static function ($payload) { |
|
| 386 | + $deleted = (object) $payload['deleted']; |
|
| 387 | 387 | |
| 388 | - return ! empty($deleted) ? $deleted : null; |
|
| 389 | - }, |
|
| 390 | - ], |
|
| 391 | - ], |
|
| 392 | - 'mutateAndGetPayload' => TicketDelete::mutateAndGetPayload($this->model, $this), |
|
| 393 | - ] |
|
| 394 | - ); |
|
| 388 | + return ! empty($deleted) ? $deleted : null; |
|
| 389 | + }, |
|
| 390 | + ], |
|
| 391 | + ], |
|
| 392 | + 'mutateAndGetPayload' => TicketDelete::mutateAndGetPayload($this->model, $this), |
|
| 393 | + ] |
|
| 394 | + ); |
|
| 395 | 395 | |
| 396 | - // remove primary key from input. |
|
| 397 | - unset($inputFields['id']); |
|
| 398 | - // Register mutation to update an entity. |
|
| 399 | - register_graphql_mutation( |
|
| 400 | - 'create' . $this->name(), |
|
| 401 | - [ |
|
| 402 | - 'inputFields' => $inputFields, |
|
| 403 | - 'outputFields' => [ |
|
| 404 | - lcfirst($this->name()) => [ |
|
| 405 | - 'type' => $this->name(), |
|
| 406 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
| 407 | - ], |
|
| 408 | - ], |
|
| 409 | - 'mutateAndGetPayload' => TicketCreate::mutateAndGetPayload($this->model, $this), |
|
| 410 | - ] |
|
| 411 | - ); |
|
| 412 | - } |
|
| 396 | + // remove primary key from input. |
|
| 397 | + unset($inputFields['id']); |
|
| 398 | + // Register mutation to update an entity. |
|
| 399 | + register_graphql_mutation( |
|
| 400 | + 'create' . $this->name(), |
|
| 401 | + [ |
|
| 402 | + 'inputFields' => $inputFields, |
|
| 403 | + 'outputFields' => [ |
|
| 404 | + lcfirst($this->name()) => [ |
|
| 405 | + 'type' => $this->name(), |
|
| 406 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
| 407 | + ], |
|
| 408 | + ], |
|
| 409 | + 'mutateAndGetPayload' => TicketCreate::mutateAndGetPayload($this->model, $this), |
|
| 410 | + ] |
|
| 411 | + ); |
|
| 412 | + } |
|
| 413 | 413 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | public function __construct(EEM_Ticket $ticket_model) |
| 43 | 43 | { |
| 44 | 44 | $this->model = $ticket_model; |
| 45 | - $this->setName($this->namespace . 'Ticket'); |
|
| 45 | + $this->setName($this->namespace.'Ticket'); |
|
| 46 | 46 | $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
| 47 | 47 | $this->setIsCustomPostType(false); |
| 48 | 48 | parent::__construct(); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | ), |
| 100 | 100 | new GraphQLOutputField( |
| 101 | 101 | 'event', |
| 102 | - $this->namespace . 'Event', |
|
| 102 | + $this->namespace.'Event', |
|
| 103 | 103 | null, |
| 104 | 104 | esc_html__('Event of the ticket.', 'event_espresso') |
| 105 | 105 | ), |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | ), |
| 267 | 267 | new GraphQLOutputField( |
| 268 | 268 | 'status', |
| 269 | - $this->namespace . 'TicketStatusEnum', |
|
| 269 | + $this->namespace.'TicketStatusEnum', |
|
| 270 | 270 | 'ticket_status', |
| 271 | 271 | esc_html__('Ticket status', 'event_espresso') |
| 272 | 272 | ), |
@@ -337,14 +337,14 @@ discard block |
||
| 337 | 337 | public function registerMutations(array $inputFields) |
| 338 | 338 | { |
| 339 | 339 | register_graphql_input_type( |
| 340 | - 'Update' . $this->name() . 'BaseInput', |
|
| 340 | + 'Update'.$this->name().'BaseInput', |
|
| 341 | 341 | [ |
| 342 | 342 | 'fields' => $inputFields, |
| 343 | 343 | ] |
| 344 | 344 | ); |
| 345 | 345 | // Register mutation to update an entity. |
| 346 | 346 | register_graphql_mutation( |
| 347 | - 'update' . $this->name(), |
|
| 347 | + 'update'.$this->name(), |
|
| 348 | 348 | [ |
| 349 | 349 | 'inputFields' => $inputFields, |
| 350 | 350 | 'outputFields' => [ |
@@ -356,10 +356,10 @@ discard block |
||
| 356 | 356 | 'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this), |
| 357 | 357 | ] |
| 358 | 358 | ); |
| 359 | - $base_input = 'Update' . $this->name() . 'BaseInput'; |
|
| 359 | + $base_input = 'Update'.$this->name().'BaseInput'; |
|
| 360 | 360 | // Register mutation to update an entity. |
| 361 | 361 | register_graphql_mutation( |
| 362 | - 'bulkUpdate' . $this->name(), |
|
| 362 | + 'bulkUpdate'.$this->name(), |
|
| 363 | 363 | array_merge( |
| 364 | 364 | Datetime::bulkUpdateBaseConfig($base_input), |
| 365 | 365 | [ |
@@ -369,7 +369,7 @@ discard block |
||
| 369 | 369 | ); |
| 370 | 370 | // Register mutation to delete an entity. |
| 371 | 371 | register_graphql_mutation( |
| 372 | - 'delete' . $this->name(), |
|
| 372 | + 'delete'.$this->name(), |
|
| 373 | 373 | [ |
| 374 | 374 | 'inputFields' => [ |
| 375 | 375 | 'id' => $inputFields['id'], |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | lcfirst($this->name()) => [ |
| 383 | 383 | 'type' => $this->name(), |
| 384 | 384 | 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
| 385 | - 'resolve' => static function ($payload) { |
|
| 385 | + 'resolve' => static function($payload) { |
|
| 386 | 386 | $deleted = (object) $payload['deleted']; |
| 387 | 387 | |
| 388 | 388 | return ! empty($deleted) ? $deleted : null; |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | unset($inputFields['id']); |
| 398 | 398 | // Register mutation to update an entity. |
| 399 | 399 | register_graphql_mutation( |
| 400 | - 'create' . $this->name(), |
|
| 400 | + 'create'.$this->name(), |
|
| 401 | 401 | [ |
| 402 | 402 | 'inputFields' => $inputFields, |
| 403 | 403 | 'outputFields' => [ |
@@ -13,446 +13,446 @@ |
||
| 13 | 13 | class EE_Price extends EE_Soft_Delete_Base_Class |
| 14 | 14 | { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * @param array $props_n_values incoming values |
|
| 18 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 19 | - * used.) |
|
| 20 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 21 | - * date_format and the second value is the time format |
|
| 22 | - * @return EE_Price |
|
| 23 | - * @throws EE_Error |
|
| 24 | - * @throws InvalidArgumentException |
|
| 25 | - * @throws ReflectionException |
|
| 26 | - * @throws InvalidDataTypeException |
|
| 27 | - * @throws InvalidInterfaceException |
|
| 28 | - */ |
|
| 29 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 30 | - { |
|
| 31 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 32 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param array $props_n_values incoming values from the database |
|
| 38 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 39 | - * the website will be used. |
|
| 40 | - * @return EE_Price |
|
| 41 | - * @throws EE_Error |
|
| 42 | - * @throws InvalidArgumentException |
|
| 43 | - * @throws ReflectionException |
|
| 44 | - * @throws InvalidDataTypeException |
|
| 45 | - * @throws InvalidInterfaceException |
|
| 46 | - */ |
|
| 47 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 48 | - { |
|
| 49 | - return new self($props_n_values, true, $timezone); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Set Price type ID |
|
| 55 | - * |
|
| 56 | - * @param int $PRT_ID |
|
| 57 | - * @throws EE_Error |
|
| 58 | - * @throws InvalidArgumentException |
|
| 59 | - * @throws ReflectionException |
|
| 60 | - * @throws InvalidDataTypeException |
|
| 61 | - * @throws InvalidInterfaceException |
|
| 62 | - */ |
|
| 63 | - public function set_type($PRT_ID = 0) |
|
| 64 | - { |
|
| 65 | - $this->set('PRT_ID', $PRT_ID); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Set Price Amount |
|
| 71 | - * |
|
| 72 | - * @param float $PRC_amount |
|
| 73 | - * @throws EE_Error |
|
| 74 | - * @throws InvalidArgumentException |
|
| 75 | - * @throws ReflectionException |
|
| 76 | - * @throws InvalidDataTypeException |
|
| 77 | - * @throws InvalidInterfaceException |
|
| 78 | - */ |
|
| 79 | - public function set_amount($PRC_amount = 0.00) |
|
| 80 | - { |
|
| 81 | - $this->set('PRC_amount', $PRC_amount); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Set Price Name |
|
| 87 | - * |
|
| 88 | - * @param string $PRC_name |
|
| 89 | - * @throws EE_Error |
|
| 90 | - * @throws InvalidArgumentException |
|
| 91 | - * @throws ReflectionException |
|
| 92 | - * @throws InvalidDataTypeException |
|
| 93 | - * @throws InvalidInterfaceException |
|
| 94 | - */ |
|
| 95 | - public function set_name($PRC_name = '') |
|
| 96 | - { |
|
| 97 | - $this->set('PRC_name', $PRC_name); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Set Price Description |
|
| 103 | - * |
|
| 104 | - * @param string $PRC_desc |
|
| 105 | - * @throws EE_Error |
|
| 106 | - * @throws InvalidArgumentException |
|
| 107 | - * @throws ReflectionException |
|
| 108 | - * @throws InvalidDataTypeException |
|
| 109 | - * @throws InvalidInterfaceException |
|
| 110 | - */ |
|
| 111 | - public function set_description($PRC_desc = '') |
|
| 112 | - { |
|
| 113 | - $this->Set('PRC_desc', $PRC_desc); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * set is_default |
|
| 119 | - * |
|
| 120 | - * @param bool $PRC_is_default |
|
| 121 | - * @throws EE_Error |
|
| 122 | - * @throws InvalidArgumentException |
|
| 123 | - * @throws ReflectionException |
|
| 124 | - * @throws InvalidDataTypeException |
|
| 125 | - * @throws InvalidInterfaceException |
|
| 126 | - */ |
|
| 127 | - public function set_is_default($PRC_is_default = false) |
|
| 128 | - { |
|
| 129 | - $this->set('PRC_is_default', $PRC_is_default); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * set deleted |
|
| 135 | - * |
|
| 136 | - * @param bool $PRC_deleted |
|
| 137 | - * @throws EE_Error |
|
| 138 | - * @throws InvalidArgumentException |
|
| 139 | - * @throws ReflectionException |
|
| 140 | - * @throws InvalidDataTypeException |
|
| 141 | - * @throws InvalidInterfaceException |
|
| 142 | - */ |
|
| 143 | - public function set_deleted($PRC_deleted = null) |
|
| 144 | - { |
|
| 145 | - $this->set('PRC_deleted', $PRC_deleted); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * get Price type |
|
| 151 | - * |
|
| 152 | - * @return int |
|
| 153 | - * @throws EE_Error |
|
| 154 | - * @throws InvalidArgumentException |
|
| 155 | - * @throws ReflectionException |
|
| 156 | - * @throws InvalidDataTypeException |
|
| 157 | - * @throws InvalidInterfaceException |
|
| 158 | - */ |
|
| 159 | - public function type() |
|
| 160 | - { |
|
| 161 | - return $this->get('PRT_ID'); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * get Price Amount |
|
| 167 | - * |
|
| 168 | - * @return float |
|
| 169 | - * @throws EE_Error |
|
| 170 | - * @throws InvalidArgumentException |
|
| 171 | - * @throws ReflectionException |
|
| 172 | - * @throws InvalidDataTypeException |
|
| 173 | - * @throws InvalidInterfaceException |
|
| 174 | - */ |
|
| 175 | - public function amount() |
|
| 176 | - { |
|
| 177 | - return $this->get('PRC_amount'); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * get Price Name |
|
| 183 | - * |
|
| 184 | - * @return string |
|
| 185 | - * @throws EE_Error |
|
| 186 | - * @throws InvalidArgumentException |
|
| 187 | - * @throws ReflectionException |
|
| 188 | - * @throws InvalidDataTypeException |
|
| 189 | - * @throws InvalidInterfaceException |
|
| 190 | - */ |
|
| 191 | - public function name() |
|
| 192 | - { |
|
| 193 | - return $this->get('PRC_name'); |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * get Price description |
|
| 199 | - * |
|
| 200 | - * @return string |
|
| 201 | - * @throws EE_Error |
|
| 202 | - * @throws InvalidArgumentException |
|
| 203 | - * @throws ReflectionException |
|
| 204 | - * @throws InvalidDataTypeException |
|
| 205 | - * @throws InvalidInterfaceException |
|
| 206 | - */ |
|
| 207 | - public function desc() |
|
| 208 | - { |
|
| 209 | - return $this->get('PRC_desc'); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * get overrides |
|
| 215 | - * |
|
| 216 | - * @return int |
|
| 217 | - * @throws EE_Error |
|
| 218 | - * @throws InvalidArgumentException |
|
| 219 | - * @throws ReflectionException |
|
| 220 | - * @throws InvalidDataTypeException |
|
| 221 | - * @throws InvalidInterfaceException |
|
| 222 | - */ |
|
| 223 | - public function overrides() |
|
| 224 | - { |
|
| 225 | - return $this->get('PRC_overrides'); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * get order |
|
| 231 | - * |
|
| 232 | - * @return int |
|
| 233 | - * @throws EE_Error |
|
| 234 | - * @throws InvalidArgumentException |
|
| 235 | - * @throws ReflectionException |
|
| 236 | - * @throws InvalidDataTypeException |
|
| 237 | - * @throws InvalidInterfaceException |
|
| 238 | - */ |
|
| 239 | - public function order() |
|
| 240 | - { |
|
| 241 | - return $this->get('PRC_order'); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * get the author of the price |
|
| 247 | - * |
|
| 248 | - * @return int |
|
| 249 | - * @throws EE_Error |
|
| 250 | - * @throws InvalidArgumentException |
|
| 251 | - * @throws ReflectionException |
|
| 252 | - * @throws InvalidDataTypeException |
|
| 253 | - * @throws InvalidInterfaceException |
|
| 254 | - * @since 4.5.0 |
|
| 255 | - */ |
|
| 256 | - public function wp_user() |
|
| 257 | - { |
|
| 258 | - return $this->get('PRC_wp_user'); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * get is_default |
|
| 264 | - * |
|
| 265 | - * @return bool |
|
| 266 | - * @throws EE_Error |
|
| 267 | - * @throws InvalidArgumentException |
|
| 268 | - * @throws ReflectionException |
|
| 269 | - * @throws InvalidDataTypeException |
|
| 270 | - * @throws InvalidInterfaceException |
|
| 271 | - */ |
|
| 272 | - public function is_default() |
|
| 273 | - { |
|
| 274 | - return $this->get('PRC_is_default'); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * get deleted |
|
| 280 | - * |
|
| 281 | - * @return bool |
|
| 282 | - * @throws EE_Error |
|
| 283 | - * @throws InvalidArgumentException |
|
| 284 | - * @throws ReflectionException |
|
| 285 | - * @throws InvalidDataTypeException |
|
| 286 | - * @throws InvalidInterfaceException |
|
| 287 | - */ |
|
| 288 | - public function deleted() |
|
| 289 | - { |
|
| 290 | - return $this->get('PRC_deleted'); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - |
|
| 294 | - /** |
|
| 295 | - * @return bool |
|
| 296 | - * @throws EE_Error |
|
| 297 | - * @throws InvalidArgumentException |
|
| 298 | - * @throws ReflectionException |
|
| 299 | - * @throws InvalidDataTypeException |
|
| 300 | - * @throws InvalidInterfaceException |
|
| 301 | - */ |
|
| 302 | - public function parent() |
|
| 303 | - { |
|
| 304 | - return $this->get('PRC_parent'); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - // some helper methods for getting info on the price_type for this price |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * return whether the price is a base price or not |
|
| 313 | - * |
|
| 314 | - * @return boolean |
|
| 315 | - * @throws EE_Error |
|
| 316 | - * @throws InvalidArgumentException |
|
| 317 | - * @throws InvalidDataTypeException |
|
| 318 | - * @throws InvalidInterfaceException |
|
| 319 | - * @throws ReflectionException |
|
| 320 | - */ |
|
| 321 | - public function is_base_price() |
|
| 322 | - { |
|
| 323 | - $price_type = $this->type_obj(); |
|
| 324 | - return $price_type->is_base_price(); |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * @return EE_Base_Class|EE_Price_Type |
|
| 330 | - * @throws EE_Error |
|
| 331 | - * @throws InvalidArgumentException |
|
| 332 | - * @throws ReflectionException |
|
| 333 | - * @throws InvalidDataTypeException |
|
| 334 | - * @throws InvalidInterfaceException |
|
| 335 | - */ |
|
| 336 | - public function type_obj() |
|
| 337 | - { |
|
| 338 | - return $this->get_first_related('Price_Type'); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * @return int |
|
| 344 | - * @throws EE_Error |
|
| 345 | - * @throws InvalidArgumentException |
|
| 346 | - * @throws ReflectionException |
|
| 347 | - * @throws InvalidDataTypeException |
|
| 348 | - * @throws InvalidInterfaceException |
|
| 349 | - */ |
|
| 350 | - public function type_order() |
|
| 351 | - { |
|
| 352 | - return $this->get_first_related('Price_Type')->order(); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * Simply indicates whether this price increases or decreases the total |
|
| 358 | - * |
|
| 359 | - * @return boolean true = discount, otherwise adds to the total |
|
| 360 | - * @throws EE_Error |
|
| 361 | - * @throws InvalidArgumentException |
|
| 362 | - * @throws ReflectionException |
|
| 363 | - * @throws InvalidDataTypeException |
|
| 364 | - * @throws InvalidInterfaceException |
|
| 365 | - */ |
|
| 366 | - public function is_discount() |
|
| 367 | - { |
|
| 368 | - $price_type = $this->type_obj(); |
|
| 369 | - return $price_type->is_discount(); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * whether the price is a percentage or not |
|
| 375 | - * |
|
| 376 | - * @return boolean |
|
| 377 | - * @throws EE_Error |
|
| 378 | - * @throws InvalidArgumentException |
|
| 379 | - * @throws InvalidDataTypeException |
|
| 380 | - * @throws InvalidInterfaceException |
|
| 381 | - * @throws ReflectionException |
|
| 382 | - */ |
|
| 383 | - public function is_percent() |
|
| 384 | - { |
|
| 385 | - $price_type = $this->type_obj(); |
|
| 386 | - return $price_type->is_percent(); |
|
| 387 | - } |
|
| 388 | - |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * whether the price is a percentage or not |
|
| 392 | - * |
|
| 393 | - * @return boolean |
|
| 394 | - * @throws EE_Error |
|
| 395 | - * @throws InvalidArgumentException |
|
| 396 | - * @throws ReflectionException |
|
| 397 | - * @throws InvalidDataTypeException |
|
| 398 | - * @throws InvalidInterfaceException |
|
| 399 | - */ |
|
| 400 | - public function is_surcharge() |
|
| 401 | - { |
|
| 402 | - $price_type = $this->type_obj(); |
|
| 403 | - return $price_type->is_surcharge(); |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * whether the price is a percentage or not |
|
| 408 | - * |
|
| 409 | - * @return boolean |
|
| 410 | - * @throws EE_Error |
|
| 411 | - * @throws InvalidArgumentException |
|
| 412 | - * @throws ReflectionException |
|
| 413 | - * @throws InvalidDataTypeException |
|
| 414 | - * @throws InvalidInterfaceException |
|
| 415 | - */ |
|
| 416 | - public function is_tax() |
|
| 417 | - { |
|
| 418 | - $price_type = $this->type_obj(); |
|
| 419 | - return $price_type->is_tax(); |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - |
|
| 423 | - /** |
|
| 424 | - * return pretty price dependant on whether its a dollar or percent. |
|
| 425 | - * |
|
| 426 | - * @return string |
|
| 427 | - * @throws EE_Error |
|
| 428 | - * @throws InvalidArgumentException |
|
| 429 | - * @throws ReflectionException |
|
| 430 | - * @throws InvalidDataTypeException |
|
| 431 | - * @throws InvalidInterfaceException |
|
| 432 | - * @since 4.4.0 |
|
| 433 | - */ |
|
| 434 | - public function pretty_price() |
|
| 435 | - { |
|
| 436 | - return ! $this->is_percent() |
|
| 437 | - ? $this->get_pretty('PRC_amount') |
|
| 438 | - : $this->get('PRC_amount') . '%'; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - /** |
|
| 443 | - * @return mixed |
|
| 444 | - * @throws EE_Error |
|
| 445 | - * @throws InvalidArgumentException |
|
| 446 | - * @throws ReflectionException |
|
| 447 | - * @throws InvalidDataTypeException |
|
| 448 | - * @throws InvalidInterfaceException |
|
| 449 | - */ |
|
| 450 | - public function get_price_without_currency_symbol() |
|
| 451 | - { |
|
| 452 | - return str_replace( |
|
| 453 | - EE_Registry::instance()->CFG->currency->sign, |
|
| 454 | - '', |
|
| 455 | - $this->get_pretty('PRC_amount') |
|
| 456 | - ); |
|
| 457 | - } |
|
| 16 | + /** |
|
| 17 | + * @param array $props_n_values incoming values |
|
| 18 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
| 19 | + * used.) |
|
| 20 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
| 21 | + * date_format and the second value is the time format |
|
| 22 | + * @return EE_Price |
|
| 23 | + * @throws EE_Error |
|
| 24 | + * @throws InvalidArgumentException |
|
| 25 | + * @throws ReflectionException |
|
| 26 | + * @throws InvalidDataTypeException |
|
| 27 | + * @throws InvalidInterfaceException |
|
| 28 | + */ |
|
| 29 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
| 30 | + { |
|
| 31 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
| 32 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param array $props_n_values incoming values from the database |
|
| 38 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
| 39 | + * the website will be used. |
|
| 40 | + * @return EE_Price |
|
| 41 | + * @throws EE_Error |
|
| 42 | + * @throws InvalidArgumentException |
|
| 43 | + * @throws ReflectionException |
|
| 44 | + * @throws InvalidDataTypeException |
|
| 45 | + * @throws InvalidInterfaceException |
|
| 46 | + */ |
|
| 47 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
| 48 | + { |
|
| 49 | + return new self($props_n_values, true, $timezone); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Set Price type ID |
|
| 55 | + * |
|
| 56 | + * @param int $PRT_ID |
|
| 57 | + * @throws EE_Error |
|
| 58 | + * @throws InvalidArgumentException |
|
| 59 | + * @throws ReflectionException |
|
| 60 | + * @throws InvalidDataTypeException |
|
| 61 | + * @throws InvalidInterfaceException |
|
| 62 | + */ |
|
| 63 | + public function set_type($PRT_ID = 0) |
|
| 64 | + { |
|
| 65 | + $this->set('PRT_ID', $PRT_ID); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Set Price Amount |
|
| 71 | + * |
|
| 72 | + * @param float $PRC_amount |
|
| 73 | + * @throws EE_Error |
|
| 74 | + * @throws InvalidArgumentException |
|
| 75 | + * @throws ReflectionException |
|
| 76 | + * @throws InvalidDataTypeException |
|
| 77 | + * @throws InvalidInterfaceException |
|
| 78 | + */ |
|
| 79 | + public function set_amount($PRC_amount = 0.00) |
|
| 80 | + { |
|
| 81 | + $this->set('PRC_amount', $PRC_amount); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Set Price Name |
|
| 87 | + * |
|
| 88 | + * @param string $PRC_name |
|
| 89 | + * @throws EE_Error |
|
| 90 | + * @throws InvalidArgumentException |
|
| 91 | + * @throws ReflectionException |
|
| 92 | + * @throws InvalidDataTypeException |
|
| 93 | + * @throws InvalidInterfaceException |
|
| 94 | + */ |
|
| 95 | + public function set_name($PRC_name = '') |
|
| 96 | + { |
|
| 97 | + $this->set('PRC_name', $PRC_name); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Set Price Description |
|
| 103 | + * |
|
| 104 | + * @param string $PRC_desc |
|
| 105 | + * @throws EE_Error |
|
| 106 | + * @throws InvalidArgumentException |
|
| 107 | + * @throws ReflectionException |
|
| 108 | + * @throws InvalidDataTypeException |
|
| 109 | + * @throws InvalidInterfaceException |
|
| 110 | + */ |
|
| 111 | + public function set_description($PRC_desc = '') |
|
| 112 | + { |
|
| 113 | + $this->Set('PRC_desc', $PRC_desc); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * set is_default |
|
| 119 | + * |
|
| 120 | + * @param bool $PRC_is_default |
|
| 121 | + * @throws EE_Error |
|
| 122 | + * @throws InvalidArgumentException |
|
| 123 | + * @throws ReflectionException |
|
| 124 | + * @throws InvalidDataTypeException |
|
| 125 | + * @throws InvalidInterfaceException |
|
| 126 | + */ |
|
| 127 | + public function set_is_default($PRC_is_default = false) |
|
| 128 | + { |
|
| 129 | + $this->set('PRC_is_default', $PRC_is_default); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * set deleted |
|
| 135 | + * |
|
| 136 | + * @param bool $PRC_deleted |
|
| 137 | + * @throws EE_Error |
|
| 138 | + * @throws InvalidArgumentException |
|
| 139 | + * @throws ReflectionException |
|
| 140 | + * @throws InvalidDataTypeException |
|
| 141 | + * @throws InvalidInterfaceException |
|
| 142 | + */ |
|
| 143 | + public function set_deleted($PRC_deleted = null) |
|
| 144 | + { |
|
| 145 | + $this->set('PRC_deleted', $PRC_deleted); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * get Price type |
|
| 151 | + * |
|
| 152 | + * @return int |
|
| 153 | + * @throws EE_Error |
|
| 154 | + * @throws InvalidArgumentException |
|
| 155 | + * @throws ReflectionException |
|
| 156 | + * @throws InvalidDataTypeException |
|
| 157 | + * @throws InvalidInterfaceException |
|
| 158 | + */ |
|
| 159 | + public function type() |
|
| 160 | + { |
|
| 161 | + return $this->get('PRT_ID'); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * get Price Amount |
|
| 167 | + * |
|
| 168 | + * @return float |
|
| 169 | + * @throws EE_Error |
|
| 170 | + * @throws InvalidArgumentException |
|
| 171 | + * @throws ReflectionException |
|
| 172 | + * @throws InvalidDataTypeException |
|
| 173 | + * @throws InvalidInterfaceException |
|
| 174 | + */ |
|
| 175 | + public function amount() |
|
| 176 | + { |
|
| 177 | + return $this->get('PRC_amount'); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * get Price Name |
|
| 183 | + * |
|
| 184 | + * @return string |
|
| 185 | + * @throws EE_Error |
|
| 186 | + * @throws InvalidArgumentException |
|
| 187 | + * @throws ReflectionException |
|
| 188 | + * @throws InvalidDataTypeException |
|
| 189 | + * @throws InvalidInterfaceException |
|
| 190 | + */ |
|
| 191 | + public function name() |
|
| 192 | + { |
|
| 193 | + return $this->get('PRC_name'); |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * get Price description |
|
| 199 | + * |
|
| 200 | + * @return string |
|
| 201 | + * @throws EE_Error |
|
| 202 | + * @throws InvalidArgumentException |
|
| 203 | + * @throws ReflectionException |
|
| 204 | + * @throws InvalidDataTypeException |
|
| 205 | + * @throws InvalidInterfaceException |
|
| 206 | + */ |
|
| 207 | + public function desc() |
|
| 208 | + { |
|
| 209 | + return $this->get('PRC_desc'); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * get overrides |
|
| 215 | + * |
|
| 216 | + * @return int |
|
| 217 | + * @throws EE_Error |
|
| 218 | + * @throws InvalidArgumentException |
|
| 219 | + * @throws ReflectionException |
|
| 220 | + * @throws InvalidDataTypeException |
|
| 221 | + * @throws InvalidInterfaceException |
|
| 222 | + */ |
|
| 223 | + public function overrides() |
|
| 224 | + { |
|
| 225 | + return $this->get('PRC_overrides'); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * get order |
|
| 231 | + * |
|
| 232 | + * @return int |
|
| 233 | + * @throws EE_Error |
|
| 234 | + * @throws InvalidArgumentException |
|
| 235 | + * @throws ReflectionException |
|
| 236 | + * @throws InvalidDataTypeException |
|
| 237 | + * @throws InvalidInterfaceException |
|
| 238 | + */ |
|
| 239 | + public function order() |
|
| 240 | + { |
|
| 241 | + return $this->get('PRC_order'); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * get the author of the price |
|
| 247 | + * |
|
| 248 | + * @return int |
|
| 249 | + * @throws EE_Error |
|
| 250 | + * @throws InvalidArgumentException |
|
| 251 | + * @throws ReflectionException |
|
| 252 | + * @throws InvalidDataTypeException |
|
| 253 | + * @throws InvalidInterfaceException |
|
| 254 | + * @since 4.5.0 |
|
| 255 | + */ |
|
| 256 | + public function wp_user() |
|
| 257 | + { |
|
| 258 | + return $this->get('PRC_wp_user'); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * get is_default |
|
| 264 | + * |
|
| 265 | + * @return bool |
|
| 266 | + * @throws EE_Error |
|
| 267 | + * @throws InvalidArgumentException |
|
| 268 | + * @throws ReflectionException |
|
| 269 | + * @throws InvalidDataTypeException |
|
| 270 | + * @throws InvalidInterfaceException |
|
| 271 | + */ |
|
| 272 | + public function is_default() |
|
| 273 | + { |
|
| 274 | + return $this->get('PRC_is_default'); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * get deleted |
|
| 280 | + * |
|
| 281 | + * @return bool |
|
| 282 | + * @throws EE_Error |
|
| 283 | + * @throws InvalidArgumentException |
|
| 284 | + * @throws ReflectionException |
|
| 285 | + * @throws InvalidDataTypeException |
|
| 286 | + * @throws InvalidInterfaceException |
|
| 287 | + */ |
|
| 288 | + public function deleted() |
|
| 289 | + { |
|
| 290 | + return $this->get('PRC_deleted'); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + |
|
| 294 | + /** |
|
| 295 | + * @return bool |
|
| 296 | + * @throws EE_Error |
|
| 297 | + * @throws InvalidArgumentException |
|
| 298 | + * @throws ReflectionException |
|
| 299 | + * @throws InvalidDataTypeException |
|
| 300 | + * @throws InvalidInterfaceException |
|
| 301 | + */ |
|
| 302 | + public function parent() |
|
| 303 | + { |
|
| 304 | + return $this->get('PRC_parent'); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + // some helper methods for getting info on the price_type for this price |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * return whether the price is a base price or not |
|
| 313 | + * |
|
| 314 | + * @return boolean |
|
| 315 | + * @throws EE_Error |
|
| 316 | + * @throws InvalidArgumentException |
|
| 317 | + * @throws InvalidDataTypeException |
|
| 318 | + * @throws InvalidInterfaceException |
|
| 319 | + * @throws ReflectionException |
|
| 320 | + */ |
|
| 321 | + public function is_base_price() |
|
| 322 | + { |
|
| 323 | + $price_type = $this->type_obj(); |
|
| 324 | + return $price_type->is_base_price(); |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * @return EE_Base_Class|EE_Price_Type |
|
| 330 | + * @throws EE_Error |
|
| 331 | + * @throws InvalidArgumentException |
|
| 332 | + * @throws ReflectionException |
|
| 333 | + * @throws InvalidDataTypeException |
|
| 334 | + * @throws InvalidInterfaceException |
|
| 335 | + */ |
|
| 336 | + public function type_obj() |
|
| 337 | + { |
|
| 338 | + return $this->get_first_related('Price_Type'); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * @return int |
|
| 344 | + * @throws EE_Error |
|
| 345 | + * @throws InvalidArgumentException |
|
| 346 | + * @throws ReflectionException |
|
| 347 | + * @throws InvalidDataTypeException |
|
| 348 | + * @throws InvalidInterfaceException |
|
| 349 | + */ |
|
| 350 | + public function type_order() |
|
| 351 | + { |
|
| 352 | + return $this->get_first_related('Price_Type')->order(); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * Simply indicates whether this price increases or decreases the total |
|
| 358 | + * |
|
| 359 | + * @return boolean true = discount, otherwise adds to the total |
|
| 360 | + * @throws EE_Error |
|
| 361 | + * @throws InvalidArgumentException |
|
| 362 | + * @throws ReflectionException |
|
| 363 | + * @throws InvalidDataTypeException |
|
| 364 | + * @throws InvalidInterfaceException |
|
| 365 | + */ |
|
| 366 | + public function is_discount() |
|
| 367 | + { |
|
| 368 | + $price_type = $this->type_obj(); |
|
| 369 | + return $price_type->is_discount(); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * whether the price is a percentage or not |
|
| 375 | + * |
|
| 376 | + * @return boolean |
|
| 377 | + * @throws EE_Error |
|
| 378 | + * @throws InvalidArgumentException |
|
| 379 | + * @throws InvalidDataTypeException |
|
| 380 | + * @throws InvalidInterfaceException |
|
| 381 | + * @throws ReflectionException |
|
| 382 | + */ |
|
| 383 | + public function is_percent() |
|
| 384 | + { |
|
| 385 | + $price_type = $this->type_obj(); |
|
| 386 | + return $price_type->is_percent(); |
|
| 387 | + } |
|
| 388 | + |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * whether the price is a percentage or not |
|
| 392 | + * |
|
| 393 | + * @return boolean |
|
| 394 | + * @throws EE_Error |
|
| 395 | + * @throws InvalidArgumentException |
|
| 396 | + * @throws ReflectionException |
|
| 397 | + * @throws InvalidDataTypeException |
|
| 398 | + * @throws InvalidInterfaceException |
|
| 399 | + */ |
|
| 400 | + public function is_surcharge() |
|
| 401 | + { |
|
| 402 | + $price_type = $this->type_obj(); |
|
| 403 | + return $price_type->is_surcharge(); |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * whether the price is a percentage or not |
|
| 408 | + * |
|
| 409 | + * @return boolean |
|
| 410 | + * @throws EE_Error |
|
| 411 | + * @throws InvalidArgumentException |
|
| 412 | + * @throws ReflectionException |
|
| 413 | + * @throws InvalidDataTypeException |
|
| 414 | + * @throws InvalidInterfaceException |
|
| 415 | + */ |
|
| 416 | + public function is_tax() |
|
| 417 | + { |
|
| 418 | + $price_type = $this->type_obj(); |
|
| 419 | + return $price_type->is_tax(); |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + |
|
| 423 | + /** |
|
| 424 | + * return pretty price dependant on whether its a dollar or percent. |
|
| 425 | + * |
|
| 426 | + * @return string |
|
| 427 | + * @throws EE_Error |
|
| 428 | + * @throws InvalidArgumentException |
|
| 429 | + * @throws ReflectionException |
|
| 430 | + * @throws InvalidDataTypeException |
|
| 431 | + * @throws InvalidInterfaceException |
|
| 432 | + * @since 4.4.0 |
|
| 433 | + */ |
|
| 434 | + public function pretty_price() |
|
| 435 | + { |
|
| 436 | + return ! $this->is_percent() |
|
| 437 | + ? $this->get_pretty('PRC_amount') |
|
| 438 | + : $this->get('PRC_amount') . '%'; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + /** |
|
| 443 | + * @return mixed |
|
| 444 | + * @throws EE_Error |
|
| 445 | + * @throws InvalidArgumentException |
|
| 446 | + * @throws ReflectionException |
|
| 447 | + * @throws InvalidDataTypeException |
|
| 448 | + * @throws InvalidInterfaceException |
|
| 449 | + */ |
|
| 450 | + public function get_price_without_currency_symbol() |
|
| 451 | + { |
|
| 452 | + return str_replace( |
|
| 453 | + EE_Registry::instance()->CFG->currency->sign, |
|
| 454 | + '', |
|
| 455 | + $this->get_pretty('PRC_amount') |
|
| 456 | + ); |
|
| 457 | + } |
|
| 458 | 458 | } |