Completed
Branch EDTR/master (5278ab)
by
unknown
22:28 queued 11:14
created
domain/services/graphql/connection_resolvers/DatetimeConnectionResolver.php 1 patch
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -18,188 +18,188 @@
 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
-        $query_args['default_where_conditions'] = 'minimum';
95
-
96
-        /**
97
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
98
-         */
99
-        $input_fields = [];
100
-        if (! empty($this->args['where'])) {
101
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
102
-
103
-            // Use the proper operator.
104
-            if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) {
105
-                $input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']];
106
-            }
107
-            if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
108
-                $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
109
-            }
110
-        }
111
-
112
-        /**
113
-         * Determine where we're at in the Graph and adjust the query context appropriately.
114
-         *
115
-         * For example, if we're querying for datetime as a field of event query, this will automatically
116
-         * set the query to pull datetimes that belong to that event.
117
-         * We can set more cases for other source types.
118
-         */
119
-        if (is_object($this->source)) {
120
-            switch (true) {
121
-                // It's surely an event
122
-                case $this->source instanceof Post:
123
-                    $where_params['EVT_ID'] = $this->source->ID;
124
-                    break;
125
-                case $this->source instanceof EE_Event:
126
-                    $where_params['EVT_ID'] = $this->source->ID();
127
-                    break;
128
-                case $this->source instanceof EE_Ticket:
129
-                    $where_params['Ticket.TKT_ID'] = $this->source->ID();
130
-                    break;
131
-                case $this->source instanceof EE_Checkin:
132
-                    $where_params['Checkin.CHK_ID'] = $this->source->ID();
133
-                    break;
134
-            }
135
-        }
136
-
137
-        /**
138
-         * Merge the input_fields with the default query_args
139
-         */
140
-        if (! empty($input_fields)) {
141
-            $where_params = array_merge($where_params, $input_fields);
142
-        }
143
-
144
-        list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID');
145
-
146
-        if (! empty($this->args['where']['upcoming'])) {
147
-            $where_params['DTT_EVT_start'] = array(
148
-                '>',
149
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
150
-            );
151
-        }
152
-
153
-        if (! empty($this->args['where']['active'])) {
154
-            $where_params['DTT_EVT_start'] = array(
155
-                '<',
156
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
157
-            );
158
-            $where_params['DTT_EVT_end'] = array(
159
-                '>',
160
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
161
-            );
162
-        }
163
-
164
-        if (! empty($this->args['where']['expired'])) {
165
-            $where_params['DTT_EVT_end'] = array(
166
-                '<',
167
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
168
-            );
169
-        }
170
-
171
-        $query_args[] = $where_params;
172
-
173
-        /**
174
-         * Return the $query_args
175
-         */
176
-        return $query_args;
177
-    }
178
-
179
-
180
-    /**
181
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
182
-     * friendly keys.
183
-     *
184
-     * @param array $where_args
185
-     * @return array
186
-     */
187
-    public function sanitizeInputFields(array $where_args)
188
-    {
189
-        $arg_mapping = [
190
-            'event'      => 'EVT_ID',
191
-            'eventIn'    => 'EVT_ID',
192
-            'eventId'    => 'EVT_ID',
193
-            'eventIdIn'  => 'EVT_ID',
194
-            'ticket'     => 'Ticket.TKT_ID',
195
-            'ticketIn'   => 'Ticket.TKT_ID',
196
-            'ticketId'   => 'Ticket.TKT_ID',
197
-            'ticketIdIn' => 'Ticket.TKT_ID',
198
-        ];
199
-        return $this->sanitizeWhereArgsForInputFields(
200
-            $where_args,
201
-            $arg_mapping,
202
-            ['event', 'eventIn', 'ticket', 'ticketIn']
203
-        );
204
-    }
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
+		$query_args['default_where_conditions'] = 'minimum';
95
+
96
+		/**
97
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
98
+		 */
99
+		$input_fields = [];
100
+		if (! empty($this->args['where'])) {
101
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
102
+
103
+			// Use the proper operator.
104
+			if (! empty($input_fields['EVT_ID']) && is_array($input_fields['EVT_ID'])) {
105
+				$input_fields['EVT_ID'] = ['in', $input_fields['EVT_ID']];
106
+			}
107
+			if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
108
+				$input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
109
+			}
110
+		}
111
+
112
+		/**
113
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
114
+		 *
115
+		 * For example, if we're querying for datetime as a field of event query, this will automatically
116
+		 * set the query to pull datetimes that belong to that event.
117
+		 * We can set more cases for other source types.
118
+		 */
119
+		if (is_object($this->source)) {
120
+			switch (true) {
121
+				// It's surely an event
122
+				case $this->source instanceof Post:
123
+					$where_params['EVT_ID'] = $this->source->ID;
124
+					break;
125
+				case $this->source instanceof EE_Event:
126
+					$where_params['EVT_ID'] = $this->source->ID();
127
+					break;
128
+				case $this->source instanceof EE_Ticket:
129
+					$where_params['Ticket.TKT_ID'] = $this->source->ID();
130
+					break;
131
+				case $this->source instanceof EE_Checkin:
132
+					$where_params['Checkin.CHK_ID'] = $this->source->ID();
133
+					break;
134
+			}
135
+		}
136
+
137
+		/**
138
+		 * Merge the input_fields with the default query_args
139
+		 */
140
+		if (! empty($input_fields)) {
141
+			$where_params = array_merge($where_params, $input_fields);
142
+		}
143
+
144
+		list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'DTT_ID');
145
+
146
+		if (! empty($this->args['where']['upcoming'])) {
147
+			$where_params['DTT_EVT_start'] = array(
148
+				'>',
149
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
150
+			);
151
+		}
152
+
153
+		if (! empty($this->args['where']['active'])) {
154
+			$where_params['DTT_EVT_start'] = array(
155
+				'<',
156
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start')
157
+			);
158
+			$where_params['DTT_EVT_end'] = array(
159
+				'>',
160
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
161
+			);
162
+		}
163
+
164
+		if (! empty($this->args['where']['expired'])) {
165
+			$where_params['DTT_EVT_end'] = array(
166
+				'<',
167
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')
168
+			);
169
+		}
170
+
171
+		$query_args[] = $where_params;
172
+
173
+		/**
174
+		 * Return the $query_args
175
+		 */
176
+		return $query_args;
177
+	}
178
+
179
+
180
+	/**
181
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
182
+	 * friendly keys.
183
+	 *
184
+	 * @param array $where_args
185
+	 * @return array
186
+	 */
187
+	public function sanitizeInputFields(array $where_args)
188
+	{
189
+		$arg_mapping = [
190
+			'event'      => 'EVT_ID',
191
+			'eventIn'    => 'EVT_ID',
192
+			'eventId'    => 'EVT_ID',
193
+			'eventIdIn'  => 'EVT_ID',
194
+			'ticket'     => 'Ticket.TKT_ID',
195
+			'ticketIn'   => 'Ticket.TKT_ID',
196
+			'ticketId'   => 'Ticket.TKT_ID',
197
+			'ticketIdIn' => 'Ticket.TKT_ID',
198
+		];
199
+		return $this->sanitizeWhereArgsForInputFields(
200
+			$where_args,
201
+			$arg_mapping,
202
+			['event', 'eventIn', 'ticket', 'ticketIn']
203
+		);
204
+	}
205 205
 }
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/PriceConnectionResolver.php 1 patch
Indentation   +149 added lines, -149 removed lines patch added patch discarded remove patch
@@ -15,153 +15,153 @@
 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
-     * Determine whether the Query should execute. If it's determined that the query should
54
-     * not be run based on context such as, but not limited to, who the user is, where in the
55
-     * ResolveTree the Query is, the relation to the node the Query is connected to, etc
56
-     * Return false to prevent the query from executing.
57
-     *
58
-     * @return bool
59
-     */
60
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
61
-    public function should_execute()
62
-    {
63
-        if ($this->should_execute === false) {
64
-            return false;
65
-        }
66
-
67
-        return $this->should_execute;
68
-    }
69
-
70
-
71
-    /**
72
-     * Here, we map the args from the input, then we make sure that we're only querying
73
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
74
-     * handle batch resolution of the posts.
75
-     *
76
-     * @return array
77
-     * @throws EE_Error
78
-     * @throws InvalidArgumentException
79
-     * @throws ReflectionException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
84
-    public function get_query_args()
85
-    {
86
-        $where_params = [];
87
-        $query_args   = [];
88
-
89
-        $query_args['limit'] = $this->getLimit();
90
-
91
-        // Avoid multiple entries by join.
92
-        $query_args['group_by'] = 'PRC_ID';
93
-
94
-        $query_args['default_where_conditions'] = 'minimum';
95
-
96
-        /**
97
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
98
-         */
99
-        $input_fields = [];
100
-        if (! empty($this->args['where'])) {
101
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
102
-
103
-            // Use the proper operator.
104
-            if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
105
-                $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
106
-            }
107
-            if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) {
108
-                $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']];
109
-            }
110
-            if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) {
111
-                $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']];
112
-            }
113
-        }
114
-
115
-        /**
116
-         * Determine where we're at in the Graph and adjust the query context appropriately.
117
-         */
118
-        if ($this->source instanceof EE_Ticket) {
119
-            $where_params['Ticket.TKT_ID'] = $this->source->ID();
120
-        }
121
-
122
-        /**
123
-         * Merge the input_fields with the default query_args
124
-         */
125
-        if (! empty($input_fields)) {
126
-            $where_params = array_merge($where_params, $input_fields);
127
-        }
128
-
129
-        list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID');
130
-
131
-        $query_args[] = $where_params;
132
-
133
-        /**
134
-         * Return the $query_args
135
-         */
136
-        return $query_args;
137
-    }
138
-
139
-
140
-    /**
141
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
142
-     * friendly keys.
143
-     *
144
-     * @param array $where_args
145
-     * @return array
146
-     */
147
-    public function sanitizeInputFields(array $where_args)
148
-    {
149
-        $arg_mapping = [
150
-            'ticket'          => 'Ticket.TKT_ID',
151
-            'ticketIn'        => 'Ticket.TKT_ID',
152
-            'ticketIdIn'      => 'Ticket.TKT_ID',
153
-            'ticketId'        => 'Ticket.TKT_ID', // priority.
154
-            'priceType'       => 'Price_Type.PRT_ID',
155
-            'priceTypeIn'     => 'Price_Type.PRT_ID',
156
-            'priceTypeIdIn'   => 'Price_Type.PRT_ID',
157
-            'priceTypeId'     => 'Price_Type.PRT_ID', // priority.
158
-            'priceBaseType'   => 'Price_Type.PBT_ID',
159
-            'priceBaseTypeIn' => 'Price_Type.PBT_ID',
160
-        ];
161
-        return $this->sanitizeWhereArgsForInputFields(
162
-            $where_args,
163
-            $arg_mapping,
164
-            ['ticket', 'ticketIn', 'priceType', 'priceTypeIn']
165
-        );
166
-    }
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
+	 * Determine whether the Query should execute. If it's determined that the query should
54
+	 * not be run based on context such as, but not limited to, who the user is, where in the
55
+	 * ResolveTree the Query is, the relation to the node the Query is connected to, etc
56
+	 * Return false to prevent the query from executing.
57
+	 *
58
+	 * @return bool
59
+	 */
60
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
61
+	public function should_execute()
62
+	{
63
+		if ($this->should_execute === false) {
64
+			return false;
65
+		}
66
+
67
+		return $this->should_execute;
68
+	}
69
+
70
+
71
+	/**
72
+	 * Here, we map the args from the input, then we make sure that we're only querying
73
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
74
+	 * handle batch resolution of the posts.
75
+	 *
76
+	 * @return array
77
+	 * @throws EE_Error
78
+	 * @throws InvalidArgumentException
79
+	 * @throws ReflectionException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
84
+	public function get_query_args()
85
+	{
86
+		$where_params = [];
87
+		$query_args   = [];
88
+
89
+		$query_args['limit'] = $this->getLimit();
90
+
91
+		// Avoid multiple entries by join.
92
+		$query_args['group_by'] = 'PRC_ID';
93
+
94
+		$query_args['default_where_conditions'] = 'minimum';
95
+
96
+		/**
97
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
98
+		 */
99
+		$input_fields = [];
100
+		if (! empty($this->args['where'])) {
101
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
102
+
103
+			// Use the proper operator.
104
+			if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) {
105
+				$input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']];
106
+			}
107
+			if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) {
108
+				$input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']];
109
+			}
110
+			if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) {
111
+				$input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']];
112
+			}
113
+		}
114
+
115
+		/**
116
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
117
+		 */
118
+		if ($this->source instanceof EE_Ticket) {
119
+			$where_params['Ticket.TKT_ID'] = $this->source->ID();
120
+		}
121
+
122
+		/**
123
+		 * Merge the input_fields with the default query_args
124
+		 */
125
+		if (! empty($input_fields)) {
126
+			$where_params = array_merge($where_params, $input_fields);
127
+		}
128
+
129
+		list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID');
130
+
131
+		$query_args[] = $where_params;
132
+
133
+		/**
134
+		 * Return the $query_args
135
+		 */
136
+		return $query_args;
137
+	}
138
+
139
+
140
+	/**
141
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
142
+	 * friendly keys.
143
+	 *
144
+	 * @param array $where_args
145
+	 * @return array
146
+	 */
147
+	public function sanitizeInputFields(array $where_args)
148
+	{
149
+		$arg_mapping = [
150
+			'ticket'          => 'Ticket.TKT_ID',
151
+			'ticketIn'        => 'Ticket.TKT_ID',
152
+			'ticketIdIn'      => 'Ticket.TKT_ID',
153
+			'ticketId'        => 'Ticket.TKT_ID', // priority.
154
+			'priceType'       => 'Price_Type.PRT_ID',
155
+			'priceTypeIn'     => 'Price_Type.PRT_ID',
156
+			'priceTypeIdIn'   => 'Price_Type.PRT_ID',
157
+			'priceTypeId'     => 'Price_Type.PRT_ID', // priority.
158
+			'priceBaseType'   => 'Price_Type.PBT_ID',
159
+			'priceBaseTypeIn' => 'Price_Type.PBT_ID',
160
+		];
161
+		return $this->sanitizeWhereArgsForInputFields(
162
+			$where_args,
163
+			$arg_mapping,
164
+			['ticket', 'ticketIn', 'priceType', 'priceTypeIn']
165
+		);
166
+	}
167 167
 }
Please login to merge, or discard this patch.
domain/services/graphql/connection_resolvers/TicketConnectionResolver.php 1 patch
Indentation   +137 added lines, -137 removed lines patch added patch discarded remove patch
@@ -15,141 +15,141 @@
 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
-     * Determine whether the Query should execute. If it's determined that the query should
54
-     * not be run based on context such as, but not limited to, who the user is, where in the
55
-     * ResolveTree the Query is, the relation to the node the Query is connected to, etc
56
-     * Return false to prevent the query from executing.
57
-     *
58
-     * @return bool
59
-     */
60
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
61
-    public function should_execute()
62
-    {
63
-        if (false === $this->should_execute) {
64
-            return false;
65
-        }
66
-
67
-        return $this->should_execute;
68
-    }
69
-
70
-
71
-    /**
72
-     * Here, we map the args from the input, then we make sure that we're only querying
73
-     * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
74
-     * handle batch resolution of the posts.
75
-     *
76
-     * @return array
77
-     * @throws EE_Error
78
-     * @throws InvalidArgumentException
79
-     * @throws ReflectionException
80
-     * @throws InvalidDataTypeException
81
-     * @throws InvalidInterfaceException
82
-     */
83
-    // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
84
-    public function get_query_args()
85
-    {
86
-        $where_params = ['TKT_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'] = 'TKT_ID';
93
-
94
-        $query_args['default_where_conditions'] = 'minimum';
95
-
96
-        /**
97
-         * Collect the input_fields and sanitize them to prepare them for sending to the Query
98
-         */
99
-        $input_fields = [];
100
-        if (! empty($this->args['where'])) {
101
-            $input_fields = $this->sanitizeInputFields($this->args['where']);
102
-
103
-            // Use the proper operator.
104
-            if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) {
105
-                $input_fields['Datetime.DTT_ID'] = ['in', $input_fields['Datetime.DTT_ID']];
106
-            }
107
-        }
108
-
109
-        /**
110
-         * Determine where we're at in the Graph and adjust the query context appropriately.
111
-         */
112
-        if ($this->source instanceof EE_Datetime) {
113
-            $where_params['Datetime.DTT_ID'] = $this->source->ID();
114
-        }
115
-
116
-        /**
117
-         * Merge the input_fields with the default query_args
118
-         */
119
-        if (! empty($input_fields)) {
120
-            $where_params = array_merge($where_params, $input_fields);
121
-        }
122
-
123
-        list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'TKT_ID');
124
-
125
-        $query_args[] = $where_params;
126
-
127
-        /**
128
-         * Return the $query_args
129
-         */
130
-        return $query_args;
131
-    }
132
-
133
-
134
-    /**
135
-     * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
136
-     * friendly keys.
137
-     *
138
-     * @param array $where_args
139
-     * @return array
140
-     */
141
-    public function sanitizeInputFields(array $where_args)
142
-    {
143
-        $arg_mapping = [
144
-            'datetime'     => 'Datetime.DTT_ID',
145
-            'datetimeIn'   => 'Datetime.DTT_ID',
146
-            'datetimeIdIn' => 'Datetime.DTT_ID',
147
-            'datetimeId'   => 'Datetime.DTT_ID', // priority.
148
-        ];
149
-        return $this->sanitizeWhereArgsForInputFields(
150
-            $where_args,
151
-            $arg_mapping,
152
-            ['datetime', 'datetimeIn']
153
-        );
154
-    }
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
+	 * Determine whether the Query should execute. If it's determined that the query should
54
+	 * not be run based on context such as, but not limited to, who the user is, where in the
55
+	 * ResolveTree the Query is, the relation to the node the Query is connected to, etc
56
+	 * Return false to prevent the query from executing.
57
+	 *
58
+	 * @return bool
59
+	 */
60
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
61
+	public function should_execute()
62
+	{
63
+		if (false === $this->should_execute) {
64
+			return false;
65
+		}
66
+
67
+		return $this->should_execute;
68
+	}
69
+
70
+
71
+	/**
72
+	 * Here, we map the args from the input, then we make sure that we're only querying
73
+	 * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers
74
+	 * handle batch resolution of the posts.
75
+	 *
76
+	 * @return array
77
+	 * @throws EE_Error
78
+	 * @throws InvalidArgumentException
79
+	 * @throws ReflectionException
80
+	 * @throws InvalidDataTypeException
81
+	 * @throws InvalidInterfaceException
82
+	 */
83
+	// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
84
+	public function get_query_args()
85
+	{
86
+		$where_params = ['TKT_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'] = 'TKT_ID';
93
+
94
+		$query_args['default_where_conditions'] = 'minimum';
95
+
96
+		/**
97
+		 * Collect the input_fields and sanitize them to prepare them for sending to the Query
98
+		 */
99
+		$input_fields = [];
100
+		if (! empty($this->args['where'])) {
101
+			$input_fields = $this->sanitizeInputFields($this->args['where']);
102
+
103
+			// Use the proper operator.
104
+			if (! empty($input_fields['Datetime.DTT_ID']) && is_array($input_fields['Datetime.DTT_ID'])) {
105
+				$input_fields['Datetime.DTT_ID'] = ['in', $input_fields['Datetime.DTT_ID']];
106
+			}
107
+		}
108
+
109
+		/**
110
+		 * Determine where we're at in the Graph and adjust the query context appropriately.
111
+		 */
112
+		if ($this->source instanceof EE_Datetime) {
113
+			$where_params['Datetime.DTT_ID'] = $this->source->ID();
114
+		}
115
+
116
+		/**
117
+		 * Merge the input_fields with the default query_args
118
+		 */
119
+		if (! empty($input_fields)) {
120
+			$where_params = array_merge($where_params, $input_fields);
121
+		}
122
+
123
+		list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'TKT_ID');
124
+
125
+		$query_args[] = $where_params;
126
+
127
+		/**
128
+		 * Return the $query_args
129
+		 */
130
+		return $query_args;
131
+	}
132
+
133
+
134
+	/**
135
+	 * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model
136
+	 * friendly keys.
137
+	 *
138
+	 * @param array $where_args
139
+	 * @return array
140
+	 */
141
+	public function sanitizeInputFields(array $where_args)
142
+	{
143
+		$arg_mapping = [
144
+			'datetime'     => 'Datetime.DTT_ID',
145
+			'datetimeIn'   => 'Datetime.DTT_ID',
146
+			'datetimeIdIn' => 'Datetime.DTT_ID',
147
+			'datetimeId'   => 'Datetime.DTT_ID', // priority.
148
+		];
149
+		return $this->sanitizeWhereArgsForInputFields(
150
+			$where_args,
151
+			$arg_mapping,
152
+			['datetime', 'datetimeIn']
153
+		);
154
+	}
155 155
 }
Please login to merge, or discard this patch.
core/domain/services/admin/events/editor/AdvancedEditorData.php 1 patch
Indentation   +503 added lines, -503 removed lines patch added patch discarded remove patch
@@ -35,217 +35,217 @@  discard block
 block discarded – undo
35 35
 class AdvancedEditorData
36 36
 {
37 37
 
38
-    /**
39
-     * @var string $namespace The graphql namespace/prefix.
40
-     */
41
-    protected $namespace = 'Espresso';
42
-
43
-    /**
44
-     * @var EE_Event
45
-     */
46
-    protected $event;
47
-
48
-    /**
49
-     * @var EE_Admin_Config
50
-     */
51
-    protected $admin_config;
52
-    /**
53
-     * @var EEM_Datetime $datetime_model
54
-     */
55
-    protected $datetime_model;
56
-    /**
57
-     * @var EEM_Price $price_model
58
-     */
59
-    protected $price_model;
60
-    /**
61
-     * @var EEM_Ticket $ticket_model
62
-     */
63
-    protected $ticket_model;
64
-
65
-
66
-    /**
67
-     * AdvancedEditorAdminForm constructor.
68
-     *
69
-     * @param EE_Event        $event
70
-     * @param EE_Admin_Config $admin_config
71
-     * @param EEM_Datetime    $datetime_model
72
-     * @param EEM_Price       $price_model
73
-     * @param EEM_Ticket      $ticket_model
74
-     */
75
-    public function __construct(
76
-        EE_Event $event,
77
-        EE_Admin_Config $admin_config,
78
-        EEM_Datetime $datetime_model,
79
-        EEM_Price $price_model,
80
-        EEM_Ticket $ticket_model
81
-    ) {
82
-        $this->event = $event;
83
-        $this->admin_config = $admin_config;
84
-        $this->datetime_model = $datetime_model;
85
-        $this->price_model = $price_model;
86
-        $this->ticket_model = $ticket_model;
87
-        add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']);
88
-    }
89
-
90
-
91
-    /**
92
-     * @throws EE_Error
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidDataTypeException
95
-     * @throws InvalidInterfaceException
96
-     * @throws ModelConfigurationException
97
-     * @throws ReflectionException
98
-     * @throws UnexpectedEntityException
99
-     * @throws DomainException
100
-     * @since $VID:$
101
-     */
102
-    public function loadScriptsStyles()
103
-    {
104
-        if ($this->admin_config->useAdvancedEditor()) {
105
-            $eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0;
106
-            if (! $eventId) {
107
-                global $post;
108
-                $eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
109
-                $eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events'
110
-                    ? $post->ID
111
-                    : $eventId;
112
-            }
113
-            if ($eventId) {
114
-                $data = $this->getEditorData($eventId);
115
-                $data = wp_json_encode($data);
116
-                add_action(
117
-                    'admin_footer',
118
-                    static function () use ($data) {
119
-                        wp_add_inline_script(
120
-                            EspressoEditorAssetManager::JS_HANDLE_EDITOR,
121
-                            "
38
+	/**
39
+	 * @var string $namespace The graphql namespace/prefix.
40
+	 */
41
+	protected $namespace = 'Espresso';
42
+
43
+	/**
44
+	 * @var EE_Event
45
+	 */
46
+	protected $event;
47
+
48
+	/**
49
+	 * @var EE_Admin_Config
50
+	 */
51
+	protected $admin_config;
52
+	/**
53
+	 * @var EEM_Datetime $datetime_model
54
+	 */
55
+	protected $datetime_model;
56
+	/**
57
+	 * @var EEM_Price $price_model
58
+	 */
59
+	protected $price_model;
60
+	/**
61
+	 * @var EEM_Ticket $ticket_model
62
+	 */
63
+	protected $ticket_model;
64
+
65
+
66
+	/**
67
+	 * AdvancedEditorAdminForm constructor.
68
+	 *
69
+	 * @param EE_Event        $event
70
+	 * @param EE_Admin_Config $admin_config
71
+	 * @param EEM_Datetime    $datetime_model
72
+	 * @param EEM_Price       $price_model
73
+	 * @param EEM_Ticket      $ticket_model
74
+	 */
75
+	public function __construct(
76
+		EE_Event $event,
77
+		EE_Admin_Config $admin_config,
78
+		EEM_Datetime $datetime_model,
79
+		EEM_Price $price_model,
80
+		EEM_Ticket $ticket_model
81
+	) {
82
+		$this->event = $event;
83
+		$this->admin_config = $admin_config;
84
+		$this->datetime_model = $datetime_model;
85
+		$this->price_model = $price_model;
86
+		$this->ticket_model = $ticket_model;
87
+		add_action('admin_enqueue_scripts', [$this, 'loadScriptsStyles']);
88
+	}
89
+
90
+
91
+	/**
92
+	 * @throws EE_Error
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidDataTypeException
95
+	 * @throws InvalidInterfaceException
96
+	 * @throws ModelConfigurationException
97
+	 * @throws ReflectionException
98
+	 * @throws UnexpectedEntityException
99
+	 * @throws DomainException
100
+	 * @since $VID:$
101
+	 */
102
+	public function loadScriptsStyles()
103
+	{
104
+		if ($this->admin_config->useAdvancedEditor()) {
105
+			$eventId = $this->event instanceof EE_Event ? $this->event->ID() : 0;
106
+			if (! $eventId) {
107
+				global $post;
108
+				$eventId = isset($_REQUEST['post']) ? absint($_REQUEST['post']) : 0;
109
+				$eventId = $eventId === 0 && $post instanceof WP_Post && $post->post_type === 'espresso_events'
110
+					? $post->ID
111
+					: $eventId;
112
+			}
113
+			if ($eventId) {
114
+				$data = $this->getEditorData($eventId);
115
+				$data = wp_json_encode($data);
116
+				add_action(
117
+					'admin_footer',
118
+					static function () use ($data) {
119
+						wp_add_inline_script(
120
+							EspressoEditorAssetManager::JS_HANDLE_EDITOR,
121
+							"
122 122
 var eeEditorData={$data};
123 123
 ",
124
-                            'before'
125
-                        );
126
-                    }
127
-                );
128
-            }
129
-        }
130
-    }
131
-
132
-
133
-    /**
134
-     * @param int $eventId
135
-     * @return array
136
-     * @throws EE_Error
137
-     * @throws InvalidDataTypeException
138
-     * @throws InvalidInterfaceException
139
-     * @throws ModelConfigurationException
140
-     * @throws UnexpectedEntityException
141
-     * @throws InvalidArgumentException
142
-     * @throws ReflectionException
143
-     * @throws DomainException
144
-     * @since $VID:$
145
-     */
146
-    protected function getEditorData($eventId)
147
-    {
148
-        $event = $this->getEventGraphQLData($eventId);
149
-        $event['dbId'] = $eventId;
150
-
151
-        $graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
152
-        $graphqlEndpoint = esc_url($graphqlEndpoint);
153
-
154
-        $currentUser = $this->getGraphQLCurrentUser();
155
-
156
-        $generalSettings = $this->getGraphQLGeneralSettings();
157
-
158
-        $i18n = self::getJedLocaleData('event_espresso');
159
-
160
-        $assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/';
161
-
162
-        return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl');
163
-    }
164
-
165
-
166
-    /**
167
-     * @param int $eventId
168
-     * @return array
169
-     * @since $VID:$
170
-     */
171
-    protected function getEventGraphQLData($eventId)
172
-    {
173
-        $datetimes = $this->getGraphQLDatetimes($eventId);
174
-
175
-        // Avoid undefined variable warning in PHP >= 7.3
176
-        $tickets = null;
177
-        $prices  = null;
178
-
179
-        if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
180
-            $this->addDefaultEntities($eventId);
181
-            $datetimes = $this->getGraphQLDatetimes($eventId);
182
-        }
183
-
184
-        if (! empty($datetimes['nodes'])) {
185
-            $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
186
-
187
-            if (! empty($datetimeIn)) {
188
-                $tickets = $this->getGraphQLTickets($datetimeIn);
189
-            }
190
-        }
191
-
192
-        if (! empty($tickets['nodes'])) {
193
-            $ticketIn = wp_list_pluck($tickets['nodes'], 'id');
194
-
195
-            if (! empty($ticketIn)) {
196
-                $prices = $this->getGraphQLPrices($ticketIn);
197
-            }
198
-        }
199
-
200
-        $priceTypes = $this->getGraphQLPriceTypes();
201
-
202
-        $relations = $this->getRelationalData($eventId);
203
-
204
-        return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
205
-    }
206
-
207
-    /**
208
-     * @param int $eventId
209
-     * @throws DomainException
210
-     * @throws EE_Error
211
-     * @throws InvalidArgumentException
212
-     * @throws InvalidDataTypeException
213
-     * @throws InvalidInterfaceException
214
-     * @throws ModelConfigurationException
215
-     * @throws ReflectionException
216
-     * @throws UnexpectedEntityException
217
-     * @since $VID:$
218
-     */
219
-    protected function addDefaultEntities($eventId)
220
-    {
221
-        $default_dates = $this->datetime_model->create_new_blank_datetime();
222
-        if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) {
223
-            $default_date = $default_dates[0];
224
-            $default_date->save();
225
-            $default_date->_add_relation_to($eventId, 'Event');
226
-            $default_tickets = $this->ticket_model->get_all_default_tickets();
227
-            $default_prices = $this->price_model->get_all_default_prices();
228
-            foreach ($default_tickets as $default_ticket) {
229
-                $default_ticket->save();
230
-                $default_ticket->_add_relation_to($default_date, 'Datetime');
231
-                foreach ($default_prices as $default_price) {
232
-                    $default_price->save();
233
-                    $default_price->_add_relation_to($default_ticket, 'Ticket');
234
-                }
235
-            }
236
-        }
237
-    }
238
-
239
-
240
-    /**
241
-     * @param int $eventId
242
-     * @return array|null
243
-     * @since $VID:$
244
-     */
245
-    protected function getGraphQLDatetimes($eventId)
246
-    {
247
-        $field_key = lcfirst($this->namespace) . 'Datetimes';
248
-        $query = <<<QUERY
124
+							'before'
125
+						);
126
+					}
127
+				);
128
+			}
129
+		}
130
+	}
131
+
132
+
133
+	/**
134
+	 * @param int $eventId
135
+	 * @return array
136
+	 * @throws EE_Error
137
+	 * @throws InvalidDataTypeException
138
+	 * @throws InvalidInterfaceException
139
+	 * @throws ModelConfigurationException
140
+	 * @throws UnexpectedEntityException
141
+	 * @throws InvalidArgumentException
142
+	 * @throws ReflectionException
143
+	 * @throws DomainException
144
+	 * @since $VID:$
145
+	 */
146
+	protected function getEditorData($eventId)
147
+	{
148
+		$event = $this->getEventGraphQLData($eventId);
149
+		$event['dbId'] = $eventId;
150
+
151
+		$graphqlEndpoint = class_exists('WPGraphQL') ? trailingslashit(site_url()) . Router::$route : '';
152
+		$graphqlEndpoint = esc_url($graphqlEndpoint);
153
+
154
+		$currentUser = $this->getGraphQLCurrentUser();
155
+
156
+		$generalSettings = $this->getGraphQLGeneralSettings();
157
+
158
+		$i18n = self::getJedLocaleData('event_espresso');
159
+
160
+		$assetsUrl = EE_PLUGIN_DIR_URL . 'assets/dist/';
161
+
162
+		return compact('event', 'graphqlEndpoint', 'currentUser', 'generalSettings', 'i18n', 'assetsUrl');
163
+	}
164
+
165
+
166
+	/**
167
+	 * @param int $eventId
168
+	 * @return array
169
+	 * @since $VID:$
170
+	 */
171
+	protected function getEventGraphQLData($eventId)
172
+	{
173
+		$datetimes = $this->getGraphQLDatetimes($eventId);
174
+
175
+		// Avoid undefined variable warning in PHP >= 7.3
176
+		$tickets = null;
177
+		$prices  = null;
178
+
179
+		if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) {
180
+			$this->addDefaultEntities($eventId);
181
+			$datetimes = $this->getGraphQLDatetimes($eventId);
182
+		}
183
+
184
+		if (! empty($datetimes['nodes'])) {
185
+			$datetimeIn = wp_list_pluck($datetimes['nodes'], 'id');
186
+
187
+			if (! empty($datetimeIn)) {
188
+				$tickets = $this->getGraphQLTickets($datetimeIn);
189
+			}
190
+		}
191
+
192
+		if (! empty($tickets['nodes'])) {
193
+			$ticketIn = wp_list_pluck($tickets['nodes'], 'id');
194
+
195
+			if (! empty($ticketIn)) {
196
+				$prices = $this->getGraphQLPrices($ticketIn);
197
+			}
198
+		}
199
+
200
+		$priceTypes = $this->getGraphQLPriceTypes();
201
+
202
+		$relations = $this->getRelationalData($eventId);
203
+
204
+		return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations');
205
+	}
206
+
207
+	/**
208
+	 * @param int $eventId
209
+	 * @throws DomainException
210
+	 * @throws EE_Error
211
+	 * @throws InvalidArgumentException
212
+	 * @throws InvalidDataTypeException
213
+	 * @throws InvalidInterfaceException
214
+	 * @throws ModelConfigurationException
215
+	 * @throws ReflectionException
216
+	 * @throws UnexpectedEntityException
217
+	 * @since $VID:$
218
+	 */
219
+	protected function addDefaultEntities($eventId)
220
+	{
221
+		$default_dates = $this->datetime_model->create_new_blank_datetime();
222
+		if (is_array($default_dates) && isset($default_dates[0]) && $default_dates[0] instanceof EE_Datetime) {
223
+			$default_date = $default_dates[0];
224
+			$default_date->save();
225
+			$default_date->_add_relation_to($eventId, 'Event');
226
+			$default_tickets = $this->ticket_model->get_all_default_tickets();
227
+			$default_prices = $this->price_model->get_all_default_prices();
228
+			foreach ($default_tickets as $default_ticket) {
229
+				$default_ticket->save();
230
+				$default_ticket->_add_relation_to($default_date, 'Datetime');
231
+				foreach ($default_prices as $default_price) {
232
+					$default_price->save();
233
+					$default_price->_add_relation_to($default_ticket, 'Ticket');
234
+				}
235
+			}
236
+		}
237
+	}
238
+
239
+
240
+	/**
241
+	 * @param int $eventId
242
+	 * @return array|null
243
+	 * @since $VID:$
244
+	 */
245
+	protected function getGraphQLDatetimes($eventId)
246
+	{
247
+		$field_key = lcfirst($this->namespace) . 'Datetimes';
248
+		$query = <<<QUERY
249 249
         query GET_DATETIMES(\$where: {$this->namespace}RootQueryDatetimesConnectionWhereArgs, \$first: Int, \$last: Int ) {
250 250
             {$field_key}(where: \$where, first: \$first, last: \$last) {
251 251
                 nodes {
@@ -274,31 +274,31 @@  discard block
 block discarded – undo
274 274
             }
275 275
         }
276 276
 QUERY;
277
-        $data = [
278
-            'operation_name' => 'GET_DATETIMES',
279
-            'variables' => [
280
-                'first' => 100,
281
-                'where' => [
282
-                    'eventId' => $eventId,
283
-                ],
284
-            ],
285
-            'query' => $query,
286
-        ];
287
-
288
-        $responseData = $this->makeGraphQLRequest($data);
289
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
290
-    }
291
-
292
-
293
-    /**
294
-     * @param array $datetimeIn
295
-     * @return array|null
296
-     * @since $VID:$
297
-     */
298
-    protected function getGraphQLTickets(array $datetimeIn)
299
-    {
300
-        $field_key = lcfirst($this->namespace) . 'Tickets';
301
-        $query = <<<QUERY
277
+		$data = [
278
+			'operation_name' => 'GET_DATETIMES',
279
+			'variables' => [
280
+				'first' => 100,
281
+				'where' => [
282
+					'eventId' => $eventId,
283
+				],
284
+			],
285
+			'query' => $query,
286
+		];
287
+
288
+		$responseData = $this->makeGraphQLRequest($data);
289
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
290
+	}
291
+
292
+
293
+	/**
294
+	 * @param array $datetimeIn
295
+	 * @return array|null
296
+	 * @since $VID:$
297
+	 */
298
+	protected function getGraphQLTickets(array $datetimeIn)
299
+	{
300
+		$field_key = lcfirst($this->namespace) . 'Tickets';
301
+		$query = <<<QUERY
302 302
         query GET_TICKETS(\$where: {$this->namespace}RootQueryTicketsConnectionWhereArgs, \$first: Int, \$last: Int ) {
303 303
             {$field_key}(where: \$where, first: \$first, last: \$last) {
304 304
                 nodes {
@@ -334,31 +334,31 @@  discard block
 block discarded – undo
334 334
             }
335 335
         }
336 336
 QUERY;
337
-        $data = [
338
-            'operation_name' => 'GET_TICKETS',
339
-            'variables' => [
340
-                'first' => 100,
341
-                'where' => [
342
-                    'datetimeIn' => $datetimeIn,
343
-                ],
344
-            ],
345
-            'query' => $query,
346
-        ];
347
-
348
-        $responseData = $this->makeGraphQLRequest($data);
349
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
350
-    }
351
-
352
-
353
-    /**
354
-     * @param array $ticketIn
355
-     * @return array|null
356
-     * @since $VID:$
357
-     */
358
-    protected function getGraphQLPrices(array $ticketIn)
359
-    {
360
-        $field_key = lcfirst($this->namespace) . 'Prices';
361
-        $query = <<<QUERY
337
+		$data = [
338
+			'operation_name' => 'GET_TICKETS',
339
+			'variables' => [
340
+				'first' => 100,
341
+				'where' => [
342
+					'datetimeIn' => $datetimeIn,
343
+				],
344
+			],
345
+			'query' => $query,
346
+		];
347
+
348
+		$responseData = $this->makeGraphQLRequest($data);
349
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
350
+	}
351
+
352
+
353
+	/**
354
+	 * @param array $ticketIn
355
+	 * @return array|null
356
+	 * @since $VID:$
357
+	 */
358
+	protected function getGraphQLPrices(array $ticketIn)
359
+	{
360
+		$field_key = lcfirst($this->namespace) . 'Prices';
361
+		$query = <<<QUERY
362 362
         query GET_PRICES(\$where: {$this->namespace}RootQueryPricesConnectionWhereArgs, \$first: Int, \$last: Int ) {
363 363
             {$field_key}(where: \$where, first: \$first, last: \$last) {
364 364
                 nodes {
@@ -382,30 +382,30 @@  discard block
 block discarded – undo
382 382
             }
383 383
         }
384 384
 QUERY;
385
-        $data = [
386
-            'operation_name' => 'GET_PRICES',
387
-            'variables' => [
388
-                'first' => 100,
389
-                'where' => [
390
-                    'ticketIn' => $ticketIn,
391
-                ],
392
-            ],
393
-            'query' => $query,
394
-        ];
395
-
396
-        $responseData = $this->makeGraphQLRequest($data);
397
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
398
-    }
399
-
400
-
401
-    /**
402
-     * @return array|null
403
-     * @since $VID:$
404
-     */
405
-    protected function getGraphQLPriceTypes()
406
-    {
407
-        $field_key = lcfirst($this->namespace) . 'PriceTypes';
408
-        $query = <<<QUERY
385
+		$data = [
386
+			'operation_name' => 'GET_PRICES',
387
+			'variables' => [
388
+				'first' => 100,
389
+				'where' => [
390
+					'ticketIn' => $ticketIn,
391
+				],
392
+			],
393
+			'query' => $query,
394
+		];
395
+
396
+		$responseData = $this->makeGraphQLRequest($data);
397
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
398
+	}
399
+
400
+
401
+	/**
402
+	 * @return array|null
403
+	 * @since $VID:$
404
+	 */
405
+	protected function getGraphQLPriceTypes()
406
+	{
407
+		$field_key = lcfirst($this->namespace) . 'PriceTypes';
408
+		$query = <<<QUERY
409 409
         query GET_PRICE_TYPES(\$first: Int, \$last: Int ) {
410 410
             {$field_key}(first: \$first, last: \$last) {
411 411
                 nodes {
@@ -426,27 +426,27 @@  discard block
 block discarded – undo
426 426
             }
427 427
         }
428 428
 QUERY;
429
-        $data = [
430
-            'operation_name' => 'GET_PRICE_TYPES',
431
-            'variables' => [
432
-                'first' => 100,
433
-            ],
434
-            'query' => $query,
435
-        ];
436
-
437
-        $responseData = $this->makeGraphQLRequest($data);
438
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
439
-    }
440
-
441
-
442
-    /**
443
-     * @return array|null
444
-     * @since $VID:$
445
-     */
446
-    protected function getGraphQLCurrentUser()
447
-    {
448
-        $field_key = 'viewer';
449
-        $query = <<<QUERY
429
+		$data = [
430
+			'operation_name' => 'GET_PRICE_TYPES',
431
+			'variables' => [
432
+				'first' => 100,
433
+			],
434
+			'query' => $query,
435
+		];
436
+
437
+		$responseData = $this->makeGraphQLRequest($data);
438
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
439
+	}
440
+
441
+
442
+	/**
443
+	 * @return array|null
444
+	 * @since $VID:$
445
+	 */
446
+	protected function getGraphQLCurrentUser()
447
+	{
448
+		$field_key = 'viewer';
449
+		$query = <<<QUERY
450 450
         query GET_CURRENT_USER {
451 451
             {$field_key} {
452 452
                 description
@@ -464,24 +464,24 @@  discard block
 block discarded – undo
464 464
             }
465 465
         }
466 466
 QUERY;
467
-        $data = [
468
-            'operation_name' => 'GET_CURRENT_USER',
469
-            'query' => $query,
470
-        ];
471
-
472
-        $responseData = $this->makeGraphQLRequest($data);
473
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
474
-    }
475
-
476
-
477
-    /**
478
-     * @return array|null
479
-     * @since $VID:$
480
-     */
481
-    protected function getGraphQLGeneralSettings()
482
-    {
483
-        $field_key = 'generalSettings';
484
-        $query = <<<QUERY
467
+		$data = [
468
+			'operation_name' => 'GET_CURRENT_USER',
469
+			'query' => $query,
470
+		];
471
+
472
+		$responseData = $this->makeGraphQLRequest($data);
473
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
474
+	}
475
+
476
+
477
+	/**
478
+	 * @return array|null
479
+	 * @since $VID:$
480
+	 */
481
+	protected function getGraphQLGeneralSettings()
482
+	{
483
+		$field_key = 'generalSettings';
484
+		$query = <<<QUERY
485 485
         query GET_GENERAL_SETTINGS {
486 486
             {$field_key} {
487 487
                 dateFormat
@@ -491,185 +491,185 @@  discard block
 block discarded – undo
491 491
             }
492 492
         }
493 493
 QUERY;
494
-        $data = [
495
-            'operation_name' => 'GET_CURRENT_USER',
496
-            'query' => $query,
497
-        ];
498
-
499
-        $responseData = $this->makeGraphQLRequest($data);
500
-        return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
501
-    }
502
-
503
-
504
-    /**
505
-     * @param array $data
506
-     * @return array
507
-     * @since $VID:$
508
-     */
509
-    protected function makeGraphQLRequest($data)
510
-    {
511
-        try {
512
-            $response = graphql($data);
513
-            if (!empty($response['data'])) {
514
-                return $response['data'];
515
-            }
516
-            return null;
517
-        } catch (\Exception $e) {
518
-            // do something with the errors thrown
519
-            return null;
520
-        }
521
-    }
522
-
523
-
524
-    /**
525
-     * @param mixed       $source  The source that's passed down the GraphQL queries
526
-     * @param array       $args    The inputArgs on the field
527
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
528
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
529
-     * @return string
530
-     * @throws EE_Error
531
-     * @throws Exception
532
-     * @throws InvalidArgumentException
533
-     * @throws InvalidDataTypeException
534
-     * @throws InvalidInterfaceException
535
-     * @throws ReflectionException
536
-     * @throws UserError
537
-     * @throws UnexpectedEntityException
538
-     * @since $VID:$
539
-     */
540
-    public static function getRelationalData($eventId)
541
-    {
542
-        $data = [
543
-            'datetimes'  => [],
544
-            'tickets'    => [],
545
-            'prices'     => [],
546
-        ];
547
-
548
-        $eem_datetime   = EEM_Datetime::instance();
549
-        $eem_ticket     = EEM_Ticket::instance();
550
-        $eem_price      = EEM_Price::instance();
551
-        $eem_price_type = EEM_Price_Type::instance();
552
-
553
-        // PROCESS DATETIMES
554
-        $related_models = [
555
-            'tickets' => $eem_ticket,
556
-        ];
557
-        // Get the IDs of event datetimes.
558
-        $datetimeIds = $eem_datetime->get_col([
559
-            [
560
-                'EVT_ID'      => $eventId,
561
-            ],
562
-            'default_where_conditions' => 'minimum',
563
-        ]);
564
-        foreach ($datetimeIds as $datetimeId) {
565
-            $GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId);
566
-            foreach ($related_models as $key => $model) {
567
-                // Get the IDs of related entities for the datetime ID.
568
-                $Ids = $model->get_col([
569
-                    [
570
-                        'Datetime.DTT_ID' => $datetimeId,
571
-                    ],
572
-                    'default_where_conditions' => 'minimum',
573
-                ]);
574
-                $data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
575
-            }
576
-        }
577
-
578
-        // PROCESS TICKETS
579
-        $related_models = [
580
-            'datetimes' => $eem_datetime,
581
-            'prices'    => $eem_price,
582
-        ];
583
-        // Get the IDs of all datetime tickets.
584
-        $ticketIds = $eem_ticket->get_col([
585
-            [
586
-                'Datetime.DTT_ID' => ['IN', $datetimeIds],
587
-            ],
588
-            'default_where_conditions' => 'minimum',
589
-            ]);
590
-        foreach ($ticketIds as $ticketId) {
591
-            $GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId);
592
-
593
-            foreach ($related_models as $key => $model) {
594
-                // Get the IDs of related entities for the ticket ID.
595
-                $Ids = $model->get_col([
596
-                    [
597
-                        'Ticket.TKT_ID' => $ticketId,
598
-                    ],
599
-                    'default_where_conditions' => 'minimum',
600
-                ]);
601
-                $data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
602
-            }
603
-        }
604
-
605
-        // PROCESS PRICES
606
-        $related_models = [
607
-            'tickets'    => $eem_ticket,
608
-            'priceTypes' => $eem_price_type,
609
-        ];
610
-        // Get the IDs of all ticket prices.
611
-        $priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['IN', $ticketIds]]]);
612
-        foreach ($priceIds as $priceId) {
613
-            $GID = self::convertToGlobalId($eem_price->item_name(), $priceId);
614
-
615
-            foreach ($related_models as $key => $model) {
616
-                // Get the IDs of related entities for the price ID.
617
-                $Ids = $model->get_col([
618
-                    [
619
-                        'Price.PRC_ID' => $priceId,
620
-                    ],
621
-                    'default_where_conditions' => 'minimum',
622
-                ]);
623
-                $data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
624
-            }
625
-        }
626
-
627
-        return $data;
628
-    }
629
-
630
-    /**
631
-     * Convert the DB ID into GID
632
-     *
633
-     * @param string    $type
634
-     * @param int|int[] $ID
635
-     * @return mixed
636
-     */
637
-    public static function convertToGlobalId($type, $ID)
638
-    {
639
-        if (is_array($ID)) {
640
-            return array_map(function ($id) use ($type) {
641
-                return self::convertToGlobalId($type, $id);
642
-            }, $ID);
643
-        }
644
-        return Relay::toGlobalId($type, $ID);
645
-    }
646
-
647
-
648
-    /**
649
-     * Returns Jed-formatted localization data.
650
-     *
651
-     * @param  string $domain Translation domain.
652
-     * @return array
653
-     */
654
-    public static function getJedLocaleData($domain)
655
-    {
656
-        $translations = get_translations_for_domain($domain);
657
-
658
-        $locale = array(
659
-            '' => array(
660
-                'domain' => $domain,
661
-                'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
662
-            ),
663
-        );
664
-
665
-        if (! empty($translations->headers['Plural-Forms'])) {
666
-            $locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
667
-        }
668
-
669
-        foreach ($translations->entries as $msgid => $entry) {
670
-            $locale[ $msgid ] = $entry->translations;
671
-        }
672
-
673
-        return $locale;
674
-    }
494
+		$data = [
495
+			'operation_name' => 'GET_CURRENT_USER',
496
+			'query' => $query,
497
+		];
498
+
499
+		$responseData = $this->makeGraphQLRequest($data);
500
+		return !empty($responseData[ $field_key ]) ? $responseData[ $field_key ] : null;
501
+	}
502
+
503
+
504
+	/**
505
+	 * @param array $data
506
+	 * @return array
507
+	 * @since $VID:$
508
+	 */
509
+	protected function makeGraphQLRequest($data)
510
+	{
511
+		try {
512
+			$response = graphql($data);
513
+			if (!empty($response['data'])) {
514
+				return $response['data'];
515
+			}
516
+			return null;
517
+		} catch (\Exception $e) {
518
+			// do something with the errors thrown
519
+			return null;
520
+		}
521
+	}
522
+
523
+
524
+	/**
525
+	 * @param mixed       $source  The source that's passed down the GraphQL queries
526
+	 * @param array       $args    The inputArgs on the field
527
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
528
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
529
+	 * @return string
530
+	 * @throws EE_Error
531
+	 * @throws Exception
532
+	 * @throws InvalidArgumentException
533
+	 * @throws InvalidDataTypeException
534
+	 * @throws InvalidInterfaceException
535
+	 * @throws ReflectionException
536
+	 * @throws UserError
537
+	 * @throws UnexpectedEntityException
538
+	 * @since $VID:$
539
+	 */
540
+	public static function getRelationalData($eventId)
541
+	{
542
+		$data = [
543
+			'datetimes'  => [],
544
+			'tickets'    => [],
545
+			'prices'     => [],
546
+		];
547
+
548
+		$eem_datetime   = EEM_Datetime::instance();
549
+		$eem_ticket     = EEM_Ticket::instance();
550
+		$eem_price      = EEM_Price::instance();
551
+		$eem_price_type = EEM_Price_Type::instance();
552
+
553
+		// PROCESS DATETIMES
554
+		$related_models = [
555
+			'tickets' => $eem_ticket,
556
+		];
557
+		// Get the IDs of event datetimes.
558
+		$datetimeIds = $eem_datetime->get_col([
559
+			[
560
+				'EVT_ID'      => $eventId,
561
+			],
562
+			'default_where_conditions' => 'minimum',
563
+		]);
564
+		foreach ($datetimeIds as $datetimeId) {
565
+			$GID = self::convertToGlobalId($eem_datetime->item_name(), $datetimeId);
566
+			foreach ($related_models as $key => $model) {
567
+				// Get the IDs of related entities for the datetime ID.
568
+				$Ids = $model->get_col([
569
+					[
570
+						'Datetime.DTT_ID' => $datetimeId,
571
+					],
572
+					'default_where_conditions' => 'minimum',
573
+				]);
574
+				$data['datetimes'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
575
+			}
576
+		}
577
+
578
+		// PROCESS TICKETS
579
+		$related_models = [
580
+			'datetimes' => $eem_datetime,
581
+			'prices'    => $eem_price,
582
+		];
583
+		// Get the IDs of all datetime tickets.
584
+		$ticketIds = $eem_ticket->get_col([
585
+			[
586
+				'Datetime.DTT_ID' => ['IN', $datetimeIds],
587
+			],
588
+			'default_where_conditions' => 'minimum',
589
+			]);
590
+		foreach ($ticketIds as $ticketId) {
591
+			$GID = self::convertToGlobalId($eem_ticket->item_name(), $ticketId);
592
+
593
+			foreach ($related_models as $key => $model) {
594
+				// Get the IDs of related entities for the ticket ID.
595
+				$Ids = $model->get_col([
596
+					[
597
+						'Ticket.TKT_ID' => $ticketId,
598
+					],
599
+					'default_where_conditions' => 'minimum',
600
+				]);
601
+				$data['tickets'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
602
+			}
603
+		}
604
+
605
+		// PROCESS PRICES
606
+		$related_models = [
607
+			'tickets'    => $eem_ticket,
608
+			'priceTypes' => $eem_price_type,
609
+		];
610
+		// Get the IDs of all ticket prices.
611
+		$priceIds = $eem_price->get_col([['Ticket.TKT_ID' => ['IN', $ticketIds]]]);
612
+		foreach ($priceIds as $priceId) {
613
+			$GID = self::convertToGlobalId($eem_price->item_name(), $priceId);
614
+
615
+			foreach ($related_models as $key => $model) {
616
+				// Get the IDs of related entities for the price ID.
617
+				$Ids = $model->get_col([
618
+					[
619
+						'Price.PRC_ID' => $priceId,
620
+					],
621
+					'default_where_conditions' => 'minimum',
622
+				]);
623
+				$data['prices'][ $GID ][ $key ] = empty($Ids) ? [] : self::convertToGlobalId($model->item_name(), $Ids);
624
+			}
625
+		}
626
+
627
+		return $data;
628
+	}
629
+
630
+	/**
631
+	 * Convert the DB ID into GID
632
+	 *
633
+	 * @param string    $type
634
+	 * @param int|int[] $ID
635
+	 * @return mixed
636
+	 */
637
+	public static function convertToGlobalId($type, $ID)
638
+	{
639
+		if (is_array($ID)) {
640
+			return array_map(function ($id) use ($type) {
641
+				return self::convertToGlobalId($type, $id);
642
+			}, $ID);
643
+		}
644
+		return Relay::toGlobalId($type, $ID);
645
+	}
646
+
647
+
648
+	/**
649
+	 * Returns Jed-formatted localization data.
650
+	 *
651
+	 * @param  string $domain Translation domain.
652
+	 * @return array
653
+	 */
654
+	public static function getJedLocaleData($domain)
655
+	{
656
+		$translations = get_translations_for_domain($domain);
657
+
658
+		$locale = array(
659
+			'' => array(
660
+				'domain' => $domain,
661
+				'lang'   => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale()
662
+			),
663
+		);
664
+
665
+		if (! empty($translations->headers['Plural-Forms'])) {
666
+			$locale['']['plural_forms'] = $translations->headers['Plural-Forms'];
667
+		}
668
+
669
+		foreach ($translations->entries as $msgid => $entry) {
670
+			$locale[ $msgid ] = $entry->translations;
671
+		}
672
+
673
+		return $locale;
674
+	}
675 675
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/PriceDelete.php 2 patches
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -17,70 +17,70 @@
 block discarded – undo
17 17
 class PriceDelete extends EntityMutator
18 18
 {
19 19
 
20
-    /**
21
-     * Defines the mutation data modification closure.
22
-     *
23
-     * @param EEM_Price $model
24
-     * @param Price     $type
25
-     * @return callable
26
-     */
27
-    public static function mutateAndGetPayload(EEM_Price $model, Price $type)
28
-    {
29
-        /**
30
-         * Deletes an entity.
31
-         *
32
-         * @param array       $input   The input for the mutation
33
-         * @param AppContext  $context The AppContext passed down to all resolvers
34
-         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35
-         * @return array
36
-         */
37
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38
-            try {
39
-                /** @var EE_Price $entity */
40
-                $entity = EntityMutator::getEntityFromInputData($model, $input);
20
+	/**
21
+	 * Defines the mutation data modification closure.
22
+	 *
23
+	 * @param EEM_Price $model
24
+	 * @param Price     $type
25
+	 * @return callable
26
+	 */
27
+	public static function mutateAndGetPayload(EEM_Price $model, Price $type)
28
+	{
29
+		/**
30
+		 * Deletes an entity.
31
+		 *
32
+		 * @param array       $input   The input for the mutation
33
+		 * @param AppContext  $context The AppContext passed down to all resolvers
34
+		 * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35
+		 * @return array
36
+		 */
37
+		return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38
+			try {
39
+				/** @var EE_Price $entity */
40
+				$entity = EntityMutator::getEntityFromInputData($model, $input);
41 41
 
42
-                // Delete the entity
43
-                if (! empty($input['deletePermanently'])) {
44
-                    $result = PriceDelete::deletePriceAndRelations($entity);
45
-                } else {
46
-                    // trash the price
47
-                    $result = $entity->delete();
48
-                }
49
-                EntityMutator::validateResults($result);
50
-            } catch (Exception $exception) {
51
-                EntityMutator::handleExceptions(
52
-                    $exception,
53
-                    esc_html__(
54
-                        'The price could not be deleted because of the following error(s)',
55
-                        'event_espresso'
56
-                    )
57
-                );
58
-            }
42
+				// Delete the entity
43
+				if (! empty($input['deletePermanently'])) {
44
+					$result = PriceDelete::deletePriceAndRelations($entity);
45
+				} else {
46
+					// trash the price
47
+					$result = $entity->delete();
48
+				}
49
+				EntityMutator::validateResults($result);
50
+			} catch (Exception $exception) {
51
+				EntityMutator::handleExceptions(
52
+					$exception,
53
+					esc_html__(
54
+						'The price could not be deleted because of the following error(s)',
55
+						'event_espresso'
56
+					)
57
+				);
58
+			}
59 59
 
60
-            return [
61
-                'deleted' => $entity,
62
-            ];
63
-        };
64
-    }
60
+			return [
61
+				'deleted' => $entity,
62
+			];
63
+		};
64
+	}
65 65
 
66
-    /**
67
-     * Deletes a price permanently along with its relations.
68
-     *
69
-     * @param EE_Price $entity
70
-     * @return bool | int
71
-     * @throws ReflectionException
72
-     * @throws InvalidArgumentException
73
-     * @throws InvalidInterfaceException
74
-     * @throws InvalidDataTypeException
75
-     * @throws EE_Error
76
-     */
77
-    public static function deletePriceAndRelations($entity)
78
-    {
79
-        // Remove relation with ticket
80
-        $entity->_remove_relations('Ticket');
81
-        // Now delete the price permanently
82
-        $result = $entity->delete_permanently();
66
+	/**
67
+	 * Deletes a price permanently along with its relations.
68
+	 *
69
+	 * @param EE_Price $entity
70
+	 * @return bool | int
71
+	 * @throws ReflectionException
72
+	 * @throws InvalidArgumentException
73
+	 * @throws InvalidInterfaceException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws EE_Error
76
+	 */
77
+	public static function deletePriceAndRelations($entity)
78
+	{
79
+		// Remove relation with ticket
80
+		$entity->_remove_relations('Ticket');
81
+		// Now delete the price permanently
82
+		$result = $entity->delete_permanently();
83 83
 
84
-        return $result;
85
-    }
84
+		return $result;
85
+	}
86 86
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@
 block discarded – undo
34 34
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35 35
          * @return array
36 36
          */
37
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
37
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38 38
             try {
39 39
                 /** @var EE_Price $entity */
40 40
                 $entity = EntityMutator::getEntityFromInputData($model, $input);
41 41
 
42 42
                 // Delete the entity
43
-                if (! empty($input['deletePermanently'])) {
43
+                if ( ! empty($input['deletePermanently'])) {
44 44
                     $result = PriceDelete::deletePriceAndRelations($entity);
45 45
                 } else {
46 46
                     // trash the price
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/DatetimeDelete.php 2 patches
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -17,109 +17,109 @@
 block discarded – undo
17 17
 class DatetimeDelete extends EntityMutator
18 18
 {
19 19
 
20
-    /**
21
-     * Defines the mutation data modification closure.
22
-     *
23
-     * @param EEM_Datetime $model
24
-     * @param Datetime     $type
25
-     * @return callable
26
-     */
27
-    public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type)
28
-    {
29
-        /**
30
-         * Deletes an entity.
31
-         *
32
-         * @param array       $input   The input for the mutation
33
-         * @param AppContext  $context The AppContext passed down to all resolvers
34
-         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35
-         * @return array|void
36
-         */
37
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38
-            try {
39
-                /** @var EE_Datetime $entity */
40
-                $entity = EntityMutator::getEntityFromInputData($model, $input);
20
+	/**
21
+	 * Defines the mutation data modification closure.
22
+	 *
23
+	 * @param EEM_Datetime $model
24
+	 * @param Datetime     $type
25
+	 * @return callable
26
+	 */
27
+	public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type)
28
+	{
29
+		/**
30
+		 * Deletes an entity.
31
+		 *
32
+		 * @param array       $input   The input for the mutation
33
+		 * @param AppContext  $context The AppContext passed down to all resolvers
34
+		 * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35
+		 * @return array|void
36
+		 */
37
+		return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38
+			try {
39
+				/** @var EE_Datetime $entity */
40
+				$entity = EntityMutator::getEntityFromInputData($model, $input);
41 41
 
42
-                // Delete the entity
43
-                if (! empty($input['deletePermanently'])) {
44
-                    $result = DatetimeDelete::deleteDatetimeAndRelations($entity);
45
-                } else {
46
-                    $result = DatetimeDelete::trashDatetimeAndRelations($entity);
47
-                }
48
-                EntityMutator::validateResults($result);
49
-            } catch (Exception $exception) {
50
-                EntityMutator::handleExceptions(
51
-                    $exception,
52
-                    esc_html__(
53
-                        'The datetime could not be deleted because of the following error(s)',
54
-                        'event_espresso'
55
-                    )
56
-                );
57
-            }
42
+				// Delete the entity
43
+				if (! empty($input['deletePermanently'])) {
44
+					$result = DatetimeDelete::deleteDatetimeAndRelations($entity);
45
+				} else {
46
+					$result = DatetimeDelete::trashDatetimeAndRelations($entity);
47
+				}
48
+				EntityMutator::validateResults($result);
49
+			} catch (Exception $exception) {
50
+				EntityMutator::handleExceptions(
51
+					$exception,
52
+					esc_html__(
53
+						'The datetime could not be deleted because of the following error(s)',
54
+						'event_espresso'
55
+					)
56
+				);
57
+			}
58 58
 
59
-            return [
60
-                'deleted' => $entity,
61
-            ];
62
-        };
63
-    }
59
+			return [
60
+				'deleted' => $entity,
61
+			];
62
+		};
63
+	}
64 64
 
65
-    /**
66
-     * Deletes a datetime permanently along with its relations.
67
-     *
68
-     * @param EE_Datetime $entity
69
-     * @return bool | int
70
-     * @throws ReflectionException
71
-     * @throws InvalidArgumentException
72
-     * @throws InvalidInterfaceException
73
-     * @throws InvalidDataTypeException
74
-     * @throws EE_Error
75
-     */
76
-    public static function deleteDatetimeAndRelations($entity)
77
-    {
78
-        // all related tickets
79
-        $tickets = $entity->tickets();
80
-        foreach ($tickets as $ticket) {
81
-            // if the ticket is related to only one datetime
82
-            if ($ticket->count_related('Datetime') === 1) {
83
-                TicketDelete::deleteTicketAndRelations($ticket);
84
-            }
85
-        }
65
+	/**
66
+	 * Deletes a datetime permanently along with its relations.
67
+	 *
68
+	 * @param EE_Datetime $entity
69
+	 * @return bool | int
70
+	 * @throws ReflectionException
71
+	 * @throws InvalidArgumentException
72
+	 * @throws InvalidInterfaceException
73
+	 * @throws InvalidDataTypeException
74
+	 * @throws EE_Error
75
+	 */
76
+	public static function deleteDatetimeAndRelations($entity)
77
+	{
78
+		// all related tickets
79
+		$tickets = $entity->tickets();
80
+		foreach ($tickets as $ticket) {
81
+			// if the ticket is related to only one datetime
82
+			if ($ticket->count_related('Datetime') === 1) {
83
+				TicketDelete::deleteTicketAndRelations($ticket);
84
+			}
85
+		}
86 86
 
87
-        // Remove relations with tickets
88
-        $entity->_remove_relations('Ticket');
89
-        // Now delete the datetime permanently
90
-        $result = $entity->delete_permanently();
87
+		// Remove relations with tickets
88
+		$entity->_remove_relations('Ticket');
89
+		// Now delete the datetime permanently
90
+		$result = $entity->delete_permanently();
91 91
 
92
-        return $result;
93
-    }
92
+		return $result;
93
+	}
94 94
 
95
-    /**
96
-     * Trashes a datetime along with its lone relations.
97
-     *
98
-     * @param EE_Datetime $entity
99
-     * @return bool | int
100
-     * @throws ReflectionException
101
-     * @throws InvalidArgumentException
102
-     * @throws InvalidInterfaceException
103
-     * @throws InvalidDataTypeException
104
-     * @throws EE_Error
105
-     */
106
-    public static function trashDatetimeAndRelations($entity)
107
-    {
108
-        // non trashed related tickets
109
-        $tickets = $entity->tickets([[
110
-            'TKT_deleted' => false,
111
-        ]]);
112
-        // loop though all tickets to check if we need to trash any
113
-        foreach ($tickets as $ticket) {
114
-            // if the ticket is related to only one datetime
115
-            if ($ticket->count_related('Datetime') === 1) {
116
-                // trash the ticket
117
-                $ticket->delete();
118
-            }
119
-        }
120
-        // trash the datetime
121
-        $result = $entity->delete();
95
+	/**
96
+	 * Trashes a datetime along with its lone relations.
97
+	 *
98
+	 * @param EE_Datetime $entity
99
+	 * @return bool | int
100
+	 * @throws ReflectionException
101
+	 * @throws InvalidArgumentException
102
+	 * @throws InvalidInterfaceException
103
+	 * @throws InvalidDataTypeException
104
+	 * @throws EE_Error
105
+	 */
106
+	public static function trashDatetimeAndRelations($entity)
107
+	{
108
+		// non trashed related tickets
109
+		$tickets = $entity->tickets([[
110
+			'TKT_deleted' => false,
111
+		]]);
112
+		// loop though all tickets to check if we need to trash any
113
+		foreach ($tickets as $ticket) {
114
+			// if the ticket is related to only one datetime
115
+			if ($ticket->count_related('Datetime') === 1) {
116
+				// trash the ticket
117
+				$ticket->delete();
118
+			}
119
+		}
120
+		// trash the datetime
121
+		$result = $entity->delete();
122 122
 
123
-        return $result;
124
-    }
123
+		return $result;
124
+	}
125 125
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@
 block discarded – undo
34 34
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35 35
          * @return array|void
36 36
          */
37
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
37
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38 38
             try {
39 39
                 /** @var EE_Datetime $entity */
40 40
                 $entity = EntityMutator::getEntityFromInputData($model, $input);
41 41
 
42 42
                 // Delete the entity
43
-                if (! empty($input['deletePermanently'])) {
43
+                if ( ! empty($input['deletePermanently'])) {
44 44
                     $result = DatetimeDelete::deleteDatetimeAndRelations($entity);
45 45
                 } else {
46 46
                     $result = DatetimeDelete::trashDatetimeAndRelations($entity);
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/TicketDelete.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -17,72 +17,72 @@
 block discarded – undo
17 17
 class TicketDelete extends EntityMutator
18 18
 {
19 19
 
20
-    /**
21
-     * Defines the mutation data modification closure.
22
-     *
23
-     * @param EEM_Ticket $model
24
-     * @param Ticket     $type
25
-     * @return callable
26
-     */
27
-    public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type)
28
-    {
29
-        /**
30
-         * Deletes an entity.
31
-         *
32
-         * @param array       $input   The input for the mutation
33
-         * @param AppContext  $context The AppContext passed down to all resolvers
34
-         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35
-         * @return array
36
-         */
37
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38
-            try {
39
-                /** @var EE_Ticket $entity */
40
-                $entity = EntityMutator::getEntityFromInputData($model, $input);
20
+	/**
21
+	 * Defines the mutation data modification closure.
22
+	 *
23
+	 * @param EEM_Ticket $model
24
+	 * @param Ticket     $type
25
+	 * @return callable
26
+	 */
27
+	public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type)
28
+	{
29
+		/**
30
+		 * Deletes an entity.
31
+		 *
32
+		 * @param array       $input   The input for the mutation
33
+		 * @param AppContext  $context The AppContext passed down to all resolvers
34
+		 * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35
+		 * @return array
36
+		 */
37
+		return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38
+			try {
39
+				/** @var EE_Ticket $entity */
40
+				$entity = EntityMutator::getEntityFromInputData($model, $input);
41 41
 
42
-                // Delete the entity
43
-                if (! empty($input['deletePermanently'])) {
44
-                    $result = TicketDelete::deleteTicketAndRelations($entity);
45
-                } else {
46
-                    // trash the ticket
47
-                    $result = $entity->delete();
48
-                }
49
-                EntityMutator::validateResults($result);
50
-            } catch (Exception $exception) {
51
-                EntityMutator::handleExceptions(
52
-                    $exception,
53
-                    esc_html__(
54
-                        'The ticket could not be deleted because of the following error(s)',
55
-                        'event_espresso'
56
-                    )
57
-                );
58
-            }
42
+				// Delete the entity
43
+				if (! empty($input['deletePermanently'])) {
44
+					$result = TicketDelete::deleteTicketAndRelations($entity);
45
+				} else {
46
+					// trash the ticket
47
+					$result = $entity->delete();
48
+				}
49
+				EntityMutator::validateResults($result);
50
+			} catch (Exception $exception) {
51
+				EntityMutator::handleExceptions(
52
+					$exception,
53
+					esc_html__(
54
+						'The ticket could not be deleted because of the following error(s)',
55
+						'event_espresso'
56
+					)
57
+				);
58
+			}
59 59
 
60
-            return [
61
-                'deleted' => $entity,
62
-            ];
63
-        };
64
-    }
60
+			return [
61
+				'deleted' => $entity,
62
+			];
63
+		};
64
+	}
65 65
 
66
-    /**
67
-     * Deletes a ticket permanently along with its relations.
68
-     *
69
-     * @param EE_Ticket $entity
70
-     * @return bool | int
71
-     * @throws ReflectionException
72
-     * @throws InvalidArgumentException
73
-     * @throws InvalidInterfaceException
74
-     * @throws InvalidDataTypeException
75
-     * @throws EE_Error
76
-     */
77
-    public static function deleteTicketAndRelations($entity)
78
-    {
79
-        // Remove related prices for the ticket
80
-        $entity->delete_related_permanently('Price');
81
-        // Remove relation with datetimes
82
-        $entity->_remove_relations('Datetime');
83
-        // Now delete the ticket permanently
84
-        $result = $entity->delete_permanently();
66
+	/**
67
+	 * Deletes a ticket permanently along with its relations.
68
+	 *
69
+	 * @param EE_Ticket $entity
70
+	 * @return bool | int
71
+	 * @throws ReflectionException
72
+	 * @throws InvalidArgumentException
73
+	 * @throws InvalidInterfaceException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws EE_Error
76
+	 */
77
+	public static function deleteTicketAndRelations($entity)
78
+	{
79
+		// Remove related prices for the ticket
80
+		$entity->delete_related_permanently('Price');
81
+		// Remove relation with datetimes
82
+		$entity->_remove_relations('Datetime');
83
+		// Now delete the ticket permanently
84
+		$result = $entity->delete_permanently();
85 85
 
86
-        return $result;
87
-    }
86
+		return $result;
87
+	}
88 88
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@
 block discarded – undo
34 34
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
35 35
          * @return array
36 36
          */
37
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
37
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
38 38
             try {
39 39
                 /** @var EE_Ticket $entity */
40 40
                 $entity = EntityMutator::getEntityFromInputData($model, $input);
41 41
 
42 42
                 // Delete the entity
43
-                if (! empty($input['deletePermanently'])) {
43
+                if ( ! empty($input['deletePermanently'])) {
44 44
                     $result = TicketDelete::deleteTicketAndRelations($entity);
45 45
                 } else {
46 46
                     // trash the ticket
Please login to merge, or discard this patch.