@@ -103,7 +103,7 @@ |
||
103 | 103 | * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns |
104 | 104 | * EQG_additional. |
105 | 105 | * |
106 | - * @param string|boolean|int $context |
|
106 | + * @param boolean $context |
|
107 | 107 | * @return string |
108 | 108 | * @since 4.10.0.p |
109 | 109 | */ |
@@ -15,113 +15,113 @@ |
||
15 | 15 | class EEM_Event_Question_Group extends EEM_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Name of the field indicating an event should use the question group for the primary attendee |
|
20 | - */ |
|
21 | - const PRIMARY = 'EQG_primary'; |
|
18 | + /** |
|
19 | + * Name of the field indicating an event should use the question group for the primary attendee |
|
20 | + */ |
|
21 | + const PRIMARY = 'EQG_primary'; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Name of hte field indicating an event should use the question group for additional attendees |
|
25 | - */ |
|
26 | - const ADDITIONAL = 'EQG_additional'; |
|
23 | + /** |
|
24 | + * Name of hte field indicating an event should use the question group for additional attendees |
|
25 | + */ |
|
26 | + const ADDITIONAL = 'EQG_additional'; |
|
27 | 27 | |
28 | - // private instance of the Event_Question_Group object |
|
29 | - protected static $_instance = null; |
|
28 | + // private instance of the Event_Question_Group object |
|
29 | + protected static $_instance = null; |
|
30 | 30 | |
31 | 31 | |
32 | - protected function __construct($timezone = null) |
|
33 | - { |
|
34 | - $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
35 | - $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
36 | - $this->_tables = [ |
|
37 | - 'Event_Question_Group' => new EE_Primary_Table('esp_event_question_group', 'EQG_ID'), |
|
38 | - ]; |
|
39 | - $this->_fields = [ |
|
40 | - 'Event_Question_Group' => [ |
|
41 | - 'EQG_ID' => new EE_Primary_Key_Int_Field( |
|
42 | - 'EQG_ID', |
|
43 | - __('Event to Question Group Link ID', 'event_espresso') |
|
44 | - ), |
|
45 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | - 'EVT_ID', |
|
47 | - __('Event ID', 'event_espresso'), |
|
48 | - false, |
|
49 | - 0, |
|
50 | - 'Event' |
|
51 | - ), |
|
52 | - 'QSG_ID' => new EE_Foreign_Key_Int_Field( |
|
53 | - 'QSG_ID', |
|
54 | - __('Question Group Id', 'event_espresso'), |
|
55 | - false, |
|
56 | - 0, |
|
57 | - 'Question_Group' |
|
58 | - ), |
|
59 | - 'EQG_primary' => new EE_Boolean_Field( |
|
60 | - 'EQG_primary', |
|
61 | - __( |
|
62 | - 'Flag indicating question is only for primary attendees', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - false, |
|
66 | - false |
|
67 | - ), |
|
68 | - 'EQG_additional' => new EE_Boolean_Field( |
|
69 | - 'EQG_additional', |
|
70 | - __( |
|
71 | - 'Flag indicating question is only for additional attendees', |
|
72 | - 'event_espresso' |
|
73 | - ), |
|
74 | - false, |
|
75 | - false |
|
76 | - ), |
|
77 | - ], |
|
78 | - ]; |
|
79 | - $this->_model_relations = [ |
|
80 | - 'Event' => new EE_Belongs_To_Relation(), |
|
81 | - 'Question_Group' => new EE_Belongs_To_Relation(), |
|
82 | - ]; |
|
32 | + protected function __construct($timezone = null) |
|
33 | + { |
|
34 | + $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
35 | + $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
36 | + $this->_tables = [ |
|
37 | + 'Event_Question_Group' => new EE_Primary_Table('esp_event_question_group', 'EQG_ID'), |
|
38 | + ]; |
|
39 | + $this->_fields = [ |
|
40 | + 'Event_Question_Group' => [ |
|
41 | + 'EQG_ID' => new EE_Primary_Key_Int_Field( |
|
42 | + 'EQG_ID', |
|
43 | + __('Event to Question Group Link ID', 'event_espresso') |
|
44 | + ), |
|
45 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | + 'EVT_ID', |
|
47 | + __('Event ID', 'event_espresso'), |
|
48 | + false, |
|
49 | + 0, |
|
50 | + 'Event' |
|
51 | + ), |
|
52 | + 'QSG_ID' => new EE_Foreign_Key_Int_Field( |
|
53 | + 'QSG_ID', |
|
54 | + __('Question Group Id', 'event_espresso'), |
|
55 | + false, |
|
56 | + 0, |
|
57 | + 'Question_Group' |
|
58 | + ), |
|
59 | + 'EQG_primary' => new EE_Boolean_Field( |
|
60 | + 'EQG_primary', |
|
61 | + __( |
|
62 | + 'Flag indicating question is only for primary attendees', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + false, |
|
66 | + false |
|
67 | + ), |
|
68 | + 'EQG_additional' => new EE_Boolean_Field( |
|
69 | + 'EQG_additional', |
|
70 | + __( |
|
71 | + 'Flag indicating question is only for additional attendees', |
|
72 | + 'event_espresso' |
|
73 | + ), |
|
74 | + false, |
|
75 | + false |
|
76 | + ), |
|
77 | + ], |
|
78 | + ]; |
|
79 | + $this->_model_relations = [ |
|
80 | + 'Event' => new EE_Belongs_To_Relation(), |
|
81 | + 'Question_Group' => new EE_Belongs_To_Relation(), |
|
82 | + ]; |
|
83 | 83 | |
84 | - // this model is generally available for reading |
|
85 | - $path_to_event = 'Event'; |
|
84 | + // this model is generally available for reading |
|
85 | + $path_to_event = 'Event'; |
|
86 | 86 | |
87 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
88 | - new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
89 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
90 | - new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
91 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
92 | - new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
93 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
94 | - new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
87 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
88 | + new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
89 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
90 | + new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
91 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
92 | + new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
93 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
94 | + new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
95 | 95 | |
96 | - parent::__construct($timezone); |
|
97 | - } |
|
96 | + parent::__construct($timezone); |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - /** |
|
101 | - * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether |
|
102 | - * this is concerning primary attendees or additional attendees. |
|
103 | - * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns |
|
104 | - * EQG_additional. |
|
105 | - * |
|
106 | - * @param string|boolean|int $context |
|
107 | - * @return string |
|
108 | - * @since 4.10.0.p |
|
109 | - */ |
|
110 | - public function fieldNameForContext($context): string |
|
111 | - { |
|
112 | - // Basically do a strict switch statement. |
|
113 | - switch (true) { |
|
114 | - case $context === 'additional': |
|
115 | - case $context === false: |
|
116 | - case $context === 0: |
|
117 | - $field_name = EEM_Event_Question_Group::ADDITIONAL; |
|
118 | - break; |
|
119 | - case $context === 'primary': |
|
120 | - case $context === true: |
|
121 | - case $context === 1: |
|
122 | - default: |
|
123 | - $field_name = EEM_Event_Question_Group::PRIMARY; |
|
124 | - } |
|
125 | - return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context); |
|
126 | - } |
|
100 | + /** |
|
101 | + * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether |
|
102 | + * this is concerning primary attendees or additional attendees. |
|
103 | + * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns |
|
104 | + * EQG_additional. |
|
105 | + * |
|
106 | + * @param string|boolean|int $context |
|
107 | + * @return string |
|
108 | + * @since 4.10.0.p |
|
109 | + */ |
|
110 | + public function fieldNameForContext($context): string |
|
111 | + { |
|
112 | + // Basically do a strict switch statement. |
|
113 | + switch (true) { |
|
114 | + case $context === 'additional': |
|
115 | + case $context === false: |
|
116 | + case $context === 0: |
|
117 | + $field_name = EEM_Event_Question_Group::ADDITIONAL; |
|
118 | + break; |
|
119 | + case $context === 'primary': |
|
120 | + case $context === true: |
|
121 | + case $context === 1: |
|
122 | + default: |
|
123 | + $field_name = EEM_Event_Question_Group::PRIMARY; |
|
124 | + } |
|
125 | + return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context); |
|
126 | + } |
|
127 | 127 | } |
@@ -84,13 +84,13 @@ |
||
84 | 84 | // this model is generally available for reading |
85 | 85 | $path_to_event = 'Event'; |
86 | 86 | |
87 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
87 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = |
|
88 | 88 | new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
89 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
89 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
90 | 90 | new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
91 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
91 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
92 | 92 | new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
93 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
93 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
94 | 94 | new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
95 | 95 | |
96 | 96 | parent::__construct($timezone); |
@@ -571,7 +571,7 @@ |
||
571 | 571 | |
572 | 572 | |
573 | 573 | /** |
574 | - * @return array |
|
574 | + * @return EEM_Question |
|
575 | 575 | */ |
576 | 576 | public function question_descriptions() |
577 | 577 | { |
@@ -10,582 +10,582 @@ |
||
10 | 10 | class EEM_Question extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | 12 | |
13 | - // constant used to indicate that the question type is COUNTRY |
|
14 | - const QST_type_country = 'COUNTRY'; |
|
13 | + // constant used to indicate that the question type is COUNTRY |
|
14 | + const QST_type_country = 'COUNTRY'; |
|
15 | 15 | |
16 | - // constant used to indicate that the question type is DATE |
|
17 | - const QST_type_date = 'DATE'; |
|
18 | - |
|
19 | - // constant used to indicate that the question type is DROPDOWN |
|
20 | - const QST_type_dropdown = 'DROPDOWN'; |
|
21 | - |
|
22 | - // constant used to indicate that the question type is CHECKBOX |
|
23 | - const QST_type_checkbox = 'CHECKBOX'; |
|
24 | - |
|
25 | - // constant used to indicate that the question type is RADIO_BTN |
|
26 | - const QST_type_radio = 'RADIO_BTN'; |
|
27 | - |
|
28 | - // constant used to indicate that the question type is STATE |
|
29 | - const QST_type_state = 'STATE'; |
|
30 | - |
|
31 | - // constant used to indicate that the question type is TEXT |
|
32 | - const QST_type_text = 'TEXT'; |
|
33 | - |
|
34 | - // constant used to indicate that the question type is TEXTAREA |
|
35 | - const QST_type_textarea = 'TEXTAREA'; |
|
36 | - |
|
37 | - // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
38 | - const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
39 | - |
|
40 | - // constant used to indicate that the question type is an email input |
|
41 | - const QST_type_email = 'EMAIL'; |
|
42 | - |
|
43 | - // constant used to indicate that the question type is an email input |
|
44 | - const QST_type_email_confirm = 'EMAIL_CONFIRM'; |
|
45 | - |
|
46 | - // constant used to indicate that the question type is a US-formatted phone number |
|
47 | - const QST_type_us_phone = 'US_PHONE'; |
|
48 | - |
|
49 | - // constant used to indicate that the question type is an integer (whole number) |
|
50 | - const QST_type_int = 'INTEGER'; |
|
51 | - |
|
52 | - // constant used to indicate that the question type is a decimal (float) |
|
53 | - const QST_type_decimal = 'DECIMAL'; |
|
54 | - |
|
55 | - // constant used to indicate that the question type is a valid URL |
|
56 | - const QST_type_url = 'URL'; |
|
57 | - |
|
58 | - // constant used to indicate that the question type is a YEAR |
|
59 | - const QST_type_year = 'YEAR'; |
|
60 | - |
|
61 | - // constant used to indicate that the question type is a multi-select |
|
62 | - const QST_type_multi_select = 'MULTI_SELECT'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Question types that are interchangeable, even after answers have been provided for them. |
|
66 | - * Top-level keys are category slugs, next level is an array of question types. If question types |
|
67 | - * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
68 | - * |
|
69 | - * @access protected |
|
70 | - * @var array $_question_type_categories { |
|
71 | - * @type string $text |
|
72 | - * @type string $single -answer-enum |
|
73 | - * @type string $multi -answer-enum |
|
74 | - * } |
|
75 | - */ |
|
76 | - protected $_question_type_categories = []; |
|
77 | - |
|
78 | - /** |
|
79 | - * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
80 | - * |
|
81 | - * @access protected |
|
82 | - * @var array $_allowed_question_types |
|
83 | - */ |
|
84 | - protected $_allowed_question_types = []; |
|
85 | - |
|
86 | - /** |
|
87 | - * brief descriptions for all the question types |
|
88 | - * |
|
89 | - * @access protected |
|
90 | - * @var EEM_Question $_instance |
|
91 | - */ |
|
92 | - protected $_question_descriptions; |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Question types that should have an admin-defined max input length |
|
97 | - * |
|
98 | - * @var array |
|
99 | - */ |
|
100 | - protected $question_types_with_max_length; |
|
101 | - |
|
102 | - |
|
103 | - // private instance of the Attendee object |
|
104 | - protected static $_instance = null; |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * EEM_Question constructor. |
|
109 | - * |
|
110 | - * @param null $timezone |
|
111 | - */ |
|
112 | - protected function __construct($timezone = null) |
|
113 | - { |
|
114 | - $this->singular_item = esc_html__('Question', 'event_espresso'); |
|
115 | - $this->plural_item = esc_html__('Questions', 'event_espresso'); |
|
116 | - $this->_allowed_question_types = apply_filters( |
|
117 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
118 | - [ |
|
119 | - EEM_Question::QST_type_text => esc_html__('Text', 'event_espresso'), |
|
120 | - EEM_Question::QST_type_textarea => esc_html__('Textarea', 'event_espresso'), |
|
121 | - EEM_Question::QST_type_checkbox => esc_html__('Checkboxes', 'event_espresso'), |
|
122 | - EEM_Question::QST_type_radio => esc_html__('Radio Buttons', 'event_espresso'), |
|
123 | - EEM_Question::QST_type_dropdown => esc_html__('Dropdown', 'event_espresso'), |
|
124 | - EEM_Question::QST_type_state => esc_html__('State/Province Dropdown', 'event_espresso'), |
|
125 | - EEM_Question::QST_type_country => esc_html__('Country Dropdown', 'event_espresso'), |
|
126 | - EEM_Question::QST_type_date => esc_html__('Date Picker', 'event_espresso'), |
|
127 | - EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'), |
|
128 | - EEM_Question::QST_type_email => esc_html__('Email', 'event_espresso'), |
|
129 | - EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'), |
|
130 | - EEM_Question::QST_type_us_phone => esc_html__('USA - Format Phone', 'event_espresso'), |
|
131 | - EEM_Question::QST_type_decimal => esc_html__('Number', 'event_espresso'), |
|
132 | - EEM_Question::QST_type_int => esc_html__('Whole Number', 'event_espresso'), |
|
133 | - EEM_Question::QST_type_url => esc_html__('URL', 'event_espresso'), |
|
134 | - EEM_Question::QST_type_year => esc_html__('Year', 'event_espresso'), |
|
135 | - EEM_Question::QST_type_multi_select => esc_html__('Multi Select', 'event_espresso'), |
|
136 | - ] |
|
137 | - ); |
|
138 | - $this->_question_descriptions = apply_filters( |
|
139 | - 'FHEE__EEM_Question__construct__question_descriptions', |
|
140 | - [ |
|
141 | - EEM_Question::QST_type_text => esc_html__( |
|
142 | - 'A single line text input field', |
|
143 | - 'event_espresso' |
|
144 | - ), |
|
145 | - EEM_Question::QST_type_textarea => esc_html__( |
|
146 | - 'A multi line text input field', |
|
147 | - 'event_espresso' |
|
148 | - ), |
|
149 | - EEM_Question::QST_type_checkbox => esc_html__( |
|
150 | - 'Allows multiple preset options to be selected', |
|
151 | - 'event_espresso' |
|
152 | - ), |
|
153 | - EEM_Question::QST_type_radio => esc_html__( |
|
154 | - 'Allows a single preset option to be selected', |
|
155 | - 'event_espresso' |
|
156 | - ), |
|
157 | - EEM_Question::QST_type_dropdown => esc_html__( |
|
158 | - 'A dropdown that allows a single selection', |
|
159 | - 'event_espresso' |
|
160 | - ), |
|
161 | - EEM_Question::QST_type_state => esc_html__( |
|
162 | - 'A dropdown that lists states/provinces', |
|
163 | - 'event_espresso' |
|
164 | - ), |
|
165 | - EEM_Question::QST_type_country => esc_html__( |
|
166 | - 'A dropdown that lists countries', |
|
167 | - 'event_espresso' |
|
168 | - ), |
|
169 | - EEM_Question::QST_type_date => esc_html__( |
|
170 | - 'A popup calendar that allows date selections', |
|
171 | - 'event_espresso' |
|
172 | - ), |
|
173 | - EEM_Question::QST_type_html_textarea => esc_html__( |
|
174 | - 'A multi line text input field that allows HTML', |
|
175 | - 'event_espresso' |
|
176 | - ), |
|
177 | - EEM_Question::QST_type_email => esc_html__( |
|
178 | - 'A text field that must contain a valid Email address', |
|
179 | - 'event_espresso' |
|
180 | - ), |
|
181 | - EEM_Question::QST_type_email_confirm => esc_html__( |
|
182 | - 'A text field that must contain a valid Email address and be equal to Email field', |
|
183 | - 'event_espresso' |
|
184 | - ), |
|
185 | - EEM_Question::QST_type_us_phone => esc_html__( |
|
186 | - 'A text field that must contain a valid US phone number', |
|
187 | - 'event_espresso' |
|
188 | - ), |
|
189 | - EEM_Question::QST_type_decimal => esc_html__( |
|
190 | - 'A text field that allows number values with decimals', |
|
191 | - 'event_espresso' |
|
192 | - ), |
|
193 | - EEM_Question::QST_type_int => esc_html__( |
|
194 | - 'A text field that only allows whole numbers (no decimals)', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - EEM_Question::QST_type_url => esc_html__( |
|
198 | - 'A text field that must contain a valid URL', |
|
199 | - 'event_espresso' |
|
200 | - ), |
|
201 | - EEM_Question::QST_type_year => esc_html__( |
|
202 | - 'A dropdown that lists the last 100 years', |
|
203 | - 'event_espresso' |
|
204 | - ), |
|
205 | - EEM_Question::QST_type_multi_select => esc_html__( |
|
206 | - 'A dropdown that allows multiple selections', |
|
207 | - 'event_espresso' |
|
208 | - ), |
|
209 | - ] |
|
210 | - ); |
|
211 | - $this->_question_type_categories = (array)apply_filters( |
|
212 | - 'FHEE__EEM_Question__construct__question_type_categories', |
|
213 | - [ |
|
214 | - 'text' => [ |
|
215 | - EEM_Question::QST_type_text, |
|
216 | - EEM_Question::QST_type_textarea, |
|
217 | - EEM_Question::QST_type_date, |
|
218 | - EEM_Question::QST_type_html_textarea, |
|
219 | - EEM_Question::QST_type_email, |
|
220 | - EEM_Question::QST_type_email_confirm, |
|
221 | - EEM_Question::QST_type_us_phone, |
|
222 | - EEM_Question::QST_type_decimal, |
|
223 | - EEM_Question::QST_type_int, |
|
224 | - EEM_Question::QST_type_url, |
|
225 | - EEM_Question::QST_type_year, |
|
226 | - ], |
|
227 | - 'single-answer-enum' => [ |
|
228 | - EEM_Question::QST_type_radio, |
|
229 | - EEM_Question::QST_type_dropdown, |
|
230 | - ], |
|
231 | - 'multi-answer-enum' => [ |
|
232 | - EEM_Question::QST_type_checkbox, |
|
233 | - EEM_Question::QST_type_multi_select, |
|
234 | - ], |
|
235 | - ] |
|
236 | - ); |
|
237 | - $this->question_types_with_max_length = apply_filters( |
|
238 | - 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
239 | - [ |
|
240 | - EEM_Question::QST_type_text, |
|
241 | - EEM_Question::QST_type_textarea, |
|
242 | - EEM_Question::QST_type_html_textarea, |
|
243 | - ] |
|
244 | - ); |
|
245 | - |
|
246 | - $this->_tables = [ |
|
247 | - 'Question' => new EE_Primary_Table('esp_question', 'QST_ID'), |
|
248 | - ]; |
|
249 | - $this->_fields = [ |
|
250 | - 'Question' => [ |
|
251 | - 'QST_ID' => new EE_Primary_Key_Int_Field( |
|
252 | - 'QST_ID', |
|
253 | - esc_html__('Question ID', 'event_espresso') |
|
254 | - ), |
|
255 | - 'QST_display_text' => new EE_Post_Content_Field( |
|
256 | - 'QST_display_text', |
|
257 | - esc_html__('Question Text', 'event_espresso'), |
|
258 | - true, |
|
259 | - '' |
|
260 | - ), |
|
261 | - 'QST_admin_label' => new EE_Plain_Text_Field( |
|
262 | - 'QST_admin_label', |
|
263 | - esc_html__('Question Label (admin-only)', 'event_espresso'), |
|
264 | - true, |
|
265 | - '' |
|
266 | - ), |
|
267 | - 'QST_system' => new EE_Plain_Text_Field( |
|
268 | - 'QST_system', |
|
269 | - esc_html__('Internal string ID for question', 'event_espresso'), |
|
270 | - false, |
|
271 | - '' |
|
272 | - ), |
|
273 | - 'QST_type' => new EE_Enum_Text_Field( |
|
274 | - 'QST_type', |
|
275 | - esc_html__('Question Type', 'event_espresso'), |
|
276 | - false, |
|
277 | - 'TEXT', |
|
278 | - $this->_allowed_question_types |
|
279 | - ), |
|
280 | - 'QST_required' => new EE_Boolean_Field( |
|
281 | - 'QST_required', |
|
282 | - esc_html__('Required Question?', 'event_espresso'), |
|
283 | - false, |
|
284 | - false |
|
285 | - ), |
|
286 | - 'QST_required_text' => new EE_Simple_HTML_Field( |
|
287 | - 'QST_required_text', |
|
288 | - esc_html__('Text to Display if Not Provided', 'event_espresso'), |
|
289 | - true, |
|
290 | - '' |
|
291 | - ), |
|
292 | - 'QST_order' => new EE_Integer_Field( |
|
293 | - 'QST_order', |
|
294 | - esc_html__('Question Order', 'event_espresso'), |
|
295 | - false, |
|
296 | - 0 |
|
297 | - ), |
|
298 | - 'QST_admin_only' => new EE_Boolean_Field( |
|
299 | - 'QST_admin_only', |
|
300 | - esc_html__('Admin-Only Question?', 'event_espresso'), |
|
301 | - false, |
|
302 | - false |
|
303 | - ), |
|
304 | - 'QST_max' => new EE_Infinite_Integer_Field( |
|
305 | - 'QST_max', |
|
306 | - esc_html__('Max Size', 'event_espresso'), |
|
307 | - false, |
|
308 | - EE_INF |
|
309 | - ), |
|
310 | - 'QST_wp_user' => new EE_WP_User_Field( |
|
311 | - 'QST_wp_user', |
|
312 | - esc_html__('Question Creator ID', 'event_espresso'), |
|
313 | - false |
|
314 | - ), |
|
315 | - 'QST_deleted' => new EE_Trashed_Flag_Field( |
|
316 | - 'QST_deleted', |
|
317 | - esc_html__('Flag Indicating question was deleted', 'event_espresso'), |
|
318 | - false, |
|
319 | - false |
|
320 | - ), |
|
321 | - ], |
|
322 | - ]; |
|
323 | - $this->_model_relations = [ |
|
324 | - 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
325 | - 'Question_Option' => new EE_Has_Many_Relation(), |
|
326 | - 'Answer' => new EE_Has_Many_Relation(), |
|
327 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
328 | - // for QST_order column |
|
329 | - 'Question_Group_Question' => new EE_Has_Many_Relation(), |
|
330 | - ]; |
|
331 | - // this model is generally available for reading |
|
332 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
333 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
334 | - new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
335 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
336 | - new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
337 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
338 | - new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
339 | - parent::__construct($timezone); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * Returns the list of allowed question types, which are normally: |
|
345 | - * 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' but they can be extended |
|
346 | - * |
|
347 | - * @return string[] |
|
348 | - */ |
|
349 | - public function allowed_question_types(): array |
|
350 | - { |
|
351 | - return $this->_allowed_question_types; |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Gets all the question types in the same category |
|
357 | - * |
|
358 | - * @param string $question_type one of EEM_Question::allowed_question_types( |
|
359 | - * @return string[] like EEM_Question::allowed_question_types() |
|
360 | - */ |
|
361 | - public function question_types_in_same_category(string $question_type): array |
|
362 | - { |
|
363 | - $question_types = [$question_type]; |
|
364 | - foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
365 | - if (in_array($question_type, $question_types_in_category)) { |
|
366 | - $question_types = $question_types_in_category; |
|
367 | - break; |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * Determines if the given question type is in the given question type category |
|
377 | - * |
|
378 | - * @param string $question_type one of EEM_Question::allowed_question_types() |
|
379 | - * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
380 | - * @return boolean |
|
381 | - */ |
|
382 | - public function question_type_is_in_category(string $question_type, string $category): bool |
|
383 | - { |
|
384 | - if (! isset($this->_question_type_categories[ $category ])) { |
|
385 | - return false; |
|
386 | - } |
|
387 | - return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * Returns all the question types in the given category |
|
393 | - * |
|
394 | - * @param string $category |
|
395 | - * @return array|mixed |
|
396 | - */ |
|
397 | - public function question_types_in_category(string $category): array |
|
398 | - { |
|
399 | - if (isset($this->_question_type_categories[ $category ])) { |
|
400 | - return $this->_question_type_categories[ $category ]; |
|
401 | - } |
|
402 | - return []; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * Returns all the question types that should have question options |
|
408 | - * |
|
409 | - * @return array |
|
410 | - */ |
|
411 | - public function question_types_with_options(): array |
|
412 | - { |
|
413 | - return array_merge( |
|
414 | - $this->question_types_in_category('single-answer-enum'), |
|
415 | - $this->question_types_in_category('multi-answer-enum') |
|
416 | - ); |
|
417 | - } |
|
418 | - |
|
419 | - |
|
420 | - /** |
|
421 | - * Returns the question type categories 2d array |
|
422 | - * |
|
423 | - * @return array see EEM_Question::_question_type_categories |
|
424 | - */ |
|
425 | - public function question_type_categories(): array |
|
426 | - { |
|
427 | - return $this->_question_type_categories; |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * Returns an array of all the QST_system values that can be allowed in the system question group |
|
433 | - * identified by $system_question_group_id |
|
434 | - * |
|
435 | - * @param string $system_question_group_id QSG_system |
|
436 | - * @return array of system question names (QST_system) |
|
437 | - */ |
|
438 | - public function allowed_system_questions_in_system_question_group(string $system_question_group_id): array |
|
439 | - { |
|
440 | - $question_system_ids = []; |
|
441 | - switch ($system_question_group_id) { |
|
442 | - case EEM_Question_Group::system_personal: |
|
443 | - $question_system_ids = [ |
|
444 | - EEM_Attendee::system_question_fname, |
|
445 | - EEM_Attendee::system_question_lname, |
|
446 | - EEM_Attendee::system_question_email, |
|
447 | - EEM_Attendee::system_question_email_confirm, |
|
448 | - EEM_Attendee::system_question_phone, |
|
449 | - ]; |
|
450 | - break; |
|
451 | - case EEM_Question_Group::system_address: |
|
452 | - $question_system_ids = [ |
|
453 | - EEM_Attendee::system_question_address, |
|
454 | - EEM_Attendee::system_question_address2, |
|
455 | - EEM_Attendee::system_question_city, |
|
456 | - EEM_Attendee::system_question_state, |
|
457 | - EEM_Attendee::system_question_country, |
|
458 | - EEM_Attendee::system_question_zip, |
|
459 | - EEM_Attendee::system_question_phone, |
|
460 | - ]; |
|
461 | - break; |
|
462 | - } |
|
463 | - return apply_filters( |
|
464 | - 'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', |
|
465 | - $question_system_ids, |
|
466 | - $system_question_group_id |
|
467 | - ); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * Returns an array of all the QST_system values that are required in the system question group |
|
473 | - * identified by $system_question_group_id |
|
474 | - * |
|
475 | - * @param string $system_question_group_id QSG_system |
|
476 | - * @return array of system question names (QST_system) |
|
477 | - */ |
|
478 | - public function required_system_questions_in_system_question_group(string $system_question_group_id): array |
|
479 | - { |
|
480 | - $question_system_ids = null; |
|
481 | - switch ($system_question_group_id) { |
|
482 | - case EEM_Question_Group::system_personal: |
|
483 | - $question_system_ids = [ |
|
484 | - EEM_Attendee::system_question_fname, |
|
485 | - EEM_Attendee::system_question_email, |
|
486 | - ]; |
|
487 | - break; |
|
488 | - default: |
|
489 | - $question_system_ids = []; |
|
490 | - } |
|
491 | - return apply_filters( |
|
492 | - 'FHEE__EEM_Question__system_questions_required_in_system_question_group', |
|
493 | - $question_system_ids, |
|
494 | - $system_question_group_id |
|
495 | - ); |
|
496 | - } |
|
497 | - |
|
498 | - |
|
499 | - /** |
|
500 | - * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
501 | - * which system question QST_ID corresponds to the QST_system 'city', use |
|
502 | - * EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
503 | - * |
|
504 | - * @param $QST_system |
|
505 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
506 | - * @throws EE_Error |
|
507 | - */ |
|
508 | - public function get_Question_ID_from_system_string($QST_system): int |
|
509 | - { |
|
510 | - return $this->get_var([['QST_system' => $QST_system]]); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * searches the db for the question with the latest question order and returns that value. |
|
516 | - * |
|
517 | - * @access public |
|
518 | - * @return int |
|
519 | - * @throws EE_Error |
|
520 | - */ |
|
521 | - public function get_latest_question_order(): int |
|
522 | - { |
|
523 | - $columns_to_select = [ |
|
524 | - 'max_order' => ["MAX(QST_order)", "%d"], |
|
525 | - ]; |
|
526 | - $max = $this->_get_all_wpdb_results([], ARRAY_A, $columns_to_select); |
|
527 | - return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - /** |
|
532 | - * Returns an array where keys are system question QST_system values, |
|
533 | - * and values are the highest question max the admin can set on the question |
|
534 | - * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
535 | - * of 5, but no larger than 12) |
|
536 | - * |
|
537 | - * @return array |
|
538 | - */ |
|
539 | - public function system_question_maxes(): array |
|
540 | - { |
|
541 | - return [ |
|
542 | - 'fname' => 45, |
|
543 | - 'lname' => 45, |
|
544 | - 'address' => 255, |
|
545 | - 'address2' => 255, |
|
546 | - 'city' => 45, |
|
547 | - 'zip' => 12, |
|
548 | - 'email' => 255, |
|
549 | - 'email_confirm' => 255, |
|
550 | - 'phone' => 45, |
|
551 | - ]; |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * Given a QST_system value, gets the question's largest allowable max input. |
|
557 | - * |
|
558 | - * @param string $system_question_value |
|
559 | - * @return int|float |
|
560 | - * @see Registration_Form_Admin_Page::system_question_maxes() |
|
561 | - */ |
|
562 | - public function absolute_max_for_system_question(string $system_question_value) |
|
563 | - { |
|
564 | - $maxes = $this->system_question_maxes(); |
|
565 | - if (isset($maxes[ $system_question_value ])) { |
|
566 | - return $maxes[ $system_question_value ]; |
|
567 | - } else { |
|
568 | - return EE_INF; |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * @return array |
|
575 | - */ |
|
576 | - public function question_descriptions() |
|
577 | - { |
|
578 | - return $this->_question_descriptions; |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Returns all the question types that should have an admin-defined max input length |
|
584 | - * |
|
585 | - * @return array |
|
586 | - */ |
|
587 | - public function questionTypesWithMaxLength(): array |
|
588 | - { |
|
589 | - return (array)$this->question_types_with_max_length; |
|
590 | - } |
|
16 | + // constant used to indicate that the question type is DATE |
|
17 | + const QST_type_date = 'DATE'; |
|
18 | + |
|
19 | + // constant used to indicate that the question type is DROPDOWN |
|
20 | + const QST_type_dropdown = 'DROPDOWN'; |
|
21 | + |
|
22 | + // constant used to indicate that the question type is CHECKBOX |
|
23 | + const QST_type_checkbox = 'CHECKBOX'; |
|
24 | + |
|
25 | + // constant used to indicate that the question type is RADIO_BTN |
|
26 | + const QST_type_radio = 'RADIO_BTN'; |
|
27 | + |
|
28 | + // constant used to indicate that the question type is STATE |
|
29 | + const QST_type_state = 'STATE'; |
|
30 | + |
|
31 | + // constant used to indicate that the question type is TEXT |
|
32 | + const QST_type_text = 'TEXT'; |
|
33 | + |
|
34 | + // constant used to indicate that the question type is TEXTAREA |
|
35 | + const QST_type_textarea = 'TEXTAREA'; |
|
36 | + |
|
37 | + // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
38 | + const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
39 | + |
|
40 | + // constant used to indicate that the question type is an email input |
|
41 | + const QST_type_email = 'EMAIL'; |
|
42 | + |
|
43 | + // constant used to indicate that the question type is an email input |
|
44 | + const QST_type_email_confirm = 'EMAIL_CONFIRM'; |
|
45 | + |
|
46 | + // constant used to indicate that the question type is a US-formatted phone number |
|
47 | + const QST_type_us_phone = 'US_PHONE'; |
|
48 | + |
|
49 | + // constant used to indicate that the question type is an integer (whole number) |
|
50 | + const QST_type_int = 'INTEGER'; |
|
51 | + |
|
52 | + // constant used to indicate that the question type is a decimal (float) |
|
53 | + const QST_type_decimal = 'DECIMAL'; |
|
54 | + |
|
55 | + // constant used to indicate that the question type is a valid URL |
|
56 | + const QST_type_url = 'URL'; |
|
57 | + |
|
58 | + // constant used to indicate that the question type is a YEAR |
|
59 | + const QST_type_year = 'YEAR'; |
|
60 | + |
|
61 | + // constant used to indicate that the question type is a multi-select |
|
62 | + const QST_type_multi_select = 'MULTI_SELECT'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Question types that are interchangeable, even after answers have been provided for them. |
|
66 | + * Top-level keys are category slugs, next level is an array of question types. If question types |
|
67 | + * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
68 | + * |
|
69 | + * @access protected |
|
70 | + * @var array $_question_type_categories { |
|
71 | + * @type string $text |
|
72 | + * @type string $single -answer-enum |
|
73 | + * @type string $multi -answer-enum |
|
74 | + * } |
|
75 | + */ |
|
76 | + protected $_question_type_categories = []; |
|
77 | + |
|
78 | + /** |
|
79 | + * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
80 | + * |
|
81 | + * @access protected |
|
82 | + * @var array $_allowed_question_types |
|
83 | + */ |
|
84 | + protected $_allowed_question_types = []; |
|
85 | + |
|
86 | + /** |
|
87 | + * brief descriptions for all the question types |
|
88 | + * |
|
89 | + * @access protected |
|
90 | + * @var EEM_Question $_instance |
|
91 | + */ |
|
92 | + protected $_question_descriptions; |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Question types that should have an admin-defined max input length |
|
97 | + * |
|
98 | + * @var array |
|
99 | + */ |
|
100 | + protected $question_types_with_max_length; |
|
101 | + |
|
102 | + |
|
103 | + // private instance of the Attendee object |
|
104 | + protected static $_instance = null; |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * EEM_Question constructor. |
|
109 | + * |
|
110 | + * @param null $timezone |
|
111 | + */ |
|
112 | + protected function __construct($timezone = null) |
|
113 | + { |
|
114 | + $this->singular_item = esc_html__('Question', 'event_espresso'); |
|
115 | + $this->plural_item = esc_html__('Questions', 'event_espresso'); |
|
116 | + $this->_allowed_question_types = apply_filters( |
|
117 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
118 | + [ |
|
119 | + EEM_Question::QST_type_text => esc_html__('Text', 'event_espresso'), |
|
120 | + EEM_Question::QST_type_textarea => esc_html__('Textarea', 'event_espresso'), |
|
121 | + EEM_Question::QST_type_checkbox => esc_html__('Checkboxes', 'event_espresso'), |
|
122 | + EEM_Question::QST_type_radio => esc_html__('Radio Buttons', 'event_espresso'), |
|
123 | + EEM_Question::QST_type_dropdown => esc_html__('Dropdown', 'event_espresso'), |
|
124 | + EEM_Question::QST_type_state => esc_html__('State/Province Dropdown', 'event_espresso'), |
|
125 | + EEM_Question::QST_type_country => esc_html__('Country Dropdown', 'event_espresso'), |
|
126 | + EEM_Question::QST_type_date => esc_html__('Date Picker', 'event_espresso'), |
|
127 | + EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'), |
|
128 | + EEM_Question::QST_type_email => esc_html__('Email', 'event_espresso'), |
|
129 | + EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'), |
|
130 | + EEM_Question::QST_type_us_phone => esc_html__('USA - Format Phone', 'event_espresso'), |
|
131 | + EEM_Question::QST_type_decimal => esc_html__('Number', 'event_espresso'), |
|
132 | + EEM_Question::QST_type_int => esc_html__('Whole Number', 'event_espresso'), |
|
133 | + EEM_Question::QST_type_url => esc_html__('URL', 'event_espresso'), |
|
134 | + EEM_Question::QST_type_year => esc_html__('Year', 'event_espresso'), |
|
135 | + EEM_Question::QST_type_multi_select => esc_html__('Multi Select', 'event_espresso'), |
|
136 | + ] |
|
137 | + ); |
|
138 | + $this->_question_descriptions = apply_filters( |
|
139 | + 'FHEE__EEM_Question__construct__question_descriptions', |
|
140 | + [ |
|
141 | + EEM_Question::QST_type_text => esc_html__( |
|
142 | + 'A single line text input field', |
|
143 | + 'event_espresso' |
|
144 | + ), |
|
145 | + EEM_Question::QST_type_textarea => esc_html__( |
|
146 | + 'A multi line text input field', |
|
147 | + 'event_espresso' |
|
148 | + ), |
|
149 | + EEM_Question::QST_type_checkbox => esc_html__( |
|
150 | + 'Allows multiple preset options to be selected', |
|
151 | + 'event_espresso' |
|
152 | + ), |
|
153 | + EEM_Question::QST_type_radio => esc_html__( |
|
154 | + 'Allows a single preset option to be selected', |
|
155 | + 'event_espresso' |
|
156 | + ), |
|
157 | + EEM_Question::QST_type_dropdown => esc_html__( |
|
158 | + 'A dropdown that allows a single selection', |
|
159 | + 'event_espresso' |
|
160 | + ), |
|
161 | + EEM_Question::QST_type_state => esc_html__( |
|
162 | + 'A dropdown that lists states/provinces', |
|
163 | + 'event_espresso' |
|
164 | + ), |
|
165 | + EEM_Question::QST_type_country => esc_html__( |
|
166 | + 'A dropdown that lists countries', |
|
167 | + 'event_espresso' |
|
168 | + ), |
|
169 | + EEM_Question::QST_type_date => esc_html__( |
|
170 | + 'A popup calendar that allows date selections', |
|
171 | + 'event_espresso' |
|
172 | + ), |
|
173 | + EEM_Question::QST_type_html_textarea => esc_html__( |
|
174 | + 'A multi line text input field that allows HTML', |
|
175 | + 'event_espresso' |
|
176 | + ), |
|
177 | + EEM_Question::QST_type_email => esc_html__( |
|
178 | + 'A text field that must contain a valid Email address', |
|
179 | + 'event_espresso' |
|
180 | + ), |
|
181 | + EEM_Question::QST_type_email_confirm => esc_html__( |
|
182 | + 'A text field that must contain a valid Email address and be equal to Email field', |
|
183 | + 'event_espresso' |
|
184 | + ), |
|
185 | + EEM_Question::QST_type_us_phone => esc_html__( |
|
186 | + 'A text field that must contain a valid US phone number', |
|
187 | + 'event_espresso' |
|
188 | + ), |
|
189 | + EEM_Question::QST_type_decimal => esc_html__( |
|
190 | + 'A text field that allows number values with decimals', |
|
191 | + 'event_espresso' |
|
192 | + ), |
|
193 | + EEM_Question::QST_type_int => esc_html__( |
|
194 | + 'A text field that only allows whole numbers (no decimals)', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + EEM_Question::QST_type_url => esc_html__( |
|
198 | + 'A text field that must contain a valid URL', |
|
199 | + 'event_espresso' |
|
200 | + ), |
|
201 | + EEM_Question::QST_type_year => esc_html__( |
|
202 | + 'A dropdown that lists the last 100 years', |
|
203 | + 'event_espresso' |
|
204 | + ), |
|
205 | + EEM_Question::QST_type_multi_select => esc_html__( |
|
206 | + 'A dropdown that allows multiple selections', |
|
207 | + 'event_espresso' |
|
208 | + ), |
|
209 | + ] |
|
210 | + ); |
|
211 | + $this->_question_type_categories = (array)apply_filters( |
|
212 | + 'FHEE__EEM_Question__construct__question_type_categories', |
|
213 | + [ |
|
214 | + 'text' => [ |
|
215 | + EEM_Question::QST_type_text, |
|
216 | + EEM_Question::QST_type_textarea, |
|
217 | + EEM_Question::QST_type_date, |
|
218 | + EEM_Question::QST_type_html_textarea, |
|
219 | + EEM_Question::QST_type_email, |
|
220 | + EEM_Question::QST_type_email_confirm, |
|
221 | + EEM_Question::QST_type_us_phone, |
|
222 | + EEM_Question::QST_type_decimal, |
|
223 | + EEM_Question::QST_type_int, |
|
224 | + EEM_Question::QST_type_url, |
|
225 | + EEM_Question::QST_type_year, |
|
226 | + ], |
|
227 | + 'single-answer-enum' => [ |
|
228 | + EEM_Question::QST_type_radio, |
|
229 | + EEM_Question::QST_type_dropdown, |
|
230 | + ], |
|
231 | + 'multi-answer-enum' => [ |
|
232 | + EEM_Question::QST_type_checkbox, |
|
233 | + EEM_Question::QST_type_multi_select, |
|
234 | + ], |
|
235 | + ] |
|
236 | + ); |
|
237 | + $this->question_types_with_max_length = apply_filters( |
|
238 | + 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
239 | + [ |
|
240 | + EEM_Question::QST_type_text, |
|
241 | + EEM_Question::QST_type_textarea, |
|
242 | + EEM_Question::QST_type_html_textarea, |
|
243 | + ] |
|
244 | + ); |
|
245 | + |
|
246 | + $this->_tables = [ |
|
247 | + 'Question' => new EE_Primary_Table('esp_question', 'QST_ID'), |
|
248 | + ]; |
|
249 | + $this->_fields = [ |
|
250 | + 'Question' => [ |
|
251 | + 'QST_ID' => new EE_Primary_Key_Int_Field( |
|
252 | + 'QST_ID', |
|
253 | + esc_html__('Question ID', 'event_espresso') |
|
254 | + ), |
|
255 | + 'QST_display_text' => new EE_Post_Content_Field( |
|
256 | + 'QST_display_text', |
|
257 | + esc_html__('Question Text', 'event_espresso'), |
|
258 | + true, |
|
259 | + '' |
|
260 | + ), |
|
261 | + 'QST_admin_label' => new EE_Plain_Text_Field( |
|
262 | + 'QST_admin_label', |
|
263 | + esc_html__('Question Label (admin-only)', 'event_espresso'), |
|
264 | + true, |
|
265 | + '' |
|
266 | + ), |
|
267 | + 'QST_system' => new EE_Plain_Text_Field( |
|
268 | + 'QST_system', |
|
269 | + esc_html__('Internal string ID for question', 'event_espresso'), |
|
270 | + false, |
|
271 | + '' |
|
272 | + ), |
|
273 | + 'QST_type' => new EE_Enum_Text_Field( |
|
274 | + 'QST_type', |
|
275 | + esc_html__('Question Type', 'event_espresso'), |
|
276 | + false, |
|
277 | + 'TEXT', |
|
278 | + $this->_allowed_question_types |
|
279 | + ), |
|
280 | + 'QST_required' => new EE_Boolean_Field( |
|
281 | + 'QST_required', |
|
282 | + esc_html__('Required Question?', 'event_espresso'), |
|
283 | + false, |
|
284 | + false |
|
285 | + ), |
|
286 | + 'QST_required_text' => new EE_Simple_HTML_Field( |
|
287 | + 'QST_required_text', |
|
288 | + esc_html__('Text to Display if Not Provided', 'event_espresso'), |
|
289 | + true, |
|
290 | + '' |
|
291 | + ), |
|
292 | + 'QST_order' => new EE_Integer_Field( |
|
293 | + 'QST_order', |
|
294 | + esc_html__('Question Order', 'event_espresso'), |
|
295 | + false, |
|
296 | + 0 |
|
297 | + ), |
|
298 | + 'QST_admin_only' => new EE_Boolean_Field( |
|
299 | + 'QST_admin_only', |
|
300 | + esc_html__('Admin-Only Question?', 'event_espresso'), |
|
301 | + false, |
|
302 | + false |
|
303 | + ), |
|
304 | + 'QST_max' => new EE_Infinite_Integer_Field( |
|
305 | + 'QST_max', |
|
306 | + esc_html__('Max Size', 'event_espresso'), |
|
307 | + false, |
|
308 | + EE_INF |
|
309 | + ), |
|
310 | + 'QST_wp_user' => new EE_WP_User_Field( |
|
311 | + 'QST_wp_user', |
|
312 | + esc_html__('Question Creator ID', 'event_espresso'), |
|
313 | + false |
|
314 | + ), |
|
315 | + 'QST_deleted' => new EE_Trashed_Flag_Field( |
|
316 | + 'QST_deleted', |
|
317 | + esc_html__('Flag Indicating question was deleted', 'event_espresso'), |
|
318 | + false, |
|
319 | + false |
|
320 | + ), |
|
321 | + ], |
|
322 | + ]; |
|
323 | + $this->_model_relations = [ |
|
324 | + 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
325 | + 'Question_Option' => new EE_Has_Many_Relation(), |
|
326 | + 'Answer' => new EE_Has_Many_Relation(), |
|
327 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
328 | + // for QST_order column |
|
329 | + 'Question_Group_Question' => new EE_Has_Many_Relation(), |
|
330 | + ]; |
|
331 | + // this model is generally available for reading |
|
332 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
333 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
334 | + new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
335 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
336 | + new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
337 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
338 | + new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
339 | + parent::__construct($timezone); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * Returns the list of allowed question types, which are normally: |
|
345 | + * 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' but they can be extended |
|
346 | + * |
|
347 | + * @return string[] |
|
348 | + */ |
|
349 | + public function allowed_question_types(): array |
|
350 | + { |
|
351 | + return $this->_allowed_question_types; |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Gets all the question types in the same category |
|
357 | + * |
|
358 | + * @param string $question_type one of EEM_Question::allowed_question_types( |
|
359 | + * @return string[] like EEM_Question::allowed_question_types() |
|
360 | + */ |
|
361 | + public function question_types_in_same_category(string $question_type): array |
|
362 | + { |
|
363 | + $question_types = [$question_type]; |
|
364 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
365 | + if (in_array($question_type, $question_types_in_category)) { |
|
366 | + $question_types = $question_types_in_category; |
|
367 | + break; |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * Determines if the given question type is in the given question type category |
|
377 | + * |
|
378 | + * @param string $question_type one of EEM_Question::allowed_question_types() |
|
379 | + * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
380 | + * @return boolean |
|
381 | + */ |
|
382 | + public function question_type_is_in_category(string $question_type, string $category): bool |
|
383 | + { |
|
384 | + if (! isset($this->_question_type_categories[ $category ])) { |
|
385 | + return false; |
|
386 | + } |
|
387 | + return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * Returns all the question types in the given category |
|
393 | + * |
|
394 | + * @param string $category |
|
395 | + * @return array|mixed |
|
396 | + */ |
|
397 | + public function question_types_in_category(string $category): array |
|
398 | + { |
|
399 | + if (isset($this->_question_type_categories[ $category ])) { |
|
400 | + return $this->_question_type_categories[ $category ]; |
|
401 | + } |
|
402 | + return []; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * Returns all the question types that should have question options |
|
408 | + * |
|
409 | + * @return array |
|
410 | + */ |
|
411 | + public function question_types_with_options(): array |
|
412 | + { |
|
413 | + return array_merge( |
|
414 | + $this->question_types_in_category('single-answer-enum'), |
|
415 | + $this->question_types_in_category('multi-answer-enum') |
|
416 | + ); |
|
417 | + } |
|
418 | + |
|
419 | + |
|
420 | + /** |
|
421 | + * Returns the question type categories 2d array |
|
422 | + * |
|
423 | + * @return array see EEM_Question::_question_type_categories |
|
424 | + */ |
|
425 | + public function question_type_categories(): array |
|
426 | + { |
|
427 | + return $this->_question_type_categories; |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * Returns an array of all the QST_system values that can be allowed in the system question group |
|
433 | + * identified by $system_question_group_id |
|
434 | + * |
|
435 | + * @param string $system_question_group_id QSG_system |
|
436 | + * @return array of system question names (QST_system) |
|
437 | + */ |
|
438 | + public function allowed_system_questions_in_system_question_group(string $system_question_group_id): array |
|
439 | + { |
|
440 | + $question_system_ids = []; |
|
441 | + switch ($system_question_group_id) { |
|
442 | + case EEM_Question_Group::system_personal: |
|
443 | + $question_system_ids = [ |
|
444 | + EEM_Attendee::system_question_fname, |
|
445 | + EEM_Attendee::system_question_lname, |
|
446 | + EEM_Attendee::system_question_email, |
|
447 | + EEM_Attendee::system_question_email_confirm, |
|
448 | + EEM_Attendee::system_question_phone, |
|
449 | + ]; |
|
450 | + break; |
|
451 | + case EEM_Question_Group::system_address: |
|
452 | + $question_system_ids = [ |
|
453 | + EEM_Attendee::system_question_address, |
|
454 | + EEM_Attendee::system_question_address2, |
|
455 | + EEM_Attendee::system_question_city, |
|
456 | + EEM_Attendee::system_question_state, |
|
457 | + EEM_Attendee::system_question_country, |
|
458 | + EEM_Attendee::system_question_zip, |
|
459 | + EEM_Attendee::system_question_phone, |
|
460 | + ]; |
|
461 | + break; |
|
462 | + } |
|
463 | + return apply_filters( |
|
464 | + 'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', |
|
465 | + $question_system_ids, |
|
466 | + $system_question_group_id |
|
467 | + ); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * Returns an array of all the QST_system values that are required in the system question group |
|
473 | + * identified by $system_question_group_id |
|
474 | + * |
|
475 | + * @param string $system_question_group_id QSG_system |
|
476 | + * @return array of system question names (QST_system) |
|
477 | + */ |
|
478 | + public function required_system_questions_in_system_question_group(string $system_question_group_id): array |
|
479 | + { |
|
480 | + $question_system_ids = null; |
|
481 | + switch ($system_question_group_id) { |
|
482 | + case EEM_Question_Group::system_personal: |
|
483 | + $question_system_ids = [ |
|
484 | + EEM_Attendee::system_question_fname, |
|
485 | + EEM_Attendee::system_question_email, |
|
486 | + ]; |
|
487 | + break; |
|
488 | + default: |
|
489 | + $question_system_ids = []; |
|
490 | + } |
|
491 | + return apply_filters( |
|
492 | + 'FHEE__EEM_Question__system_questions_required_in_system_question_group', |
|
493 | + $question_system_ids, |
|
494 | + $system_question_group_id |
|
495 | + ); |
|
496 | + } |
|
497 | + |
|
498 | + |
|
499 | + /** |
|
500 | + * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
501 | + * which system question QST_ID corresponds to the QST_system 'city', use |
|
502 | + * EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
503 | + * |
|
504 | + * @param $QST_system |
|
505 | + * @return int of QST_ID for the question that corresponds to that QST_system |
|
506 | + * @throws EE_Error |
|
507 | + */ |
|
508 | + public function get_Question_ID_from_system_string($QST_system): int |
|
509 | + { |
|
510 | + return $this->get_var([['QST_system' => $QST_system]]); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * searches the db for the question with the latest question order and returns that value. |
|
516 | + * |
|
517 | + * @access public |
|
518 | + * @return int |
|
519 | + * @throws EE_Error |
|
520 | + */ |
|
521 | + public function get_latest_question_order(): int |
|
522 | + { |
|
523 | + $columns_to_select = [ |
|
524 | + 'max_order' => ["MAX(QST_order)", "%d"], |
|
525 | + ]; |
|
526 | + $max = $this->_get_all_wpdb_results([], ARRAY_A, $columns_to_select); |
|
527 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + /** |
|
532 | + * Returns an array where keys are system question QST_system values, |
|
533 | + * and values are the highest question max the admin can set on the question |
|
534 | + * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
535 | + * of 5, but no larger than 12) |
|
536 | + * |
|
537 | + * @return array |
|
538 | + */ |
|
539 | + public function system_question_maxes(): array |
|
540 | + { |
|
541 | + return [ |
|
542 | + 'fname' => 45, |
|
543 | + 'lname' => 45, |
|
544 | + 'address' => 255, |
|
545 | + 'address2' => 255, |
|
546 | + 'city' => 45, |
|
547 | + 'zip' => 12, |
|
548 | + 'email' => 255, |
|
549 | + 'email_confirm' => 255, |
|
550 | + 'phone' => 45, |
|
551 | + ]; |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * Given a QST_system value, gets the question's largest allowable max input. |
|
557 | + * |
|
558 | + * @param string $system_question_value |
|
559 | + * @return int|float |
|
560 | + * @see Registration_Form_Admin_Page::system_question_maxes() |
|
561 | + */ |
|
562 | + public function absolute_max_for_system_question(string $system_question_value) |
|
563 | + { |
|
564 | + $maxes = $this->system_question_maxes(); |
|
565 | + if (isset($maxes[ $system_question_value ])) { |
|
566 | + return $maxes[ $system_question_value ]; |
|
567 | + } else { |
|
568 | + return EE_INF; |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * @return array |
|
575 | + */ |
|
576 | + public function question_descriptions() |
|
577 | + { |
|
578 | + return $this->_question_descriptions; |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Returns all the question types that should have an admin-defined max input length |
|
584 | + * |
|
585 | + * @return array |
|
586 | + */ |
|
587 | + public function questionTypesWithMaxLength(): array |
|
588 | + { |
|
589 | + return (array)$this->question_types_with_max_length; |
|
590 | + } |
|
591 | 591 | } |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | EEM_Question::QST_type_multi_select => esc_html__('Multi Select', 'event_espresso'), |
136 | 136 | ] |
137 | 137 | ); |
138 | - $this->_question_descriptions = apply_filters( |
|
138 | + $this->_question_descriptions = apply_filters( |
|
139 | 139 | 'FHEE__EEM_Question__construct__question_descriptions', |
140 | 140 | [ |
141 | 141 | EEM_Question::QST_type_text => esc_html__( |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | ), |
209 | 209 | ] |
210 | 210 | ); |
211 | - $this->_question_type_categories = (array)apply_filters( |
|
211 | + $this->_question_type_categories = (array) apply_filters( |
|
212 | 212 | 'FHEE__EEM_Question__construct__question_type_categories', |
213 | 213 | [ |
214 | 214 | 'text' => [ |
@@ -329,12 +329,12 @@ discard block |
||
329 | 329 | 'Question_Group_Question' => new EE_Has_Many_Relation(), |
330 | 330 | ]; |
331 | 331 | // this model is generally available for reading |
332 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
333 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
332 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
333 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
334 | 334 | new EE_Restriction_Generator_Reg_Form('QST_system'); |
335 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
335 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
336 | 336 | new EE_Restriction_Generator_Reg_Form('QST_system'); |
337 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
337 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
338 | 338 | new EE_Restriction_Generator_Reg_Form('QST_system'); |
339 | 339 | parent::__construct($timezone); |
340 | 340 | } |
@@ -381,10 +381,10 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public function question_type_is_in_category(string $question_type, string $category): bool |
383 | 383 | { |
384 | - if (! isset($this->_question_type_categories[ $category ])) { |
|
384 | + if ( ! isset($this->_question_type_categories[$category])) { |
|
385 | 385 | return false; |
386 | 386 | } |
387 | - return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
387 | + return in_array($question_type, $this->_question_type_categories[$category]); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | |
@@ -396,8 +396,8 @@ discard block |
||
396 | 396 | */ |
397 | 397 | public function question_types_in_category(string $category): array |
398 | 398 | { |
399 | - if (isset($this->_question_type_categories[ $category ])) { |
|
400 | - return $this->_question_type_categories[ $category ]; |
|
399 | + if (isset($this->_question_type_categories[$category])) { |
|
400 | + return $this->_question_type_categories[$category]; |
|
401 | 401 | } |
402 | 402 | return []; |
403 | 403 | } |
@@ -562,8 +562,8 @@ discard block |
||
562 | 562 | public function absolute_max_for_system_question(string $system_question_value) |
563 | 563 | { |
564 | 564 | $maxes = $this->system_question_maxes(); |
565 | - if (isset($maxes[ $system_question_value ])) { |
|
566 | - return $maxes[ $system_question_value ]; |
|
565 | + if (isset($maxes[$system_question_value])) { |
|
566 | + return $maxes[$system_question_value]; |
|
567 | 567 | } else { |
568 | 568 | return EE_INF; |
569 | 569 | } |
@@ -586,6 +586,6 @@ discard block |
||
586 | 586 | */ |
587 | 587 | public function questionTypesWithMaxLength(): array |
588 | 588 | { |
589 | - return (array)$this->question_types_with_max_length; |
|
589 | + return (array) $this->question_types_with_max_length; |
|
590 | 590 | } |
591 | 591 | } |
@@ -10,79 +10,79 @@ |
||
10 | 10 | class EEM_Question_Option extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | 12 | |
13 | - // private instance of the Attendee object |
|
14 | - protected static $_instance = null; |
|
13 | + // private instance of the Attendee object |
|
14 | + protected static $_instance = null; |
|
15 | 15 | |
16 | 16 | |
17 | - protected function __construct($timezone = null) |
|
18 | - { |
|
19 | - $this->singular_item = esc_html__('Question Option', 'event_espresso'); |
|
20 | - $this->plural_item = esc_html__('Question Options', 'event_espresso'); |
|
17 | + protected function __construct($timezone = null) |
|
18 | + { |
|
19 | + $this->singular_item = esc_html__('Question Option', 'event_espresso'); |
|
20 | + $this->plural_item = esc_html__('Question Options', 'event_espresso'); |
|
21 | 21 | |
22 | - $this->_tables = [ |
|
23 | - 'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'), |
|
24 | - ]; |
|
25 | - $this->_fields = [ |
|
26 | - 'Question_Option' => [ |
|
27 | - 'QSO_ID' => new EE_Primary_Key_Int_Field( |
|
28 | - 'QSO_ID', esc_html__('Question Option ID', 'event_espresso') |
|
29 | - ), |
|
30 | - 'QST_ID' => new EE_Foreign_Key_Int_Field( |
|
31 | - 'QST_ID', |
|
32 | - esc_html__('Question ID', 'event_espresso'), |
|
33 | - false, |
|
34 | - 0, |
|
35 | - 'Question' |
|
36 | - ), |
|
37 | - 'QSO_value' => new EE_Plain_Text_Field( |
|
38 | - 'QSO_value', |
|
39 | - esc_html__("Question Option Value", "event_espresso"), |
|
40 | - false, |
|
41 | - '' |
|
42 | - ), |
|
43 | - 'QSO_desc' => new EE_Post_Content_Field( |
|
44 | - 'QSO_desc', |
|
45 | - esc_html__('Question Option Description', 'event_espresso'), |
|
46 | - false, |
|
47 | - '' |
|
48 | - ), |
|
49 | - 'QSO_order' => new EE_Integer_Field( |
|
50 | - 'QSO_order', |
|
51 | - esc_html__('Question Option Order', 'event_espresso'), |
|
52 | - false, |
|
53 | - 0 |
|
54 | - ), |
|
55 | - 'QSO_system' => new EE_Plain_Text_Field( |
|
56 | - 'QSO_system', |
|
57 | - esc_html__('Internal string ID for question option', 'event_espresso'), |
|
58 | - true, |
|
59 | - null |
|
60 | - ), |
|
61 | - 'QSO_deleted' => new EE_Trashed_Flag_Field( |
|
62 | - 'QSO_deleted', |
|
63 | - esc_html__('Flag indicating Option was trashed', 'event_espresso'), |
|
64 | - false, |
|
65 | - false |
|
66 | - ), |
|
67 | - ], |
|
68 | - ]; |
|
69 | - $this->_model_relations = [ |
|
70 | - 'Question' => new EE_Belongs_To_Relation(), |
|
71 | - ]; |
|
22 | + $this->_tables = [ |
|
23 | + 'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID'), |
|
24 | + ]; |
|
25 | + $this->_fields = [ |
|
26 | + 'Question_Option' => [ |
|
27 | + 'QSO_ID' => new EE_Primary_Key_Int_Field( |
|
28 | + 'QSO_ID', esc_html__('Question Option ID', 'event_espresso') |
|
29 | + ), |
|
30 | + 'QST_ID' => new EE_Foreign_Key_Int_Field( |
|
31 | + 'QST_ID', |
|
32 | + esc_html__('Question ID', 'event_espresso'), |
|
33 | + false, |
|
34 | + 0, |
|
35 | + 'Question' |
|
36 | + ), |
|
37 | + 'QSO_value' => new EE_Plain_Text_Field( |
|
38 | + 'QSO_value', |
|
39 | + esc_html__("Question Option Value", "event_espresso"), |
|
40 | + false, |
|
41 | + '' |
|
42 | + ), |
|
43 | + 'QSO_desc' => new EE_Post_Content_Field( |
|
44 | + 'QSO_desc', |
|
45 | + esc_html__('Question Option Description', 'event_espresso'), |
|
46 | + false, |
|
47 | + '' |
|
48 | + ), |
|
49 | + 'QSO_order' => new EE_Integer_Field( |
|
50 | + 'QSO_order', |
|
51 | + esc_html__('Question Option Order', 'event_espresso'), |
|
52 | + false, |
|
53 | + 0 |
|
54 | + ), |
|
55 | + 'QSO_system' => new EE_Plain_Text_Field( |
|
56 | + 'QSO_system', |
|
57 | + esc_html__('Internal string ID for question option', 'event_espresso'), |
|
58 | + true, |
|
59 | + null |
|
60 | + ), |
|
61 | + 'QSO_deleted' => new EE_Trashed_Flag_Field( |
|
62 | + 'QSO_deleted', |
|
63 | + esc_html__('Flag indicating Option was trashed', 'event_espresso'), |
|
64 | + false, |
|
65 | + false |
|
66 | + ), |
|
67 | + ], |
|
68 | + ]; |
|
69 | + $this->_model_relations = [ |
|
70 | + 'Question' => new EE_Belongs_To_Relation(), |
|
71 | + ]; |
|
72 | 72 | |
73 | - $this->_caps_slug = 'questions'; |
|
74 | - $this->_model_chain_to_wp_user = 'Question'; |
|
73 | + $this->_caps_slug = 'questions'; |
|
74 | + $this->_model_chain_to_wp_user = 'Question'; |
|
75 | 75 | |
76 | - // this model is generally available for reading |
|
77 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
78 | - new EE_Restriction_Generator_Public(); |
|
79 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
80 | - new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
81 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
82 | - new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
83 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
84 | - new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
76 | + // this model is generally available for reading |
|
77 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
78 | + new EE_Restriction_Generator_Public(); |
|
79 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
80 | + new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
81 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
82 | + new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
83 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
84 | + new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
85 | 85 | |
86 | - parent::__construct($timezone); |
|
87 | - } |
|
86 | + parent::__construct($timezone); |
|
87 | + } |
|
88 | 88 | } |
@@ -74,13 +74,13 @@ |
||
74 | 74 | $this->_model_chain_to_wp_user = 'Question'; |
75 | 75 | |
76 | 76 | // this model is generally available for reading |
77 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
77 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = |
|
78 | 78 | new EE_Restriction_Generator_Public(); |
79 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
79 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
80 | 80 | new EE_Restriction_Generator_Reg_Form('QSO_system'); |
81 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
81 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
82 | 82 | new EE_Restriction_Generator_Reg_Form('QSO_system'); |
83 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
83 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
84 | 84 | new EE_Restriction_Generator_Reg_Form('QSO_system'); |
85 | 85 | |
86 | 86 | parent::__construct($timezone); |
@@ -14,64 +14,64 @@ |
||
14 | 14 | class EEM_Question_Group_Question extends EEM_Base |
15 | 15 | { |
16 | 16 | |
17 | - // private instance of the Attendee object |
|
18 | - protected static $_instance = null; |
|
17 | + // private instance of the Attendee object |
|
18 | + protected static $_instance = null; |
|
19 | 19 | |
20 | 20 | |
21 | - protected function __construct($timezone = null) |
|
22 | - { |
|
23 | - $this->singular_item = esc_html__('Question Group to Question Link', 'event_espresso'); |
|
24 | - $this->plural_item = esc_html__('Question Group to Question Links', 'event_espresso'); |
|
25 | - $this->_tables = [ |
|
26 | - 'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID'), |
|
27 | - ]; |
|
28 | - $this->_fields = [ |
|
29 | - 'Question_Group_Question' => [ |
|
30 | - 'QGQ_ID' => new EE_Primary_Key_Int_Field( |
|
31 | - 'QGQ_ID', |
|
32 | - esc_html__('Question Group to Question Link ID', 'event_espresso') |
|
33 | - ), |
|
34 | - 'QSG_ID' => new EE_Foreign_Key_Int_Field( |
|
35 | - 'QSG_ID', |
|
36 | - esc_html__('Question Group ID', 'event_espresso'), |
|
37 | - false, |
|
38 | - 0, |
|
39 | - 'Question_Group' |
|
40 | - ), |
|
41 | - 'QST_ID' => new EE_Foreign_Key_Int_Field( |
|
42 | - 'QST_ID', |
|
43 | - esc_html__('Question Id', 'event_espresso'), |
|
44 | - false, |
|
45 | - 0, |
|
46 | - 'Question' |
|
47 | - ), |
|
48 | - 'QGQ_order' => new EE_Integer_Field( |
|
49 | - 'QGQ_order', |
|
50 | - esc_html__('Question Group Question Order', 'event_espresso'), |
|
51 | - false, |
|
52 | - 0 |
|
53 | - ), |
|
54 | - ], |
|
55 | - ]; |
|
56 | - $this->_model_relations = [ |
|
57 | - 'Question_Group' => new EE_Belongs_To_Relation(), |
|
58 | - 'Question' => new EE_Belongs_To_Relation(), |
|
59 | - ]; |
|
21 | + protected function __construct($timezone = null) |
|
22 | + { |
|
23 | + $this->singular_item = esc_html__('Question Group to Question Link', 'event_espresso'); |
|
24 | + $this->plural_item = esc_html__('Question Group to Question Links', 'event_espresso'); |
|
25 | + $this->_tables = [ |
|
26 | + 'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID'), |
|
27 | + ]; |
|
28 | + $this->_fields = [ |
|
29 | + 'Question_Group_Question' => [ |
|
30 | + 'QGQ_ID' => new EE_Primary_Key_Int_Field( |
|
31 | + 'QGQ_ID', |
|
32 | + esc_html__('Question Group to Question Link ID', 'event_espresso') |
|
33 | + ), |
|
34 | + 'QSG_ID' => new EE_Foreign_Key_Int_Field( |
|
35 | + 'QSG_ID', |
|
36 | + esc_html__('Question Group ID', 'event_espresso'), |
|
37 | + false, |
|
38 | + 0, |
|
39 | + 'Question_Group' |
|
40 | + ), |
|
41 | + 'QST_ID' => new EE_Foreign_Key_Int_Field( |
|
42 | + 'QST_ID', |
|
43 | + esc_html__('Question Id', 'event_espresso'), |
|
44 | + false, |
|
45 | + 0, |
|
46 | + 'Question' |
|
47 | + ), |
|
48 | + 'QGQ_order' => new EE_Integer_Field( |
|
49 | + 'QGQ_order', |
|
50 | + esc_html__('Question Group Question Order', 'event_espresso'), |
|
51 | + false, |
|
52 | + 0 |
|
53 | + ), |
|
54 | + ], |
|
55 | + ]; |
|
56 | + $this->_model_relations = [ |
|
57 | + 'Question_Group' => new EE_Belongs_To_Relation(), |
|
58 | + 'Question' => new EE_Belongs_To_Relation(), |
|
59 | + ]; |
|
60 | 60 | |
61 | - $this->_model_chain_to_wp_user = 'Question_Group'; |
|
61 | + $this->_model_chain_to_wp_user = 'Question_Group'; |
|
62 | 62 | |
63 | - // this model is generally available for reading |
|
64 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
65 | - new EE_Restriction_Generator_Public(); |
|
66 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
67 | - new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
69 | - new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
70 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
71 | - new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
63 | + // this model is generally available for reading |
|
64 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
65 | + new EE_Restriction_Generator_Public(); |
|
66 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
67 | + new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
68 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
69 | + new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
70 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
71 | + new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
72 | 72 | |
73 | - // use the caps for question groups |
|
74 | - $this->_caps_slug = 'question_groups'; |
|
75 | - parent::__construct($timezone); |
|
76 | - } |
|
73 | + // use the caps for question groups |
|
74 | + $this->_caps_slug = 'question_groups'; |
|
75 | + parent::__construct($timezone); |
|
76 | + } |
|
77 | 77 | } |
@@ -61,13 +61,13 @@ |
||
61 | 61 | $this->_model_chain_to_wp_user = 'Question_Group'; |
62 | 62 | |
63 | 63 | // this model is generally available for reading |
64 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
64 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = |
|
65 | 65 | new EE_Restriction_Generator_Public(); |
66 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
66 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
67 | 67 | new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
69 | 69 | new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
70 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
70 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
71 | 71 | new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
72 | 72 | |
73 | 73 | // use the caps for question groups |
@@ -10,136 +10,136 @@ |
||
10 | 10 | class EEM_Question_Group extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | 12 | |
13 | - const system_personal = 1; |
|
13 | + const system_personal = 1; |
|
14 | 14 | |
15 | - const system_address = 2; |
|
15 | + const system_address = 2; |
|
16 | 16 | |
17 | - /** |
|
18 | - * private instance of the EEM_Question_Group object |
|
19 | - * |
|
20 | - * @var EEM_Question_Group |
|
21 | - */ |
|
22 | - protected static $_instance = null; |
|
17 | + /** |
|
18 | + * private instance of the EEM_Question_Group object |
|
19 | + * |
|
20 | + * @var EEM_Question_Group |
|
21 | + */ |
|
22 | + protected static $_instance = null; |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * EEM_Question_Group constructor. |
|
27 | - * |
|
28 | - * @param string|null $timezone |
|
29 | - */ |
|
30 | - protected function __construct($timezone = null) |
|
31 | - { |
|
32 | - $this->singular_item = esc_html__('Question Group', 'event_espresso'); |
|
33 | - $this->plural_item = esc_html__('Question Groups', 'event_espresso'); |
|
25 | + /** |
|
26 | + * EEM_Question_Group constructor. |
|
27 | + * |
|
28 | + * @param string|null $timezone |
|
29 | + */ |
|
30 | + protected function __construct($timezone = null) |
|
31 | + { |
|
32 | + $this->singular_item = esc_html__('Question Group', 'event_espresso'); |
|
33 | + $this->plural_item = esc_html__('Question Groups', 'event_espresso'); |
|
34 | 34 | |
35 | - $this->_tables = [ |
|
36 | - 'Question_Group' => new EE_Primary_Table('esp_question_group', 'QSG_ID'), |
|
37 | - ]; |
|
38 | - $this->_fields = [ |
|
39 | - 'Question_Group' => [ |
|
40 | - 'QSG_ID' => new EE_Primary_Key_Int_Field( |
|
41 | - 'QSG_ID', |
|
42 | - esc_html__('Question Group ID', 'event_espresso') |
|
43 | - ), |
|
44 | - 'QSG_name' => new EE_Plain_Text_Field( |
|
45 | - 'QSG_name', |
|
46 | - esc_html__('Question Group Name', 'event_espresso'), |
|
47 | - false, |
|
48 | - '' |
|
49 | - ), |
|
50 | - 'QSG_identifier' => new EE_Plain_Text_Field( |
|
51 | - 'QSG_identifier', |
|
52 | - esc_html__('Text ID for question Group', 'event_espresso'), |
|
53 | - false, |
|
54 | - '' |
|
55 | - ), |
|
56 | - 'QSG_desc' => new EE_Post_Content_Field( |
|
57 | - 'QSG_desc', |
|
58 | - esc_html__('Description of Question Group', 'event_espresso'), |
|
59 | - true, |
|
60 | - '' |
|
61 | - ), |
|
62 | - 'QSG_order' => new EE_Integer_Field( |
|
63 | - 'QSG_order', |
|
64 | - esc_html__('Order in which to show the question group', 'event_espresso'), |
|
65 | - true, |
|
66 | - 0 |
|
67 | - ), |
|
68 | - 'QSG_show_group_name' => new EE_Boolean_Field( |
|
69 | - 'QSG_show_group_name', |
|
70 | - esc_html__( |
|
71 | - 'Flag indicating whether to show the group\'s name on the registration page', |
|
72 | - 'event_espresso' |
|
73 | - ), |
|
74 | - false, |
|
75 | - true |
|
76 | - ), |
|
77 | - 'QSG_show_group_desc' => new EE_Boolean_Field( |
|
78 | - 'QSG_show_group_desc', |
|
79 | - esc_html__( |
|
80 | - 'Flag indicating whether to show the group\s description on the registration page', |
|
81 | - 'event_espresso' |
|
82 | - ), |
|
83 | - false, |
|
84 | - false |
|
85 | - ), |
|
86 | - 'QSG_wp_user' => new EE_WP_User_Field( |
|
87 | - 'QSG_wp_user', |
|
88 | - esc_html__('Question Group Creator ID', 'event_espresso'), |
|
89 | - false |
|
90 | - ), |
|
91 | - 'QSG_system' => new EE_Integer_Field( |
|
92 | - 'QSG_system', |
|
93 | - esc_html__( |
|
94 | - 'Indicate IF this is a system group and if it is what system group it corresponds to.', |
|
95 | - 'event_espresso' |
|
96 | - ), |
|
97 | - false, |
|
98 | - 0 |
|
99 | - ), |
|
100 | - 'QSG_deleted' => new EE_Trashed_Flag_Field( |
|
101 | - 'QSG_deleted', |
|
102 | - esc_html__('Flag indicating this question group was deleted', 'event_espresso'), |
|
103 | - false, |
|
104 | - false |
|
105 | - ), |
|
106 | - ], |
|
107 | - ]; |
|
108 | - $this->_model_relations = [ |
|
109 | - 'Question' => new EE_HABTM_Relation('Question_Group_Question'), |
|
110 | - 'Event' => new EE_HABTM_Relation('Event_Question_Group'), |
|
111 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
112 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
113 | - ]; |
|
114 | - // this model is generally available for reading |
|
115 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
116 | - new EE_Restriction_Generator_Public(); |
|
117 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
118 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
119 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
120 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
121 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
122 | - new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
35 | + $this->_tables = [ |
|
36 | + 'Question_Group' => new EE_Primary_Table('esp_question_group', 'QSG_ID'), |
|
37 | + ]; |
|
38 | + $this->_fields = [ |
|
39 | + 'Question_Group' => [ |
|
40 | + 'QSG_ID' => new EE_Primary_Key_Int_Field( |
|
41 | + 'QSG_ID', |
|
42 | + esc_html__('Question Group ID', 'event_espresso') |
|
43 | + ), |
|
44 | + 'QSG_name' => new EE_Plain_Text_Field( |
|
45 | + 'QSG_name', |
|
46 | + esc_html__('Question Group Name', 'event_espresso'), |
|
47 | + false, |
|
48 | + '' |
|
49 | + ), |
|
50 | + 'QSG_identifier' => new EE_Plain_Text_Field( |
|
51 | + 'QSG_identifier', |
|
52 | + esc_html__('Text ID for question Group', 'event_espresso'), |
|
53 | + false, |
|
54 | + '' |
|
55 | + ), |
|
56 | + 'QSG_desc' => new EE_Post_Content_Field( |
|
57 | + 'QSG_desc', |
|
58 | + esc_html__('Description of Question Group', 'event_espresso'), |
|
59 | + true, |
|
60 | + '' |
|
61 | + ), |
|
62 | + 'QSG_order' => new EE_Integer_Field( |
|
63 | + 'QSG_order', |
|
64 | + esc_html__('Order in which to show the question group', 'event_espresso'), |
|
65 | + true, |
|
66 | + 0 |
|
67 | + ), |
|
68 | + 'QSG_show_group_name' => new EE_Boolean_Field( |
|
69 | + 'QSG_show_group_name', |
|
70 | + esc_html__( |
|
71 | + 'Flag indicating whether to show the group\'s name on the registration page', |
|
72 | + 'event_espresso' |
|
73 | + ), |
|
74 | + false, |
|
75 | + true |
|
76 | + ), |
|
77 | + 'QSG_show_group_desc' => new EE_Boolean_Field( |
|
78 | + 'QSG_show_group_desc', |
|
79 | + esc_html__( |
|
80 | + 'Flag indicating whether to show the group\s description on the registration page', |
|
81 | + 'event_espresso' |
|
82 | + ), |
|
83 | + false, |
|
84 | + false |
|
85 | + ), |
|
86 | + 'QSG_wp_user' => new EE_WP_User_Field( |
|
87 | + 'QSG_wp_user', |
|
88 | + esc_html__('Question Group Creator ID', 'event_espresso'), |
|
89 | + false |
|
90 | + ), |
|
91 | + 'QSG_system' => new EE_Integer_Field( |
|
92 | + 'QSG_system', |
|
93 | + esc_html__( |
|
94 | + 'Indicate IF this is a system group and if it is what system group it corresponds to.', |
|
95 | + 'event_espresso' |
|
96 | + ), |
|
97 | + false, |
|
98 | + 0 |
|
99 | + ), |
|
100 | + 'QSG_deleted' => new EE_Trashed_Flag_Field( |
|
101 | + 'QSG_deleted', |
|
102 | + esc_html__('Flag indicating this question group was deleted', 'event_espresso'), |
|
103 | + false, |
|
104 | + false |
|
105 | + ), |
|
106 | + ], |
|
107 | + ]; |
|
108 | + $this->_model_relations = [ |
|
109 | + 'Question' => new EE_HABTM_Relation('Question_Group_Question'), |
|
110 | + 'Event' => new EE_HABTM_Relation('Event_Question_Group'), |
|
111 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
112 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
113 | + ]; |
|
114 | + // this model is generally available for reading |
|
115 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
116 | + new EE_Restriction_Generator_Public(); |
|
117 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
118 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
119 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
120 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
121 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
122 | + new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
123 | 123 | |
124 | - parent::__construct($timezone); |
|
125 | - } |
|
124 | + parent::__construct($timezone); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | |
128 | - /** |
|
129 | - * searches the db for the question group with the latest question order and returns that value. |
|
130 | - * |
|
131 | - * @return int |
|
132 | - * @throws EE_Error |
|
133 | - */ |
|
134 | - public function get_latest_question_group_order(): int |
|
135 | - { |
|
136 | - $max = $this->_get_all_wpdb_results( |
|
137 | - [], |
|
138 | - ARRAY_A, |
|
139 | - [ |
|
140 | - 'max_order' => ["MAX(QSG_order)", "%d"], |
|
141 | - ] |
|
142 | - ); |
|
143 | - return $max[0]['max_order']; |
|
144 | - } |
|
128 | + /** |
|
129 | + * searches the db for the question group with the latest question order and returns that value. |
|
130 | + * |
|
131 | + * @return int |
|
132 | + * @throws EE_Error |
|
133 | + */ |
|
134 | + public function get_latest_question_group_order(): int |
|
135 | + { |
|
136 | + $max = $this->_get_all_wpdb_results( |
|
137 | + [], |
|
138 | + ARRAY_A, |
|
139 | + [ |
|
140 | + 'max_order' => ["MAX(QSG_order)", "%d"], |
|
141 | + ] |
|
142 | + ); |
|
143 | + return $max[0]['max_order']; |
|
144 | + } |
|
145 | 145 | } |