@@ -5,76 +5,76 @@ |
||
5 | 5 | class EE_JSON_Field extends EE_Model_Field_Base |
6 | 6 | { |
7 | 7 | |
8 | - /** |
|
9 | - * @var JsonDataHandler |
|
10 | - */ |
|
11 | - private $json_data_handler; |
|
8 | + /** |
|
9 | + * @var JsonDataHandler |
|
10 | + */ |
|
11 | + private $json_data_handler; |
|
12 | 12 | |
13 | 13 | |
14 | - /** |
|
15 | - * @param string $table_column |
|
16 | - * @param string $nicename |
|
17 | - * @param bool $nullable |
|
18 | - * @param null $default_value |
|
19 | - */ |
|
20 | - public function __construct( |
|
21 | - $table_column, |
|
22 | - $nicename, |
|
23 | - $nullable, |
|
24 | - $default_value = null |
|
25 | - ) { |
|
26 | - $this->json_data_handler = new JsonDataHandler(); |
|
27 | - $this->json_data_handler->configure( |
|
28 | - JsonDataHandler::DATA_TYPE_OBJECT |
|
29 | - ); |
|
30 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
31 | - } |
|
14 | + /** |
|
15 | + * @param string $table_column |
|
16 | + * @param string $nicename |
|
17 | + * @param bool $nullable |
|
18 | + * @param null $default_value |
|
19 | + */ |
|
20 | + public function __construct( |
|
21 | + $table_column, |
|
22 | + $nicename, |
|
23 | + $nullable, |
|
24 | + $default_value = null |
|
25 | + ) { |
|
26 | + $this->json_data_handler = new JsonDataHandler(); |
|
27 | + $this->json_data_handler->configure( |
|
28 | + JsonDataHandler::DATA_TYPE_OBJECT |
|
29 | + ); |
|
30 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - // /** |
|
35 | - // * When get() is called on a model object (eg EE_Event), before returning its value, |
|
36 | - // * call this function on it, allowing us to customize the returned value based on |
|
37 | - // * the field's type. Eg, we may want to unserialize it, strip tags, etc. By default, |
|
38 | - // * we simply return it. |
|
39 | - // * |
|
40 | - // * @param mixed $value_of_field_on_model_object |
|
41 | - // * @return mixed |
|
42 | - // */ |
|
43 | - // public function prepare_for_get($value_of_field_on_model_object) |
|
44 | - // { |
|
45 | - // // return $this->json_data_handler->decodeJson($value_of_field_on_model_object); |
|
46 | - // return $value_of_field_on_model_object; |
|
47 | - // } |
|
34 | + // /** |
|
35 | + // * When get() is called on a model object (eg EE_Event), before returning its value, |
|
36 | + // * call this function on it, allowing us to customize the returned value based on |
|
37 | + // * the field's type. Eg, we may want to unserialize it, strip tags, etc. By default, |
|
38 | + // * we simply return it. |
|
39 | + // * |
|
40 | + // * @param mixed $value_of_field_on_model_object |
|
41 | + // * @return mixed |
|
42 | + // */ |
|
43 | + // public function prepare_for_get($value_of_field_on_model_object) |
|
44 | + // { |
|
45 | + // // return $this->json_data_handler->decodeJson($value_of_field_on_model_object); |
|
46 | + // return $value_of_field_on_model_object; |
|
47 | + // } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * When creating a brand-new model object, or setting a particular value for one of its fields, this function |
|
52 | - * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc. |
|
53 | - * By default, we do nothing. |
|
54 | - * |
|
55 | - * If the model field is going to perform any validation on the input, this is where it should be done |
|
56 | - * (once the value is on the model object, it may be used in other ways besides putting it into the DB |
|
57 | - * so it's best to validate it right away). |
|
58 | - * |
|
59 | - * @param mixed $value_inputted_for_field_on_model_object |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
63 | - { |
|
64 | - return $this->json_data_handler->encodeData($value_inputted_for_field_on_model_object); |
|
65 | - } |
|
50 | + /** |
|
51 | + * When creating a brand-new model object, or setting a particular value for one of its fields, this function |
|
52 | + * is called before setting it on the model object. We may want to strip slashes, unserialize the value, etc. |
|
53 | + * By default, we do nothing. |
|
54 | + * |
|
55 | + * If the model field is going to perform any validation on the input, this is where it should be done |
|
56 | + * (once the value is on the model object, it may be used in other ways besides putting it into the DB |
|
57 | + * so it's best to validate it right away). |
|
58 | + * |
|
59 | + * @param mixed $value_inputted_for_field_on_model_object |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
63 | + { |
|
64 | + return $this->json_data_handler->encodeData($value_inputted_for_field_on_model_object); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * When inserting or updating a field on a model object, run this function on each |
|
70 | - * value to prepare it for insertion into the db. Generally this converts |
|
71 | - * the validated input on the model object into the format used in the DB. |
|
72 | - * |
|
73 | - * @param mixed $value_of_field_on_model_object |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - public function prepare_for_use_in_db($value_of_field_on_model_object) |
|
77 | - { |
|
78 | - return $this->json_data_handler->encodeData($value_of_field_on_model_object); |
|
79 | - } |
|
68 | + /** |
|
69 | + * When inserting or updating a field on a model object, run this function on each |
|
70 | + * value to prepare it for insertion into the db. Generally this converts |
|
71 | + * the validated input on the model object into the format used in the DB. |
|
72 | + * |
|
73 | + * @param mixed $value_of_field_on_model_object |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + public function prepare_for_use_in_db($value_of_field_on_model_object) |
|
77 | + { |
|
78 | + return $this->json_data_handler->encodeData($value_of_field_on_model_object); |
|
79 | + } |
|
80 | 80 | } |
@@ -2,41 +2,41 @@ |
||
2 | 2 | |
3 | 3 | class EE_Foreign_Key_String_Field extends EE_Foreign_Key_Field_Base |
4 | 4 | { |
5 | - /** |
|
6 | - * Whether the value should be converted to uppercase on insertion. |
|
7 | - * |
|
8 | - * @var boolean |
|
9 | - */ |
|
10 | - protected $is_uppercase; |
|
5 | + /** |
|
6 | + * Whether the value should be converted to uppercase on insertion. |
|
7 | + * |
|
8 | + * @var boolean |
|
9 | + */ |
|
10 | + protected $is_uppercase; |
|
11 | 11 | |
12 | 12 | |
13 | - /** |
|
14 | - * @param string $table_column name of column for field |
|
15 | - * @param string $nicename should be internationalized with __('blah','event_espresso') |
|
16 | - * @param boolean $nullable |
|
17 | - * @param int|string $default_value data type should match field type |
|
18 | - * @param string|string[] $model_name eg 'Event','Answer','Term', etc. |
|
19 | - * Basically its the model class's name without the "EEM_" |
|
20 | - * @param boolean $is_uppercase Whether the value should be converted to uppercase on insertion. |
|
21 | - */ |
|
22 | - public function __construct($table_column, $nicename, $nullable, $default_value, $model_name, $is_uppercase = true) |
|
23 | - { |
|
24 | - $this->is_uppercase = $is_uppercase; |
|
25 | - parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
26 | - } |
|
13 | + /** |
|
14 | + * @param string $table_column name of column for field |
|
15 | + * @param string $nicename should be internationalized with __('blah','event_espresso') |
|
16 | + * @param boolean $nullable |
|
17 | + * @param int|string $default_value data type should match field type |
|
18 | + * @param string|string[] $model_name eg 'Event','Answer','Term', etc. |
|
19 | + * Basically its the model class's name without the "EEM_" |
|
20 | + * @param boolean $is_uppercase Whether the value should be converted to uppercase on insertion. |
|
21 | + */ |
|
22 | + public function __construct($table_column, $nicename, $nullable, $default_value, $model_name, $is_uppercase = true) |
|
23 | + { |
|
24 | + $this->is_uppercase = $is_uppercase; |
|
25 | + parent::__construct($table_column, $nicename, $nullable, $default_value, $model_name); |
|
26 | + } |
|
27 | 27 | |
28 | - /** |
|
29 | - * removes all tags when setting |
|
30 | - * |
|
31 | - * @param string $value_inputted_for_field_on_model_object |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
35 | - { |
|
36 | - if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
37 | - $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
38 | - } |
|
39 | - $clean_value = wp_strip_all_tags($value_inputted_for_field_on_model_object); |
|
40 | - return $this->is_uppercase ? strtoupper($clean_value) : $clean_value; |
|
41 | - } |
|
28 | + /** |
|
29 | + * removes all tags when setting |
|
30 | + * |
|
31 | + * @param string $value_inputted_for_field_on_model_object |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
35 | + { |
|
36 | + if ($this->is_model_obj_of_type_pointed_to($value_inputted_for_field_on_model_object)) { |
|
37 | + $value_inputted_for_field_on_model_object = $value_inputted_for_field_on_model_object->ID(); |
|
38 | + } |
|
39 | + $clean_value = wp_strip_all_tags($value_inputted_for_field_on_model_object); |
|
40 | + return $this->is_uppercase ? strtoupper($clean_value) : $clean_value; |
|
41 | + } |
|
42 | 42 | } |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function attributes(): ?Attributes |
139 | 139 | { |
140 | - if (! $this->attributes instanceof Attributes) { |
|
140 | + if ( ! $this->attributes instanceof Attributes) { |
|
141 | 141 | $this->attributes = Attributes::fromJson($this->get('FIN_attributes')); |
142 | 142 | } |
143 | 143 | return $this->attributes; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | */ |
192 | 192 | public function helpText(): ?HelpText |
193 | 193 | { |
194 | - if (! $this->helpText instanceof HelpText) { |
|
194 | + if ( ! $this->helpText instanceof HelpText) { |
|
195 | 195 | $this->helpText = HelpText::fromJson($this->get('FIN_helpText')); |
196 | 196 | } |
197 | 197 | return $this->helpText; |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public function label(): ?FormLabel |
223 | 223 | { |
224 | - if (! $this->label instanceof FormLabel) { |
|
224 | + if ( ! $this->label instanceof FormLabel) { |
|
225 | 225 | $this->label = FormLabel::fromJson($this->get('FIN_label')); |
226 | 226 | } |
227 | 227 | return $this->label; |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | public function setMapsTo(string $model, string $field) |
265 | 265 | { |
266 | 266 | $model_name = strpos($model, 'EEM_') !== 0 ? "EEM_$model" : $model; |
267 | - if (! class_exists($model_name)) { |
|
267 | + if ( ! class_exists($model_name)) { |
|
268 | 268 | throw new DomainException( |
269 | 269 | sprintf( |
270 | 270 | esc_html__( |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | public function options(): ?InputOptions |
290 | 290 | { |
291 | - if (! $this->options instanceof InputOptions) { |
|
291 | + if ( ! $this->options instanceof InputOptions) { |
|
292 | 292 | $this->options = InputOptions::fromJson($this->get('FIN_options')); |
293 | 293 | } |
294 | 294 | return $this->options; |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | */ |
368 | 368 | public function required(): ?Required |
369 | 369 | { |
370 | - if (! $this->required instanceof Required) { |
|
370 | + if ( ! $this->required instanceof Required) { |
|
371 | 371 | $this->required = Required::fromJson($this->get('FIN_required')); |
372 | 372 | } |
373 | 373 | return $this->required; |
@@ -28,471 +28,471 @@ |
||
28 | 28 | */ |
29 | 29 | class EE_Form_Element extends EE_Base_Class |
30 | 30 | { |
31 | - /** |
|
32 | - * @var Attributes |
|
33 | - */ |
|
34 | - private $attributes; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var FormLabel |
|
38 | - */ |
|
39 | - private $label; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var HelpText |
|
43 | - */ |
|
44 | - private $helpText; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var InputOptions |
|
48 | - */ |
|
49 | - private $options; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var Required |
|
53 | - */ |
|
54 | - private $required; |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @param array $props_n_values |
|
59 | - * @return EE_Form_Element |
|
60 | - * @throws EE_Error |
|
61 | - * @throws ReflectionException |
|
62 | - */ |
|
63 | - public static function new_instance(array $props_n_values = []): EE_Form_Element |
|
64 | - { |
|
65 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
66 | - return $has_object ?: new self($props_n_values); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @param array $props_n_values |
|
72 | - * @return EE_Form_Element |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - public static function new_instance_from_db(array $props_n_values = []): EE_Form_Element |
|
77 | - { |
|
78 | - return new self($props_n_values); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Form Element UUID (universally unique identifier) |
|
84 | - * |
|
85 | - * @return string |
|
86 | - * @throws EE_Error |
|
87 | - * @throws ReflectionException |
|
88 | - */ |
|
89 | - public function UUID(): string |
|
90 | - { |
|
91 | - return $this->get('FIN_UUID'); |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param string $UUID |
|
97 | - * @throws EE_Error |
|
98 | - * @throws ReflectionException |
|
99 | - */ |
|
100 | - public function setUUID(string $UUID) |
|
101 | - { |
|
102 | - $this->set('FIN_UUID', $UUID); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Whether or not input is only displayed in the admin. If false, input will appear in public forms |
|
108 | - * |
|
109 | - * @return bool |
|
110 | - * @throws EE_Error |
|
111 | - * @throws ReflectionException |
|
112 | - */ |
|
113 | - public function adminOnly(): ?bool |
|
114 | - { |
|
115 | - return $this->get('FIN_adminOnly'); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param bool $admin_only |
|
121 | - * @throws EE_Error |
|
122 | - * @throws ReflectionException |
|
123 | - */ |
|
124 | - public function setAdminOnly(bool $admin_only) |
|
125 | - { |
|
126 | - $this->set('FIN_adminOnly', $admin_only); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * JSON string of HTML attributes such as class, max, min, placeholder, type, etc. |
|
132 | - * |
|
133 | - * @return Attributes |
|
134 | - * @throws EE_Error |
|
135 | - * @throws ReflectionException |
|
136 | - */ |
|
137 | - public function attributes(): ?Attributes |
|
138 | - { |
|
139 | - if (! $this->attributes instanceof Attributes) { |
|
140 | - $this->attributes = Attributes::fromJson($this->get('FIN_attributes')); |
|
141 | - } |
|
142 | - return $this->attributes; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @param Attributes $attributes |
|
148 | - * @throws EE_Error |
|
149 | - * @throws ReflectionException |
|
150 | - */ |
|
151 | - public function setAttributes(Attributes $attributes) |
|
152 | - { |
|
153 | - // set local object |
|
154 | - $this->attributes = $attributes; |
|
155 | - // then pass to model as an array which will get converted to JSON by the model field |
|
156 | - $this->set('FIN_attributes', $attributes->toArray()); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * UUID of parent form section this form input belongs to. |
|
162 | - * |
|
163 | - * @return string |
|
164 | - * @throws EE_Error |
|
165 | - * @throws ReflectionException |
|
166 | - */ |
|
167 | - public function belongsTo(): string |
|
168 | - { |
|
169 | - return $this->get('FSC_UUID'); |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @param string $relation_UUID |
|
175 | - * @throws EE_Error |
|
176 | - * @throws ReflectionException |
|
177 | - */ |
|
178 | - public function setBelongsTo(string $relation_UUID) |
|
179 | - { |
|
180 | - $this->set('FSC_UUID', $relation_UUID); |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * returns a HelpText object for managing input help text |
|
186 | - * |
|
187 | - * @return HelpText |
|
188 | - * @throws EE_Error |
|
189 | - * @throws ReflectionException |
|
190 | - */ |
|
191 | - public function helpText(): ?HelpText |
|
192 | - { |
|
193 | - if (! $this->helpText instanceof HelpText) { |
|
194 | - $this->helpText = HelpText::fromJson($this->get('FIN_helpText')); |
|
195 | - } |
|
196 | - return $this->helpText; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @param HelpText $helpText |
|
202 | - * @throws EE_Error |
|
203 | - * @throws ReflectionException |
|
204 | - */ |
|
205 | - public function setHelpText(HelpText $helpText) |
|
206 | - { |
|
207 | - // set local object |
|
208 | - $this->helpText = $helpText; |
|
209 | - // then pass to model as an array which will get converted to JSON by the model field |
|
210 | - $this->set('FIN_helpText', $helpText->toArray()); |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * returns a FormLabel object for managing input labels |
|
216 | - * |
|
217 | - * @return FormLabel |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function label(): ?FormLabel |
|
222 | - { |
|
223 | - if (! $this->label instanceof FormLabel) { |
|
224 | - $this->label = FormLabel::fromJson($this->get('FIN_label')); |
|
225 | - } |
|
226 | - return $this->label; |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * @param FormLabel $label |
|
232 | - * @throws EE_Error |
|
233 | - * @throws ReflectionException |
|
234 | - */ |
|
235 | - public function setLabel(FormLabel $label) |
|
236 | - { |
|
237 | - // set local object |
|
238 | - $this->label = $label; |
|
239 | - // then pass to model as an array which will get converted to JSON by the model field |
|
240 | - $this->set('FIN_label', $label->toArray()); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * Model and Fields name that this input maps to; ex: Attendee.email |
|
246 | - * |
|
247 | - * @return string |
|
248 | - * @throws EE_Error |
|
249 | - * @throws ReflectionException |
|
250 | - */ |
|
251 | - public function mapsTo(): ?string |
|
252 | - { |
|
253 | - return $this->get('FIN_mapsTo'); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * @param string $model ex: Attendee |
|
259 | - * @param string $field ex: email |
|
260 | - * @throws EE_Error |
|
261 | - * @throws ReflectionException |
|
262 | - */ |
|
263 | - public function setMapsTo(string $model, string $field) |
|
264 | - { |
|
265 | - $model_name = strpos($model, 'EEM_') !== 0 ? "EEM_$model" : $model; |
|
266 | - if (! class_exists($model_name)) { |
|
267 | - throw new DomainException( |
|
268 | - sprintf( |
|
269 | - esc_html__( |
|
270 | - 'The %1$s model does not exist or can not be located. Please verify the spelling and whether it is loaded.', |
|
271 | - 'event_espresso' |
|
272 | - ), |
|
273 | - $model_name |
|
274 | - ) |
|
275 | - ); |
|
276 | - } |
|
277 | - $this->set('FIN_mapsTo', "{$model}.{$field}"); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc |
|
283 | - * |
|
284 | - * @return InputOptions |
|
285 | - * @throws EE_Error |
|
286 | - * @throws ReflectionException |
|
287 | - */ |
|
288 | - public function options(): ?InputOptions |
|
289 | - { |
|
290 | - if (! $this->options instanceof InputOptions) { |
|
291 | - $this->options = InputOptions::fromJson($this->get('FIN_options')); |
|
292 | - } |
|
293 | - return $this->options; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * @param InputOptions $options |
|
299 | - * @throws EE_Error |
|
300 | - * @throws ReflectionException |
|
301 | - */ |
|
302 | - public function setOptions(InputOptions $options) |
|
303 | - { |
|
304 | - // set local object |
|
305 | - $this->options = $options; |
|
306 | - // then pass to model as an array which will get converted to JSON by the model field |
|
307 | - $this->set('FIN_options', $options->toArray()); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * Order in which form input appears in a form. |
|
314 | - * |
|
315 | - * @return int |
|
316 | - * @throws EE_Error |
|
317 | - * @throws ReflectionException |
|
318 | - */ |
|
319 | - public function order(): int |
|
320 | - { |
|
321 | - return $this->get('FIN_order'); |
|
322 | - } |
|
323 | - |
|
324 | - |
|
325 | - /** |
|
326 | - * @param int $order |
|
327 | - * @throws EE_Error |
|
328 | - * @throws ReflectionException |
|
329 | - */ |
|
330 | - public function setOrder(int $order) |
|
331 | - { |
|
332 | - $this->set('FIN_order', $order); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Example text displayed within an input to assist users with completing the form. |
|
338 | - * |
|
339 | - * @return string |
|
340 | - * @throws EE_Error |
|
341 | - * @throws ReflectionException |
|
342 | - */ |
|
343 | - public function placeholder(): ?string |
|
344 | - { |
|
345 | - return $this->get('FIN_placeholder'); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @param string $placeholder |
|
351 | - * @throws EE_Error |
|
352 | - * @throws ReflectionException |
|
353 | - */ |
|
354 | - public function setPlaceholder(string $placeholder) |
|
355 | - { |
|
356 | - $this->set('FIN_placeholder', $placeholder); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Whether or not the input must be supplied with a value in order to complete the form. |
|
362 | - * |
|
363 | - * @return Required |
|
364 | - * @throws EE_Error |
|
365 | - * @throws ReflectionException |
|
366 | - */ |
|
367 | - public function required(): ?Required |
|
368 | - { |
|
369 | - if (! $this->required instanceof Required) { |
|
370 | - $this->required = Required::fromJson($this->get('FIN_required')); |
|
371 | - } |
|
372 | - return $this->required; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * @param Required $required |
|
378 | - * @throws EE_Error |
|
379 | - * @throws ReflectionException |
|
380 | - */ |
|
381 | - public function setRequired(Required $required) |
|
382 | - { |
|
383 | - // set local object |
|
384 | - $this->required = $required; |
|
385 | - // then pass to model as an array which will get converted to JSON by the model field |
|
386 | - $this->set('FIN_required', $required->toArray()); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * version of public label for use in identifiers |
|
392 | - * |
|
393 | - * @return string |
|
394 | - * @throws EE_Error |
|
395 | - * @throws ReflectionException |
|
396 | - */ |
|
397 | - public function slug(): ?string |
|
398 | - { |
|
399 | - return sanitize_title($this->label()->publicLabel()); |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
405 | - * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
406 | - * |
|
407 | - * @return string |
|
408 | - * @throws EE_Error |
|
409 | - * @throws ReflectionException |
|
410 | - */ |
|
411 | - public function status(): string |
|
412 | - { |
|
413 | - return $this->get('FIN_status'); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
419 | - * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
420 | - * |
|
421 | - * @param string $status |
|
422 | - * @throws EE_Error |
|
423 | - * @throws ReflectionException |
|
424 | - */ |
|
425 | - public function setStatus(string $status) |
|
426 | - { |
|
427 | - $this->set('FIN_status', $status); |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Form input type. |
|
433 | - * Values correspond to the EventEspresso\core\domain\entities\form\Input::TYPE_* constants. |
|
434 | - * |
|
435 | - * @return string |
|
436 | - * @throws EE_Error |
|
437 | - * @throws ReflectionException |
|
438 | - */ |
|
439 | - public function type(): ?string |
|
440 | - { |
|
441 | - return $this->get('FIN_type'); |
|
442 | - } |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * @param string $type |
|
447 | - * @throws EE_Error |
|
448 | - * @throws ReflectionException |
|
449 | - */ |
|
450 | - public function setType(string $type) |
|
451 | - { |
|
452 | - $this->set('FIN_type', $type); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * ID of the WP User that created this form input. |
|
458 | - * |
|
459 | - * @return int |
|
460 | - * @throws EE_Error |
|
461 | - * @throws ReflectionException |
|
462 | - */ |
|
463 | - public function wp_user(): int |
|
464 | - { |
|
465 | - return $this->get('FIN_wpUser'); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - /** |
|
470 | - * returns the id the wordpress user who created this question |
|
471 | - * |
|
472 | - * @param int $wp_user |
|
473 | - * @throws EE_Error |
|
474 | - * @throws ReflectionException |
|
475 | - */ |
|
476 | - public function setWpUser(int $wp_user) |
|
477 | - { |
|
478 | - $this->set('FIN_wpUser', $wp_user); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - /** |
|
483 | - * @param array $set_cols_n_values |
|
484 | - * @return bool|int|string |
|
485 | - * @throws EE_Error |
|
486 | - * @throws ReflectionException |
|
487 | - */ |
|
488 | - public function save($set_cols_n_values = []) |
|
489 | - { |
|
490 | - // make sure internal versions for all composite objects are updated |
|
491 | - $this->set('FIN_attributes', $this->attributes()->toArray()); |
|
492 | - $this->set('FIN_helpText', $this->helpText()->toArray()); |
|
493 | - $this->set('FIN_label', $this->label()->toArray()); |
|
494 | - $this->set('FIN_options', $this->options()->toArray()); |
|
495 | - $this->set('FIN_required', $this->required()->toArray()); |
|
496 | - return parent::save($set_cols_n_values); |
|
497 | - } |
|
31 | + /** |
|
32 | + * @var Attributes |
|
33 | + */ |
|
34 | + private $attributes; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var FormLabel |
|
38 | + */ |
|
39 | + private $label; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var HelpText |
|
43 | + */ |
|
44 | + private $helpText; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var InputOptions |
|
48 | + */ |
|
49 | + private $options; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var Required |
|
53 | + */ |
|
54 | + private $required; |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @param array $props_n_values |
|
59 | + * @return EE_Form_Element |
|
60 | + * @throws EE_Error |
|
61 | + * @throws ReflectionException |
|
62 | + */ |
|
63 | + public static function new_instance(array $props_n_values = []): EE_Form_Element |
|
64 | + { |
|
65 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
66 | + return $has_object ?: new self($props_n_values); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @param array $props_n_values |
|
72 | + * @return EE_Form_Element |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + public static function new_instance_from_db(array $props_n_values = []): EE_Form_Element |
|
77 | + { |
|
78 | + return new self($props_n_values); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Form Element UUID (universally unique identifier) |
|
84 | + * |
|
85 | + * @return string |
|
86 | + * @throws EE_Error |
|
87 | + * @throws ReflectionException |
|
88 | + */ |
|
89 | + public function UUID(): string |
|
90 | + { |
|
91 | + return $this->get('FIN_UUID'); |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param string $UUID |
|
97 | + * @throws EE_Error |
|
98 | + * @throws ReflectionException |
|
99 | + */ |
|
100 | + public function setUUID(string $UUID) |
|
101 | + { |
|
102 | + $this->set('FIN_UUID', $UUID); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Whether or not input is only displayed in the admin. If false, input will appear in public forms |
|
108 | + * |
|
109 | + * @return bool |
|
110 | + * @throws EE_Error |
|
111 | + * @throws ReflectionException |
|
112 | + */ |
|
113 | + public function adminOnly(): ?bool |
|
114 | + { |
|
115 | + return $this->get('FIN_adminOnly'); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param bool $admin_only |
|
121 | + * @throws EE_Error |
|
122 | + * @throws ReflectionException |
|
123 | + */ |
|
124 | + public function setAdminOnly(bool $admin_only) |
|
125 | + { |
|
126 | + $this->set('FIN_adminOnly', $admin_only); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * JSON string of HTML attributes such as class, max, min, placeholder, type, etc. |
|
132 | + * |
|
133 | + * @return Attributes |
|
134 | + * @throws EE_Error |
|
135 | + * @throws ReflectionException |
|
136 | + */ |
|
137 | + public function attributes(): ?Attributes |
|
138 | + { |
|
139 | + if (! $this->attributes instanceof Attributes) { |
|
140 | + $this->attributes = Attributes::fromJson($this->get('FIN_attributes')); |
|
141 | + } |
|
142 | + return $this->attributes; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @param Attributes $attributes |
|
148 | + * @throws EE_Error |
|
149 | + * @throws ReflectionException |
|
150 | + */ |
|
151 | + public function setAttributes(Attributes $attributes) |
|
152 | + { |
|
153 | + // set local object |
|
154 | + $this->attributes = $attributes; |
|
155 | + // then pass to model as an array which will get converted to JSON by the model field |
|
156 | + $this->set('FIN_attributes', $attributes->toArray()); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * UUID of parent form section this form input belongs to. |
|
162 | + * |
|
163 | + * @return string |
|
164 | + * @throws EE_Error |
|
165 | + * @throws ReflectionException |
|
166 | + */ |
|
167 | + public function belongsTo(): string |
|
168 | + { |
|
169 | + return $this->get('FSC_UUID'); |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @param string $relation_UUID |
|
175 | + * @throws EE_Error |
|
176 | + * @throws ReflectionException |
|
177 | + */ |
|
178 | + public function setBelongsTo(string $relation_UUID) |
|
179 | + { |
|
180 | + $this->set('FSC_UUID', $relation_UUID); |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * returns a HelpText object for managing input help text |
|
186 | + * |
|
187 | + * @return HelpText |
|
188 | + * @throws EE_Error |
|
189 | + * @throws ReflectionException |
|
190 | + */ |
|
191 | + public function helpText(): ?HelpText |
|
192 | + { |
|
193 | + if (! $this->helpText instanceof HelpText) { |
|
194 | + $this->helpText = HelpText::fromJson($this->get('FIN_helpText')); |
|
195 | + } |
|
196 | + return $this->helpText; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @param HelpText $helpText |
|
202 | + * @throws EE_Error |
|
203 | + * @throws ReflectionException |
|
204 | + */ |
|
205 | + public function setHelpText(HelpText $helpText) |
|
206 | + { |
|
207 | + // set local object |
|
208 | + $this->helpText = $helpText; |
|
209 | + // then pass to model as an array which will get converted to JSON by the model field |
|
210 | + $this->set('FIN_helpText', $helpText->toArray()); |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * returns a FormLabel object for managing input labels |
|
216 | + * |
|
217 | + * @return FormLabel |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function label(): ?FormLabel |
|
222 | + { |
|
223 | + if (! $this->label instanceof FormLabel) { |
|
224 | + $this->label = FormLabel::fromJson($this->get('FIN_label')); |
|
225 | + } |
|
226 | + return $this->label; |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * @param FormLabel $label |
|
232 | + * @throws EE_Error |
|
233 | + * @throws ReflectionException |
|
234 | + */ |
|
235 | + public function setLabel(FormLabel $label) |
|
236 | + { |
|
237 | + // set local object |
|
238 | + $this->label = $label; |
|
239 | + // then pass to model as an array which will get converted to JSON by the model field |
|
240 | + $this->set('FIN_label', $label->toArray()); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * Model and Fields name that this input maps to; ex: Attendee.email |
|
246 | + * |
|
247 | + * @return string |
|
248 | + * @throws EE_Error |
|
249 | + * @throws ReflectionException |
|
250 | + */ |
|
251 | + public function mapsTo(): ?string |
|
252 | + { |
|
253 | + return $this->get('FIN_mapsTo'); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * @param string $model ex: Attendee |
|
259 | + * @param string $field ex: email |
|
260 | + * @throws EE_Error |
|
261 | + * @throws ReflectionException |
|
262 | + */ |
|
263 | + public function setMapsTo(string $model, string $field) |
|
264 | + { |
|
265 | + $model_name = strpos($model, 'EEM_') !== 0 ? "EEM_$model" : $model; |
|
266 | + if (! class_exists($model_name)) { |
|
267 | + throw new DomainException( |
|
268 | + sprintf( |
|
269 | + esc_html__( |
|
270 | + 'The %1$s model does not exist or can not be located. Please verify the spelling and whether it is loaded.', |
|
271 | + 'event_espresso' |
|
272 | + ), |
|
273 | + $model_name |
|
274 | + ) |
|
275 | + ); |
|
276 | + } |
|
277 | + $this->set('FIN_mapsTo', "{$model}.{$field}"); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc |
|
283 | + * |
|
284 | + * @return InputOptions |
|
285 | + * @throws EE_Error |
|
286 | + * @throws ReflectionException |
|
287 | + */ |
|
288 | + public function options(): ?InputOptions |
|
289 | + { |
|
290 | + if (! $this->options instanceof InputOptions) { |
|
291 | + $this->options = InputOptions::fromJson($this->get('FIN_options')); |
|
292 | + } |
|
293 | + return $this->options; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * @param InputOptions $options |
|
299 | + * @throws EE_Error |
|
300 | + * @throws ReflectionException |
|
301 | + */ |
|
302 | + public function setOptions(InputOptions $options) |
|
303 | + { |
|
304 | + // set local object |
|
305 | + $this->options = $options; |
|
306 | + // then pass to model as an array which will get converted to JSON by the model field |
|
307 | + $this->set('FIN_options', $options->toArray()); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * Order in which form input appears in a form. |
|
314 | + * |
|
315 | + * @return int |
|
316 | + * @throws EE_Error |
|
317 | + * @throws ReflectionException |
|
318 | + */ |
|
319 | + public function order(): int |
|
320 | + { |
|
321 | + return $this->get('FIN_order'); |
|
322 | + } |
|
323 | + |
|
324 | + |
|
325 | + /** |
|
326 | + * @param int $order |
|
327 | + * @throws EE_Error |
|
328 | + * @throws ReflectionException |
|
329 | + */ |
|
330 | + public function setOrder(int $order) |
|
331 | + { |
|
332 | + $this->set('FIN_order', $order); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Example text displayed within an input to assist users with completing the form. |
|
338 | + * |
|
339 | + * @return string |
|
340 | + * @throws EE_Error |
|
341 | + * @throws ReflectionException |
|
342 | + */ |
|
343 | + public function placeholder(): ?string |
|
344 | + { |
|
345 | + return $this->get('FIN_placeholder'); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @param string $placeholder |
|
351 | + * @throws EE_Error |
|
352 | + * @throws ReflectionException |
|
353 | + */ |
|
354 | + public function setPlaceholder(string $placeholder) |
|
355 | + { |
|
356 | + $this->set('FIN_placeholder', $placeholder); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Whether or not the input must be supplied with a value in order to complete the form. |
|
362 | + * |
|
363 | + * @return Required |
|
364 | + * @throws EE_Error |
|
365 | + * @throws ReflectionException |
|
366 | + */ |
|
367 | + public function required(): ?Required |
|
368 | + { |
|
369 | + if (! $this->required instanceof Required) { |
|
370 | + $this->required = Required::fromJson($this->get('FIN_required')); |
|
371 | + } |
|
372 | + return $this->required; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * @param Required $required |
|
378 | + * @throws EE_Error |
|
379 | + * @throws ReflectionException |
|
380 | + */ |
|
381 | + public function setRequired(Required $required) |
|
382 | + { |
|
383 | + // set local object |
|
384 | + $this->required = $required; |
|
385 | + // then pass to model as an array which will get converted to JSON by the model field |
|
386 | + $this->set('FIN_required', $required->toArray()); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * version of public label for use in identifiers |
|
392 | + * |
|
393 | + * @return string |
|
394 | + * @throws EE_Error |
|
395 | + * @throws ReflectionException |
|
396 | + */ |
|
397 | + public function slug(): ?string |
|
398 | + { |
|
399 | + return sanitize_title($this->label()->publicLabel()); |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
405 | + * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
406 | + * |
|
407 | + * @return string |
|
408 | + * @throws EE_Error |
|
409 | + * @throws ReflectionException |
|
410 | + */ |
|
411 | + public function status(): string |
|
412 | + { |
|
413 | + return $this->get('FIN_status'); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Whether form input is active, archived, trashed, or used as a default on new forms. |
|
419 | + * Values correspond to the EEM_Form_Element::STATUS_* constants. |
|
420 | + * |
|
421 | + * @param string $status |
|
422 | + * @throws EE_Error |
|
423 | + * @throws ReflectionException |
|
424 | + */ |
|
425 | + public function setStatus(string $status) |
|
426 | + { |
|
427 | + $this->set('FIN_status', $status); |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Form input type. |
|
433 | + * Values correspond to the EventEspresso\core\domain\entities\form\Input::TYPE_* constants. |
|
434 | + * |
|
435 | + * @return string |
|
436 | + * @throws EE_Error |
|
437 | + * @throws ReflectionException |
|
438 | + */ |
|
439 | + public function type(): ?string |
|
440 | + { |
|
441 | + return $this->get('FIN_type'); |
|
442 | + } |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * @param string $type |
|
447 | + * @throws EE_Error |
|
448 | + * @throws ReflectionException |
|
449 | + */ |
|
450 | + public function setType(string $type) |
|
451 | + { |
|
452 | + $this->set('FIN_type', $type); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * ID of the WP User that created this form input. |
|
458 | + * |
|
459 | + * @return int |
|
460 | + * @throws EE_Error |
|
461 | + * @throws ReflectionException |
|
462 | + */ |
|
463 | + public function wp_user(): int |
|
464 | + { |
|
465 | + return $this->get('FIN_wpUser'); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + /** |
|
470 | + * returns the id the wordpress user who created this question |
|
471 | + * |
|
472 | + * @param int $wp_user |
|
473 | + * @throws EE_Error |
|
474 | + * @throws ReflectionException |
|
475 | + */ |
|
476 | + public function setWpUser(int $wp_user) |
|
477 | + { |
|
478 | + $this->set('FIN_wpUser', $wp_user); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + /** |
|
483 | + * @param array $set_cols_n_values |
|
484 | + * @return bool|int|string |
|
485 | + * @throws EE_Error |
|
486 | + * @throws ReflectionException |
|
487 | + */ |
|
488 | + public function save($set_cols_n_values = []) |
|
489 | + { |
|
490 | + // make sure internal versions for all composite objects are updated |
|
491 | + $this->set('FIN_attributes', $this->attributes()->toArray()); |
|
492 | + $this->set('FIN_helpText', $this->helpText()->toArray()); |
|
493 | + $this->set('FIN_label', $this->label()->toArray()); |
|
494 | + $this->set('FIN_options', $this->options()->toArray()); |
|
495 | + $this->set('FIN_required', $this->required()->toArray()); |
|
496 | + return parent::save($set_cols_n_values); |
|
497 | + } |
|
498 | 498 | } |
@@ -12,77 +12,77 @@ |
||
12 | 12 | |
13 | 13 | class CopyAttendeeInfoForm extends EE_Form_Section_Proper |
14 | 14 | { |
15 | - /** |
|
16 | - * CopyAttendeeInfoForm constructor. |
|
17 | - * |
|
18 | - * @param EE_Registration[] $registrations |
|
19 | - * @param string $slug |
|
20 | - * @throws EE_Error |
|
21 | - * @throws ReflectionException |
|
22 | - */ |
|
23 | - public function __construct(array $registrations, string $slug) |
|
24 | - { |
|
25 | - parent::__construct( |
|
26 | - [ |
|
27 | - 'subsections' => $this->copyAttendeeInfoInputs($registrations), |
|
28 | - 'layout_strategy' => new EE_Template_Layout( |
|
29 | - [ |
|
30 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
31 | - . $slug |
|
32 | - . '/copy_attendee_info.template.php', |
|
33 | - 'begin_template_file' => null, |
|
34 | - 'input_template_file' => null, |
|
35 | - 'subsection_template_file' => null, |
|
36 | - 'end_template_file' => null, |
|
37 | - ] |
|
38 | - ), |
|
39 | - ] |
|
40 | - ); |
|
41 | - } |
|
15 | + /** |
|
16 | + * CopyAttendeeInfoForm constructor. |
|
17 | + * |
|
18 | + * @param EE_Registration[] $registrations |
|
19 | + * @param string $slug |
|
20 | + * @throws EE_Error |
|
21 | + * @throws ReflectionException |
|
22 | + */ |
|
23 | + public function __construct(array $registrations, string $slug) |
|
24 | + { |
|
25 | + parent::__construct( |
|
26 | + [ |
|
27 | + 'subsections' => $this->copyAttendeeInfoInputs($registrations), |
|
28 | + 'layout_strategy' => new EE_Template_Layout( |
|
29 | + [ |
|
30 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
31 | + . $slug |
|
32 | + . '/copy_attendee_info.template.php', |
|
33 | + 'begin_template_file' => null, |
|
34 | + 'input_template_file' => null, |
|
35 | + 'subsection_template_file' => null, |
|
36 | + 'end_template_file' => null, |
|
37 | + ] |
|
38 | + ), |
|
39 | + ] |
|
40 | + ); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @param array $registrations |
|
46 | - * @return array |
|
47 | - * @throws EE_Error |
|
48 | - * @throws ReflectionException |
|
49 | - */ |
|
50 | - private function copyAttendeeInfoInputs(array $registrations): array |
|
51 | - { |
|
52 | - $copy_attendee_info_inputs = []; |
|
53 | - $prev_ticket = null; |
|
54 | - foreach ($registrations as $registration) { |
|
55 | - // for all attendees other than the primary attendee |
|
56 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
57 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
58 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
59 | - $item_name = $registration->ticket()->name(); |
|
60 | - $item_name .= $registration->ticket()->description() !== '' |
|
61 | - ? ' - ' . $registration->ticket()->description() |
|
62 | - : ''; |
|
63 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
64 | - = new EE_Form_Section_HTML( |
|
65 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
66 | - ); |
|
67 | - $prev_ticket = $registration->ticket()->ID(); |
|
68 | - } |
|
44 | + /** |
|
45 | + * @param array $registrations |
|
46 | + * @return array |
|
47 | + * @throws EE_Error |
|
48 | + * @throws ReflectionException |
|
49 | + */ |
|
50 | + private function copyAttendeeInfoInputs(array $registrations): array |
|
51 | + { |
|
52 | + $copy_attendee_info_inputs = []; |
|
53 | + $prev_ticket = null; |
|
54 | + foreach ($registrations as $registration) { |
|
55 | + // for all attendees other than the primary attendee |
|
56 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
57 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
58 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
59 | + $item_name = $registration->ticket()->name(); |
|
60 | + $item_name .= $registration->ticket()->description() !== '' |
|
61 | + ? ' - ' . $registration->ticket()->description() |
|
62 | + : ''; |
|
63 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
64 | + = new EE_Form_Section_HTML( |
|
65 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
66 | + ); |
|
67 | + $prev_ticket = $registration->ticket()->ID(); |
|
68 | + } |
|
69 | 69 | |
70 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
71 | - = new EE_Checkbox_Multi_Input( |
|
72 | - [ |
|
73 | - $registration->ID() => sprintf( |
|
74 | - esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
75 | - $registration->count() |
|
76 | - ) |
|
77 | - ], |
|
78 | - [ |
|
79 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
80 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
81 | - 'display_html_label_text' => false, |
|
82 | - ] |
|
83 | - ); |
|
84 | - } |
|
85 | - } |
|
86 | - return $copy_attendee_info_inputs; |
|
87 | - } |
|
70 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
71 | + = new EE_Checkbox_Multi_Input( |
|
72 | + [ |
|
73 | + $registration->ID() => sprintf( |
|
74 | + esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
75 | + $registration->count() |
|
76 | + ) |
|
77 | + ], |
|
78 | + [ |
|
79 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
80 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
81 | + 'display_html_label_text' => false, |
|
82 | + ] |
|
83 | + ); |
|
84 | + } |
|
85 | + } |
|
86 | + return $copy_attendee_info_inputs; |
|
87 | + } |
|
88 | 88 | } |
@@ -56,18 +56,18 @@ discard block |
||
56 | 56 | if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
57 | 57 | // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
58 | 58 | if ($registration->ticket()->ID() !== $prev_ticket) { |
59 | - $item_name = $registration->ticket()->name(); |
|
60 | - $item_name .= $registration->ticket()->description() !== '' |
|
61 | - ? ' - ' . $registration->ticket()->description() |
|
59 | + $item_name = $registration->ticket()->name(); |
|
60 | + $item_name .= $registration->ticket()->description() !== '' |
|
61 | + ? ' - '.$registration->ticket()->description() |
|
62 | 62 | : ''; |
63 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
63 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] |
|
64 | 64 | = new EE_Form_Section_HTML( |
65 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
65 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
66 | 66 | ); |
67 | 67 | $prev_ticket = $registration->ticket()->ID(); |
68 | 68 | } |
69 | 69 | |
70 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
70 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] |
|
71 | 71 | = new EE_Checkbox_Multi_Input( |
72 | 72 | [ |
73 | 73 | $registration->ID() => sprintf( |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | ) |
77 | 77 | ], |
78 | 78 | [ |
79 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
79 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
80 | 80 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
81 | 81 | 'display_html_label_text' => false, |
82 | 82 | ] |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function addRequiredQuestion(string $identifier, string $required_question): void |
141 | 141 | { |
142 | - $this->required_questions[ $identifier ] = $required_question; |
|
142 | + $this->required_questions[$identifier] = $required_question; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | |
@@ -203,17 +203,17 @@ discard block |
||
203 | 203 | // Increment the reg forms number if form is valid. |
204 | 204 | if ($registrant_form->hasQuestions()) { |
205 | 205 | $this->reg_form_count++; |
206 | - $subsections[ $reg_url_link ] = $registrant_form; |
|
206 | + $subsections[$reg_url_link] = $registrant_form; |
|
207 | 207 | } else { |
208 | 208 | // or just add a blank section if there are no questions |
209 | - $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
209 | + $subsections[$reg_url_link] = new EE_Form_Section_HTML(); |
|
210 | 210 | } |
211 | 211 | |
212 | - $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
213 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
214 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
212 | + $this->template_args['registrations'][$reg_url_link] = $registration; |
|
213 | + $this->template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
214 | + $this->template_args['ticket_count'][$registration->ticket()->ID()] |
|
215 | 215 | ) |
216 | - ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
216 | + ? $this->template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
217 | 217 | : 1; |
218 | 218 | $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
219 | 219 | $this->reg_step->checkout->cart->get_grand_total(), |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | $ticket_line_item = is_array($ticket_line_item) |
224 | 224 | ? reset($ticket_line_item) |
225 | 225 | : $ticket_line_item; |
226 | - $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
226 | + $this->template_args['ticket_line_item'][$registration->ticket()->ID()] = |
|
227 | 227 | $Line_Item_Display->display_line_item($ticket_line_item); |
228 | 228 | if ($registration->is_primary_registrant()) { |
229 | 229 | $primary_registrant = $reg_url_link; |
@@ -233,13 +233,13 @@ discard block |
||
233 | 233 | |
234 | 234 | if ($primary_registrant && count($registrations) > 1) { |
235 | 235 | if ( |
236 | - isset($subsections[ $primary_registrant ]) |
|
237 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
236 | + isset($subsections[$primary_registrant]) |
|
237 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
238 | 238 | ) { |
239 | 239 | $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
240 | 240 | ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
241 | 241 | : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
242 | - $subsections[ $primary_registrant ]->add_subsections( |
|
242 | + $subsections[$primary_registrant]->add_subsections( |
|
243 | 243 | $copy_options, |
244 | 244 | 'primary_registrant', |
245 | 245 | false |
@@ -251,8 +251,8 @@ discard block |
||
251 | 251 | // Set the registration form template (default: one form per ticket details table). |
252 | 252 | // We decide the template to used based on the number of forms. |
253 | 253 | $template = $this->reg_form_count > 1 |
254 | - ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
255 | - : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
254 | + ? SPCO_REG_STEPS_PATH . $this->reg_step->slug().'/attendee_info_main.template.php' |
|
255 | + : SPCO_REG_STEPS_PATH.$this->reg_step->slug().'/attendee_info_single.template.php'; |
|
256 | 256 | $this->reg_step->setTemplate($template); |
257 | 257 | |
258 | 258 | return $subsections; |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
267 | 267 | { |
268 | 268 | // if this isn't a revisit, and they have the privacy consent box enabled, add it |
269 | - if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
269 | + if ( ! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
270 | 270 | $extra_inputs_section->add_subsections( |
271 | 271 | [ |
272 | 272 | 'consent_box' => new PrivacyConsentCheckboxForm( |
@@ -31,251 +31,251 @@ |
||
31 | 31 | */ |
32 | 32 | class RegForm extends EE_Form_Section_Proper |
33 | 33 | { |
34 | - /** |
|
35 | - * @var bool |
|
36 | - */ |
|
37 | - private $print_copy_info = false; |
|
34 | + /** |
|
35 | + * @var bool |
|
36 | + */ |
|
37 | + private $print_copy_info = false; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var EE_Registration_Config |
|
41 | - */ |
|
42 | - public $reg_config; |
|
39 | + /** |
|
40 | + * @var EE_Registration_Config |
|
41 | + */ |
|
42 | + public $reg_config; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var int |
|
46 | - */ |
|
47 | - protected $reg_form_count = 0; |
|
44 | + /** |
|
45 | + * @var int |
|
46 | + */ |
|
47 | + protected $reg_form_count = 0; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var EE_SPCO_Reg_Step_Attendee_Information |
|
51 | - */ |
|
52 | - public $reg_step; |
|
49 | + /** |
|
50 | + * @var EE_SPCO_Reg_Step_Attendee_Information |
|
51 | + */ |
|
52 | + public $reg_step; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - private $required_questions = []; |
|
54 | + /** |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + private $required_questions = []; |
|
58 | 58 | |
59 | - /** |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - private $template_args = []; |
|
59 | + /** |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + private $template_args = []; |
|
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * RegForm constructor. |
|
67 | - * |
|
68 | - * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
69 | - * @param EE_Registration_Config $reg_config |
|
70 | - * @throws ReflectionException |
|
71 | - * @throws EE_Error |
|
72 | - */ |
|
73 | - public function __construct( |
|
74 | - EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
75 | - EE_Registration_Config $reg_config |
|
76 | - ) { |
|
77 | - $this->reg_step = $reg_step; |
|
78 | - $this->reg_config = $reg_config; |
|
79 | - // setup some classes so that they are ready for loading during construction of other classes |
|
80 | - LoaderFactory::getShared(CountryOptions::class, [$this->reg_step->checkout->action]); |
|
81 | - LoaderFactory::getShared(StateOptions::class, [$this->reg_step->checkout->action]); |
|
82 | - LoaderFactory::getShared(RegFormQuestionFactory::class, [[$this, 'addRequiredQuestion']]); |
|
83 | - parent::__construct( |
|
84 | - [ |
|
85 | - 'name' => $this->reg_step->reg_form_name(), |
|
86 | - 'html_id' => $this->reg_step->reg_form_name(), |
|
87 | - 'subsections' => $this->generateSubsections(), |
|
88 | - 'layout_strategy' => new EE_Template_Layout( |
|
89 | - [ |
|
90 | - 'layout_template_file' => $this->reg_step->template(), // layout_template |
|
91 | - 'template_args' => $this->template_args, |
|
92 | - ] |
|
93 | - ), |
|
94 | - ] |
|
95 | - ); |
|
96 | - } |
|
65 | + /** |
|
66 | + * RegForm constructor. |
|
67 | + * |
|
68 | + * @param EE_SPCO_Reg_Step_Attendee_Information $reg_step |
|
69 | + * @param EE_Registration_Config $reg_config |
|
70 | + * @throws ReflectionException |
|
71 | + * @throws EE_Error |
|
72 | + */ |
|
73 | + public function __construct( |
|
74 | + EE_SPCO_Reg_Step_Attendee_Information $reg_step, |
|
75 | + EE_Registration_Config $reg_config |
|
76 | + ) { |
|
77 | + $this->reg_step = $reg_step; |
|
78 | + $this->reg_config = $reg_config; |
|
79 | + // setup some classes so that they are ready for loading during construction of other classes |
|
80 | + LoaderFactory::getShared(CountryOptions::class, [$this->reg_step->checkout->action]); |
|
81 | + LoaderFactory::getShared(StateOptions::class, [$this->reg_step->checkout->action]); |
|
82 | + LoaderFactory::getShared(RegFormQuestionFactory::class, [[$this, 'addRequiredQuestion']]); |
|
83 | + parent::__construct( |
|
84 | + [ |
|
85 | + 'name' => $this->reg_step->reg_form_name(), |
|
86 | + 'html_id' => $this->reg_step->reg_form_name(), |
|
87 | + 'subsections' => $this->generateSubsections(), |
|
88 | + 'layout_strategy' => new EE_Template_Layout( |
|
89 | + [ |
|
90 | + 'layout_template_file' => $this->reg_step->template(), // layout_template |
|
91 | + 'template_args' => $this->template_args, |
|
92 | + ] |
|
93 | + ), |
|
94 | + ] |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - public function enablePrintCopyInfo(): void |
|
103 | - { |
|
104 | - $this->print_copy_info = true; |
|
105 | - } |
|
99 | + /** |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + public function enablePrintCopyInfo(): void |
|
103 | + { |
|
104 | + $this->print_copy_info = true; |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public function printCopyInfo(): bool |
|
112 | - { |
|
113 | - return $this->print_copy_info; |
|
114 | - } |
|
108 | + /** |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public function printCopyInfo(): bool |
|
112 | + { |
|
113 | + return $this->print_copy_info; |
|
114 | + } |
|
115 | 115 | |
116 | 116 | |
117 | - /** |
|
118 | - * @return int |
|
119 | - */ |
|
120 | - public function regFormCount(): int |
|
121 | - { |
|
122 | - return $this->reg_form_count; |
|
123 | - } |
|
117 | + /** |
|
118 | + * @return int |
|
119 | + */ |
|
120 | + public function regFormCount(): int |
|
121 | + { |
|
122 | + return $this->reg_form_count; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | - /** |
|
127 | - * @return array |
|
128 | - */ |
|
129 | - public function requiredQuestions(): array |
|
130 | - { |
|
131 | - return $this->required_questions; |
|
132 | - } |
|
126 | + /** |
|
127 | + * @return array |
|
128 | + */ |
|
129 | + public function requiredQuestions(): array |
|
130 | + { |
|
131 | + return $this->required_questions; |
|
132 | + } |
|
133 | 133 | |
134 | 134 | |
135 | - /** |
|
136 | - * @param string $identifier |
|
137 | - * @param string $required_question |
|
138 | - */ |
|
139 | - public function addRequiredQuestion(string $identifier, string $required_question): void |
|
140 | - { |
|
141 | - $this->required_questions[ $identifier ] = $required_question; |
|
142 | - } |
|
135 | + /** |
|
136 | + * @param string $identifier |
|
137 | + * @param string $required_question |
|
138 | + */ |
|
139 | + public function addRequiredQuestion(string $identifier, string $required_question): void |
|
140 | + { |
|
141 | + $this->required_questions[ $identifier ] = $required_question; |
|
142 | + } |
|
143 | 143 | |
144 | 144 | |
145 | - /** |
|
146 | - * @return EE_Form_Section_Proper[] |
|
147 | - * @throws DomainException |
|
148 | - * @throws EE_Error |
|
149 | - * @throws InvalidArgumentException |
|
150 | - * @throws ReflectionException |
|
151 | - * @throws EntityNotFoundException |
|
152 | - * @throws InvalidDataTypeException |
|
153 | - * @throws InvalidInterfaceException |
|
154 | - */ |
|
155 | - private function generateSubsections(): array |
|
156 | - { |
|
157 | - // Init reg forms count. |
|
158 | - $this->reg_form_count = 0; |
|
145 | + /** |
|
146 | + * @return EE_Form_Section_Proper[] |
|
147 | + * @throws DomainException |
|
148 | + * @throws EE_Error |
|
149 | + * @throws InvalidArgumentException |
|
150 | + * @throws ReflectionException |
|
151 | + * @throws EntityNotFoundException |
|
152 | + * @throws InvalidDataTypeException |
|
153 | + * @throws InvalidInterfaceException |
|
154 | + */ |
|
155 | + private function generateSubsections(): array |
|
156 | + { |
|
157 | + // Init reg forms count. |
|
158 | + $this->reg_form_count = 0; |
|
159 | 159 | |
160 | - $primary_registrant = null; |
|
161 | - // autoload Line_Item_Display classes |
|
162 | - EEH_Autoloader::register_line_item_display_autoloaders(); |
|
163 | - $Line_Item_Display = new EE_Line_Item_Display(); |
|
164 | - // calculate taxes |
|
165 | - $Line_Item_Display->display_line_item( |
|
166 | - $this->reg_step->checkout->cart->get_grand_total(), |
|
167 | - ['set_tax_rate' => true] |
|
168 | - ); |
|
169 | - $extra_inputs_section = $this->reg_step->reg_step_hidden_inputs(); |
|
170 | - $this->addPrivacyConsentCheckbox($extra_inputs_section); |
|
171 | - $subsections = [ |
|
172 | - 'default_hidden_inputs' => $extra_inputs_section, |
|
173 | - ]; |
|
160 | + $primary_registrant = null; |
|
161 | + // autoload Line_Item_Display classes |
|
162 | + EEH_Autoloader::register_line_item_display_autoloaders(); |
|
163 | + $Line_Item_Display = new EE_Line_Item_Display(); |
|
164 | + // calculate taxes |
|
165 | + $Line_Item_Display->display_line_item( |
|
166 | + $this->reg_step->checkout->cart->get_grand_total(), |
|
167 | + ['set_tax_rate' => true] |
|
168 | + ); |
|
169 | + $extra_inputs_section = $this->reg_step->reg_step_hidden_inputs(); |
|
170 | + $this->addPrivacyConsentCheckbox($extra_inputs_section); |
|
171 | + $subsections = [ |
|
172 | + 'default_hidden_inputs' => $extra_inputs_section, |
|
173 | + ]; |
|
174 | 174 | |
175 | - $this->template_args = [ |
|
176 | - 'revisit' => $this->reg_step->checkout->revisit, |
|
177 | - 'registrations' => [], |
|
178 | - 'ticket_count' => [], |
|
179 | - ]; |
|
180 | - // grab the saved registrations from the transaction |
|
181 | - $registrations = $this->reg_step->checkout->transaction->registrations( |
|
182 | - $this->reg_step->checkout->reg_cache_where_params |
|
183 | - ); |
|
184 | - if ($registrations) { |
|
185 | - foreach ($registrations as $registration) { |
|
186 | - // can this registration be processed during this visit ? |
|
187 | - if ( |
|
188 | - $registration instanceof EE_Registration |
|
189 | - && $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration) |
|
190 | - ) { |
|
191 | - $reg_url_link = $registration->reg_url_link(); |
|
192 | - /** @var RegistrantForm $registrant_form */ |
|
193 | - $registrant_form = LoaderFactory::getNew( |
|
194 | - RegistrantForm::class, |
|
195 | - [ |
|
196 | - $registration, |
|
197 | - $this->reg_config->copyAttendeeInfo(), |
|
198 | - [$this, 'enablePrintCopyInfo'], |
|
199 | - $this->reg_step, |
|
200 | - ] |
|
201 | - ); |
|
202 | - // Increment the reg forms number if form is valid. |
|
203 | - if ($registrant_form->hasQuestions()) { |
|
204 | - $this->reg_form_count++; |
|
205 | - $subsections[ $reg_url_link ] = $registrant_form; |
|
206 | - } else { |
|
207 | - // or just add a blank section if there are no questions |
|
208 | - $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
209 | - } |
|
175 | + $this->template_args = [ |
|
176 | + 'revisit' => $this->reg_step->checkout->revisit, |
|
177 | + 'registrations' => [], |
|
178 | + 'ticket_count' => [], |
|
179 | + ]; |
|
180 | + // grab the saved registrations from the transaction |
|
181 | + $registrations = $this->reg_step->checkout->transaction->registrations( |
|
182 | + $this->reg_step->checkout->reg_cache_where_params |
|
183 | + ); |
|
184 | + if ($registrations) { |
|
185 | + foreach ($registrations as $registration) { |
|
186 | + // can this registration be processed during this visit ? |
|
187 | + if ( |
|
188 | + $registration instanceof EE_Registration |
|
189 | + && $this->reg_step->checkout->visit_allows_processing_of_this_registration($registration) |
|
190 | + ) { |
|
191 | + $reg_url_link = $registration->reg_url_link(); |
|
192 | + /** @var RegistrantForm $registrant_form */ |
|
193 | + $registrant_form = LoaderFactory::getNew( |
|
194 | + RegistrantForm::class, |
|
195 | + [ |
|
196 | + $registration, |
|
197 | + $this->reg_config->copyAttendeeInfo(), |
|
198 | + [$this, 'enablePrintCopyInfo'], |
|
199 | + $this->reg_step, |
|
200 | + ] |
|
201 | + ); |
|
202 | + // Increment the reg forms number if form is valid. |
|
203 | + if ($registrant_form->hasQuestions()) { |
|
204 | + $this->reg_form_count++; |
|
205 | + $subsections[ $reg_url_link ] = $registrant_form; |
|
206 | + } else { |
|
207 | + // or just add a blank section if there are no questions |
|
208 | + $subsections[ $reg_url_link ] = new EE_Form_Section_HTML(); |
|
209 | + } |
|
210 | 210 | |
211 | - $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
212 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
213 | - $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
214 | - ) |
|
215 | - ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
216 | - : 1; |
|
217 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
218 | - $this->reg_step->checkout->cart->get_grand_total(), |
|
219 | - 'Ticket', |
|
220 | - [$registration->ticket()->ID()] |
|
221 | - ); |
|
222 | - $ticket_line_item = is_array($ticket_line_item) |
|
223 | - ? reset($ticket_line_item) |
|
224 | - : $ticket_line_item; |
|
225 | - $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
226 | - $Line_Item_Display->display_line_item($ticket_line_item); |
|
227 | - if ($registration->is_primary_registrant()) { |
|
228 | - $primary_registrant = $reg_url_link; |
|
229 | - } |
|
230 | - } |
|
231 | - } |
|
211 | + $this->template_args['registrations'][ $reg_url_link ] = $registration; |
|
212 | + $this->template_args['ticket_count'][ $registration->ticket()->ID() ] = isset( |
|
213 | + $this->template_args['ticket_count'][ $registration->ticket()->ID() ] |
|
214 | + ) |
|
215 | + ? $this->template_args['ticket_count'][ $registration->ticket()->ID() ] + 1 |
|
216 | + : 1; |
|
217 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
218 | + $this->reg_step->checkout->cart->get_grand_total(), |
|
219 | + 'Ticket', |
|
220 | + [$registration->ticket()->ID()] |
|
221 | + ); |
|
222 | + $ticket_line_item = is_array($ticket_line_item) |
|
223 | + ? reset($ticket_line_item) |
|
224 | + : $ticket_line_item; |
|
225 | + $this->template_args['ticket_line_item'][ $registration->ticket()->ID() ] = |
|
226 | + $Line_Item_Display->display_line_item($ticket_line_item); |
|
227 | + if ($registration->is_primary_registrant()) { |
|
228 | + $primary_registrant = $reg_url_link; |
|
229 | + } |
|
230 | + } |
|
231 | + } |
|
232 | 232 | |
233 | - if ($primary_registrant && count($registrations) > 1) { |
|
234 | - if ( |
|
235 | - isset($subsections[ $primary_registrant ]) |
|
236 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
237 | - ) { |
|
238 | - $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
|
239 | - ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
|
240 | - : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
|
241 | - $subsections[ $primary_registrant ]->add_subsections( |
|
242 | - $copy_options, |
|
243 | - 'primary_registrant', |
|
244 | - false |
|
245 | - ); |
|
246 | - } |
|
247 | - } |
|
248 | - } |
|
233 | + if ($primary_registrant && count($registrations) > 1) { |
|
234 | + if ( |
|
235 | + isset($subsections[ $primary_registrant ]) |
|
236 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
237 | + ) { |
|
238 | + $copy_options['spco_copy_attendee_chk'] = $this->print_copy_info |
|
239 | + ? new CopyAttendeeInfoForm($registrations, $this->reg_step->slug()) |
|
240 | + : new AutoCopyAttendeeInfoForm($this->reg_step->slug()); |
|
241 | + $subsections[ $primary_registrant ]->add_subsections( |
|
242 | + $copy_options, |
|
243 | + 'primary_registrant', |
|
244 | + false |
|
245 | + ); |
|
246 | + } |
|
247 | + } |
|
248 | + } |
|
249 | 249 | |
250 | - // Set the registration form template (default: one form per ticket details table). |
|
251 | - // We decide the template to used based on the number of forms. |
|
252 | - $template = $this->reg_form_count > 1 |
|
253 | - ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
254 | - : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
255 | - $this->reg_step->setTemplate($template); |
|
250 | + // Set the registration form template (default: one form per ticket details table). |
|
251 | + // We decide the template to used based on the number of forms. |
|
252 | + $template = $this->reg_form_count > 1 |
|
253 | + ? SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_main.template.php' |
|
254 | + : SPCO_REG_STEPS_PATH . $this->reg_step->slug() . '/attendee_info_single.template.php'; |
|
255 | + $this->reg_step->setTemplate($template); |
|
256 | 256 | |
257 | - return $subsections; |
|
258 | - } |
|
257 | + return $subsections; |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - /** |
|
262 | - * @param EE_Form_Section_Proper $extra_inputs_section |
|
263 | - * @throws EE_Error |
|
264 | - */ |
|
265 | - private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
|
266 | - { |
|
267 | - // if this isn't a revisit, and they have the privacy consent box enabled, add it |
|
268 | - if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
269 | - $extra_inputs_section->add_subsections( |
|
270 | - [ |
|
271 | - 'consent_box' => new PrivacyConsentCheckboxForm( |
|
272 | - $this->reg_step->slug(), |
|
273 | - $this->reg_config->getConsentCheckboxLabelText() |
|
274 | - ) |
|
275 | - ], |
|
276 | - null, |
|
277 | - false |
|
278 | - ); |
|
279 | - } |
|
280 | - } |
|
261 | + /** |
|
262 | + * @param EE_Form_Section_Proper $extra_inputs_section |
|
263 | + * @throws EE_Error |
|
264 | + */ |
|
265 | + private function addPrivacyConsentCheckbox(EE_Form_Section_Proper $extra_inputs_section) |
|
266 | + { |
|
267 | + // if this isn't a revisit, and they have the privacy consent box enabled, add it |
|
268 | + if (! $this->reg_step->checkout->revisit && $this->reg_config->isConsentCheckboxEnabled()) { |
|
269 | + $extra_inputs_section->add_subsections( |
|
270 | + [ |
|
271 | + 'consent_box' => new PrivacyConsentCheckboxForm( |
|
272 | + $this->reg_step->slug(), |
|
273 | + $this->reg_config->getConsentCheckboxLabelText() |
|
274 | + ) |
|
275 | + ], |
|
276 | + null, |
|
277 | + false |
|
278 | + ); |
|
279 | + } |
|
280 | + } |
|
281 | 281 | } |
@@ -11,130 +11,130 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Form_Submission extends EEM_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * @var EEM_Form_Submission |
|
16 | - */ |
|
17 | - protected static $_instance; |
|
14 | + /** |
|
15 | + * @var EEM_Form_Submission |
|
16 | + */ |
|
17 | + protected static $_instance; |
|
18 | 18 | |
19 | - /** |
|
20 | - * @var RequestInterface |
|
21 | - */ |
|
22 | - private $request; |
|
19 | + /** |
|
20 | + * @var RequestInterface |
|
21 | + */ |
|
22 | + private $request; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * EEM_Form_Submission constructor. |
|
27 | - * |
|
28 | - * @param string|null $timezone |
|
29 | - * @throws EE_Error |
|
30 | - */ |
|
31 | - protected function __construct(?string $timezone) |
|
32 | - { |
|
33 | - $this->singular_item = esc_html__('Form Submission', 'event_espresso'); |
|
34 | - $this->plural_item = esc_html__('Form Submissions', 'event_espresso'); |
|
25 | + /** |
|
26 | + * EEM_Form_Submission constructor. |
|
27 | + * |
|
28 | + * @param string|null $timezone |
|
29 | + * @throws EE_Error |
|
30 | + */ |
|
31 | + protected function __construct(?string $timezone) |
|
32 | + { |
|
33 | + $this->singular_item = esc_html__('Form Submission', 'event_espresso'); |
|
34 | + $this->plural_item = esc_html__('Form Submissions', 'event_espresso'); |
|
35 | 35 | |
36 | - $this->_tables = [ |
|
37 | - 'Form_Submission' => new EE_Primary_Table('esp_form_submission', 'FSB_UUID'), |
|
38 | - ]; |
|
39 | - $this->_fields = [ |
|
40 | - 'Form_Submission' => [ |
|
41 | - 'FSB_UUID' => new EE_Primary_Key_String_Field( |
|
42 | - 'FSB_UUID', |
|
43 | - esc_html__('Form Submission UUID (universally unique identifier)', 'event_espresso') |
|
44 | - ), |
|
45 | - 'FSC_UUID' => new EE_Foreign_Key_String_Field( |
|
46 | - 'FSC_UUID', |
|
47 | - esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso'), |
|
48 | - false, |
|
49 | - '', |
|
50 | - 'Form_Section', |
|
51 | - false |
|
52 | - ), |
|
53 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
54 | - 'TXN_ID', |
|
55 | - esc_html__('Transaction ID', 'event_espresso'), |
|
56 | - false, |
|
57 | - 0, |
|
58 | - 'Transaction' |
|
59 | - ), |
|
60 | - 'FSB_data' => new EE_JSON_Field( |
|
61 | - 'FSB_data', |
|
62 | - esc_html__('Serialized form submission data', 'event_espresso'), |
|
63 | - true, |
|
64 | - null |
|
65 | - ), |
|
66 | - 'FSB_submitted' => new EE_Datetime_Field( |
|
67 | - 'FSB_submitted', |
|
68 | - esc_html__('Form submission timestamp', 'event_espresso'), |
|
69 | - false, |
|
70 | - EE_Datetime_Field::now, |
|
71 | - $timezone |
|
72 | - ), |
|
73 | - ], |
|
74 | - ]; |
|
75 | - $this->_model_relations = [ |
|
76 | - 'Form_Section' => new EE_Belongs_To_Relation(), |
|
77 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
78 | - ]; |
|
79 | - parent::__construct($timezone); |
|
80 | - $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
81 | - } |
|
36 | + $this->_tables = [ |
|
37 | + 'Form_Submission' => new EE_Primary_Table('esp_form_submission', 'FSB_UUID'), |
|
38 | + ]; |
|
39 | + $this->_fields = [ |
|
40 | + 'Form_Submission' => [ |
|
41 | + 'FSB_UUID' => new EE_Primary_Key_String_Field( |
|
42 | + 'FSB_UUID', |
|
43 | + esc_html__('Form Submission UUID (universally unique identifier)', 'event_espresso') |
|
44 | + ), |
|
45 | + 'FSC_UUID' => new EE_Foreign_Key_String_Field( |
|
46 | + 'FSC_UUID', |
|
47 | + esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso'), |
|
48 | + false, |
|
49 | + '', |
|
50 | + 'Form_Section', |
|
51 | + false |
|
52 | + ), |
|
53 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
54 | + 'TXN_ID', |
|
55 | + esc_html__('Transaction ID', 'event_espresso'), |
|
56 | + false, |
|
57 | + 0, |
|
58 | + 'Transaction' |
|
59 | + ), |
|
60 | + 'FSB_data' => new EE_JSON_Field( |
|
61 | + 'FSB_data', |
|
62 | + esc_html__('Serialized form submission data', 'event_espresso'), |
|
63 | + true, |
|
64 | + null |
|
65 | + ), |
|
66 | + 'FSB_submitted' => new EE_Datetime_Field( |
|
67 | + 'FSB_submitted', |
|
68 | + esc_html__('Form submission timestamp', 'event_espresso'), |
|
69 | + false, |
|
70 | + EE_Datetime_Field::now, |
|
71 | + $timezone |
|
72 | + ), |
|
73 | + ], |
|
74 | + ]; |
|
75 | + $this->_model_relations = [ |
|
76 | + 'Form_Section' => new EE_Belongs_To_Relation(), |
|
77 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
78 | + ]; |
|
79 | + parent::__construct($timezone); |
|
80 | + $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * adds all default where conditions unless the current request originates from the admin |
|
86 | - * |
|
87 | - * @param array $query_params |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - private function addDefaultWhereConditions(array $query_params): array |
|
91 | - { |
|
92 | - // might need to add a way to identify GQL requests for admin domains |
|
93 | - $query_params['default_where_conditions'] = $this->request->isAdmin() || $this->request->isAdminAjax() |
|
94 | - ? EEM_Base::default_where_conditions_none |
|
95 | - : EEM_Base::default_where_conditions_all; |
|
96 | - return $query_params; |
|
97 | - } |
|
84 | + /** |
|
85 | + * adds all default where conditions unless the current request originates from the admin |
|
86 | + * |
|
87 | + * @param array $query_params |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + private function addDefaultWhereConditions(array $query_params): array |
|
91 | + { |
|
92 | + // might need to add a way to identify GQL requests for admin domains |
|
93 | + $query_params['default_where_conditions'] = $this->request->isAdmin() || $this->request->isAdminAjax() |
|
94 | + ? EEM_Base::default_where_conditions_none |
|
95 | + : EEM_Base::default_where_conditions_all; |
|
96 | + return $query_params; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - /** |
|
101 | - * form sections should always be sorted in ascending order via the FSC_order field |
|
102 | - * |
|
103 | - * @param array $query_params |
|
104 | - * @return array |
|
105 | - */ |
|
106 | - private function addOrderByQueryParams(array $query_params): array |
|
107 | - { |
|
108 | - $query_params['order_by'] = ['FSB_submitted' => 'ASC']; |
|
109 | - return $query_params; |
|
110 | - } |
|
100 | + /** |
|
101 | + * form sections should always be sorted in ascending order via the FSC_order field |
|
102 | + * |
|
103 | + * @param array $query_params |
|
104 | + * @return array |
|
105 | + */ |
|
106 | + private function addOrderByQueryParams(array $query_params): array |
|
107 | + { |
|
108 | + $query_params['order_by'] = ['FSB_submitted' => 'ASC']; |
|
109 | + return $query_params; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * @param EE_Event $event |
|
115 | - * @return EE_Form_Submission[]|null |
|
116 | - * @throws EE_Error |
|
117 | - * @throws ReflectionException |
|
118 | - */ |
|
119 | - public function getAllFormSubmissionsForEvent(EE_Event $event): ?array |
|
120 | - { |
|
121 | - $query_params = [['FSC_UUID' => $event->registrationFormUuid()]]; |
|
122 | - $query_params = $this->addDefaultWhereConditions($query_params); |
|
123 | - $query_params = $this->addOrderByQueryParams($query_params); |
|
124 | - return $this->get_all($query_params); |
|
125 | - } |
|
113 | + /** |
|
114 | + * @param EE_Event $event |
|
115 | + * @return EE_Form_Submission[]|null |
|
116 | + * @throws EE_Error |
|
117 | + * @throws ReflectionException |
|
118 | + */ |
|
119 | + public function getAllFormSubmissionsForEvent(EE_Event $event): ?array |
|
120 | + { |
|
121 | + $query_params = [['FSC_UUID' => $event->registrationFormUuid()]]; |
|
122 | + $query_params = $this->addDefaultWhereConditions($query_params); |
|
123 | + $query_params = $this->addOrderByQueryParams($query_params); |
|
124 | + return $this->get_all($query_params); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | |
128 | - /** |
|
129 | - * @param EE_Transaction $transaction |
|
130 | - * @return EE_Form_Submission|null |
|
131 | - * @throws EE_Error |
|
132 | - * @throws ReflectionException |
|
133 | - */ |
|
134 | - public function getFormSubmissionForTransaction(EE_Transaction $transaction): ?EE_Form_Submission |
|
135 | - { |
|
136 | - $query_params = [['TXN_ID' => $transaction->ID()]]; |
|
137 | - $query_params = $this->addDefaultWhereConditions($query_params); |
|
138 | - return $this->get_one($query_params); |
|
139 | - } |
|
128 | + /** |
|
129 | + * @param EE_Transaction $transaction |
|
130 | + * @return EE_Form_Submission|null |
|
131 | + * @throws EE_Error |
|
132 | + * @throws ReflectionException |
|
133 | + */ |
|
134 | + public function getFormSubmissionForTransaction(EE_Transaction $transaction): ?EE_Form_Submission |
|
135 | + { |
|
136 | + $query_params = [['TXN_ID' => $transaction->ID()]]; |
|
137 | + $query_params = $this->addDefaultWhereConditions($query_params); |
|
138 | + return $this->get_one($query_params); |
|
139 | + } |
|
140 | 140 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getModelObjNodesInGroup($code) |
52 | 52 | { |
53 | - if (! $code) { |
|
53 | + if ( ! $code) { |
|
54 | 54 | throw new Exception( |
55 | 55 | esc_html__( |
56 | 56 | 'We aren’t sure which job you are performing. Please press back in your browser and try again.', |
@@ -58,9 +58,9 @@ discard block |
||
58 | 58 | ) |
59 | 59 | ); |
60 | 60 | } |
61 | - $deletion_data = get_option($this->getOptionPrefix() . $code, []); |
|
61 | + $deletion_data = get_option($this->getOptionPrefix().$code, []); |
|
62 | 62 | foreach ($deletion_data as $root) { |
63 | - if (! $root instanceof ModelObjNode) { |
|
63 | + if ( ! $root instanceof ModelObjNode) { |
|
64 | 64 | throw new UnexpectedEntityException($root, 'ModelObjNode'); |
65 | 65 | } |
66 | 66 | } |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | public function persistModelObjNodesGroup(array $model_obj_nodes, $code) |
122 | 122 | { |
123 | 123 | return add_option( |
124 | - $this->getOptionPrefix() . $code, |
|
124 | + $this->getOptionPrefix().$code, |
|
125 | 125 | $model_obj_nodes, |
126 | 126 | null, |
127 | 127 | 'no' |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | */ |
138 | 138 | public function deleteModelObjNodesInGroup($code) |
139 | 139 | { |
140 | - return delete_option($this->getOptionPrefix() . $code); |
|
140 | + return delete_option($this->getOptionPrefix().$code); |
|
141 | 141 | } |
142 | 142 | } |
143 | 143 | // End of file NodeGroupDao.php |
@@ -22,125 +22,125 @@ |
||
22 | 22 | */ |
23 | 23 | class NodeGroupDao |
24 | 24 | { |
25 | - /** |
|
26 | - * @return mixed|void |
|
27 | - */ |
|
28 | - public function generateGroupCode() |
|
29 | - { |
|
30 | - return wp_generate_password(6, false); |
|
31 | - } |
|
25 | + /** |
|
26 | + * @return mixed|void |
|
27 | + */ |
|
28 | + public function generateGroupCode() |
|
29 | + { |
|
30 | + return wp_generate_password(6, false); |
|
31 | + } |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Gets the string we put in front of the WP Option name used to store the jobs. |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - private function getOptionPrefix() |
|
40 | - { |
|
41 | - return 'ee_deletion_'; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Gets the string we put in front of the WP Option name used to store the jobs. |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + private function getOptionPrefix() |
|
40 | + { |
|
41 | + return 'ee_deletion_'; |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @param $code |
|
47 | - * @return ModelObjNode[] |
|
48 | - * @throws Exception |
|
49 | - * @throws UnexpectedEntityException |
|
50 | - * @throws Exception |
|
51 | - */ |
|
52 | - public function getModelObjNodesInGroup($code) |
|
53 | - { |
|
54 | - if (! $code) { |
|
55 | - throw new Exception( |
|
56 | - esc_html__( |
|
57 | - 'We aren’t sure which job you are performing. Please press back in your browser and try again.', |
|
58 | - 'event_espresso' |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
62 | - $deletion_data = get_option($this->getOptionPrefix() . $code, []); |
|
63 | - foreach ($deletion_data as $root) { |
|
64 | - if (! $root instanceof ModelObjNode) { |
|
65 | - throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
66 | - } |
|
67 | - } |
|
68 | - return $deletion_data; |
|
69 | - } |
|
45 | + /** |
|
46 | + * @param $code |
|
47 | + * @return ModelObjNode[] |
|
48 | + * @throws Exception |
|
49 | + * @throws UnexpectedEntityException |
|
50 | + * @throws Exception |
|
51 | + */ |
|
52 | + public function getModelObjNodesInGroup($code) |
|
53 | + { |
|
54 | + if (! $code) { |
|
55 | + throw new Exception( |
|
56 | + esc_html__( |
|
57 | + 'We aren’t sure which job you are performing. Please press back in your browser and try again.', |
|
58 | + 'event_espresso' |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | + $deletion_data = get_option($this->getOptionPrefix() . $code, []); |
|
63 | + foreach ($deletion_data as $root) { |
|
64 | + if (! $root instanceof ModelObjNode) { |
|
65 | + throw new UnexpectedEntityException($root, 'ModelObjNode'); |
|
66 | + } |
|
67 | + } |
|
68 | + return $deletion_data; |
|
69 | + } |
|
70 | 70 | |
71 | 71 | |
72 | - /** |
|
73 | - * Gets an array indicating what database rows are contained in the job. |
|
74 | - * Each top-level key is a model name, and its value is an array of IDs. |
|
75 | - * |
|
76 | - * @param ModelObjNode[] $model_obj_nodes |
|
77 | - * @return array |
|
78 | - * @throws EE_Error |
|
79 | - * @throws InvalidDataTypeException |
|
80 | - * @throws InvalidInterfaceException |
|
81 | - * @throws InvalidArgumentException |
|
82 | - * @throws ReflectionException |
|
83 | - */ |
|
84 | - public function getModelsAndIdsContainedIn(array $model_obj_nodes) |
|
85 | - { |
|
86 | - $models_and_ids_to_delete = []; |
|
87 | - foreach ($model_obj_nodes as $root) { |
|
88 | - $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
89 | - } |
|
90 | - return $models_and_ids_to_delete; |
|
91 | - } |
|
72 | + /** |
|
73 | + * Gets an array indicating what database rows are contained in the job. |
|
74 | + * Each top-level key is a model name, and its value is an array of IDs. |
|
75 | + * |
|
76 | + * @param ModelObjNode[] $model_obj_nodes |
|
77 | + * @return array |
|
78 | + * @throws EE_Error |
|
79 | + * @throws InvalidDataTypeException |
|
80 | + * @throws InvalidInterfaceException |
|
81 | + * @throws InvalidArgumentException |
|
82 | + * @throws ReflectionException |
|
83 | + */ |
|
84 | + public function getModelsAndIdsContainedIn(array $model_obj_nodes) |
|
85 | + { |
|
86 | + $models_and_ids_to_delete = []; |
|
87 | + foreach ($model_obj_nodes as $root) { |
|
88 | + $models_and_ids_to_delete = array_replace_recursive($models_and_ids_to_delete, $root->getIds()); |
|
89 | + } |
|
90 | + return $models_and_ids_to_delete; |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * Gets an array indicating what database rows are contained in the job. |
|
96 | - * Each top-level key is a model name, and its value is an array of IDs. |
|
97 | - * |
|
98 | - * @param string $code |
|
99 | - * @return array |
|
100 | - * @throws EE_Error |
|
101 | - * @throws Exception |
|
102 | - * @throws InvalidArgumentException |
|
103 | - * @throws InvalidDataTypeException |
|
104 | - * @throws InvalidInterfaceException |
|
105 | - * @throws ReflectionException |
|
106 | - * @throws UnexpectedEntityException |
|
107 | - * @throws Exception |
|
108 | - */ |
|
109 | - public function getModelsAndIdsFromGroup($code) |
|
110 | - { |
|
111 | - $model_obj_nodes = $this->getModelObjNodesInGroup($code); |
|
112 | - return $this->getModelsAndIdsContainedIn($model_obj_nodes); |
|
113 | - } |
|
94 | + /** |
|
95 | + * Gets an array indicating what database rows are contained in the job. |
|
96 | + * Each top-level key is a model name, and its value is an array of IDs. |
|
97 | + * |
|
98 | + * @param string $code |
|
99 | + * @return array |
|
100 | + * @throws EE_Error |
|
101 | + * @throws Exception |
|
102 | + * @throws InvalidArgumentException |
|
103 | + * @throws InvalidDataTypeException |
|
104 | + * @throws InvalidInterfaceException |
|
105 | + * @throws ReflectionException |
|
106 | + * @throws UnexpectedEntityException |
|
107 | + * @throws Exception |
|
108 | + */ |
|
109 | + public function getModelsAndIdsFromGroup($code) |
|
110 | + { |
|
111 | + $model_obj_nodes = $this->getModelObjNodesInGroup($code); |
|
112 | + return $this->getModelsAndIdsContainedIn($model_obj_nodes); |
|
113 | + } |
|
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Persists the ModelObjNodes for future requests, using the code for reference. |
|
118 | - * |
|
119 | - * @param ModelObjNode[] $model_obj_nodes |
|
120 | - * @param string $code |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function persistModelObjNodesGroup(array $model_obj_nodes, $code) |
|
124 | - { |
|
125 | - return add_option( |
|
126 | - $this->getOptionPrefix() . $code, |
|
127 | - $model_obj_nodes, |
|
128 | - null, |
|
129 | - 'no' |
|
130 | - ); |
|
131 | - } |
|
116 | + /** |
|
117 | + * Persists the ModelObjNodes for future requests, using the code for reference. |
|
118 | + * |
|
119 | + * @param ModelObjNode[] $model_obj_nodes |
|
120 | + * @param string $code |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function persistModelObjNodesGroup(array $model_obj_nodes, $code) |
|
124 | + { |
|
125 | + return add_option( |
|
126 | + $this->getOptionPrefix() . $code, |
|
127 | + $model_obj_nodes, |
|
128 | + null, |
|
129 | + 'no' |
|
130 | + ); |
|
131 | + } |
|
132 | 132 | |
133 | 133 | |
134 | - /** |
|
135 | - * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though. |
|
136 | - * |
|
137 | - * @param $code |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - public function deleteModelObjNodesInGroup($code) |
|
141 | - { |
|
142 | - return delete_option($this->getOptionPrefix() . $code); |
|
143 | - } |
|
134 | + /** |
|
135 | + * Forgets about the group of ModelObjNodes. Doesn't delete the rows in the database they reference though. |
|
136 | + * |
|
137 | + * @param $code |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + public function deleteModelObjNodesInGroup($code) |
|
141 | + { |
|
142 | + return delete_option($this->getOptionPrefix() . $code); |
|
143 | + } |
|
144 | 144 | } |
145 | 145 | // End of file NodeGroupDao.php |
146 | 146 | // Location: EventEspresso\core\services\orm\tree_traversal/NodeGroupDao.php |
@@ -98,17 +98,17 @@ discard block |
||
98 | 98 | ], |
99 | 99 | ] |
100 | 100 | ); |
101 | - $new_item_nodes = []; |
|
101 | + $new_item_nodes = []; |
|
102 | 102 | |
103 | 103 | // Add entity nodes for each of the model objects we fetched. |
104 | 104 | foreach ($related_model_objs as $related_model_obj) { |
105 | - $entity_node = new ModelObjNode( |
|
105 | + $entity_node = new ModelObjNode( |
|
106 | 106 | $related_model_obj->ID(), |
107 | 107 | $related_model_obj->get_model(), |
108 | 108 | $this->dont_traverse_models |
109 | 109 | ); |
110 | - $this->nodes[ $related_model_obj->ID() ] = $entity_node; |
|
111 | - $new_item_nodes[ $related_model_obj->ID() ] = $entity_node; |
|
110 | + $this->nodes[$related_model_obj->ID()] = $entity_node; |
|
111 | + $new_item_nodes[$related_model_obj->ID()] = $entity_node; |
|
112 | 112 | } |
113 | 113 | $num_identified += count($new_item_nodes); |
114 | 114 | if ($num_identified < $model_objects_to_identify) { |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | protected function allChildrenComplete() |
136 | 136 | { |
137 | 137 | foreach ($this->nodes as $model_obj_node) { |
138 | - if (! $model_obj_node->isComplete()) { |
|
138 | + if ( ! $model_obj_node->isComplete()) { |
|
139 | 139 | return false; |
140 | 140 | } |
141 | 141 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget) |
154 | 154 | { |
155 | 155 | $work_done = 0; |
156 | - if (! $model_obj_nodes) { |
|
156 | + if ( ! $model_obj_nodes) { |
|
157 | 157 | return 0; |
158 | 158 | } |
159 | 159 | foreach ($model_obj_nodes as $model_obj_node) { |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | $relation_settings = null; |
230 | 230 | } |
231 | 231 | if ($relation_settings instanceof EE_Has_Many_Any_Relation) { |
232 | - $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = |
|
232 | + $where_params[$this->related_model->get_field_containing_related_model_name()->get_name()] = |
|
233 | 233 | $this->main_model->get_this_model_name(); |
234 | 234 | } |
235 | 235 | return $where_params; |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | 'objs' => [], |
250 | 250 | ]; |
251 | 251 | foreach ($this->nodes as $id => $model_obj_node) { |
252 | - $tree['objs'][ $id ] = $model_obj_node->toArray(); |
|
252 | + $tree['objs'][$id] = $model_obj_node->toArray(); |
|
253 | 253 | } |
254 | 254 | return $tree; |
255 | 255 | } |
@@ -24,309 +24,309 @@ |
||
24 | 24 | */ |
25 | 25 | class RelationNode extends BaseNode |
26 | 26 | { |
27 | - /** |
|
28 | - * @var int |
|
29 | - */ |
|
30 | - protected $count; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string|int |
|
34 | - */ |
|
35 | - protected $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EEM_Base |
|
39 | - */ |
|
40 | - protected $main_model; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var ModelObjNode[] |
|
44 | - */ |
|
45 | - protected $nodes; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var EEM_Base |
|
49 | - */ |
|
50 | - protected $related_model; |
|
51 | - |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * RelationNode constructor. |
|
56 | - * |
|
57 | - * @param $main_model_obj_id |
|
58 | - * @param EEM_Base $main_model |
|
59 | - * @param EEM_Base $related_model |
|
60 | - * @param array $dont_traverse_models array of model names we DON'T want to traverse |
|
61 | - */ |
|
62 | - public function __construct( |
|
63 | - $main_model_obj_id, |
|
64 | - EEM_Base $main_model, |
|
65 | - EEM_Base $related_model, |
|
66 | - array $dont_traverse_models = [] |
|
67 | - ) { |
|
68 | - $this->id = $main_model_obj_id; |
|
69 | - $this->main_model = $main_model; |
|
70 | - $this->related_model = $related_model; |
|
71 | - $this->nodes = []; |
|
72 | - $this->dont_traverse_models = $dont_traverse_models; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Here is where most of the work happens. We've counted how many related model objects exist, here we identify |
|
78 | - * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc. |
|
79 | - * |
|
80 | - * @param int $model_objects_to_identify |
|
81 | - * @return int |
|
82 | - * @throws EE_Error |
|
83 | - * @throws InvalidArgumentException |
|
84 | - * @throws InvalidDataTypeException |
|
85 | - * @throws InvalidInterfaceException |
|
86 | - * @throws ReflectionException |
|
87 | - */ |
|
88 | - protected function work($model_objects_to_identify) |
|
89 | - { |
|
90 | - $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify); |
|
91 | - if ($num_identified < $model_objects_to_identify) { |
|
92 | - $related_model_objs = $this->related_model->get_all( |
|
93 | - [ |
|
94 | - $this->whereQueryParams(), |
|
95 | - 'limit' => [ |
|
96 | - count($this->nodes), |
|
97 | - $model_objects_to_identify - $num_identified, |
|
98 | - ], |
|
99 | - ] |
|
100 | - ); |
|
101 | - $new_item_nodes = []; |
|
102 | - |
|
103 | - // Add entity nodes for each of the model objects we fetched. |
|
104 | - foreach ($related_model_objs as $related_model_obj) { |
|
105 | - $entity_node = new ModelObjNode( |
|
106 | - $related_model_obj->ID(), |
|
107 | - $related_model_obj->get_model(), |
|
108 | - $this->dont_traverse_models |
|
109 | - ); |
|
110 | - $this->nodes[ $related_model_obj->ID() ] = $entity_node; |
|
111 | - $new_item_nodes[ $related_model_obj->ID() ] = $entity_node; |
|
112 | - } |
|
113 | - $num_identified += count($new_item_nodes); |
|
114 | - if ($num_identified < $model_objects_to_identify) { |
|
115 | - // And lastly do the work. |
|
116 | - $num_identified += $this->visitAlreadyDiscoveredNodes( |
|
117 | - $new_item_nodes, |
|
118 | - $model_objects_to_identify - $num_identified |
|
119 | - ); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) { |
|
124 | - $this->complete = true; |
|
125 | - } |
|
126 | - return $num_identified; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Checks if all the identified child nodes are complete or not. |
|
132 | - * |
|
133 | - * @return bool |
|
134 | - */ |
|
135 | - protected function allChildrenComplete() |
|
136 | - { |
|
137 | - foreach ($this->nodes as $model_obj_node) { |
|
138 | - if (! $model_obj_node->isComplete()) { |
|
139 | - return false; |
|
140 | - } |
|
141 | - } |
|
142 | - return true; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget. |
|
148 | - * |
|
149 | - * @param ModelObjNode[] $model_obj_nodes |
|
150 | - * @param $work_budget |
|
151 | - * @return int |
|
152 | - */ |
|
153 | - protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget) |
|
154 | - { |
|
155 | - $work_done = 0; |
|
156 | - if (! $model_obj_nodes) { |
|
157 | - return 0; |
|
158 | - } |
|
159 | - foreach ($model_obj_nodes as $model_obj_node) { |
|
160 | - if ($work_done >= $work_budget) { |
|
161 | - break; |
|
162 | - } |
|
163 | - $work_done += $model_obj_node->visit($work_budget - $work_done); |
|
164 | - } |
|
165 | - return $work_done; |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Whether this item has already been initialized |
|
171 | - */ |
|
172 | - protected function isDiscovered() |
|
173 | - { |
|
174 | - return $this->count !== null; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @return boolean |
|
180 | - */ |
|
181 | - public function isComplete() |
|
182 | - { |
|
183 | - if ($this->complete === null) { |
|
184 | - if (count($this->nodes) === $this->count) { |
|
185 | - $this->complete = true; |
|
186 | - } else { |
|
187 | - $this->complete = false; |
|
188 | - } |
|
189 | - } |
|
190 | - return $this->complete; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Discovers how many related model objects exist. |
|
196 | - * |
|
197 | - * @return void |
|
198 | - * @throws EE_Error |
|
199 | - * @throws InvalidArgumentException |
|
200 | - * @throws InvalidDataTypeException |
|
201 | - * @throws InvalidInterfaceException |
|
202 | - */ |
|
203 | - protected function discover() |
|
204 | - { |
|
205 | - $this->count = $this->related_model->count([$this->whereQueryParams()]); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @return array |
|
211 | - * @throws EE_Error |
|
212 | - * @throws InvalidDataTypeException |
|
213 | - * @throws InvalidInterfaceException |
|
214 | - * @throws InvalidArgumentException |
|
215 | - */ |
|
216 | - protected function whereQueryParams() |
|
217 | - { |
|
218 | - $where_params = [ |
|
219 | - $this->related_model->get_foreign_key_to( |
|
220 | - $this->main_model->get_this_model_name() |
|
221 | - )->get_name() => $this->id, |
|
222 | - ]; |
|
223 | - try { |
|
224 | - $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name()); |
|
225 | - } catch (EE_Error $e) { |
|
226 | - // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table |
|
227 | - // which hasn't been explicitly declared in the main model object's model's relations. |
|
228 | - $relation_settings = null; |
|
229 | - } |
|
230 | - if ($relation_settings instanceof EE_Has_Many_Any_Relation) { |
|
231 | - $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = |
|
232 | - $this->main_model->get_this_model_name(); |
|
233 | - } |
|
234 | - return $where_params; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * @return array |
|
240 | - * @throws EE_Error |
|
241 | - * @throws ReflectionException |
|
242 | - */ |
|
243 | - public function toArray() |
|
244 | - { |
|
245 | - $tree = [ |
|
246 | - 'count' => $this->count, |
|
247 | - 'complete' => $this->isComplete(), |
|
248 | - 'objs' => [], |
|
249 | - ]; |
|
250 | - foreach ($this->nodes as $id => $model_obj_node) { |
|
251 | - $tree['objs'][ $id ] = $model_obj_node->toArray(); |
|
252 | - } |
|
253 | - return $tree; |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * Gets the IDs of all the model objects to delete; indexed first by model object name. |
|
259 | - * |
|
260 | - * @return array |
|
261 | - * @throws EE_Error |
|
262 | - * @throws ReflectionException |
|
263 | - */ |
|
264 | - public function getIds() |
|
265 | - { |
|
266 | - if (empty($this->nodes)) { |
|
267 | - return []; |
|
268 | - } |
|
269 | - $ids = [ |
|
270 | - $this->related_model->get_this_model_name() => array_combine( |
|
271 | - array_keys($this->nodes), |
|
272 | - array_keys($this->nodes) |
|
273 | - ), |
|
274 | - ]; |
|
275 | - foreach ($this->nodes as $model_obj_node) { |
|
276 | - $ids = array_replace_recursive($ids, $model_obj_node->getIds()); |
|
277 | - } |
|
278 | - return $ids; |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * Returns the number of sub-nodes found (ie, related model objects across this relation.) |
|
284 | - * |
|
285 | - * @return int |
|
286 | - */ |
|
287 | - public function countSubNodes() |
|
288 | - { |
|
289 | - return count($this->nodes); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Don't serialize the models. Just record their names on some dynamic properties. |
|
295 | - * |
|
296 | - * @return array |
|
297 | - */ |
|
298 | - public function __sleep() |
|
299 | - { |
|
300 | - $this->m = $this->main_model->get_this_model_name(); |
|
301 | - $this->rm = $this->related_model->get_this_model_name(); |
|
302 | - return array_merge( |
|
303 | - [ |
|
304 | - 'm', |
|
305 | - 'rm', |
|
306 | - 'id', |
|
307 | - 'count', |
|
308 | - 'nodes', |
|
309 | - ], |
|
310 | - parent::__sleep() |
|
311 | - ); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * Use the dynamic properties to instantiate the models we use. |
|
317 | - * |
|
318 | - * @throws EE_Error |
|
319 | - * @throws InvalidArgumentException |
|
320 | - * @throws InvalidDataTypeException |
|
321 | - * @throws InvalidInterfaceException |
|
322 | - * @throws ReflectionException |
|
323 | - */ |
|
324 | - public function __wakeup() |
|
325 | - { |
|
326 | - $this->main_model = EE_Registry::instance()->load_model($this->m); |
|
327 | - $this->related_model = EE_Registry::instance()->load_model($this->rm); |
|
328 | - parent::__wakeup(); |
|
329 | - } |
|
27 | + /** |
|
28 | + * @var int |
|
29 | + */ |
|
30 | + protected $count; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string|int |
|
34 | + */ |
|
35 | + protected $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EEM_Base |
|
39 | + */ |
|
40 | + protected $main_model; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var ModelObjNode[] |
|
44 | + */ |
|
45 | + protected $nodes; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var EEM_Base |
|
49 | + */ |
|
50 | + protected $related_model; |
|
51 | + |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * RelationNode constructor. |
|
56 | + * |
|
57 | + * @param $main_model_obj_id |
|
58 | + * @param EEM_Base $main_model |
|
59 | + * @param EEM_Base $related_model |
|
60 | + * @param array $dont_traverse_models array of model names we DON'T want to traverse |
|
61 | + */ |
|
62 | + public function __construct( |
|
63 | + $main_model_obj_id, |
|
64 | + EEM_Base $main_model, |
|
65 | + EEM_Base $related_model, |
|
66 | + array $dont_traverse_models = [] |
|
67 | + ) { |
|
68 | + $this->id = $main_model_obj_id; |
|
69 | + $this->main_model = $main_model; |
|
70 | + $this->related_model = $related_model; |
|
71 | + $this->nodes = []; |
|
72 | + $this->dont_traverse_models = $dont_traverse_models; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Here is where most of the work happens. We've counted how many related model objects exist, here we identify |
|
78 | + * them (ie, learn their IDs). But its recursive, so we'll also find their related dependent model objects etc. |
|
79 | + * |
|
80 | + * @param int $model_objects_to_identify |
|
81 | + * @return int |
|
82 | + * @throws EE_Error |
|
83 | + * @throws InvalidArgumentException |
|
84 | + * @throws InvalidDataTypeException |
|
85 | + * @throws InvalidInterfaceException |
|
86 | + * @throws ReflectionException |
|
87 | + */ |
|
88 | + protected function work($model_objects_to_identify) |
|
89 | + { |
|
90 | + $num_identified = $this->visitAlreadyDiscoveredNodes($this->nodes, $model_objects_to_identify); |
|
91 | + if ($num_identified < $model_objects_to_identify) { |
|
92 | + $related_model_objs = $this->related_model->get_all( |
|
93 | + [ |
|
94 | + $this->whereQueryParams(), |
|
95 | + 'limit' => [ |
|
96 | + count($this->nodes), |
|
97 | + $model_objects_to_identify - $num_identified, |
|
98 | + ], |
|
99 | + ] |
|
100 | + ); |
|
101 | + $new_item_nodes = []; |
|
102 | + |
|
103 | + // Add entity nodes for each of the model objects we fetched. |
|
104 | + foreach ($related_model_objs as $related_model_obj) { |
|
105 | + $entity_node = new ModelObjNode( |
|
106 | + $related_model_obj->ID(), |
|
107 | + $related_model_obj->get_model(), |
|
108 | + $this->dont_traverse_models |
|
109 | + ); |
|
110 | + $this->nodes[ $related_model_obj->ID() ] = $entity_node; |
|
111 | + $new_item_nodes[ $related_model_obj->ID() ] = $entity_node; |
|
112 | + } |
|
113 | + $num_identified += count($new_item_nodes); |
|
114 | + if ($num_identified < $model_objects_to_identify) { |
|
115 | + // And lastly do the work. |
|
116 | + $num_identified += $this->visitAlreadyDiscoveredNodes( |
|
117 | + $new_item_nodes, |
|
118 | + $model_objects_to_identify - $num_identified |
|
119 | + ); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + if (count($this->nodes) >= $this->count && $this->allChildrenComplete()) { |
|
124 | + $this->complete = true; |
|
125 | + } |
|
126 | + return $num_identified; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Checks if all the identified child nodes are complete or not. |
|
132 | + * |
|
133 | + * @return bool |
|
134 | + */ |
|
135 | + protected function allChildrenComplete() |
|
136 | + { |
|
137 | + foreach ($this->nodes as $model_obj_node) { |
|
138 | + if (! $model_obj_node->isComplete()) { |
|
139 | + return false; |
|
140 | + } |
|
141 | + } |
|
142 | + return true; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Visits the provided nodes and keeps track of how much work was done, making sure to not go over budget. |
|
148 | + * |
|
149 | + * @param ModelObjNode[] $model_obj_nodes |
|
150 | + * @param $work_budget |
|
151 | + * @return int |
|
152 | + */ |
|
153 | + protected function visitAlreadyDiscoveredNodes($model_obj_nodes, $work_budget) |
|
154 | + { |
|
155 | + $work_done = 0; |
|
156 | + if (! $model_obj_nodes) { |
|
157 | + return 0; |
|
158 | + } |
|
159 | + foreach ($model_obj_nodes as $model_obj_node) { |
|
160 | + if ($work_done >= $work_budget) { |
|
161 | + break; |
|
162 | + } |
|
163 | + $work_done += $model_obj_node->visit($work_budget - $work_done); |
|
164 | + } |
|
165 | + return $work_done; |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Whether this item has already been initialized |
|
171 | + */ |
|
172 | + protected function isDiscovered() |
|
173 | + { |
|
174 | + return $this->count !== null; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @return boolean |
|
180 | + */ |
|
181 | + public function isComplete() |
|
182 | + { |
|
183 | + if ($this->complete === null) { |
|
184 | + if (count($this->nodes) === $this->count) { |
|
185 | + $this->complete = true; |
|
186 | + } else { |
|
187 | + $this->complete = false; |
|
188 | + } |
|
189 | + } |
|
190 | + return $this->complete; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Discovers how many related model objects exist. |
|
196 | + * |
|
197 | + * @return void |
|
198 | + * @throws EE_Error |
|
199 | + * @throws InvalidArgumentException |
|
200 | + * @throws InvalidDataTypeException |
|
201 | + * @throws InvalidInterfaceException |
|
202 | + */ |
|
203 | + protected function discover() |
|
204 | + { |
|
205 | + $this->count = $this->related_model->count([$this->whereQueryParams()]); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @return array |
|
211 | + * @throws EE_Error |
|
212 | + * @throws InvalidDataTypeException |
|
213 | + * @throws InvalidInterfaceException |
|
214 | + * @throws InvalidArgumentException |
|
215 | + */ |
|
216 | + protected function whereQueryParams() |
|
217 | + { |
|
218 | + $where_params = [ |
|
219 | + $this->related_model->get_foreign_key_to( |
|
220 | + $this->main_model->get_this_model_name() |
|
221 | + )->get_name() => $this->id, |
|
222 | + ]; |
|
223 | + try { |
|
224 | + $relation_settings = $this->main_model->related_settings_for($this->related_model->get_this_model_name()); |
|
225 | + } catch (EE_Error $e) { |
|
226 | + // This will happen for has-and-belongs-to-many relations, when this node's related model is that join table |
|
227 | + // which hasn't been explicitly declared in the main model object's model's relations. |
|
228 | + $relation_settings = null; |
|
229 | + } |
|
230 | + if ($relation_settings instanceof EE_Has_Many_Any_Relation) { |
|
231 | + $where_params[ $this->related_model->get_field_containing_related_model_name()->get_name() ] = |
|
232 | + $this->main_model->get_this_model_name(); |
|
233 | + } |
|
234 | + return $where_params; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * @return array |
|
240 | + * @throws EE_Error |
|
241 | + * @throws ReflectionException |
|
242 | + */ |
|
243 | + public function toArray() |
|
244 | + { |
|
245 | + $tree = [ |
|
246 | + 'count' => $this->count, |
|
247 | + 'complete' => $this->isComplete(), |
|
248 | + 'objs' => [], |
|
249 | + ]; |
|
250 | + foreach ($this->nodes as $id => $model_obj_node) { |
|
251 | + $tree['objs'][ $id ] = $model_obj_node->toArray(); |
|
252 | + } |
|
253 | + return $tree; |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * Gets the IDs of all the model objects to delete; indexed first by model object name. |
|
259 | + * |
|
260 | + * @return array |
|
261 | + * @throws EE_Error |
|
262 | + * @throws ReflectionException |
|
263 | + */ |
|
264 | + public function getIds() |
|
265 | + { |
|
266 | + if (empty($this->nodes)) { |
|
267 | + return []; |
|
268 | + } |
|
269 | + $ids = [ |
|
270 | + $this->related_model->get_this_model_name() => array_combine( |
|
271 | + array_keys($this->nodes), |
|
272 | + array_keys($this->nodes) |
|
273 | + ), |
|
274 | + ]; |
|
275 | + foreach ($this->nodes as $model_obj_node) { |
|
276 | + $ids = array_replace_recursive($ids, $model_obj_node->getIds()); |
|
277 | + } |
|
278 | + return $ids; |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * Returns the number of sub-nodes found (ie, related model objects across this relation.) |
|
284 | + * |
|
285 | + * @return int |
|
286 | + */ |
|
287 | + public function countSubNodes() |
|
288 | + { |
|
289 | + return count($this->nodes); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Don't serialize the models. Just record their names on some dynamic properties. |
|
295 | + * |
|
296 | + * @return array |
|
297 | + */ |
|
298 | + public function __sleep() |
|
299 | + { |
|
300 | + $this->m = $this->main_model->get_this_model_name(); |
|
301 | + $this->rm = $this->related_model->get_this_model_name(); |
|
302 | + return array_merge( |
|
303 | + [ |
|
304 | + 'm', |
|
305 | + 'rm', |
|
306 | + 'id', |
|
307 | + 'count', |
|
308 | + 'nodes', |
|
309 | + ], |
|
310 | + parent::__sleep() |
|
311 | + ); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * Use the dynamic properties to instantiate the models we use. |
|
317 | + * |
|
318 | + * @throws EE_Error |
|
319 | + * @throws InvalidArgumentException |
|
320 | + * @throws InvalidDataTypeException |
|
321 | + * @throws InvalidInterfaceException |
|
322 | + * @throws ReflectionException |
|
323 | + */ |
|
324 | + public function __wakeup() |
|
325 | + { |
|
326 | + $this->main_model = EE_Registry::instance()->load_model($this->m); |
|
327 | + $this->related_model = EE_Registry::instance()->load_model($this->rm); |
|
328 | + parent::__wakeup(); |
|
329 | + } |
|
330 | 330 | } |
331 | 331 | // End of file RelationNode.php |
332 | 332 | // Location: EventEspresso\core\services\orm\tree_traversal/RelationNode.php |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public static function register(string $addon_name = '', array $setup_args = []): bool |
31 | 31 | { |
32 | - self::$exporters[ $addon_name ] = $setup_args; |
|
32 | + self::$exporters[$addon_name] = $setup_args; |
|
33 | 33 | // add to list of modules to be registered |
34 | 34 | add_filter( |
35 | 35 | 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public static function deregister(string $addon_name = '') |
46 | 46 | { |
47 | - unset(self::$exporters[ $addon_name ]); |
|
47 | + unset(self::$exporters[$addon_name]); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 |
@@ -12,51 +12,51 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Register_Personal_Data_Exporter implements EEI_Plugin_API |
14 | 14 | { |
15 | - /** |
|
16 | - * FQCN for all privacy policy generators |
|
17 | - * |
|
18 | - * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | - */ |
|
20 | - protected static $exporters = []; |
|
15 | + /** |
|
16 | + * FQCN for all privacy policy generators |
|
17 | + * |
|
18 | + * @var array keys are plugin_ids, and values are an array of FQCNs or FQCNs |
|
19 | + */ |
|
20 | + protected static $exporters = []; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param string $addon_name |
|
25 | - * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | - * OR fully qualified class names of privacy policies |
|
27 | - * @return bool |
|
28 | - */ |
|
29 | - public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | - { |
|
31 | - self::$exporters[ $addon_name ] = $setup_args; |
|
32 | - // add to list of modules to be registered |
|
33 | - add_filter( |
|
34 | - 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
|
35 | - ['EE_Register_Personal_Data_Exporter', 'addExporters'] |
|
36 | - ); |
|
37 | - return true; |
|
38 | - } |
|
23 | + /** |
|
24 | + * @param string $addon_name |
|
25 | + * @param array $setup_args can be the fully qualified namespaces each containing only privacy policies, |
|
26 | + * OR fully qualified class names of privacy policies |
|
27 | + * @return bool |
|
28 | + */ |
|
29 | + public static function register(string $addon_name = '', array $setup_args = []): bool |
|
30 | + { |
|
31 | + self::$exporters[ $addon_name ] = $setup_args; |
|
32 | + // add to list of modules to be registered |
|
33 | + add_filter( |
|
34 | + 'FHEE__EventEspresso_core_services_privacy_export_PersonalDataExporterManager__exporters', |
|
35 | + ['EE_Register_Personal_Data_Exporter', 'addExporters'] |
|
36 | + ); |
|
37 | + return true; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @param string $addon_name |
|
43 | - */ |
|
44 | - public static function deregister(string $addon_name = '') |
|
45 | - { |
|
46 | - unset(self::$exporters[ $addon_name ]); |
|
47 | - } |
|
41 | + /** |
|
42 | + * @param string $addon_name |
|
43 | + */ |
|
44 | + public static function deregister(string $addon_name = '') |
|
45 | + { |
|
46 | + unset(self::$exporters[ $addon_name ]); |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * Adds our personal data exporters registered by add-ons |
|
52 | - * |
|
53 | - * @param string[] $exporters |
|
54 | - * @return string[] |
|
55 | - */ |
|
56 | - public static function addExporters(array $exporters): array |
|
57 | - { |
|
58 | - return array_merge($exporters, ...self::$exporters); |
|
59 | - } |
|
50 | + /** |
|
51 | + * Adds our personal data exporters registered by add-ons |
|
52 | + * |
|
53 | + * @param string[] $exporters |
|
54 | + * @return string[] |
|
55 | + */ |
|
56 | + public static function addExporters(array $exporters): array |
|
57 | + { |
|
58 | + return array_merge($exporters, ...self::$exporters); |
|
59 | + } |
|
60 | 60 | } |
61 | 61 | // End of file EE_Register_Personal_Data_Exporter.lib.php |
62 | 62 | // Location: ${NAMESPACE}/EE_Register_Personal_Data_Exporter.lib.php |