1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\graphql\mutators; |
4
|
|
|
|
5
|
|
|
use EE_Ticket; |
6
|
|
|
use EEM_Ticket; |
7
|
|
|
use EventEspresso\core\domain\services\graphql\types\Ticket; |
8
|
|
|
use EventEspresso\core\domain\services\graphql\data\mutations\TicketMutation; |
9
|
|
|
use Exception; |
10
|
|
|
use GraphQL\Type\Definition\ResolveInfo; |
11
|
|
|
use WPGraphQL\AppContext; |
12
|
|
|
|
13
|
|
|
class TicketUpdate extends EntityMutator |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Defines the mutation data modification closure. |
18
|
|
|
* |
19
|
|
|
* @param EEM_Ticket $model |
20
|
|
|
* @param Ticket $type |
21
|
|
|
* @return callable |
22
|
|
|
*/ |
23
|
|
|
public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Updates an entity. |
27
|
|
|
* |
28
|
|
|
* @param array $input The input for the mutation |
29
|
|
|
* @param AppContext $context The AppContext passed down to all resolvers |
30
|
|
|
* @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
31
|
|
|
* @return array |
32
|
|
|
*/ |
33
|
|
|
return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
34
|
|
|
try { |
35
|
|
|
/** @var EE_Ticket $entity */ |
36
|
|
|
$entity = EntityMutator::getEntityFromInputData($model, $input); |
37
|
|
|
|
38
|
|
|
$datetimes = []; |
39
|
|
|
$prices = []; |
40
|
|
|
|
41
|
|
|
$args = TicketMutation::prepareFields($input); |
42
|
|
|
|
43
|
|
|
if (isset($args['datetimes'])) { |
44
|
|
|
$datetimes = $args['datetimes']; |
45
|
|
|
unset($args['datetimes']); |
46
|
|
|
} |
47
|
|
|
if (isset($args['prices'])) { |
48
|
|
|
$prices = $args['prices']; |
49
|
|
|
unset($args['prices']); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$entity->save($args); |
53
|
|
|
|
54
|
|
|
if (! empty($datetimes)) { |
55
|
|
|
TicketMutation::setRelatedDatetimes($entity, $datetimes); |
56
|
|
|
} |
57
|
|
|
if (! empty($prices)) { |
58
|
|
|
TicketMutation::setRelatedPrices($entity, $prices); |
59
|
|
|
} |
60
|
|
|
} catch (Exception $exception) { |
61
|
|
|
EntityMutator::handleExceptions( |
62
|
|
|
$exception, |
63
|
|
|
esc_html__( |
64
|
|
|
'The ticket could not be deleted because of the following error(s)', |
65
|
|
|
'event_espresso' |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return [ |
71
|
|
|
'id' => $entity->ID(), |
72
|
|
|
]; |
73
|
|
|
}; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|