Completed
Branch EDTR/refactor-fast-api-fetch (cef37c)
by
unknown
09:44 queued 46s
created

EventDatetimesConnection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 4
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 4
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *     Event Espresso
4
 *     Manage events, sell tickets, and receive payments from your WordPress website.
5
 *     Copyright (c) 2008-2019 Event Espresso  All Rights Reserved.
6
 *
7
 *     This program is free software: you can redistribute it and/or modify
8
 *     it under the terms of the GNU General Public License as published by
9
 *     the Free Software Foundation, either version 3 of the License, or
10
 *     (at your option) any later version.
11
 *
12
 *     This program is distributed in the hope that it will be useful,
13
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *     GNU General Public License for more details.
16
 *
17
 *     You should have received a copy of the GNU General Public License
18
 *     along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
 */
20
21
namespace EventEspresso\core\domain\services\graphql\connections;
22
23
use EE_Base_Class;
24
use EEM_Datetime;
25
use EventEspresso\core\domain\services\graphql\connection_resolvers\DatetimeConnectionResolver;
26
use EventEspresso\core\services\graphql\ConnectionInterface;
27
use Exception;
28
29
/**
30
 * Class EventDatetimesConnection
31
 * Description
32
 *
33
 * @package EventEspresso\core\domain\services\graphql\connections
34
 * @author  Brent Christensen
35
 * @since   $VID:$
36
 */
37 View Code Duplication
class EventDatetimesConnection implements ConnectionInterface
38
{
39
40
    /**
41
     * @var EEM_Datetime $model
42
     */
43
    protected $model;
44
45
46
    /**
47
     * DatetimeConnection constructor.
48
     *
49
     * @param EEM_Datetime               $model
50
     */
51
    public function __construct(EEM_Datetime $model)
52
    {
53
        $this->model = $model;
54
    }
55
56
57
    /**
58
     * @return array
59
     * @since $VID:$
60
     */
61
    public function config()
62
    {
63
        return [
64
            'fromType'           => 'Event',
65
            'toType'             => 'Datetime',
66
            'fromFieldName'      => 'datetimes',
67
            'connectionTypeName' => 'EventDatetimesConnection',
68
            'resolve'            => [$this, 'resolveConnection'],
69
            'resolveNode'        => [$this, 'resolveNode']
70
        ];
71
    }
72
73
74
    /**
75
     * @param $entity
76
     * @param $args
77
     * @param $context
78
     * @param $info
79
     * @return array
80
     * @throws Exception
81
     * @since $VID:$
82
     */
83
    public function resolveConnection($entity, $args, $context, $info)
84
    {
85
        $resolver = new DatetimeConnectionResolver($entity, $args, $context, $info);
86
        return $resolver->get_connection();
87
    }
88
89
90
    /**
91
     * @param $id
92
     * @param $args
93
     * @param $context
94
     * @param $info
95
     * @return EE_Base_Class
96
     * @since $VID:$
97
     */
98
    public function resolveNode($id, $args, $context, $info)
99
    {
100
        return $this->model->get_one_by_ID($id);
101
    }
102
}
103