Completed
Branch EDTR/master (080f77)
by
unknown
10:29 queued 01:20
created
core/domain/services/graphql/types/Ticket.php 1 patch
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -33,344 +33,344 @@
 block discarded – undo
33 33
 class Ticket extends TypeBase
34 34
 {
35 35
 
36
-    /**
37
-     * Ticket constructor.
38
-     *
39
-     * @param EEM_Ticket $ticket_model
40
-     */
41
-    public function __construct(EEM_Ticket $ticket_model)
42
-    {
43
-        $this->model = $ticket_model;
44
-        $this->setName($this->namespace . 'Ticket');
45
-        $this->setDescription(__('A ticket for an event date', 'event_espresso'));
46
-        $this->setIsCustomPostType(false);
47
-        parent::__construct();
48
-    }
36
+	/**
37
+	 * Ticket constructor.
38
+	 *
39
+	 * @param EEM_Ticket $ticket_model
40
+	 */
41
+	public function __construct(EEM_Ticket $ticket_model)
42
+	{
43
+		$this->model = $ticket_model;
44
+		$this->setName($this->namespace . 'Ticket');
45
+		$this->setDescription(__('A ticket for an event date', 'event_espresso'));
46
+		$this->setIsCustomPostType(false);
47
+		parent::__construct();
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @return GraphQLFieldInterface[]
53
-     * @since $VID:$
54
-     */
55
-    public function getFields()
56
-    {
57
-        return [
58
-            new GraphQLField(
59
-                'id',
60
-                ['non_null' => 'ID'],
61
-                null,
62
-                esc_html__('The globally unique ID for the object.', 'event_espresso')
63
-            ),
64
-            new GraphQLOutputField(
65
-                'dbId',
66
-                ['non_null' => 'Int'],
67
-                'ID',
68
-                esc_html__('Ticket ID', 'event_espresso')
69
-            ),
70
-            new GraphQLInputField(
71
-                'datetimes',
72
-                ['list_of' => 'ID'],
73
-                null,
74
-                sprintf(
75
-                    '%1$s %2$s',
76
-                    esc_html__('Globally unique IDs of the datetimes related to the ticket.', 'event_espresso'),
77
-                    esc_html__('Ignored if empty.', 'event_espresso')
78
-                )
79
-            ),
80
-            new GraphQLField(
81
-                'description',
82
-                'String',
83
-                'description',
84
-                esc_html__('Description of Ticket', 'event_espresso')
85
-            ),
86
-            new GraphQLField(
87
-                'endDate',
88
-                'String',
89
-                'end_date',
90
-                esc_html__('End date and time of the Ticket', 'event_espresso'),
91
-                [$this, 'formatDatetime']
92
-            ),
93
-            new GraphQLOutputField(
94
-                'event',
95
-                $this->namespace . 'Event',
96
-                null,
97
-                esc_html__('Event of the ticket.', 'event_espresso')
98
-            ),
99
-            new GraphQLField(
100
-                'isDefault',
101
-                'Boolean',
102
-                'is_default',
103
-                esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso')
104
-            ),
105
-            new GraphQLOutputField(
106
-                'isExpired',
107
-                'Boolean',
108
-                'is_expired',
109
-                esc_html__('Flag indicating ticket is no longer available because its available dates have expired', 'event_espresso')
110
-            ),
111
-            new GraphQLOutputField(
112
-                'isFree',
113
-                'Boolean',
114
-                'is_free',
115
-                esc_html__('Flag indicating whether the ticket is free.', 'event_espresso')
116
-            ),
117
-            new GraphQLOutputField(
118
-                'isOnSale',
119
-                'Boolean',
120
-                'is_on_sale',
121
-                esc_html__('Flag indicating ticket ticket is on sale or not', 'event_espresso')
122
-            ),
123
-            new GraphQLOutputField(
124
-                'isPending',
125
-                'Boolean',
126
-                'is_pending',
127
-                esc_html__('Flag indicating ticket is yet to go on sale or not', 'event_espresso')
128
-            ),
129
-            new GraphQLField(
130
-                'isRequired',
131
-                'Boolean',
132
-                'required',
133
-                esc_html__(
134
-                    'Flag indicating whether this ticket must be purchased with a transaction',
135
-                    'event_espresso'
136
-                )
137
-            ),
138
-            new GraphQLOutputField(
139
-                'isSoldOut',
140
-                'Boolean',
141
-                null,
142
-                esc_html__('Flag indicating whether the ticket is sold out', 'event_espresso'),
143
-                null,
144
-                [$this, 'getIsSoldOut']
145
-            ),
146
-            new GraphQLField(
147
-                'isTaxable',
148
-                'Boolean',
149
-                'taxable',
150
-                esc_html__(
151
-                    'Flag indicating whether there is tax applied on this ticket',
152
-                    'event_espresso'
153
-                )
154
-            ),
155
-            new GraphQLField(
156
-                'isTrashed',
157
-                'Boolean',
158
-                'deleted',
159
-                esc_html__('Flag indicating ticket has been trashed.', 'event_espresso')
160
-            ),
161
-            new GraphQLField(
162
-                'max',
163
-                'Int',
164
-                'max',
165
-                esc_html__(
166
-                    'Maximum quantity of this ticket that can be purchased in one transaction',
167
-                    'event_espresso'
168
-                ),
169
-                [$this, 'parseInfiniteValue']
170
-            ),
171
-            new GraphQLField(
172
-                'min',
173
-                'Int',
174
-                'min',
175
-                esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso')
176
-            ),
177
-            new GraphQLField(
178
-                'name',
179
-                'String',
180
-                'name',
181
-                esc_html__('Ticket Name', 'event_espresso')
182
-            ),
183
-            new GraphQLField(
184
-                'order',
185
-                'Int',
186
-                'order',
187
-                esc_html__('The order in which the Datetime is displayed', 'event_espresso')
188
-            ),
189
-            new GraphQLOutputField(
190
-                'parent',
191
-                $this->name(),
192
-                null,
193
-                esc_html__('The parent ticket of the current ticket', 'event_espresso')
194
-            ),
195
-            new GraphQLInputField(
196
-                'parent',
197
-                'ID',
198
-                null,
199
-                esc_html__('The parent ticket ID', 'event_espresso')
200
-            ),
201
-            new GraphQLField(
202
-                'price',
203
-                'Float',
204
-                'price',
205
-                esc_html__('Final calculated price for ticket', 'event_espresso')
206
-            ),
207
-            new GraphQLInputField(
208
-                'prices',
209
-                ['list_of' => 'ID'],
210
-                null,
211
-                sprintf(
212
-                    '%1$s %2$s',
213
-                    esc_html__('Globally unique IDs of the prices related to the ticket.', 'event_espresso'),
214
-                    esc_html__('Ignored if empty.', 'event_espresso')
215
-                )
216
-            ),
217
-            new GraphQLField(
218
-                'quantity',
219
-                'Int',
220
-                'qty',
221
-                esc_html__('Quantity of this ticket that is available', 'event_espresso'),
222
-                [$this, 'parseInfiniteValue']
223
-            ),
224
-            new GraphQLField(
225
-                'reserved',
226
-                'Int',
227
-                'reserved',
228
-                esc_html__(
229
-                    'Quantity of this ticket that is reserved, but not yet fully purchased',
230
-                    'event_espresso'
231
-                )
232
-            ),
233
-            new GraphQLField(
234
-                'reverseCalculate',
235
-                'Boolean',
236
-                'reverse_calculate',
237
-                esc_html__(
238
-                    'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.',
239
-                    'event_espresso'
240
-                )
241
-            ),
242
-            new GraphQLField(
243
-                'row',
244
-                'Int',
245
-                'row',
246
-                esc_html__('How tickets are displayed in the ui', 'event_espresso')
247
-            ),
248
-            new GraphQLField(
249
-                'sold',
250
-                'Int',
251
-                'sold',
252
-                esc_html__('Number of this ticket sold', 'event_espresso')
253
-            ),
254
-            new GraphQLOutputField(
255
-                'status',
256
-                $this->namespace . 'TicketStatusEnum',
257
-                'ticket_status',
258
-                esc_html__('Ticket status', 'event_espresso')
259
-            ),
260
-            new GraphQLField(
261
-                'startDate',
262
-                'String',
263
-                'start_date',
264
-                esc_html__('Start date and time of the Ticket', 'event_espresso'),
265
-                [$this, 'formatDatetime']
266
-            ),
267
-            new GraphQLField(
268
-                'uses',
269
-                'Int',
270
-                'uses',
271
-                esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
272
-                [$this, 'parseInfiniteValue']
273
-            ),
274
-            new GraphQLOutputField(
275
-                'wpUser',
276
-                'User',
277
-                null,
278
-                esc_html__('Ticket Creator', 'event_espresso')
279
-            ),
280
-            new GraphQLInputField(
281
-                'wpUser',
282
-                'Int',
283
-                null,
284
-                esc_html__('Ticket Creator ID', 'event_espresso')
285
-            ),
286
-        ];
287
-    }
51
+	/**
52
+	 * @return GraphQLFieldInterface[]
53
+	 * @since $VID:$
54
+	 */
55
+	public function getFields()
56
+	{
57
+		return [
58
+			new GraphQLField(
59
+				'id',
60
+				['non_null' => 'ID'],
61
+				null,
62
+				esc_html__('The globally unique ID for the object.', 'event_espresso')
63
+			),
64
+			new GraphQLOutputField(
65
+				'dbId',
66
+				['non_null' => 'Int'],
67
+				'ID',
68
+				esc_html__('Ticket ID', 'event_espresso')
69
+			),
70
+			new GraphQLInputField(
71
+				'datetimes',
72
+				['list_of' => 'ID'],
73
+				null,
74
+				sprintf(
75
+					'%1$s %2$s',
76
+					esc_html__('Globally unique IDs of the datetimes related to the ticket.', 'event_espresso'),
77
+					esc_html__('Ignored if empty.', 'event_espresso')
78
+				)
79
+			),
80
+			new GraphQLField(
81
+				'description',
82
+				'String',
83
+				'description',
84
+				esc_html__('Description of Ticket', 'event_espresso')
85
+			),
86
+			new GraphQLField(
87
+				'endDate',
88
+				'String',
89
+				'end_date',
90
+				esc_html__('End date and time of the Ticket', 'event_espresso'),
91
+				[$this, 'formatDatetime']
92
+			),
93
+			new GraphQLOutputField(
94
+				'event',
95
+				$this->namespace . 'Event',
96
+				null,
97
+				esc_html__('Event of the ticket.', 'event_espresso')
98
+			),
99
+			new GraphQLField(
100
+				'isDefault',
101
+				'Boolean',
102
+				'is_default',
103
+				esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso')
104
+			),
105
+			new GraphQLOutputField(
106
+				'isExpired',
107
+				'Boolean',
108
+				'is_expired',
109
+				esc_html__('Flag indicating ticket is no longer available because its available dates have expired', 'event_espresso')
110
+			),
111
+			new GraphQLOutputField(
112
+				'isFree',
113
+				'Boolean',
114
+				'is_free',
115
+				esc_html__('Flag indicating whether the ticket is free.', 'event_espresso')
116
+			),
117
+			new GraphQLOutputField(
118
+				'isOnSale',
119
+				'Boolean',
120
+				'is_on_sale',
121
+				esc_html__('Flag indicating ticket ticket is on sale or not', 'event_espresso')
122
+			),
123
+			new GraphQLOutputField(
124
+				'isPending',
125
+				'Boolean',
126
+				'is_pending',
127
+				esc_html__('Flag indicating ticket is yet to go on sale or not', 'event_espresso')
128
+			),
129
+			new GraphQLField(
130
+				'isRequired',
131
+				'Boolean',
132
+				'required',
133
+				esc_html__(
134
+					'Flag indicating whether this ticket must be purchased with a transaction',
135
+					'event_espresso'
136
+				)
137
+			),
138
+			new GraphQLOutputField(
139
+				'isSoldOut',
140
+				'Boolean',
141
+				null,
142
+				esc_html__('Flag indicating whether the ticket is sold out', 'event_espresso'),
143
+				null,
144
+				[$this, 'getIsSoldOut']
145
+			),
146
+			new GraphQLField(
147
+				'isTaxable',
148
+				'Boolean',
149
+				'taxable',
150
+				esc_html__(
151
+					'Flag indicating whether there is tax applied on this ticket',
152
+					'event_espresso'
153
+				)
154
+			),
155
+			new GraphQLField(
156
+				'isTrashed',
157
+				'Boolean',
158
+				'deleted',
159
+				esc_html__('Flag indicating ticket has been trashed.', 'event_espresso')
160
+			),
161
+			new GraphQLField(
162
+				'max',
163
+				'Int',
164
+				'max',
165
+				esc_html__(
166
+					'Maximum quantity of this ticket that can be purchased in one transaction',
167
+					'event_espresso'
168
+				),
169
+				[$this, 'parseInfiniteValue']
170
+			),
171
+			new GraphQLField(
172
+				'min',
173
+				'Int',
174
+				'min',
175
+				esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso')
176
+			),
177
+			new GraphQLField(
178
+				'name',
179
+				'String',
180
+				'name',
181
+				esc_html__('Ticket Name', 'event_espresso')
182
+			),
183
+			new GraphQLField(
184
+				'order',
185
+				'Int',
186
+				'order',
187
+				esc_html__('The order in which the Datetime is displayed', 'event_espresso')
188
+			),
189
+			new GraphQLOutputField(
190
+				'parent',
191
+				$this->name(),
192
+				null,
193
+				esc_html__('The parent ticket of the current ticket', 'event_espresso')
194
+			),
195
+			new GraphQLInputField(
196
+				'parent',
197
+				'ID',
198
+				null,
199
+				esc_html__('The parent ticket ID', 'event_espresso')
200
+			),
201
+			new GraphQLField(
202
+				'price',
203
+				'Float',
204
+				'price',
205
+				esc_html__('Final calculated price for ticket', 'event_espresso')
206
+			),
207
+			new GraphQLInputField(
208
+				'prices',
209
+				['list_of' => 'ID'],
210
+				null,
211
+				sprintf(
212
+					'%1$s %2$s',
213
+					esc_html__('Globally unique IDs of the prices related to the ticket.', 'event_espresso'),
214
+					esc_html__('Ignored if empty.', 'event_espresso')
215
+				)
216
+			),
217
+			new GraphQLField(
218
+				'quantity',
219
+				'Int',
220
+				'qty',
221
+				esc_html__('Quantity of this ticket that is available', 'event_espresso'),
222
+				[$this, 'parseInfiniteValue']
223
+			),
224
+			new GraphQLField(
225
+				'reserved',
226
+				'Int',
227
+				'reserved',
228
+				esc_html__(
229
+					'Quantity of this ticket that is reserved, but not yet fully purchased',
230
+					'event_espresso'
231
+				)
232
+			),
233
+			new GraphQLField(
234
+				'reverseCalculate',
235
+				'Boolean',
236
+				'reverse_calculate',
237
+				esc_html__(
238
+					'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.',
239
+					'event_espresso'
240
+				)
241
+			),
242
+			new GraphQLField(
243
+				'row',
244
+				'Int',
245
+				'row',
246
+				esc_html__('How tickets are displayed in the ui', 'event_espresso')
247
+			),
248
+			new GraphQLField(
249
+				'sold',
250
+				'Int',
251
+				'sold',
252
+				esc_html__('Number of this ticket sold', 'event_espresso')
253
+			),
254
+			new GraphQLOutputField(
255
+				'status',
256
+				$this->namespace . 'TicketStatusEnum',
257
+				'ticket_status',
258
+				esc_html__('Ticket status', 'event_espresso')
259
+			),
260
+			new GraphQLField(
261
+				'startDate',
262
+				'String',
263
+				'start_date',
264
+				esc_html__('Start date and time of the Ticket', 'event_espresso'),
265
+				[$this, 'formatDatetime']
266
+			),
267
+			new GraphQLField(
268
+				'uses',
269
+				'Int',
270
+				'uses',
271
+				esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
272
+				[$this, 'parseInfiniteValue']
273
+			),
274
+			new GraphQLOutputField(
275
+				'wpUser',
276
+				'User',
277
+				null,
278
+				esc_html__('Ticket Creator', 'event_espresso')
279
+			),
280
+			new GraphQLInputField(
281
+				'wpUser',
282
+				'Int',
283
+				null,
284
+				esc_html__('Ticket Creator ID', 'event_espresso')
285
+			),
286
+		];
287
+	}
288 288
 
289 289
 
290
-    /**
291
-     * @param EE_Ticket   $source  The source that's passed down the GraphQL queries
292
-     * @param array       $args    The inputArgs on the field
293
-     * @param AppContext  $context The AppContext passed down the GraphQL tree
294
-     * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
295
-     * @return string
296
-     * @throws Exception
297
-     * @throws InvalidArgumentException
298
-     * @throws InvalidDataTypeException
299
-     * @throws InvalidInterfaceException
300
-     * @throws ReflectionException
301
-     * @throws UserError
302
-     * @throws UnexpectedEntityException
303
-     * @since $VID:$
304
-     */
305
-    public function getIsSoldOut(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info)
306
-    {
307
-        return $source->ticket_status() === EE_Ticket::sold_out;
308
-    }
290
+	/**
291
+	 * @param EE_Ticket   $source  The source that's passed down the GraphQL queries
292
+	 * @param array       $args    The inputArgs on the field
293
+	 * @param AppContext  $context The AppContext passed down the GraphQL tree
294
+	 * @param ResolveInfo $info    The ResolveInfo passed down the GraphQL tree
295
+	 * @return string
296
+	 * @throws Exception
297
+	 * @throws InvalidArgumentException
298
+	 * @throws InvalidDataTypeException
299
+	 * @throws InvalidInterfaceException
300
+	 * @throws ReflectionException
301
+	 * @throws UserError
302
+	 * @throws UnexpectedEntityException
303
+	 * @since $VID:$
304
+	 */
305
+	public function getIsSoldOut(EE_Ticket $source, array $args, AppContext $context, ResolveInfo $info)
306
+	{
307
+		return $source->ticket_status() === EE_Ticket::sold_out;
308
+	}
309 309
 
310 310
 
311
-    /**
312
-     * @param array $inputFields The mutation input fields.
313
-     * @throws InvalidArgumentException
314
-     * @throws ReflectionException
315
-     * @since $VID:$
316
-     */
317
-    public function registerMutations(array $inputFields)
318
-    {
319
-        // Register mutation to update an entity.
320
-        register_graphql_mutation(
321
-            'update' . $this->name(),
322
-            [
323
-                'inputFields'         => $inputFields,
324
-                'outputFields'        => [
325
-                    lcfirst($this->name()) => [
326
-                        'type'    => $this->name(),
327
-                        'resolve' => [$this, 'resolveFromPayload'],
328
-                    ],
329
-                ],
330
-                'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this),
331
-            ]
332
-        );
333
-        // Register mutation to delete an entity.
334
-        register_graphql_mutation(
335
-            'delete' . $this->name(),
336
-            [
337
-                'inputFields'         => [
338
-                    'id'                => $inputFields['id'],
339
-                    'deletePermanently' => [
340
-                        'type'        => 'Boolean',
341
-                        'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'),
342
-                    ],
343
-                ],
344
-                'outputFields'        => [
345
-                    lcfirst($this->name()) => [
346
-                        'type'        => $this->name(),
347
-                        'description' => esc_html__('The object before it was deleted', 'event_espresso'),
348
-                        'resolve'     => static function ($payload) {
349
-                            $deleted = (object) $payload['deleted'];
311
+	/**
312
+	 * @param array $inputFields The mutation input fields.
313
+	 * @throws InvalidArgumentException
314
+	 * @throws ReflectionException
315
+	 * @since $VID:$
316
+	 */
317
+	public function registerMutations(array $inputFields)
318
+	{
319
+		// Register mutation to update an entity.
320
+		register_graphql_mutation(
321
+			'update' . $this->name(),
322
+			[
323
+				'inputFields'         => $inputFields,
324
+				'outputFields'        => [
325
+					lcfirst($this->name()) => [
326
+						'type'    => $this->name(),
327
+						'resolve' => [$this, 'resolveFromPayload'],
328
+					],
329
+				],
330
+				'mutateAndGetPayload' => TicketUpdate::mutateAndGetPayload($this->model, $this),
331
+			]
332
+		);
333
+		// Register mutation to delete an entity.
334
+		register_graphql_mutation(
335
+			'delete' . $this->name(),
336
+			[
337
+				'inputFields'         => [
338
+					'id'                => $inputFields['id'],
339
+					'deletePermanently' => [
340
+						'type'        => 'Boolean',
341
+						'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'),
342
+					],
343
+				],
344
+				'outputFields'        => [
345
+					lcfirst($this->name()) => [
346
+						'type'        => $this->name(),
347
+						'description' => esc_html__('The object before it was deleted', 'event_espresso'),
348
+						'resolve'     => static function ($payload) {
349
+							$deleted = (object) $payload['deleted'];
350 350
 
351
-                            return ! empty($deleted) ? $deleted : null;
352
-                        },
353
-                    ],
354
-                ],
355
-                'mutateAndGetPayload' => TicketDelete::mutateAndGetPayload($this->model, $this),
356
-            ]
357
-        );
351
+							return ! empty($deleted) ? $deleted : null;
352
+						},
353
+					],
354
+				],
355
+				'mutateAndGetPayload' => TicketDelete::mutateAndGetPayload($this->model, $this),
356
+			]
357
+		);
358 358
 
359
-        // remove primary key from input.
360
-        unset($inputFields['id']);
361
-        // Register mutation to update an entity.
362
-        register_graphql_mutation(
363
-            'create' . $this->name(),
364
-            [
365
-                'inputFields'         => $inputFields,
366
-                'outputFields'        => [
367
-                    lcfirst($this->name()) => [
368
-                        'type'    => $this->name(),
369
-                        'resolve' => [$this, 'resolveFromPayload'],
370
-                    ],
371
-                ],
372
-                'mutateAndGetPayload' => TicketCreate::mutateAndGetPayload($this->model, $this),
373
-            ]
374
-        );
375
-    }
359
+		// remove primary key from input.
360
+		unset($inputFields['id']);
361
+		// Register mutation to update an entity.
362
+		register_graphql_mutation(
363
+			'create' . $this->name(),
364
+			[
365
+				'inputFields'         => $inputFields,
366
+				'outputFields'        => [
367
+					lcfirst($this->name()) => [
368
+						'type'    => $this->name(),
369
+						'resolve' => [$this, 'resolveFromPayload'],
370
+					],
371
+				],
372
+				'mutateAndGetPayload' => TicketCreate::mutateAndGetPayload($this->model, $this),
373
+			]
374
+		);
375
+	}
376 376
 }
Please login to merge, or discard this patch.