|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace EventEspresso\core\domain\services\registration\form\v1; |
|
4
|
|
|
|
|
5
|
|
|
use EE_Admin_Two_Column_Layout; |
|
6
|
|
|
use EE_Div_Per_Section_Layout; |
|
7
|
|
|
use EE_Error; |
|
8
|
|
|
use EE_Form_Section_HTML; |
|
9
|
|
|
use EE_Form_Section_Proper; |
|
10
|
|
|
use EE_Question; |
|
11
|
|
|
use EE_Question_Group; |
|
12
|
|
|
use EE_Registration; |
|
13
|
|
|
use EEH_HTML; |
|
14
|
|
|
use ReflectionException; |
|
15
|
|
|
|
|
16
|
|
|
class RegFormQuestionGroup extends EE_Form_Section_Proper |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var RegFormQuestionFactory |
|
20
|
|
|
*/ |
|
21
|
|
|
public $reg_form_question_factory; |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* RegFormQuestionGroup constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @param EE_Registration $registration |
|
28
|
|
|
* @param EE_Question_Group $question_group |
|
29
|
|
|
* @param bool $admin_request |
|
30
|
|
|
* @param RegFormQuestionFactory $reg_form_question_factory |
|
31
|
|
|
* @throws EE_Error |
|
32
|
|
|
* @throws ReflectionException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct( |
|
35
|
|
|
EE_Registration $registration, |
|
36
|
|
|
EE_Question_Group $question_group, |
|
37
|
|
|
bool $admin_request, |
|
38
|
|
|
RegFormQuestionFactory $reg_form_question_factory |
|
39
|
|
|
) { |
|
40
|
|
|
$this->reg_form_question_factory = $reg_form_question_factory; |
|
41
|
|
|
parent::__construct($this->generateFormArgs($registration, $question_group, $admin_request)); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param EE_Registration $registration |
|
47
|
|
|
* @param EE_Question_Group $question_group |
|
48
|
|
|
* @param bool $admin_request |
|
49
|
|
|
* @return array |
|
50
|
|
|
* @throws EE_Error |
|
51
|
|
|
* @throws ReflectionException |
|
52
|
|
|
*/ |
|
53
|
|
|
private function generateFormArgs( |
|
54
|
|
|
EE_Registration $registration, |
|
55
|
|
|
EE_Question_Group $question_group, |
|
56
|
|
|
bool $admin_request |
|
57
|
|
|
): array { |
|
58
|
|
|
// array of params to pass to parent constructor |
|
59
|
|
|
$form_args = [ |
|
60
|
|
|
'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' . $registration->ID(), |
|
61
|
|
|
'html_class' => $admin_request |
|
62
|
|
|
? 'form-table ee-reg-form-qstn-grp-dv' |
|
63
|
|
|
: 'ee-reg-form-qstn-grp-dv', |
|
64
|
|
|
'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-' |
|
65
|
|
|
. $registration->ID() . '-lbl', |
|
66
|
|
|
'subsections' => [ |
|
67
|
|
|
'reg_form_qstn_grp_hdr' => $this->questionGroupHeader($question_group, $admin_request), |
|
68
|
|
|
], |
|
69
|
|
|
'layout_strategy' => $admin_request |
|
70
|
|
|
? new EE_Admin_Two_Column_Layout() |
|
71
|
|
|
: new EE_Div_Per_Section_Layout(), |
|
72
|
|
|
]; |
|
73
|
|
|
// where params |
|
74
|
|
|
$query_params = ['QST_deleted' => 0]; |
|
75
|
|
|
// don't load admin only questions on the frontend |
|
76
|
|
|
if (! $admin_request) { |
|
77
|
|
|
$query_params['QST_admin_only'] = ['!=', true]; |
|
78
|
|
|
} |
|
79
|
|
|
$questions = $question_group->get_many_related( |
|
80
|
|
|
'Question', |
|
81
|
|
|
apply_filters( |
|
82
|
|
|
'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__related_questions_query_params', |
|
83
|
|
|
[ |
|
84
|
|
|
$query_params, |
|
85
|
|
|
'order_by' => [ |
|
86
|
|
|
'Question_Group_Question.QGQ_order' => 'ASC', |
|
87
|
|
|
], |
|
88
|
|
|
], |
|
89
|
|
|
$question_group, |
|
90
|
|
|
$registration, |
|
91
|
|
|
$this |
|
92
|
|
|
) |
|
93
|
|
|
); |
|
94
|
|
|
// filter for additional content before questions |
|
95
|
|
|
$form_args['subsections']['reg_form_questions_before'] = new EE_Form_Section_HTML( |
|
96
|
|
|
apply_filters( |
|
97
|
|
|
'FHEE__EEH_Form_Fields__generate_question_groups_html__before_question_group_questions', |
|
98
|
|
|
'', |
|
99
|
|
|
$registration, |
|
100
|
|
|
$question_group, |
|
101
|
|
|
$this |
|
102
|
|
|
) |
|
103
|
|
|
); |
|
104
|
|
|
// loop thru questions |
|
105
|
|
|
foreach ($questions as $question) { |
|
106
|
|
|
if ($question instanceof EE_Question) { |
|
107
|
|
|
$identifier = $question->is_system_question() |
|
108
|
|
|
? $question->system_ID() |
|
109
|
|
|
: $question->ID(); |
|
110
|
|
|
|
|
111
|
|
|
$form_args['subsections'][ $identifier ] = $this->reg_form_question_factory->create( |
|
112
|
|
|
$registration, |
|
113
|
|
|
$question |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
$form_args['subsections'] = apply_filters( |
|
118
|
|
|
'FHEE__EE_SPCO_Reg_Step_Attendee_Information__question_group_reg_form__subsections_array', |
|
119
|
|
|
$form_args['subsections'], |
|
120
|
|
|
$registration, |
|
121
|
|
|
$question_group, |
|
122
|
|
|
$this |
|
123
|
|
|
); |
|
124
|
|
|
// filter for additional content after questions |
|
125
|
|
|
$form_args['subsections']['reg_form_questions_after'] = new EE_Form_Section_HTML( |
|
126
|
|
|
apply_filters( |
|
127
|
|
|
'FHEE__EEH_Form_Fields__generate_question_groups_html__after_question_group_questions', |
|
128
|
|
|
'', |
|
129
|
|
|
$registration, |
|
130
|
|
|
$question_group, |
|
131
|
|
|
$this |
|
132
|
|
|
) |
|
133
|
|
|
); |
|
134
|
|
|
|
|
135
|
|
|
return $form_args; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @param EE_Question_Group $question_group |
|
141
|
|
|
* @param bool $admin_request |
|
142
|
|
|
* @return EE_Form_Section_HTML |
|
143
|
|
|
*/ |
|
144
|
|
|
private function questionGroupHeader(EE_Question_Group $question_group, bool $admin_request): EE_Form_Section_HTML |
|
145
|
|
|
{ |
|
146
|
|
|
$html = ''; |
|
147
|
|
|
// group_name |
|
148
|
|
|
if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
149
|
|
|
if ($admin_request) { |
|
150
|
|
|
$html .= EEH_HTML::br(); |
|
151
|
|
|
$html .= EEH_HTML::h3( |
|
152
|
|
|
$question_group->name(), |
|
153
|
|
|
'', |
|
154
|
|
|
'ee-reg-form-qstn-grp-title title', |
|
155
|
|
|
'font-size: 1.3em; padding-left:0;' |
|
156
|
|
|
); |
|
157
|
|
|
} else { |
|
158
|
|
|
$html .= EEH_HTML::h4( |
|
159
|
|
|
$question_group->name(), |
|
160
|
|
|
'', |
|
161
|
|
|
'ee-reg-form-qstn-grp-title section-title' |
|
162
|
|
|
); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
// group_desc |
|
166
|
|
|
if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
167
|
|
|
$html .= EEH_HTML::p( |
|
168
|
|
|
$question_group->desc(), |
|
169
|
|
|
'', |
|
170
|
|
|
$admin_request |
|
171
|
|
|
? 'ee-reg-form-qstn-grp-desc-pg' |
|
172
|
|
|
: 'ee-reg-form-qstn-grp-desc-pg small-text lt-grey-text' |
|
173
|
|
|
); |
|
174
|
|
|
} |
|
175
|
|
|
return new EE_Form_Section_HTML($html); |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|