Completed
Branch EDTR/master (46772d)
by
unknown
19:53 queued 09:36
created
domain/services/graphql/connection_resolvers/DatetimeConnectionResolver.php 1 patch
Indentation   +165 added lines, -165 removed lines patch added patch discarded remove patch
@@ -18,169 +18,169 @@
 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
-     * Here, we map the args from the input, then we make sure that we're only querying
55
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
56
-     * handle batch resolution of the posts.
57
-     *
58
-     * @return array
59
-     * @throws EE_Error
60
-     * @throws InvalidArgumentException
61
-     * @throws InvalidDataTypeException
62
-     * @throws InvalidInterfaceException
63
-     */
64
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
65
-    public function get_query_args()
66
-    {
67
-        $where_params = ['DTT_deleted' => ['IN', [true, false]]];
68
-        $query_args   = [];
69
-
70
-        $query_args['limit'] = $this->getLimit();
71
-
72
-        // Avoid multiple entries by join.
73
-        $query_args['group_by'] = 'DTT_ID';
74
-
75
-        $query_args['default_where_conditions'] = 'minimum';
76
-
77
-        /**
78
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
79
-         */
80
-        $input_fields = [];
81
-        if (! empty($this->args['where'])) {
82
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
83
-
84
-            // Use the proper operator.
85
-            if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) {
86
-                $input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']];
87
-            }
88
-            if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
89
-                $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
90
-            }
91
-        }
92
-
93
-        /**
94
-         * Determine where we're at in the Graph and adjust the query context appropriately.
95
-         *
96
-         * For example, if we're querying for datetime as a field of event query, this will automatically
97
-         * set the query to pull datetimes that belong to that event.
98
-         * We can set more cases for other source types.
99
-         */
100
-        if (is_object($this->source)) {
101
-            switch (true) {
102
-                // It's surely an event
103
-                case $this->source instanceof Post:
104
-                    $where_params['EVT_ID'] = $this->source->ID;
105
-                    break;
106
-                case $this->source instanceof EE_Event:
107
-                    $where_params['EVT_ID'] = $this->source->ID();
108
-                    break;
109
-                case $this->source instanceof EE_Ticket:
110
-                    $where_params['Ticket.TKT_ID'] = $this->source->ID();
111
-                    break;
112
-                case $this->source instanceof EE_Checkin:
113
-                    $where_params['Checkin.CHK_ID'] = $this->source->ID();
114
-                    break;
115
-            }
116
-        }
117
-
118
-        /**
119
-         * Merge the input_fields with the default query_args
120
-         */
121
-        if (! empty($input_fields)) {
122
-            $where_params = array_merge($where_params, $input_fields);
123
-        }
124
-
125
-        list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID');
126
-
127
-        if (! empty($this->args['where']['upcoming'])) {
128
-            $where_params['DTT_EVT_start'] = array(
129
-                '>',
130
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
131
-            );
132
-        }
133
-
134
-        if (! empty($this->args['where']['active'])) {
135
-            $where_params['DTT_EVT_start'] = array(
136
-                '<',
137
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
138
-            );
139
-            $where_params['DTT_EVT_end'] = array(
140
-                '>',
141
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
142
-            );
143
-        }
144
-
145
-        if (! empty($this->args['where']['expired'])) {
146
-            $where_params['DTT_EVT_end'] = array(
147
-                '<',
148
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
149
-            );
150
-        }
151
-
152
-        $query_args[] = $where_params;
153
-
154
-        /**
155
-         * Return the $query_args
156
-         */
157
-        return $query_args;
158
-    }
159
-
160
-
161
-    /**
162
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
163
-     * friendly keys.
164
-     *
165
-     * @param array $where_args
166
-     * @return array
167
-     */
168
-    public function sanitizeInputFields(array $where_args)
169
-    {
170
-        $arg_mapping = [
171
-            'event'      => 'EVT_ID',
172
-            'eventIn'    => 'EVT_ID',
173
-            'eventId'    => 'EVT_ID',
174
-            'eventIdIn'  => 'EVT_ID',
175
-            'ticket'     => 'Ticket.TKT_ID',
176
-            'ticketIn'   => 'Ticket.TKT_ID',
177
-            'ticketId'   => 'Ticket.TKT_ID',
178
-            'ticketIdIn' => 'Ticket.TKT_ID',
179
-        ];
180
-        return $this->sanitizeWhereArgsForInputFields(
181
-            $where_args,
182
-            $arg_mapping,
183
-            ['event', 'eventIn', 'ticket', 'ticketIn']
184
-        );
185
-    }
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
+	 * Here, we map the args from the input, then we make sure that we're only querying
55
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
56
+	 * handle batch resolution of the posts.
57
+	 *
58
+	 * @return array
59
+	 * @throws EE_Error
60
+	 * @throws InvalidArgumentException
61
+	 * @throws InvalidDataTypeException
62
+	 * @throws InvalidInterfaceException
63
+	 */
64
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
65
+	public function get_query_args()
66
+	{
67
+		$where_params = ['DTT_deleted' => ['IN', [true, false]]];
68
+		$query_args   = [];
69
+
70
+		$query_args['limit'] = $this->getLimit();
71
+
72
+		// Avoid multiple entries by join.
73
+		$query_args['group_by'] = 'DTT_ID';
74
+
75
+		$query_args['default_where_conditions'] = 'minimum';
76
+
77
+		/**
78
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
79
+		 */
80
+		$input_fields = [];
81
+		if (! empty($this->args['where'])) {
82
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
83
+
84
+			// Use the proper operator.
85
+			if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) {
86
+				$input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']];
87
+			}
88
+			if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
89
+				$input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
90
+			}
91
+		}
92
+
93
+		/**
94
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
95
+		 *
96
+		 * For example, if we're querying for datetime as a field of event query, this will automatically
97
+		 * set the query to pull datetimes that belong to that event.
98
+		 * We can set more cases for other source types.
99
+		 */
100
+		if (is_object($this->source)) {
101
+			switch (true) {
102
+				// It's surely an event
103
+				case $this->source instanceof Post:
104
+					$where_params['EVT_ID'] = $this->source->ID;
105
+					break;
106
+				case $this->source instanceof EE_Event:
107
+					$where_params['EVT_ID'] = $this->source->ID();
108
+					break;
109
+				case $this->source instanceof EE_Ticket:
110
+					$where_params['Ticket.TKT_ID'] = $this->source->ID();
111
+					break;
112
+				case $this->source instanceof EE_Checkin:
113
+					$where_params['Checkin.CHK_ID'] = $this->source->ID();
114
+					break;
115
+			}
116
+		}
117
+
118
+		/**
119
+		 * Merge the input_fields with the default query_args
120
+		 */
121
+		if (! empty($input_fields)) {
122
+			$where_params = array_merge($where_params, $input_fields);
123
+		}
124
+
125
+		list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID');
126
+
127
+		if (! empty($this->args['where']['upcoming'])) {
128
+			$where_params['DTT_EVT_start'] = array(
129
+				'>',
130
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
131
+			);
132
+		}
133
+
134
+		if (! empty($this->args['where']['active'])) {
135
+			$where_params['DTT_EVT_start'] = array(
136
+				'<',
137
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
138
+			);
139
+			$where_params['DTT_EVT_end'] = array(
140
+				'>',
141
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
142
+			);
143
+		}
144
+
145
+		if (! empty($this->args['where']['expired'])) {
146
+			$where_params['DTT_EVT_end'] = array(
147
+				'<',
148
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
149
+			);
150
+		}
151
+
152
+		$query_args[] = $where_params;
153
+
154
+		/**
155
+		 * Return the $query_args
156
+		 */
157
+		return $query_args;
158
+	}
159
+
160
+
161
+	/**
162
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
163
+	 * friendly keys.
164
+	 *
165
+	 * @param array $where_args
166
+	 * @return array
167
+	 */
168
+	public function sanitizeInputFields(array $where_args)
169
+	{
170
+		$arg_mapping = [
171
+			'event'      => 'EVT_ID',
172
+			'eventIn'    => 'EVT_ID',
173
+			'eventId'    => 'EVT_ID',
174
+			'eventIdIn'  => 'EVT_ID',
175
+			'ticket'     => 'Ticket.TKT_ID',
176
+			'ticketIn'   => 'Ticket.TKT_ID',
177
+			'ticketId'   => 'Ticket.TKT_ID',
178
+			'ticketIdIn' => 'Ticket.TKT_ID',
179
+		];
180
+		return $this->sanitizeWhereArgsForInputFields(
181
+			$where_args,
182
+			$arg_mapping,
183
+			['event', 'eventIn', 'ticket', 'ticketIn']
184
+		);
185
+	}
186 186
 }
Please login to merge, or discard this patch.
services/graphql/connection_resolvers/PriceTypeConnectionResolver.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -14,66 +14,66 @@
 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
-     * Here, we map the args from the input, then we make sure that we're only querying
53
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
54
-     * handle batch resolution of the posts.
55
-     *
56
-     * @return array
57
-     * @throws EE_Error
58
-     * @throws InvalidArgumentException
59
-     * @throws ReflectionException
60
-     * @throws InvalidDataTypeException
61
-     * @throws InvalidInterfaceException
62
-     */
63
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
64
-    public function get_query_args()
65
-    {
66
-        $where_params = [];
67
-        $query_args   = [];
51
+	/**
52
+	 * Here, we map the args from the input, then we make sure that we're only querying
53
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
54
+	 * handle batch resolution of the posts.
55
+	 *
56
+	 * @return array
57
+	 * @throws EE_Error
58
+	 * @throws InvalidArgumentException
59
+	 * @throws ReflectionException
60
+	 * @throws InvalidDataTypeException
61
+	 * @throws InvalidInterfaceException
62
+	 */
63
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
64
+	public function get_query_args()
65
+	{
66
+		$where_params = [];
67
+		$query_args   = [];
68 68
 
69
-        $query_args['limit'] = $this->getLimit();
69
+		$query_args['limit'] = $this->getLimit();
70 70
 
71
-        // Avoid multiple entries by join.
72
-        $query_args['group_by'] = 'PRT_ID';
71
+		// Avoid multiple entries by join.
72
+		$query_args['group_by'] = 'PRT_ID';
73 73
 
74
-        /**
75
-         * Return the $query_args
76
-         */
77
-        return $query_args;
78
-    }
74
+		/**
75
+		 * Return the $query_args
76
+		 */
77
+		return $query_args;
78
+	}
79 79
 }
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/VenueConnectionResolver.php 1 patch
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -16,126 +16,126 @@
 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
-     * Here, we map the args from the input, then we make sure that we're only querying
55
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
56
-     * handle batch resolution of the posts.
57
-     *
58
-     * @return array
59
-     */
60
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
61
-    public function get_query_args()
62
-    {
63
-        $query_args = [];
64
-
65
-        /**
66
-         * Prepare for later use
67
-         */
68
-        $last = ! empty($this->args['last']) ? $this->args['last'] : null;
69
-        $first = ! empty($this->args['first']) ? $this->args['first'] : null;
70
-
71
-        /**
72
-         * Set limit the highest value of $first and $last, with a (filterable) max of 100
73
-         */
74
-        $query_args['limit'] = min(
75
-            max(absint($first), absint($last), 10),
76
-            $this->query_amount
77
-        ) + 1;
78
-
79
-        /**
80
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
81
-         */
82
-        $input_fields = [];
83
-        if (! empty($this->args['where'])) {
84
-            $input_fields = $this->sanitize_input_fields($this->args['where']);
85
-        }
86
-
87
-        /**
88
-         * Determine where we're at in the Graph and adjust the query context appropriately.
89
-         * For example, if we're querying for datetime as a field of event query, this will automatically
90
-         * set the query to pull datetimes that belong to that event.
91
-         * We can set more cases for other source types.
92
-         */
93
-        if (is_object($this->source)) {
94
-            switch (true) {
95
-                // Assumed to be an event
96
-                case $this->source instanceof Post:
97
-                    $query_args[] = ['Event.EVT_ID' => $this->source->ID];
98
-                    break;
99
-                case $this->source instanceof EE_Event:
100
-                    $query_args[] = ['Event.EVT_ID' => $this->source->ID()];
101
-                    break;
102
-            }
103
-        }
104
-
105
-        /**
106
-         * Merge the input_fields with the default query_args
107
-         */
108
-        if (! empty($input_fields)) {
109
-            $query_args = array_merge($query_args, $input_fields);
110
-        }
111
-
112
-        /**
113
-         * Return the $query_args
114
-         */
115
-        return $query_args;
116
-    }
117
-
118
-
119
-    /**
120
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query
121
-     * friendly keys. There's probably a cleaner/more dynamic way to approach this, but
122
-     * this was quick. I'd be down to explore more dynamic ways to map this, but for
123
-     * now this gets the job done.
124
-     *
125
-     * @param array $query_args
126
-     * @return array
127
-     */
128
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
129
-    public function sanitize_input_fields(array $query_args)
130
-    {
131
-        $arg_mapping = [
132
-            'orderBy' => 'order_by',
133
-            'order'   => 'order',
134
-        ];
135
-
136
-        /**
137
-         * Return the Query Args
138
-         */
139
-        return ! empty($query_args) && is_array($query_args) ? $query_args : [];
140
-    }
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
+	 * Here, we map the args from the input, then we make sure that we're only querying
55
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
56
+	 * handle batch resolution of the posts.
57
+	 *
58
+	 * @return array
59
+	 */
60
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
61
+	public function get_query_args()
62
+	{
63
+		$query_args = [];
64
+
65
+		/**
66
+		 * Prepare for later use
67
+		 */
68
+		$last = ! empty($this->args['last']) ? $this->args['last'] : null;
69
+		$first = ! empty($this->args['first']) ? $this->args['first'] : null;
70
+
71
+		/**
72
+		 * Set limit the highest value of $first and $last, with a (filterable) max of 100
73
+		 */
74
+		$query_args['limit'] = min(
75
+			max(absint($first), absint($last), 10),
76
+			$this->query_amount
77
+		) + 1;
78
+
79
+		/**
80
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
81
+		 */
82
+		$input_fields = [];
83
+		if (! empty($this->args['where'])) {
84
+			$input_fields = $this->sanitize_input_fields($this->args['where']);
85
+		}
86
+
87
+		/**
88
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
89
+		 * For example, if we're querying for datetime as a field of event query, this will automatically
90
+		 * set the query to pull datetimes that belong to that event.
91
+		 * We can set more cases for other source types.
92
+		 */
93
+		if (is_object($this->source)) {
94
+			switch (true) {
95
+				// Assumed to be an event
96
+				case $this->source instanceof Post:
97
+					$query_args[] = ['Event.EVT_ID' => $this->source->ID];
98
+					break;
99
+				case $this->source instanceof EE_Event:
100
+					$query_args[] = ['Event.EVT_ID' => $this->source->ID()];
101
+					break;
102
+			}
103
+		}
104
+
105
+		/**
106
+		 * Merge the input_fields with the default query_args
107
+		 */
108
+		if (! empty($input_fields)) {
109
+			$query_args = array_merge($query_args, $input_fields);
110
+		}
111
+
112
+		/**
113
+		 * Return the $query_args
114
+		 */
115
+		return $query_args;
116
+	}
117
+
118
+
119
+	/**
120
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query
121
+	 * friendly keys. There's probably a cleaner/more dynamic way to approach this, but
122
+	 * this was quick. I'd be down to explore more dynamic ways to map this, but for
123
+	 * now this gets the job done.
124
+	 *
125
+	 * @param array $query_args
126
+	 * @return array
127
+	 */
128
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
129
+	public function sanitize_input_fields(array $query_args)
130
+	{
131
+		$arg_mapping = [
132
+			'orderBy' => 'order_by',
133
+			'order'   => 'order',
134
+		];
135
+
136
+		/**
137
+		 * Return the Query Args
138
+		 */
139
+		return ! empty($query_args) && is_array($query_args) ? $query_args : [];
140
+	}
141 141
 }
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/AttendeeConnectionResolver.php 1 patch
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -16,155 +16,155 @@
 block discarded – undo
16 16
  */
17 17
 class AttendeeConnectionResolver extends AbstractConnectionResolver
18 18
 {
19
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
20
-    public function get_loader_name()
21
-    {
22
-        return 'espresso_attendee';
23
-    }
24
-
25
-    /**
26
-     * @return EEM_Attendee
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_Attendee::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
-     * Here, we map the args from the input, then we make sure that we're only querying
55
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
56
-     * handle batch resolution of the posts.
57
-     *
58
-     * @return array
59
-     * @throws EE_Error
60
-     * @throws InvalidArgumentException
61
-     * @throws ReflectionException
62
-     * @throws InvalidDataTypeException
63
-     * @throws InvalidInterfaceException
64
-     */
65
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
66
-    public function get_query_args()
67
-    {
68
-        $where_params = [];
69
-        $query_args   = [];
70
-
71
-        $query_args['limit'] = $this->getLimit();
72
-
73
-        // Avoid multiple entries by join.
74
-        $query_args['group_by'] = 'ATT_ID';
75
-
76
-        $query_args['default_where_conditions'] = 'minimum';
77
-
78
-        /**
79
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
80
-         */
81
-        $input_fields = [];
82
-        if (! empty($this->args['where'])) {
83
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
84
-
85
-            // Since we do not have any falsy values in query params
86
-            // Lets get rid of empty values
87
-            $input_fields = array_filter($input_fields);
88
-
89
-            // Use the proper operator.
90
-            if (! empty($input_fields['Registration.Event.EVT_ID']) && is_array($input_fields['Registration.Event.EVT_ID'])) {
91
-                $input_fields['Registration.Event.EVT_ID'] = ['IN', $input_fields['Registration.Event.EVT_ID']];
92
-            }
93
-            if (! empty($input_fields['Registration.Ticket.TKT_ID']) && is_array($input_fields['Registration.Ticket.TKT_ID'])) {
94
-                $input_fields['Registration.Ticket.TKT_ID'] = ['IN', $input_fields['Registration.Ticket.TKT_ID']];
95
-            }
96
-            // If Ticket param is passed, it will have preference over Datetime param
97
-            // So, use Datetime param only if a Ticket param is not passed
98
-            if (! empty($input_fields['Datetime.DTT_ID']) && empty($input_fields['Registration.Ticket.TKT_ID'])) {
99
-                $datetimeIds = $input_fields['Datetime.DTT_ID'];
100
-                // Make sure it's an array, ready for "IN" operator
101
-                $datetimeIds = is_array($datetimeIds) ? $datetimeIds : [$datetimeIds];
102
-
103
-                try {
104
-                    // Get related ticket IDs for the given dates
105
-                    $ticketIds = EEM_Ticket::instance()->get_col([
106
-                        [
107
-                            'Datetime.DTT_ID' => ['IN', $datetimeIds],
108
-                            'TKT_deleted'     => ['IN', [true, false]],
109
-                        ],
110
-                        'default_where_conditions' => 'minimum',
111
-                    ]);
112
-                } catch (Throwable $th) {
113
-                    $ticketIds = [];
114
-                }
115
-
116
-                if (!empty($ticketIds)) {
117
-                    $input_fields['Registration.Ticket.TKT_ID'] = ['IN', $ticketIds];
118
-                }
119
-            }
120
-            // Since there is no relation between Attendee and Datetime, we need to remove it
121
-            unset($input_fields['Datetime.DTT_ID']);
122
-        }
123
-
124
-        /**
125
-         * Merge the input_fields with the default query_args
126
-         */
127
-        if (! empty($input_fields)) {
128
-            $where_params = array_merge($where_params, $input_fields);
129
-        }
130
-
131
-        list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'ATT_ID');
132
-
133
-        $query_args[] = $where_params;
134
-
135
-        /**
136
-         * Return the $query_args
137
-         */
138
-        return $query_args;
139
-    }
140
-
141
-
142
-    /**
143
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
144
-     * friendly keys.
145
-     *
146
-     * @param array $where_args
147
-     * @return array
148
-     */
149
-    public function sanitizeInputFields(array $where_args)
150
-    {
151
-        $arg_mapping = [
152
-            // There is no direct relation between Attendee and Datetime
153
-            // But we will handle it via Tickets related to given dates
154
-            'datetime'      => 'Datetime.DTT_ID',
155
-            'datetimeIn'    => 'Datetime.DTT_ID',
156
-            'event'         => 'Registration.Event.EVT_ID',
157
-            'eventIn'       => 'Registration.Event.EVT_ID',
158
-            'regTicket'     => 'Registration.Ticket.TKT_ID',
159
-            'regTicketIn'   => 'Registration.Ticket.TKT_ID',
160
-            'regTicketIdIn' => 'Registration.Ticket.TKT_ID',
161
-            'regTicketId'   => 'Registration.Ticket.TKT_ID', // priority.
162
-            'regStatus'     => 'Registration.Status.STS_ID',
163
-        ];
164
-        return $this->sanitizeWhereArgsForInputFields(
165
-            $where_args,
166
-            $arg_mapping,
167
-            ['datetime', 'datetimeIn', 'event', 'eventIn', 'regTicket', 'regTicketIn']
168
-        );
169
-    }
19
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
20
+	public function get_loader_name()
21
+	{
22
+		return 'espresso_attendee';
23
+	}
24
+
25
+	/**
26
+	 * @return EEM_Attendee
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_Attendee::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
+	 * Here, we map the args from the input, then we make sure that we're only querying
55
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
56
+	 * handle batch resolution of the posts.
57
+	 *
58
+	 * @return array
59
+	 * @throws EE_Error
60
+	 * @throws InvalidArgumentException
61
+	 * @throws ReflectionException
62
+	 * @throws InvalidDataTypeException
63
+	 * @throws InvalidInterfaceException
64
+	 */
65
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
66
+	public function get_query_args()
67
+	{
68
+		$where_params = [];
69
+		$query_args   = [];
70
+
71
+		$query_args['limit'] = $this->getLimit();
72
+
73
+		// Avoid multiple entries by join.
74
+		$query_args['group_by'] = 'ATT_ID';
75
+
76
+		$query_args['default_where_conditions'] = 'minimum';
77
+
78
+		/**
79
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
80
+		 */
81
+		$input_fields = [];
82
+		if (! empty($this->args['where'])) {
83
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
84
+
85
+			// Since we do not have any falsy values in query params
86
+			// Lets get rid of empty values
87
+			$input_fields = array_filter($input_fields);
88
+
89
+			// Use the proper operator.
90
+			if (! empty($input_fields['Registration.Event.EVT_ID']) && is_array($input_fields['Registration.Event.EVT_ID'])) {
91
+				$input_fields['Registration.Event.EVT_ID'] = ['IN', $input_fields['Registration.Event.EVT_ID']];
92
+			}
93
+			if (! empty($input_fields['Registration.Ticket.TKT_ID']) && is_array($input_fields['Registration.Ticket.TKT_ID'])) {
94
+				$input_fields['Registration.Ticket.TKT_ID'] = ['IN', $input_fields['Registration.Ticket.TKT_ID']];
95
+			}
96
+			// If Ticket param is passed, it will have preference over Datetime param
97
+			// So, use Datetime param only if a Ticket param is not passed
98
+			if (! empty($input_fields['Datetime.DTT_ID']) && empty($input_fields['Registration.Ticket.TKT_ID'])) {
99
+				$datetimeIds = $input_fields['Datetime.DTT_ID'];
100
+				// Make sure it's an array, ready for "IN" operator
101
+				$datetimeIds = is_array($datetimeIds) ? $datetimeIds : [$datetimeIds];
102
+
103
+				try {
104
+					// Get related ticket IDs for the given dates
105
+					$ticketIds = EEM_Ticket::instance()->get_col([
106
+						[
107
+							'Datetime.DTT_ID' => ['IN', $datetimeIds],
108
+							'TKT_deleted'     => ['IN', [true, false]],
109
+						],
110
+						'default_where_conditions' => 'minimum',
111
+					]);
112
+				} catch (Throwable $th) {
113
+					$ticketIds = [];
114
+				}
115
+
116
+				if (!empty($ticketIds)) {
117
+					$input_fields['Registration.Ticket.TKT_ID'] = ['IN', $ticketIds];
118
+				}
119
+			}
120
+			// Since there is no relation between Attendee and Datetime, we need to remove it
121
+			unset($input_fields['Datetime.DTT_ID']);
122
+		}
123
+
124
+		/**
125
+		 * Merge the input_fields with the default query_args
126
+		 */
127
+		if (! empty($input_fields)) {
128
+			$where_params = array_merge($where_params, $input_fields);
129
+		}
130
+
131
+		list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'ATT_ID');
132
+
133
+		$query_args[] = $where_params;
134
+
135
+		/**
136
+		 * Return the $query_args
137
+		 */
138
+		return $query_args;
139
+	}
140
+
141
+
142
+	/**
143
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
144
+	 * friendly keys.
145
+	 *
146
+	 * @param array $where_args
147
+	 * @return array
148
+	 */
149
+	public function sanitizeInputFields(array $where_args)
150
+	{
151
+		$arg_mapping = [
152
+			// There is no direct relation between Attendee and Datetime
153
+			// But we will handle it via Tickets related to given dates
154
+			'datetime'      => 'Datetime.DTT_ID',
155
+			'datetimeIn'    => 'Datetime.DTT_ID',
156
+			'event'         => 'Registration.Event.EVT_ID',
157
+			'eventIn'       => 'Registration.Event.EVT_ID',
158
+			'regTicket'     => 'Registration.Ticket.TKT_ID',
159
+			'regTicketIn'   => 'Registration.Ticket.TKT_ID',
160
+			'regTicketIdIn' => 'Registration.Ticket.TKT_ID',
161
+			'regTicketId'   => 'Registration.Ticket.TKT_ID', // priority.
162
+			'regStatus'     => 'Registration.Status.STS_ID',
163
+		];
164
+		return $this->sanitizeWhereArgsForInputFields(
165
+			$where_args,
166
+			$arg_mapping,
167
+			['datetime', 'datetimeIn', 'event', 'eventIn', 'regTicket', 'regTicketIn']
168
+		);
169
+	}
170 170
 }
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/PriceConnectionResolver.php 1 patch
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -15,161 +15,161 @@
 block discarded – undo
15 15
  */
16 16
 class PriceConnectionResolver extends AbstractConnectionResolver
17 17
 {
18
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
19
-    public function get_loader_name()
20
-    {
21
-        return 'espresso_price';
22
-    }
23
-
24
-    /**
25
-     * @return EEM_Price
26
-     * @throws EE_Error
27
-     * @throws InvalidArgumentException
28
-     * @throws InvalidDataTypeException
29
-     * @throws InvalidInterfaceException
30
-     */
31
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
32
-    public function get_query()
33
-    {
34
-        return EEM_Price::instance();
35
-    }
36
-
37
-
38
-    /**
39
-     * Return an array of item IDs from the query
40
-     *
41
-     * @return array
42
-     */
43
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
44
-    public function get_ids()
45
-    {
46
-        $results = $this->query->get_col($this->query_args);
47
-
48
-        return ! empty($results) ? $results : [];
49
-    }
50
-
51
-
52
-    /**
53
-     * Here, we map the args from the input, then we make sure that we're only querying
54
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
55
-     * handle batch resolution of the posts.
56
-     *
57
-     * @return array
58
-     * @throws EE_Error
59
-     * @throws InvalidArgumentException
60
-     * @throws ReflectionException
61
-     * @throws InvalidDataTypeException
62
-     * @throws InvalidInterfaceException
63
-     */
64
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
65
-    public function get_query_args()
66
-    {
67
-        $where_params = [];
68
-        $query_args   = [];
69
-
70
-        $query_args['limit'] = $this->getLimit();
71
-
72
-        // Avoid multiple entries by join.
73
-        $query_args['group_by'] = 'PRC_ID';
74
-
75
-        $query_args['default_where_conditions'] = 'minimum';
76
-
77
-        /**
78
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
79
-         */
80
-        $input_fields = [];
81
-        if (! empty($this->args['where'])) {
82
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
83
-
84
-            // Use the proper operator.
85
-            if (! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) {
86
-                $input_fields['PRC_ID'] = ['in', $input_fields['PRC_ID']];
87
-            }
88
-            if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
89
-                $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
90
-            }
91
-            if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) {
92
-                $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']];
93
-            }
94
-            if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) {
95
-                $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']];
96
-            }
97
-        }
98
-
99
-        /**
100
-         * Determine where we're at in the Graph and adjust the query context appropriately.
101
-         */
102
-        if ($this->source instanceof EE_Ticket) {
103
-            $where_params['Ticket.TKT_ID'] = $this->source->ID();
104
-        }
105
-
106
-        /**
107
-         * Merge the input_fields with the default query_args
108
-         */
109
-        if (! empty($input_fields)) {
110
-            $where_params = array_merge($where_params, $input_fields);
111
-        }
112
-
113
-        list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID');
114
-
115
-        // If default prices should be included.
116
-        if (! empty($this->args['where']['includeDefaultPrices'])) {
117
-            /**
118
-             * We need to get each price that
119
-             * - satisfies $where_params above
120
-             * OR
121
-             * - it's a default non trashed price
122
-             */
123
-            $where_params = [
124
-                'OR' => [
125
-                    // use extra OR instead of AND to avoid it getting overridden
126
-                    'OR' => [
127
-                        'AND' => [
128
-                            'PRC_deleted'    => 0,
129
-                            'PRC_is_default' => 1,
130
-                        ]
131
-                    ],
132
-                    'AND' => $where_params,
133
-                ],
134
-            ];
135
-        }
136
-
137
-        $query_args[] = $where_params;
138
-
139
-        /**
140
-         * Return the $query_args
141
-         */
142
-        return $query_args;
143
-    }
144
-
145
-
146
-    /**
147
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
148
-     * friendly keys.
149
-     *
150
-     * @param array $where_args
151
-     * @return array
152
-     */
153
-    public function sanitizeInputFields(array $where_args)
154
-    {
155
-        $arg_mapping = [
156
-            'in'              => 'PRC_ID',
157
-            'idIn'            => 'PRC_ID',
158
-            'ticket'          => 'Ticket.TKT_ID',
159
-            'ticketIn'        => 'Ticket.TKT_ID',
160
-            'ticketIdIn'      => 'Ticket.TKT_ID',
161
-            'ticketId'        => 'Ticket.TKT_ID', // priority.
162
-            'priceType'       => 'Price_Type.PRT_ID',
163
-            'priceTypeIn'     => 'Price_Type.PRT_ID',
164
-            'priceTypeIdIn'   => 'Price_Type.PRT_ID',
165
-            'priceTypeId'     => 'Price_Type.PRT_ID', // priority.
166
-            'priceBaseType'   => 'Price_Type.PBT_ID',
167
-            'priceBaseTypeIn' => 'Price_Type.PBT_ID',
168
-        ];
169
-        return $this->sanitizeWhereArgsForInputFields(
170
-            $where_args,
171
-            $arg_mapping,
172
-            ['in', 'ticket', 'ticketIn', 'priceType', 'priceTypeIn']
173
-        );
174
-    }
18
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
19
+	public function get_loader_name()
20
+	{
21
+		return 'espresso_price';
22
+	}
23
+
24
+	/**
25
+	 * @return EEM_Price
26
+	 * @throws EE_Error
27
+	 * @throws InvalidArgumentException
28
+	 * @throws InvalidDataTypeException
29
+	 * @throws InvalidInterfaceException
30
+	 */
31
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
32
+	public function get_query()
33
+	{
34
+		return EEM_Price::instance();
35
+	}
36
+
37
+
38
+	/**
39
+	 * Return an array of item IDs from the query
40
+	 *
41
+	 * @return array
42
+	 */
43
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
44
+	public function get_ids()
45
+	{
46
+		$results = $this->query->get_col($this->query_args);
47
+
48
+		return ! empty($results) ? $results : [];
49
+	}
50
+
51
+
52
+	/**
53
+	 * Here, we map the args from the input, then we make sure that we're only querying
54
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
55
+	 * handle batch resolution of the posts.
56
+	 *
57
+	 * @return array
58
+	 * @throws EE_Error
59
+	 * @throws InvalidArgumentException
60
+	 * @throws ReflectionException
61
+	 * @throws InvalidDataTypeException
62
+	 * @throws InvalidInterfaceException
63
+	 */
64
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
65
+	public function get_query_args()
66
+	{
67
+		$where_params = [];
68
+		$query_args   = [];
69
+
70
+		$query_args['limit'] = $this->getLimit();
71
+
72
+		// Avoid multiple entries by join.
73
+		$query_args['group_by'] = 'PRC_ID';
74
+
75
+		$query_args['default_where_conditions'] = 'minimum';
76
+
77
+		/**
78
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
79
+		 */
80
+		$input_fields = [];
81
+		if (! empty($this->args['where'])) {
82
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
83
+
84
+			// Use the proper operator.
85
+			if (! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) {
86
+				$input_fields['PRC_ID'] = ['in', $input_fields['PRC_ID']];
87
+			}
88
+			if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
89
+				$input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
90
+			}
91
+			if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) {
92
+				$input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']];
93
+			}
94
+			if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) {
95
+				$input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']];
96
+			}
97
+		}
98
+
99
+		/**
100
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
101
+		 */
102
+		if ($this->source instanceof EE_Ticket) {
103
+			$where_params['Ticket.TKT_ID'] = $this->source->ID();
104
+		}
105
+
106
+		/**
107
+		 * Merge the input_fields with the default query_args
108
+		 */
109
+		if (! empty($input_fields)) {
110
+			$where_params = array_merge($where_params, $input_fields);
111
+		}
112
+
113
+		list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID');
114
+
115
+		// If default prices should be included.
116
+		if (! empty($this->args['where']['includeDefaultPrices'])) {
117
+			/**
118
+			 * We need to get each price that
119
+			 * - satisfies $where_params above
120
+			 * OR
121
+			 * - it's a default non trashed price
122
+			 */
123
+			$where_params = [
124
+				'OR' => [
125
+					// use extra OR instead of AND to avoid it getting overridden
126
+					'OR' => [
127
+						'AND' => [
128
+							'PRC_deleted'    => 0,
129
+							'PRC_is_default' => 1,
130
+						]
131
+					],
132
+					'AND' => $where_params,
133
+				],
134
+			];
135
+		}
136
+
137
+		$query_args[] = $where_params;
138
+
139
+		/**
140
+		 * Return the $query_args
141
+		 */
142
+		return $query_args;
143
+	}
144
+
145
+
146
+	/**
147
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
148
+	 * friendly keys.
149
+	 *
150
+	 * @param array $where_args
151
+	 * @return array
152
+	 */
153
+	public function sanitizeInputFields(array $where_args)
154
+	{
155
+		$arg_mapping = [
156
+			'in'              => 'PRC_ID',
157
+			'idIn'            => 'PRC_ID',
158
+			'ticket'          => 'Ticket.TKT_ID',
159
+			'ticketIn'        => 'Ticket.TKT_ID',
160
+			'ticketIdIn'      => 'Ticket.TKT_ID',
161
+			'ticketId'        => 'Ticket.TKT_ID', // priority.
162
+			'priceType'       => 'Price_Type.PRT_ID',
163
+			'priceTypeIn'     => 'Price_Type.PRT_ID',
164
+			'priceTypeIdIn'   => 'Price_Type.PRT_ID',
165
+			'priceTypeId'     => 'Price_Type.PRT_ID', // priority.
166
+			'priceBaseType'   => 'Price_Type.PBT_ID',
167
+			'priceBaseTypeIn' => 'Price_Type.PBT_ID',
168
+		];
169
+		return $this->sanitizeWhereArgsForInputFields(
170
+			$where_args,
171
+			$arg_mapping,
172
+			['in', 'ticket', 'ticketIn', 'priceType', 'priceTypeIn']
173
+		);
174
+	}
175 175
 }
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/AbstractConnectionResolver.php 1 patch
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -18,182 +18,182 @@
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * Determine whether the Query should execute. If it's determined that the query should
23
-     * not be run based on context such as, but not limited to, who the user is, where in the
24
-     * ResolveTree the Query is, the relation to the node the Query is connected to, etc
25
-     * Return false to prevent the query from executing.
26
-     *
27
-     * @return bool
28
-     */
29
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
30
-    public function should_execute()
31
-    {
32
-        return $this->should_execute;
33
-    }
34
-
35
-    /**
36
-     * Set limit the highest value of first and last, with a (filterable) max of 100
37
-     *
38
-     * @return array
39
-     */
40
-    protected function getLimit()
41
-    {
42
-        $first = ! empty($this->args['first']) ? absint($this->args['first']) : null;
43
-        $last  = ! empty($this->args['last']) ? absint($this->args['last']) : null;
44
-
45
-        $limit = min(
46
-            max($first, $last, 100),
47
-            $this->query_amount
48
-        );
49
-        $limit++;
50
-        return $limit;
51
-    }
52
-
53
-    /**
54
-     * Get_amount_requested
55
-     *
56
-     * This checks the $args to determine the amount requested
57
-     *
58
-     * @return int|null
59
-     * @throws \Exception
60
-     */
61
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
62
-    public function get_amount_requested()
63
-    {
64
-        $amount_requested = parent::get_amount_requested();
65
-
66
-        /**
67
-         * If both first & last are used in the input args, throw an exception as that won't
68
-         * work properly
69
-         */
70
-        if (empty($this->args['first']) && empty($this->args['last']) && $amount_requested === 10) {
71
-            return 100; // default.
72
-        }
73
-
74
-        return $amount_requested;
75
-    }
76
-
77
-    /**
78
-     * Determine whether or not the the offset is valid, i.e the entity corresponding to the
79
-     * offset exists. Offset is equivalent to entity ID. So this function is equivalent to
80
-     * checking if the entity with the given ID exists.
81
-     *
82
-     * @access public
83
-     *
84
-     * @param int $offset The ID of the node used for the cursor offset
85
-     *
86
-     * @return bool
87
-     */
88
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
89
-    public function is_valid_offset($offset)
90
-    {
91
-        $entity = $this->get_query()->get_one_by_ID($offset);
21
+	/**
22
+	 * Determine whether the Query should execute. If it's determined that the query should
23
+	 * not be run based on context such as, but not limited to, who the user is, where in the
24
+	 * ResolveTree the Query is, the relation to the node the Query is connected to, etc
25
+	 * Return false to prevent the query from executing.
26
+	 *
27
+	 * @return bool
28
+	 */
29
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
30
+	public function should_execute()
31
+	{
32
+		return $this->should_execute;
33
+	}
34
+
35
+	/**
36
+	 * Set limit the highest value of first and last, with a (filterable) max of 100
37
+	 *
38
+	 * @return array
39
+	 */
40
+	protected function getLimit()
41
+	{
42
+		$first = ! empty($this->args['first']) ? absint($this->args['first']) : null;
43
+		$last  = ! empty($this->args['last']) ? absint($this->args['last']) : null;
44
+
45
+		$limit = min(
46
+			max($first, $last, 100),
47
+			$this->query_amount
48
+		);
49
+		$limit++;
50
+		return $limit;
51
+	}
52
+
53
+	/**
54
+	 * Get_amount_requested
55
+	 *
56
+	 * This checks the $args to determine the amount requested
57
+	 *
58
+	 * @return int|null
59
+	 * @throws \Exception
60
+	 */
61
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
62
+	public function get_amount_requested()
63
+	{
64
+		$amount_requested = parent::get_amount_requested();
65
+
66
+		/**
67
+		 * If both first & last are used in the input args, throw an exception as that won't
68
+		 * work properly
69
+		 */
70
+		if (empty($this->args['first']) && empty($this->args['last']) && $amount_requested === 10) {
71
+			return 100; // default.
72
+		}
73
+
74
+		return $amount_requested;
75
+	}
76
+
77
+	/**
78
+	 * Determine whether or not the the offset is valid, i.e the entity corresponding to the
79
+	 * offset exists. Offset is equivalent to entity ID. So this function is equivalent to
80
+	 * checking if the entity with the given ID exists.
81
+	 *
82
+	 * @access public
83
+	 *
84
+	 * @param int $offset The ID of the node used for the cursor offset
85
+	 *
86
+	 * @return bool
87
+	 */
88
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
89
+	public function is_valid_offset($offset)
90
+	{
91
+		$entity = $this->get_query()->get_one_by_ID($offset);
92 92
         
93
-        return $entity instanceof EE_Base_Class;
94
-    }
95
-
96
-    /**
97
-     * Validates Model.
98
-     *
99
-     * @param array $entity Entity node.
100
-     *
101
-     * @return bool
102
-     */
103
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
104
-    protected function is_valid_model($entity)
105
-    {
106
-        return $entity instanceof EE_Base_Class;
107
-    }
108
-
109
-
110
-    /**
111
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
112
-     * friendly keys.
113
-     *
114
-     * @param array  $query_args
115
-     * @param array  $where_params
116
-     * @param string $primary_key
117
-     * @return array
118
-     */
119
-    protected function mapOrderbyInputArgs(array $query_args, array $where_params, $primary_key)
120
-    {
121
-        // ID of the current offset
122
-        $offset = $this->get_offset();
123
-        /**
124
-         * Map the orderby inputArgs to the WP_Query
125
-         */
126
-        if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) {
127
-            $query_args['order_by'] = [];
128
-            foreach ($this->args['where']['orderby'] as $orderby_input) {
129
-                $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order'];
130
-            }
131
-        } elseif ($offset) {
132
-            $compare                      = $this->args['last'] ? '<' : '>';
133
-            $where_params[ $primary_key ] = [ $compare, $offset ];
134
-        }
135
-        return [ $query_args, $where_params ];
136
-    }
137
-
138
-
139
-    /**
140
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
141
-     * friendly keys.
142
-     *
143
-     * @param array $where_args
144
-     * @param array $arg_mapping
145
-     * @param array $id_fields   The fields to convert from global IDs to DB IDs.
146
-     * @return array
147
-     */
148
-    protected function sanitizeWhereArgsForInputFields(
149
-        array $where_args,
150
-        array $arg_mapping,
151
-        array $id_fields
152
-    ) {
153
-        $query_args = [];
154
-
155
-        foreach ($where_args as $arg => $value) {
156
-            if (! array_key_exists($arg, $arg_mapping)) {
157
-                continue;
158
-            }
159
-
160
-            if (is_array($value) && ! empty($value)) {
161
-                $value = array_map(
162
-                    static function ($value) {
163
-                        if (is_string($value)) {
164
-                            $value = sanitize_text_field($value);
165
-                        }
166
-                        return $value;
167
-                    },
168
-                    $value
169
-                );
170
-            } elseif (is_string($value)) {
171
-                $value = sanitize_text_field($value);
172
-            }
173
-            $query_args[ $arg_mapping[ $arg ] ] = in_array($arg, $id_fields, true)
174
-                ? $this->convertGlobalId($value)
175
-                : $value;
176
-        }
177
-
178
-        /**
179
-         * Return the Query Args
180
-         */
181
-        return ! empty($query_args) && is_array($query_args) ? $query_args : [];
182
-    }
183
-
184
-
185
-    /**
186
-     * Converts global ID to DB ID.
187
-     *
188
-     * @param string|string[] $ID
189
-     * @return mixed
190
-     */
191
-    protected function convertGlobalId($ID)
192
-    {
193
-        if (is_array($ID)) {
194
-            return array_map([ $this, 'convertGlobalId' ], $ID);
195
-        }
196
-        $parts = Relay::fromGlobalId($ID);
197
-        return ! empty($parts['id']) ? $parts['id'] : null;
198
-    }
93
+		return $entity instanceof EE_Base_Class;
94
+	}
95
+
96
+	/**
97
+	 * Validates Model.
98
+	 *
99
+	 * @param array $entity Entity node.
100
+	 *
101
+	 * @return bool
102
+	 */
103
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
104
+	protected function is_valid_model($entity)
105
+	{
106
+		return $entity instanceof EE_Base_Class;
107
+	}
108
+
109
+
110
+	/**
111
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
112
+	 * friendly keys.
113
+	 *
114
+	 * @param array  $query_args
115
+	 * @param array  $where_params
116
+	 * @param string $primary_key
117
+	 * @return array
118
+	 */
119
+	protected function mapOrderbyInputArgs(array $query_args, array $where_params, $primary_key)
120
+	{
121
+		// ID of the current offset
122
+		$offset = $this->get_offset();
123
+		/**
124
+		 * Map the orderby inputArgs to the WP_Query
125
+		 */
126
+		if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) {
127
+			$query_args['order_by'] = [];
128
+			foreach ($this->args['where']['orderby'] as $orderby_input) {
129
+				$query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order'];
130
+			}
131
+		} elseif ($offset) {
132
+			$compare                      = $this->args['last'] ? '<' : '>';
133
+			$where_params[ $primary_key ] = [ $compare, $offset ];
134
+		}
135
+		return [ $query_args, $where_params ];
136
+	}
137
+
138
+
139
+	/**
140
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
141
+	 * friendly keys.
142
+	 *
143
+	 * @param array $where_args
144
+	 * @param array $arg_mapping
145
+	 * @param array $id_fields   The fields to convert from global IDs to DB IDs.
146
+	 * @return array
147
+	 */
148
+	protected function sanitizeWhereArgsForInputFields(
149
+		array $where_args,
150
+		array $arg_mapping,
151
+		array $id_fields
152
+	) {
153
+		$query_args = [];
154
+
155
+		foreach ($where_args as $arg => $value) {
156
+			if (! array_key_exists($arg, $arg_mapping)) {
157
+				continue;
158
+			}
159
+
160
+			if (is_array($value) && ! empty($value)) {
161
+				$value = array_map(
162
+					static function ($value) {
163
+						if (is_string($value)) {
164
+							$value = sanitize_text_field($value);
165
+						}
166
+						return $value;
167
+					},
168
+					$value
169
+				);
170
+			} elseif (is_string($value)) {
171
+				$value = sanitize_text_field($value);
172
+			}
173
+			$query_args[ $arg_mapping[ $arg ] ] = in_array($arg, $id_fields, true)
174
+				? $this->convertGlobalId($value)
175
+				: $value;
176
+		}
177
+
178
+		/**
179
+		 * Return the Query Args
180
+		 */
181
+		return ! empty($query_args) && is_array($query_args) ? $query_args : [];
182
+	}
183
+
184
+
185
+	/**
186
+	 * Converts global ID to DB ID.
187
+	 *
188
+	 * @param string|string[] $ID
189
+	 * @return mixed
190
+	 */
191
+	protected function convertGlobalId($ID)
192
+	{
193
+		if (is_array($ID)) {
194
+			return array_map([ $this, 'convertGlobalId' ], $ID);
195
+		}
196
+		$parts = Relay::fromGlobalId($ID);
197
+		return ! empty($parts['id']) ? $parts['id'] : null;
198
+	}
199 199
 }
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/TicketConnectionResolver.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -15,122 +15,122 @@
 block discarded – undo
15 15
  */
16 16
 class TicketConnectionResolver extends AbstractConnectionResolver
17 17
 {
18
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
19
-    public function get_loader_name()
20
-    {
21
-        return 'espresso_ticket';
22
-    }
23
-
24
-    /**
25
-     * @return EEM_Ticket
26
-     * @throws EE_Error
27
-     * @throws InvalidArgumentException
28
-     * @throws InvalidDataTypeException
29
-     * @throws InvalidInterfaceException
30
-     */
31
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
32
-    public function get_query()
33
-    {
34
-        return EEM_Ticket::instance();
35
-    }
36
-
37
-
38
-    /**
39
-     * Return an array of item IDs from the query
40
-     *
41
-     * @return array
42
-     */
43
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
44
-    public function get_ids()
45
-    {
46
-        $results = $this->query->get_col($this->query_args);
47
-
48
-        return ! empty($results) ? $results : [];
49
-    }
50
-
51
-
52
-    /**
53
-     * Here, we map the args from the input, then we make sure that we're only querying
54
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
55
-     * handle batch resolution of the posts.
56
-     *
57
-     * @return array
58
-     * @throws EE_Error
59
-     * @throws InvalidArgumentException
60
-     * @throws ReflectionException
61
-     * @throws InvalidDataTypeException
62
-     * @throws InvalidInterfaceException
63
-     */
64
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
65
-    public function get_query_args()
66
-    {
67
-        $where_params = ['TKT_deleted' => ['IN', [true, false]]];
68
-        $query_args   = [];
69
-
70
-        $query_args['limit'] = $this->getLimit();
71
-
72
-        // Avoid multiple entries by join.
73
-        $query_args['group_by'] = 'TKT_ID';
74
-
75
-        $query_args['default_where_conditions'] = 'minimum';
76
-
77
-        /**
78
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
79
-         */
80
-        $input_fields = [];
81
-        if (! empty($this->args['where'])) {
82
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
83
-
84
-            // Use the proper operator.
85
-            if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) {
86
-                $input_fields['Datetime.DTT_ID'] = ['in', $input_fields['Datetime.DTT_ID']];
87
-            }
88
-        }
89
-
90
-        /**
91
-         * Determine where we're at in the Graph and adjust the query context appropriately.
92
-         */
93
-        if ($this->source instanceof EE_Datetime) {
94
-            $where_params['Datetime.DTT_ID'] = $this->source->ID();
95
-        }
96
-
97
-        /**
98
-         * Merge the input_fields with the default query_args
99
-         */
100
-        if (! empty($input_fields)) {
101
-            $where_params = array_merge($where_params, $input_fields);
102
-        }
103
-
104
-        list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'TKT_ID');
105
-
106
-        $query_args[] = $where_params;
107
-
108
-        /**
109
-         * Return the $query_args
110
-         */
111
-        return $query_args;
112
-    }
113
-
114
-
115
-    /**
116
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
117
-     * friendly keys.
118
-     *
119
-     * @param array $where_args
120
-     * @return array
121
-     */
122
-    public function sanitizeInputFields(array $where_args)
123
-    {
124
-        $arg_mapping = [
125
-            'datetime'     => 'Datetime.DTT_ID',
126
-            'datetimeIn'   => 'Datetime.DTT_ID',
127
-            'datetimeIdIn' => 'Datetime.DTT_ID',
128
-            'datetimeId'   => 'Datetime.DTT_ID', // priority.
129
-        ];
130
-        return $this->sanitizeWhereArgsForInputFields(
131
-            $where_args,
132
-            $arg_mapping,
133
-            ['datetime', 'datetimeIn']
134
-        );
135
-    }
18
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
19
+	public function get_loader_name()
20
+	{
21
+		return 'espresso_ticket';
22
+	}
23
+
24
+	/**
25
+	 * @return EEM_Ticket
26
+	 * @throws EE_Error
27
+	 * @throws InvalidArgumentException
28
+	 * @throws InvalidDataTypeException
29
+	 * @throws InvalidInterfaceException
30
+	 */
31
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
32
+	public function get_query()
33
+	{
34
+		return EEM_Ticket::instance();
35
+	}
36
+
37
+
38
+	/**
39
+	 * Return an array of item IDs from the query
40
+	 *
41
+	 * @return array
42
+	 */
43
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
44
+	public function get_ids()
45
+	{
46
+		$results = $this->query->get_col($this->query_args);
47
+
48
+		return ! empty($results) ? $results : [];
49
+	}
50
+
51
+
52
+	/**
53
+	 * Here, we map the args from the input, then we make sure that we're only querying
54
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
55
+	 * handle batch resolution of the posts.
56
+	 *
57
+	 * @return array
58
+	 * @throws EE_Error
59
+	 * @throws InvalidArgumentException
60
+	 * @throws ReflectionException
61
+	 * @throws InvalidDataTypeException
62
+	 * @throws InvalidInterfaceException
63
+	 */
64
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
65
+	public function get_query_args()
66
+	{
67
+		$where_params = ['TKT_deleted' => ['IN', [true, false]]];
68
+		$query_args   = [];
69
+
70
+		$query_args['limit'] = $this->getLimit();
71
+
72
+		// Avoid multiple entries by join.
73
+		$query_args['group_by'] = 'TKT_ID';
74
+
75
+		$query_args['default_where_conditions'] = 'minimum';
76
+
77
+		/**
78
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
79
+		 */
80
+		$input_fields = [];
81
+		if (! empty($this->args['where'])) {
82
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
83
+
84
+			// Use the proper operator.
85
+			if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) {
86
+				$input_fields['Datetime.DTT_ID'] = ['in', $input_fields['Datetime.DTT_ID']];
87
+			}
88
+		}
89
+
90
+		/**
91
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
92
+		 */
93
+		if ($this->source instanceof EE_Datetime) {
94
+			$where_params['Datetime.DTT_ID'] = $this->source->ID();
95
+		}
96
+
97
+		/**
98
+		 * Merge the input_fields with the default query_args
99
+		 */
100
+		if (! empty($input_fields)) {
101
+			$where_params = array_merge($where_params, $input_fields);
102
+		}
103
+
104
+		list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'TKT_ID');
105
+
106
+		$query_args[] = $where_params;
107
+
108
+		/**
109
+		 * Return the $query_args
110
+		 */
111
+		return $query_args;
112
+	}
113
+
114
+
115
+	/**
116
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
117
+	 * friendly keys.
118
+	 *
119
+	 * @param array $where_args
120
+	 * @return array
121
+	 */
122
+	public function sanitizeInputFields(array $where_args)
123
+	{
124
+		$arg_mapping = [
125
+			'datetime'     => 'Datetime.DTT_ID',
126
+			'datetimeIn'   => 'Datetime.DTT_ID',
127
+			'datetimeIdIn' => 'Datetime.DTT_ID',
128
+			'datetimeId'   => 'Datetime.DTT_ID', // priority.
129
+		];
130
+		return $this->sanitizeWhereArgsForInputFields(
131
+			$where_args,
132
+			$arg_mapping,
133
+			['datetime', 'datetimeIn']
134
+		);
135
+	}
136 136
 }
Please login to merge, or discard this patch.