Completed
Branch EDTR/master (0d7008)
by
unknown
34:37 queued 26:06
created
domain/services/graphql/connection_resolvers/DatetimeConnectionResolver.php 1 patch
Indentation   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -18,186 +18,186 @@
 block discarded – undo
18 18
  */
19 19
 class DatetimeConnectionResolver extends AbstractConnectionResolver
20 20
 {
21
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
22
-    public function get_loader_name()
23
-    {
24
-        return 'espresso_datetime';
25
-    }
26
-
27
-    /**
28
-     * @return EEM_Datetime
29
-     * @throws EE_Error
30
-     * @throws InvalidArgumentException
31
-     * @throws InvalidDataTypeException
32
-     * @throws InvalidInterfaceException
33
-     */
34
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
-    public function get_query()
36
-    {
37
-        return EEM_Datetime::instance();
38
-    }
39
-
40
-    /**
41
-     * Return an array of item IDs from the query
42
-     *
43
-     * @return array
44
-     */
45
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
-    public function get_ids()
47
-    {
48
-        $results = $this->query->get_col($this->query_args);
49
-
50
-        return ! empty($results) ? $results : [];
51
-    }
52
-
53
-    /**
54
-     * Determine whether the Query should execute. If it's determined that the query should
55
-     * not be run based on context such as, but not limited to, who the user is, where in the
56
-     * ResolveTree the Query is, the relation to the node the Query is connected to, etc
57
-     *
58
-     * Return false to prevent the query from executing.
59
-     *
60
-     * @return bool
61
-     */
62
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
63
-    public function should_execute()
64
-    {
65
-        if (false === $this->should_execute) {
66
-            return false;
67
-        }
68
-
69
-        return $this->should_execute;
70
-    }
71
-
72
-    /**
73
-     * Here, we map the args from the input, then we make sure that we're only querying
74
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
75
-     * handle batch resolution of the posts.
76
-     *
77
-     * @return array
78
-     * @throws EE_Error
79
-     * @throws InvalidArgumentException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
84
-    public function get_query_args()
85
-    {
86
-        $where_params = ['DTT_deleted' => ['IN', [true, false]]];
87
-        $query_args   = [];
88
-
89
-        $query_args['limit'] = $this->getLimit();
90
-
91
-        // Avoid multiple entries by join.
92
-        $query_args['group_by'] = 'DTT_ID';
93
-
94
-        /**
95
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
96
-         */
97
-        $input_fields = [];
98
-        if (! empty($this->args['where'])) {
99
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
100
-
101
-            // Use the proper operator.
102
-            if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) {
103
-                $input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']];
104
-            }
105
-            if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
106
-                $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
107
-            }
108
-        }
109
-
110
-        /**
111
-         * Determine where we're at in the Graph and adjust the query context appropriately.
112
-         *
113
-         * For example, if we're querying for datetime as a field of event query, this will automatically
114
-         * set the query to pull datetimes that belong to that event.
115
-         * We can set more cases for other source types.
116
-         */
117
-        if (is_object($this->source)) {
118
-            switch (true) {
119
-                // It's surely an event
120
-                case $this->source instanceof Post:
121
-                    $where_params['EVT_ID'] = $this->source->ID;
122
-                    break;
123
-                case $this->source instanceof EE_Event:
124
-                    $where_params['EVT_ID'] = $this->source->ID();
125
-                    break;
126
-                case $this->source instanceof EE_Ticket:
127
-                    $where_params['Ticket.TKT_ID'] = $this->source->ID();
128
-                    break;
129
-                case $this->source instanceof EE_Checkin:
130
-                    $where_params['Checkin.CHK_ID'] = $this->source->ID();
131
-                    break;
132
-            }
133
-        }
134
-
135
-        /**
136
-         * Merge the input_fields with the default query_args
137
-         */
138
-        if (! empty($input_fields)) {
139
-            $where_params = array_merge($where_params, $input_fields);
140
-        }
141
-
142
-        list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID');
143
-
144
-        if (! empty($this->args['where']['upcoming'])) {
145
-            $where_params['DTT_EVT_start'] = array(
146
-                '>',
147
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
148
-            );
149
-        }
150
-
151
-        if (! empty($this->args['where']['active'])) {
152
-            $where_params['DTT_EVT_start'] = array(
153
-                '<',
154
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
155
-            );
156
-            $where_params['DTT_EVT_end'] = array(
157
-                '>',
158
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
159
-            );
160
-        }
161
-
162
-        if (! empty($this->args['where']['expired'])) {
163
-            $where_params['DTT_EVT_end'] = array(
164
-                '<',
165
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
166
-            );
167
-        }
168
-
169
-        $query_args[] = $where_params;
170
-
171
-        /**
172
-         * Return the $query_args
173
-         */
174
-        return $query_args;
175
-    }
176
-
177
-
178
-    /**
179
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
180
-     * friendly keys.
181
-     *
182
-     * @param array $where_args
183
-     * @return array
184
-     */
185
-    public function sanitizeInputFields(array $where_args)
186
-    {
187
-        $arg_mapping = [
188
-            'event'      => 'EVT_ID',
189
-            'eventIn'    => 'EVT_ID',
190
-            'eventId'    => 'EVT_ID',
191
-            'eventIdIn'  => 'EVT_ID',
192
-            'ticket'     => 'Ticket.TKT_ID',
193
-            'ticketIn'   => 'Ticket.TKT_ID',
194
-            'ticketId'   => 'Ticket.TKT_ID',
195
-            'ticketIdIn' => 'Ticket.TKT_ID',
196
-        ];
197
-        return $this->sanitizeWhereArgsForInputFields(
198
-            $where_args,
199
-            $arg_mapping,
200
-            ['event', 'eventIn', 'ticket', 'ticketIn']
201
-        );
202
-    }
21
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
22
+	public function get_loader_name()
23
+	{
24
+		return 'espresso_datetime';
25
+	}
26
+
27
+	/**
28
+	 * @return EEM_Datetime
29
+	 * @throws EE_Error
30
+	 * @throws InvalidArgumentException
31
+	 * @throws InvalidDataTypeException
32
+	 * @throws InvalidInterfaceException
33
+	 */
34
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
35
+	public function get_query()
36
+	{
37
+		return EEM_Datetime::instance();
38
+	}
39
+
40
+	/**
41
+	 * Return an array of item IDs from the query
42
+	 *
43
+	 * @return array
44
+	 */
45
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
46
+	public function get_ids()
47
+	{
48
+		$results = $this->query->get_col($this->query_args);
49
+
50
+		return ! empty($results) ? $results : [];
51
+	}
52
+
53
+	/**
54
+	 * Determine whether the Query should execute. If it's determined that the query should
55
+	 * not be run based on context such as, but not limited to, who the user is, where in the
56
+	 * ResolveTree the Query is, the relation to the node the Query is connected to, etc
57
+	 *
58
+	 * Return false to prevent the query from executing.
59
+	 *
60
+	 * @return bool
61
+	 */
62
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
63
+	public function should_execute()
64
+	{
65
+		if (false === $this->should_execute) {
66
+			return false;
67
+		}
68
+
69
+		return $this->should_execute;
70
+	}
71
+
72
+	/**
73
+	 * Here, we map the args from the input, then we make sure that we're only querying
74
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
75
+	 * handle batch resolution of the posts.
76
+	 *
77
+	 * @return array
78
+	 * @throws EE_Error
79
+	 * @throws InvalidArgumentException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
84
+	public function get_query_args()
85
+	{
86
+		$where_params = ['DTT_deleted' => ['IN', [true, false]]];
87
+		$query_args   = [];
88
+
89
+		$query_args['limit'] = $this->getLimit();
90
+
91
+		// Avoid multiple entries by join.
92
+		$query_args['group_by'] = 'DTT_ID';
93
+
94
+		/**
95
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
96
+		 */
97
+		$input_fields = [];
98
+		if (! empty($this->args['where'])) {
99
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
100
+
101
+			// Use the proper operator.
102
+			if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) {
103
+				$input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']];
104
+			}
105
+			if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
106
+				$input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
107
+			}
108
+		}
109
+
110
+		/**
111
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
112
+		 *
113
+		 * For example, if we're querying for datetime as a field of event query, this will automatically
114
+		 * set the query to pull datetimes that belong to that event.
115
+		 * We can set more cases for other source types.
116
+		 */
117
+		if (is_object($this->source)) {
118
+			switch (true) {
119
+				// It's surely an event
120
+				case $this->source instanceof Post:
121
+					$where_params['EVT_ID'] = $this->source->ID;
122
+					break;
123
+				case $this->source instanceof EE_Event:
124
+					$where_params['EVT_ID'] = $this->source->ID();
125
+					break;
126
+				case $this->source instanceof EE_Ticket:
127
+					$where_params['Ticket.TKT_ID'] = $this->source->ID();
128
+					break;
129
+				case $this->source instanceof EE_Checkin:
130
+					$where_params['Checkin.CHK_ID'] = $this->source->ID();
131
+					break;
132
+			}
133
+		}
134
+
135
+		/**
136
+		 * Merge the input_fields with the default query_args
137
+		 */
138
+		if (! empty($input_fields)) {
139
+			$where_params = array_merge($where_params, $input_fields);
140
+		}
141
+
142
+		list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID');
143
+
144
+		if (! empty($this->args['where']['upcoming'])) {
145
+			$where_params['DTT_EVT_start'] = array(
146
+				'>',
147
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
148
+			);
149
+		}
150
+
151
+		if (! empty($this->args['where']['active'])) {
152
+			$where_params['DTT_EVT_start'] = array(
153
+				'<',
154
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
155
+			);
156
+			$where_params['DTT_EVT_end'] = array(
157
+				'>',
158
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
159
+			);
160
+		}
161
+
162
+		if (! empty($this->args['where']['expired'])) {
163
+			$where_params['DTT_EVT_end'] = array(
164
+				'<',
165
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
166
+			);
167
+		}
168
+
169
+		$query_args[] = $where_params;
170
+
171
+		/**
172
+		 * Return the $query_args
173
+		 */
174
+		return $query_args;
175
+	}
176
+
177
+
178
+	/**
179
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
180
+	 * friendly keys.
181
+	 *
182
+	 * @param array $where_args
183
+	 * @return array
184
+	 */
185
+	public function sanitizeInputFields(array $where_args)
186
+	{
187
+		$arg_mapping = [
188
+			'event'      => 'EVT_ID',
189
+			'eventIn'    => 'EVT_ID',
190
+			'eventId'    => 'EVT_ID',
191
+			'eventIdIn'  => 'EVT_ID',
192
+			'ticket'     => 'Ticket.TKT_ID',
193
+			'ticketIn'   => 'Ticket.TKT_ID',
194
+			'ticketId'   => 'Ticket.TKT_ID',
195
+			'ticketIdIn' => 'Ticket.TKT_ID',
196
+		];
197
+		return $this->sanitizeWhereArgsForInputFields(
198
+			$where_args,
199
+			$arg_mapping,
200
+			['event', 'eventIn', 'ticket', 'ticketIn']
201
+		);
202
+	}
203 203
 }
Please login to merge, or discard this patch.
services/graphql/connection_resolvers/PriceTypeConnectionResolver.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -14,85 +14,85 @@
 block discarded – undo
14 14
  */
15 15
 class PriceTypeConnectionResolver extends AbstractConnectionResolver
16 16
 {
17
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
18
-    public function get_loader_name()
19
-    {
20
-        return 'espresso_priceType';
21
-    }
17
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
18
+	public function get_loader_name()
19
+	{
20
+		return 'espresso_priceType';
21
+	}
22 22
 
23
-    /**
24
-     * @return EEM_Price_Type
25
-     * @throws EE_Error
26
-     * @throws InvalidArgumentException
27
-     * @throws InvalidDataTypeException
28
-     * @throws InvalidInterfaceException
29
-     */
30
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
31
-    public function get_query()
32
-    {
33
-        return EEM_Price_Type::instance();
34
-    }
23
+	/**
24
+	 * @return EEM_Price_Type
25
+	 * @throws EE_Error
26
+	 * @throws InvalidArgumentException
27
+	 * @throws InvalidDataTypeException
28
+	 * @throws InvalidInterfaceException
29
+	 */
30
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
31
+	public function get_query()
32
+	{
33
+		return EEM_Price_Type::instance();
34
+	}
35 35
 
36 36
 
37
-    /**
38
-     * Return an array of item IDs from the query
39
-     *
40
-     * @return array
41
-     */
42
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
43
-    public function get_ids()
44
-    {
45
-        $results = $this->query->get_col($this->query_args);
37
+	/**
38
+	 * Return an array of item IDs from the query
39
+	 *
40
+	 * @return array
41
+	 */
42
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
43
+	public function get_ids()
44
+	{
45
+		$results = $this->query->get_col($this->query_args);
46 46
 
47
-        return ! empty($results) ? $results : [];
48
-    }
47
+		return ! empty($results) ? $results : [];
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * Determine whether the Query should execute. If it's determined that the query should
53
-     * not be run based on context such as, but not limited to, who the user is, where in the
54
-     * ResolveTree the Query is, the relation to the node the Query is connected to, etc
55
-     * Return false to prevent the query from executing.
56
-     *
57
-     * @return bool
58
-     */
59
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
60
-    public function should_execute()
61
-    {
62
-        if ($this->should_execute === false) {
63
-            return false;
64
-        }
51
+	/**
52
+	 * Determine whether the Query should execute. If it's determined that the query should
53
+	 * not be run based on context such as, but not limited to, who the user is, where in the
54
+	 * ResolveTree the Query is, the relation to the node the Query is connected to, etc
55
+	 * Return false to prevent the query from executing.
56
+	 *
57
+	 * @return bool
58
+	 */
59
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
60
+	public function should_execute()
61
+	{
62
+		if ($this->should_execute === false) {
63
+			return false;
64
+		}
65 65
 
66
-        return $this->should_execute;
67
-    }
66
+		return $this->should_execute;
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * Here, we map the args from the input, then we make sure that we're only querying
72
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
73
-     * handle batch resolution of the posts.
74
-     *
75
-     * @return array
76
-     * @throws EE_Error
77
-     * @throws InvalidArgumentException
78
-     * @throws ReflectionException
79
-     * @throws InvalidDataTypeException
80
-     * @throws InvalidInterfaceException
81
-     */
82
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
83
-    public function get_query_args()
84
-    {
85
-        $where_params = [];
86
-        $query_args   = [];
70
+	/**
71
+	 * Here, we map the args from the input, then we make sure that we're only querying
72
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
73
+	 * handle batch resolution of the posts.
74
+	 *
75
+	 * @return array
76
+	 * @throws EE_Error
77
+	 * @throws InvalidArgumentException
78
+	 * @throws ReflectionException
79
+	 * @throws InvalidDataTypeException
80
+	 * @throws InvalidInterfaceException
81
+	 */
82
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
83
+	public function get_query_args()
84
+	{
85
+		$where_params = [];
86
+		$query_args   = [];
87 87
 
88
-        $query_args['limit'] = $this->getLimit();
88
+		$query_args['limit'] = $this->getLimit();
89 89
 
90
-        // Avoid multiple entries by join.
91
-        $query_args['group_by'] = 'PRT_ID';
90
+		// Avoid multiple entries by join.
91
+		$query_args['group_by'] = 'PRT_ID';
92 92
 
93
-        /**
94
-         * Return the $query_args
95
-         */
96
-        return $query_args;
97
-    }
93
+		/**
94
+		 * Return the $query_args
95
+		 */
96
+		return $query_args;
97
+	}
98 98
 }
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/VenueConnectionResolver.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -16,145 +16,145 @@
 block discarded – undo
16 16
  */
17 17
 class VenueConnectionResolver extends AbstractConnectionResolver
18 18
 {
19
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
20
-    public function get_loader_name()
21
-    {
22
-        return 'espresso_venue';
23
-    }
24
-
25
-    /**
26
-     * @return EEM_Venue
27
-     * @throws EE_Error
28
-     * @throws InvalidArgumentException
29
-     * @throws InvalidDataTypeException
30
-     * @throws InvalidInterfaceException
31
-     */
32
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
33
-    public function get_query()
34
-    {
35
-        return EEM_Venue::instance();
36
-    }
37
-
38
-
39
-    /**
40
-     * Return an array of item IDs from the query
41
-     *
42
-     * @return array
43
-     */
44
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
45
-    public function get_ids()
46
-    {
47
-        $results = $this->query->get_col($this->query_args);
48
-
49
-        return ! empty($results) ? $results : [];
50
-    }
51
-
52
-
53
-    /**
54
-     * Determine whether the Query should execute. If it's determined that the query should
55
-     * not be run based on context such as, but not limited to, who the user is, where in the
56
-     * ResolveTree the Query is, the relation to the node the Query is connected to, etc
57
-     * Return false to prevent the query from executing.
58
-     *
59
-     * @return bool
60
-     */
61
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
62
-    public function should_execute()
63
-    {
64
-        if (false === $this->should_execute) {
65
-            return false;
66
-        }
67
-
68
-        return $this->should_execute;
69
-    }
70
-
71
-
72
-    /**
73
-     * Here, we map the args from the input, then we make sure that we're only querying
74
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
75
-     * handle batch resolution of the posts.
76
-     *
77
-     * @return array
78
-     */
79
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
80
-    public function get_query_args()
81
-    {
82
-        $query_args = [];
83
-
84
-        /**
85
-         * Prepare for later use
86
-         */
87
-        $last = ! empty($this->args['last']) ? $this->args['last'] : null;
88
-        $first = ! empty($this->args['first']) ? $this->args['first'] : null;
89
-
90
-        /**
91
-         * Set limit the highest value of $first and $last, with a (filterable) max of 100
92
-         */
93
-        $query_args['limit'] = min(
94
-            max(absint($first), absint($last), 10),
95
-            $this->query_amount
96
-        ) + 1;
97
-
98
-        /**
99
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
100
-         */
101
-        $input_fields = [];
102
-        if (! empty($this->args['where'])) {
103
-            $input_fields = $this->sanitize_input_fields($this->args['where']);
104
-        }
105
-
106
-        /**
107
-         * Determine where we're at in the Graph and adjust the query context appropriately.
108
-         * For example, if we're querying for datetime as a field of event query, this will automatically
109
-         * set the query to pull datetimes that belong to that event.
110
-         * We can set more cases for other source types.
111
-         */
112
-        if (is_object($this->source)) {
113
-            switch (true) {
114
-                // Assumed to be an event
115
-                case $this->source instanceof Post:
116
-                    $query_args[] = ['Event.EVT_ID' => $this->source->ID];
117
-                    break;
118
-                case $this->source instanceof EE_Event:
119
-                    $query_args[] = ['Event.EVT_ID' => $this->source->ID()];
120
-                    break;
121
-            }
122
-        }
123
-
124
-        /**
125
-         * Merge the input_fields with the default query_args
126
-         */
127
-        if (! empty($input_fields)) {
128
-            $query_args = array_merge($query_args, $input_fields);
129
-        }
130
-
131
-        /**
132
-         * Return the $query_args
133
-         */
134
-        return $query_args;
135
-    }
136
-
137
-
138
-    /**
139
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query
140
-     * friendly keys. There's probably a cleaner/more dynamic way to approach this, but
141
-     * this was quick. I'd be down to explore more dynamic ways to map this, but for
142
-     * now this gets the job done.
143
-     *
144
-     * @param array $query_args
145
-     * @return array
146
-     */
147
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
148
-    public function sanitize_input_fields(array $query_args)
149
-    {
150
-        $arg_mapping = [
151
-            'orderBy' => 'order_by',
152
-            'order'   => 'order',
153
-        ];
154
-
155
-        /**
156
-         * Return the Query Args
157
-         */
158
-        return ! empty($query_args) && is_array($query_args) ? $query_args : [];
159
-    }
19
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
20
+	public function get_loader_name()
21
+	{
22
+		return 'espresso_venue';
23
+	}
24
+
25
+	/**
26
+	 * @return EEM_Venue
27
+	 * @throws EE_Error
28
+	 * @throws InvalidArgumentException
29
+	 * @throws InvalidDataTypeException
30
+	 * @throws InvalidInterfaceException
31
+	 */
32
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
33
+	public function get_query()
34
+	{
35
+		return EEM_Venue::instance();
36
+	}
37
+
38
+
39
+	/**
40
+	 * Return an array of item IDs from the query
41
+	 *
42
+	 * @return array
43
+	 */
44
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
45
+	public function get_ids()
46
+	{
47
+		$results = $this->query->get_col($this->query_args);
48
+
49
+		return ! empty($results) ? $results : [];
50
+	}
51
+
52
+
53
+	/**
54
+	 * Determine whether the Query should execute. If it's determined that the query should
55
+	 * not be run based on context such as, but not limited to, who the user is, where in the
56
+	 * ResolveTree the Query is, the relation to the node the Query is connected to, etc
57
+	 * Return false to prevent the query from executing.
58
+	 *
59
+	 * @return bool
60
+	 */
61
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
62
+	public function should_execute()
63
+	{
64
+		if (false === $this->should_execute) {
65
+			return false;
66
+		}
67
+
68
+		return $this->should_execute;
69
+	}
70
+
71
+
72
+	/**
73
+	 * Here, we map the args from the input, then we make sure that we're only querying
74
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
75
+	 * handle batch resolution of the posts.
76
+	 *
77
+	 * @return array
78
+	 */
79
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
80
+	public function get_query_args()
81
+	{
82
+		$query_args = [];
83
+
84
+		/**
85
+		 * Prepare for later use
86
+		 */
87
+		$last = ! empty($this->args['last']) ? $this->args['last'] : null;
88
+		$first = ! empty($this->args['first']) ? $this->args['first'] : null;
89
+
90
+		/**
91
+		 * Set limit the highest value of $first and $last, with a (filterable) max of 100
92
+		 */
93
+		$query_args['limit'] = min(
94
+			max(absint($first), absint($last), 10),
95
+			$this->query_amount
96
+		) + 1;
97
+
98
+		/**
99
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
100
+		 */
101
+		$input_fields = [];
102
+		if (! empty($this->args['where'])) {
103
+			$input_fields = $this->sanitize_input_fields($this->args['where']);
104
+		}
105
+
106
+		/**
107
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
108
+		 * For example, if we're querying for datetime as a field of event query, this will automatically
109
+		 * set the query to pull datetimes that belong to that event.
110
+		 * We can set more cases for other source types.
111
+		 */
112
+		if (is_object($this->source)) {
113
+			switch (true) {
114
+				// Assumed to be an event
115
+				case $this->source instanceof Post:
116
+					$query_args[] = ['Event.EVT_ID' => $this->source->ID];
117
+					break;
118
+				case $this->source instanceof EE_Event:
119
+					$query_args[] = ['Event.EVT_ID' => $this->source->ID()];
120
+					break;
121
+			}
122
+		}
123
+
124
+		/**
125
+		 * Merge the input_fields with the default query_args
126
+		 */
127
+		if (! empty($input_fields)) {
128
+			$query_args = array_merge($query_args, $input_fields);
129
+		}
130
+
131
+		/**
132
+		 * Return the $query_args
133
+		 */
134
+		return $query_args;
135
+	}
136
+
137
+
138
+	/**
139
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query
140
+	 * friendly keys. There's probably a cleaner/more dynamic way to approach this, but
141
+	 * this was quick. I'd be down to explore more dynamic ways to map this, but for
142
+	 * now this gets the job done.
143
+	 *
144
+	 * @param array $query_args
145
+	 * @return array
146
+	 */
147
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
148
+	public function sanitize_input_fields(array $query_args)
149
+	{
150
+		$arg_mapping = [
151
+			'orderBy' => 'order_by',
152
+			'order'   => 'order',
153
+		];
154
+
155
+		/**
156
+		 * Return the Query Args
157
+		 */
158
+		return ! empty($query_args) && is_array($query_args) ? $query_args : [];
159
+	}
160 160
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/data/loaders/AbstractLoader.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -9,70 +9,70 @@
 block discarded – undo
9 9
  */
10 10
 abstract class AbstractLoader extends AbstractDataLoader
11 11
 {
12
-    protected $primaryKey;
12
+	protected $primaryKey;
13 13
 
14
-    /**
15
-     * @return EE_Base_Class
16
-     * @throws EE_Error
17
-     * @throws InvalidArgumentException
18
-     * @throws InvalidDataTypeException
19
-     * @throws InvalidInterfaceException
20
-     */
21
-    abstract protected function getQuery();
14
+	/**
15
+	 * @return EE_Base_Class
16
+	 * @throws EE_Error
17
+	 * @throws InvalidArgumentException
18
+	 * @throws InvalidDataTypeException
19
+	 * @throws InvalidInterfaceException
20
+	 */
21
+	abstract protected function getQuery();
22 22
 
23
-    /**
24
-     * @param array $keys
25
-     *
26
-     * @return array
27
-     * @throws EE_Error
28
-     * @throws InvalidArgumentException
29
-     * @throws InvalidDataTypeException
30
-     * @throws InvalidInterfaceException
31
-     */
32
-    abstract protected function getWhereParams(array $keys);
23
+	/**
24
+	 * @param array $keys
25
+	 *
26
+	 * @return array
27
+	 * @throws EE_Error
28
+	 * @throws InvalidArgumentException
29
+	 * @throws InvalidDataTypeException
30
+	 * @throws InvalidInterfaceException
31
+	 */
32
+	abstract protected function getWhereParams(array $keys);
33 33
 
34
-    /**
35
-     * Given array of keys, loads and returns a map consisting of keys from `keys` array and loaded
36
-     * values
37
-     *
38
-     * Note that order of returned values must match exactly the order of keys.
39
-     * If some entry is not available for given key - it must include null for the missing key.
40
-     *
41
-     * For example:
42
-     * loadKeys(['a', 'b', 'c']) -> ['a' => 'value1, 'b' => null, 'c' => 'value3']
43
-     *
44
-     * @param array $keys
45
-     *
46
-     * @return array
47
-     * @throws \Exception
48
-     */
49
-    public function loadKeys(array $keys)
50
-    {
51
-        if (empty($keys)) {
52
-            return $keys;
53
-        }
34
+	/**
35
+	 * Given array of keys, loads and returns a map consisting of keys from `keys` array and loaded
36
+	 * values
37
+	 *
38
+	 * Note that order of returned values must match exactly the order of keys.
39
+	 * If some entry is not available for given key - it must include null for the missing key.
40
+	 *
41
+	 * For example:
42
+	 * loadKeys(['a', 'b', 'c']) -> ['a' => 'value1, 'b' => null, 'c' => 'value3']
43
+	 *
44
+	 * @param array $keys
45
+	 *
46
+	 * @return array
47
+	 * @throws \Exception
48
+	 */
49
+	public function loadKeys(array $keys)
50
+	{
51
+		if (empty($keys)) {
52
+			return $keys;
53
+		}
54 54
 
55
-        $args = [
56
-            $this->getWhereParams($keys),
57
-        ];
55
+		$args = [
56
+			$this->getWhereParams($keys),
57
+		];
58 58
 
59
-        $query = $this->getQuery();
60
-        $result = $query->get_all($args);
59
+		$query = $this->getQuery();
60
+		$result = $query->get_all($args);
61 61
         
62
-        $loadedItems = [];
62
+		$loadedItems = [];
63 63
 
64
-        /**
65
-         * Loop over the items and return an array of loaded items,
66
-         * where the key is the ID and the value is the Object passed through
67
-         * the model layer.
68
-         */
69
-        foreach ($keys as $key) {
70
-            if (isset($result[ $key ])) {
71
-                $loadedItems[ $key ] = $result[ $key ];
72
-            } else {
73
-                $loadedItems[ $key ] = null;
74
-            }
75
-        }
76
-        return $loadedItems;
77
-    }
64
+		/**
65
+		 * Loop over the items and return an array of loaded items,
66
+		 * where the key is the ID and the value is the Object passed through
67
+		 * the model layer.
68
+		 */
69
+		foreach ($keys as $key) {
70
+			if (isset($result[ $key ])) {
71
+				$loadedItems[ $key ] = $result[ $key ];
72
+			} else {
73
+				$loadedItems[ $key ] = null;
74
+			}
75
+		}
76
+		return $loadedItems;
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -67,10 +67,10 @@
 block discarded – undo
67 67
          * the model layer.
68 68
          */
69 69
         foreach ($keys as $key) {
70
-            if (isset($result[ $key ])) {
71
-                $loadedItems[ $key ] = $result[ $key ];
70
+            if (isset($result[$key])) {
71
+                $loadedItems[$key] = $result[$key];
72 72
             } else {
73
-                $loadedItems[ $key ] = null;
73
+                $loadedItems[$key] = null;
74 74
             }
75 75
         }
76 76
         return $loadedItems;
Please login to merge, or discard this patch.
core/domain/services/graphql/data/loaders/PriceTypeLoader.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -12,31 +12,31 @@
 block discarded – undo
12 12
  */
13 13
 class PriceTypeLoader extends AbstractLoader
14 14
 {
15
-    /**
16
-     * @return EE_Base_Class
17
-     * @throws EE_Error
18
-     * @throws InvalidArgumentException
19
-     * @throws InvalidDataTypeException
20
-     * @throws InvalidInterfaceException
21
-     */
22
-    protected function getQuery()
23
-    {
24
-        return EEM_PriceType::instance();
25
-    }
15
+	/**
16
+	 * @return EE_Base_Class
17
+	 * @throws EE_Error
18
+	 * @throws InvalidArgumentException
19
+	 * @throws InvalidDataTypeException
20
+	 * @throws InvalidInterfaceException
21
+	 */
22
+	protected function getQuery()
23
+	{
24
+		return EEM_PriceType::instance();
25
+	}
26 26
 
27
-    /**
28
-     * @param array $keys
29
-     *
30
-     * @return array
31
-     * @throws EE_Error
32
-     * @throws InvalidArgumentException
33
-     * @throws InvalidDataTypeException
34
-     * @throws InvalidInterfaceException
35
-     */
36
-    protected function getWhereParams(array $keys)
37
-    {
38
-        return [
39
-            'PRT_ID' => ['IN', $keys],
40
-        ];
41
-    }
27
+	/**
28
+	 * @param array $keys
29
+	 *
30
+	 * @return array
31
+	 * @throws EE_Error
32
+	 * @throws InvalidArgumentException
33
+	 * @throws InvalidDataTypeException
34
+	 * @throws InvalidInterfaceException
35
+	 */
36
+	protected function getWhereParams(array $keys)
37
+	{
38
+		return [
39
+			'PRT_ID' => ['IN', $keys],
40
+		];
41
+	}
42 42
 }
Please login to merge, or discard this patch.