1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\graphql\connections; |
4
|
|
|
|
5
|
|
|
use EE_Base_Class; |
6
|
|
|
use EEM_Ticket; |
7
|
|
|
use EventEspresso\core\domain\services\graphql\connection_resolvers\TicketConnectionResolver; |
8
|
|
|
use EventEspresso\core\services\graphql\connections\ConnectionInterface; |
9
|
|
|
use Exception; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DatetimeTicketsConnection |
13
|
|
|
* Description |
14
|
|
|
* |
15
|
|
|
* @package EventEspresso\core\domain\services\graphql\connections |
16
|
|
|
* @author Brent Christensen |
17
|
|
|
* @since $VID:$ |
18
|
|
|
*/ |
19
|
|
|
class DatetimeTicketsConnection implements ConnectionInterface |
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var EEM_Ticket $model |
24
|
|
|
*/ |
25
|
|
|
protected $model; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* DatetimeConnection constructor. |
30
|
|
|
* |
31
|
|
|
* @param EEM_Ticket $model |
32
|
|
|
*/ |
33
|
|
|
public function __construct(EEM_Ticket $model) |
34
|
|
|
{ |
35
|
|
|
$this->model = $model; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return array |
41
|
|
|
* @since $VID:$ |
42
|
|
|
*/ |
43
|
|
|
public function config() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
'fromType' => 'Datetime', |
47
|
|
|
'toType' => 'Ticket', |
48
|
|
|
'fromFieldName' => 'tickets', |
49
|
|
|
'connectionTypeName' => 'DatetimeTicketsConnection', |
50
|
|
|
'connectionArgs' => self::get_connection_args(), |
51
|
|
|
'resolve' => [$this, 'resolveConnection'], |
52
|
|
|
'resolveNode' => [$this, 'resolveNode'] |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param $entity |
59
|
|
|
* @param $args |
60
|
|
|
* @param $context |
61
|
|
|
* @param $info |
62
|
|
|
* @return array |
63
|
|
|
* @throws Exception |
64
|
|
|
* @since $VID:$ |
65
|
|
|
*/ |
66
|
|
|
public function resolveConnection($entity, $args, $context, $info) |
67
|
|
|
{ |
68
|
|
|
$resolver = new TicketConnectionResolver($entity, $args, $context, $info); |
69
|
|
|
return $resolver->get_connection(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param $id |
75
|
|
|
* @param $args |
76
|
|
|
* @param $context |
77
|
|
|
* @param $info |
78
|
|
|
* @return EE_Base_Class |
79
|
|
|
* @since $VID:$ |
80
|
|
|
*/ |
81
|
|
|
public function resolveNode($id, $args, $context, $info) |
82
|
|
|
{ |
83
|
|
|
return $this->model->get_one_by_ID($id); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Given an optional array of args, this returns the args to be used in the connection |
88
|
|
|
* |
89
|
|
|
* @access public |
90
|
|
|
* @param array $args The args to modify the defaults |
91
|
|
|
* |
92
|
|
|
* @return array |
93
|
|
|
*/ |
94
|
|
|
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
95
|
|
|
public static function get_connection_args($args = []) |
96
|
|
|
{ |
97
|
|
|
return array_merge( |
98
|
|
|
[ |
99
|
|
|
'orderby' => [ |
100
|
|
|
'type' => ['list_of' => 'TicketsConnectionOrderbyInput'], |
101
|
|
|
'description' => esc_html__('What paramater to use to order the objects by.', 'event_espresso'), |
102
|
|
|
], |
103
|
|
|
'datetimeId' => [ |
104
|
|
|
'type' => 'Int', |
105
|
|
|
'description' => esc_html__('Datetime ID to get the tickets for.', 'event_espresso'), |
106
|
|
|
], |
107
|
|
|
'datetimeIn' => [ |
108
|
|
|
'type' => ['list_of' => 'Int'], |
109
|
|
|
'description' => esc_html__('Datetime IDs to get the tickets for.', 'event_espresso'), |
110
|
|
|
], |
111
|
|
|
], |
112
|
|
|
$args |
113
|
|
|
); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|