@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function __construct(EEM_Form_Element $form_element_model) |
36 | 36 | { |
37 | - $this->setName($this->namespace . 'FormElement'); |
|
37 | + $this->setName($this->namespace.'FormElement'); |
|
38 | 38 | $this->setDescription(__('A form element', 'event_espresso')); |
39 | 39 | $this->setIsCustomPostType(false); |
40 | 40 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | ), |
134 | 134 | new GraphQLField( |
135 | 135 | 'status', |
136 | - $this->namespace . 'FormStatusEnum', |
|
136 | + $this->namespace.'FormStatusEnum', |
|
137 | 137 | 'status', |
138 | 138 | esc_html__( |
139 | 139 | 'Whether form element is active, archived, trashed, or used as a default on new forms.', |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | ), |
143 | 143 | new GraphQLField( |
144 | 144 | 'type', |
145 | - $this->namespace . 'ElementTypeEnum', |
|
145 | + $this->namespace.'ElementTypeEnum', |
|
146 | 146 | 'type', |
147 | 147 | esc_html__('Form element type.', 'event_espresso') |
148 | 148 | ), |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | { |
181 | 181 | // Register mutation to update an entity. |
182 | 182 | register_graphql_mutation( |
183 | - 'update' . $this->name(), |
|
183 | + 'update'.$this->name(), |
|
184 | 184 | [ |
185 | 185 | 'inputFields' => $inputFields, |
186 | 186 | 'outputFields' => [ |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | ); |
195 | 195 | // Register mutation to delete an entity. |
196 | 196 | register_graphql_mutation( |
197 | - 'delete' . $this->name(), |
|
197 | + 'delete'.$this->name(), |
|
198 | 198 | [ |
199 | 199 | 'inputFields' => [ |
200 | 200 | 'id' => $inputFields['id'], |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | lcfirst($this->name()) => [ |
204 | 204 | 'type' => $this->name(), |
205 | 205 | 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
206 | - 'resolve' => static function ($payload) { |
|
206 | + 'resolve' => static function($payload) { |
|
207 | 207 | $deleted = (object) $payload['deleted']; |
208 | 208 | |
209 | 209 | return ! empty($deleted) ? $deleted : null; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | |
221 | 221 | // Register mutation to update an entity. |
222 | 222 | register_graphql_mutation( |
223 | - 'create' . $this->name(), |
|
223 | + 'create'.$this->name(), |
|
224 | 224 | [ |
225 | 225 | 'inputFields' => $inputFields, |
226 | 226 | 'outputFields' => [ |
@@ -26,210 +26,210 @@ |
||
26 | 26 | */ |
27 | 27 | class FormElement extends TypeBase |
28 | 28 | { |
29 | - /** |
|
30 | - * FormElement constructor. |
|
31 | - * |
|
32 | - * @param EEM_Form_Element $form_element_model |
|
33 | - */ |
|
34 | - public function __construct(EEM_Form_Element $form_element_model) |
|
35 | - { |
|
36 | - $this->setName($this->namespace . 'FormElement'); |
|
37 | - $this->setDescription(__('A form element', 'event_espresso')); |
|
38 | - $this->setIsCustomPostType(false); |
|
29 | + /** |
|
30 | + * FormElement constructor. |
|
31 | + * |
|
32 | + * @param EEM_Form_Element $form_element_model |
|
33 | + */ |
|
34 | + public function __construct(EEM_Form_Element $form_element_model) |
|
35 | + { |
|
36 | + $this->setName($this->namespace . 'FormElement'); |
|
37 | + $this->setDescription(__('A form element', 'event_espresso')); |
|
38 | + $this->setIsCustomPostType(false); |
|
39 | 39 | |
40 | - parent::__construct($form_element_model); |
|
41 | - } |
|
40 | + parent::__construct($form_element_model); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @return GraphQLFieldInterface[] |
|
46 | - */ |
|
47 | - public function getFields() |
|
48 | - { |
|
49 | - $fields = [ |
|
50 | - new GraphQLField( |
|
51 | - 'id', |
|
52 | - ['non_null' => 'ID'], |
|
53 | - null, |
|
54 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | - ), |
|
56 | - new GraphQLField( |
|
57 | - 'adminOnly', |
|
58 | - 'Boolean', |
|
59 | - 'adminOnly', |
|
60 | - esc_html__( |
|
61 | - 'Whether or not the element is only displayed in the admin. If false, input will appear in public forms', |
|
62 | - 'event_espresso' |
|
63 | - ) |
|
64 | - ), |
|
65 | - new GraphQLField( |
|
66 | - 'attributes', |
|
67 | - 'String', |
|
68 | - 'attributes', |
|
69 | - esc_html__( |
|
70 | - 'JSON string of HTML attributes such as class, max, min, placeholder, type, etc.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - [$this, 'toJson'] |
|
74 | - ), |
|
75 | - new GraphQLField( |
|
76 | - 'belongsTo', |
|
77 | - 'String', |
|
78 | - 'belongsTo', |
|
79 | - esc_html__('UUID of parent form section this form element belongs to.', 'event_espresso') |
|
80 | - ), |
|
81 | - new GraphQLField( |
|
82 | - 'helpText', |
|
83 | - 'String', |
|
84 | - 'helpText', |
|
85 | - esc_html__( |
|
86 | - "JSON string of properties pertaining to any help text required for an input.", |
|
87 | - 'event_espresso' |
|
88 | - ), |
|
89 | - [$this, 'toJson'] |
|
90 | - ), |
|
91 | - new GraphQLField( |
|
92 | - 'label', |
|
93 | - 'String', |
|
94 | - 'label', |
|
95 | - esc_html__( |
|
96 | - 'JSON string of properties pertaining to an element\'s label.', |
|
97 | - 'event_espresso' |
|
98 | - ), |
|
99 | - [$this, 'toJson'] |
|
100 | - ), |
|
101 | - new GraphQLField( |
|
102 | - 'mapsTo', |
|
103 | - 'String', |
|
104 | - 'mapsTo', |
|
105 | - esc_html__("Model and Fields name that this element maps to; ex: Attendee.email", 'event_espresso') |
|
106 | - ), |
|
107 | - new GraphQLField( |
|
108 | - 'options', |
|
109 | - 'String', |
|
110 | - 'options', |
|
111 | - esc_html__( |
|
112 | - "JSON string of options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc.", |
|
113 | - 'event_espresso' |
|
114 | - ), |
|
115 | - [$this, 'toJson'] |
|
116 | - ), |
|
117 | - new GraphQLField( |
|
118 | - 'order', |
|
119 | - 'Int', |
|
120 | - 'order', |
|
121 | - esc_html__('Order in which form element appears in a form.', 'event_espresso') |
|
122 | - ), |
|
123 | - new GraphQLField( |
|
124 | - 'required', |
|
125 | - 'String', |
|
126 | - 'required', |
|
127 | - esc_html__( |
|
128 | - "properties pertaining to an input\'s required status and the validation text to display.", |
|
129 | - 'event_espresso' |
|
130 | - ), |
|
131 | - [$this, 'toJson'] |
|
132 | - ), |
|
133 | - new GraphQLField( |
|
134 | - 'status', |
|
135 | - $this->namespace . 'FormStatusEnum', |
|
136 | - 'status', |
|
137 | - esc_html__( |
|
138 | - 'Whether form element is active, archived, trashed, or used as a default on new forms.', |
|
139 | - 'event_espresso' |
|
140 | - ) |
|
141 | - ), |
|
142 | - new GraphQLField( |
|
143 | - 'type', |
|
144 | - $this->namespace . 'ElementTypeEnum', |
|
145 | - 'type', |
|
146 | - esc_html__('Form element type.', 'event_espresso') |
|
147 | - ), |
|
148 | - new GraphQLOutputField( |
|
149 | - 'wpUser', |
|
150 | - 'User', |
|
151 | - null, |
|
152 | - esc_html__('WP User that created this form element.', 'event_espresso') |
|
153 | - ), |
|
154 | - new GraphQLInputField( |
|
155 | - 'wpUser', |
|
156 | - 'ID', |
|
157 | - null, |
|
158 | - esc_html__('ID of the WP User that created the form element.', 'event_espresso') |
|
159 | - ), |
|
160 | - ]; |
|
44 | + /** |
|
45 | + * @return GraphQLFieldInterface[] |
|
46 | + */ |
|
47 | + public function getFields() |
|
48 | + { |
|
49 | + $fields = [ |
|
50 | + new GraphQLField( |
|
51 | + 'id', |
|
52 | + ['non_null' => 'ID'], |
|
53 | + null, |
|
54 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | + ), |
|
56 | + new GraphQLField( |
|
57 | + 'adminOnly', |
|
58 | + 'Boolean', |
|
59 | + 'adminOnly', |
|
60 | + esc_html__( |
|
61 | + 'Whether or not the element is only displayed in the admin. If false, input will appear in public forms', |
|
62 | + 'event_espresso' |
|
63 | + ) |
|
64 | + ), |
|
65 | + new GraphQLField( |
|
66 | + 'attributes', |
|
67 | + 'String', |
|
68 | + 'attributes', |
|
69 | + esc_html__( |
|
70 | + 'JSON string of HTML attributes such as class, max, min, placeholder, type, etc.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + [$this, 'toJson'] |
|
74 | + ), |
|
75 | + new GraphQLField( |
|
76 | + 'belongsTo', |
|
77 | + 'String', |
|
78 | + 'belongsTo', |
|
79 | + esc_html__('UUID of parent form section this form element belongs to.', 'event_espresso') |
|
80 | + ), |
|
81 | + new GraphQLField( |
|
82 | + 'helpText', |
|
83 | + 'String', |
|
84 | + 'helpText', |
|
85 | + esc_html__( |
|
86 | + "JSON string of properties pertaining to any help text required for an input.", |
|
87 | + 'event_espresso' |
|
88 | + ), |
|
89 | + [$this, 'toJson'] |
|
90 | + ), |
|
91 | + new GraphQLField( |
|
92 | + 'label', |
|
93 | + 'String', |
|
94 | + 'label', |
|
95 | + esc_html__( |
|
96 | + 'JSON string of properties pertaining to an element\'s label.', |
|
97 | + 'event_espresso' |
|
98 | + ), |
|
99 | + [$this, 'toJson'] |
|
100 | + ), |
|
101 | + new GraphQLField( |
|
102 | + 'mapsTo', |
|
103 | + 'String', |
|
104 | + 'mapsTo', |
|
105 | + esc_html__("Model and Fields name that this element maps to; ex: Attendee.email", 'event_espresso') |
|
106 | + ), |
|
107 | + new GraphQLField( |
|
108 | + 'options', |
|
109 | + 'String', |
|
110 | + 'options', |
|
111 | + esc_html__( |
|
112 | + "JSON string of options for ENUM type inputs like checkboxes, radio buttons, select inputs, etc.", |
|
113 | + 'event_espresso' |
|
114 | + ), |
|
115 | + [$this, 'toJson'] |
|
116 | + ), |
|
117 | + new GraphQLField( |
|
118 | + 'order', |
|
119 | + 'Int', |
|
120 | + 'order', |
|
121 | + esc_html__('Order in which form element appears in a form.', 'event_espresso') |
|
122 | + ), |
|
123 | + new GraphQLField( |
|
124 | + 'required', |
|
125 | + 'String', |
|
126 | + 'required', |
|
127 | + esc_html__( |
|
128 | + "properties pertaining to an input\'s required status and the validation text to display.", |
|
129 | + 'event_espresso' |
|
130 | + ), |
|
131 | + [$this, 'toJson'] |
|
132 | + ), |
|
133 | + new GraphQLField( |
|
134 | + 'status', |
|
135 | + $this->namespace . 'FormStatusEnum', |
|
136 | + 'status', |
|
137 | + esc_html__( |
|
138 | + 'Whether form element is active, archived, trashed, or used as a default on new forms.', |
|
139 | + 'event_espresso' |
|
140 | + ) |
|
141 | + ), |
|
142 | + new GraphQLField( |
|
143 | + 'type', |
|
144 | + $this->namespace . 'ElementTypeEnum', |
|
145 | + 'type', |
|
146 | + esc_html__('Form element type.', 'event_espresso') |
|
147 | + ), |
|
148 | + new GraphQLOutputField( |
|
149 | + 'wpUser', |
|
150 | + 'User', |
|
151 | + null, |
|
152 | + esc_html__('WP User that created this form element.', 'event_espresso') |
|
153 | + ), |
|
154 | + new GraphQLInputField( |
|
155 | + 'wpUser', |
|
156 | + 'ID', |
|
157 | + null, |
|
158 | + esc_html__('ID of the WP User that created the form element.', 'event_espresso') |
|
159 | + ), |
|
160 | + ]; |
|
161 | 161 | |
162 | - return apply_filters( |
|
163 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__form_element_fields', |
|
164 | - $fields, |
|
165 | - $this->name, |
|
166 | - $this->model |
|
167 | - ); |
|
168 | - } |
|
162 | + return apply_filters( |
|
163 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__form_element_fields', |
|
164 | + $fields, |
|
165 | + $this->name, |
|
166 | + $this->model |
|
167 | + ); |
|
168 | + } |
|
169 | 169 | |
170 | 170 | |
171 | - /** |
|
172 | - * @param array $inputFields The mutation input fields. |
|
173 | - * @throws InvalidArgumentException |
|
174 | - * @throws ReflectionException |
|
175 | - * @throws Exception |
|
176 | - * @since $VID:$ |
|
177 | - */ |
|
178 | - public function registerMutations($inputFields) |
|
179 | - { |
|
180 | - // Register mutation to update an entity. |
|
181 | - register_graphql_mutation( |
|
182 | - 'update' . $this->name(), |
|
183 | - [ |
|
184 | - 'inputFields' => $inputFields, |
|
185 | - 'outputFields' => [ |
|
186 | - lcfirst($this->name()) => [ |
|
187 | - 'type' => $this->name(), |
|
188 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
189 | - ], |
|
190 | - ], |
|
191 | - 'mutateAndGetPayload' => FormElementUpdate::mutateAndGetPayload($this->model), |
|
192 | - ] |
|
193 | - ); |
|
194 | - // Register mutation to delete an entity. |
|
195 | - register_graphql_mutation( |
|
196 | - 'delete' . $this->name(), |
|
197 | - [ |
|
198 | - 'inputFields' => [ |
|
199 | - 'id' => $inputFields['id'], |
|
200 | - ], |
|
201 | - 'outputFields' => [ |
|
202 | - lcfirst($this->name()) => [ |
|
203 | - 'type' => $this->name(), |
|
204 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
205 | - 'resolve' => static function ($payload) { |
|
206 | - $deleted = (object) $payload['deleted']; |
|
171 | + /** |
|
172 | + * @param array $inputFields The mutation input fields. |
|
173 | + * @throws InvalidArgumentException |
|
174 | + * @throws ReflectionException |
|
175 | + * @throws Exception |
|
176 | + * @since $VID:$ |
|
177 | + */ |
|
178 | + public function registerMutations($inputFields) |
|
179 | + { |
|
180 | + // Register mutation to update an entity. |
|
181 | + register_graphql_mutation( |
|
182 | + 'update' . $this->name(), |
|
183 | + [ |
|
184 | + 'inputFields' => $inputFields, |
|
185 | + 'outputFields' => [ |
|
186 | + lcfirst($this->name()) => [ |
|
187 | + 'type' => $this->name(), |
|
188 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
189 | + ], |
|
190 | + ], |
|
191 | + 'mutateAndGetPayload' => FormElementUpdate::mutateAndGetPayload($this->model), |
|
192 | + ] |
|
193 | + ); |
|
194 | + // Register mutation to delete an entity. |
|
195 | + register_graphql_mutation( |
|
196 | + 'delete' . $this->name(), |
|
197 | + [ |
|
198 | + 'inputFields' => [ |
|
199 | + 'id' => $inputFields['id'], |
|
200 | + ], |
|
201 | + 'outputFields' => [ |
|
202 | + lcfirst($this->name()) => [ |
|
203 | + 'type' => $this->name(), |
|
204 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
205 | + 'resolve' => static function ($payload) { |
|
206 | + $deleted = (object) $payload['deleted']; |
|
207 | 207 | |
208 | - return ! empty($deleted) ? $deleted : null; |
|
209 | - }, |
|
210 | - ], |
|
211 | - ], |
|
212 | - 'mutateAndGetPayload' => FormElementDelete::mutateAndGetPayload($this->model), |
|
213 | - ] |
|
214 | - ); |
|
208 | + return ! empty($deleted) ? $deleted : null; |
|
209 | + }, |
|
210 | + ], |
|
211 | + ], |
|
212 | + 'mutateAndGetPayload' => FormElementDelete::mutateAndGetPayload($this->model), |
|
213 | + ] |
|
214 | + ); |
|
215 | 215 | |
216 | - // Make element 'type' a required field for create mutations |
|
217 | - // Yes it's "['type']['type']" |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function __construct(EEM_Form_Section $form_section_model) |
36 | 36 | { |
37 | - $this->setName($this->namespace . 'FormSection'); |
|
37 | + $this->setName($this->namespace.'FormSection'); |
|
38 | 38 | $this->setDescription(__('A form section', 'event_espresso')); |
39 | 39 | $this->setIsCustomPostType(false); |
40 | 40 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | ), |
57 | 57 | new GraphQLField( |
58 | 58 | 'appliesTo', |
59 | - $this->namespace . 'FormSectionAppliesToEnum', |
|
59 | + $this->namespace.'FormSectionAppliesToEnum', |
|
60 | 60 | 'appliesTo', |
61 | 61 | esc_html__('Form user type that this form section should be presented to.', 'event_espresso') |
62 | 62 | ), |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | ), |
95 | 95 | new GraphQLField( |
96 | 96 | 'status', |
97 | - $this->namespace . 'FormStatusEnum', |
|
97 | + $this->namespace.'FormStatusEnum', |
|
98 | 98 | 'status', |
99 | 99 | esc_html__( |
100 | 100 | 'Whether form section is active, archived, shared, trashed, or used as a default on new forms.', |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | { |
136 | 136 | // Register mutation to update an entity. |
137 | 137 | register_graphql_mutation( |
138 | - 'update' . $this->name(), |
|
138 | + 'update'.$this->name(), |
|
139 | 139 | [ |
140 | 140 | 'inputFields' => $inputFields, |
141 | 141 | 'outputFields' => [ |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | ); |
150 | 150 | // Register mutation to delete an entity. |
151 | 151 | register_graphql_mutation( |
152 | - 'delete' . $this->name(), |
|
152 | + 'delete'.$this->name(), |
|
153 | 153 | [ |
154 | 154 | 'inputFields' => [ |
155 | 155 | 'id' => $inputFields['id'], |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | lcfirst($this->name()) => [ |
159 | 159 | 'type' => $this->name(), |
160 | 160 | 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
161 | - 'resolve' => static function ($payload) { |
|
161 | + 'resolve' => static function($payload) { |
|
162 | 162 | $deleted = (object) $payload['deleted']; |
163 | 163 | |
164 | 164 | return ! empty($deleted) ? $deleted : null; |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | |
172 | 172 | // Register mutation to update an entity. |
173 | 173 | register_graphql_mutation( |
174 | - 'create' . $this->name(), |
|
174 | + 'create'.$this->name(), |
|
175 | 175 | [ |
176 | 176 | 'inputFields' => $inputFields, |
177 | 177 | 'outputFields' => [ |
@@ -26,191 +26,191 @@ |
||
26 | 26 | */ |
27 | 27 | class FormSection extends TypeBase |
28 | 28 | { |
29 | - /** |
|
30 | - * FormSection constructor. |
|
31 | - * |
|
32 | - * @param EEM_Form_Section $form_section_model |
|
33 | - */ |
|
34 | - public function __construct(EEM_Form_Section $form_section_model) |
|
35 | - { |
|
36 | - $this->setName($this->namespace . 'FormSection'); |
|
37 | - $this->setDescription(__('A form section', 'event_espresso')); |
|
38 | - $this->setIsCustomPostType(false); |
|
29 | + /** |
|
30 | + * FormSection constructor. |
|
31 | + * |
|
32 | + * @param EEM_Form_Section $form_section_model |
|
33 | + */ |
|
34 | + public function __construct(EEM_Form_Section $form_section_model) |
|
35 | + { |
|
36 | + $this->setName($this->namespace . 'FormSection'); |
|
37 | + $this->setDescription(__('A form section', 'event_espresso')); |
|
38 | + $this->setIsCustomPostType(false); |
|
39 | 39 | |
40 | - parent::__construct($form_section_model); |
|
41 | - } |
|
40 | + parent::__construct($form_section_model); |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @return GraphQLFieldInterface[] |
|
46 | - */ |
|
47 | - public function getFields() |
|
48 | - { |
|
49 | - $fields = [ |
|
50 | - new GraphQLField( |
|
51 | - 'id', |
|
52 | - ['non_null' => 'ID'], |
|
53 | - null, |
|
54 | - esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | - ), |
|
56 | - new GraphQLField( |
|
57 | - 'appliesTo', |
|
58 | - $this->namespace . 'FormSectionAppliesToEnum', |
|
59 | - 'appliesTo', |
|
60 | - esc_html__('Form user type that this form section should be presented to.', 'event_espresso') |
|
61 | - ), |
|
62 | - new GraphQLField( |
|
63 | - 'attributes', |
|
64 | - 'String', |
|
65 | - 'attributes', |
|
66 | - esc_html__( |
|
67 | - 'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.', |
|
68 | - 'event_espresso' |
|
69 | - ), |
|
70 | - [$this, 'toJson'] |
|
71 | - ), |
|
72 | - new GraphQLField( |
|
73 | - 'belongsTo', |
|
74 | - 'String', |
|
75 | - 'belongsTo', |
|
76 | - esc_html__('UUID or ID of related entity this form section belongs to.', 'event_espresso') |
|
77 | - ), |
|
78 | - new GraphQLOutputField( |
|
79 | - 'isActive', |
|
80 | - 'Boolean', |
|
81 | - 'isActive', |
|
82 | - esc_html__('Flag indicating whether the section is active.', 'event_espresso') |
|
83 | - ), |
|
84 | - new GraphQLOutputField( |
|
85 | - 'isArchived', |
|
86 | - 'Boolean', |
|
87 | - 'isArchived', |
|
88 | - esc_html__('Flag indicating whether the section is archived.', 'event_espresso') |
|
89 | - ), |
|
90 | - new GraphQLOutputField( |
|
91 | - 'isDefault', |
|
92 | - 'Boolean', |
|
93 | - 'isDefault', |
|
94 | - esc_html__('Flag indicating whether the section is a default one.', 'event_espresso') |
|
95 | - ), |
|
96 | - new GraphQLOutputField( |
|
97 | - 'isShared', |
|
98 | - 'Boolean', |
|
99 | - 'isShared', |
|
100 | - esc_html__('Flag indicating whether the section is a shared one.', 'event_espresso') |
|
101 | - ), |
|
102 | - new GraphQLOutputField( |
|
103 | - 'isTrashed', |
|
104 | - 'Boolean', |
|
105 | - 'isTrashed', |
|
106 | - esc_html__('Flag indicating whether the section is trashed.', 'event_espresso') |
|
107 | - ), |
|
108 | - new GraphQLField( |
|
109 | - 'label', |
|
110 | - 'String', |
|
111 | - 'label', |
|
112 | - esc_html__( |
|
113 | - 'JSON string of properties pertaining to a form section\'s label.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - [$this, 'toJson'] |
|
117 | - ), |
|
118 | - new GraphQLField( |
|
119 | - 'order', |
|
120 | - 'Int', |
|
121 | - 'order', |
|
122 | - esc_html__('Order in which form section appears in a form.', 'event_espresso') |
|
123 | - ), |
|
124 | - new GraphQLField( |
|
125 | - 'status', |
|
126 | - $this->namespace . 'FormStatusEnum', |
|
127 | - 'status', |
|
128 | - esc_html__( |
|
129 | - 'Whether form section is active, archived, shared, trashed, or used as a default on new forms.', |
|
130 | - 'event_espresso' |
|
131 | - ) |
|
132 | - ), |
|
133 | - new GraphQLOutputField( |
|
134 | - 'wpUser', |
|
135 | - 'User', |
|
136 | - null, |
|
137 | - esc_html__('WP User that created this form section.', 'event_espresso') |
|
138 | - ), |
|
139 | - new GraphQLInputField( |
|
140 | - 'wpUser', |
|
141 | - 'ID', |
|
142 | - null, |
|
143 | - esc_html__('ID of the WP User that created the form section.', 'event_espresso') |
|
144 | - ), |
|
145 | - ]; |
|
44 | + /** |
|
45 | + * @return GraphQLFieldInterface[] |
|
46 | + */ |
|
47 | + public function getFields() |
|
48 | + { |
|
49 | + $fields = [ |
|
50 | + new GraphQLField( |
|
51 | + 'id', |
|
52 | + ['non_null' => 'ID'], |
|
53 | + null, |
|
54 | + esc_html__('The globally unique ID for the object.', 'event_espresso') |
|
55 | + ), |
|
56 | + new GraphQLField( |
|
57 | + 'appliesTo', |
|
58 | + $this->namespace . 'FormSectionAppliesToEnum', |
|
59 | + 'appliesTo', |
|
60 | + esc_html__('Form user type that this form section should be presented to.', 'event_espresso') |
|
61 | + ), |
|
62 | + new GraphQLField( |
|
63 | + 'attributes', |
|
64 | + 'String', |
|
65 | + 'attributes', |
|
66 | + esc_html__( |
|
67 | + 'JSON string of HTML attributes, such as class, to be applied to this form section\'s container.', |
|
68 | + 'event_espresso' |
|
69 | + ), |
|
70 | + [$this, 'toJson'] |
|
71 | + ), |
|
72 | + new GraphQLField( |
|
73 | + 'belongsTo', |
|
74 | + 'String', |
|
75 | + 'belongsTo', |
|
76 | + esc_html__('UUID or ID of related entity this form section belongs to.', 'event_espresso') |
|
77 | + ), |
|
78 | + new GraphQLOutputField( |
|
79 | + 'isActive', |
|
80 | + 'Boolean', |
|
81 | + 'isActive', |
|
82 | + esc_html__('Flag indicating whether the section is active.', 'event_espresso') |
|
83 | + ), |
|
84 | + new GraphQLOutputField( |
|
85 | + 'isArchived', |
|
86 | + 'Boolean', |
|
87 | + 'isArchived', |
|
88 | + esc_html__('Flag indicating whether the section is archived.', 'event_espresso') |
|
89 | + ), |
|
90 | + new GraphQLOutputField( |
|
91 | + 'isDefault', |
|
92 | + 'Boolean', |
|
93 | + 'isDefault', |
|
94 | + esc_html__('Flag indicating whether the section is a default one.', 'event_espresso') |
|
95 | + ), |
|
96 | + new GraphQLOutputField( |
|
97 | + 'isShared', |
|
98 | + 'Boolean', |
|
99 | + 'isShared', |
|
100 | + esc_html__('Flag indicating whether the section is a shared one.', 'event_espresso') |
|
101 | + ), |
|
102 | + new GraphQLOutputField( |
|
103 | + 'isTrashed', |
|
104 | + 'Boolean', |
|
105 | + 'isTrashed', |
|
106 | + esc_html__('Flag indicating whether the section is trashed.', 'event_espresso') |
|
107 | + ), |
|
108 | + new GraphQLField( |
|
109 | + 'label', |
|
110 | + 'String', |
|
111 | + 'label', |
|
112 | + esc_html__( |
|
113 | + 'JSON string of properties pertaining to a form section\'s label.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + [$this, 'toJson'] |
|
117 | + ), |
|
118 | + new GraphQLField( |
|
119 | + 'order', |
|
120 | + 'Int', |
|
121 | + 'order', |
|
122 | + esc_html__('Order in which form section appears in a form.', 'event_espresso') |
|
123 | + ), |
|
124 | + new GraphQLField( |
|
125 | + 'status', |
|
126 | + $this->namespace . 'FormStatusEnum', |
|
127 | + 'status', |
|
128 | + esc_html__( |
|
129 | + 'Whether form section is active, archived, shared, trashed, or used as a default on new forms.', |
|
130 | + 'event_espresso' |
|
131 | + ) |
|
132 | + ), |
|
133 | + new GraphQLOutputField( |
|
134 | + 'wpUser', |
|
135 | + 'User', |
|
136 | + null, |
|
137 | + esc_html__('WP User that created this form section.', 'event_espresso') |
|
138 | + ), |
|
139 | + new GraphQLInputField( |
|
140 | + 'wpUser', |
|
141 | + 'ID', |
|
142 | + null, |
|
143 | + esc_html__('ID of the WP User that created the form section.', 'event_espresso') |
|
144 | + ), |
|
145 | + ]; |
|
146 | 146 | |
147 | - return apply_filters( |
|
148 | - 'FHEE__EventEspresso_core_domain_services_graphql_types__form_section_fields', |
|
149 | - $fields, |
|
150 | - $this->name, |
|
151 | - $this->model |
|
152 | - ); |
|
153 | - } |
|
147 | + return apply_filters( |
|
148 | + 'FHEE__EventEspresso_core_domain_services_graphql_types__form_section_fields', |
|
149 | + $fields, |
|
150 | + $this->name, |
|
151 | + $this->model |
|
152 | + ); |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * @param array $inputFields The mutation input fields. |
|
158 | - * @throws InvalidArgumentException |
|
159 | - * @throws ReflectionException |
|
160 | - * @throws Exception |
|
161 | - * @since $VID:$ |
|
162 | - */ |
|
163 | - public function registerMutations($inputFields) |
|
164 | - { |
|
165 | - // Register mutation to update an entity. |
|
166 | - register_graphql_mutation( |
|
167 | - 'update' . $this->name(), |
|
168 | - [ |
|
169 | - 'inputFields' => $inputFields, |
|
170 | - 'outputFields' => [ |
|
171 | - lcfirst($this->name()) => [ |
|
172 | - 'type' => $this->name(), |
|
173 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
174 | - ], |
|
175 | - ], |
|
176 | - 'mutateAndGetPayload' => FormSectionUpdate::mutateAndGetPayload($this->model), |
|
177 | - ] |
|
178 | - ); |
|
179 | - // Register mutation to delete an entity. |
|
180 | - register_graphql_mutation( |
|
181 | - 'delete' . $this->name(), |
|
182 | - [ |
|
183 | - 'inputFields' => [ |
|
184 | - 'id' => $inputFields['id'], |
|
185 | - ], |
|
186 | - 'outputFields' => [ |
|
187 | - lcfirst($this->name()) => [ |
|
188 | - 'type' => $this->name(), |
|
189 | - 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
190 | - 'resolve' => static function ($payload) { |
|
191 | - $deleted = (object) $payload['deleted']; |
|
156 | + /** |
|
157 | + * @param array $inputFields The mutation input fields. |
|
158 | + * @throws InvalidArgumentException |
|
159 | + * @throws ReflectionException |
|
160 | + * @throws Exception |
|
161 | + * @since $VID:$ |
|
162 | + */ |
|
163 | + public function registerMutations($inputFields) |
|
164 | + { |
|
165 | + // Register mutation to update an entity. |
|
166 | + register_graphql_mutation( |
|
167 | + 'update' . $this->name(), |
|
168 | + [ |
|
169 | + 'inputFields' => $inputFields, |
|
170 | + 'outputFields' => [ |
|
171 | + lcfirst($this->name()) => [ |
|
172 | + 'type' => $this->name(), |
|
173 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
174 | + ], |
|
175 | + ], |
|
176 | + 'mutateAndGetPayload' => FormSectionUpdate::mutateAndGetPayload($this->model), |
|
177 | + ] |
|
178 | + ); |
|
179 | + // Register mutation to delete an entity. |
|
180 | + register_graphql_mutation( |
|
181 | + 'delete' . $this->name(), |
|
182 | + [ |
|
183 | + 'inputFields' => [ |
|
184 | + 'id' => $inputFields['id'], |
|
185 | + ], |
|
186 | + 'outputFields' => [ |
|
187 | + lcfirst($this->name()) => [ |
|
188 | + 'type' => $this->name(), |
|
189 | + 'description' => esc_html__('The object before it was deleted', 'event_espresso'), |
|
190 | + 'resolve' => static function ($payload) { |
|
191 | + $deleted = (object) $payload['deleted']; |
|
192 | 192 | |
193 | - return ! empty($deleted) ? $deleted : null; |
|
194 | - }, |
|
195 | - ], |
|
196 | - ], |
|
197 | - 'mutateAndGetPayload' => FormSectionDelete::mutateAndGetPayload($this->model), |
|
198 | - ] |
|
199 | - ); |
|
193 | + return ! empty($deleted) ? $deleted : null; |
|
194 | + }, |
|
195 | + ], |
|
196 | + ], |
|
197 | + 'mutateAndGetPayload' => FormSectionDelete::mutateAndGetPayload($this->model), |
|
198 | + ] |
|
199 | + ); |
|
200 | 200 | |
201 | - // Register mutation to update an entity. |
|
202 | - register_graphql_mutation( |
|
203 | - 'create' . $this->name(), |
|
204 | - [ |
|
205 | - 'inputFields' => $inputFields, |
|
206 | - 'outputFields' => [ |
|
207 | - lcfirst($this->name()) => [ |
|
208 | - 'type' => $this->name(), |
|
209 | - 'resolve' => [$this, 'resolveFromPayload'], |
|
210 | - ], |
|
211 | - ], |
|
212 | - 'mutateAndGetPayload' => FormSectionCreate::mutateAndGetPayload($this->model), |
|
213 | - ] |
|
214 | - ); |
|
215 | - } |
|
201 | + // Register mutation to update an entity. |
|
202 | + register_graphql_mutation( |
|
203 | + 'create' . $this->name(), |
|
204 | + [ |
|
205 | + 'inputFields' => $inputFields, |
|
206 | + 'outputFields' => [ |
|
207 | + lcfirst($this->name()) => [ |
|
208 | + 'type' => $this->name(), |
|
209 | + 'resolve' => [$this, 'resolveFromPayload'], |
|
210 | + ], |
|
211 | + ], |
|
212 | + 'mutateAndGetPayload' => FormSectionCreate::mutateAndGetPayload($this->model), |
|
213 | + ] |
|
214 | + ); |
|
215 | + } |
|
216 | 216 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | */ |
94 | 94 | public function get_table_name() |
95 | 95 | { |
96 | - return $this->get_table_prefix() . $this->_table_name; |
|
96 | + return $this->get_table_prefix().$this->_table_name; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function get_table_alias() |
107 | 107 | { |
108 | - if (! $this->_table_alias) { |
|
108 | + if ( ! $this->_table_alias) { |
|
109 | 109 | throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
110 | 110 | } |
111 | 111 | return $this->_table_alias; |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | */ |
129 | 129 | public function get_fully_qualified_pk_column() |
130 | 130 | { |
131 | - return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
131 | + return $this->get_table_alias().".".$this->get_pk_column(); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function get_select_join_limit($limit) |
141 | 141 | { |
142 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
143 | - return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
142 | + $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit; |
|
143 | + return SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 |
@@ -6,151 +6,151 @@ |
||
6 | 6 | */ |
7 | 7 | abstract class EE_Table_Base |
8 | 8 | { |
9 | - /** |
|
10 | - * This holds the table_name without the table prefix. |
|
11 | - * |
|
12 | - * @var string |
|
13 | - */ |
|
14 | - public $_table_name; |
|
15 | - |
|
16 | - |
|
17 | - /** |
|
18 | - * This holds what is used as the alias for the table in queries. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $_table_alias; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Table's private key column |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $_pk_column; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * Whether this table is a global table (in multisite) or specific to site. |
|
35 | - * |
|
36 | - * @var bool |
|
37 | - */ |
|
38 | - protected $_global; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * @param string $table_name with or without wpdb prefix |
|
43 | - * @param string $pk_column |
|
44 | - * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
45 | - * install, or whether each site on a multisite install has a copy of this table |
|
46 | - * @global wpdb $wpdb |
|
47 | - */ |
|
48 | - public function __construct($table_name, $pk_column, $global = false) |
|
49 | - { |
|
50 | - $this->_global = $global; |
|
51 | - $prefix = $this->get_table_prefix(); |
|
52 | - // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
53 | - if (strpos($table_name, $prefix) === 0) { |
|
54 | - $table_name = substr_replace($table_name, '', 0, strlen($prefix)); |
|
55 | - } |
|
56 | - $this->_table_name = $table_name; |
|
57 | - $this->_pk_column = $pk_column; |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * This returns the table prefix for the current model state. |
|
63 | - * |
|
64 | - * @return string |
|
65 | - * @global wpdb $wpdb |
|
66 | - */ |
|
67 | - public function get_table_prefix() |
|
68 | - { |
|
69 | - global $wpdb; |
|
70 | - if ($this->_global) { |
|
71 | - return $wpdb->base_prefix; |
|
72 | - } |
|
73 | - return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * Used to set the table_alias property |
|
79 | - * |
|
80 | - * @param string $table_alias |
|
81 | - */ |
|
82 | - public function _construct_finalize_with_alias($table_alias) |
|
83 | - { |
|
84 | - $this->_table_alias = $table_alias; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
90 | - * |
|
91 | - * @return string |
|
92 | - */ |
|
93 | - public function get_table_name() |
|
94 | - { |
|
95 | - return $this->get_table_prefix() . $this->_table_name; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Provides what is currently set as the alias for the table to be used in queries. |
|
101 | - * |
|
102 | - * @return string |
|
103 | - * @throws EE_Error |
|
104 | - */ |
|
105 | - public function get_table_alias() |
|
106 | - { |
|
107 | - if (! $this->_table_alias) { |
|
108 | - throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
109 | - } |
|
110 | - return $this->_table_alias; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return string name of column of PK |
|
116 | - */ |
|
117 | - public function get_pk_column() |
|
118 | - { |
|
119 | - return $this->_pk_column; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * returns a string with the table alias, a period, and the private key's column. |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function get_fully_qualified_pk_column() |
|
129 | - { |
|
130 | - return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * returns the special sql for a inner select with a limit. |
|
136 | - * |
|
137 | - * @return string SQL select |
|
138 | - */ |
|
139 | - public function get_select_join_limit($limit) |
|
140 | - { |
|
141 | - $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
142 | - return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Returns whether or not htis is a global table (ie, on multisite there's |
|
148 | - * only one of these tables, on the main blog) |
|
149 | - * |
|
150 | - * @return boolean |
|
151 | - */ |
|
152 | - public function is_global() |
|
153 | - { |
|
154 | - return $this->_global; |
|
155 | - } |
|
9 | + /** |
|
10 | + * This holds the table_name without the table prefix. |
|
11 | + * |
|
12 | + * @var string |
|
13 | + */ |
|
14 | + public $_table_name; |
|
15 | + |
|
16 | + |
|
17 | + /** |
|
18 | + * This holds what is used as the alias for the table in queries. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $_table_alias; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Table's private key column |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $_pk_column; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * Whether this table is a global table (in multisite) or specific to site. |
|
35 | + * |
|
36 | + * @var bool |
|
37 | + */ |
|
38 | + protected $_global; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * @param string $table_name with or without wpdb prefix |
|
43 | + * @param string $pk_column |
|
44 | + * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite |
|
45 | + * install, or whether each site on a multisite install has a copy of this table |
|
46 | + * @global wpdb $wpdb |
|
47 | + */ |
|
48 | + public function __construct($table_name, $pk_column, $global = false) |
|
49 | + { |
|
50 | + $this->_global = $global; |
|
51 | + $prefix = $this->get_table_prefix(); |
|
52 | + // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed. |
|
53 | + if (strpos($table_name, $prefix) === 0) { |
|
54 | + $table_name = substr_replace($table_name, '', 0, strlen($prefix)); |
|
55 | + } |
|
56 | + $this->_table_name = $table_name; |
|
57 | + $this->_pk_column = $pk_column; |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * This returns the table prefix for the current model state. |
|
63 | + * |
|
64 | + * @return string |
|
65 | + * @global wpdb $wpdb |
|
66 | + */ |
|
67 | + public function get_table_prefix() |
|
68 | + { |
|
69 | + global $wpdb; |
|
70 | + if ($this->_global) { |
|
71 | + return $wpdb->base_prefix; |
|
72 | + } |
|
73 | + return $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id()); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * Used to set the table_alias property |
|
79 | + * |
|
80 | + * @param string $table_alias |
|
81 | + */ |
|
82 | + public function _construct_finalize_with_alias($table_alias) |
|
83 | + { |
|
84 | + $this->_table_alias = $table_alias; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * Returns the fully qualified table name for the database (includes the table prefix current for the blog). |
|
90 | + * |
|
91 | + * @return string |
|
92 | + */ |
|
93 | + public function get_table_name() |
|
94 | + { |
|
95 | + return $this->get_table_prefix() . $this->_table_name; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Provides what is currently set as the alias for the table to be used in queries. |
|
101 | + * |
|
102 | + * @return string |
|
103 | + * @throws EE_Error |
|
104 | + */ |
|
105 | + public function get_table_alias() |
|
106 | + { |
|
107 | + if (! $this->_table_alias) { |
|
108 | + throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?"); |
|
109 | + } |
|
110 | + return $this->_table_alias; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return string name of column of PK |
|
116 | + */ |
|
117 | + public function get_pk_column() |
|
118 | + { |
|
119 | + return $this->_pk_column; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * returns a string with the table alias, a period, and the private key's column. |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function get_fully_qualified_pk_column() |
|
129 | + { |
|
130 | + return $this->get_table_alias() . "." . $this->get_pk_column(); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * returns the special sql for a inner select with a limit. |
|
136 | + * |
|
137 | + * @return string SQL select |
|
138 | + */ |
|
139 | + public function get_select_join_limit($limit) |
|
140 | + { |
|
141 | + $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit; |
|
142 | + return SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Returns whether or not htis is a global table (ie, on multisite there's |
|
148 | + * only one of these tables, on the main blog) |
|
149 | + * |
|
150 | + * @return boolean |
|
151 | + */ |
|
152 | + public function is_global() |
|
153 | + { |
|
154 | + return $this->_global; |
|
155 | + } |
|
156 | 156 | } |
@@ -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 | } |
@@ -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 | ] |
@@ -12,78 +12,78 @@ |
||
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, $slug) |
|
24 | - { |
|
25 | - $slug = (string) $slug; |
|
26 | - parent::__construct( |
|
27 | - [ |
|
28 | - 'subsections' => $this->copyAttendeeInfoInputs($registrations), |
|
29 | - 'layout_strategy' => new EE_Template_Layout( |
|
30 | - [ |
|
31 | - 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
32 | - . $slug |
|
33 | - . '/copy_attendee_info.template.php', |
|
34 | - 'begin_template_file' => null, |
|
35 | - 'input_template_file' => null, |
|
36 | - 'subsection_template_file' => null, |
|
37 | - 'end_template_file' => null, |
|
38 | - ] |
|
39 | - ), |
|
40 | - ] |
|
41 | - ); |
|
42 | - } |
|
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, $slug) |
|
24 | + { |
|
25 | + $slug = (string) $slug; |
|
26 | + parent::__construct( |
|
27 | + [ |
|
28 | + 'subsections' => $this->copyAttendeeInfoInputs($registrations), |
|
29 | + 'layout_strategy' => new EE_Template_Layout( |
|
30 | + [ |
|
31 | + 'layout_template_file' => SPCO_REG_STEPS_PATH |
|
32 | + . $slug |
|
33 | + . '/copy_attendee_info.template.php', |
|
34 | + 'begin_template_file' => null, |
|
35 | + 'input_template_file' => null, |
|
36 | + 'subsection_template_file' => null, |
|
37 | + 'end_template_file' => null, |
|
38 | + ] |
|
39 | + ), |
|
40 | + ] |
|
41 | + ); |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @param array $registrations |
|
47 | - * @return array |
|
48 | - * @throws EE_Error |
|
49 | - * @throws ReflectionException |
|
50 | - */ |
|
51 | - private function copyAttendeeInfoInputs(array $registrations) |
|
52 | - { |
|
53 | - $copy_attendee_info_inputs = []; |
|
54 | - $prev_ticket = null; |
|
55 | - foreach ($registrations as $registration) { |
|
56 | - // for all attendees other than the primary attendee |
|
57 | - if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
58 | - // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
59 | - if ($registration->ticket()->ID() !== $prev_ticket) { |
|
60 | - $item_name = $registration->ticket()->name(); |
|
61 | - $item_name .= $registration->ticket()->description() !== '' |
|
62 | - ? ' - ' . $registration->ticket()->description() |
|
63 | - : ''; |
|
64 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
65 | - = new EE_Form_Section_HTML( |
|
66 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
67 | - ); |
|
68 | - $prev_ticket = $registration->ticket()->ID(); |
|
69 | - } |
|
45 | + /** |
|
46 | + * @param array $registrations |
|
47 | + * @return array |
|
48 | + * @throws EE_Error |
|
49 | + * @throws ReflectionException |
|
50 | + */ |
|
51 | + private function copyAttendeeInfoInputs(array $registrations) |
|
52 | + { |
|
53 | + $copy_attendee_info_inputs = []; |
|
54 | + $prev_ticket = null; |
|
55 | + foreach ($registrations as $registration) { |
|
56 | + // for all attendees other than the primary attendee |
|
57 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
58 | + // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
|
59 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
60 | + $item_name = $registration->ticket()->name(); |
|
61 | + $item_name .= $registration->ticket()->description() !== '' |
|
62 | + ? ' - ' . $registration->ticket()->description() |
|
63 | + : ''; |
|
64 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] |
|
65 | + = new EE_Form_Section_HTML( |
|
66 | + '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
67 | + ); |
|
68 | + $prev_ticket = $registration->ticket()->ID(); |
|
69 | + } |
|
70 | 70 | |
71 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
72 | - = new EE_Checkbox_Multi_Input( |
|
73 | - [ |
|
74 | - $registration->ID() => sprintf( |
|
75 | - esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
76 | - $registration->count() |
|
77 | - ) |
|
78 | - ], |
|
79 | - [ |
|
80 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
81 | - 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
82 | - 'display_html_label_text' => false, |
|
83 | - ] |
|
84 | - ); |
|
85 | - } |
|
86 | - } |
|
87 | - return $copy_attendee_info_inputs; |
|
88 | - } |
|
71 | + $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] |
|
72 | + = new EE_Checkbox_Multi_Input( |
|
73 | + [ |
|
74 | + $registration->ID() => sprintf( |
|
75 | + esc_html_x('Attendee #%s', 'Attendee #123', 'event_espresso'), |
|
76 | + $registration->count() |
|
77 | + ) |
|
78 | + ], |
|
79 | + [ |
|
80 | + 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
81 | + 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
|
82 | + 'display_html_label_text' => false, |
|
83 | + ] |
|
84 | + ); |
|
85 | + } |
|
86 | + } |
|
87 | + return $copy_attendee_info_inputs; |
|
88 | + } |
|
89 | 89 | } |
@@ -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 |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $UUID = $section->UUID(); |
56 | 56 | |
57 | 57 | // Avoid duplicates, if any |
58 | - $sections[ $UUID ] = [ |
|
58 | + $sections[$UUID] = [ |
|
59 | 59 | 'id' => $UUID, |
60 | 60 | 'appliesTo' => GQLUtils::formatEnumKey($section->appliesTo()), |
61 | 61 | 'attributes' => $section->attributes()->toJson(), |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $UUID = $element->UUID(); |
86 | 86 | |
87 | 87 | // Avoid duplicates |
88 | - $elements[ $UUID ] = [ |
|
88 | + $elements[$UUID] = [ |
|
89 | 89 | 'id' => $UUID, |
90 | 90 | 'adminOnly' => $element->adminOnly(), |
91 | 91 | 'attributes' => $element->attributes()->toJson(), |
@@ -23,87 +23,87 @@ |
||
23 | 23 | */ |
24 | 24 | class FormBuilder implements EventEditorDataInterface |
25 | 25 | { |
26 | - /** |
|
27 | - * @param int $eventId |
|
28 | - * @return array |
|
29 | - * @throws EE_Error |
|
30 | - * @throws ReflectionException |
|
31 | - */ |
|
32 | - public function getData($eventId) |
|
33 | - { |
|
34 | - /** @var EE_Event $event */ |
|
35 | - $event = EEM_Event::instance()->get_one_by_ID($eventId); |
|
36 | - $topLevelSectionId = $event->registrationFormUuid(); |
|
26 | + /** |
|
27 | + * @param int $eventId |
|
28 | + * @return array |
|
29 | + * @throws EE_Error |
|
30 | + * @throws ReflectionException |
|
31 | + */ |
|
32 | + public function getData($eventId) |
|
33 | + { |
|
34 | + /** @var EE_Event $event */ |
|
35 | + $event = EEM_Event::instance()->get_one_by_ID($eventId); |
|
36 | + $topLevelSectionId = $event->registrationFormUuid(); |
|
37 | 37 | |
38 | - /** @var EE_Form_Section[] $form_sections */ |
|
39 | - $form_sections = EEM_Form_Section::instance()->get_all([ |
|
40 | - [ |
|
41 | - 'OR' => [ |
|
42 | - 'FSC_UUID' => $topLevelSectionId, // top level form |
|
43 | - 'FSC_belongsTo' => $topLevelSectionId, // child form sections |
|
44 | - 'FSC_status' => FormStatus::SHARED, // shared form sections |
|
45 | - ] |
|
46 | - ], |
|
47 | - 'order_by' => ['FSC_order' => 'ASC'], |
|
48 | - ]); |
|
38 | + /** @var EE_Form_Section[] $form_sections */ |
|
39 | + $form_sections = EEM_Form_Section::instance()->get_all([ |
|
40 | + [ |
|
41 | + 'OR' => [ |
|
42 | + 'FSC_UUID' => $topLevelSectionId, // top level form |
|
43 | + 'FSC_belongsTo' => $topLevelSectionId, // child form sections |
|
44 | + 'FSC_status' => FormStatus::SHARED, // shared form sections |
|
45 | + ] |
|
46 | + ], |
|
47 | + 'order_by' => ['FSC_order' => 'ASC'], |
|
48 | + ]); |
|
49 | 49 | |
50 | - $sections = []; |
|
51 | - foreach ($form_sections as $section) { |
|
52 | - if ($section instanceof EE_Form_Section) { |
|
53 | - $UUID = $section->UUID(); |
|
50 | + $sections = []; |
|
51 | + foreach ($form_sections as $section) { |
|
52 | + if ($section instanceof EE_Form_Section) { |
|
53 | + $UUID = $section->UUID(); |
|
54 | 54 | |
55 | - // Avoid duplicates, if any |
|
56 | - $sections[ $UUID ] = [ |
|
57 | - 'id' => $UUID, |
|
58 | - 'appliesTo' => GQLUtils::formatEnumKey($section->appliesTo()), |
|
59 | - 'attributes' => $section->attributes()->toJson(), |
|
60 | - 'belongsTo' => $section->belongsTo(), |
|
61 | - 'isActive' => $section->isActive(), |
|
62 | - 'isArchived' => $section->isArchived(), |
|
63 | - 'isDefault' => $section->isDefault(), |
|
64 | - 'isShared' => $section->isShared(), |
|
65 | - 'isTrashed' => $section->isTrashed(), |
|
66 | - 'label' => $section->label()->toJson(), |
|
67 | - 'order' => $section->order(), |
|
68 | - 'status' => GQLUtils::formatEnumKey($section->status()), |
|
69 | - ]; |
|
70 | - } |
|
71 | - } |
|
55 | + // Avoid duplicates, if any |
|
56 | + $sections[ $UUID ] = [ |
|
57 | + 'id' => $UUID, |
|
58 | + 'appliesTo' => GQLUtils::formatEnumKey($section->appliesTo()), |
|
59 | + 'attributes' => $section->attributes()->toJson(), |
|
60 | + 'belongsTo' => $section->belongsTo(), |
|
61 | + 'isActive' => $section->isActive(), |
|
62 | + 'isArchived' => $section->isArchived(), |
|
63 | + 'isDefault' => $section->isDefault(), |
|
64 | + 'isShared' => $section->isShared(), |
|
65 | + 'isTrashed' => $section->isTrashed(), |
|
66 | + 'label' => $section->label()->toJson(), |
|
67 | + 'order' => $section->order(), |
|
68 | + 'status' => GQLUtils::formatEnumKey($section->status()), |
|
69 | + ]; |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - /** @var EE_Form_Element[] $form_elements */ |
|
74 | - $form_elements = EEM_Form_Element::instance()->get_all([ |
|
75 | - [ |
|
76 | - 'FSC_UUID' => ['IN', array_keys($sections)] |
|
77 | - ] |
|
78 | - ]); |
|
73 | + /** @var EE_Form_Element[] $form_elements */ |
|
74 | + $form_elements = EEM_Form_Element::instance()->get_all([ |
|
75 | + [ |
|
76 | + 'FSC_UUID' => ['IN', array_keys($sections)] |
|
77 | + ] |
|
78 | + ]); |
|
79 | 79 | |
80 | - $elements = []; |
|
81 | - foreach ($form_elements as $element) { |
|
82 | - if ($element instanceof EE_Form_Element) { |
|
83 | - $UUID = $element->UUID(); |
|
80 | + $elements = []; |
|
81 | + foreach ($form_elements as $element) { |
|
82 | + if ($element instanceof EE_Form_Element) { |
|
83 | + $UUID = $element->UUID(); |
|
84 | 84 | |
85 | - // Avoid duplicates |
|
86 | - $elements[ $UUID ] = [ |
|
87 | - 'id' => $UUID, |
|
88 | - 'adminOnly' => $element->adminOnly(), |
|
89 | - 'attributes' => $element->attributes()->toJson(), |
|
90 | - 'belongsTo' => $element->belongsTo(), |
|
91 | - 'helpText' => $element->helpText()->toJson(), |
|
92 | - 'label' => $element->label()->toJson(), |
|
93 | - 'mapsTo' => $element->mapsTo(), |
|
94 | - 'options' => $element->options()->toJson(), |
|
95 | - 'order' => $element->order(), |
|
96 | - 'required' => $element->required()->toJson(), |
|
97 | - 'status' => GQLUtils::formatEnumKey($element->status()), |
|
98 | - 'type' => GQLUtils::formatEnumKey($element->type()), |
|
99 | - ]; |
|
100 | - } |
|
101 | - } |
|
85 | + // Avoid duplicates |
|
86 | + $elements[ $UUID ] = [ |
|
87 | + 'id' => $UUID, |
|
88 | + 'adminOnly' => $element->adminOnly(), |
|
89 | + 'attributes' => $element->attributes()->toJson(), |
|
90 | + 'belongsTo' => $element->belongsTo(), |
|
91 | + 'helpText' => $element->helpText()->toJson(), |
|
92 | + 'label' => $element->label()->toJson(), |
|
93 | + 'mapsTo' => $element->mapsTo(), |
|
94 | + 'options' => $element->options()->toJson(), |
|
95 | + 'order' => $element->order(), |
|
96 | + 'required' => $element->required()->toJson(), |
|
97 | + 'status' => GQLUtils::formatEnumKey($element->status()), |
|
98 | + 'type' => GQLUtils::formatEnumKey($element->type()), |
|
99 | + ]; |
|
100 | + } |
|
101 | + } |
|
102 | 102 | |
103 | - return [ |
|
104 | - 'elements' => array_values($elements), |
|
105 | - 'sections' => array_values($sections), |
|
106 | - 'topLevelSectionId' => $event->registrationFormUuid() |
|
107 | - ]; |
|
108 | - } |
|
103 | + return [ |
|
104 | + 'elements' => array_values($elements), |
|
105 | + 'sections' => array_values($sections), |
|
106 | + 'topLevelSectionId' => $event->registrationFormUuid() |
|
107 | + ]; |
|
108 | + } |
|
109 | 109 | } |
@@ -75,11 +75,11 @@ discard block |
||
75 | 75 | $this->setDisplayStrategy($display_strategy_name); |
76 | 76 | $this->setDefaultStep($default_step); |
77 | 77 | $this->setFormStepUrlKey($form_step_url_key); |
78 | - if (! $collection instanceof CollectionInterface) { |
|
78 | + if ( ! $collection instanceof CollectionInterface) { |
|
79 | 79 | $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface'); |
80 | 80 | } |
81 | 81 | $this->collection = $collection; |
82 | - if (! $request instanceof RequestInterface) { |
|
82 | + if ( ! $request instanceof RequestInterface) { |
|
83 | 83 | /** @var RequestInterface $request */ |
84 | 84 | $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
85 | 85 | } |
@@ -94,23 +94,23 @@ discard block |
||
94 | 94 | */ |
95 | 95 | protected function setDisplayStrategy($display_strategy_name = 'number_bubbles') |
96 | 96 | { |
97 | - if (! is_string($display_strategy_name)) { |
|
97 | + if ( ! is_string($display_strategy_name)) { |
|
98 | 98 | throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string'); |
99 | 99 | } |
100 | 100 | // build up FQCN from incoming display strategy folder name |
101 | 101 | $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\'; |
102 | - $display_strategy_class .= $display_strategy_name . '\\'; |
|
102 | + $display_strategy_class .= $display_strategy_name.'\\'; |
|
103 | 103 | $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name))); |
104 | 104 | $display_strategy_class .= 'ProgressStepsDisplay'; |
105 | 105 | $display_strategy_class = apply_filters( |
106 | 106 | 'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class', |
107 | 107 | $display_strategy_class |
108 | 108 | ); |
109 | - if (! class_exists($display_strategy_class)) { |
|
109 | + if ( ! class_exists($display_strategy_class)) { |
|
110 | 110 | throw new InvalidClassException($display_strategy_class); |
111 | 111 | } |
112 | 112 | $display_strategy = new $display_strategy_class(); |
113 | - if (! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
113 | + if ( ! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
114 | 114 | throw new InvalidClassException( |
115 | 115 | $display_strategy_class, |
116 | 116 | sprintf( |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | public function setDefaultStep($default_step) |
132 | 132 | { |
133 | - if (! is_string($default_step)) { |
|
133 | + if ( ! is_string($default_step)) { |
|
134 | 134 | throw new InvalidDataTypeException('$default_step', $default_step, 'string'); |
135 | 135 | } |
136 | 136 | $this->default_step = $default_step; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
145 | 145 | { |
146 | - if (! is_string($form_step_url_key)) { |
|
146 | + if ( ! is_string($form_step_url_key)) { |
|
147 | 147 | throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
148 | 148 | } |
149 | 149 | $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | // grab the step previously known as current, in case we need to revert |
164 | 164 | $current_current_step = $this->collection->current(); |
165 | 165 | // verify that requested step exists |
166 | - if (! $this->collection->has($step)) { |
|
166 | + if ( ! $this->collection->has($step)) { |
|
167 | 167 | throw new InvalidIdentifierException($step, $this->default_step); |
168 | 168 | } |
169 | 169 | if ($this->collection->setCurrent($step)) { |
@@ -26,225 +26,225 @@ |
||
26 | 26 | */ |
27 | 27 | class ProgressStepManager |
28 | 28 | { |
29 | - /** |
|
30 | - * @var ProgressStepInterface[] |
|
31 | - */ |
|
32 | - private $collection; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private $default_step; |
|
38 | - |
|
39 | - /** |
|
40 | - * the key used for the URL param that denotes the current form step |
|
41 | - * defaults to 'ee-form-step' |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - private $form_step_url_key = ''; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var ProgressStepsDisplayInterface |
|
49 | - */ |
|
50 | - private $display_strategy; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var RequestInterface |
|
54 | - */ |
|
55 | - private $request; |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * ProgressStepManager constructor |
|
60 | - * |
|
61 | - * @param string $display_strategy_name |
|
62 | - * @param string $default_step |
|
63 | - * @param string $form_step_url_key |
|
64 | - * @param CollectionInterface $collection |
|
65 | - * @param RequestInterface $request |
|
66 | - */ |
|
67 | - public function __construct( |
|
68 | - $display_strategy_name = 'number_bubbles', |
|
69 | - $default_step = '', |
|
70 | - $form_step_url_key = '', |
|
71 | - CollectionInterface $collection = null, |
|
72 | - RequestInterface $request = null |
|
73 | - ) { |
|
74 | - $this->setDisplayStrategy($display_strategy_name); |
|
75 | - $this->setDefaultStep($default_step); |
|
76 | - $this->setFormStepUrlKey($form_step_url_key); |
|
77 | - if (! $collection instanceof CollectionInterface) { |
|
78 | - $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface'); |
|
79 | - } |
|
80 | - $this->collection = $collection; |
|
81 | - if (! $request instanceof RequestInterface) { |
|
82 | - /** @var RequestInterface $request */ |
|
83 | - $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
84 | - } |
|
85 | - $this->request = $request; |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @param string $display_strategy_name |
|
91 | - * @throws InvalidDataTypeException |
|
92 | - * @throws InvalidClassException |
|
93 | - */ |
|
94 | - protected function setDisplayStrategy($display_strategy_name = 'number_bubbles') |
|
95 | - { |
|
96 | - if (! is_string($display_strategy_name)) { |
|
97 | - throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string'); |
|
98 | - } |
|
99 | - // build up FQCN from incoming display strategy folder name |
|
100 | - $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\'; |
|
101 | - $display_strategy_class .= $display_strategy_name . '\\'; |
|
102 | - $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name))); |
|
103 | - $display_strategy_class .= 'ProgressStepsDisplay'; |
|
104 | - $display_strategy_class = apply_filters( |
|
105 | - 'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class', |
|
106 | - $display_strategy_class |
|
107 | - ); |
|
108 | - if (! class_exists($display_strategy_class)) { |
|
109 | - throw new InvalidClassException($display_strategy_class); |
|
110 | - } |
|
111 | - $display_strategy = new $display_strategy_class(); |
|
112 | - if (! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
113 | - throw new InvalidClassException( |
|
114 | - $display_strategy_class, |
|
115 | - sprintf( |
|
116 | - esc_html__('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'), |
|
117 | - $display_strategy_class, |
|
118 | - '\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface' |
|
119 | - ) |
|
120 | - ); |
|
121 | - } |
|
122 | - $this->display_strategy = $display_strategy; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $default_step |
|
128 | - * @throws InvalidDataTypeException |
|
129 | - */ |
|
130 | - public function setDefaultStep($default_step) |
|
131 | - { |
|
132 | - if (! is_string($default_step)) { |
|
133 | - throw new InvalidDataTypeException('$default_step', $default_step, 'string'); |
|
134 | - } |
|
135 | - $this->default_step = $default_step; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $form_step_url_key |
|
141 | - * @throws InvalidDataTypeException |
|
142 | - */ |
|
143 | - public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
144 | - { |
|
145 | - if (! is_string($form_step_url_key)) { |
|
146 | - throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
147 | - } |
|
148 | - $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param string $step |
|
154 | - * @throws InvalidIdentifierException |
|
155 | - */ |
|
156 | - public function setCurrentStep($step = '') |
|
157 | - { |
|
158 | - // use incoming value if it's set, otherwise use request param if it's set, otherwise use default |
|
159 | - $step = ! empty($step) |
|
160 | - ? $step |
|
161 | - : $this->request->getRequestParam($this->form_step_url_key, $this->default_step); |
|
162 | - // grab the step previously known as current, in case we need to revert |
|
163 | - $current_current_step = $this->collection->current(); |
|
164 | - // verify that requested step exists |
|
165 | - if (! $this->collection->has($step)) { |
|
166 | - throw new InvalidIdentifierException($step, $this->default_step); |
|
167 | - } |
|
168 | - if ($this->collection->setCurrent($step)) { |
|
169 | - // if the old boss is the same as the new boss, then nothing changes |
|
170 | - if ($this->collection->current() !== $current_current_step) { |
|
171 | - $current_current_step->setIsCurrent(false); |
|
172 | - } |
|
173 | - $this->collection->current()->setIsCurrent(); |
|
174 | - } else { |
|
175 | - $this->collection->setCurrent($current_current_step->id()); |
|
176 | - $current_current_step->setIsCurrent(true); |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * setPreviousStepsCompleted |
|
183 | - */ |
|
184 | - public function setPreviousStepsCompleted() |
|
185 | - { |
|
186 | - $current_current_step = $this->collection->current(); |
|
187 | - $this->collection->rewind(); |
|
188 | - while ($this->collection->valid()) { |
|
189 | - if ($this->collection->current() === $current_current_step) { |
|
190 | - break; |
|
191 | - } |
|
192 | - $this->setCurrentStepCompleted(); |
|
193 | - $this->collection->next(); |
|
194 | - } |
|
195 | - $this->collection->setCurrentUsingObject($current_current_step); |
|
196 | - return false; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return ProgressStepInterface |
|
202 | - */ |
|
203 | - public function currentStep() |
|
204 | - { |
|
205 | - return $this->collection->current(); |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @return ProgressStepInterface |
|
211 | - */ |
|
212 | - public function nextStep() |
|
213 | - { |
|
214 | - return $this->collection->next(); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - public function enqueueStylesAndScripts() |
|
222 | - { |
|
223 | - $this->display_strategy->enqueueStylesAndScripts(); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * echos out HTML |
|
229 | - * |
|
230 | - * @return string |
|
231 | - */ |
|
232 | - public function displaySteps() |
|
233 | - { |
|
234 | - return EEH_Template::display_template( |
|
235 | - $this->display_strategy->getTemplate(), |
|
236 | - array('progress_steps' => $this->collection), |
|
237 | - true |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param bool $completed |
|
244 | - * @return ProgressStepInterface |
|
245 | - */ |
|
246 | - public function setCurrentStepCompleted($completed = true) |
|
247 | - { |
|
248 | - return $this->collection->current()->setIsCompleted($completed); |
|
249 | - } |
|
29 | + /** |
|
30 | + * @var ProgressStepInterface[] |
|
31 | + */ |
|
32 | + private $collection; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private $default_step; |
|
38 | + |
|
39 | + /** |
|
40 | + * the key used for the URL param that denotes the current form step |
|
41 | + * defaults to 'ee-form-step' |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + private $form_step_url_key = ''; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var ProgressStepsDisplayInterface |
|
49 | + */ |
|
50 | + private $display_strategy; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var RequestInterface |
|
54 | + */ |
|
55 | + private $request; |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * ProgressStepManager constructor |
|
60 | + * |
|
61 | + * @param string $display_strategy_name |
|
62 | + * @param string $default_step |
|
63 | + * @param string $form_step_url_key |
|
64 | + * @param CollectionInterface $collection |
|
65 | + * @param RequestInterface $request |
|
66 | + */ |
|
67 | + public function __construct( |
|
68 | + $display_strategy_name = 'number_bubbles', |
|
69 | + $default_step = '', |
|
70 | + $form_step_url_key = '', |
|
71 | + CollectionInterface $collection = null, |
|
72 | + RequestInterface $request = null |
|
73 | + ) { |
|
74 | + $this->setDisplayStrategy($display_strategy_name); |
|
75 | + $this->setDefaultStep($default_step); |
|
76 | + $this->setFormStepUrlKey($form_step_url_key); |
|
77 | + if (! $collection instanceof CollectionInterface) { |
|
78 | + $collection = new Collection('\EventEspresso\core\services\progress_steps\ProgressStepInterface'); |
|
79 | + } |
|
80 | + $this->collection = $collection; |
|
81 | + if (! $request instanceof RequestInterface) { |
|
82 | + /** @var RequestInterface $request */ |
|
83 | + $request = LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\Request'); |
|
84 | + } |
|
85 | + $this->request = $request; |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @param string $display_strategy_name |
|
91 | + * @throws InvalidDataTypeException |
|
92 | + * @throws InvalidClassException |
|
93 | + */ |
|
94 | + protected function setDisplayStrategy($display_strategy_name = 'number_bubbles') |
|
95 | + { |
|
96 | + if (! is_string($display_strategy_name)) { |
|
97 | + throw new InvalidDataTypeException('$display_strategy_name', $display_strategy_name, 'string'); |
|
98 | + } |
|
99 | + // build up FQCN from incoming display strategy folder name |
|
100 | + $display_strategy_class = 'EventEspresso\core\services\progress_steps\display_strategies\\'; |
|
101 | + $display_strategy_class .= $display_strategy_name . '\\'; |
|
102 | + $display_strategy_class .= str_replace(' ', '', ucwords(str_replace('_', ' ', $display_strategy_name))); |
|
103 | + $display_strategy_class .= 'ProgressStepsDisplay'; |
|
104 | + $display_strategy_class = apply_filters( |
|
105 | + 'FHEE__ProgressStepManager__setDisplayStrategy__display_strategy_class', |
|
106 | + $display_strategy_class |
|
107 | + ); |
|
108 | + if (! class_exists($display_strategy_class)) { |
|
109 | + throw new InvalidClassException($display_strategy_class); |
|
110 | + } |
|
111 | + $display_strategy = new $display_strategy_class(); |
|
112 | + if (! $display_strategy instanceof ProgressStepsDisplayInterface) { |
|
113 | + throw new InvalidClassException( |
|
114 | + $display_strategy_class, |
|
115 | + sprintf( |
|
116 | + esc_html__('The "%1$s" Class needs to be an implementation of the "%1$s" Interface.', 'event_espresso'), |
|
117 | + $display_strategy_class, |
|
118 | + '\EventEspresso\core\services\progress_steps\display_strategies\ProgressStepsDisplayInterface' |
|
119 | + ) |
|
120 | + ); |
|
121 | + } |
|
122 | + $this->display_strategy = $display_strategy; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $default_step |
|
128 | + * @throws InvalidDataTypeException |
|
129 | + */ |
|
130 | + public function setDefaultStep($default_step) |
|
131 | + { |
|
132 | + if (! is_string($default_step)) { |
|
133 | + throw new InvalidDataTypeException('$default_step', $default_step, 'string'); |
|
134 | + } |
|
135 | + $this->default_step = $default_step; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $form_step_url_key |
|
141 | + * @throws InvalidDataTypeException |
|
142 | + */ |
|
143 | + public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
144 | + { |
|
145 | + if (! is_string($form_step_url_key)) { |
|
146 | + throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
147 | + } |
|
148 | + $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param string $step |
|
154 | + * @throws InvalidIdentifierException |
|
155 | + */ |
|
156 | + public function setCurrentStep($step = '') |
|
157 | + { |
|
158 | + // use incoming value if it's set, otherwise use request param if it's set, otherwise use default |
|
159 | + $step = ! empty($step) |
|
160 | + ? $step |
|
161 | + : $this->request->getRequestParam($this->form_step_url_key, $this->default_step); |
|
162 | + // grab the step previously known as current, in case we need to revert |
|
163 | + $current_current_step = $this->collection->current(); |
|
164 | + // verify that requested step exists |
|
165 | + if (! $this->collection->has($step)) { |
|
166 | + throw new InvalidIdentifierException($step, $this->default_step); |
|
167 | + } |
|
168 | + if ($this->collection->setCurrent($step)) { |
|
169 | + // if the old boss is the same as the new boss, then nothing changes |
|
170 | + if ($this->collection->current() !== $current_current_step) { |
|
171 | + $current_current_step->setIsCurrent(false); |
|
172 | + } |
|
173 | + $this->collection->current()->setIsCurrent(); |
|
174 | + } else { |
|
175 | + $this->collection->setCurrent($current_current_step->id()); |
|
176 | + $current_current_step->setIsCurrent(true); |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * setPreviousStepsCompleted |
|
183 | + */ |
|
184 | + public function setPreviousStepsCompleted() |
|
185 | + { |
|
186 | + $current_current_step = $this->collection->current(); |
|
187 | + $this->collection->rewind(); |
|
188 | + while ($this->collection->valid()) { |
|
189 | + if ($this->collection->current() === $current_current_step) { |
|
190 | + break; |
|
191 | + } |
|
192 | + $this->setCurrentStepCompleted(); |
|
193 | + $this->collection->next(); |
|
194 | + } |
|
195 | + $this->collection->setCurrentUsingObject($current_current_step); |
|
196 | + return false; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return ProgressStepInterface |
|
202 | + */ |
|
203 | + public function currentStep() |
|
204 | + { |
|
205 | + return $this->collection->current(); |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @return ProgressStepInterface |
|
211 | + */ |
|
212 | + public function nextStep() |
|
213 | + { |
|
214 | + return $this->collection->next(); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + public function enqueueStylesAndScripts() |
|
222 | + { |
|
223 | + $this->display_strategy->enqueueStylesAndScripts(); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * echos out HTML |
|
229 | + * |
|
230 | + * @return string |
|
231 | + */ |
|
232 | + public function displaySteps() |
|
233 | + { |
|
234 | + return EEH_Template::display_template( |
|
235 | + $this->display_strategy->getTemplate(), |
|
236 | + array('progress_steps' => $this->collection), |
|
237 | + true |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param bool $completed |
|
244 | + * @return ProgressStepInterface |
|
245 | + */ |
|
246 | + public function setCurrentStepCompleted($completed = true) |
|
247 | + { |
|
248 | + return $this->collection->current()->setIsCompleted($completed); |
|
249 | + } |
|
250 | 250 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | protected function setBaseUrl($base_url) |
142 | 142 | { |
143 | - if (! is_string($base_url)) { |
|
143 | + if ( ! is_string($base_url)) { |
|
144 | 144 | throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
145 | 145 | } |
146 | 146 | if (empty($base_url)) { |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | */ |
172 | 172 | public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
173 | 173 | { |
174 | - if (! is_string($form_step_url_key)) { |
|
174 | + if ( ! is_string($form_step_url_key)) { |
|
175 | 175 | throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
176 | 176 | } |
177 | 177 | $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | */ |
194 | 194 | protected function setDefaultFormStep($default_form_step) |
195 | 195 | { |
196 | - if (! is_string($default_form_step)) { |
|
196 | + if ( ! is_string($default_form_step)) { |
|
197 | 197 | throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
198 | 198 | } |
199 | 199 | $this->default_form_step = $default_form_step; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | protected function setCurrentStepFromRequest() |
209 | 209 | { |
210 | 210 | $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
211 | - if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
211 | + if ( ! $this->form_steps->setCurrent($current_step_slug)) { |
|
212 | 212 | throw new InvalidIdentifierException( |
213 | 213 | $current_step_slug, |
214 | 214 | $this->defaultFormStep(), |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | */ |
228 | 228 | public function getCurrentStep() |
229 | 229 | { |
230 | - if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
230 | + if ( ! $this->form_steps->current() instanceof SequentialStepForm) { |
|
231 | 231 | throw new InvalidFormHandlerException($this->form_steps->current()); |
232 | 232 | } |
233 | 233 | return $this->form_steps->current(); |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | public function formAction() |
242 | 242 | { |
243 | - if (! is_string($this->form_action) || empty($this->form_action)) { |
|
243 | + if ( ! is_string($this->form_action) || empty($this->form_action)) { |
|
244 | 244 | $this->form_action = $this->baseUrl(); |
245 | 245 | } |
246 | 246 | return $this->form_action; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function setFormAction($form_action) |
255 | 255 | { |
256 | - if (! is_string($form_action)) { |
|
256 | + if ( ! is_string($form_action)) { |
|
257 | 257 | throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
258 | 258 | } |
259 | 259 | $this->form_action = $form_action; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function addFormActionArgs($form_action_args = array()) |
269 | 269 | { |
270 | - if (! is_array($form_action_args)) { |
|
270 | + if ( ! is_array($form_action_args)) { |
|
271 | 271 | throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
272 | 272 | } |
273 | 273 | $form_action_args = ! empty($form_action_args) |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | protected function getProgressStepsCollection() |
333 | 333 | { |
334 | 334 | static $collection = null; |
335 | - if (! $collection instanceof ProgressStepCollection) { |
|
335 | + if ( ! $collection instanceof ProgressStepCollection) { |
|
336 | 336 | $collection = new ProgressStepCollection(); |
337 | 337 | } |
338 | 338 | return $collection; |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | /** @var SequentialStepForm $form_step */ |
355 | 355 | foreach ($this->form_steps as $form_step) { |
356 | 356 | // is this step active ? |
357 | - if (! $form_step->initialize()) { |
|
357 | + if ( ! $form_step->initialize()) { |
|
358 | 358 | continue; |
359 | 359 | } |
360 | 360 | $progress_steps_collection->add( |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | { |
424 | 424 | $form_step = $this->buildCurrentStepForm(); |
425 | 425 | // no displayable content ? then skip straight to processing |
426 | - if (! $form_step->displayable()) { |
|
426 | + if ( ! $form_step->displayable()) { |
|
427 | 427 | $this->addFormActionArgs(); |
428 | 428 | $form_step->setFormAction($this->formAction()); |
429 | 429 | wp_safe_redirect($form_step->formAction()); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | public function displayProgressSteps($return_as_string = true) |
500 | 500 | { |
501 | 501 | $form_step = $this->getCurrentStep(); |
502 | - if (! $form_step->displayable()) { |
|
502 | + if ( ! $form_step->displayable()) { |
|
503 | 503 | return ''; |
504 | 504 | } |
505 | 505 | $progress_steps = apply_filters( |
@@ -30,583 +30,583 @@ |
||
30 | 30 | */ |
31 | 31 | abstract class SequentialStepFormManager |
32 | 32 | { |
33 | - /** |
|
34 | - * a simplified URL with no form related parameters |
|
35 | - * that will be used to build the form's redirect URLs |
|
36 | - * |
|
37 | - * @var string $base_url |
|
38 | - */ |
|
39 | - private $base_url = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * the key used for the URL param that denotes the current form step |
|
43 | - * defaults to 'ee-form-step' |
|
44 | - * |
|
45 | - * @var string $form_step_url_key |
|
46 | - */ |
|
47 | - private $form_step_url_key = ''; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var string $default_form_step |
|
51 | - */ |
|
52 | - private $default_form_step = ''; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var string $form_action |
|
56 | - */ |
|
57 | - private $form_action; |
|
58 | - |
|
59 | - /** |
|
60 | - * value of one of the string constant above |
|
61 | - * |
|
62 | - * @var string $form_config |
|
63 | - */ |
|
64 | - private $form_config; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var string $progress_step_style |
|
68 | - */ |
|
69 | - private $progress_step_style = ''; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var RequestInterface $request |
|
73 | - */ |
|
74 | - private $request; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var Collection $form_steps |
|
78 | - */ |
|
79 | - protected $form_steps; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var ProgressStepManager $progress_step_manager |
|
83 | - */ |
|
84 | - protected $progress_step_manager; |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @return Collection|null |
|
89 | - */ |
|
90 | - abstract protected function getFormStepsCollection(); |
|
91 | - |
|
92 | - // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
93 | - /** |
|
94 | - * StepsManager constructor |
|
95 | - * |
|
96 | - * @param string $base_url |
|
97 | - * @param string $default_form_step |
|
98 | - * @param string $form_action |
|
99 | - * @param string $form_config |
|
100 | - * @param EE_Request|RequestInterface|null $request |
|
101 | - * @param string $progress_step_style |
|
102 | - * @throws InvalidDataTypeException |
|
103 | - * @throws InvalidArgumentException |
|
104 | - */ |
|
105 | - public function __construct( |
|
106 | - $base_url, |
|
107 | - $default_form_step, |
|
108 | - $form_action = '', |
|
109 | - $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
110 | - $progress_step_style = 'number_bubbles', |
|
111 | - $request = null |
|
112 | - ) { |
|
113 | - $this->setBaseUrl($base_url); |
|
114 | - $this->setDefaultFormStep($default_form_step); |
|
115 | - $this->setFormAction($form_action); |
|
116 | - $this->setFormConfig($form_config); |
|
117 | - $this->setProgressStepStyle($progress_step_style); |
|
118 | - $this->request = $request instanceof RequestInterface |
|
119 | - ? $request |
|
120 | - : LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @return string |
|
126 | - * @throws InvalidFormHandlerException |
|
127 | - */ |
|
128 | - public function baseUrl() |
|
129 | - { |
|
130 | - if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
131 | - add_query_arg( |
|
132 | - array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
133 | - $this->base_url |
|
134 | - ); |
|
135 | - } |
|
136 | - return $this->base_url; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @param string $base_url |
|
142 | - * @throws InvalidDataTypeException |
|
143 | - * @throws InvalidArgumentException |
|
144 | - */ |
|
145 | - protected function setBaseUrl($base_url) |
|
146 | - { |
|
147 | - if (! is_string($base_url)) { |
|
148 | - throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
149 | - } |
|
150 | - if (empty($base_url)) { |
|
151 | - throw new InvalidArgumentException( |
|
152 | - esc_html__('The base URL can not be an empty string.', 'event_espresso') |
|
153 | - ); |
|
154 | - } |
|
155 | - $this->base_url = $base_url; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @return string |
|
161 | - * @throws InvalidDataTypeException |
|
162 | - */ |
|
163 | - public function formStepUrlKey() |
|
164 | - { |
|
165 | - if (empty($this->form_step_url_key)) { |
|
166 | - $this->setFormStepUrlKey(); |
|
167 | - } |
|
168 | - return $this->form_step_url_key; |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * @param string $form_step_url_key |
|
174 | - * @throws InvalidDataTypeException |
|
175 | - */ |
|
176 | - public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
177 | - { |
|
178 | - if (! is_string($form_step_url_key)) { |
|
179 | - throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
180 | - } |
|
181 | - $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @return string |
|
187 | - */ |
|
188 | - public function defaultFormStep() |
|
189 | - { |
|
190 | - return $this->default_form_step; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @param $default_form_step |
|
196 | - * @throws InvalidDataTypeException |
|
197 | - */ |
|
198 | - protected function setDefaultFormStep($default_form_step) |
|
199 | - { |
|
200 | - if (! is_string($default_form_step)) { |
|
201 | - throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
202 | - } |
|
203 | - $this->default_form_step = $default_form_step; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * @return void |
|
209 | - * @throws InvalidIdentifierException |
|
210 | - * @throws InvalidDataTypeException |
|
211 | - */ |
|
212 | - protected function setCurrentStepFromRequest() |
|
213 | - { |
|
214 | - $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
|
215 | - if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
216 | - throw new InvalidIdentifierException( |
|
217 | - $current_step_slug, |
|
218 | - $this->defaultFormStep(), |
|
219 | - sprintf( |
|
220 | - esc_html__('The "%1$s" form step could not be set.', 'event_espresso'), |
|
221 | - $current_step_slug |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * @return SequentialStepFormInterface|object |
|
230 | - * @throws InvalidFormHandlerException |
|
231 | - */ |
|
232 | - public function getCurrentStep() |
|
233 | - { |
|
234 | - if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
235 | - throw new InvalidFormHandlerException($this->form_steps->current()); |
|
236 | - } |
|
237 | - return $this->form_steps->current(); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * @return string |
|
243 | - * @throws InvalidFormHandlerException |
|
244 | - */ |
|
245 | - public function formAction() |
|
246 | - { |
|
247 | - if (! is_string($this->form_action) || empty($this->form_action)) { |
|
248 | - $this->form_action = $this->baseUrl(); |
|
249 | - } |
|
250 | - return $this->form_action; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param string $form_action |
|
256 | - * @throws InvalidDataTypeException |
|
257 | - */ |
|
258 | - public function setFormAction($form_action) |
|
259 | - { |
|
260 | - if (! is_string($form_action)) { |
|
261 | - throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
262 | - } |
|
263 | - $this->form_action = $form_action; |
|
264 | - } |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * @param array $form_action_args |
|
269 | - * @throws InvalidDataTypeException |
|
270 | - * @throws InvalidFormHandlerException |
|
271 | - */ |
|
272 | - public function addFormActionArgs($form_action_args = array()) |
|
273 | - { |
|
274 | - if (! is_array($form_action_args)) { |
|
275 | - throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
276 | - } |
|
277 | - $form_action_args = ! empty($form_action_args) |
|
278 | - ? $form_action_args |
|
279 | - : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
280 | - $this->getCurrentStep()->setFormAction( |
|
281 | - add_query_arg($form_action_args, $this->formAction()) |
|
282 | - ); |
|
283 | - $this->form_action = $this->getCurrentStep()->formAction(); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @return string |
|
289 | - */ |
|
290 | - public function formConfig() |
|
291 | - { |
|
292 | - return $this->form_config; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @param string $form_config |
|
298 | - */ |
|
299 | - public function setFormConfig($form_config) |
|
300 | - { |
|
301 | - $this->form_config = $form_config; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @return string |
|
307 | - */ |
|
308 | - public function progressStepStyle() |
|
309 | - { |
|
310 | - return $this->progress_step_style; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @param string $progress_step_style |
|
316 | - */ |
|
317 | - public function setProgressStepStyle($progress_step_style) |
|
318 | - { |
|
319 | - $this->progress_step_style = $progress_step_style; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @return RequestInterface |
|
325 | - */ |
|
326 | - public function request() |
|
327 | - { |
|
328 | - return $this->request; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * @return Collection|null |
|
334 | - * @throws InvalidInterfaceException |
|
335 | - */ |
|
336 | - protected function getProgressStepsCollection() |
|
337 | - { |
|
338 | - static $collection = null; |
|
339 | - if (! $collection instanceof ProgressStepCollection) { |
|
340 | - $collection = new ProgressStepCollection(); |
|
341 | - } |
|
342 | - return $collection; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param Collection $progress_steps_collection |
|
348 | - * @return ProgressStepManager |
|
349 | - * @throws InvalidInterfaceException |
|
350 | - * @throws InvalidClassException |
|
351 | - * @throws InvalidDataTypeException |
|
352 | - * @throws InvalidEntityException |
|
353 | - * @throws InvalidFormHandlerException |
|
354 | - */ |
|
355 | - protected function generateProgressSteps($progress_steps_collection) |
|
356 | - { |
|
357 | - $current_step = $this->getCurrentStep(); |
|
358 | - /** @var SequentialStepForm $form_step */ |
|
359 | - foreach ($this->form_steps as $form_step) { |
|
360 | - // is this step active ? |
|
361 | - if (! $form_step->initialize()) { |
|
362 | - continue; |
|
363 | - } |
|
364 | - $progress_steps_collection->add( |
|
365 | - new ProgressStep( |
|
366 | - $form_step->order(), |
|
367 | - $form_step->slug(), |
|
368 | - $form_step->slug(), |
|
369 | - $form_step->formName() |
|
370 | - ), |
|
371 | - $form_step->slug() |
|
372 | - ); |
|
373 | - } |
|
374 | - // set collection pointer back to current step |
|
375 | - $this->form_steps->setCurrentUsingObject($current_step); |
|
376 | - return new ProgressStepManager( |
|
377 | - $this->progressStepStyle(), |
|
378 | - $this->defaultFormStep(), |
|
379 | - $this->formStepUrlKey(), |
|
380 | - $progress_steps_collection |
|
381 | - ); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * @throws InvalidClassException |
|
387 | - * @throws InvalidDataTypeException |
|
388 | - * @throws InvalidEntityException |
|
389 | - * @throws InvalidIdentifierException |
|
390 | - * @throws InvalidInterfaceException |
|
391 | - * @throws InvalidArgumentException |
|
392 | - * @throws InvalidFormHandlerException |
|
393 | - */ |
|
394 | - public function buildForm() |
|
395 | - { |
|
396 | - $this->buildCurrentStepFormForDisplay(); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * @param array $form_data |
|
402 | - * @throws InvalidArgumentException |
|
403 | - * @throws InvalidClassException |
|
404 | - * @throws InvalidDataTypeException |
|
405 | - * @throws InvalidEntityException |
|
406 | - * @throws InvalidFormHandlerException |
|
407 | - * @throws InvalidIdentifierException |
|
408 | - * @throws InvalidInterfaceException |
|
409 | - */ |
|
410 | - public function processForm($form_data = array()) |
|
411 | - { |
|
412 | - $this->buildCurrentStepFormForProcessing(); |
|
413 | - $this->processCurrentStepForm($form_data); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * @throws InvalidClassException |
|
419 | - * @throws InvalidDataTypeException |
|
420 | - * @throws InvalidEntityException |
|
421 | - * @throws InvalidInterfaceException |
|
422 | - * @throws InvalidIdentifierException |
|
423 | - * @throws InvalidArgumentException |
|
424 | - * @throws InvalidFormHandlerException |
|
425 | - */ |
|
426 | - public function buildCurrentStepFormForDisplay() |
|
427 | - { |
|
428 | - $form_step = $this->buildCurrentStepForm(); |
|
429 | - // no displayable content ? then skip straight to processing |
|
430 | - if (! $form_step->displayable()) { |
|
431 | - $this->addFormActionArgs(); |
|
432 | - $form_step->setFormAction($this->formAction()); |
|
433 | - wp_safe_redirect($form_step->formAction()); |
|
434 | - } |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * @throws InvalidClassException |
|
440 | - * @throws InvalidDataTypeException |
|
441 | - * @throws InvalidEntityException |
|
442 | - * @throws InvalidInterfaceException |
|
443 | - * @throws InvalidIdentifierException |
|
444 | - * @throws InvalidArgumentException |
|
445 | - * @throws InvalidFormHandlerException |
|
446 | - */ |
|
447 | - public function buildCurrentStepFormForProcessing() |
|
448 | - { |
|
449 | - $this->buildCurrentStepForm(false); |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * @param bool $for_display |
|
455 | - * @return SequentialStepFormInterface |
|
456 | - * @throws InvalidArgumentException |
|
457 | - * @throws InvalidClassException |
|
458 | - * @throws InvalidDataTypeException |
|
459 | - * @throws InvalidEntityException |
|
460 | - * @throws InvalidFormHandlerException |
|
461 | - * @throws InvalidIdentifierException |
|
462 | - * @throws InvalidInterfaceException |
|
463 | - */ |
|
464 | - private function buildCurrentStepForm($for_display = true) |
|
465 | - { |
|
466 | - $this->form_steps = $this->getFormStepsCollection(); |
|
467 | - $this->setCurrentStepFromRequest(); |
|
468 | - $form_step = $this->getCurrentStep(); |
|
469 | - if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) { |
|
470 | - $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso')); |
|
471 | - } |
|
472 | - if ($for_display && $form_step->displayable()) { |
|
473 | - $this->progress_step_manager = $this->generateProgressSteps( |
|
474 | - $this->getProgressStepsCollection() |
|
475 | - ); |
|
476 | - $this->progress_step_manager->setCurrentStep( |
|
477 | - $form_step->slug() |
|
478 | - ); |
|
479 | - // mark all previous progress steps as completed |
|
480 | - $this->progress_step_manager->setPreviousStepsCompleted(); |
|
481 | - $this->progress_step_manager->enqueueStylesAndScripts(); |
|
482 | - $this->addFormActionArgs(); |
|
483 | - $form_step->setFormAction($this->formAction()); |
|
484 | - } else { |
|
485 | - $form_step->setRedirectUrl($this->baseUrl()); |
|
486 | - $form_step->addRedirectArgs( |
|
487 | - array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
488 | - ); |
|
489 | - } |
|
490 | - $form_step->generate(); |
|
491 | - if ($for_display) { |
|
492 | - $form_step->enqueueStylesAndScripts(); |
|
493 | - } |
|
494 | - return $form_step; |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * @param bool $return_as_string |
|
500 | - * @return string |
|
501 | - * @throws InvalidFormHandlerException |
|
502 | - */ |
|
503 | - public function displayProgressSteps($return_as_string = true) |
|
504 | - { |
|
505 | - $form_step = $this->getCurrentStep(); |
|
506 | - if (! $form_step->displayable()) { |
|
507 | - return ''; |
|
508 | - } |
|
509 | - $progress_steps = apply_filters( |
|
510 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
|
511 | - '' |
|
512 | - ); |
|
513 | - $progress_steps .= $this->progress_step_manager->displaySteps(); |
|
514 | - $progress_steps .= apply_filters( |
|
515 | - 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
|
516 | - '' |
|
517 | - ); |
|
518 | - if ($return_as_string) { |
|
519 | - return $progress_steps; |
|
520 | - } |
|
521 | - echo wp_kses($progress_steps, AllowedTags::getWithFormTags()); |
|
522 | - return ''; |
|
523 | - } |
|
524 | - |
|
525 | - |
|
526 | - /** |
|
527 | - * @param bool $return_as_string |
|
528 | - * @return string |
|
529 | - * @throws InvalidFormHandlerException |
|
530 | - */ |
|
531 | - public function displayCurrentStepForm($return_as_string = true) |
|
532 | - { |
|
533 | - if ($return_as_string) { |
|
534 | - return $this->getCurrentStep()->display(); |
|
535 | - } |
|
536 | - echo wp_kses($this->getCurrentStep()->display(), AllowedTags::getWithFormTags()); |
|
537 | - return ''; |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @param array $form_data |
|
543 | - * @return void |
|
544 | - * @throws InvalidArgumentException |
|
545 | - * @throws InvalidDataTypeException |
|
546 | - * @throws InvalidFormHandlerException |
|
547 | - */ |
|
548 | - public function processCurrentStepForm($form_data = array()) |
|
549 | - { |
|
550 | - // grab instance of current step because after calling next() below, |
|
551 | - // any calls to getCurrentStep() will return the "next" step because we advanced |
|
552 | - $current_step = $this->getCurrentStep(); |
|
553 | - try { |
|
554 | - // form processing should either throw exceptions or return true |
|
555 | - $current_step->process($form_data); |
|
556 | - } catch (Exception $e) { |
|
557 | - // something went wrong, convert the Exception to an EE_Error |
|
558 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
559 | - // prevent redirect to next step or other if exception was thrown |
|
560 | - if ( |
|
561 | - $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
|
562 | - || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
|
563 | - ) { |
|
564 | - $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
565 | - } |
|
566 | - } |
|
567 | - // save notices to a transient so that when we redirect back |
|
568 | - // to the display portion for this step |
|
569 | - // those notices can be displayed |
|
570 | - EE_Error::get_notices(false, true); |
|
571 | - $this->redirectForm($current_step); |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * handles where to go to next |
|
577 | - * |
|
578 | - * @param SequentialStepFormInterface $current_step |
|
579 | - * @throws InvalidArgumentException |
|
580 | - * @throws InvalidDataTypeException |
|
581 | - * @throws InvalidFormHandlerException |
|
582 | - */ |
|
583 | - public function redirectForm($current_step) |
|
584 | - { |
|
585 | - $redirect_step = $current_step; |
|
586 | - switch ($current_step->redirectTo()) { |
|
587 | - case SequentialStepForm::REDIRECT_TO_OTHER: |
|
588 | - // going somewhere else, so just check out now |
|
589 | - wp_safe_redirect($redirect_step->redirectUrl()); |
|
590 | - exit(); |
|
591 | - case SequentialStepForm::REDIRECT_TO_PREV_STEP: |
|
592 | - $redirect_step = $this->form_steps->previous(); |
|
593 | - break; |
|
594 | - case SequentialStepForm::REDIRECT_TO_NEXT_STEP: |
|
595 | - $this->form_steps->next(); |
|
596 | - if ($this->form_steps->valid()) { |
|
597 | - $redirect_step = $this->form_steps->current(); |
|
598 | - } |
|
599 | - break; |
|
600 | - case SequentialStepForm::REDIRECT_TO_CURRENT_STEP: |
|
601 | - default: |
|
602 | - // $redirect_step is already set |
|
603 | - } |
|
604 | - $current_step->setRedirectUrl($this->baseUrl()); |
|
605 | - $current_step->addRedirectArgs( |
|
606 | - // use the slug for whatever step we are redirecting too |
|
607 | - array($this->formStepUrlKey() => $redirect_step->slug()) |
|
608 | - ); |
|
609 | - wp_safe_redirect($current_step->redirectUrl()); |
|
610 | - exit(); |
|
611 | - } |
|
33 | + /** |
|
34 | + * a simplified URL with no form related parameters |
|
35 | + * that will be used to build the form's redirect URLs |
|
36 | + * |
|
37 | + * @var string $base_url |
|
38 | + */ |
|
39 | + private $base_url = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * the key used for the URL param that denotes the current form step |
|
43 | + * defaults to 'ee-form-step' |
|
44 | + * |
|
45 | + * @var string $form_step_url_key |
|
46 | + */ |
|
47 | + private $form_step_url_key = ''; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var string $default_form_step |
|
51 | + */ |
|
52 | + private $default_form_step = ''; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var string $form_action |
|
56 | + */ |
|
57 | + private $form_action; |
|
58 | + |
|
59 | + /** |
|
60 | + * value of one of the string constant above |
|
61 | + * |
|
62 | + * @var string $form_config |
|
63 | + */ |
|
64 | + private $form_config; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var string $progress_step_style |
|
68 | + */ |
|
69 | + private $progress_step_style = ''; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var RequestInterface $request |
|
73 | + */ |
|
74 | + private $request; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var Collection $form_steps |
|
78 | + */ |
|
79 | + protected $form_steps; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var ProgressStepManager $progress_step_manager |
|
83 | + */ |
|
84 | + protected $progress_step_manager; |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @return Collection|null |
|
89 | + */ |
|
90 | + abstract protected function getFormStepsCollection(); |
|
91 | + |
|
92 | + // phpcs:disable PEAR.Functions.ValidDefaultValue.NotAtEnd |
|
93 | + /** |
|
94 | + * StepsManager constructor |
|
95 | + * |
|
96 | + * @param string $base_url |
|
97 | + * @param string $default_form_step |
|
98 | + * @param string $form_action |
|
99 | + * @param string $form_config |
|
100 | + * @param EE_Request|RequestInterface|null $request |
|
101 | + * @param string $progress_step_style |
|
102 | + * @throws InvalidDataTypeException |
|
103 | + * @throws InvalidArgumentException |
|
104 | + */ |
|
105 | + public function __construct( |
|
106 | + $base_url, |
|
107 | + $default_form_step, |
|
108 | + $form_action = '', |
|
109 | + $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT, |
|
110 | + $progress_step_style = 'number_bubbles', |
|
111 | + $request = null |
|
112 | + ) { |
|
113 | + $this->setBaseUrl($base_url); |
|
114 | + $this->setDefaultFormStep($default_form_step); |
|
115 | + $this->setFormAction($form_action); |
|
116 | + $this->setFormConfig($form_config); |
|
117 | + $this->setProgressStepStyle($progress_step_style); |
|
118 | + $this->request = $request instanceof RequestInterface |
|
119 | + ? $request |
|
120 | + : LoaderFactory::getLoader()->getShared('EventEspresso\core\services\request\RequestInterface'); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @return string |
|
126 | + * @throws InvalidFormHandlerException |
|
127 | + */ |
|
128 | + public function baseUrl() |
|
129 | + { |
|
130 | + if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) { |
|
131 | + add_query_arg( |
|
132 | + array($this->form_step_url_key => $this->getCurrentStep()->slug()), |
|
133 | + $this->base_url |
|
134 | + ); |
|
135 | + } |
|
136 | + return $this->base_url; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @param string $base_url |
|
142 | + * @throws InvalidDataTypeException |
|
143 | + * @throws InvalidArgumentException |
|
144 | + */ |
|
145 | + protected function setBaseUrl($base_url) |
|
146 | + { |
|
147 | + if (! is_string($base_url)) { |
|
148 | + throw new InvalidDataTypeException('$base_url', $base_url, 'string'); |
|
149 | + } |
|
150 | + if (empty($base_url)) { |
|
151 | + throw new InvalidArgumentException( |
|
152 | + esc_html__('The base URL can not be an empty string.', 'event_espresso') |
|
153 | + ); |
|
154 | + } |
|
155 | + $this->base_url = $base_url; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @return string |
|
161 | + * @throws InvalidDataTypeException |
|
162 | + */ |
|
163 | + public function formStepUrlKey() |
|
164 | + { |
|
165 | + if (empty($this->form_step_url_key)) { |
|
166 | + $this->setFormStepUrlKey(); |
|
167 | + } |
|
168 | + return $this->form_step_url_key; |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * @param string $form_step_url_key |
|
174 | + * @throws InvalidDataTypeException |
|
175 | + */ |
|
176 | + public function setFormStepUrlKey($form_step_url_key = 'ee-form-step') |
|
177 | + { |
|
178 | + if (! is_string($form_step_url_key)) { |
|
179 | + throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string'); |
|
180 | + } |
|
181 | + $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step'; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @return string |
|
187 | + */ |
|
188 | + public function defaultFormStep() |
|
189 | + { |
|
190 | + return $this->default_form_step; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @param $default_form_step |
|
196 | + * @throws InvalidDataTypeException |
|
197 | + */ |
|
198 | + protected function setDefaultFormStep($default_form_step) |
|
199 | + { |
|
200 | + if (! is_string($default_form_step)) { |
|
201 | + throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string'); |
|
202 | + } |
|
203 | + $this->default_form_step = $default_form_step; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * @return void |
|
209 | + * @throws InvalidIdentifierException |
|
210 | + * @throws InvalidDataTypeException |
|
211 | + */ |
|
212 | + protected function setCurrentStepFromRequest() |
|
213 | + { |
|
214 | + $current_step_slug = $this->request()->getRequestParam($this->formStepUrlKey(), $this->defaultFormStep()); |
|
215 | + if (! $this->form_steps->setCurrent($current_step_slug)) { |
|
216 | + throw new InvalidIdentifierException( |
|
217 | + $current_step_slug, |
|
218 | + $this->defaultFormStep(), |
|
219 | + sprintf( |
|
220 | + esc_html__('The "%1$s" form step could not be set.', 'event_espresso'), |
|
221 | + $current_step_slug |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * @return SequentialStepFormInterface|object |
|
230 | + * @throws InvalidFormHandlerException |
|
231 | + */ |
|
232 | + public function getCurrentStep() |
|
233 | + { |
|
234 | + if (! $this->form_steps->current() instanceof SequentialStepForm) { |
|
235 | + throw new InvalidFormHandlerException($this->form_steps->current()); |
|
236 | + } |
|
237 | + return $this->form_steps->current(); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * @return string |
|
243 | + * @throws InvalidFormHandlerException |
|
244 | + */ |
|
245 | + public function formAction() |
|
246 | + { |
|
247 | + if (! is_string($this->form_action) || empty($this->form_action)) { |
|
248 | + $this->form_action = $this->baseUrl(); |
|
249 | + } |
|
250 | + return $this->form_action; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param string $form_action |
|
256 | + * @throws InvalidDataTypeException |
|
257 | + */ |
|
258 | + public function setFormAction($form_action) |
|
259 | + { |
|
260 | + if (! is_string($form_action)) { |
|
261 | + throw new InvalidDataTypeException('$form_action', $form_action, 'string'); |
|
262 | + } |
|
263 | + $this->form_action = $form_action; |
|
264 | + } |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * @param array $form_action_args |
|
269 | + * @throws InvalidDataTypeException |
|
270 | + * @throws InvalidFormHandlerException |
|
271 | + */ |
|
272 | + public function addFormActionArgs($form_action_args = array()) |
|
273 | + { |
|
274 | + if (! is_array($form_action_args)) { |
|
275 | + throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array'); |
|
276 | + } |
|
277 | + $form_action_args = ! empty($form_action_args) |
|
278 | + ? $form_action_args |
|
279 | + : array($this->formStepUrlKey() => $this->form_steps->current()->slug()); |
|
280 | + $this->getCurrentStep()->setFormAction( |
|
281 | + add_query_arg($form_action_args, $this->formAction()) |
|
282 | + ); |
|
283 | + $this->form_action = $this->getCurrentStep()->formAction(); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @return string |
|
289 | + */ |
|
290 | + public function formConfig() |
|
291 | + { |
|
292 | + return $this->form_config; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @param string $form_config |
|
298 | + */ |
|
299 | + public function setFormConfig($form_config) |
|
300 | + { |
|
301 | + $this->form_config = $form_config; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @return string |
|
307 | + */ |
|
308 | + public function progressStepStyle() |
|
309 | + { |
|
310 | + return $this->progress_step_style; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @param string $progress_step_style |
|
316 | + */ |
|
317 | + public function setProgressStepStyle($progress_step_style) |
|
318 | + { |
|
319 | + $this->progress_step_style = $progress_step_style; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @return RequestInterface |
|
325 | + */ |
|
326 | + public function request() |
|
327 | + { |
|
328 | + return $this->request; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * @return Collection|null |
|
334 | + * @throws InvalidInterfaceException |
|
335 | + */ |
|
336 | + protected function getProgressStepsCollection() |
|
337 | + { |
|
338 | + static $collection = null; |
|
339 | + if (! $collection instanceof ProgressStepCollection) { |
|
340 | + $collection = new ProgressStepCollection(); |
|
341 | + } |
|
342 | + return $collection; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param Collection $progress_steps_collection |
|
348 | + * @return ProgressStepManager |
|
349 | + * @throws InvalidInterfaceException |
|
350 | + * @throws InvalidClassException |
|
351 | + * @throws InvalidDataTypeException |
|
352 | + * @throws InvalidEntityException |
|
353 | + * @throws InvalidFormHandlerException |
|
354 | + */ |
|
355 | + protected function generateProgressSteps($progress_steps_collection) |
|
356 | + { |
|
357 | + $current_step = $this->getCurrentStep(); |
|
358 | + /** @var SequentialStepForm $form_step */ |
|
359 | + foreach ($this->form_steps as $form_step) { |
|
360 | + // is this step active ? |
|
361 | + if (! $form_step->initialize()) { |
|
362 | + continue; |
|
363 | + } |
|
364 | + $progress_steps_collection->add( |
|
365 | + new ProgressStep( |
|
366 | + $form_step->order(), |
|
367 | + $form_step->slug(), |
|
368 | + $form_step->slug(), |
|
369 | + $form_step->formName() |
|
370 | + ), |
|
371 | + $form_step->slug() |
|
372 | + ); |
|
373 | + } |
|
374 | + // set collection pointer back to current step |
|
375 | + $this->form_steps->setCurrentUsingObject($current_step); |
|
376 | + return new ProgressStepManager( |
|
377 | + $this->progressStepStyle(), |
|
378 | + $this->defaultFormStep(), |
|
379 | + $this->formStepUrlKey(), |
|
380 | + $progress_steps_collection |
|
381 | + ); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * @throws InvalidClassException |
|
387 | + * @throws InvalidDataTypeException |
|
388 | + * @throws InvalidEntityException |
|
389 | + * @throws InvalidIdentifierException |
|
390 | + * @throws InvalidInterfaceException |
|
391 | + * @throws InvalidArgumentException |
|
392 | + * @throws InvalidFormHandlerException |
|
393 | + */ |
|
394 | + public function buildForm() |
|
395 | + { |
|
396 | + $this->buildCurrentStepFormForDisplay(); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * @param array $form_data |
|
402 | + * @throws InvalidArgumentException |
|
403 | + * @throws InvalidClassException |
|
404 | + * @throws InvalidDataTypeException |
|
405 | + * @throws InvalidEntityException |
|
406 | + * @throws InvalidFormHandlerException |
|
407 | + * @throws InvalidIdentifierException |
|
408 | + * @throws InvalidInterfaceException |
|
409 | + */ |
|
410 | + public function processForm($form_data = array()) |
|
411 | + { |
|
412 | + $this->buildCurrentStepFormForProcessing(); |
|
413 | + $this->processCurrentStepForm($form_data); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * @throws InvalidClassException |
|
419 | + * @throws InvalidDataTypeException |
|
420 | + * @throws InvalidEntityException |
|
421 | + * @throws InvalidInterfaceException |
|
422 | + * @throws InvalidIdentifierException |
|
423 | + * @throws InvalidArgumentException |
|
424 | + * @throws InvalidFormHandlerException |
|
425 | + */ |
|
426 | + public function buildCurrentStepFormForDisplay() |
|
427 | + { |
|
428 | + $form_step = $this->buildCurrentStepForm(); |
|
429 | + // no displayable content ? then skip straight to processing |
|
430 | + if (! $form_step->displayable()) { |
|
431 | + $this->addFormActionArgs(); |
|
432 | + $form_step->setFormAction($this->formAction()); |
|
433 | + wp_safe_redirect($form_step->formAction()); |
|
434 | + } |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * @throws InvalidClassException |
|
440 | + * @throws InvalidDataTypeException |
|
441 | + * @throws InvalidEntityException |
|
442 | + * @throws InvalidInterfaceException |
|
443 | + * @throws InvalidIdentifierException |
|
444 | + * @throws InvalidArgumentException |
|
445 | + * @throws InvalidFormHandlerException |
|
446 | + */ |
|
447 | + public function buildCurrentStepFormForProcessing() |
|
448 | + { |
|
449 | + $this->buildCurrentStepForm(false); |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * @param bool $for_display |
|
455 | + * @return SequentialStepFormInterface |
|
456 | + * @throws InvalidArgumentException |
|
457 | + * @throws InvalidClassException |
|
458 | + * @throws InvalidDataTypeException |
|
459 | + * @throws InvalidEntityException |
|
460 | + * @throws InvalidFormHandlerException |
|
461 | + * @throws InvalidIdentifierException |
|
462 | + * @throws InvalidInterfaceException |
|
463 | + */ |
|
464 | + private function buildCurrentStepForm($for_display = true) |
|
465 | + { |
|
466 | + $this->form_steps = $this->getFormStepsCollection(); |
|
467 | + $this->setCurrentStepFromRequest(); |
|
468 | + $form_step = $this->getCurrentStep(); |
|
469 | + if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) { |
|
470 | + $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso')); |
|
471 | + } |
|
472 | + if ($for_display && $form_step->displayable()) { |
|
473 | + $this->progress_step_manager = $this->generateProgressSteps( |
|
474 | + $this->getProgressStepsCollection() |
|
475 | + ); |
|
476 | + $this->progress_step_manager->setCurrentStep( |
|
477 | + $form_step->slug() |
|
478 | + ); |
|
479 | + // mark all previous progress steps as completed |
|
480 | + $this->progress_step_manager->setPreviousStepsCompleted(); |
|
481 | + $this->progress_step_manager->enqueueStylesAndScripts(); |
|
482 | + $this->addFormActionArgs(); |
|
483 | + $form_step->setFormAction($this->formAction()); |
|
484 | + } else { |
|
485 | + $form_step->setRedirectUrl($this->baseUrl()); |
|
486 | + $form_step->addRedirectArgs( |
|
487 | + array($this->formStepUrlKey() => $this->form_steps->current()->slug()) |
|
488 | + ); |
|
489 | + } |
|
490 | + $form_step->generate(); |
|
491 | + if ($for_display) { |
|
492 | + $form_step->enqueueStylesAndScripts(); |
|
493 | + } |
|
494 | + return $form_step; |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * @param bool $return_as_string |
|
500 | + * @return string |
|
501 | + * @throws InvalidFormHandlerException |
|
502 | + */ |
|
503 | + public function displayProgressSteps($return_as_string = true) |
|
504 | + { |
|
505 | + $form_step = $this->getCurrentStep(); |
|
506 | + if (! $form_step->displayable()) { |
|
507 | + return ''; |
|
508 | + } |
|
509 | + $progress_steps = apply_filters( |
|
510 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps', |
|
511 | + '' |
|
512 | + ); |
|
513 | + $progress_steps .= $this->progress_step_manager->displaySteps(); |
|
514 | + $progress_steps .= apply_filters( |
|
515 | + 'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps', |
|
516 | + '' |
|
517 | + ); |
|
518 | + if ($return_as_string) { |
|
519 | + return $progress_steps; |
|
520 | + } |
|
521 | + echo wp_kses($progress_steps, AllowedTags::getWithFormTags()); |
|
522 | + return ''; |
|
523 | + } |
|
524 | + |
|
525 | + |
|
526 | + /** |
|
527 | + * @param bool $return_as_string |
|
528 | + * @return string |
|
529 | + * @throws InvalidFormHandlerException |
|
530 | + */ |
|
531 | + public function displayCurrentStepForm($return_as_string = true) |
|
532 | + { |
|
533 | + if ($return_as_string) { |
|
534 | + return $this->getCurrentStep()->display(); |
|
535 | + } |
|
536 | + echo wp_kses($this->getCurrentStep()->display(), AllowedTags::getWithFormTags()); |
|
537 | + return ''; |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @param array $form_data |
|
543 | + * @return void |
|
544 | + * @throws InvalidArgumentException |
|
545 | + * @throws InvalidDataTypeException |
|
546 | + * @throws InvalidFormHandlerException |
|
547 | + */ |
|
548 | + public function processCurrentStepForm($form_data = array()) |
|
549 | + { |
|
550 | + // grab instance of current step because after calling next() below, |
|
551 | + // any calls to getCurrentStep() will return the "next" step because we advanced |
|
552 | + $current_step = $this->getCurrentStep(); |
|
553 | + try { |
|
554 | + // form processing should either throw exceptions or return true |
|
555 | + $current_step->process($form_data); |
|
556 | + } catch (Exception $e) { |
|
557 | + // something went wrong, convert the Exception to an EE_Error |
|
558 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
559 | + // prevent redirect to next step or other if exception was thrown |
|
560 | + if ( |
|
561 | + $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP |
|
562 | + || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER |
|
563 | + ) { |
|
564 | + $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP); |
|
565 | + } |
|
566 | + } |
|
567 | + // save notices to a transient so that when we redirect back |
|
568 | + // to the display portion for this step |
|
569 | + // those notices can be displayed |
|
570 | + EE_Error::get_notices(false, true); |
|
571 | + $this->redirectForm($current_step); |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * handles where to go to next |
|
577 | + * |
|
578 | + * @param SequentialStepFormInterface $current_step |
|
579 | + * @throws InvalidArgumentException |
|
580 | + * @throws InvalidDataTypeException |
|
581 | + * @throws InvalidFormHandlerException |
|
582 | + */ |
|
583 | + public function redirectForm($current_step) |
|
584 | + { |
|
585 | + $redirect_step = $current_step; |
|
586 | + switch ($current_step->redirectTo()) { |
|
587 | + case SequentialStepForm::REDIRECT_TO_OTHER: |
|
588 | + // going somewhere else, so just check out now |
|
589 | + wp_safe_redirect($redirect_step->redirectUrl()); |
|
590 | + exit(); |
|
591 | + case SequentialStepForm::REDIRECT_TO_PREV_STEP: |
|
592 | + $redirect_step = $this->form_steps->previous(); |
|
593 | + break; |
|
594 | + case SequentialStepForm::REDIRECT_TO_NEXT_STEP: |
|
595 | + $this->form_steps->next(); |
|
596 | + if ($this->form_steps->valid()) { |
|
597 | + $redirect_step = $this->form_steps->current(); |
|
598 | + } |
|
599 | + break; |
|
600 | + case SequentialStepForm::REDIRECT_TO_CURRENT_STEP: |
|
601 | + default: |
|
602 | + // $redirect_step is already set |
|
603 | + } |
|
604 | + $current_step->setRedirectUrl($this->baseUrl()); |
|
605 | + $current_step->addRedirectArgs( |
|
606 | + // use the slug for whatever step we are redirecting too |
|
607 | + array($this->formStepUrlKey() => $redirect_step->slug()) |
|
608 | + ); |
|
609 | + wp_safe_redirect($current_step->redirectUrl()); |
|
610 | + exit(); |
|
611 | + } |
|
612 | 612 | } |