@@ -36,7 +36,7 @@ |
||
36 | 36 | |
37 | 37 | |
38 | 38 | /** |
39 | - * @return GraphQLFieldInterface[] |
|
39 | + * @return GraphQLField[] |
|
40 | 40 | * @since $VID:$ |
41 | 41 | */ |
42 | 42 | public function getFields() |
@@ -25,215 +25,215 @@ |
||
25 | 25 | class Price extends TypeBase |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Price constructor. |
|
30 | - * |
|
31 | - * @param EEM_Price $price_model |
|
32 | - */ |
|
33 | - public function __construct(EEM_Price $price_model) |
|
34 | - { |
|
35 | - $this->model = $price_model; |
|
36 | - $this->setName('Price'); |
|
37 | - $this->setDescription(__('A price.', 'event_espresso')); |
|
38 | - $this->setIsCustomPostType(false); |
|
39 | - parent::__construct(); |
|
40 | - } |
|
28 | + /** |
|
29 | + * Price constructor. |
|
30 | + * |
|
31 | + * @param EEM_Price $price_model |
|
32 | + */ |
|
33 | + public function __construct(EEM_Price $price_model) |
|
34 | + { |
|
35 | + $this->model = $price_model; |
|
36 | + $this->setName('Price'); |
|
37 | + $this->setDescription(__('A price.', 'event_espresso')); |
|
38 | + $this->setIsCustomPostType(false); |
|
39 | + parent::__construct(); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @return GraphQLFieldInterface[] |
|
45 | - * @since $VID:$ |
|
46 | - */ |
|
47 | - public function getFields() |
|
48 | - { |
|
49 | - return [ |
|
50 | - new GraphQLField( |
|
51 | - 'id', |
|
52 | - ['non_null' => 'ID'], |
|
53 | - null, |
|
54 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | - ), |
|
56 | - new GraphQLOutputField( |
|
57 | - 'dbId', |
|
58 | - ['non_null' => 'Int'], |
|
59 | - 'ID', |
|
60 | - esc_html__('Price ID', 'event_espresso') |
|
61 | - ), |
|
62 | - new GraphQLField( |
|
63 | - 'name', |
|
64 | - 'String', |
|
65 | - 'name', |
|
66 | - esc_html__('Price Name', 'event_espresso') |
|
67 | - ), |
|
68 | - new GraphQLField( |
|
69 | - 'amount', |
|
70 | - 'Float', |
|
71 | - 'amount', |
|
72 | - esc_html__('Price Amount', 'event_espresso') |
|
73 | - ), |
|
74 | - new GraphQLField( |
|
75 | - 'desc', |
|
76 | - 'String', |
|
77 | - 'desc', |
|
78 | - esc_html__('Price description', 'event_espresso') |
|
79 | - ), |
|
80 | - new GraphQLField( |
|
81 | - 'overrides', |
|
82 | - 'Int', |
|
83 | - 'overrides', |
|
84 | - esc_html__('Price ID for a global Price that will be overridden by this Price.', 'event_espresso') |
|
85 | - ), |
|
86 | - new GraphQLField( |
|
87 | - 'order', |
|
88 | - 'Int', |
|
89 | - 'order', |
|
90 | - esc_html__('Order of Application of Price.', 'event_espresso') |
|
91 | - ), |
|
92 | - new GraphQLOutputField( |
|
93 | - 'parent', |
|
94 | - $this->name(), |
|
95 | - null, |
|
96 | - esc_html__('The parent price of the current price', 'event_espresso') |
|
97 | - ), |
|
98 | - new GraphQLInputField( |
|
99 | - 'parent', |
|
100 | - 'ID', |
|
101 | - null, |
|
102 | - esc_html__('The parent price ID', 'event_espresso') |
|
103 | - ), |
|
104 | - new GraphQLOutputField( |
|
105 | - 'priceType', |
|
106 | - 'PriceType', |
|
107 | - 'type_obj', |
|
108 | - esc_html__('The related price type object.', 'event_espresso') |
|
109 | - ), |
|
110 | - new GraphQLOutputField( |
|
111 | - 'priceTypeOrder', |
|
112 | - 'Int', |
|
113 | - 'type_order', |
|
114 | - esc_html__('Order of Application of Price type.', 'event_espresso') |
|
115 | - ), |
|
116 | - new GraphQLInputField( |
|
117 | - 'priceType', |
|
118 | - 'ID', |
|
119 | - null, |
|
120 | - esc_html__('The price type ID', 'event_espresso') |
|
121 | - ), |
|
122 | - new GraphQLOutputField( |
|
123 | - 'isDeleted', |
|
124 | - 'Boolean', |
|
125 | - 'deleted', |
|
126 | - esc_html__('Flag indicating price has been trashed.', 'event_espresso') |
|
127 | - ), |
|
128 | - new GraphQLField( |
|
129 | - 'isDefault', |
|
130 | - 'Boolean', |
|
131 | - 'is_default', |
|
132 | - esc_html__('Flag indicating price is the default one.', 'event_espresso') |
|
133 | - ), |
|
134 | - new GraphQLOutputField( |
|
135 | - 'isPercent', |
|
136 | - 'Boolean', |
|
137 | - 'is_percent', |
|
138 | - esc_html__('Flag indicating price is a percentage.', 'event_espresso') |
|
139 | - ), |
|
140 | - new GraphQLOutputField( |
|
141 | - 'isBasePrice', |
|
142 | - 'Boolean', |
|
143 | - 'is_base_price', |
|
144 | - esc_html__('Flag indicating price is a base price type.', 'event_espresso') |
|
145 | - ), |
|
146 | - new GraphQLOutputField( |
|
147 | - 'isDiscount', |
|
148 | - 'Boolean', |
|
149 | - 'is_discount', |
|
150 | - esc_html__('Flag indicating price is a discount.', 'event_espresso') |
|
151 | - ), |
|
152 | - new GraphQLOutputField( |
|
153 | - 'isTax', |
|
154 | - 'Boolean', |
|
155 | - 'is_tax', |
|
156 | - esc_html__('Flag indicating price is a tax.', 'event_espresso') |
|
157 | - ), |
|
158 | - new GraphQLOutputField( |
|
159 | - 'wpUser', |
|
160 | - 'User', |
|
161 | - null, |
|
162 | - esc_html__('Price Creator', 'event_espresso') |
|
163 | - ), |
|
164 | - new GraphQLInputField( |
|
165 | - 'wpUser', |
|
166 | - 'Int', |
|
167 | - null, |
|
168 | - esc_html__('Price Creator ID', 'event_espresso') |
|
169 | - ), |
|
170 | - ]; |
|
171 | - } |
|
43 | + /** |
|
44 | + * @return GraphQLFieldInterface[] |
|
45 | + * @since $VID:$ |
|
46 | + */ |
|
47 | + public function getFields() |
|
48 | + { |
|
49 | + return [ |
|
50 | + new GraphQLField( |
|
51 | + 'id', |
|
52 | + ['non_null' => 'ID'], |
|
53 | + null, |
|
54 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | + ), |
|
56 | + new GraphQLOutputField( |
|
57 | + 'dbId', |
|
58 | + ['non_null' => 'Int'], |
|
59 | + 'ID', |
|
60 | + esc_html__('Price ID', 'event_espresso') |
|
61 | + ), |
|
62 | + new GraphQLField( |
|
63 | + 'name', |
|
64 | + 'String', |
|
65 | + 'name', |
|
66 | + esc_html__('Price Name', 'event_espresso') |
|
67 | + ), |
|
68 | + new GraphQLField( |
|
69 | + 'amount', |
|
70 | + 'Float', |
|
71 | + 'amount', |
|
72 | + esc_html__('Price Amount', 'event_espresso') |
|
73 | + ), |
|
74 | + new GraphQLField( |
|
75 | + 'desc', |
|
76 | + 'String', |
|
77 | + 'desc', |
|
78 | + esc_html__('Price description', 'event_espresso') |
|
79 | + ), |
|
80 | + new GraphQLField( |
|
81 | + 'overrides', |
|
82 | + 'Int', |
|
83 | + 'overrides', |
|
84 | + esc_html__('Price ID for a global Price that will be overridden by this Price.', 'event_espresso') |
|
85 | + ), |
|
86 | + new GraphQLField( |
|
87 | + 'order', |
|
88 | + 'Int', |
|
89 | + 'order', |
|
90 | + esc_html__('Order of Application of Price.', 'event_espresso') |
|
91 | + ), |
|
92 | + new GraphQLOutputField( |
|
93 | + 'parent', |
|
94 | + $this->name(), |
|
95 | + null, |
|
96 | + esc_html__('The parent price of the current price', 'event_espresso') |
|
97 | + ), |
|
98 | + new GraphQLInputField( |
|
99 | + 'parent', |
|
100 | + 'ID', |
|
101 | + null, |
|
102 | + esc_html__('The parent price ID', 'event_espresso') |
|
103 | + ), |
|
104 | + new GraphQLOutputField( |
|
105 | + 'priceType', |
|
106 | + 'PriceType', |
|
107 | + 'type_obj', |
|
108 | + esc_html__('The related price type object.', 'event_espresso') |
|
109 | + ), |
|
110 | + new GraphQLOutputField( |
|
111 | + 'priceTypeOrder', |
|
112 | + 'Int', |
|
113 | + 'type_order', |
|
114 | + esc_html__('Order of Application of Price type.', 'event_espresso') |
|
115 | + ), |
|
116 | + new GraphQLInputField( |
|
117 | + 'priceType', |
|
118 | + 'ID', |
|
119 | + null, |
|
120 | + esc_html__('The price type ID', 'event_espresso') |
|
121 | + ), |
|
122 | + new GraphQLOutputField( |
|
123 | + 'isDeleted', |
|
124 | + 'Boolean', |
|
125 | + 'deleted', |
|
126 | + esc_html__('Flag indicating price has been trashed.', 'event_espresso') |
|
127 | + ), |
|
128 | + new GraphQLField( |
|
129 | + 'isDefault', |
|
130 | + 'Boolean', |
|
131 | + 'is_default', |
|
132 | + esc_html__('Flag indicating price is the default one.', 'event_espresso') |
|
133 | + ), |
|
134 | + new GraphQLOutputField( |
|
135 | + 'isPercent', |
|
136 | + 'Boolean', |
|
137 | + 'is_percent', |
|
138 | + esc_html__('Flag indicating price is a percentage.', 'event_espresso') |
|
139 | + ), |
|
140 | + new GraphQLOutputField( |
|
141 | + 'isBasePrice', |
|
142 | + 'Boolean', |
|
143 | + 'is_base_price', |
|
144 | + esc_html__('Flag indicating price is a base price type.', 'event_espresso') |
|
145 | + ), |
|
146 | + new GraphQLOutputField( |
|
147 | + 'isDiscount', |
|
148 | + 'Boolean', |
|
149 | + 'is_discount', |
|
150 | + esc_html__('Flag indicating price is a discount.', 'event_espresso') |
|
151 | + ), |
|
152 | + new GraphQLOutputField( |
|
153 | + 'isTax', |
|
154 | + 'Boolean', |
|
155 | + 'is_tax', |
|
156 | + esc_html__('Flag indicating price is a tax.', 'event_espresso') |
|
157 | + ), |
|
158 | + new GraphQLOutputField( |
|
159 | + 'wpUser', |
|
160 | + 'User', |
|
161 | + null, |
|
162 | + esc_html__('Price Creator', 'event_espresso') |
|
163 | + ), |
|
164 | + new GraphQLInputField( |
|
165 | + 'wpUser', |
|
166 | + 'Int', |
|
167 | + null, |
|
168 | + esc_html__('Price Creator ID', 'event_espresso') |
|
169 | + ), |
|
170 | + ]; |
|
171 | + } |
|
172 | 172 | |
173 | 173 | |
174 | - /** |
|
175 | - * @param array $inputFields The mutation input fields. |
|
176 | - * @throws InvalidArgumentException |
|
177 | - * @throws ReflectionException |
|
178 | - * @since $VID:$ |
|
179 | - */ |
|
180 | - public function registerMutations(array $inputFields) |
|
181 | - { |
|
182 | - // Register mutation to update an entity. |
|
183 | - register_graphql_mutation( |
|
184 | - 'update' . $this->name(), |
|
185 | - [ |
|
186 | - 'inputFields' => $inputFields, |
|
187 | - 'outputFields' => [ |
|
188 | - lcfirst($this->name()) => [ |
|
189 | - 'type' => $this->name(), |
|
190 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
191 | - ], |
|
192 | - ], |
|
193 | - 'mutateAndGetPayload' => PriceUpdate::mutateAndGetPayload($this->model, $this), |
|
194 | - ] |
|
195 | - ); |
|
196 | - // Register mutation to delete an entity. |
|
197 | - register_graphql_mutation( |
|
198 | - 'delete' . $this->name(), |
|
199 | - [ |
|
200 | - 'inputFields' => [ |
|
201 | - 'id' => $inputFields['id'], |
|
202 | - 'deletePermanently' => [ |
|
203 | - 'type' => 'Boolean', |
|
204 | - 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
205 | - ], |
|
206 | - ], |
|
207 | - 'outputFields' => [ |
|
208 | - lcfirst($this->name()) => [ |
|
209 | - 'type' => $this->name(), |
|
210 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
211 | - 'resolve' => static function ($payload) { |
|
212 | - $deleted = (object) $payload['deleted']; |
|
174 | + /** |
|
175 | + * @param array $inputFields The mutation input fields. |
|
176 | + * @throws InvalidArgumentException |
|
177 | + * @throws ReflectionException |
|
178 | + * @since $VID:$ |
|
179 | + */ |
|
180 | + public function registerMutations(array $inputFields) |
|
181 | + { |
|
182 | + // Register mutation to update an entity. |
|
183 | + register_graphql_mutation( |
|
184 | + 'update' . $this->name(), |
|
185 | + [ |
|
186 | + 'inputFields' => $inputFields, |
|
187 | + 'outputFields' => [ |
|
188 | + lcfirst($this->name()) => [ |
|
189 | + 'type' => $this->name(), |
|
190 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
191 | + ], |
|
192 | + ], |
|
193 | + 'mutateAndGetPayload' => PriceUpdate::mutateAndGetPayload($this->model, $this), |
|
194 | + ] |
|
195 | + ); |
|
196 | + // Register mutation to delete an entity. |
|
197 | + register_graphql_mutation( |
|
198 | + 'delete' . $this->name(), |
|
199 | + [ |
|
200 | + 'inputFields' => [ |
|
201 | + 'id' => $inputFields['id'], |
|
202 | + 'deletePermanently' => [ |
|
203 | + 'type' => 'Boolean', |
|
204 | + 'description' => esc_html__('Whether to delete the entity permanently.', 'event_espresso'), |
|
205 | + ], |
|
206 | + ], |
|
207 | + 'outputFields' => [ |
|
208 | + lcfirst($this->name()) => [ |
|
209 | + 'type' => $this->name(), |
|
210 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
211 | + 'resolve' => static function ($payload) { |
|
212 | + $deleted = (object) $payload['deleted']; |
|
213 | 213 | |
214 | - return ! empty($deleted) ? $deleted : null; |
|
215 | - }, |
|
216 | - ], |
|
217 | - ], |
|
218 | - 'mutateAndGetPayload' => PriceDelete::mutateAndGetPayload($this->model, $this), |
|
219 | - ] |
|
220 | - ); |
|
214 | + return ! empty($deleted) ? $deleted : null; |
|
215 | + }, |
|
216 | + ], |
|
217 | + ], |
|
218 | + 'mutateAndGetPayload' => PriceDelete::mutateAndGetPayload($this->model, $this), |
|
219 | + ] |
|
220 | + ); |
|
221 | 221 | |
222 | - // remove primary key from input. |
|
223 | - unset($inputFields['id']); |
|
224 | - // Register mutation to update an entity. |
|
225 | - register_graphql_mutation( |
|
226 | - 'create' . $this->name(), |
|
227 | - [ |
|
228 | - 'inputFields' => $inputFields, |
|
229 | - 'outputFields' => [ |
|
230 | - lcfirst($this->name()) => [ |
|
231 | - 'type' => $this->name(), |
|
232 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
233 | - ], |
|
234 | - ], |
|
235 | - 'mutateAndGetPayload' => PriceCreate::mutateAndGetPayload($this->model, $this), |
|
236 | - ] |
|
237 | - ); |
|
238 | - } |
|
222 | + // remove primary key from input. |
|
223 | + unset($inputFields['id']); |
|
224 | + // Register mutation to update an entity. |
|
225 | + register_graphql_mutation( |
|
226 | + 'create' . $this->name(), |
|
227 | + [ |
|
228 | + 'inputFields' => $inputFields, |
|
229 | + 'outputFields' => [ |
|
230 | + lcfirst($this->name()) => [ |
|
231 | + 'type' => $this->name(), |
|
232 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
233 | + ], |
|
234 | + ], |
|
235 | + 'mutateAndGetPayload' => PriceCreate::mutateAndGetPayload($this->model, $this), |
|
236 | + ] |
|
237 | + ); |
|
238 | + } |
|
239 | 239 | } |
@@ -167,7 +167,7 @@ |
||
167 | 167 | /** |
168 | 168 | * get is Price Type a percent? |
169 | 169 | * |
170 | - * @return mixed |
|
170 | + * @return boolean |
|
171 | 171 | * @throws EE_Error |
172 | 172 | * @throws InvalidArgumentException |
173 | 173 | * @throws InvalidDataTypeException |
@@ -13,276 +13,276 @@ |
||
13 | 13 | class EE_Price_Type extends EE_Soft_Delete_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $props_n_values |
|
18 | - * @return EE_Price_Type |
|
19 | - * @throws EE_Error |
|
20 | - * @throws InvalidArgumentException |
|
21 | - * @throws ReflectionException |
|
22 | - * @throws InvalidDataTypeException |
|
23 | - * @throws InvalidInterfaceException |
|
24 | - */ |
|
25 | - public static function new_instance($props_n_values = array()) |
|
26 | - { |
|
27 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
28 | - return $has_object ? $has_object : new self($props_n_values); |
|
29 | - } |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @param array $props_n_values |
|
34 | - * @return EE_Price_Type |
|
35 | - * @throws EE_Error |
|
36 | - * @throws InvalidArgumentException |
|
37 | - * @throws ReflectionException |
|
38 | - * @throws InvalidDataTypeException |
|
39 | - * @throws InvalidInterfaceException |
|
40 | - */ |
|
41 | - public static function new_instance_from_db($props_n_values = array()) |
|
42 | - { |
|
43 | - return new self($props_n_values, true); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Set Price Type Name |
|
49 | - * |
|
50 | - * @param string $PRT_name |
|
51 | - * @throws EE_Error |
|
52 | - * @throws InvalidArgumentException |
|
53 | - * @throws ReflectionException |
|
54 | - * @throws InvalidDataTypeException |
|
55 | - * @throws InvalidInterfaceException |
|
56 | - */ |
|
57 | - public function set_name($PRT_name = '') |
|
58 | - { |
|
59 | - $this->set('PRT_name', $PRT_name); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Set Price Type a percent |
|
65 | - * |
|
66 | - * @param bool $PRT_is_percent |
|
67 | - * @throws EE_Error |
|
68 | - * @throws InvalidArgumentException |
|
69 | - * @throws ReflectionException |
|
70 | - * @throws InvalidDataTypeException |
|
71 | - * @throws InvalidInterfaceException |
|
72 | - */ |
|
73 | - public function set_is_percent($PRT_is_percent = false) |
|
74 | - { |
|
75 | - $this->set('PRT_is_percent', $PRT_is_percent); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Set Price Type order |
|
81 | - * |
|
82 | - * @param int $PRT_order |
|
83 | - * @throws EE_Error |
|
84 | - * @throws InvalidArgumentException |
|
85 | - * @throws ReflectionException |
|
86 | - * @throws InvalidDataTypeException |
|
87 | - * @throws InvalidInterfaceException |
|
88 | - */ |
|
89 | - public function set_order($PRT_order = 0) |
|
90 | - { |
|
91 | - $this->set('PRT_order', $PRT_order); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - * @throws ReflectionException |
|
101 | - */ |
|
102 | - public function move_to_trash() |
|
103 | - { |
|
104 | - $this->set('PRT_deleted', true); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @throws EE_Error |
|
110 | - * @throws InvalidArgumentException |
|
111 | - * @throws InvalidDataTypeException |
|
112 | - * @throws InvalidInterfaceException |
|
113 | - * @throws ReflectionException |
|
114 | - */ |
|
115 | - public function restore_from_trash() |
|
116 | - { |
|
117 | - $this->set('PRT_deleted', false); |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * get Price Type Name |
|
123 | - * |
|
124 | - * @return mixed |
|
125 | - * @throws EE_Error |
|
126 | - * @throws InvalidArgumentException |
|
127 | - * @throws InvalidDataTypeException |
|
128 | - * @throws InvalidInterfaceException |
|
129 | - * @throws ReflectionException |
|
130 | - */ |
|
131 | - public function name() |
|
132 | - { |
|
133 | - return $this->get('PRT_name'); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * get base Price Type |
|
139 | - * |
|
140 | - * @return mixed |
|
141 | - * @throws EE_Error |
|
142 | - * @throws InvalidArgumentException |
|
143 | - * @throws InvalidDataTypeException |
|
144 | - * @throws InvalidInterfaceException |
|
145 | - * @throws ReflectionException |
|
146 | - */ |
|
147 | - public function base_type() |
|
148 | - { |
|
149 | - return $this->get('PBT_ID'); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @return mixed |
|
155 | - * @throws EE_Error |
|
156 | - * @throws InvalidArgumentException |
|
157 | - * @throws ReflectionException |
|
158 | - * @throws InvalidDataTypeException |
|
159 | - * @throws InvalidInterfaceException |
|
160 | - */ |
|
161 | - public function base_type_name() |
|
162 | - { |
|
163 | - return $this->get_pretty('PBT_ID'); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * get is Price Type a percent? |
|
169 | - * |
|
170 | - * @return mixed |
|
171 | - * @throws EE_Error |
|
172 | - * @throws InvalidArgumentException |
|
173 | - * @throws InvalidDataTypeException |
|
174 | - * @throws InvalidInterfaceException |
|
175 | - * @throws ReflectionException |
|
176 | - */ |
|
177 | - public function is_base_price() |
|
178 | - { |
|
179 | - return $this->get('PBT_ID') === EEM_Price_Type::base_type_base_price; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * get is Price Type a percent? |
|
185 | - * |
|
186 | - * @return mixed |
|
187 | - * @throws EE_Error |
|
188 | - * @throws InvalidArgumentException |
|
189 | - * @throws InvalidDataTypeException |
|
190 | - * @throws InvalidInterfaceException |
|
191 | - * @throws ReflectionException |
|
192 | - */ |
|
193 | - public function is_percent() |
|
194 | - { |
|
195 | - return $this->get('PRT_is_percent'); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * @return bool |
|
201 | - * @throws EE_Error |
|
202 | - * @throws InvalidArgumentException |
|
203 | - * @throws ReflectionException |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - */ |
|
207 | - public function is_discount() |
|
208 | - { |
|
209 | - return $this->get('PBT_ID') === EEM_Price_Type::base_type_discount; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * @return bool |
|
215 | - * @throws EE_Error |
|
216 | - * @throws InvalidArgumentException |
|
217 | - * @throws ReflectionException |
|
218 | - * @throws InvalidDataTypeException |
|
219 | - * @throws InvalidInterfaceException |
|
220 | - */ |
|
221 | - public function is_surcharge() |
|
222 | - { |
|
223 | - return $this->get('PBT_ID') === EEM_Price_Type::base_type_surcharge; |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * @return bool |
|
229 | - * @throws EE_Error |
|
230 | - * @throws InvalidArgumentException |
|
231 | - * @throws ReflectionException |
|
232 | - * @throws InvalidDataTypeException |
|
233 | - * @throws InvalidInterfaceException |
|
234 | - */ |
|
235 | - public function is_tax() |
|
236 | - { |
|
237 | - return $this->get('PBT_ID') === EEM_Price_Type::base_type_tax; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * get the author of the price type. |
|
243 | - * |
|
244 | - * @return int |
|
245 | - * @throws EE_Error |
|
246 | - * @throws InvalidArgumentException |
|
247 | - * @throws ReflectionException |
|
248 | - * @throws InvalidDataTypeException |
|
249 | - * @throws InvalidInterfaceException |
|
250 | - * @since 4.5.0 |
|
251 | - */ |
|
252 | - public function wp_user() |
|
253 | - { |
|
254 | - return $this->get('PRT_wp_user'); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * get Price Type order |
|
260 | - * |
|
261 | - * @return int |
|
262 | - * @throws EE_Error |
|
263 | - * @throws InvalidArgumentException |
|
264 | - * @throws InvalidDataTypeException |
|
265 | - * @throws InvalidInterfaceException |
|
266 | - * @throws ReflectionException |
|
267 | - */ |
|
268 | - public function order() |
|
269 | - { |
|
270 | - return $this->get('PRT_order'); |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * get is Price Type deleted ? |
|
276 | - * |
|
277 | - * @return mixed |
|
278 | - * @throws EE_Error |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws InvalidDataTypeException |
|
281 | - * @throws InvalidInterfaceException |
|
282 | - * @throws ReflectionException |
|
283 | - */ |
|
284 | - public function deleted() |
|
285 | - { |
|
286 | - return $this->get('PRT_deleted'); |
|
287 | - } |
|
16 | + /** |
|
17 | + * @param array $props_n_values |
|
18 | + * @return EE_Price_Type |
|
19 | + * @throws EE_Error |
|
20 | + * @throws InvalidArgumentException |
|
21 | + * @throws ReflectionException |
|
22 | + * @throws InvalidDataTypeException |
|
23 | + * @throws InvalidInterfaceException |
|
24 | + */ |
|
25 | + public static function new_instance($props_n_values = array()) |
|
26 | + { |
|
27 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
28 | + return $has_object ? $has_object : new self($props_n_values); |
|
29 | + } |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @param array $props_n_values |
|
34 | + * @return EE_Price_Type |
|
35 | + * @throws EE_Error |
|
36 | + * @throws InvalidArgumentException |
|
37 | + * @throws ReflectionException |
|
38 | + * @throws InvalidDataTypeException |
|
39 | + * @throws InvalidInterfaceException |
|
40 | + */ |
|
41 | + public static function new_instance_from_db($props_n_values = array()) |
|
42 | + { |
|
43 | + return new self($props_n_values, true); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Set Price Type Name |
|
49 | + * |
|
50 | + * @param string $PRT_name |
|
51 | + * @throws EE_Error |
|
52 | + * @throws InvalidArgumentException |
|
53 | + * @throws ReflectionException |
|
54 | + * @throws InvalidDataTypeException |
|
55 | + * @throws InvalidInterfaceException |
|
56 | + */ |
|
57 | + public function set_name($PRT_name = '') |
|
58 | + { |
|
59 | + $this->set('PRT_name', $PRT_name); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Set Price Type a percent |
|
65 | + * |
|
66 | + * @param bool $PRT_is_percent |
|
67 | + * @throws EE_Error |
|
68 | + * @throws InvalidArgumentException |
|
69 | + * @throws ReflectionException |
|
70 | + * @throws InvalidDataTypeException |
|
71 | + * @throws InvalidInterfaceException |
|
72 | + */ |
|
73 | + public function set_is_percent($PRT_is_percent = false) |
|
74 | + { |
|
75 | + $this->set('PRT_is_percent', $PRT_is_percent); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Set Price Type order |
|
81 | + * |
|
82 | + * @param int $PRT_order |
|
83 | + * @throws EE_Error |
|
84 | + * @throws InvalidArgumentException |
|
85 | + * @throws ReflectionException |
|
86 | + * @throws InvalidDataTypeException |
|
87 | + * @throws InvalidInterfaceException |
|
88 | + */ |
|
89 | + public function set_order($PRT_order = 0) |
|
90 | + { |
|
91 | + $this->set('PRT_order', $PRT_order); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + * @throws ReflectionException |
|
101 | + */ |
|
102 | + public function move_to_trash() |
|
103 | + { |
|
104 | + $this->set('PRT_deleted', true); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @throws EE_Error |
|
110 | + * @throws InvalidArgumentException |
|
111 | + * @throws InvalidDataTypeException |
|
112 | + * @throws InvalidInterfaceException |
|
113 | + * @throws ReflectionException |
|
114 | + */ |
|
115 | + public function restore_from_trash() |
|
116 | + { |
|
117 | + $this->set('PRT_deleted', false); |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * get Price Type Name |
|
123 | + * |
|
124 | + * @return mixed |
|
125 | + * @throws EE_Error |
|
126 | + * @throws InvalidArgumentException |
|
127 | + * @throws InvalidDataTypeException |
|
128 | + * @throws InvalidInterfaceException |
|
129 | + * @throws ReflectionException |
|
130 | + */ |
|
131 | + public function name() |
|
132 | + { |
|
133 | + return $this->get('PRT_name'); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * get base Price Type |
|
139 | + * |
|
140 | + * @return mixed |
|
141 | + * @throws EE_Error |
|
142 | + * @throws InvalidArgumentException |
|
143 | + * @throws InvalidDataTypeException |
|
144 | + * @throws InvalidInterfaceException |
|
145 | + * @throws ReflectionException |
|
146 | + */ |
|
147 | + public function base_type() |
|
148 | + { |
|
149 | + return $this->get('PBT_ID'); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @return mixed |
|
155 | + * @throws EE_Error |
|
156 | + * @throws InvalidArgumentException |
|
157 | + * @throws ReflectionException |
|
158 | + * @throws InvalidDataTypeException |
|
159 | + * @throws InvalidInterfaceException |
|
160 | + */ |
|
161 | + public function base_type_name() |
|
162 | + { |
|
163 | + return $this->get_pretty('PBT_ID'); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * get is Price Type a percent? |
|
169 | + * |
|
170 | + * @return mixed |
|
171 | + * @throws EE_Error |
|
172 | + * @throws InvalidArgumentException |
|
173 | + * @throws InvalidDataTypeException |
|
174 | + * @throws InvalidInterfaceException |
|
175 | + * @throws ReflectionException |
|
176 | + */ |
|
177 | + public function is_base_price() |
|
178 | + { |
|
179 | + return $this->get('PBT_ID') === EEM_Price_Type::base_type_base_price; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * get is Price Type a percent? |
|
185 | + * |
|
186 | + * @return mixed |
|
187 | + * @throws EE_Error |
|
188 | + * @throws InvalidArgumentException |
|
189 | + * @throws InvalidDataTypeException |
|
190 | + * @throws InvalidInterfaceException |
|
191 | + * @throws ReflectionException |
|
192 | + */ |
|
193 | + public function is_percent() |
|
194 | + { |
|
195 | + return $this->get('PRT_is_percent'); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * @return bool |
|
201 | + * @throws EE_Error |
|
202 | + * @throws InvalidArgumentException |
|
203 | + * @throws ReflectionException |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + */ |
|
207 | + public function is_discount() |
|
208 | + { |
|
209 | + return $this->get('PBT_ID') === EEM_Price_Type::base_type_discount; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * @return bool |
|
215 | + * @throws EE_Error |
|
216 | + * @throws InvalidArgumentException |
|
217 | + * @throws ReflectionException |
|
218 | + * @throws InvalidDataTypeException |
|
219 | + * @throws InvalidInterfaceException |
|
220 | + */ |
|
221 | + public function is_surcharge() |
|
222 | + { |
|
223 | + return $this->get('PBT_ID') === EEM_Price_Type::base_type_surcharge; |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * @return bool |
|
229 | + * @throws EE_Error |
|
230 | + * @throws InvalidArgumentException |
|
231 | + * @throws ReflectionException |
|
232 | + * @throws InvalidDataTypeException |
|
233 | + * @throws InvalidInterfaceException |
|
234 | + */ |
|
235 | + public function is_tax() |
|
236 | + { |
|
237 | + return $this->get('PBT_ID') === EEM_Price_Type::base_type_tax; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * get the author of the price type. |
|
243 | + * |
|
244 | + * @return int |
|
245 | + * @throws EE_Error |
|
246 | + * @throws InvalidArgumentException |
|
247 | + * @throws ReflectionException |
|
248 | + * @throws InvalidDataTypeException |
|
249 | + * @throws InvalidInterfaceException |
|
250 | + * @since 4.5.0 |
|
251 | + */ |
|
252 | + public function wp_user() |
|
253 | + { |
|
254 | + return $this->get('PRT_wp_user'); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * get Price Type order |
|
260 | + * |
|
261 | + * @return int |
|
262 | + * @throws EE_Error |
|
263 | + * @throws InvalidArgumentException |
|
264 | + * @throws InvalidDataTypeException |
|
265 | + * @throws InvalidInterfaceException |
|
266 | + * @throws ReflectionException |
|
267 | + */ |
|
268 | + public function order() |
|
269 | + { |
|
270 | + return $this->get('PRT_order'); |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * get is Price Type deleted ? |
|
276 | + * |
|
277 | + * @return mixed |
|
278 | + * @throws EE_Error |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws InvalidDataTypeException |
|
281 | + * @throws InvalidInterfaceException |
|
282 | + * @throws ReflectionException |
|
283 | + */ |
|
284 | + public function deleted() |
|
285 | + { |
|
286 | + return $this->get('PRT_deleted'); |
|
287 | + } |
|
288 | 288 | } |
@@ -22,100 +22,100 @@ |
||
22 | 22 | class PriceType extends TypeBase |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * PriceType constructor. |
|
27 | - * |
|
28 | - * @param EEM_Price_Type $price_type_model |
|
29 | - */ |
|
30 | - public function __construct(EEM_Price_Type $price_type_model) |
|
31 | - { |
|
32 | - $this->model = $price_type_model; |
|
33 | - $this->setName('PriceType'); |
|
34 | - $this->setDescription(__('A price type.', 'event_espresso')); |
|
35 | - $this->setIsCustomPostType(false); |
|
36 | - parent::__construct(); |
|
37 | - } |
|
25 | + /** |
|
26 | + * PriceType constructor. |
|
27 | + * |
|
28 | + * @param EEM_Price_Type $price_type_model |
|
29 | + */ |
|
30 | + public function __construct(EEM_Price_Type $price_type_model) |
|
31 | + { |
|
32 | + $this->model = $price_type_model; |
|
33 | + $this->setName('PriceType'); |
|
34 | + $this->setDescription(__('A price type.', 'event_espresso')); |
|
35 | + $this->setIsCustomPostType(false); |
|
36 | + parent::__construct(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @return GraphQLFieldInterface[] |
|
42 | - * @since $VID:$ |
|
43 | - */ |
|
44 | - public function getFields() |
|
45 | - { |
|
46 | - return [ |
|
47 | - new GraphQLField( |
|
48 | - 'id', |
|
49 | - ['non_null' => 'ID'], |
|
50 | - null, |
|
51 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
52 | - ), |
|
53 | - new GraphQLOutputField( |
|
54 | - 'dbId', |
|
55 | - ['non_null' => 'Int'], |
|
56 | - 'ID', |
|
57 | - esc_html__('Price type ID', 'event_espresso') |
|
58 | - ), |
|
59 | - new GraphQLField( |
|
60 | - 'baseType', |
|
61 | - 'PriceBaseTypeEnum', |
|
62 | - 'base_type', |
|
63 | - esc_html__('Price Base type', 'event_espresso') |
|
64 | - ), |
|
65 | - new GraphQLField( |
|
66 | - 'isBasePrice', |
|
67 | - 'Boolean', |
|
68 | - 'is_base_price', |
|
69 | - esc_html__('Flag indicating price type is a base price.', 'event_espresso') |
|
70 | - ), |
|
71 | - new GraphQLField( |
|
72 | - 'isDeleted', |
|
73 | - 'Boolean', |
|
74 | - 'deleted', |
|
75 | - esc_html__('Flag indicating price type has been trashed.', 'event_espresso') |
|
76 | - ), |
|
77 | - new GraphQLOutputField( |
|
78 | - 'isDiscount', |
|
79 | - 'Boolean', |
|
80 | - 'is_discount', |
|
81 | - esc_html__('Flag indicating price type is a discount.', 'event_espresso') |
|
82 | - ), |
|
83 | - new GraphQLField( |
|
84 | - 'isPercent', |
|
85 | - 'Boolean', |
|
86 | - 'is_percent', |
|
87 | - esc_html__('Flag indicating price type is a percentage.', 'event_espresso') |
|
88 | - ), |
|
89 | - new GraphQLOutputField( |
|
90 | - 'isTax', |
|
91 | - 'Boolean', |
|
92 | - 'is_tax', |
|
93 | - esc_html__('Flag indicating price is a tax.', 'event_espresso') |
|
94 | - ), |
|
95 | - new GraphQLField( |
|
96 | - 'name', |
|
97 | - 'String', |
|
98 | - 'name', |
|
99 | - esc_html__('Price type Name', 'event_espresso') |
|
100 | - ), |
|
101 | - new GraphQLField( |
|
102 | - 'order', |
|
103 | - 'Int', |
|
104 | - 'order', |
|
105 | - esc_html__('Order in which price should be applied.', 'event_espresso') |
|
106 | - ), |
|
107 | - new GraphQLOutputField( |
|
108 | - 'wpUser', |
|
109 | - 'User', |
|
110 | - null, |
|
111 | - esc_html__('Price Type Creator', 'event_espresso') |
|
112 | - ), |
|
113 | - new GraphQLInputField( |
|
114 | - 'wpUser', |
|
115 | - 'Int', |
|
116 | - null, |
|
117 | - esc_html__('Price Type Creator ID', 'event_espresso') |
|
118 | - ), |
|
119 | - ]; |
|
120 | - } |
|
40 | + /** |
|
41 | + * @return GraphQLFieldInterface[] |
|
42 | + * @since $VID:$ |
|
43 | + */ |
|
44 | + public function getFields() |
|
45 | + { |
|
46 | + return [ |
|
47 | + new GraphQLField( |
|
48 | + 'id', |
|
49 | + ['non_null' => 'ID'], |
|
50 | + null, |
|
51 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
52 | + ), |
|
53 | + new GraphQLOutputField( |
|
54 | + 'dbId', |
|
55 | + ['non_null' => 'Int'], |
|
56 | + 'ID', |
|
57 | + esc_html__('Price type ID', 'event_espresso') |
|
58 | + ), |
|
59 | + new GraphQLField( |
|
60 | + 'baseType', |
|
61 | + 'PriceBaseTypeEnum', |
|
62 | + 'base_type', |
|
63 | + esc_html__('Price Base type', 'event_espresso') |
|
64 | + ), |
|
65 | + new GraphQLField( |
|
66 | + 'isBasePrice', |
|
67 | + 'Boolean', |
|
68 | + 'is_base_price', |
|
69 | + esc_html__('Flag indicating price type is a base price.', 'event_espresso') |
|
70 | + ), |
|
71 | + new GraphQLField( |
|
72 | + 'isDeleted', |
|
73 | + 'Boolean', |
|
74 | + 'deleted', |
|
75 | + esc_html__('Flag indicating price type has been trashed.', 'event_espresso') |
|
76 | + ), |
|
77 | + new GraphQLOutputField( |
|
78 | + 'isDiscount', |
|
79 | + 'Boolean', |
|
80 | + 'is_discount', |
|
81 | + esc_html__('Flag indicating price type is a discount.', 'event_espresso') |
|
82 | + ), |
|
83 | + new GraphQLField( |
|
84 | + 'isPercent', |
|
85 | + 'Boolean', |
|
86 | + 'is_percent', |
|
87 | + esc_html__('Flag indicating price type is a percentage.', 'event_espresso') |
|
88 | + ), |
|
89 | + new GraphQLOutputField( |
|
90 | + 'isTax', |
|
91 | + 'Boolean', |
|
92 | + 'is_tax', |
|
93 | + esc_html__('Flag indicating price is a tax.', 'event_espresso') |
|
94 | + ), |
|
95 | + new GraphQLField( |
|
96 | + 'name', |
|
97 | + 'String', |
|
98 | + 'name', |
|
99 | + esc_html__('Price type Name', 'event_espresso') |
|
100 | + ), |
|
101 | + new GraphQLField( |
|
102 | + 'order', |
|
103 | + 'Int', |
|
104 | + 'order', |
|
105 | + esc_html__('Order in which price should be applied.', 'event_espresso') |
|
106 | + ), |
|
107 | + new GraphQLOutputField( |
|
108 | + 'wpUser', |
|
109 | + 'User', |
|
110 | + null, |
|
111 | + esc_html__('Price Type Creator', 'event_espresso') |
|
112 | + ), |
|
113 | + new GraphQLInputField( |
|
114 | + 'wpUser', |
|
115 | + 'Int', |
|
116 | + null, |
|
117 | + esc_html__('Price Type Creator ID', 'event_espresso') |
|
118 | + ), |
|
119 | + ]; |
|
120 | + } |
|
121 | 121 | } |
@@ -13,430 +13,430 @@ |
||
13 | 13 | class EE_Price extends EE_Soft_Delete_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $props_n_values incoming values |
|
18 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
19 | - * used.) |
|
20 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
21 | - * date_format and the second value is the time format |
|
22 | - * @return EE_Price |
|
23 | - * @throws EE_Error |
|
24 | - * @throws InvalidArgumentException |
|
25 | - * @throws ReflectionException |
|
26 | - * @throws InvalidDataTypeException |
|
27 | - * @throws InvalidInterfaceException |
|
28 | - */ |
|
29 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
30 | - { |
|
31 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
32 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @param array $props_n_values incoming values from the database |
|
38 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
39 | - * the website will be used. |
|
40 | - * @return EE_Price |
|
41 | - * @throws EE_Error |
|
42 | - * @throws InvalidArgumentException |
|
43 | - * @throws ReflectionException |
|
44 | - * @throws InvalidDataTypeException |
|
45 | - * @throws InvalidInterfaceException |
|
46 | - */ |
|
47 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
48 | - { |
|
49 | - return new self($props_n_values, true, $timezone); |
|
50 | - } |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Set Price type ID |
|
55 | - * |
|
56 | - * @param int $PRT_ID |
|
57 | - * @throws EE_Error |
|
58 | - * @throws InvalidArgumentException |
|
59 | - * @throws ReflectionException |
|
60 | - * @throws InvalidDataTypeException |
|
61 | - * @throws InvalidInterfaceException |
|
62 | - */ |
|
63 | - public function set_type($PRT_ID = 0) |
|
64 | - { |
|
65 | - $this->set('PRT_ID', $PRT_ID); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Set Price Amount |
|
71 | - * |
|
72 | - * @param float $PRC_amount |
|
73 | - * @throws EE_Error |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @throws ReflectionException |
|
76 | - * @throws InvalidDataTypeException |
|
77 | - * @throws InvalidInterfaceException |
|
78 | - */ |
|
79 | - public function set_amount($PRC_amount = 0.00) |
|
80 | - { |
|
81 | - $this->set('PRC_amount', $PRC_amount); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Set Price Name |
|
87 | - * |
|
88 | - * @param string $PRC_name |
|
89 | - * @throws EE_Error |
|
90 | - * @throws InvalidArgumentException |
|
91 | - * @throws ReflectionException |
|
92 | - * @throws InvalidDataTypeException |
|
93 | - * @throws InvalidInterfaceException |
|
94 | - */ |
|
95 | - public function set_name($PRC_name = '') |
|
96 | - { |
|
97 | - $this->set('PRC_name', $PRC_name); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Set Price Description |
|
103 | - * |
|
104 | - * @param string $PRC_desc |
|
105 | - * @throws EE_Error |
|
106 | - * @throws InvalidArgumentException |
|
107 | - * @throws ReflectionException |
|
108 | - * @throws InvalidDataTypeException |
|
109 | - * @throws InvalidInterfaceException |
|
110 | - */ |
|
111 | - public function set_description($PRC_desc = '') |
|
112 | - { |
|
113 | - $this->Set('PRC_desc', $PRC_desc); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * set is_default |
|
119 | - * |
|
120 | - * @param bool $PRC_is_default |
|
121 | - * @throws EE_Error |
|
122 | - * @throws InvalidArgumentException |
|
123 | - * @throws ReflectionException |
|
124 | - * @throws InvalidDataTypeException |
|
125 | - * @throws InvalidInterfaceException |
|
126 | - */ |
|
127 | - public function set_is_default($PRC_is_default = false) |
|
128 | - { |
|
129 | - $this->set('PRC_is_default', $PRC_is_default); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * set deleted |
|
135 | - * |
|
136 | - * @param bool $PRC_deleted |
|
137 | - * @throws EE_Error |
|
138 | - * @throws InvalidArgumentException |
|
139 | - * @throws ReflectionException |
|
140 | - * @throws InvalidDataTypeException |
|
141 | - * @throws InvalidInterfaceException |
|
142 | - */ |
|
143 | - public function set_deleted($PRC_deleted = null) |
|
144 | - { |
|
145 | - $this->set('PRC_deleted', $PRC_deleted); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * get Price type |
|
151 | - * |
|
152 | - * @return int |
|
153 | - * @throws EE_Error |
|
154 | - * @throws InvalidArgumentException |
|
155 | - * @throws ReflectionException |
|
156 | - * @throws InvalidDataTypeException |
|
157 | - * @throws InvalidInterfaceException |
|
158 | - */ |
|
159 | - public function type() |
|
160 | - { |
|
161 | - return $this->get('PRT_ID'); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * get Price Amount |
|
167 | - * |
|
168 | - * @return float |
|
169 | - * @throws EE_Error |
|
170 | - * @throws InvalidArgumentException |
|
171 | - * @throws ReflectionException |
|
172 | - * @throws InvalidDataTypeException |
|
173 | - * @throws InvalidInterfaceException |
|
174 | - */ |
|
175 | - public function amount() |
|
176 | - { |
|
177 | - return $this->get('PRC_amount'); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * get Price Name |
|
183 | - * |
|
184 | - * @return string |
|
185 | - * @throws EE_Error |
|
186 | - * @throws InvalidArgumentException |
|
187 | - * @throws ReflectionException |
|
188 | - * @throws InvalidDataTypeException |
|
189 | - * @throws InvalidInterfaceException |
|
190 | - */ |
|
191 | - public function name() |
|
192 | - { |
|
193 | - return $this->get('PRC_name'); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * get Price description |
|
199 | - * |
|
200 | - * @return string |
|
201 | - * @throws EE_Error |
|
202 | - * @throws InvalidArgumentException |
|
203 | - * @throws ReflectionException |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - */ |
|
207 | - public function desc() |
|
208 | - { |
|
209 | - return $this->get('PRC_desc'); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * get overrides |
|
215 | - * |
|
216 | - * @return int |
|
217 | - * @throws EE_Error |
|
218 | - * @throws InvalidArgumentException |
|
219 | - * @throws ReflectionException |
|
220 | - * @throws InvalidDataTypeException |
|
221 | - * @throws InvalidInterfaceException |
|
222 | - */ |
|
223 | - public function overrides() |
|
224 | - { |
|
225 | - return $this->get('PRC_overrides'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * get order |
|
231 | - * |
|
232 | - * @return int |
|
233 | - * @throws EE_Error |
|
234 | - * @throws InvalidArgumentException |
|
235 | - * @throws ReflectionException |
|
236 | - * @throws InvalidDataTypeException |
|
237 | - * @throws InvalidInterfaceException |
|
238 | - */ |
|
239 | - public function order() |
|
240 | - { |
|
241 | - return $this->get('PRC_order'); |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * get the author of the price |
|
247 | - * |
|
248 | - * @return int |
|
249 | - * @throws EE_Error |
|
250 | - * @throws InvalidArgumentException |
|
251 | - * @throws ReflectionException |
|
252 | - * @throws InvalidDataTypeException |
|
253 | - * @throws InvalidInterfaceException |
|
254 | - * @since 4.5.0 |
|
255 | - */ |
|
256 | - public function wp_user() |
|
257 | - { |
|
258 | - return $this->get('PRC_wp_user'); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * get is_default |
|
264 | - * |
|
265 | - * @return bool |
|
266 | - * @throws EE_Error |
|
267 | - * @throws InvalidArgumentException |
|
268 | - * @throws ReflectionException |
|
269 | - * @throws InvalidDataTypeException |
|
270 | - * @throws InvalidInterfaceException |
|
271 | - */ |
|
272 | - public function is_default() |
|
273 | - { |
|
274 | - return $this->get('PRC_is_default'); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * get deleted |
|
280 | - * |
|
281 | - * @return bool |
|
282 | - * @throws EE_Error |
|
283 | - * @throws InvalidArgumentException |
|
284 | - * @throws ReflectionException |
|
285 | - * @throws InvalidDataTypeException |
|
286 | - * @throws InvalidInterfaceException |
|
287 | - */ |
|
288 | - public function deleted() |
|
289 | - { |
|
290 | - return $this->get('PRC_deleted'); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * @return bool |
|
296 | - * @throws EE_Error |
|
297 | - * @throws InvalidArgumentException |
|
298 | - * @throws ReflectionException |
|
299 | - * @throws InvalidDataTypeException |
|
300 | - * @throws InvalidInterfaceException |
|
301 | - */ |
|
302 | - public function parent() |
|
303 | - { |
|
304 | - return $this->get('PRC_parent'); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - // some helper methods for getting info on the price_type for this price |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * return whether the price is a base price or not |
|
313 | - * |
|
314 | - * @return boolean |
|
315 | - * @throws EE_Error |
|
316 | - * @throws InvalidArgumentException |
|
317 | - * @throws InvalidDataTypeException |
|
318 | - * @throws InvalidInterfaceException |
|
319 | - * @throws ReflectionException |
|
320 | - */ |
|
321 | - public function is_base_price() |
|
322 | - { |
|
323 | - $price_type = $this->type_obj(); |
|
324 | - return $price_type->is_base_price(); |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @return EE_Base_Class|EE_Price_Type |
|
330 | - * @throws EE_Error |
|
331 | - * @throws InvalidArgumentException |
|
332 | - * @throws ReflectionException |
|
333 | - * @throws InvalidDataTypeException |
|
334 | - * @throws InvalidInterfaceException |
|
335 | - */ |
|
336 | - public function type_obj() |
|
337 | - { |
|
338 | - return $this->get_first_related('Price_Type'); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * @return int |
|
344 | - * @throws EE_Error |
|
345 | - * @throws InvalidArgumentException |
|
346 | - * @throws ReflectionException |
|
347 | - * @throws InvalidDataTypeException |
|
348 | - * @throws InvalidInterfaceException |
|
349 | - */ |
|
350 | - public function type_order() |
|
351 | - { |
|
352 | - return $this->get_first_related('Price_Type')->order(); |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * Simply indicates whether this price increases or decreases the total |
|
358 | - * |
|
359 | - * @return boolean true = discount, otherwise adds to the total |
|
360 | - * @throws EE_Error |
|
361 | - * @throws InvalidArgumentException |
|
362 | - * @throws ReflectionException |
|
363 | - * @throws InvalidDataTypeException |
|
364 | - * @throws InvalidInterfaceException |
|
365 | - */ |
|
366 | - public function is_discount() |
|
367 | - { |
|
368 | - $price_type = $this->type_obj(); |
|
369 | - return $price_type->is_discount(); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * whether the price is a percentage or not |
|
375 | - * |
|
376 | - * @return boolean |
|
377 | - * @throws EE_Error |
|
378 | - * @throws InvalidArgumentException |
|
379 | - * @throws InvalidDataTypeException |
|
380 | - * @throws InvalidInterfaceException |
|
381 | - * @throws ReflectionException |
|
382 | - */ |
|
383 | - public function is_percent() |
|
384 | - { |
|
385 | - $price_type = $this->type_obj(); |
|
386 | - return $price_type->is_percent(); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * whether the price is a percentage or not |
|
392 | - * |
|
393 | - * @return boolean |
|
394 | - * @throws EE_Error |
|
395 | - * @throws InvalidArgumentException |
|
396 | - * @throws ReflectionException |
|
397 | - * @throws InvalidDataTypeException |
|
398 | - * @throws InvalidInterfaceException |
|
399 | - */ |
|
400 | - public function is_tax() |
|
401 | - { |
|
402 | - $price_type = $this->type_obj(); |
|
403 | - return $price_type->is_tax(); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - /** |
|
408 | - * return pretty price dependant on whether its a dollar or percent. |
|
409 | - * |
|
410 | - * @return string |
|
411 | - * @throws EE_Error |
|
412 | - * @throws InvalidArgumentException |
|
413 | - * @throws ReflectionException |
|
414 | - * @throws InvalidDataTypeException |
|
415 | - * @throws InvalidInterfaceException |
|
416 | - * @since 4.4.0 |
|
417 | - */ |
|
418 | - public function pretty_price() |
|
419 | - { |
|
420 | - return ! $this->is_percent() |
|
421 | - ? $this->get_pretty('PRC_amount') |
|
422 | - : $this->get('PRC_amount') . '%'; |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * @return mixed |
|
428 | - * @throws EE_Error |
|
429 | - * @throws InvalidArgumentException |
|
430 | - * @throws ReflectionException |
|
431 | - * @throws InvalidDataTypeException |
|
432 | - * @throws InvalidInterfaceException |
|
433 | - */ |
|
434 | - public function get_price_without_currency_symbol() |
|
435 | - { |
|
436 | - return str_replace( |
|
437 | - EE_Registry::instance()->CFG->currency->sign, |
|
438 | - '', |
|
439 | - $this->get_pretty('PRC_amount') |
|
440 | - ); |
|
441 | - } |
|
16 | + /** |
|
17 | + * @param array $props_n_values incoming values |
|
18 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
19 | + * used.) |
|
20 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
21 | + * date_format and the second value is the time format |
|
22 | + * @return EE_Price |
|
23 | + * @throws EE_Error |
|
24 | + * @throws InvalidArgumentException |
|
25 | + * @throws ReflectionException |
|
26 | + * @throws InvalidDataTypeException |
|
27 | + * @throws InvalidInterfaceException |
|
28 | + */ |
|
29 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
30 | + { |
|
31 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
32 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @param array $props_n_values incoming values from the database |
|
38 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
39 | + * the website will be used. |
|
40 | + * @return EE_Price |
|
41 | + * @throws EE_Error |
|
42 | + * @throws InvalidArgumentException |
|
43 | + * @throws ReflectionException |
|
44 | + * @throws InvalidDataTypeException |
|
45 | + * @throws InvalidInterfaceException |
|
46 | + */ |
|
47 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
48 | + { |
|
49 | + return new self($props_n_values, true, $timezone); |
|
50 | + } |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Set Price type ID |
|
55 | + * |
|
56 | + * @param int $PRT_ID |
|
57 | + * @throws EE_Error |
|
58 | + * @throws InvalidArgumentException |
|
59 | + * @throws ReflectionException |
|
60 | + * @throws InvalidDataTypeException |
|
61 | + * @throws InvalidInterfaceException |
|
62 | + */ |
|
63 | + public function set_type($PRT_ID = 0) |
|
64 | + { |
|
65 | + $this->set('PRT_ID', $PRT_ID); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Set Price Amount |
|
71 | + * |
|
72 | + * @param float $PRC_amount |
|
73 | + * @throws EE_Error |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @throws ReflectionException |
|
76 | + * @throws InvalidDataTypeException |
|
77 | + * @throws InvalidInterfaceException |
|
78 | + */ |
|
79 | + public function set_amount($PRC_amount = 0.00) |
|
80 | + { |
|
81 | + $this->set('PRC_amount', $PRC_amount); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Set Price Name |
|
87 | + * |
|
88 | + * @param string $PRC_name |
|
89 | + * @throws EE_Error |
|
90 | + * @throws InvalidArgumentException |
|
91 | + * @throws ReflectionException |
|
92 | + * @throws InvalidDataTypeException |
|
93 | + * @throws InvalidInterfaceException |
|
94 | + */ |
|
95 | + public function set_name($PRC_name = '') |
|
96 | + { |
|
97 | + $this->set('PRC_name', $PRC_name); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Set Price Description |
|
103 | + * |
|
104 | + * @param string $PRC_desc |
|
105 | + * @throws EE_Error |
|
106 | + * @throws InvalidArgumentException |
|
107 | + * @throws ReflectionException |
|
108 | + * @throws InvalidDataTypeException |
|
109 | + * @throws InvalidInterfaceException |
|
110 | + */ |
|
111 | + public function set_description($PRC_desc = '') |
|
112 | + { |
|
113 | + $this->Set('PRC_desc', $PRC_desc); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * set is_default |
|
119 | + * |
|
120 | + * @param bool $PRC_is_default |
|
121 | + * @throws EE_Error |
|
122 | + * @throws InvalidArgumentException |
|
123 | + * @throws ReflectionException |
|
124 | + * @throws InvalidDataTypeException |
|
125 | + * @throws InvalidInterfaceException |
|
126 | + */ |
|
127 | + public function set_is_default($PRC_is_default = false) |
|
128 | + { |
|
129 | + $this->set('PRC_is_default', $PRC_is_default); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * set deleted |
|
135 | + * |
|
136 | + * @param bool $PRC_deleted |
|
137 | + * @throws EE_Error |
|
138 | + * @throws InvalidArgumentException |
|
139 | + * @throws ReflectionException |
|
140 | + * @throws InvalidDataTypeException |
|
141 | + * @throws InvalidInterfaceException |
|
142 | + */ |
|
143 | + public function set_deleted($PRC_deleted = null) |
|
144 | + { |
|
145 | + $this->set('PRC_deleted', $PRC_deleted); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * get Price type |
|
151 | + * |
|
152 | + * @return int |
|
153 | + * @throws EE_Error |
|
154 | + * @throws InvalidArgumentException |
|
155 | + * @throws ReflectionException |
|
156 | + * @throws InvalidDataTypeException |
|
157 | + * @throws InvalidInterfaceException |
|
158 | + */ |
|
159 | + public function type() |
|
160 | + { |
|
161 | + return $this->get('PRT_ID'); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * get Price Amount |
|
167 | + * |
|
168 | + * @return float |
|
169 | + * @throws EE_Error |
|
170 | + * @throws InvalidArgumentException |
|
171 | + * @throws ReflectionException |
|
172 | + * @throws InvalidDataTypeException |
|
173 | + * @throws InvalidInterfaceException |
|
174 | + */ |
|
175 | + public function amount() |
|
176 | + { |
|
177 | + return $this->get('PRC_amount'); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * get Price Name |
|
183 | + * |
|
184 | + * @return string |
|
185 | + * @throws EE_Error |
|
186 | + * @throws InvalidArgumentException |
|
187 | + * @throws ReflectionException |
|
188 | + * @throws InvalidDataTypeException |
|
189 | + * @throws InvalidInterfaceException |
|
190 | + */ |
|
191 | + public function name() |
|
192 | + { |
|
193 | + return $this->get('PRC_name'); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * get Price description |
|
199 | + * |
|
200 | + * @return string |
|
201 | + * @throws EE_Error |
|
202 | + * @throws InvalidArgumentException |
|
203 | + * @throws ReflectionException |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + */ |
|
207 | + public function desc() |
|
208 | + { |
|
209 | + return $this->get('PRC_desc'); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * get overrides |
|
215 | + * |
|
216 | + * @return int |
|
217 | + * @throws EE_Error |
|
218 | + * @throws InvalidArgumentException |
|
219 | + * @throws ReflectionException |
|
220 | + * @throws InvalidDataTypeException |
|
221 | + * @throws InvalidInterfaceException |
|
222 | + */ |
|
223 | + public function overrides() |
|
224 | + { |
|
225 | + return $this->get('PRC_overrides'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * get order |
|
231 | + * |
|
232 | + * @return int |
|
233 | + * @throws EE_Error |
|
234 | + * @throws InvalidArgumentException |
|
235 | + * @throws ReflectionException |
|
236 | + * @throws InvalidDataTypeException |
|
237 | + * @throws InvalidInterfaceException |
|
238 | + */ |
|
239 | + public function order() |
|
240 | + { |
|
241 | + return $this->get('PRC_order'); |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * get the author of the price |
|
247 | + * |
|
248 | + * @return int |
|
249 | + * @throws EE_Error |
|
250 | + * @throws InvalidArgumentException |
|
251 | + * @throws ReflectionException |
|
252 | + * @throws InvalidDataTypeException |
|
253 | + * @throws InvalidInterfaceException |
|
254 | + * @since 4.5.0 |
|
255 | + */ |
|
256 | + public function wp_user() |
|
257 | + { |
|
258 | + return $this->get('PRC_wp_user'); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * get is_default |
|
264 | + * |
|
265 | + * @return bool |
|
266 | + * @throws EE_Error |
|
267 | + * @throws InvalidArgumentException |
|
268 | + * @throws ReflectionException |
|
269 | + * @throws InvalidDataTypeException |
|
270 | + * @throws InvalidInterfaceException |
|
271 | + */ |
|
272 | + public function is_default() |
|
273 | + { |
|
274 | + return $this->get('PRC_is_default'); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * get deleted |
|
280 | + * |
|
281 | + * @return bool |
|
282 | + * @throws EE_Error |
|
283 | + * @throws InvalidArgumentException |
|
284 | + * @throws ReflectionException |
|
285 | + * @throws InvalidDataTypeException |
|
286 | + * @throws InvalidInterfaceException |
|
287 | + */ |
|
288 | + public function deleted() |
|
289 | + { |
|
290 | + return $this->get('PRC_deleted'); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * @return bool |
|
296 | + * @throws EE_Error |
|
297 | + * @throws InvalidArgumentException |
|
298 | + * @throws ReflectionException |
|
299 | + * @throws InvalidDataTypeException |
|
300 | + * @throws InvalidInterfaceException |
|
301 | + */ |
|
302 | + public function parent() |
|
303 | + { |
|
304 | + return $this->get('PRC_parent'); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + // some helper methods for getting info on the price_type for this price |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * return whether the price is a base price or not |
|
313 | + * |
|
314 | + * @return boolean |
|
315 | + * @throws EE_Error |
|
316 | + * @throws InvalidArgumentException |
|
317 | + * @throws InvalidDataTypeException |
|
318 | + * @throws InvalidInterfaceException |
|
319 | + * @throws ReflectionException |
|
320 | + */ |
|
321 | + public function is_base_price() |
|
322 | + { |
|
323 | + $price_type = $this->type_obj(); |
|
324 | + return $price_type->is_base_price(); |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @return EE_Base_Class|EE_Price_Type |
|
330 | + * @throws EE_Error |
|
331 | + * @throws InvalidArgumentException |
|
332 | + * @throws ReflectionException |
|
333 | + * @throws InvalidDataTypeException |
|
334 | + * @throws InvalidInterfaceException |
|
335 | + */ |
|
336 | + public function type_obj() |
|
337 | + { |
|
338 | + return $this->get_first_related('Price_Type'); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * @return int |
|
344 | + * @throws EE_Error |
|
345 | + * @throws InvalidArgumentException |
|
346 | + * @throws ReflectionException |
|
347 | + * @throws InvalidDataTypeException |
|
348 | + * @throws InvalidInterfaceException |
|
349 | + */ |
|
350 | + public function type_order() |
|
351 | + { |
|
352 | + return $this->get_first_related('Price_Type')->order(); |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * Simply indicates whether this price increases or decreases the total |
|
358 | + * |
|
359 | + * @return boolean true = discount, otherwise adds to the total |
|
360 | + * @throws EE_Error |
|
361 | + * @throws InvalidArgumentException |
|
362 | + * @throws ReflectionException |
|
363 | + * @throws InvalidDataTypeException |
|
364 | + * @throws InvalidInterfaceException |
|
365 | + */ |
|
366 | + public function is_discount() |
|
367 | + { |
|
368 | + $price_type = $this->type_obj(); |
|
369 | + return $price_type->is_discount(); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * whether the price is a percentage or not |
|
375 | + * |
|
376 | + * @return boolean |
|
377 | + * @throws EE_Error |
|
378 | + * @throws InvalidArgumentException |
|
379 | + * @throws InvalidDataTypeException |
|
380 | + * @throws InvalidInterfaceException |
|
381 | + * @throws ReflectionException |
|
382 | + */ |
|
383 | + public function is_percent() |
|
384 | + { |
|
385 | + $price_type = $this->type_obj(); |
|
386 | + return $price_type->is_percent(); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * whether the price is a percentage or not |
|
392 | + * |
|
393 | + * @return boolean |
|
394 | + * @throws EE_Error |
|
395 | + * @throws InvalidArgumentException |
|
396 | + * @throws ReflectionException |
|
397 | + * @throws InvalidDataTypeException |
|
398 | + * @throws InvalidInterfaceException |
|
399 | + */ |
|
400 | + public function is_tax() |
|
401 | + { |
|
402 | + $price_type = $this->type_obj(); |
|
403 | + return $price_type->is_tax(); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + /** |
|
408 | + * return pretty price dependant on whether its a dollar or percent. |
|
409 | + * |
|
410 | + * @return string |
|
411 | + * @throws EE_Error |
|
412 | + * @throws InvalidArgumentException |
|
413 | + * @throws ReflectionException |
|
414 | + * @throws InvalidDataTypeException |
|
415 | + * @throws InvalidInterfaceException |
|
416 | + * @since 4.4.0 |
|
417 | + */ |
|
418 | + public function pretty_price() |
|
419 | + { |
|
420 | + return ! $this->is_percent() |
|
421 | + ? $this->get_pretty('PRC_amount') |
|
422 | + : $this->get('PRC_amount') . '%'; |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * @return mixed |
|
428 | + * @throws EE_Error |
|
429 | + * @throws InvalidArgumentException |
|
430 | + * @throws ReflectionException |
|
431 | + * @throws InvalidDataTypeException |
|
432 | + * @throws InvalidInterfaceException |
|
433 | + */ |
|
434 | + public function get_price_without_currency_symbol() |
|
435 | + { |
|
436 | + return str_replace( |
|
437 | + EE_Registry::instance()->CFG->currency->sign, |
|
438 | + '', |
|
439 | + $this->get_pretty('PRC_amount') |
|
440 | + ); |
|
441 | + } |
|
442 | 442 | } |
@@ -419,7 +419,7 @@ |
||
419 | 419 | { |
420 | 420 | return ! $this->is_percent() |
421 | 421 | ? $this->get_pretty('PRC_amount') |
422 | - : $this->get('PRC_amount') . '%'; |
|
422 | + : $this->get('PRC_amount').'%'; |
|
423 | 423 | } |
424 | 424 | |
425 | 425 |
@@ -6,7 +6,6 @@ discard block |
||
6 | 6 | use EE_Datetime; |
7 | 7 | use EventEspresso\core\domain\services\graphql\types\Datetime; |
8 | 8 | use EventEspresso\core\domain\services\graphql\data\mutations\DatetimeMutation; |
9 | - |
|
10 | 9 | use EE_Error; |
11 | 10 | use EventEspresso\core\exceptions\ExceptionStackTraceDisplay; |
12 | 11 | use Exception; |
@@ -14,7 +13,6 @@ discard block |
||
14 | 13 | use ReflectionException; |
15 | 14 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
16 | 15 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
17 | - |
|
18 | 16 | use GraphQL\Type\Definition\ResolveInfo; |
19 | 17 | use RuntimeException; |
20 | 18 | use WPGraphQL\AppContext; |
@@ -24,92 +24,92 @@ |
||
24 | 24 | class DatetimeUpdate |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Defines the mutation data modification closure. |
|
29 | - * |
|
30 | - * @param EEM_Datetime $model |
|
31 | - * @param Datetime $type |
|
32 | - * @return callable |
|
33 | - */ |
|
34 | - public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
35 | - { |
|
36 | - /** |
|
37 | - * Updates an entity. |
|
38 | - * |
|
39 | - * @param array $input The input for the mutation |
|
40 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
41 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
42 | - * @return array |
|
43 | - * @throws UserError |
|
44 | - * @throws ReflectionException |
|
45 | - * @throws InvalidArgumentException |
|
46 | - * @throws InvalidInterfaceException |
|
47 | - * @throws InvalidDataTypeException |
|
48 | - * @throws EE_Error |
|
49 | - */ |
|
50 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
51 | - /** |
|
52 | - * Stop now if a user isn't allowed to create a datetime. |
|
53 | - */ |
|
54 | - if (! current_user_can('ee_edit_events')) { |
|
55 | - // translators: the %1$s is the name of the object being mutated |
|
56 | - throw new UserError( |
|
57 | - sprintf(esc_html__('Sorry, you are not allowed to edit %1$s', 'event_espresso'), $type->name()) |
|
58 | - ); |
|
59 | - } |
|
60 | - $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
27 | + /** |
|
28 | + * Defines the mutation data modification closure. |
|
29 | + * |
|
30 | + * @param EEM_Datetime $model |
|
31 | + * @param Datetime $type |
|
32 | + * @return callable |
|
33 | + */ |
|
34 | + public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
35 | + { |
|
36 | + /** |
|
37 | + * Updates an entity. |
|
38 | + * |
|
39 | + * @param array $input The input for the mutation |
|
40 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
41 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
42 | + * @return array |
|
43 | + * @throws UserError |
|
44 | + * @throws ReflectionException |
|
45 | + * @throws InvalidArgumentException |
|
46 | + * @throws InvalidInterfaceException |
|
47 | + * @throws InvalidDataTypeException |
|
48 | + * @throws EE_Error |
|
49 | + */ |
|
50 | + return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
51 | + /** |
|
52 | + * Stop now if a user isn't allowed to create a datetime. |
|
53 | + */ |
|
54 | + if (! current_user_can('ee_edit_events')) { |
|
55 | + // translators: the %1$s is the name of the object being mutated |
|
56 | + throw new UserError( |
|
57 | + sprintf(esc_html__('Sorry, you are not allowed to edit %1$s', 'event_espresso'), $type->name()) |
|
58 | + ); |
|
59 | + } |
|
60 | + $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
61 | 61 | |
62 | - $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
63 | - $entity = null; |
|
62 | + $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
63 | + $entity = null; |
|
64 | 64 | |
65 | - if ($id) { |
|
66 | - $entity = $model->get_one_by_ID($id); |
|
67 | - $id = $entity->ID(); |
|
68 | - } |
|
65 | + if ($id) { |
|
66 | + $entity = $model->get_one_by_ID($id); |
|
67 | + $id = $entity->ID(); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * If there's no existing datetime, throw an exception |
|
72 | - */ |
|
73 | - if (! $id || ! ($entity instanceof EE_Datetime)) { |
|
74 | - // translators: the placeholder is the name of the type being updated |
|
75 | - throw new UserError( |
|
76 | - sprintf(esc_html__('No %1$s could be found to update', 'event_espresso'), $type->name()) |
|
77 | - ); |
|
78 | - } |
|
70 | + /** |
|
71 | + * If there's no existing datetime, throw an exception |
|
72 | + */ |
|
73 | + if (! $id || ! ($entity instanceof EE_Datetime)) { |
|
74 | + // translators: the placeholder is the name of the type being updated |
|
75 | + throw new UserError( |
|
76 | + sprintf(esc_html__('No %1$s could be found to update', 'event_espresso'), $type->name()) |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | - $tickets = []; |
|
80 | + $tickets = []; |
|
81 | 81 | |
82 | - $args = DatetimeMutation::prepareFields($input); |
|
82 | + $args = DatetimeMutation::prepareFields($input); |
|
83 | 83 | |
84 | - if (isset($args['tickets'])) { |
|
85 | - $tickets = $args['tickets']; |
|
86 | - unset($args['tickets']); |
|
87 | - } |
|
84 | + if (isset($args['tickets'])) { |
|
85 | + $tickets = $args['tickets']; |
|
86 | + unset($args['tickets']); |
|
87 | + } |
|
88 | 88 | |
89 | - // Update the entity |
|
90 | - try { |
|
91 | - $entity->save($args); |
|
92 | - } catch (Exception $exception) { |
|
93 | - new ExceptionStackTraceDisplay( |
|
94 | - new RuntimeException( |
|
95 | - sprintf( |
|
96 | - esc_html__( |
|
97 | - 'The Datetime failed to update because of the following error(s): %1$s', |
|
98 | - 'event_espresso' |
|
99 | - ), |
|
100 | - $exception->getMessage() |
|
101 | - ) |
|
102 | - ) |
|
103 | - ); |
|
104 | - } |
|
89 | + // Update the entity |
|
90 | + try { |
|
91 | + $entity->save($args); |
|
92 | + } catch (Exception $exception) { |
|
93 | + new ExceptionStackTraceDisplay( |
|
94 | + new RuntimeException( |
|
95 | + sprintf( |
|
96 | + esc_html__( |
|
97 | + 'The Datetime failed to update because of the following error(s): %1$s', |
|
98 | + 'event_espresso' |
|
99 | + ), |
|
100 | + $exception->getMessage() |
|
101 | + ) |
|
102 | + ) |
|
103 | + ); |
|
104 | + } |
|
105 | 105 | |
106 | - if ($id && ! empty($tickets)) { |
|
107 | - DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
108 | - } |
|
106 | + if ($id && ! empty($tickets)) { |
|
107 | + DatetimeMutation::setRelatedTickets($entity, $tickets); |
|
108 | + } |
|
109 | 109 | |
110 | - return [ |
|
111 | - 'id' => $id, |
|
112 | - ]; |
|
113 | - }; |
|
114 | - } |
|
110 | + return [ |
|
111 | + 'id' => $id, |
|
112 | + ]; |
|
113 | + }; |
|
114 | + } |
|
115 | 115 | } |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | * @throws InvalidDataTypeException |
48 | 48 | * @throws EE_Error |
49 | 49 | */ |
50 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
50 | + return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
51 | 51 | /** |
52 | 52 | * Stop now if a user isn't allowed to create a datetime. |
53 | 53 | */ |
54 | - if (! current_user_can('ee_edit_events')) { |
|
54 | + if ( ! current_user_can('ee_edit_events')) { |
|
55 | 55 | // translators: the %1$s is the name of the object being mutated |
56 | 56 | throw new UserError( |
57 | 57 | sprintf(esc_html__('Sorry, you are not allowed to edit %1$s', 'event_espresso'), $type->name()) |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * If there's no existing datetime, throw an exception |
72 | 72 | */ |
73 | - if (! $id || ! ($entity instanceof EE_Datetime)) { |
|
73 | + if ( ! $id || ! ($entity instanceof EE_Datetime)) { |
|
74 | 74 | // translators: the placeholder is the name of the type being updated |
75 | 75 | throw new UserError( |
76 | 76 | sprintf(esc_html__('No %1$s could be found to update', 'event_espresso'), $type->name()) |
@@ -6,7 +6,6 @@ discard block |
||
6 | 6 | use EE_Price; |
7 | 7 | use EventEspresso\core\domain\services\graphql\types\Price; |
8 | 8 | use EventEspresso\core\domain\services\graphql\data\mutations\PriceMutation; |
9 | - |
|
10 | 9 | use EE_Error; |
11 | 10 | use EventEspresso\core\exceptions\ExceptionStackTraceDisplay; |
12 | 11 | use Exception; |
@@ -14,7 +13,6 @@ discard block |
||
14 | 13 | use ReflectionException; |
15 | 14 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
16 | 15 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
17 | - |
|
18 | 16 | use GraphQL\Type\Definition\ResolveInfo; |
19 | 17 | use RuntimeException; |
20 | 18 | use WPGraphQL\AppContext; |
@@ -24,80 +24,80 @@ |
||
24 | 24 | class PriceUpdate |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Defines the mutation data modification closure. |
|
29 | - * |
|
30 | - * @param EEM_Price $model |
|
31 | - * @param Price $type |
|
32 | - * @return callable |
|
33 | - */ |
|
34 | - public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
35 | - { |
|
36 | - /** |
|
37 | - * Updates an entity. |
|
38 | - * |
|
39 | - * @param array $input The input for the mutation |
|
40 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
41 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
42 | - * @return array |
|
43 | - * @throws UserError |
|
44 | - * @throws ReflectionException |
|
45 | - * @throws InvalidArgumentException |
|
46 | - * @throws InvalidInterfaceException |
|
47 | - * @throws InvalidDataTypeException |
|
48 | - * @throws EE_Error |
|
49 | - */ |
|
50 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
51 | - /** |
|
52 | - * Stop now if a user isn't allowed to create an entity. |
|
53 | - */ |
|
54 | - if (! current_user_can('ee_edit_events')) { |
|
55 | - // translators: the %1$s is the name of the object being mutated |
|
56 | - throw new UserError( |
|
57 | - sprintf(esc_html__('Sorry, you are not allowed to edit %1$s', 'event_espresso'), $type->name()) |
|
58 | - ); |
|
59 | - } |
|
60 | - $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
27 | + /** |
|
28 | + * Defines the mutation data modification closure. |
|
29 | + * |
|
30 | + * @param EEM_Price $model |
|
31 | + * @param Price $type |
|
32 | + * @return callable |
|
33 | + */ |
|
34 | + public static function mutateAndGetPayload(EEM_Price $model, Price $type) |
|
35 | + { |
|
36 | + /** |
|
37 | + * Updates an entity. |
|
38 | + * |
|
39 | + * @param array $input The input for the mutation |
|
40 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
41 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
42 | + * @return array |
|
43 | + * @throws UserError |
|
44 | + * @throws ReflectionException |
|
45 | + * @throws InvalidArgumentException |
|
46 | + * @throws InvalidInterfaceException |
|
47 | + * @throws InvalidDataTypeException |
|
48 | + * @throws EE_Error |
|
49 | + */ |
|
50 | + return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
51 | + /** |
|
52 | + * Stop now if a user isn't allowed to create an entity. |
|
53 | + */ |
|
54 | + if (! current_user_can('ee_edit_events')) { |
|
55 | + // translators: the %1$s is the name of the object being mutated |
|
56 | + throw new UserError( |
|
57 | + sprintf(esc_html__('Sorry, you are not allowed to edit %1$s', 'event_espresso'), $type->name()) |
|
58 | + ); |
|
59 | + } |
|
60 | + $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
61 | 61 | |
62 | - $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
63 | - $entity = null; |
|
62 | + $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
63 | + $entity = null; |
|
64 | 64 | |
65 | - if ($id) { |
|
66 | - $entity = $model->get_one_by_ID($id); |
|
67 | - } |
|
65 | + if ($id) { |
|
66 | + $entity = $model->get_one_by_ID($id); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * If there's no existing entity, throw an exception |
|
71 | - */ |
|
72 | - if (! $id || ! ($entity instanceof EE_Price)) { |
|
73 | - // translators: the placeholder is the name of the type being updated |
|
74 | - throw new UserError( |
|
75 | - sprintf(esc_html__('No %1$s could be found to update', 'event_espresso'), $type->name()) |
|
76 | - ); |
|
77 | - } |
|
69 | + /** |
|
70 | + * If there's no existing entity, throw an exception |
|
71 | + */ |
|
72 | + if (! $id || ! ($entity instanceof EE_Price)) { |
|
73 | + // translators: the placeholder is the name of the type being updated |
|
74 | + throw new UserError( |
|
75 | + sprintf(esc_html__('No %1$s could be found to update', 'event_espresso'), $type->name()) |
|
76 | + ); |
|
77 | + } |
|
78 | 78 | |
79 | - $args = PriceMutation::prepareFields($input); |
|
79 | + $args = PriceMutation::prepareFields($input); |
|
80 | 80 | |
81 | - // Update the entity |
|
82 | - try { |
|
83 | - $entity->save($args); |
|
84 | - } catch (Exception $exception) { |
|
85 | - new ExceptionStackTraceDisplay( |
|
86 | - new RuntimeException( |
|
87 | - sprintf( |
|
88 | - esc_html__( |
|
89 | - 'The Price failed to update because of the following error(s): %1$s', |
|
90 | - 'event_espresso' |
|
91 | - ), |
|
92 | - $exception->getMessage() |
|
93 | - ) |
|
94 | - ) |
|
95 | - ); |
|
96 | - } |
|
81 | + // Update the entity |
|
82 | + try { |
|
83 | + $entity->save($args); |
|
84 | + } catch (Exception $exception) { |
|
85 | + new ExceptionStackTraceDisplay( |
|
86 | + new RuntimeException( |
|
87 | + sprintf( |
|
88 | + esc_html__( |
|
89 | + 'The Price failed to update because of the following error(s): %1$s', |
|
90 | + 'event_espresso' |
|
91 | + ), |
|
92 | + $exception->getMessage() |
|
93 | + ) |
|
94 | + ) |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | |
98 | - return [ |
|
99 | - 'id' => $id, |
|
100 | - ]; |
|
101 | - }; |
|
102 | - } |
|
98 | + return [ |
|
99 | + 'id' => $id, |
|
100 | + ]; |
|
101 | + }; |
|
102 | + } |
|
103 | 103 | } |
@@ -6,7 +6,6 @@ discard block |
||
6 | 6 | use EE_Ticket; |
7 | 7 | use EventEspresso\core\domain\services\graphql\types\Ticket; |
8 | 8 | use EventEspresso\core\domain\services\graphql\data\mutations\TicketMutation; |
9 | - |
|
10 | 9 | use EE_Error; |
11 | 10 | use EventEspresso\core\exceptions\ExceptionStackTraceDisplay; |
12 | 11 | use Exception; |
@@ -14,7 +13,6 @@ discard block |
||
14 | 13 | use ReflectionException; |
15 | 14 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
16 | 15 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
17 | - |
|
18 | 16 | use GraphQL\Type\Definition\ResolveInfo; |
19 | 17 | use RuntimeException; |
20 | 18 | use WPGraphQL\AppContext; |
@@ -24,101 +24,101 @@ |
||
24 | 24 | class TicketUpdate |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Defines the mutation data modification closure. |
|
29 | - * |
|
30 | - * @param EEM_Ticket $model |
|
31 | - * @param Ticket $type |
|
32 | - * @return callable |
|
33 | - */ |
|
34 | - public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
35 | - { |
|
36 | - /** |
|
37 | - * Updates an entity. |
|
38 | - * |
|
39 | - * @param array $input The input for the mutation |
|
40 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
41 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
42 | - * @return array |
|
43 | - * @throws UserError |
|
44 | - * @throws ReflectionException |
|
45 | - * @throws InvalidArgumentException |
|
46 | - * @throws InvalidInterfaceException |
|
47 | - * @throws InvalidDataTypeException |
|
48 | - * @throws EE_Error |
|
49 | - */ |
|
50 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
51 | - /** |
|
52 | - * Stop now if a user isn't allowed to create an entity. |
|
53 | - */ |
|
54 | - if (! current_user_can('ee_edit_events')) { |
|
55 | - // translators: the %1$s is the name of the object being mutated |
|
56 | - throw new UserError( |
|
57 | - sprintf(esc_html__('Sorry, you are not allowed to edit %1$s', 'event_espresso'), $type->name()) |
|
58 | - ); |
|
59 | - } |
|
60 | - $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
61 | - |
|
62 | - $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
63 | - $entity = null; |
|
64 | - |
|
65 | - if ($id) { |
|
66 | - $entity = $model->get_one_by_ID($id); |
|
67 | - $id = $entity->ID(); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * If there's no existing entity, throw an exception |
|
72 | - */ |
|
73 | - if (! $id || ! ($entity instanceof EE_Ticket)) { |
|
74 | - // translators: the placeholder is the name of the type being updated |
|
75 | - throw new UserError( |
|
76 | - sprintf(esc_html__('No %1$s could be found to update', 'event_espresso'), $type->name()) |
|
77 | - ); |
|
78 | - } |
|
79 | - |
|
80 | - $datetimes = []; |
|
81 | - $prices = []; |
|
82 | - |
|
83 | - $args = TicketMutation::prepareFields($input); |
|
84 | - |
|
85 | - if (isset($args['datetimes'])) { |
|
86 | - $datetimes = $args['datetimes']; |
|
87 | - unset($args['datetimes']); |
|
88 | - } |
|
89 | - if (isset($args['prices'])) { |
|
90 | - $prices = $args['prices']; |
|
91 | - unset($args['prices']); |
|
92 | - } |
|
93 | - |
|
94 | - // Update the entity |
|
95 | - try { |
|
96 | - $entity->save($args); |
|
97 | - } catch (Exception $exception) { |
|
98 | - new ExceptionStackTraceDisplay( |
|
99 | - new RuntimeException( |
|
100 | - sprintf( |
|
101 | - esc_html__( |
|
102 | - 'The Ticket failed to update because of the following error(s): %1$s', |
|
103 | - 'event_espresso' |
|
104 | - ), |
|
105 | - $exception->getMessage() |
|
106 | - ) |
|
107 | - ) |
|
108 | - ); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - if ($id && ! empty($datetimes)) { |
|
113 | - TicketMutation::setRelatedDatetimes($entity, $datetimes); |
|
114 | - } |
|
115 | - if ($id && ! empty($prices)) { |
|
116 | - TicketMutation::setRelatedPrices($entity, $prices); |
|
117 | - } |
|
118 | - |
|
119 | - return [ |
|
120 | - 'id' => $id, |
|
121 | - ]; |
|
122 | - }; |
|
123 | - } |
|
27 | + /** |
|
28 | + * Defines the mutation data modification closure. |
|
29 | + * |
|
30 | + * @param EEM_Ticket $model |
|
31 | + * @param Ticket $type |
|
32 | + * @return callable |
|
33 | + */ |
|
34 | + public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
|
35 | + { |
|
36 | + /** |
|
37 | + * Updates an entity. |
|
38 | + * |
|
39 | + * @param array $input The input for the mutation |
|
40 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
41 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
42 | + * @return array |
|
43 | + * @throws UserError |
|
44 | + * @throws ReflectionException |
|
45 | + * @throws InvalidArgumentException |
|
46 | + * @throws InvalidInterfaceException |
|
47 | + * @throws InvalidDataTypeException |
|
48 | + * @throws EE_Error |
|
49 | + */ |
|
50 | + return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
51 | + /** |
|
52 | + * Stop now if a user isn't allowed to create an entity. |
|
53 | + */ |
|
54 | + if (! current_user_can('ee_edit_events')) { |
|
55 | + // translators: the %1$s is the name of the object being mutated |
|
56 | + throw new UserError( |
|
57 | + sprintf(esc_html__('Sorry, you are not allowed to edit %1$s', 'event_espresso'), $type->name()) |
|
58 | + ); |
|
59 | + } |
|
60 | + $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null; |
|
61 | + |
|
62 | + $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0; |
|
63 | + $entity = null; |
|
64 | + |
|
65 | + if ($id) { |
|
66 | + $entity = $model->get_one_by_ID($id); |
|
67 | + $id = $entity->ID(); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * If there's no existing entity, throw an exception |
|
72 | + */ |
|
73 | + if (! $id || ! ($entity instanceof EE_Ticket)) { |
|
74 | + // translators: the placeholder is the name of the type being updated |
|
75 | + throw new UserError( |
|
76 | + sprintf(esc_html__('No %1$s could be found to update', 'event_espresso'), $type->name()) |
|
77 | + ); |
|
78 | + } |
|
79 | + |
|
80 | + $datetimes = []; |
|
81 | + $prices = []; |
|
82 | + |
|
83 | + $args = TicketMutation::prepareFields($input); |
|
84 | + |
|
85 | + if (isset($args['datetimes'])) { |
|
86 | + $datetimes = $args['datetimes']; |
|
87 | + unset($args['datetimes']); |
|
88 | + } |
|
89 | + if (isset($args['prices'])) { |
|
90 | + $prices = $args['prices']; |
|
91 | + unset($args['prices']); |
|
92 | + } |
|
93 | + |
|
94 | + // Update the entity |
|
95 | + try { |
|
96 | + $entity->save($args); |
|
97 | + } catch (Exception $exception) { |
|
98 | + new ExceptionStackTraceDisplay( |
|
99 | + new RuntimeException( |
|
100 | + sprintf( |
|
101 | + esc_html__( |
|
102 | + 'The Ticket failed to update because of the following error(s): %1$s', |
|
103 | + 'event_espresso' |
|
104 | + ), |
|
105 | + $exception->getMessage() |
|
106 | + ) |
|
107 | + ) |
|
108 | + ); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + if ($id && ! empty($datetimes)) { |
|
113 | + TicketMutation::setRelatedDatetimes($entity, $datetimes); |
|
114 | + } |
|
115 | + if ($id && ! empty($prices)) { |
|
116 | + TicketMutation::setRelatedPrices($entity, $prices); |
|
117 | + } |
|
118 | + |
|
119 | + return [ |
|
120 | + 'id' => $id, |
|
121 | + ]; |
|
122 | + }; |
|
123 | + } |
|
124 | 124 | } |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | * @throws InvalidDataTypeException |
48 | 48 | * @throws EE_Error |
49 | 49 | */ |
50 | - return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
50 | + return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) { |
|
51 | 51 | /** |
52 | 52 | * Stop now if a user isn't allowed to create an entity. |
53 | 53 | */ |
54 | - if (! current_user_can('ee_edit_events')) { |
|
54 | + if ( ! current_user_can('ee_edit_events')) { |
|
55 | 55 | // translators: the %1$s is the name of the object being mutated |
56 | 56 | throw new UserError( |
57 | 57 | sprintf(esc_html__('Sorry, you are not allowed to edit %1$s', 'event_espresso'), $type->name()) |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * If there's no existing entity, throw an exception |
72 | 72 | */ |
73 | - if (! $id || ! ($entity instanceof EE_Ticket)) { |
|
73 | + if ( ! $id || ! ($entity instanceof EE_Ticket)) { |
|
74 | 74 | // translators: the placeholder is the name of the type being updated |
75 | 75 | throw new UserError( |
76 | 76 | sprintf(esc_html__('No %1$s could be found to update', 'event_espresso'), $type->name()) |