Completed
Branch EDTR/master (f9130a)
by
unknown
46:59 queued 38:09
created

EventDatetimesConnection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 109
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
A get_connection_args() 0 32 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
                'eventId'  => [
105
                    'type'        => 'Int',
106
                    'description' => esc_html__('Event ID of the datetime.', 'event_espresso'),
107
                ],
108
                'ticketId' => [
109
                    'type'        => 'Int',
110
                    'description' => esc_html__('Ticket ID of the datetime.', 'event_espresso'),
111
                ],
112
                'upcoming' => [
113
                    'type'        => 'Boolean',
114
                    'description' => esc_html__('Datetimes which are upcoming.', 'event_espresso'),
115
                ],
116
                'active'   => [
117
                    'type'        => 'Boolean',
118
                    'description' => esc_html__('Datetimes which are active.', 'event_espresso'),
119
                ],
120
                'expired'  => [
121
                    'type'        => 'Boolean',
122
                    'description' => esc_html__('Datetimes which are expired.', 'event_espresso'),
123
                ],
124
            ],
125
            $args
126
        );
127
    }
128
}
129