@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * FieldResolver constructor. |
56 | 56 | * |
57 | - * @param mixed $model The model instance. |
|
57 | + * @param \EEM_Base $model The model instance. |
|
58 | 58 | * @param array $fields The fields registered for the type. |
59 | 59 | */ |
60 | 60 | public function __construct($model, array $fields) |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | |
66 | 66 | |
67 | 67 | /** |
68 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
68 | + * @param EE_Base_Class $source The source that's passed down the GraphQL queries |
|
69 | 69 | * @param array $args The inputArgs on the field |
70 | 70 | * @param AppContext $context The AppContext passed down the GraphQL tree |
71 | 71 | * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
@@ -12,7 +12,6 @@ discard block |
||
12 | 12 | use EEM_State; |
13 | 13 | use EEM_Country; |
14 | 14 | use EE_Error; |
15 | - |
|
16 | 15 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
17 | 16 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
18 | 17 | use EventEspresso\core\exceptions\UnexpectedEntityException; |
@@ -21,7 +20,6 @@ discard block |
||
21 | 20 | use Exception; |
22 | 21 | use InvalidArgumentException; |
23 | 22 | use ReflectionException; |
24 | - |
|
25 | 23 | use WPGraphQL\Data\DataSource; |
26 | 24 | use GraphQL\Deferred; |
27 | 25 | use GraphQL\Error\UserError; |
@@ -40,200 +40,200 @@ |
||
40 | 40 | class FieldResolver extends ResolverBase |
41 | 41 | { |
42 | 42 | |
43 | - /** |
|
44 | - * @var mixed $model |
|
45 | - */ |
|
46 | - protected $model; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array $fields . |
|
50 | - */ |
|
51 | - protected $fields; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * FieldResolver constructor. |
|
56 | - * |
|
57 | - * @param mixed $model The model instance. |
|
58 | - * @param array $fields The fields registered for the type. |
|
59 | - */ |
|
60 | - public function __construct($model, array $fields) |
|
61 | - { |
|
62 | - $this->model = $model; |
|
63 | - $this->fields = $fields; |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
69 | - * @param array $args The inputArgs on the field |
|
70 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
71 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
72 | - * @return string |
|
73 | - * @throws EE_Error |
|
74 | - * @throws Exception |
|
75 | - * @throws InvalidArgumentException |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - * @throws ReflectionException |
|
79 | - * @throws UserError |
|
80 | - * @throws UnexpectedEntityException |
|
81 | - * @since $VID:$ |
|
82 | - */ |
|
83 | - public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
|
84 | - { |
|
85 | - $fieldName = $info->fieldName; |
|
86 | - $field = isset($this->fields[ $fieldName ]) ? $this->fields[ $fieldName ] : null; |
|
87 | - // Field should exist in teh registered fields |
|
88 | - if ($field instanceof GraphQLField) { |
|
89 | - // check if the field should be resolved. |
|
90 | - if (! $field->shouldResolve()) { |
|
91 | - return null; |
|
92 | - } |
|
93 | - // Give priority to the internal resolver. |
|
94 | - if ($field->hasInternalResolver()) { |
|
95 | - return $field->resolve($source, $args, $context, $info); |
|
96 | - } |
|
97 | - // Check if the field has a key mapped to model. |
|
98 | - if (! empty($field->key())) { |
|
99 | - $value = $source->{$field->key()}(); |
|
100 | - return $field->mayBeFormatValue($value); |
|
101 | - } |
|
102 | - switch ($fieldName) { |
|
103 | - case 'parent': |
|
104 | - return $this->resolveParent($source); |
|
105 | - case 'event': |
|
106 | - return $this->resolveEvent($source, $args, $context); |
|
107 | - case 'wpUser': |
|
108 | - return $this->resolveWpUser($source, $args, $context); |
|
109 | - case 'state': // Venue |
|
110 | - return $this->resolveState($source); |
|
111 | - case 'country': // State, Venue |
|
112 | - return $this->resolveCountry($source); |
|
113 | - } |
|
114 | - } |
|
115 | - return null; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param mixed $source |
|
121 | - * @param $args |
|
122 | - * @param $context |
|
123 | - * @return Deferred|null |
|
124 | - * @throws Exception |
|
125 | - * @since $VID:$ |
|
126 | - */ |
|
127 | - public function resolveWpUser($source, $args, $context) |
|
128 | - { |
|
129 | - $user_id = $source->wp_user(); |
|
130 | - return $user_id |
|
131 | - ? DataSource::resolve_user($user_id, $context) |
|
132 | - : null; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * @param mixed $source |
|
138 | - * @return EE_Base_Class|null |
|
139 | - * @throws EE_Error |
|
140 | - * @throws InvalidArgumentException |
|
141 | - * @throws InvalidDataTypeException |
|
142 | - * @throws InvalidInterfaceException |
|
143 | - * @throws ReflectionException |
|
144 | - * @since $VID:$ |
|
145 | - */ |
|
146 | - public function resolveParent($source) |
|
147 | - { |
|
148 | - return $this->model->get_one_by_ID($source->parent()); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param mixed $source |
|
154 | - * @param $args |
|
155 | - * @param $context |
|
156 | - * @return Deferred|null |
|
157 | - * @throws EE_Error |
|
158 | - * @throws InvalidArgumentException |
|
159 | - * @throws InvalidDataTypeException |
|
160 | - * @throws InvalidInterfaceException |
|
161 | - * @throws ReflectionException |
|
162 | - * @throws UserError |
|
163 | - * @throws UnexpectedEntityException |
|
164 | - * @since $VID:$ |
|
165 | - */ |
|
166 | - public function resolveEvent($source, $args, $context) |
|
167 | - { |
|
168 | - switch (true) { |
|
169 | - case $source instanceof EE_Datetime: |
|
170 | - $event = $source->event(); |
|
171 | - break; |
|
172 | - case $source instanceof EE_Venue: |
|
173 | - case $source instanceof EE_Ticket: |
|
174 | - $event = $source->get_related_event(); |
|
175 | - break; |
|
176 | - default: |
|
177 | - $event = null; |
|
178 | - break; |
|
179 | - } |
|
180 | - return $event instanceof EE_Event |
|
181 | - ? DataSource::resolve_post_object($event->ID(), $context) |
|
182 | - : null; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param mixed $source The source instance. |
|
188 | - * @return EE_Base_Class|null |
|
189 | - * @throws EE_Error |
|
190 | - * @throws InvalidArgumentException |
|
191 | - * @throws InvalidDataTypeException |
|
192 | - * @throws InvalidInterfaceException |
|
193 | - * @since $VID:$ |
|
194 | - */ |
|
195 | - public function resolveState($source) |
|
196 | - { |
|
197 | - switch (true) { |
|
198 | - case $source instanceof EE_Attendee: |
|
199 | - case $source instanceof EE_Venue: |
|
200 | - $state_id = $source->state_ID(); |
|
201 | - break; |
|
202 | - default: |
|
203 | - $state_id = null; |
|
204 | - break; |
|
205 | - } |
|
206 | - return $state_id |
|
207 | - ? EEM_State::instance()->get_one_by_ID($state_id) |
|
208 | - : null; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * @param mixed $source The source instance. |
|
214 | - * @return EE_Base_Class|null |
|
215 | - * @throws EE_Error |
|
216 | - * @throws InvalidArgumentException |
|
217 | - * @throws InvalidDataTypeException |
|
218 | - * @throws InvalidInterfaceException |
|
219 | - * @since $VID:$ |
|
220 | - */ |
|
221 | - public function resolveCountry($source) |
|
222 | - { |
|
223 | - switch (true) { |
|
224 | - case $source instanceof EE_State: |
|
225 | - $country_iso = $source->country_iso(); |
|
226 | - break; |
|
227 | - case $source instanceof EE_Venue: |
|
228 | - $country_iso = $source->country_ID(); |
|
229 | - break; |
|
230 | - default: |
|
231 | - $country_iso = null; |
|
232 | - break; |
|
233 | - } |
|
234 | - |
|
235 | - return $country_iso |
|
236 | - ? EEM_Country::instance()->get_one_by_ID($country_iso) |
|
237 | - : null; |
|
238 | - } |
|
43 | + /** |
|
44 | + * @var mixed $model |
|
45 | + */ |
|
46 | + protected $model; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array $fields . |
|
50 | + */ |
|
51 | + protected $fields; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * FieldResolver constructor. |
|
56 | + * |
|
57 | + * @param mixed $model The model instance. |
|
58 | + * @param array $fields The fields registered for the type. |
|
59 | + */ |
|
60 | + public function __construct($model, array $fields) |
|
61 | + { |
|
62 | + $this->model = $model; |
|
63 | + $this->fields = $fields; |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
69 | + * @param array $args The inputArgs on the field |
|
70 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
71 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
72 | + * @return string |
|
73 | + * @throws EE_Error |
|
74 | + * @throws Exception |
|
75 | + * @throws InvalidArgumentException |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + * @throws ReflectionException |
|
79 | + * @throws UserError |
|
80 | + * @throws UnexpectedEntityException |
|
81 | + * @since $VID:$ |
|
82 | + */ |
|
83 | + public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
|
84 | + { |
|
85 | + $fieldName = $info->fieldName; |
|
86 | + $field = isset($this->fields[ $fieldName ]) ? $this->fields[ $fieldName ] : null; |
|
87 | + // Field should exist in teh registered fields |
|
88 | + if ($field instanceof GraphQLField) { |
|
89 | + // check if the field should be resolved. |
|
90 | + if (! $field->shouldResolve()) { |
|
91 | + return null; |
|
92 | + } |
|
93 | + // Give priority to the internal resolver. |
|
94 | + if ($field->hasInternalResolver()) { |
|
95 | + return $field->resolve($source, $args, $context, $info); |
|
96 | + } |
|
97 | + // Check if the field has a key mapped to model. |
|
98 | + if (! empty($field->key())) { |
|
99 | + $value = $source->{$field->key()}(); |
|
100 | + return $field->mayBeFormatValue($value); |
|
101 | + } |
|
102 | + switch ($fieldName) { |
|
103 | + case 'parent': |
|
104 | + return $this->resolveParent($source); |
|
105 | + case 'event': |
|
106 | + return $this->resolveEvent($source, $args, $context); |
|
107 | + case 'wpUser': |
|
108 | + return $this->resolveWpUser($source, $args, $context); |
|
109 | + case 'state': // Venue |
|
110 | + return $this->resolveState($source); |
|
111 | + case 'country': // State, Venue |
|
112 | + return $this->resolveCountry($source); |
|
113 | + } |
|
114 | + } |
|
115 | + return null; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param mixed $source |
|
121 | + * @param $args |
|
122 | + * @param $context |
|
123 | + * @return Deferred|null |
|
124 | + * @throws Exception |
|
125 | + * @since $VID:$ |
|
126 | + */ |
|
127 | + public function resolveWpUser($source, $args, $context) |
|
128 | + { |
|
129 | + $user_id = $source->wp_user(); |
|
130 | + return $user_id |
|
131 | + ? DataSource::resolve_user($user_id, $context) |
|
132 | + : null; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * @param mixed $source |
|
138 | + * @return EE_Base_Class|null |
|
139 | + * @throws EE_Error |
|
140 | + * @throws InvalidArgumentException |
|
141 | + * @throws InvalidDataTypeException |
|
142 | + * @throws InvalidInterfaceException |
|
143 | + * @throws ReflectionException |
|
144 | + * @since $VID:$ |
|
145 | + */ |
|
146 | + public function resolveParent($source) |
|
147 | + { |
|
148 | + return $this->model->get_one_by_ID($source->parent()); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param mixed $source |
|
154 | + * @param $args |
|
155 | + * @param $context |
|
156 | + * @return Deferred|null |
|
157 | + * @throws EE_Error |
|
158 | + * @throws InvalidArgumentException |
|
159 | + * @throws InvalidDataTypeException |
|
160 | + * @throws InvalidInterfaceException |
|
161 | + * @throws ReflectionException |
|
162 | + * @throws UserError |
|
163 | + * @throws UnexpectedEntityException |
|
164 | + * @since $VID:$ |
|
165 | + */ |
|
166 | + public function resolveEvent($source, $args, $context) |
|
167 | + { |
|
168 | + switch (true) { |
|
169 | + case $source instanceof EE_Datetime: |
|
170 | + $event = $source->event(); |
|
171 | + break; |
|
172 | + case $source instanceof EE_Venue: |
|
173 | + case $source instanceof EE_Ticket: |
|
174 | + $event = $source->get_related_event(); |
|
175 | + break; |
|
176 | + default: |
|
177 | + $event = null; |
|
178 | + break; |
|
179 | + } |
|
180 | + return $event instanceof EE_Event |
|
181 | + ? DataSource::resolve_post_object($event->ID(), $context) |
|
182 | + : null; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param mixed $source The source instance. |
|
188 | + * @return EE_Base_Class|null |
|
189 | + * @throws EE_Error |
|
190 | + * @throws InvalidArgumentException |
|
191 | + * @throws InvalidDataTypeException |
|
192 | + * @throws InvalidInterfaceException |
|
193 | + * @since $VID:$ |
|
194 | + */ |
|
195 | + public function resolveState($source) |
|
196 | + { |
|
197 | + switch (true) { |
|
198 | + case $source instanceof EE_Attendee: |
|
199 | + case $source instanceof EE_Venue: |
|
200 | + $state_id = $source->state_ID(); |
|
201 | + break; |
|
202 | + default: |
|
203 | + $state_id = null; |
|
204 | + break; |
|
205 | + } |
|
206 | + return $state_id |
|
207 | + ? EEM_State::instance()->get_one_by_ID($state_id) |
|
208 | + : null; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * @param mixed $source The source instance. |
|
214 | + * @return EE_Base_Class|null |
|
215 | + * @throws EE_Error |
|
216 | + * @throws InvalidArgumentException |
|
217 | + * @throws InvalidDataTypeException |
|
218 | + * @throws InvalidInterfaceException |
|
219 | + * @since $VID:$ |
|
220 | + */ |
|
221 | + public function resolveCountry($source) |
|
222 | + { |
|
223 | + switch (true) { |
|
224 | + case $source instanceof EE_State: |
|
225 | + $country_iso = $source->country_iso(); |
|
226 | + break; |
|
227 | + case $source instanceof EE_Venue: |
|
228 | + $country_iso = $source->country_ID(); |
|
229 | + break; |
|
230 | + default: |
|
231 | + $country_iso = null; |
|
232 | + break; |
|
233 | + } |
|
234 | + |
|
235 | + return $country_iso |
|
236 | + ? EEM_Country::instance()->get_one_by_ID($country_iso) |
|
237 | + : null; |
|
238 | + } |
|
239 | 239 | } |
240 | 240 | \ No newline at end of file |
@@ -83,11 +83,11 @@ discard block |
||
83 | 83 | public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
84 | 84 | { |
85 | 85 | $fieldName = $info->fieldName; |
86 | - $field = isset($this->fields[ $fieldName ]) ? $this->fields[ $fieldName ] : null; |
|
86 | + $field = isset($this->fields[$fieldName]) ? $this->fields[$fieldName] : null; |
|
87 | 87 | // Field should exist in teh registered fields |
88 | 88 | if ($field instanceof GraphQLField) { |
89 | 89 | // check if the field should be resolved. |
90 | - if (! $field->shouldResolve()) { |
|
90 | + if ( ! $field->shouldResolve()) { |
|
91 | 91 | return null; |
92 | 92 | } |
93 | 93 | // Give priority to the internal resolver. |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | return $field->resolve($source, $args, $context, $info); |
96 | 96 | } |
97 | 97 | // Check if the field has a key mapped to model. |
98 | - if (! empty($field->key())) { |
|
98 | + if ( ! empty($field->key())) { |
|
99 | 99 | $value = $source->{$field->key()}(); |
100 | 100 | return $field->mayBeFormatValue($value); |
101 | 101 | } |
@@ -15,194 +15,194 @@ |
||
15 | 15 | class GraphQLField |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var array $caps |
|
20 | - */ |
|
21 | - protected $caps; |
|
22 | - |
|
23 | - /** |
|
24 | - * @var string $description |
|
25 | - */ |
|
26 | - protected $description; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var callable $formatter |
|
30 | - */ |
|
31 | - protected $formatter; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var string|null $key |
|
35 | - */ |
|
36 | - protected $key; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $name |
|
40 | - */ |
|
41 | - protected $name; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var callable $resolve |
|
45 | - */ |
|
46 | - protected $resolver; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var string|string[] $type |
|
50 | - */ |
|
51 | - protected $type; |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
18 | + /** |
|
19 | + * @var array $caps |
|
20 | + */ |
|
21 | + protected $caps; |
|
22 | + |
|
23 | + /** |
|
24 | + * @var string $description |
|
25 | + */ |
|
26 | + protected $description; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var callable $formatter |
|
30 | + */ |
|
31 | + protected $formatter; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var string|null $key |
|
35 | + */ |
|
36 | + protected $key; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $name |
|
40 | + */ |
|
41 | + protected $name; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var callable $resolve |
|
45 | + */ |
|
46 | + protected $resolver; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var string|string[] $type |
|
50 | + */ |
|
51 | + protected $type; |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | 55 | * @param string $name |
56 | 56 | * @param string|string[] $type |
57 | - * @param string|null $key |
|
58 | - * @param string $description |
|
59 | - * @param callable|null $formatter |
|
60 | - * @param callable|null $resolver |
|
61 | - * @param array $caps |
|
62 | - */ |
|
63 | - public function __construct( |
|
57 | + * @param string|null $key |
|
58 | + * @param string $description |
|
59 | + * @param callable|null $formatter |
|
60 | + * @param callable|null $resolver |
|
61 | + * @param array $caps |
|
62 | + */ |
|
63 | + public function __construct( |
|
64 | 64 | $name, |
65 | - $type, |
|
66 | - $key = null, |
|
67 | - $description = '', |
|
68 | - callable $formatter = null, |
|
69 | - callable $resolver = null, |
|
70 | - array $caps = [] |
|
71 | - ) { |
|
72 | - $this->key = $key; |
|
73 | - $this->name = $name; |
|
74 | - $this->type = $type; |
|
75 | - $this->description = $description; |
|
76 | - $this->formatter = $formatter; |
|
77 | - $this->resolver = $resolver; |
|
78 | - $this->caps = $caps; |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public function caps() |
|
86 | - { |
|
87 | - return $this->caps; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @return string |
|
93 | - */ |
|
94 | - public function description() |
|
95 | - { |
|
96 | - return $this->description; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - public function key() |
|
104 | - { |
|
105 | - return $this->key; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function name() |
|
113 | - { |
|
114 | - return $this->name; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return string|string[] |
|
120 | - */ |
|
121 | - public function type() |
|
122 | - { |
|
123 | - return $this->type; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Whether the field should resolve |
|
131 | - * based on the user caps etc. |
|
132 | - * |
|
133 | - * @return boolean |
|
134 | - */ |
|
135 | - public function shouldResolve() |
|
136 | - { |
|
137 | - foreach ($this->caps as $cap) { |
|
138 | - if (! current_user_can($cap)) { |
|
139 | - return false; |
|
140 | - } |
|
141 | - } |
|
142 | - return true; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Whether the field has an explicit resolver set. |
|
148 | - * |
|
149 | - * @return boolean |
|
150 | - */ |
|
151 | - public function hasInternalResolver() |
|
152 | - { |
|
153 | - return is_callable($this->resolver); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Whether the field has an explicit resolver set. |
|
159 | - * |
|
160 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
161 | - * @param array $args The inputArgs on the field |
|
162 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
163 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
164 | - * @return mixed |
|
165 | - * @throws LogicException |
|
166 | - */ |
|
167 | - public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
|
168 | - { |
|
169 | - if (! $this->hasInternalResolver()) { |
|
170 | - throw new LogicException('GraphQLField has no internal resolver.'); |
|
171 | - } |
|
172 | - // dynamic methods using $this don't play nice |
|
173 | - // so capture resolver to a single var first |
|
174 | - $resolver = $this->resolver; |
|
175 | - return $resolver($source, $args, $context, $info); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Checks if the format callback is set. |
|
181 | - * If yes, then uses it to format the value. |
|
182 | - * |
|
183 | - * @param mixed $value |
|
184 | - * @return mixed The formatted value. |
|
185 | - */ |
|
186 | - public function mayBeFormatValue($value) |
|
187 | - { |
|
188 | - if (is_callable($this->formatter)) { |
|
189 | - // dynamic methods using $this don't play nice |
|
190 | - // so capture formatter to a single var first |
|
191 | - $formatter = $this->formatter; |
|
192 | - return $formatter($value); |
|
193 | - } |
|
194 | - return $value; |
|
195 | - } |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * Convert the field to array to be |
|
200 | - * able to pass as config to WP GraphQL |
|
201 | - * |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public function toArray() |
|
205 | - { |
|
206 | - return get_object_vars($this); |
|
207 | - } |
|
65 | + $type, |
|
66 | + $key = null, |
|
67 | + $description = '', |
|
68 | + callable $formatter = null, |
|
69 | + callable $resolver = null, |
|
70 | + array $caps = [] |
|
71 | + ) { |
|
72 | + $this->key = $key; |
|
73 | + $this->name = $name; |
|
74 | + $this->type = $type; |
|
75 | + $this->description = $description; |
|
76 | + $this->formatter = $formatter; |
|
77 | + $this->resolver = $resolver; |
|
78 | + $this->caps = $caps; |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public function caps() |
|
86 | + { |
|
87 | + return $this->caps; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @return string |
|
93 | + */ |
|
94 | + public function description() |
|
95 | + { |
|
96 | + return $this->description; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + public function key() |
|
104 | + { |
|
105 | + return $this->key; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function name() |
|
113 | + { |
|
114 | + return $this->name; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return string|string[] |
|
120 | + */ |
|
121 | + public function type() |
|
122 | + { |
|
123 | + return $this->type; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Whether the field should resolve |
|
131 | + * based on the user caps etc. |
|
132 | + * |
|
133 | + * @return boolean |
|
134 | + */ |
|
135 | + public function shouldResolve() |
|
136 | + { |
|
137 | + foreach ($this->caps as $cap) { |
|
138 | + if (! current_user_can($cap)) { |
|
139 | + return false; |
|
140 | + } |
|
141 | + } |
|
142 | + return true; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Whether the field has an explicit resolver set. |
|
148 | + * |
|
149 | + * @return boolean |
|
150 | + */ |
|
151 | + public function hasInternalResolver() |
|
152 | + { |
|
153 | + return is_callable($this->resolver); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Whether the field has an explicit resolver set. |
|
159 | + * |
|
160 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
161 | + * @param array $args The inputArgs on the field |
|
162 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
163 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
164 | + * @return mixed |
|
165 | + * @throws LogicException |
|
166 | + */ |
|
167 | + public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
|
168 | + { |
|
169 | + if (! $this->hasInternalResolver()) { |
|
170 | + throw new LogicException('GraphQLField has no internal resolver.'); |
|
171 | + } |
|
172 | + // dynamic methods using $this don't play nice |
|
173 | + // so capture resolver to a single var first |
|
174 | + $resolver = $this->resolver; |
|
175 | + return $resolver($source, $args, $context, $info); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Checks if the format callback is set. |
|
181 | + * If yes, then uses it to format the value. |
|
182 | + * |
|
183 | + * @param mixed $value |
|
184 | + * @return mixed The formatted value. |
|
185 | + */ |
|
186 | + public function mayBeFormatValue($value) |
|
187 | + { |
|
188 | + if (is_callable($this->formatter)) { |
|
189 | + // dynamic methods using $this don't play nice |
|
190 | + // so capture formatter to a single var first |
|
191 | + $formatter = $this->formatter; |
|
192 | + return $formatter($value); |
|
193 | + } |
|
194 | + return $value; |
|
195 | + } |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * Convert the field to array to be |
|
200 | + * able to pass as config to WP GraphQL |
|
201 | + * |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public function toArray() |
|
205 | + { |
|
206 | + return get_object_vars($this); |
|
207 | + } |
|
208 | 208 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | public function shouldResolve() |
136 | 136 | { |
137 | 137 | foreach ($this->caps as $cap) { |
138 | - if (! current_user_can($cap)) { |
|
138 | + if ( ! current_user_can($cap)) { |
|
139 | 139 | return false; |
140 | 140 | } |
141 | 141 | } |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function resolve($source, array $args, AppContext $context, ResolveInfo $info) |
168 | 168 | { |
169 | - if (! $this->hasInternalResolver()) { |
|
169 | + if ( ! $this->hasInternalResolver()) { |
|
170 | 170 | throw new LogicException('GraphQLField has no internal resolver.'); |
171 | 171 | } |
172 | 172 | // dynamic methods using $this don't play nice |
@@ -32,166 +32,166 @@ |
||
32 | 32 | class Event extends TypeBase |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Event constructor. |
|
37 | - * |
|
38 | - * @param EEM_Event $event_model |
|
39 | - */ |
|
40 | - public function __construct(EEM_Event $event_model) |
|
41 | - { |
|
42 | - $this->model = $event_model; |
|
43 | - $this->setName('Event'); |
|
44 | - $this->setIsCustomPostType(true); |
|
45 | - parent::__construct(); |
|
46 | - } |
|
35 | + /** |
|
36 | + * Event constructor. |
|
37 | + * |
|
38 | + * @param EEM_Event $event_model |
|
39 | + */ |
|
40 | + public function __construct(EEM_Event $event_model) |
|
41 | + { |
|
42 | + $this->model = $event_model; |
|
43 | + $this->setName('Event'); |
|
44 | + $this->setIsCustomPostType(true); |
|
45 | + parent::__construct(); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * @return GraphQLField[] |
|
51 | - * @since $VID:$ |
|
52 | - */ |
|
53 | - public function getFields() |
|
54 | - { |
|
55 | - return [ |
|
56 | - new GraphQLField( |
|
57 | - 'name', |
|
58 | - 'String', |
|
59 | - 'name', |
|
60 | - __('Event Name', 'event_espresso') |
|
61 | - ), |
|
62 | - new GraphQLField( |
|
63 | - 'desc', |
|
64 | - 'String', |
|
65 | - 'description', |
|
66 | - __('Event Description', 'event_espresso') |
|
67 | - ), |
|
68 | - new GraphQLField( |
|
69 | - 'shortDesc', |
|
70 | - 'String', |
|
71 | - 'short_description', |
|
72 | - __('Event Short Description', 'event_espresso') |
|
73 | - ), |
|
74 | - new GraphQLField( |
|
75 | - 'created', |
|
76 | - 'String', |
|
77 | - 'created', |
|
78 | - __('Date/Time Event Created', 'event_espresso') |
|
79 | - ), |
|
80 | - new GraphQLField( |
|
81 | - 'wpUser', |
|
82 | - 'User', |
|
83 | - null, |
|
84 | - __('Event Creator', 'event_espresso') |
|
85 | - ), |
|
86 | - new GraphQLField( |
|
87 | - 'order', |
|
88 | - 'Int', |
|
89 | - 'order', |
|
90 | - __('Event Menu Order', 'event_espresso') |
|
91 | - ), |
|
92 | - new GraphQLField( |
|
93 | - 'displayDesc', |
|
94 | - 'Boolean', |
|
95 | - 'display_description', |
|
96 | - __('Display Description Flag', 'event_espresso') |
|
97 | - ), |
|
98 | - new GraphQLField( |
|
99 | - 'displayTicketSelector', |
|
100 | - 'Boolean', |
|
101 | - 'display_ticket_selector', |
|
102 | - __('Display Ticket Selector Flag', 'event_espresso') |
|
103 | - ), |
|
104 | - new GraphQLField( |
|
105 | - 'visibleOn', |
|
106 | - 'String', |
|
107 | - 'visible_on', |
|
108 | - __('Event Visible Date', 'event_espresso') |
|
109 | - ), |
|
110 | - new GraphQLField( |
|
111 | - 'additionalLimit', |
|
112 | - 'String', |
|
113 | - 'additional_limit', |
|
114 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso') |
|
115 | - ), |
|
116 | - new GraphQLField( |
|
117 | - 'phone', |
|
118 | - 'String', |
|
119 | - 'phone', |
|
120 | - __('Event Phone Number', 'event_espresso') |
|
121 | - ), |
|
122 | - new GraphQLField( |
|
123 | - 'memberOnly', |
|
124 | - 'Boolean', |
|
125 | - 'member_only', |
|
126 | - __('Member-Only Event Flag', 'event_espresso') |
|
127 | - ), |
|
128 | - new GraphQLField( |
|
129 | - 'allowOverflow', |
|
130 | - 'Boolean', |
|
131 | - 'allow_overflow', |
|
132 | - __('Allow Overflow on Event', 'event_espresso') |
|
133 | - ), |
|
134 | - new GraphQLField( |
|
135 | - 'timezoneString', |
|
136 | - 'String', |
|
137 | - 'timezone_string', |
|
138 | - __('Timezone (name) for Event times', 'event_espresso') |
|
139 | - ), |
|
140 | - new GraphQLField( |
|
141 | - 'externalUrl', |
|
142 | - 'String', |
|
143 | - 'external_url', |
|
144 | - __('URL of Event Page if hosted elsewhere', 'event_espresso') |
|
145 | - ), |
|
146 | - new GraphQLField( |
|
147 | - 'donations', |
|
148 | - 'Boolean', |
|
149 | - 'donations', |
|
150 | - __('Accept Donations?', 'event_espresso') |
|
151 | - ), |
|
152 | - new GraphQLField( |
|
153 | - 'isSoldOut', |
|
154 | - 'Boolean', |
|
155 | - 'is_sold_out', |
|
156 | - __('Flag indicating whether the tickets sold for the event, met or exceed the registration limit', |
|
157 | - 'event_espresso') |
|
158 | - ), |
|
159 | - new GraphQLField( |
|
160 | - 'isPostponed', |
|
161 | - 'Boolean', |
|
162 | - 'is_postponed', |
|
163 | - __('Flag indicating whether the event is marked as postponed', 'event_espresso') |
|
164 | - ), |
|
165 | - new GraphQLField( |
|
166 | - 'isCancelled', |
|
167 | - 'Boolean', |
|
168 | - 'is_cancelled', |
|
169 | - __('Flag indicating whether the event is marked as cancelled', 'event_espresso') |
|
170 | - ), |
|
171 | - new GraphQLField( |
|
172 | - 'isUpcoming', |
|
173 | - 'Boolean', |
|
174 | - 'is_upcoming', |
|
175 | - __('Whether the event is upcoming', 'event_espresso') |
|
176 | - ), |
|
177 | - new GraphQLField( |
|
178 | - 'isActive', |
|
179 | - 'Boolean', |
|
180 | - 'is_active', |
|
181 | - __('Flag indicating event is active', 'event_espresso') |
|
182 | - ), |
|
183 | - new GraphQLField( |
|
184 | - 'isInactive', |
|
185 | - 'Boolean', |
|
186 | - 'is_inactive', |
|
187 | - __('Flag indicating event is inactive', 'event_espresso') |
|
188 | - ), |
|
189 | - new GraphQLField( |
|
190 | - 'isExpired', |
|
191 | - 'Boolean', |
|
192 | - 'is_expired', |
|
193 | - __('Flag indicating event is expired or not', 'event_espresso') |
|
194 | - ), |
|
195 | - ]; |
|
196 | - } |
|
49 | + /** |
|
50 | + * @return GraphQLField[] |
|
51 | + * @since $VID:$ |
|
52 | + */ |
|
53 | + public function getFields() |
|
54 | + { |
|
55 | + return [ |
|
56 | + new GraphQLField( |
|
57 | + 'name', |
|
58 | + 'String', |
|
59 | + 'name', |
|
60 | + __('Event Name', 'event_espresso') |
|
61 | + ), |
|
62 | + new GraphQLField( |
|
63 | + 'desc', |
|
64 | + 'String', |
|
65 | + 'description', |
|
66 | + __('Event Description', 'event_espresso') |
|
67 | + ), |
|
68 | + new GraphQLField( |
|
69 | + 'shortDesc', |
|
70 | + 'String', |
|
71 | + 'short_description', |
|
72 | + __('Event Short Description', 'event_espresso') |
|
73 | + ), |
|
74 | + new GraphQLField( |
|
75 | + 'created', |
|
76 | + 'String', |
|
77 | + 'created', |
|
78 | + __('Date/Time Event Created', 'event_espresso') |
|
79 | + ), |
|
80 | + new GraphQLField( |
|
81 | + 'wpUser', |
|
82 | + 'User', |
|
83 | + null, |
|
84 | + __('Event Creator', 'event_espresso') |
|
85 | + ), |
|
86 | + new GraphQLField( |
|
87 | + 'order', |
|
88 | + 'Int', |
|
89 | + 'order', |
|
90 | + __('Event Menu Order', 'event_espresso') |
|
91 | + ), |
|
92 | + new GraphQLField( |
|
93 | + 'displayDesc', |
|
94 | + 'Boolean', |
|
95 | + 'display_description', |
|
96 | + __('Display Description Flag', 'event_espresso') |
|
97 | + ), |
|
98 | + new GraphQLField( |
|
99 | + 'displayTicketSelector', |
|
100 | + 'Boolean', |
|
101 | + 'display_ticket_selector', |
|
102 | + __('Display Ticket Selector Flag', 'event_espresso') |
|
103 | + ), |
|
104 | + new GraphQLField( |
|
105 | + 'visibleOn', |
|
106 | + 'String', |
|
107 | + 'visible_on', |
|
108 | + __('Event Visible Date', 'event_espresso') |
|
109 | + ), |
|
110 | + new GraphQLField( |
|
111 | + 'additionalLimit', |
|
112 | + 'String', |
|
113 | + 'additional_limit', |
|
114 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso') |
|
115 | + ), |
|
116 | + new GraphQLField( |
|
117 | + 'phone', |
|
118 | + 'String', |
|
119 | + 'phone', |
|
120 | + __('Event Phone Number', 'event_espresso') |
|
121 | + ), |
|
122 | + new GraphQLField( |
|
123 | + 'memberOnly', |
|
124 | + 'Boolean', |
|
125 | + 'member_only', |
|
126 | + __('Member-Only Event Flag', 'event_espresso') |
|
127 | + ), |
|
128 | + new GraphQLField( |
|
129 | + 'allowOverflow', |
|
130 | + 'Boolean', |
|
131 | + 'allow_overflow', |
|
132 | + __('Allow Overflow on Event', 'event_espresso') |
|
133 | + ), |
|
134 | + new GraphQLField( |
|
135 | + 'timezoneString', |
|
136 | + 'String', |
|
137 | + 'timezone_string', |
|
138 | + __('Timezone (name) for Event times', 'event_espresso') |
|
139 | + ), |
|
140 | + new GraphQLField( |
|
141 | + 'externalUrl', |
|
142 | + 'String', |
|
143 | + 'external_url', |
|
144 | + __('URL of Event Page if hosted elsewhere', 'event_espresso') |
|
145 | + ), |
|
146 | + new GraphQLField( |
|
147 | + 'donations', |
|
148 | + 'Boolean', |
|
149 | + 'donations', |
|
150 | + __('Accept Donations?', 'event_espresso') |
|
151 | + ), |
|
152 | + new GraphQLField( |
|
153 | + 'isSoldOut', |
|
154 | + 'Boolean', |
|
155 | + 'is_sold_out', |
|
156 | + __('Flag indicating whether the tickets sold for the event, met or exceed the registration limit', |
|
157 | + 'event_espresso') |
|
158 | + ), |
|
159 | + new GraphQLField( |
|
160 | + 'isPostponed', |
|
161 | + 'Boolean', |
|
162 | + 'is_postponed', |
|
163 | + __('Flag indicating whether the event is marked as postponed', 'event_espresso') |
|
164 | + ), |
|
165 | + new GraphQLField( |
|
166 | + 'isCancelled', |
|
167 | + 'Boolean', |
|
168 | + 'is_cancelled', |
|
169 | + __('Flag indicating whether the event is marked as cancelled', 'event_espresso') |
|
170 | + ), |
|
171 | + new GraphQLField( |
|
172 | + 'isUpcoming', |
|
173 | + 'Boolean', |
|
174 | + 'is_upcoming', |
|
175 | + __('Whether the event is upcoming', 'event_espresso') |
|
176 | + ), |
|
177 | + new GraphQLField( |
|
178 | + 'isActive', |
|
179 | + 'Boolean', |
|
180 | + 'is_active', |
|
181 | + __('Flag indicating event is active', 'event_espresso') |
|
182 | + ), |
|
183 | + new GraphQLField( |
|
184 | + 'isInactive', |
|
185 | + 'Boolean', |
|
186 | + 'is_inactive', |
|
187 | + __('Flag indicating event is inactive', 'event_espresso') |
|
188 | + ), |
|
189 | + new GraphQLField( |
|
190 | + 'isExpired', |
|
191 | + 'Boolean', |
|
192 | + 'is_expired', |
|
193 | + __('Flag indicating event is expired or not', 'event_espresso') |
|
194 | + ), |
|
195 | + ]; |
|
196 | + } |
|
197 | 197 | } |
198 | 198 | \ No newline at end of file |
@@ -32,59 +32,59 @@ |
||
32 | 32 | class State extends TypeBase |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * State constructor. |
|
37 | - * |
|
38 | - * @param EEM_State $state_model |
|
39 | - */ |
|
40 | - public function __construct(EEM_State $state_model) |
|
41 | - { |
|
42 | - $this->model = $state_model; |
|
43 | - $this->setName('State'); |
|
44 | - $this->setDescription(__('A state', 'event_espresso')); |
|
45 | - $this->setIsCustomPostType(false); |
|
35 | + /** |
|
36 | + * State constructor. |
|
37 | + * |
|
38 | + * @param EEM_State $state_model |
|
39 | + */ |
|
40 | + public function __construct(EEM_State $state_model) |
|
41 | + { |
|
42 | + $this->model = $state_model; |
|
43 | + $this->setName('State'); |
|
44 | + $this->setDescription(__('A state', 'event_espresso')); |
|
45 | + $this->setIsCustomPostType(false); |
|
46 | 46 | |
47 | - parent::__construct(); |
|
48 | - } |
|
47 | + parent::__construct(); |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | - /** |
|
52 | - * @return GraphQLField[] |
|
53 | - * @since $VID:$ |
|
54 | - */ |
|
55 | - public function getFields() |
|
56 | - { |
|
57 | - return [ |
|
58 | - new GraphQLField( |
|
59 | - 'id', |
|
60 | - ['non_null' => 'Int'], |
|
61 | - 'ID', |
|
62 | - __('State ID', 'event_espresso') |
|
63 | - ), |
|
64 | - new GraphQLField( |
|
65 | - 'abbreviation', |
|
66 | - 'String', |
|
67 | - 'abbrev', |
|
68 | - __('State Abbreviation', 'event_espresso') |
|
69 | - ), |
|
70 | - new GraphQLField( |
|
71 | - 'name', |
|
72 | - 'String', |
|
73 | - 'name', |
|
74 | - __('State Name', 'event_espresso') |
|
75 | - ), |
|
76 | - new GraphQLField( |
|
77 | - 'isActive', |
|
78 | - 'Boolean', |
|
79 | - 'active', |
|
80 | - __('State Active Flag', 'event_espresso') |
|
81 | - ), |
|
82 | - new GraphQLField( |
|
83 | - 'country', |
|
84 | - 'Country', |
|
85 | - null, |
|
86 | - __('Country for the state', 'event_espresso') |
|
87 | - ), |
|
88 | - ]; |
|
89 | - } |
|
51 | + /** |
|
52 | + * @return GraphQLField[] |
|
53 | + * @since $VID:$ |
|
54 | + */ |
|
55 | + public function getFields() |
|
56 | + { |
|
57 | + return [ |
|
58 | + new GraphQLField( |
|
59 | + 'id', |
|
60 | + ['non_null' => 'Int'], |
|
61 | + 'ID', |
|
62 | + __('State ID', 'event_espresso') |
|
63 | + ), |
|
64 | + new GraphQLField( |
|
65 | + 'abbreviation', |
|
66 | + 'String', |
|
67 | + 'abbrev', |
|
68 | + __('State Abbreviation', 'event_espresso') |
|
69 | + ), |
|
70 | + new GraphQLField( |
|
71 | + 'name', |
|
72 | + 'String', |
|
73 | + 'name', |
|
74 | + __('State Name', 'event_espresso') |
|
75 | + ), |
|
76 | + new GraphQLField( |
|
77 | + 'isActive', |
|
78 | + 'Boolean', |
|
79 | + 'active', |
|
80 | + __('State Active Flag', 'event_espresso') |
|
81 | + ), |
|
82 | + new GraphQLField( |
|
83 | + 'country', |
|
84 | + 'Country', |
|
85 | + null, |
|
86 | + __('Country for the state', 'event_espresso') |
|
87 | + ), |
|
88 | + ]; |
|
89 | + } |
|
90 | 90 | } |
91 | 91 | \ No newline at end of file |
@@ -35,163 +35,163 @@ |
||
35 | 35 | class Ticket extends TypeBase |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * Ticket constructor. |
|
40 | - * |
|
41 | - * @param EEM_Ticket $ticket_model |
|
42 | - */ |
|
43 | - public function __construct(EEM_Ticket $ticket_model) |
|
44 | - { |
|
45 | - $this->model = $ticket_model; |
|
46 | - $this->setName('Ticket'); |
|
47 | - $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
|
48 | - $this->setIsCustomPostType(false); |
|
49 | - parent::__construct(); |
|
50 | - } |
|
38 | + /** |
|
39 | + * Ticket constructor. |
|
40 | + * |
|
41 | + * @param EEM_Ticket $ticket_model |
|
42 | + */ |
|
43 | + public function __construct(EEM_Ticket $ticket_model) |
|
44 | + { |
|
45 | + $this->model = $ticket_model; |
|
46 | + $this->setName('Ticket'); |
|
47 | + $this->setDescription(__('A ticket for an event date', 'event_espresso')); |
|
48 | + $this->setIsCustomPostType(false); |
|
49 | + parent::__construct(); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @return GraphQLField[] |
|
55 | - * @since $VID:$ |
|
56 | - */ |
|
57 | - protected function getFields() |
|
58 | - { |
|
59 | - return [ |
|
60 | - new GraphQLField( |
|
61 | - 'id', |
|
62 | - ['non_null' => 'Int'], |
|
63 | - 'ID', |
|
64 | - __('Ticket ID', 'event_espresso') |
|
65 | - ), |
|
66 | - new GraphQLField( |
|
67 | - 'name', |
|
68 | - 'String', |
|
69 | - 'name', |
|
70 | - __('Ticket Name', 'event_espresso') |
|
71 | - ), |
|
72 | - new GraphQLField( |
|
73 | - 'description', |
|
74 | - 'String', |
|
75 | - 'description', |
|
76 | - __('Description of Ticket', 'event_espresso') |
|
77 | - ), |
|
78 | - new GraphQLField( |
|
79 | - 'startDate', |
|
80 | - 'String', |
|
81 | - 'start_date', |
|
82 | - __('Start time/date of Ticket', 'event_espresso') |
|
83 | - ), |
|
84 | - new GraphQLField( |
|
85 | - 'endDate', |
|
86 | - 'String', |
|
87 | - 'end_date', |
|
88 | - __('End time/date of Ticket', 'event_espresso') |
|
89 | - ), |
|
90 | - new GraphQLField( |
|
91 | - 'min', |
|
92 | - 'Int', |
|
93 | - 'min', |
|
94 | - __('Minimum quantity of this ticket that must be purchased', 'event_espresso') |
|
95 | - ), |
|
96 | - new GraphQLField( |
|
97 | - 'max', |
|
98 | - 'Int', |
|
99 | - 'max', |
|
100 | - __('Maximum quantity of this ticket that can be purchased in one transaction', 'event_espresso'), |
|
101 | - [$this, 'parseInfiniteValue'] |
|
102 | - ), |
|
103 | - new GraphQLField( |
|
104 | - 'price', |
|
105 | - 'Float', |
|
106 | - 'price', |
|
107 | - __('Final calculated price for ticket', 'event_espresso') |
|
108 | - ), |
|
109 | - new GraphQLField( |
|
110 | - 'sold', |
|
111 | - 'Int', |
|
112 | - 'sold', |
|
113 | - __('Number of this ticket sold', 'event_espresso') |
|
114 | - ), |
|
115 | - new GraphQLField( |
|
116 | - 'quantity', |
|
117 | - 'Int', |
|
118 | - 'qty', |
|
119 | - __('Quantity of this ticket that is available', 'event_espresso'), |
|
120 | - [$this, 'parseInfiniteValue'] |
|
121 | - ), |
|
122 | - new GraphQLField( |
|
123 | - 'reserved', |
|
124 | - 'Int', |
|
125 | - 'reserved', |
|
126 | - __('Quantity of this ticket that is reserved, but not yet fully purchased', 'event_espresso') |
|
127 | - ), |
|
128 | - new GraphQLField( |
|
129 | - 'uses', |
|
130 | - 'Int', |
|
131 | - 'uses', |
|
132 | - __('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
133 | - [$this, 'parseInfiniteValue'] |
|
134 | - ), |
|
135 | - new GraphQLField( |
|
136 | - 'isRequired', |
|
137 | - 'Boolean', |
|
138 | - 'required', |
|
139 | - __('Flag indicating whether this ticket must be purchased with a transaction', 'event_espresso') |
|
140 | - ), |
|
141 | - new GraphQLField( |
|
142 | - 'isTaxable', |
|
143 | - 'Boolean', |
|
144 | - 'taxable', |
|
145 | - __('Flag indicating whether there is tax applied on this ticket', 'event_espresso') |
|
146 | - ), |
|
147 | - new GraphQLField( |
|
148 | - 'isDefault', |
|
149 | - 'Boolean', |
|
150 | - 'is_default', |
|
151 | - __('Flag indicating that this ticket is a default ticket', 'event_espresso') |
|
152 | - ), |
|
153 | - new GraphQLField( |
|
154 | - 'order', |
|
155 | - 'Int', |
|
156 | - 'order', |
|
157 | - __('The order in which the Datetime is displayed', 'event_espresso') |
|
158 | - ), |
|
159 | - new GraphQLField( |
|
160 | - 'row', |
|
161 | - 'Int', |
|
162 | - 'row', |
|
163 | - __('How tickets are displayed in the ui', 'event_espresso') |
|
164 | - ), |
|
165 | - new GraphQLField( |
|
166 | - 'wpUser', |
|
167 | - 'User', |
|
168 | - null, |
|
169 | - __('Ticket Creator ID', 'event_espresso') |
|
170 | - ), |
|
171 | - new GraphQLField( |
|
172 | - 'parent', |
|
173 | - 'Ticket', |
|
174 | - null, |
|
175 | - __('The parent ticket of the current ticket', 'event_espresso') |
|
176 | - ), |
|
177 | - new GraphQLField( |
|
178 | - 'reverseCalculate', |
|
179 | - 'Boolean', |
|
180 | - 'reverse_calculate', |
|
181 | - __('Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', 'event_espresso') |
|
182 | - ), |
|
183 | - new GraphQLField( |
|
184 | - 'isFree', |
|
185 | - 'Boolean', |
|
186 | - 'is_free', |
|
187 | - __('Flag indicating whether the ticket is free.', 'event_espresso') |
|
188 | - ), |
|
189 | - new GraphQLField( |
|
190 | - 'Event', |
|
191 | - 'Event', |
|
192 | - null, |
|
193 | - __('Event of the ticket.', 'event_espresso') |
|
194 | - ), |
|
195 | - ]; |
|
196 | - } |
|
53 | + /** |
|
54 | + * @return GraphQLField[] |
|
55 | + * @since $VID:$ |
|
56 | + */ |
|
57 | + protected function getFields() |
|
58 | + { |
|
59 | + return [ |
|
60 | + new GraphQLField( |
|
61 | + 'id', |
|
62 | + ['non_null' => 'Int'], |
|
63 | + 'ID', |
|
64 | + __('Ticket ID', 'event_espresso') |
|
65 | + ), |
|
66 | + new GraphQLField( |
|
67 | + 'name', |
|
68 | + 'String', |
|
69 | + 'name', |
|
70 | + __('Ticket Name', 'event_espresso') |
|
71 | + ), |
|
72 | + new GraphQLField( |
|
73 | + 'description', |
|
74 | + 'String', |
|
75 | + 'description', |
|
76 | + __('Description of Ticket', 'event_espresso') |
|
77 | + ), |
|
78 | + new GraphQLField( |
|
79 | + 'startDate', |
|
80 | + 'String', |
|
81 | + 'start_date', |
|
82 | + __('Start time/date of Ticket', 'event_espresso') |
|
83 | + ), |
|
84 | + new GraphQLField( |
|
85 | + 'endDate', |
|
86 | + 'String', |
|
87 | + 'end_date', |
|
88 | + __('End time/date of Ticket', 'event_espresso') |
|
89 | + ), |
|
90 | + new GraphQLField( |
|
91 | + 'min', |
|
92 | + 'Int', |
|
93 | + 'min', |
|
94 | + __('Minimum quantity of this ticket that must be purchased', 'event_espresso') |
|
95 | + ), |
|
96 | + new GraphQLField( |
|
97 | + 'max', |
|
98 | + 'Int', |
|
99 | + 'max', |
|
100 | + __('Maximum quantity of this ticket that can be purchased in one transaction', 'event_espresso'), |
|
101 | + [$this, 'parseInfiniteValue'] |
|
102 | + ), |
|
103 | + new GraphQLField( |
|
104 | + 'price', |
|
105 | + 'Float', |
|
106 | + 'price', |
|
107 | + __('Final calculated price for ticket', 'event_espresso') |
|
108 | + ), |
|
109 | + new GraphQLField( |
|
110 | + 'sold', |
|
111 | + 'Int', |
|
112 | + 'sold', |
|
113 | + __('Number of this ticket sold', 'event_espresso') |
|
114 | + ), |
|
115 | + new GraphQLField( |
|
116 | + 'quantity', |
|
117 | + 'Int', |
|
118 | + 'qty', |
|
119 | + __('Quantity of this ticket that is available', 'event_espresso'), |
|
120 | + [$this, 'parseInfiniteValue'] |
|
121 | + ), |
|
122 | + new GraphQLField( |
|
123 | + 'reserved', |
|
124 | + 'Int', |
|
125 | + 'reserved', |
|
126 | + __('Quantity of this ticket that is reserved, but not yet fully purchased', 'event_espresso') |
|
127 | + ), |
|
128 | + new GraphQLField( |
|
129 | + 'uses', |
|
130 | + 'Int', |
|
131 | + 'uses', |
|
132 | + __('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
133 | + [$this, 'parseInfiniteValue'] |
|
134 | + ), |
|
135 | + new GraphQLField( |
|
136 | + 'isRequired', |
|
137 | + 'Boolean', |
|
138 | + 'required', |
|
139 | + __('Flag indicating whether this ticket must be purchased with a transaction', 'event_espresso') |
|
140 | + ), |
|
141 | + new GraphQLField( |
|
142 | + 'isTaxable', |
|
143 | + 'Boolean', |
|
144 | + 'taxable', |
|
145 | + __('Flag indicating whether there is tax applied on this ticket', 'event_espresso') |
|
146 | + ), |
|
147 | + new GraphQLField( |
|
148 | + 'isDefault', |
|
149 | + 'Boolean', |
|
150 | + 'is_default', |
|
151 | + __('Flag indicating that this ticket is a default ticket', 'event_espresso') |
|
152 | + ), |
|
153 | + new GraphQLField( |
|
154 | + 'order', |
|
155 | + 'Int', |
|
156 | + 'order', |
|
157 | + __('The order in which the Datetime is displayed', 'event_espresso') |
|
158 | + ), |
|
159 | + new GraphQLField( |
|
160 | + 'row', |
|
161 | + 'Int', |
|
162 | + 'row', |
|
163 | + __('How tickets are displayed in the ui', 'event_espresso') |
|
164 | + ), |
|
165 | + new GraphQLField( |
|
166 | + 'wpUser', |
|
167 | + 'User', |
|
168 | + null, |
|
169 | + __('Ticket Creator ID', 'event_espresso') |
|
170 | + ), |
|
171 | + new GraphQLField( |
|
172 | + 'parent', |
|
173 | + 'Ticket', |
|
174 | + null, |
|
175 | + __('The parent ticket of the current ticket', 'event_espresso') |
|
176 | + ), |
|
177 | + new GraphQLField( |
|
178 | + 'reverseCalculate', |
|
179 | + 'Boolean', |
|
180 | + 'reverse_calculate', |
|
181 | + __('Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', 'event_espresso') |
|
182 | + ), |
|
183 | + new GraphQLField( |
|
184 | + 'isFree', |
|
185 | + 'Boolean', |
|
186 | + 'is_free', |
|
187 | + __('Flag indicating whether the ticket is free.', 'event_espresso') |
|
188 | + ), |
|
189 | + new GraphQLField( |
|
190 | + 'Event', |
|
191 | + 'Event', |
|
192 | + null, |
|
193 | + __('Event of the ticket.', 'event_espresso') |
|
194 | + ), |
|
195 | + ]; |
|
196 | + } |
|
197 | 197 | } |
198 | 198 | \ No newline at end of file |
@@ -32,156 +32,156 @@ |
||
32 | 32 | class Datetime extends TypeBase |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * EventDate constructor. |
|
37 | - * |
|
38 | - * @param EEM_Datetime $datetime_model |
|
39 | - */ |
|
40 | - public function __construct(EEM_Datetime $datetime_model) |
|
41 | - { |
|
42 | - $this->model = $datetime_model; |
|
43 | - $this->setName('Datetime'); |
|
44 | - $this->setDescription(__('An event date', 'event_espresso')); |
|
45 | - $this->setIsCustomPostType(false); |
|
46 | - parent::__construct(); |
|
47 | - } |
|
35 | + /** |
|
36 | + * EventDate constructor. |
|
37 | + * |
|
38 | + * @param EEM_Datetime $datetime_model |
|
39 | + */ |
|
40 | + public function __construct(EEM_Datetime $datetime_model) |
|
41 | + { |
|
42 | + $this->model = $datetime_model; |
|
43 | + $this->setName('Datetime'); |
|
44 | + $this->setDescription(__('An event date', 'event_espresso')); |
|
45 | + $this->setIsCustomPostType(false); |
|
46 | + parent::__construct(); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @return GraphQLField[] |
|
52 | - * @since $VID:$ |
|
53 | - */ |
|
54 | - public function getFields() |
|
55 | - { |
|
56 | - return [ |
|
57 | - new GraphQLField( |
|
58 | - 'id', |
|
59 | - ['non_null' => 'Int'], |
|
60 | - 'ID', |
|
61 | - __('The datetime ID.', 'event_espresso') |
|
62 | - ), |
|
63 | - new GraphQLField( |
|
64 | - 'name', |
|
65 | - 'String', |
|
66 | - 'name', |
|
67 | - __('Datetime Name', 'event_espresso') |
|
68 | - ), |
|
69 | - new GraphQLField( |
|
70 | - 'description', |
|
71 | - 'String', |
|
72 | - 'description', |
|
73 | - __('Description for Datetime', 'event_espresso') |
|
74 | - ), |
|
75 | - new GraphQLField( |
|
76 | - 'start', |
|
77 | - 'String', |
|
78 | - 'start', |
|
79 | - __('Start timestamp of Event', 'event_espresso') |
|
80 | - ), |
|
81 | - new GraphQLField( |
|
82 | - 'startDate', |
|
83 | - 'String', |
|
84 | - 'start_date', |
|
85 | - __('Start time/date of Event', 'event_espresso') |
|
86 | - ), |
|
87 | - new GraphQLField( |
|
88 | - 'end', |
|
89 | - 'String', |
|
90 | - 'end', |
|
91 | - __('End timestamp of Event', 'event_espresso') |
|
92 | - ), |
|
93 | - new GraphQLField( |
|
94 | - 'endDate', |
|
95 | - 'String', |
|
96 | - 'end_date', |
|
97 | - __('End time/date of Event', 'event_espresso') |
|
98 | - ), |
|
99 | - new GraphQLField( |
|
100 | - 'startTime', |
|
101 | - 'String', |
|
102 | - 'start_time', |
|
103 | - __('Start time of Event', 'event_espresso') |
|
104 | - ), |
|
105 | - new GraphQLField( |
|
106 | - 'endTime', |
|
107 | - 'String', |
|
108 | - 'end_time', |
|
109 | - __('End time of Event', 'event_espresso') |
|
110 | - ), |
|
111 | - new GraphQLField( |
|
112 | - 'capacity', |
|
113 | - 'Int', |
|
114 | - 'reg_limit', |
|
115 | - __('Registration Limit for this time', 'event_espresso'), |
|
116 | - [$this, 'parseInfiniteValue'] |
|
117 | - ), |
|
118 | - new GraphQLField( |
|
119 | - 'sold', |
|
120 | - 'Int', |
|
121 | - 'sold', |
|
122 | - __('How many sales for this Datetime that have occurred', 'event_espresso') |
|
123 | - ), |
|
124 | - new GraphQLField( |
|
125 | - 'reserved', |
|
126 | - 'Int', |
|
127 | - 'reserved', |
|
128 | - __('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso') |
|
129 | - ), |
|
130 | - new GraphQLField( |
|
131 | - 'order', |
|
132 | - 'Int', |
|
133 | - 'order', |
|
134 | - __('The order in which the Datetime is displayed', 'event_espresso') |
|
135 | - ), |
|
136 | - new GraphQLField( |
|
137 | - 'length', |
|
138 | - 'Int', |
|
139 | - 'length', |
|
140 | - __('The length of the event (start to end time) in seconds', 'event_espresso') |
|
141 | - ), |
|
142 | - new GraphQLField( |
|
143 | - 'parent', |
|
144 | - 'Datetime', |
|
145 | - null, |
|
146 | - __('The parent datetime of the current datetime', 'event_espresso') |
|
147 | - ), |
|
148 | - new GraphQLField( |
|
149 | - 'isPrimary', |
|
150 | - 'Boolean', |
|
151 | - 'is_primary', |
|
152 | - __('Flag indicating datetime is primary one for event', 'event_espresso') |
|
153 | - ), |
|
154 | - new GraphQLField( |
|
155 | - 'isSoldOut', |
|
156 | - 'Boolean', |
|
157 | - 'sold_out', |
|
158 | - __('Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit', |
|
159 | - 'event_espresso') |
|
160 | - ), |
|
161 | - new GraphQLField( |
|
162 | - 'isUpcoming', |
|
163 | - 'Boolean', |
|
164 | - 'is_upcoming', |
|
165 | - __('Whether the date is upcoming', 'event_espresso') |
|
166 | - ), |
|
167 | - new GraphQLField( |
|
168 | - 'isActive', |
|
169 | - 'Boolean', |
|
170 | - 'is_active', |
|
171 | - __('Flag indicating datetime is active', 'event_espresso') |
|
172 | - ), |
|
173 | - new GraphQLField( |
|
174 | - 'isExpired', |
|
175 | - 'Boolean', |
|
176 | - 'is_expired', |
|
177 | - __('Flag indicating datetime is expired or not', 'event_espresso') |
|
178 | - ), |
|
179 | - new GraphQLField( |
|
180 | - 'event', |
|
181 | - 'Event', |
|
182 | - null, |
|
183 | - __('Event of the datetime.', 'event_espresso') |
|
184 | - ), |
|
185 | - ]; |
|
186 | - } |
|
50 | + /** |
|
51 | + * @return GraphQLField[] |
|
52 | + * @since $VID:$ |
|
53 | + */ |
|
54 | + public function getFields() |
|
55 | + { |
|
56 | + return [ |
|
57 | + new GraphQLField( |
|
58 | + 'id', |
|
59 | + ['non_null' => 'Int'], |
|
60 | + 'ID', |
|
61 | + __('The datetime ID.', 'event_espresso') |
|
62 | + ), |
|
63 | + new GraphQLField( |
|
64 | + 'name', |
|
65 | + 'String', |
|
66 | + 'name', |
|
67 | + __('Datetime Name', 'event_espresso') |
|
68 | + ), |
|
69 | + new GraphQLField( |
|
70 | + 'description', |
|
71 | + 'String', |
|
72 | + 'description', |
|
73 | + __('Description for Datetime', 'event_espresso') |
|
74 | + ), |
|
75 | + new GraphQLField( |
|
76 | + 'start', |
|
77 | + 'String', |
|
78 | + 'start', |
|
79 | + __('Start timestamp of Event', 'event_espresso') |
|
80 | + ), |
|
81 | + new GraphQLField( |
|
82 | + 'startDate', |
|
83 | + 'String', |
|
84 | + 'start_date', |
|
85 | + __('Start time/date of Event', 'event_espresso') |
|
86 | + ), |
|
87 | + new GraphQLField( |
|
88 | + 'end', |
|
89 | + 'String', |
|
90 | + 'end', |
|
91 | + __('End timestamp of Event', 'event_espresso') |
|
92 | + ), |
|
93 | + new GraphQLField( |
|
94 | + 'endDate', |
|
95 | + 'String', |
|
96 | + 'end_date', |
|
97 | + __('End time/date of Event', 'event_espresso') |
|
98 | + ), |
|
99 | + new GraphQLField( |
|
100 | + 'startTime', |
|
101 | + 'String', |
|
102 | + 'start_time', |
|
103 | + __('Start time of Event', 'event_espresso') |
|
104 | + ), |
|
105 | + new GraphQLField( |
|
106 | + 'endTime', |
|
107 | + 'String', |
|
108 | + 'end_time', |
|
109 | + __('End time of Event', 'event_espresso') |
|
110 | + ), |
|
111 | + new GraphQLField( |
|
112 | + 'capacity', |
|
113 | + 'Int', |
|
114 | + 'reg_limit', |
|
115 | + __('Registration Limit for this time', 'event_espresso'), |
|
116 | + [$this, 'parseInfiniteValue'] |
|
117 | + ), |
|
118 | + new GraphQLField( |
|
119 | + 'sold', |
|
120 | + 'Int', |
|
121 | + 'sold', |
|
122 | + __('How many sales for this Datetime that have occurred', 'event_espresso') |
|
123 | + ), |
|
124 | + new GraphQLField( |
|
125 | + 'reserved', |
|
126 | + 'Int', |
|
127 | + 'reserved', |
|
128 | + __('Quantity of tickets reserved, but not yet fully purchased', 'event_espresso') |
|
129 | + ), |
|
130 | + new GraphQLField( |
|
131 | + 'order', |
|
132 | + 'Int', |
|
133 | + 'order', |
|
134 | + __('The order in which the Datetime is displayed', 'event_espresso') |
|
135 | + ), |
|
136 | + new GraphQLField( |
|
137 | + 'length', |
|
138 | + 'Int', |
|
139 | + 'length', |
|
140 | + __('The length of the event (start to end time) in seconds', 'event_espresso') |
|
141 | + ), |
|
142 | + new GraphQLField( |
|
143 | + 'parent', |
|
144 | + 'Datetime', |
|
145 | + null, |
|
146 | + __('The parent datetime of the current datetime', 'event_espresso') |
|
147 | + ), |
|
148 | + new GraphQLField( |
|
149 | + 'isPrimary', |
|
150 | + 'Boolean', |
|
151 | + 'is_primary', |
|
152 | + __('Flag indicating datetime is primary one for event', 'event_espresso') |
|
153 | + ), |
|
154 | + new GraphQLField( |
|
155 | + 'isSoldOut', |
|
156 | + 'Boolean', |
|
157 | + 'sold_out', |
|
158 | + __('Flag indicating whether the tickets sold for this datetime, met or exceed the registration limit', |
|
159 | + 'event_espresso') |
|
160 | + ), |
|
161 | + new GraphQLField( |
|
162 | + 'isUpcoming', |
|
163 | + 'Boolean', |
|
164 | + 'is_upcoming', |
|
165 | + __('Whether the date is upcoming', 'event_espresso') |
|
166 | + ), |
|
167 | + new GraphQLField( |
|
168 | + 'isActive', |
|
169 | + 'Boolean', |
|
170 | + 'is_active', |
|
171 | + __('Flag indicating datetime is active', 'event_espresso') |
|
172 | + ), |
|
173 | + new GraphQLField( |
|
174 | + 'isExpired', |
|
175 | + 'Boolean', |
|
176 | + 'is_expired', |
|
177 | + __('Flag indicating datetime is expired or not', 'event_espresso') |
|
178 | + ), |
|
179 | + new GraphQLField( |
|
180 | + 'event', |
|
181 | + 'Event', |
|
182 | + null, |
|
183 | + __('Event of the datetime.', 'event_espresso') |
|
184 | + ), |
|
185 | + ]; |
|
186 | + } |
|
187 | 187 | } |
188 | 188 | \ No newline at end of file |
@@ -35,81 +35,81 @@ |
||
35 | 35 | class Country extends TypeBase |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * Country constructor. |
|
40 | - * |
|
41 | - * @param EEM_Country $country_model |
|
42 | - */ |
|
43 | - public function __construct(EEM_Country $country_model) |
|
44 | - { |
|
45 | - $this->model = $country_model; |
|
46 | - $this->setName('Country'); |
|
47 | - $this->setDescription(__('A country', 'event_espresso')); |
|
48 | - $this->setIsCustomPostType(false); |
|
49 | - parent::__construct(); |
|
50 | - } |
|
38 | + /** |
|
39 | + * Country constructor. |
|
40 | + * |
|
41 | + * @param EEM_Country $country_model |
|
42 | + */ |
|
43 | + public function __construct(EEM_Country $country_model) |
|
44 | + { |
|
45 | + $this->model = $country_model; |
|
46 | + $this->setName('Country'); |
|
47 | + $this->setDescription(__('A country', 'event_espresso')); |
|
48 | + $this->setIsCustomPostType(false); |
|
49 | + parent::__construct(); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * @return GraphQLField[] |
|
55 | - * @since $VID:$ |
|
56 | - */ |
|
57 | - public function getFields() |
|
58 | - { |
|
59 | - return [ |
|
60 | - new GraphQLField( |
|
61 | - 'name', |
|
62 | - 'String', |
|
63 | - 'name', |
|
64 | - __('Country Name', 'event_espresso') |
|
65 | - ), |
|
66 | - new GraphQLField( |
|
67 | - 'currencyCode', |
|
68 | - 'String', |
|
69 | - 'currency_code', |
|
70 | - __('Country Currency Code', 'event_espresso') |
|
71 | - ), |
|
72 | - new GraphQLField( |
|
73 | - 'currencySingular', |
|
74 | - 'String', |
|
75 | - 'currency_name_single', |
|
76 | - __('Currency Name Singular', 'event_espresso') |
|
77 | - ), |
|
78 | - new GraphQLField( |
|
79 | - 'currencyPlural', |
|
80 | - 'String', |
|
81 | - 'currency_name_plural', |
|
82 | - __('Currency Name Plural', 'event_espresso') |
|
83 | - ), |
|
84 | - new GraphQLField( |
|
85 | - 'currencySign', |
|
86 | - 'String', |
|
87 | - 'currency_sign',__('Currency Sign', 'event_espresso') |
|
88 | - ), |
|
89 | - new GraphQLField( |
|
90 | - 'currencySignBeforeNumber', |
|
91 | - 'String', |
|
92 | - 'currency_sign_before', |
|
93 | - __('Currency Sign Before Number', 'event_espresso') |
|
94 | - ), |
|
95 | - new GraphQLField( |
|
96 | - 'currencyDecimalPlaces', |
|
97 | - 'String', |
|
98 | - 'currency_decimal_places', |
|
99 | - __('Currency Decimal Places', 'event_espresso') |
|
100 | - ), |
|
101 | - new GraphQLField( |
|
102 | - 'currencyDecimalMark', |
|
103 | - 'String', |
|
104 | - 'currency_decimal_mark', |
|
105 | - __('Currency Decimal Mark', 'event_espresso') |
|
106 | - ), |
|
107 | - new GraphQLField( |
|
108 | - 'currencyThousandsSeparator', |
|
109 | - 'String', |
|
110 | - 'currency_thousands_separator', |
|
111 | - __('Currency Thousands Separator', 'event_espresso') |
|
112 | - ), |
|
113 | - ]; |
|
114 | - } |
|
53 | + /** |
|
54 | + * @return GraphQLField[] |
|
55 | + * @since $VID:$ |
|
56 | + */ |
|
57 | + public function getFields() |
|
58 | + { |
|
59 | + return [ |
|
60 | + new GraphQLField( |
|
61 | + 'name', |
|
62 | + 'String', |
|
63 | + 'name', |
|
64 | + __('Country Name', 'event_espresso') |
|
65 | + ), |
|
66 | + new GraphQLField( |
|
67 | + 'currencyCode', |
|
68 | + 'String', |
|
69 | + 'currency_code', |
|
70 | + __('Country Currency Code', 'event_espresso') |
|
71 | + ), |
|
72 | + new GraphQLField( |
|
73 | + 'currencySingular', |
|
74 | + 'String', |
|
75 | + 'currency_name_single', |
|
76 | + __('Currency Name Singular', 'event_espresso') |
|
77 | + ), |
|
78 | + new GraphQLField( |
|
79 | + 'currencyPlural', |
|
80 | + 'String', |
|
81 | + 'currency_name_plural', |
|
82 | + __('Currency Name Plural', 'event_espresso') |
|
83 | + ), |
|
84 | + new GraphQLField( |
|
85 | + 'currencySign', |
|
86 | + 'String', |
|
87 | + 'currency_sign',__('Currency Sign', 'event_espresso') |
|
88 | + ), |
|
89 | + new GraphQLField( |
|
90 | + 'currencySignBeforeNumber', |
|
91 | + 'String', |
|
92 | + 'currency_sign_before', |
|
93 | + __('Currency Sign Before Number', 'event_espresso') |
|
94 | + ), |
|
95 | + new GraphQLField( |
|
96 | + 'currencyDecimalPlaces', |
|
97 | + 'String', |
|
98 | + 'currency_decimal_places', |
|
99 | + __('Currency Decimal Places', 'event_espresso') |
|
100 | + ), |
|
101 | + new GraphQLField( |
|
102 | + 'currencyDecimalMark', |
|
103 | + 'String', |
|
104 | + 'currency_decimal_mark', |
|
105 | + __('Currency Decimal Mark', 'event_espresso') |
|
106 | + ), |
|
107 | + new GraphQLField( |
|
108 | + 'currencyThousandsSeparator', |
|
109 | + 'String', |
|
110 | + 'currency_thousands_separator', |
|
111 | + __('Currency Thousands Separator', 'event_espresso') |
|
112 | + ), |
|
113 | + ]; |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | \ No newline at end of file |
@@ -84,7 +84,7 @@ |
||
84 | 84 | new GraphQLField( |
85 | 85 | 'currencySign', |
86 | 86 | 'String', |
87 | - 'currency_sign',__('Currency Sign', 'event_espresso') |
|
87 | + 'currency_sign', __('Currency Sign', 'event_espresso') |
|
88 | 88 | ), |
89 | 89 | new GraphQLField( |
90 | 90 | 'currencySignBeforeNumber', |
@@ -32,148 +32,148 @@ |
||
32 | 32 | class Venue extends TypeBase |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * Venue constructor. |
|
37 | - * |
|
38 | - * @param EEM_Venue $venue_model |
|
39 | - */ |
|
40 | - public function __construct(EEM_Venue $venue_model) |
|
41 | - { |
|
42 | - $this->model = $venue_model; |
|
43 | - $this->setName('Venue'); |
|
44 | - $this->setIsCustomPostType(true); |
|
45 | - parent::__construct(); |
|
46 | - } |
|
35 | + /** |
|
36 | + * Venue constructor. |
|
37 | + * |
|
38 | + * @param EEM_Venue $venue_model |
|
39 | + */ |
|
40 | + public function __construct(EEM_Venue $venue_model) |
|
41 | + { |
|
42 | + $this->model = $venue_model; |
|
43 | + $this->setName('Venue'); |
|
44 | + $this->setIsCustomPostType(true); |
|
45 | + parent::__construct(); |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * @return GraphQLField[] |
|
51 | - * @since $VID:$ |
|
52 | - */ |
|
53 | - public function getFields() |
|
54 | - { |
|
55 | - return [ |
|
56 | - new GraphQLField( |
|
57 | - 'name', |
|
58 | - 'String', |
|
59 | - 'name', |
|
60 | - __('Venue Name', 'event_espresso') |
|
61 | - ), |
|
62 | - new GraphQLField( |
|
63 | - 'desc', |
|
64 | - 'String', |
|
65 | - 'description', |
|
66 | - __('Venue Description', 'event_espresso') |
|
67 | - ), |
|
68 | - new GraphQLField( |
|
69 | - 'shortDesc', |
|
70 | - 'String', |
|
71 | - 'excerpt', |
|
72 | - __('Short Description of Venue', 'event_espresso') |
|
73 | - ), |
|
74 | - new GraphQLField( |
|
75 | - 'identifier', |
|
76 | - 'String', |
|
77 | - 'identifier', |
|
78 | - __('Venue Identifier', 'event_espresso') |
|
79 | - ), |
|
80 | - new GraphQLField( |
|
81 | - 'created', |
|
82 | - 'String', |
|
83 | - 'created', |
|
84 | - __('Date Venue Created', 'event_espresso') |
|
85 | - ), |
|
86 | - new GraphQLField( |
|
87 | - 'order', |
|
88 | - 'Int', |
|
89 | - 'order', |
|
90 | - __('Venue order', 'event_espresso') |
|
91 | - ), |
|
92 | - new GraphQLField( |
|
93 | - 'wpUser', |
|
94 | - 'User', |
|
95 | - null, |
|
96 | - __('Venue Creator', 'event_espresso') |
|
97 | - ), |
|
98 | - new GraphQLField( |
|
99 | - 'address', |
|
100 | - 'String', |
|
101 | - 'address', |
|
102 | - __('Venue Address line 1', 'event_espresso') |
|
103 | - ), |
|
104 | - new GraphQLField( |
|
105 | - 'address2', |
|
106 | - 'String', |
|
107 | - 'address2', |
|
108 | - __('Venue Address line 2', 'event_espresso') |
|
109 | - ), |
|
110 | - new GraphQLField( |
|
111 | - 'city', |
|
112 | - 'String', |
|
113 | - 'city', |
|
114 | - __('Venue City', 'event_espresso') |
|
115 | - ), |
|
116 | - new GraphQLField( |
|
117 | - 'state', |
|
118 | - 'State', |
|
119 | - null, |
|
120 | - __('Venue state', 'event_espresso') |
|
121 | - ), |
|
122 | - new GraphQLField( |
|
123 | - 'country', |
|
124 | - 'Country', |
|
125 | - null, |
|
126 | - __('Venue country', 'event_espresso') |
|
127 | - ), |
|
128 | - new GraphQLField( |
|
129 | - 'zip', |
|
130 | - 'String', |
|
131 | - 'zip', |
|
132 | - __('Venue Zip/Postal Code', 'event_espresso') |
|
133 | - ), |
|
134 | - new GraphQLField( |
|
135 | - 'capacity', |
|
136 | - 'Int', |
|
137 | - 'capacity', |
|
138 | - __('Venue Capacity', 'event_espresso'), |
|
139 | - [$this, 'parseInfiniteValue'] |
|
140 | - ), |
|
141 | - new GraphQLField( |
|
142 | - 'phone', |
|
143 | - 'String', |
|
144 | - 'phone', |
|
145 | - __('Venue Phone', 'event_espresso') |
|
146 | - ), |
|
147 | - new GraphQLField( |
|
148 | - 'virtualPhone', |
|
149 | - 'String', |
|
150 | - 'virtual_phone', |
|
151 | - __('Call in Number', 'event_espresso') |
|
152 | - ), |
|
153 | - new GraphQLField( |
|
154 | - 'url', |
|
155 | - 'String', |
|
156 | - 'venue_url', |
|
157 | - __('Venue Website', 'event_espresso') |
|
158 | - ), |
|
159 | - new GraphQLField( |
|
160 | - 'virtualUrl', |
|
161 | - 'String', |
|
162 | - 'virtual_url', |
|
163 | - __('Virtual URL', 'event_espresso') |
|
164 | - ), |
|
165 | - new GraphQLField( |
|
166 | - 'googleMapLink', |
|
167 | - 'String', |
|
168 | - 'google_map_link', |
|
169 | - __('Google Map Link', 'event_espresso') |
|
170 | - ), |
|
171 | - new GraphQLField( |
|
172 | - 'enableForGmap', |
|
173 | - 'String', |
|
174 | - 'enable_for_gmap', |
|
175 | - __('Show Google Map?', 'event_espresso') |
|
176 | - ), |
|
177 | - ]; |
|
178 | - } |
|
49 | + /** |
|
50 | + * @return GraphQLField[] |
|
51 | + * @since $VID:$ |
|
52 | + */ |
|
53 | + public function getFields() |
|
54 | + { |
|
55 | + return [ |
|
56 | + new GraphQLField( |
|
57 | + 'name', |
|
58 | + 'String', |
|
59 | + 'name', |
|
60 | + __('Venue Name', 'event_espresso') |
|
61 | + ), |
|
62 | + new GraphQLField( |
|
63 | + 'desc', |
|
64 | + 'String', |
|
65 | + 'description', |
|
66 | + __('Venue Description', 'event_espresso') |
|
67 | + ), |
|
68 | + new GraphQLField( |
|
69 | + 'shortDesc', |
|
70 | + 'String', |
|
71 | + 'excerpt', |
|
72 | + __('Short Description of Venue', 'event_espresso') |
|
73 | + ), |
|
74 | + new GraphQLField( |
|
75 | + 'identifier', |
|
76 | + 'String', |
|
77 | + 'identifier', |
|
78 | + __('Venue Identifier', 'event_espresso') |
|
79 | + ), |
|
80 | + new GraphQLField( |
|
81 | + 'created', |
|
82 | + 'String', |
|
83 | + 'created', |
|
84 | + __('Date Venue Created', 'event_espresso') |
|
85 | + ), |
|
86 | + new GraphQLField( |
|
87 | + 'order', |
|
88 | + 'Int', |
|
89 | + 'order', |
|
90 | + __('Venue order', 'event_espresso') |
|
91 | + ), |
|
92 | + new GraphQLField( |
|
93 | + 'wpUser', |
|
94 | + 'User', |
|
95 | + null, |
|
96 | + __('Venue Creator', 'event_espresso') |
|
97 | + ), |
|
98 | + new GraphQLField( |
|
99 | + 'address', |
|
100 | + 'String', |
|
101 | + 'address', |
|
102 | + __('Venue Address line 1', 'event_espresso') |
|
103 | + ), |
|
104 | + new GraphQLField( |
|
105 | + 'address2', |
|
106 | + 'String', |
|
107 | + 'address2', |
|
108 | + __('Venue Address line 2', 'event_espresso') |
|
109 | + ), |
|
110 | + new GraphQLField( |
|
111 | + 'city', |
|
112 | + 'String', |
|
113 | + 'city', |
|
114 | + __('Venue City', 'event_espresso') |
|
115 | + ), |
|
116 | + new GraphQLField( |
|
117 | + 'state', |
|
118 | + 'State', |
|
119 | + null, |
|
120 | + __('Venue state', 'event_espresso') |
|
121 | + ), |
|
122 | + new GraphQLField( |
|
123 | + 'country', |
|
124 | + 'Country', |
|
125 | + null, |
|
126 | + __('Venue country', 'event_espresso') |
|
127 | + ), |
|
128 | + new GraphQLField( |
|
129 | + 'zip', |
|
130 | + 'String', |
|
131 | + 'zip', |
|
132 | + __('Venue Zip/Postal Code', 'event_espresso') |
|
133 | + ), |
|
134 | + new GraphQLField( |
|
135 | + 'capacity', |
|
136 | + 'Int', |
|
137 | + 'capacity', |
|
138 | + __('Venue Capacity', 'event_espresso'), |
|
139 | + [$this, 'parseInfiniteValue'] |
|
140 | + ), |
|
141 | + new GraphQLField( |
|
142 | + 'phone', |
|
143 | + 'String', |
|
144 | + 'phone', |
|
145 | + __('Venue Phone', 'event_espresso') |
|
146 | + ), |
|
147 | + new GraphQLField( |
|
148 | + 'virtualPhone', |
|
149 | + 'String', |
|
150 | + 'virtual_phone', |
|
151 | + __('Call in Number', 'event_espresso') |
|
152 | + ), |
|
153 | + new GraphQLField( |
|
154 | + 'url', |
|
155 | + 'String', |
|
156 | + 'venue_url', |
|
157 | + __('Venue Website', 'event_espresso') |
|
158 | + ), |
|
159 | + new GraphQLField( |
|
160 | + 'virtualUrl', |
|
161 | + 'String', |
|
162 | + 'virtual_url', |
|
163 | + __('Virtual URL', 'event_espresso') |
|
164 | + ), |
|
165 | + new GraphQLField( |
|
166 | + 'googleMapLink', |
|
167 | + 'String', |
|
168 | + 'google_map_link', |
|
169 | + __('Google Map Link', 'event_espresso') |
|
170 | + ), |
|
171 | + new GraphQLField( |
|
172 | + 'enableForGmap', |
|
173 | + 'String', |
|
174 | + 'enable_for_gmap', |
|
175 | + __('Show Google Map?', 'event_espresso') |
|
176 | + ), |
|
177 | + ]; |
|
178 | + } |
|
179 | 179 | } |
180 | 180 | \ No newline at end of file |
@@ -46,228 +46,228 @@ |
||
46 | 46 | abstract class TypeBase implements TypeInterface |
47 | 47 | { |
48 | 48 | |
49 | - /** |
|
50 | - * @var EEM_Base $model |
|
51 | - */ |
|
52 | - protected $model; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string $name |
|
56 | - */ |
|
57 | - protected $name = ''; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var string $description |
|
61 | - */ |
|
62 | - protected $description = ''; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var GraphQLField[] $fields |
|
66 | - */ |
|
67 | - protected $fields = []; |
|
68 | - |
|
69 | - /** |
|
70 | - * @var array $graphql_to_model_map |
|
71 | - */ |
|
72 | - protected $graphql_to_model_map = []; |
|
73 | - |
|
74 | - /** |
|
75 | - * @var FieldResolver $field_resolver |
|
76 | - */ |
|
77 | - protected $field_resolver; |
|
78 | - |
|
79 | - /** |
|
80 | - * @var bool $is_custom_post_type |
|
81 | - */ |
|
82 | - protected $is_custom_post_type = false; |
|
83 | - |
|
84 | - /** |
|
85 | - * TypeBase constructor. |
|
86 | - */ |
|
87 | - public function __construct() |
|
88 | - { |
|
89 | - $this->setFields($this->getFields()); |
|
90 | - $this->field_resolver = new FieldResolver( |
|
91 | - $this->model, |
|
92 | - $this->getFieldsForResolver() |
|
93 | - ); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @return GraphQLField[] |
|
99 | - * @since $VID:$ |
|
100 | - */ |
|
101 | - abstract protected function getFields(); |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function name() |
|
108 | - { |
|
109 | - return $this->name; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * @param string $name |
|
115 | - */ |
|
116 | - protected function setName($name) |
|
117 | - { |
|
118 | - $this->name = $name; |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public function description() |
|
126 | - { |
|
127 | - return $this->description; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * @param string $description |
|
133 | - */ |
|
134 | - protected function setDescription($description) |
|
135 | - { |
|
136 | - $this->description = $description; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return GraphQLField[] |
|
142 | - * @since $VID:$ |
|
143 | - */ |
|
144 | - public function fields() |
|
145 | - { |
|
146 | - return (array) $this->fields; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * @param GraphQLField[] $fields |
|
152 | - */ |
|
153 | - protected function setFields(array $fields) |
|
154 | - { |
|
155 | - foreach ($fields as $field) { |
|
156 | - if ($field instanceof GraphQLField) { |
|
157 | - $this->fields[] = $field; |
|
158 | - } |
|
159 | - } |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Creates a key map to pass to GraphQL registration. |
|
165 | - * @return array |
|
166 | - * @since $VID:$ |
|
167 | - */ |
|
168 | - public function getFieldsForGQL() |
|
169 | - { |
|
170 | - $fields = []; |
|
171 | - foreach ($this->fields() as $field) { |
|
172 | - $config = $field->toArray(); |
|
173 | - $config['resolve'] = [$this, 'resolveField']; |
|
174 | - $fields[$field->name()] = $config; |
|
175 | - } |
|
176 | - return $fields; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * Creates a key map for internal resolver. |
|
182 | - * @return array |
|
183 | - * @since $VID:$ |
|
184 | - */ |
|
185 | - public function getFieldsForResolver() |
|
186 | - { |
|
187 | - $fields = []; |
|
188 | - foreach ($this->fields() as $field) { |
|
189 | - $fields[$field->name()] = $field; |
|
190 | - } |
|
191 | - return $fields; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * @return bool |
|
197 | - */ |
|
198 | - public function isCustomPostType() |
|
199 | - { |
|
200 | - return $this->is_custom_post_type; |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * @param bool $is_custom_post_type |
|
206 | - */ |
|
207 | - protected function setIsCustomPostType($is_custom_post_type) |
|
208 | - { |
|
209 | - $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @param int $value |
|
215 | - * @return int |
|
216 | - * @since $VID:$ |
|
217 | - */ |
|
218 | - public function parseInfiniteValue($value) |
|
219 | - { |
|
220 | - $value = trim($value); |
|
221 | - return $value === null |
|
222 | - || $value === '' |
|
223 | - || $value === '∞' |
|
224 | - || $value === 'INF' |
|
225 | - || $value === INF |
|
226 | - || $value === EE_INF |
|
227 | - || is_infinite((float) $value) |
|
228 | - ? -1 |
|
229 | - : $value; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * @param mixed $source |
|
235 | - * @return EE_Base_Class|null |
|
236 | - * @since $VID:$ |
|
237 | - */ |
|
238 | - private function getModel($source) |
|
239 | - { |
|
240 | - // If it comes from a custom connection |
|
241 | - // where the $source is already instantiated. |
|
242 | - if ($source instanceof EE_Base_Class) { |
|
243 | - return $source; |
|
244 | - } |
|
245 | - return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @param mixed $source The source that's passed down the GraphQL queries |
|
251 | - * @param array $args The inputArgs on the field |
|
252 | - * @param AppContext $context The AppContext passed down the GraphQL tree |
|
253 | - * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
254 | - * @return string |
|
255 | - * @throws EE_Error |
|
256 | - * @throws InvalidDataTypeException |
|
257 | - * @throws InvalidInterfaceException |
|
258 | - * @throws UnexpectedEntityException |
|
259 | - * @throws UserError |
|
260 | - * @throws InvalidArgumentException |
|
261 | - * @throws ReflectionException |
|
262 | - * @since $VID:$ |
|
263 | - */ |
|
264 | - public function resolveField($source, $args, AppContext $context, ResolveInfo $info) |
|
265 | - { |
|
266 | - $source = $this->getModel($source); |
|
267 | - if ($source instanceof EE_Base_Class) { |
|
268 | - return $this->field_resolver->resolve($source, $args, $context, $info); |
|
269 | - } |
|
270 | - return null; |
|
271 | - } |
|
49 | + /** |
|
50 | + * @var EEM_Base $model |
|
51 | + */ |
|
52 | + protected $model; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string $name |
|
56 | + */ |
|
57 | + protected $name = ''; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var string $description |
|
61 | + */ |
|
62 | + protected $description = ''; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var GraphQLField[] $fields |
|
66 | + */ |
|
67 | + protected $fields = []; |
|
68 | + |
|
69 | + /** |
|
70 | + * @var array $graphql_to_model_map |
|
71 | + */ |
|
72 | + protected $graphql_to_model_map = []; |
|
73 | + |
|
74 | + /** |
|
75 | + * @var FieldResolver $field_resolver |
|
76 | + */ |
|
77 | + protected $field_resolver; |
|
78 | + |
|
79 | + /** |
|
80 | + * @var bool $is_custom_post_type |
|
81 | + */ |
|
82 | + protected $is_custom_post_type = false; |
|
83 | + |
|
84 | + /** |
|
85 | + * TypeBase constructor. |
|
86 | + */ |
|
87 | + public function __construct() |
|
88 | + { |
|
89 | + $this->setFields($this->getFields()); |
|
90 | + $this->field_resolver = new FieldResolver( |
|
91 | + $this->model, |
|
92 | + $this->getFieldsForResolver() |
|
93 | + ); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @return GraphQLField[] |
|
99 | + * @since $VID:$ |
|
100 | + */ |
|
101 | + abstract protected function getFields(); |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function name() |
|
108 | + { |
|
109 | + return $this->name; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * @param string $name |
|
115 | + */ |
|
116 | + protected function setName($name) |
|
117 | + { |
|
118 | + $this->name = $name; |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public function description() |
|
126 | + { |
|
127 | + return $this->description; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * @param string $description |
|
133 | + */ |
|
134 | + protected function setDescription($description) |
|
135 | + { |
|
136 | + $this->description = $description; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return GraphQLField[] |
|
142 | + * @since $VID:$ |
|
143 | + */ |
|
144 | + public function fields() |
|
145 | + { |
|
146 | + return (array) $this->fields; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * @param GraphQLField[] $fields |
|
152 | + */ |
|
153 | + protected function setFields(array $fields) |
|
154 | + { |
|
155 | + foreach ($fields as $field) { |
|
156 | + if ($field instanceof GraphQLField) { |
|
157 | + $this->fields[] = $field; |
|
158 | + } |
|
159 | + } |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Creates a key map to pass to GraphQL registration. |
|
165 | + * @return array |
|
166 | + * @since $VID:$ |
|
167 | + */ |
|
168 | + public function getFieldsForGQL() |
|
169 | + { |
|
170 | + $fields = []; |
|
171 | + foreach ($this->fields() as $field) { |
|
172 | + $config = $field->toArray(); |
|
173 | + $config['resolve'] = [$this, 'resolveField']; |
|
174 | + $fields[$field->name()] = $config; |
|
175 | + } |
|
176 | + return $fields; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * Creates a key map for internal resolver. |
|
182 | + * @return array |
|
183 | + * @since $VID:$ |
|
184 | + */ |
|
185 | + public function getFieldsForResolver() |
|
186 | + { |
|
187 | + $fields = []; |
|
188 | + foreach ($this->fields() as $field) { |
|
189 | + $fields[$field->name()] = $field; |
|
190 | + } |
|
191 | + return $fields; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * @return bool |
|
197 | + */ |
|
198 | + public function isCustomPostType() |
|
199 | + { |
|
200 | + return $this->is_custom_post_type; |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * @param bool $is_custom_post_type |
|
206 | + */ |
|
207 | + protected function setIsCustomPostType($is_custom_post_type) |
|
208 | + { |
|
209 | + $this->is_custom_post_type = filter_var($is_custom_post_type, FILTER_VALIDATE_BOOLEAN); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @param int $value |
|
215 | + * @return int |
|
216 | + * @since $VID:$ |
|
217 | + */ |
|
218 | + public function parseInfiniteValue($value) |
|
219 | + { |
|
220 | + $value = trim($value); |
|
221 | + return $value === null |
|
222 | + || $value === '' |
|
223 | + || $value === '∞' |
|
224 | + || $value === 'INF' |
|
225 | + || $value === INF |
|
226 | + || $value === EE_INF |
|
227 | + || is_infinite((float) $value) |
|
228 | + ? -1 |
|
229 | + : $value; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * @param mixed $source |
|
235 | + * @return EE_Base_Class|null |
|
236 | + * @since $VID:$ |
|
237 | + */ |
|
238 | + private function getModel($source) |
|
239 | + { |
|
240 | + // If it comes from a custom connection |
|
241 | + // where the $source is already instantiated. |
|
242 | + if ($source instanceof EE_Base_Class) { |
|
243 | + return $source; |
|
244 | + } |
|
245 | + return $source instanceof Post ? $this->model->get_one_by_ID($source->ID) : null; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @param mixed $source The source that's passed down the GraphQL queries |
|
251 | + * @param array $args The inputArgs on the field |
|
252 | + * @param AppContext $context The AppContext passed down the GraphQL tree |
|
253 | + * @param ResolveInfo $info The ResolveInfo passed down the GraphQL tree |
|
254 | + * @return string |
|
255 | + * @throws EE_Error |
|
256 | + * @throws InvalidDataTypeException |
|
257 | + * @throws InvalidInterfaceException |
|
258 | + * @throws UnexpectedEntityException |
|
259 | + * @throws UserError |
|
260 | + * @throws InvalidArgumentException |
|
261 | + * @throws ReflectionException |
|
262 | + * @since $VID:$ |
|
263 | + */ |
|
264 | + public function resolveField($source, $args, AppContext $context, ResolveInfo $info) |
|
265 | + { |
|
266 | + $source = $this->getModel($source); |
|
267 | + if ($source instanceof EE_Base_Class) { |
|
268 | + return $this->field_resolver->resolve($source, $args, $context, $info); |
|
269 | + } |
|
270 | + return null; |
|
271 | + } |
|
272 | 272 | |
273 | 273 | } |
274 | 274 | \ No newline at end of file |