Completed
Branch EDTR/master (bb716e)
by
unknown
57:55 queued 49:04
created

EventDatetimesConnection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 133
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A config() 0 12 1
A resolveConnection() 0 5 1
A resolveNode() 0 4 1
B get_connection_args() 0 56 1
1
<?php
2
3
namespace EventEspresso\core\domain\services\graphql\connections;
4
5
use EE_Base_Class;
6
use EEM_Datetime;
7
use EventEspresso\core\domain\services\graphql\connection_resolvers\DatetimeConnectionResolver;
8
use EventEspresso\core\services\graphql\connections\ConnectionInterface;
9
use Exception;
10
use WPGraphQL\Type\WPObjectType;
11
12
/**
13
 * Class EventDatetimesConnection
14
 * Description
15
 *
16
 * @package EventEspresso\core\domain\services\graphql\connections
17
 * @author  Brent Christensen
18
 * @since   $VID:$
19
 */
20
class EventDatetimesConnection implements ConnectionInterface
21
{
22
23
    /**
24
     * @var EEM_Datetime $model
25
     */
26
    protected $model;
27
28
29
    /**
30
     * DatetimeConnection constructor.
31
     *
32
     * @param EEM_Datetime               $model
33
     */
34
    public function __construct(EEM_Datetime $model)
35
    {
36
        $this->model = $model;
37
    }
38
39
40
    /**
41
     * @return array
42
     * @since $VID:$
43
     */
44
    public function config()
45
    {
46
        return [
47
            'fromType'           => 'Event',
48
            'toType'             => 'Datetime',
49
            'fromFieldName'      => 'datetimes',
50
            'connectionTypeName' => 'EventDatetimesConnection',
51
            'connectionArgs'     => self::get_connection_args(),
52
            'resolve'            => [$this, 'resolveConnection'],
53
            'resolveNode'        => [$this, 'resolveNode']
54
        ];
55
    }
56
57
58
    /**
59
     * @param $entity
60
     * @param $args
61
     * @param $context
62
     * @param $info
63
     * @return array
64
     * @throws Exception
65
     * @since $VID:$
66
     */
67
    public function resolveConnection($entity, $args, $context, $info)
68
    {
69
        $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info);
70
        return $resolver->get_connection();
71
    }
72
73
74
    /**
75
     * @param $id
76
     * @param $args
77
     * @param $context
78
     * @param $info
79
     * @return EE_Base_Class
80
     * @since $VID:$
81
     */
82
    public function resolveNode($id, $args, $context, $info)
83
    {
84
        return $this->model->get_one_by_ID($id);
85
    }
86
87
    /**
88
     * Given an optional array of args, this returns the args to be used in the connection
89
     *
90
     * @access public
91
     * @param array $args The args to modify the defaults
92
     *
93
     * @return array
94
     */
95
    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
96
    public static function get_connection_args($args = [])
97
    {
98
        return array_merge(
99
            [
100
                'orderby'      => [
101
                    'type'        => ['list_of' => 'DatetimesConnectionOrderbyInput'],
102
                    'description' => esc_html__('What paramater to use to order the objects by.', 'event_espresso'),
103
                ],
104
                'event'  => [
105
                    'type'        => 'ID',
106
                    'description' => esc_html__('Globally unique event ID to get the datetimes for.', 'event_espresso'),
107
                ],
108
                'eventIn'  => [
109
                    'type'        => ['list_of' => 'ID'],
110
                    'description' => esc_html__('Globally unique event IDs to get the datetimes for.', 'event_espresso'),
111
                ],
112
                'eventId'  => [
113
                    'type'        => 'Int',
114
                    'description' => esc_html__('Event ID to get the datetimes for.', 'event_espresso'),
115
                ],
116
                'eventIdIn'  => [
117
                    'type'        => ['list_of' => 'Int'],
118
                    'description' => esc_html__('Event IDs to get the datetimes for.', 'event_espresso'),
119
                ],
120
                'ticket' => [
121
                    'type'        => 'ID',
122
                    'description' => esc_html__('Globally unique ticket ID to get the datetimes for.', 'event_espresso'),
123
                ],
124
                'ticketIn' => [
125
                    'type'        => ['list_of' => 'ID'],
126
                    'description' => esc_html__('Globally unique ticket IDs to get the datetimes for.', 'event_espresso'),
127
                ],
128
                'ticketId' => [
129
                    'type'        => 'Int',
130
                    'description' => esc_html__('Ticket ID to get the datetimes for.', 'event_espresso'),
131
                ],
132
                'ticketIdIn' => [
133
                    'type'        => ['list_of' => 'Int'],
134
                    'description' => esc_html__('Ticket IDs to get the datetimes for.', 'event_espresso'),
135
                ],
136
                'upcoming' => [
137
                    'type'        => 'Boolean',
138
                    'description' => esc_html__('Datetimes which are upcoming.', 'event_espresso'),
139
                ],
140
                'active'   => [
141
                    'type'        => 'Boolean',
142
                    'description' => esc_html__('Datetimes which are active.', 'event_espresso'),
143
                ],
144
                'expired'  => [
145
                    'type'        => 'Boolean',
146
                    'description' => esc_html__('Datetimes which are expired.', 'event_espresso'),
147
                ],
148
            ],
149
            $args
150
        );
151
    }
152
}
153