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