@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | { |
| 41 | 41 | // if there are no standard caps for this model, then for now all we know |
| 42 | 42 | // if they need the default cap to access this |
| 43 | - if (! $this->model()->cap_slug()) { |
|
| 43 | + if ( ! $this->model()->cap_slug()) { |
|
| 44 | 44 | return array( |
| 45 | 45 | EE_Restriction_Generator_Base::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
| 46 | 46 | ); |
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | // there is no "ee_read_system_questions" cap; in order to read reg form items you only need "ee_read_{model_name}". |
| 52 | 52 | // there is also no "ee_delete_system_questions" cap. But folks shouldn't be deleting system questions anyway |
| 53 | 53 | if ($this->action() !== EEM_Base::caps_read) { |
| 54 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_system') ] = new EE_Default_Where_Conditions( |
|
| 54 | + $restrictions[EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_system')] = new EE_Default_Where_Conditions( |
|
| 55 | 55 | array( |
| 56 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_system') => array( |
|
| 56 | + 'OR*no_'.EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action().'_system') => array( |
|
| 57 | 57 | $this->_system_field_name => array('IN', array('', 0)), |
| 58 | - $this->_system_field_name . '*' => array('IS_NULL') |
|
| 58 | + $this->_system_field_name.'*' => array('IS_NULL') |
|
| 59 | 59 | ) |
| 60 | 60 | ) |
| 61 | 61 | ); |
@@ -14,51 +14,51 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_Restriction_Generator_Reg_Form extends EE_Restriction_Generator_Base |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * |
|
| 19 | - * @var string the name of the field that indicates whether or not this is a system thing |
|
| 20 | - */ |
|
| 21 | - protected $_system_field_name = null; |
|
| 17 | + /** |
|
| 18 | + * |
|
| 19 | + * @var string the name of the field that indicates whether or not this is a system thing |
|
| 20 | + */ |
|
| 21 | + protected $_system_field_name = null; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Accepts the name of the field that indicates whether or not an object is a "system" one or not |
|
| 25 | - * @param string $system_field_name |
|
| 26 | - */ |
|
| 27 | - public function __construct($system_field_name) |
|
| 28 | - { |
|
| 29 | - $this->_system_field_name = $system_field_name; |
|
| 30 | - } |
|
| 23 | + /** |
|
| 24 | + * Accepts the name of the field that indicates whether or not an object is a "system" one or not |
|
| 25 | + * @param string $system_field_name |
|
| 26 | + */ |
|
| 27 | + public function __construct($system_field_name) |
|
| 28 | + { |
|
| 29 | + $this->_system_field_name = $system_field_name; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * |
|
| 35 | - * @return \EE_Default_Where_Conditions[] |
|
| 36 | - * @throws EE_Error |
|
| 37 | - */ |
|
| 38 | - protected function _generate_restrictions() |
|
| 39 | - { |
|
| 40 | - // if there are no standard caps for this model, then for now all we know |
|
| 41 | - // if they need the default cap to access this |
|
| 42 | - if (! $this->model()->cap_slug()) { |
|
| 43 | - return array( |
|
| 44 | - EE_Restriction_Generator_Base::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
|
| 45 | - ); |
|
| 46 | - } |
|
| 47 | - $restrictions = array( |
|
| 48 | - EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) => new EE_Return_None_Where_Conditions(), |
|
| 49 | - ); |
|
| 50 | - // there is no "ee_read_system_questions" cap; in order to read reg form items you only need "ee_read_{model_name}". |
|
| 51 | - // there is also no "ee_delete_system_questions" cap. But folks shouldn't be deleting system questions anyway |
|
| 52 | - if ($this->action() !== EEM_Base::caps_read) { |
|
| 53 | - $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_system') ] = new EE_Default_Where_Conditions( |
|
| 54 | - array( |
|
| 55 | - 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_system') => array( |
|
| 56 | - $this->_system_field_name => array('IN', array('', 0)), |
|
| 57 | - $this->_system_field_name . '*' => array('IS_NULL') |
|
| 58 | - ) |
|
| 59 | - ) |
|
| 60 | - ); |
|
| 61 | - } |
|
| 62 | - return $restrictions; |
|
| 63 | - } |
|
| 33 | + /** |
|
| 34 | + * |
|
| 35 | + * @return \EE_Default_Where_Conditions[] |
|
| 36 | + * @throws EE_Error |
|
| 37 | + */ |
|
| 38 | + protected function _generate_restrictions() |
|
| 39 | + { |
|
| 40 | + // if there are no standard caps for this model, then for now all we know |
|
| 41 | + // if they need the default cap to access this |
|
| 42 | + if (! $this->model()->cap_slug()) { |
|
| 43 | + return array( |
|
| 44 | + EE_Restriction_Generator_Base::get_default_restrictions_cap() => new EE_Return_None_Where_Conditions() |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | + $restrictions = array( |
|
| 48 | + EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action()) => new EE_Return_None_Where_Conditions(), |
|
| 49 | + ); |
|
| 50 | + // there is no "ee_read_system_questions" cap; in order to read reg form items you only need "ee_read_{model_name}". |
|
| 51 | + // there is also no "ee_delete_system_questions" cap. But folks shouldn't be deleting system questions anyway |
|
| 52 | + if ($this->action() !== EEM_Base::caps_read) { |
|
| 53 | + $restrictions[ EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_system') ] = new EE_Default_Where_Conditions( |
|
| 54 | + array( |
|
| 55 | + 'OR*no_' . EE_Restriction_Generator_Base::get_cap_name($this->model(), $this->action() . '_system') => array( |
|
| 56 | + $this->_system_field_name => array('IN', array('', 0)), |
|
| 57 | + $this->_system_field_name . '*' => array('IS_NULL') |
|
| 58 | + ) |
|
| 59 | + ) |
|
| 60 | + ); |
|
| 61 | + } |
|
| 62 | + return $restrictions; |
|
| 63 | + } |
|
| 64 | 64 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | return array_merge( |
| 26 | 26 | parent::_get_default_where_conditions(), |
| 27 | 27 | array( |
| 28 | - $status_field->get_name() => array('NOT IN',array('auto-draft','trash') ) |
|
| 28 | + $status_field->get_name() => array('NOT IN', array('auto-draft', 'trash')) |
|
| 29 | 29 | ) |
| 30 | 30 | ); |
| 31 | 31 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | /** |
| 4 | 4 | * |
| 5 | 5 | * Class EE_Default_Where_Conditions |
| 6 | - * |
|
| 6 | + * |
|
| 7 | 7 | * Strategy specifically for adding where conditions specific to CPT models. |
| 8 | 8 | * |
| 9 | 9 | * @package Event Espresso |
@@ -14,19 +14,19 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_CPT_Where_Conditions extends EE_CPT_Minimum_Where_Conditions |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Gets the where default where conditions for a custom post type model |
|
| 19 | - * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment" |
|
| 20 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
| 21 | - */ |
|
| 22 | - protected function _get_default_where_conditions() |
|
| 23 | - { |
|
| 24 | - $status_field = $this->_get_field_on_column('post_status'); |
|
| 25 | - return array_merge( |
|
| 26 | - parent::_get_default_where_conditions(), |
|
| 27 | - array( |
|
| 28 | - $status_field->get_name() => array('NOT IN',array('auto-draft','trash') ) |
|
| 29 | - ) |
|
| 30 | - ); |
|
| 31 | - } |
|
| 17 | + /** |
|
| 18 | + * Gets the where default where conditions for a custom post type model |
|
| 19 | + * @param string $model_relation_path. Eg, from Event to Payment, this should be "Registration.Transaction.Payment" |
|
| 20 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions |
|
| 21 | + */ |
|
| 22 | + protected function _get_default_where_conditions() |
|
| 23 | + { |
|
| 24 | + $status_field = $this->_get_field_on_column('post_status'); |
|
| 25 | + return array_merge( |
|
| 26 | + parent::_get_default_where_conditions(), |
|
| 27 | + array( |
|
| 28 | + $status_field->get_name() => array('NOT IN',array('auto-draft','trash') ) |
|
| 29 | + ) |
|
| 30 | + ); |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -32,20 +32,20 @@ |
||
| 32 | 32 | protected function _generate_restrictions() |
| 33 | 33 | { |
| 34 | 34 | // if there are no standard caps for this model, then for allow full access |
| 35 | - if (! $this->model()->cap_slug()) { |
|
| 35 | + if ( ! $this->model()->cap_slug()) { |
|
| 36 | 36 | return array( |
| 37 | 37 | ); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | return array( |
| 41 | 41 | 'ee_manage_event_categories' => new EE_Default_Where_Conditions(array( |
| 42 | - $this->_path_to_taxonomy_model . 'taxonomy*no_ee_manage_event_categories' => array( '!=', 'espresso_event_categories' ) |
|
| 42 | + $this->_path_to_taxonomy_model.'taxonomy*no_ee_manage_event_categories' => array('!=', 'espresso_event_categories') |
|
| 43 | 43 | )), |
| 44 | 44 | 'ee_manage_venue_categories' => new EE_Default_Where_Conditions(array( |
| 45 | - $this->_path_to_taxonomy_model . 'taxonomy*no_ee_manage_venue_categories' => array( '!=', 'espresso_venue_categories' ) |
|
| 45 | + $this->_path_to_taxonomy_model.'taxonomy*no_ee_manage_venue_categories' => array('!=', 'espresso_venue_categories') |
|
| 46 | 46 | )), |
| 47 | 47 | 'ee_manage_event_types' => new EE_Default_Where_Conditions(array( |
| 48 | - $this->_path_to_taxonomy_model . 'taxonomy*ee_manage_event_types' => array( '!=', 'espresso_event_types' ) |
|
| 48 | + $this->_path_to_taxonomy_model.'taxonomy*ee_manage_event_types' => array('!=', 'espresso_event_types') |
|
| 49 | 49 | )), |
| 50 | 50 | ); |
| 51 | 51 | } |
@@ -12,40 +12,40 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EE_Restriction_Generator_Taxonomy_Protected extends EE_Restriction_Generator_Base |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Model chain/path to taxonomy model, including the term_taxonomy model itself |
|
| 17 | - * @var string |
|
| 18 | - */ |
|
| 19 | - protected $_path_to_taxonomy_model; |
|
| 20 | - /** |
|
| 21 | - * |
|
| 22 | - * @param string $path_to_taxonomy_model Model chain/path to taxonomy model, including the term_taxonomy model itself |
|
| 23 | - */ |
|
| 24 | - public function __construct($path_to_taxonomy_model) |
|
| 25 | - { |
|
| 26 | - if ($path_to_taxonomy_model !== '' && substr($path_to_taxonomy_model, -1, 1) != '.') { |
|
| 27 | - $path_to_taxonomy_model .= '.'; |
|
| 28 | - } |
|
| 29 | - $this->_path_to_taxonomy_model = $path_to_taxonomy_model; |
|
| 30 | - } |
|
| 31 | - protected function _generate_restrictions() |
|
| 32 | - { |
|
| 33 | - // if there are no standard caps for this model, then for allow full access |
|
| 34 | - if (! $this->model()->cap_slug()) { |
|
| 35 | - return array( |
|
| 36 | - ); |
|
| 37 | - } |
|
| 15 | + /** |
|
| 16 | + * Model chain/path to taxonomy model, including the term_taxonomy model itself |
|
| 17 | + * @var string |
|
| 18 | + */ |
|
| 19 | + protected $_path_to_taxonomy_model; |
|
| 20 | + /** |
|
| 21 | + * |
|
| 22 | + * @param string $path_to_taxonomy_model Model chain/path to taxonomy model, including the term_taxonomy model itself |
|
| 23 | + */ |
|
| 24 | + public function __construct($path_to_taxonomy_model) |
|
| 25 | + { |
|
| 26 | + if ($path_to_taxonomy_model !== '' && substr($path_to_taxonomy_model, -1, 1) != '.') { |
|
| 27 | + $path_to_taxonomy_model .= '.'; |
|
| 28 | + } |
|
| 29 | + $this->_path_to_taxonomy_model = $path_to_taxonomy_model; |
|
| 30 | + } |
|
| 31 | + protected function _generate_restrictions() |
|
| 32 | + { |
|
| 33 | + // if there are no standard caps for this model, then for allow full access |
|
| 34 | + if (! $this->model()->cap_slug()) { |
|
| 35 | + return array( |
|
| 36 | + ); |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - return array( |
|
| 40 | - 'ee_manage_event_categories' => new EE_Default_Where_Conditions(array( |
|
| 41 | - $this->_path_to_taxonomy_model . 'taxonomy*no_ee_manage_event_categories' => array( '!=', 'espresso_event_categories' ) |
|
| 42 | - )), |
|
| 43 | - 'ee_manage_venue_categories' => new EE_Default_Where_Conditions(array( |
|
| 44 | - $this->_path_to_taxonomy_model . 'taxonomy*no_ee_manage_venue_categories' => array( '!=', 'espresso_venue_categories' ) |
|
| 45 | - )), |
|
| 46 | - 'ee_manage_event_types' => new EE_Default_Where_Conditions(array( |
|
| 47 | - $this->_path_to_taxonomy_model . 'taxonomy*ee_manage_event_types' => array( '!=', 'espresso_event_types' ) |
|
| 48 | - )), |
|
| 49 | - ); |
|
| 50 | - } |
|
| 39 | + return array( |
|
| 40 | + 'ee_manage_event_categories' => new EE_Default_Where_Conditions(array( |
|
| 41 | + $this->_path_to_taxonomy_model . 'taxonomy*no_ee_manage_event_categories' => array( '!=', 'espresso_event_categories' ) |
|
| 42 | + )), |
|
| 43 | + 'ee_manage_venue_categories' => new EE_Default_Where_Conditions(array( |
|
| 44 | + $this->_path_to_taxonomy_model . 'taxonomy*no_ee_manage_venue_categories' => array( '!=', 'espresso_venue_categories' ) |
|
| 45 | + )), |
|
| 46 | + 'ee_manage_event_types' => new EE_Default_Where_Conditions(array( |
|
| 47 | + $this->_path_to_taxonomy_model . 'taxonomy*ee_manage_event_types' => array( '!=', 'espresso_event_types' ) |
|
| 48 | + )), |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -12,13 +12,13 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class EE_Return_None_Where_Conditions extends EE_Default_Where_Conditions |
| 14 | 14 | { |
| 15 | - protected function _get_default_where_conditions() |
|
| 16 | - { |
|
| 17 | - if ($this->_model->has_primary_key_field()) { |
|
| 18 | - return array( $this->_model->primary_key_name() => array('<', 0 ) ); |
|
| 19 | - } else { |
|
| 20 | - $fk_field = $this->_model->get_a_field_of_type('EE_Foreign_Key_Field_Base'); |
|
| 21 | - return array( 'AND*impossible' => array( $fk_field->get_name() => array('IS_NULL'), $fk_field->get_name() => 'IS_NOT_NULL' ) ); |
|
| 22 | - } |
|
| 23 | - } |
|
| 15 | + protected function _get_default_where_conditions() |
|
| 16 | + { |
|
| 17 | + if ($this->_model->has_primary_key_field()) { |
|
| 18 | + return array( $this->_model->primary_key_name() => array('<', 0 ) ); |
|
| 19 | + } else { |
|
| 20 | + $fk_field = $this->_model->get_a_field_of_type('EE_Foreign_Key_Field_Base'); |
|
| 21 | + return array( 'AND*impossible' => array( $fk_field->get_name() => array('IS_NULL'), $fk_field->get_name() => 'IS_NOT_NULL' ) ); |
|
| 22 | + } |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -15,10 +15,10 @@ |
||
| 15 | 15 | protected function _get_default_where_conditions() |
| 16 | 16 | { |
| 17 | 17 | if ($this->_model->has_primary_key_field()) { |
| 18 | - return array( $this->_model->primary_key_name() => array('<', 0 ) ); |
|
| 18 | + return array($this->_model->primary_key_name() => array('<', 0)); |
|
| 19 | 19 | } else { |
| 20 | 20 | $fk_field = $this->_model->get_a_field_of_type('EE_Foreign_Key_Field_Base'); |
| 21 | - return array( 'AND*impossible' => array( $fk_field->get_name() => array('IS_NULL'), $fk_field->get_name() => 'IS_NOT_NULL' ) ); |
|
| 21 | + return array('AND*impossible' => array($fk_field->get_name() => array('IS_NULL'), $fk_field->get_name() => 'IS_NOT_NULL')); |
|
| 22 | 22 | } |
| 23 | 23 | } |
| 24 | 24 | } |
@@ -39,10 +39,10 @@ |
||
| 39 | 39 | |
| 40 | 40 | $this->_model_chain_to_wp_user = 'Question'; |
| 41 | 41 | // this model is generally available for reading |
| 42 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 43 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 44 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 45 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 42 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 43 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 44 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 45 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 46 | 46 | $this->_caps_slug = 'questions'; |
| 47 | 47 | parent::__construct($timezone); |
| 48 | 48 | } |
@@ -11,39 +11,39 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class EEM_Question_Option extends EEM_Soft_Delete_Base |
| 13 | 13 | { |
| 14 | - // private instance of the Attendee object |
|
| 15 | - protected static $_instance = null; |
|
| 14 | + // private instance of the Attendee object |
|
| 15 | + protected static $_instance = null; |
|
| 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 = array( |
|
| 23 | - 'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID') |
|
| 24 | - ); |
|
| 25 | - $this->_fields = array( |
|
| 26 | - 'Question_Option' => array( |
|
| 27 | - 'QSO_ID' => new EE_Primary_Key_Int_Field('QSO_ID', esc_html__('Question Option ID', 'event_espresso')), |
|
| 28 | - 'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
| 29 | - 'QSO_value' => new EE_Plain_Text_Field('QSO_value', esc_html__("Question Option Value", "event_espresso"), false, ''), |
|
| 30 | - 'QSO_desc' => new EE_Post_Content_Field('QSO_desc', esc_html__('Question Option Description', 'event_espresso'), false, ''), |
|
| 31 | - 'QSO_order' => new EE_Integer_Field('QSO_order', esc_html__('Question Option Order', 'event_espresso'), false, 0), |
|
| 32 | - 'QSO_system' => new EE_Plain_Text_Field('QSO_system', esc_html__('Internal string ID for question option', 'event_espresso'), true, null), |
|
| 33 | - 'QSO_deleted' => new EE_Trashed_Flag_Field('QSO_deleted', esc_html__('Flag indicating Option was trashed', 'event_espresso'), false, false) |
|
| 34 | - ) |
|
| 35 | - ); |
|
| 36 | - $this->_model_relations = array( |
|
| 37 | - 'Question' => new EE_Belongs_To_Relation() |
|
| 38 | - ); |
|
| 22 | + $this->_tables = array( |
|
| 23 | + 'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID') |
|
| 24 | + ); |
|
| 25 | + $this->_fields = array( |
|
| 26 | + 'Question_Option' => array( |
|
| 27 | + 'QSO_ID' => new EE_Primary_Key_Int_Field('QSO_ID', esc_html__('Question Option ID', 'event_espresso')), |
|
| 28 | + 'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso'), false, 0, 'Question'), |
|
| 29 | + 'QSO_value' => new EE_Plain_Text_Field('QSO_value', esc_html__("Question Option Value", "event_espresso"), false, ''), |
|
| 30 | + 'QSO_desc' => new EE_Post_Content_Field('QSO_desc', esc_html__('Question Option Description', 'event_espresso'), false, ''), |
|
| 31 | + 'QSO_order' => new EE_Integer_Field('QSO_order', esc_html__('Question Option Order', 'event_espresso'), false, 0), |
|
| 32 | + 'QSO_system' => new EE_Plain_Text_Field('QSO_system', esc_html__('Internal string ID for question option', 'event_espresso'), true, null), |
|
| 33 | + 'QSO_deleted' => new EE_Trashed_Flag_Field('QSO_deleted', esc_html__('Flag indicating Option was trashed', 'event_espresso'), false, false) |
|
| 34 | + ) |
|
| 35 | + ); |
|
| 36 | + $this->_model_relations = array( |
|
| 37 | + 'Question' => new EE_Belongs_To_Relation() |
|
| 38 | + ); |
|
| 39 | 39 | |
| 40 | - $this->_model_chain_to_wp_user = 'Question'; |
|
| 41 | - // this model is generally available for reading |
|
| 42 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 43 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 44 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 45 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 46 | - $this->_caps_slug = 'questions'; |
|
| 47 | - parent::__construct($timezone); |
|
| 48 | - } |
|
| 40 | + $this->_model_chain_to_wp_user = 'Question'; |
|
| 41 | + // this model is generally available for reading |
|
| 42 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 43 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 44 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 45 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSO_system'); |
|
| 46 | + $this->_caps_slug = 'questions'; |
|
| 47 | + parent::__construct($timezone); |
|
| 48 | + } |
|
| 49 | 49 | } |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | ); |
| 50 | 50 | $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
| 51 | 51 | foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
| 52 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
| 52 | + $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
| 53 | 53 | } |
| 54 | 54 | $this->_caps_slug = 'messages'; |
| 55 | 55 | parent::__construct($timezone); |
@@ -14,45 +14,45 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EEM_Message_Template extends EEM_Base |
| 16 | 16 | { |
| 17 | - // private instance of the EEM_Message_Template object |
|
| 18 | - protected static $_instance = null; |
|
| 17 | + // private instance of the EEM_Message_Template object |
|
| 18 | + protected static $_instance = null; |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * private constructor to prevent direct creation |
|
| 24 | - * |
|
| 25 | - * @Constructor |
|
| 26 | - * @access protected |
|
| 27 | - * @param string $timezone |
|
| 28 | - * @throws \EE_Error |
|
| 29 | - */ |
|
| 30 | - protected function __construct($timezone = null) |
|
| 31 | - { |
|
| 32 | - $this->singular_item = esc_html__('Message Template', 'event_espresso'); |
|
| 33 | - $this->plural_item = esc_html__('Message Templates', 'event_espresso'); |
|
| 22 | + /** |
|
| 23 | + * private constructor to prevent direct creation |
|
| 24 | + * |
|
| 25 | + * @Constructor |
|
| 26 | + * @access protected |
|
| 27 | + * @param string $timezone |
|
| 28 | + * @throws \EE_Error |
|
| 29 | + */ |
|
| 30 | + protected function __construct($timezone = null) |
|
| 31 | + { |
|
| 32 | + $this->singular_item = esc_html__('Message Template', 'event_espresso'); |
|
| 33 | + $this->plural_item = esc_html__('Message Templates', 'event_espresso'); |
|
| 34 | 34 | |
| 35 | - $this->_tables = array( |
|
| 36 | - 'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID') |
|
| 37 | - ); |
|
| 38 | - $this->_fields = array( |
|
| 39 | - 'Message_Template' => array( |
|
| 40 | - 'MTP_ID' => new EE_Primary_Key_Int_Field('MTP_ID', esc_html__('Message Template ID', 'event_espresso')), |
|
| 41 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso'), false, 0, 'Message_Template_Group'), |
|
| 42 | - 'MTP_template_field' => new EE_Plain_Text_Field('MTP_template_field', esc_html__('Field Name for this Template', 'event_espresso'), false, 'default'), |
|
| 43 | - 'MTP_context' => new EE_Plain_Text_Field('MTP_context', esc_html__('Message Type Context for this field', 'event_espresso'), false, 'admin'), |
|
| 44 | - 'MTP_content' => new EE_Serialized_Text_Field('MTP_content', esc_html__('The field content for the template', 'event_espresso'), false, ''), |
|
| 45 | - ) |
|
| 46 | - ); |
|
| 35 | + $this->_tables = array( |
|
| 36 | + 'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID') |
|
| 37 | + ); |
|
| 38 | + $this->_fields = array( |
|
| 39 | + 'Message_Template' => array( |
|
| 40 | + 'MTP_ID' => new EE_Primary_Key_Int_Field('MTP_ID', esc_html__('Message Template ID', 'event_espresso')), |
|
| 41 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso'), false, 0, 'Message_Template_Group'), |
|
| 42 | + 'MTP_template_field' => new EE_Plain_Text_Field('MTP_template_field', esc_html__('Field Name for this Template', 'event_espresso'), false, 'default'), |
|
| 43 | + 'MTP_context' => new EE_Plain_Text_Field('MTP_context', esc_html__('Message Type Context for this field', 'event_espresso'), false, 'admin'), |
|
| 44 | + 'MTP_content' => new EE_Serialized_Text_Field('MTP_content', esc_html__('The field content for the template', 'event_espresso'), false, ''), |
|
| 45 | + ) |
|
| 46 | + ); |
|
| 47 | 47 | |
| 48 | - $this->_model_relations = array( |
|
| 49 | - 'Message_Template_Group' => new EE_Belongs_To_Relation() |
|
| 50 | - ); |
|
| 51 | - $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
|
| 52 | - foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
| 53 | - $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
| 54 | - } |
|
| 55 | - $this->_caps_slug = 'messages'; |
|
| 56 | - parent::__construct($timezone); |
|
| 57 | - } |
|
| 48 | + $this->_model_relations = array( |
|
| 49 | + 'Message_Template_Group' => new EE_Belongs_To_Relation() |
|
| 50 | + ); |
|
| 51 | + $this->_model_chain_to_wp_user = 'Message_Template_Group'; |
|
| 52 | + foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) { |
|
| 53 | + $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global'); |
|
| 54 | + } |
|
| 55 | + $this->_caps_slug = 'messages'; |
|
| 56 | + parent::__construct($timezone); |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -42,10 +42,10 @@ |
||
| 42 | 42 | |
| 43 | 43 | $this->_model_chain_to_wp_user = 'Question_Group'; |
| 44 | 44 | // this model is generally available for reading |
| 45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 46 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 47 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 48 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 49 | 49 | // use the caps for question groups |
| 50 | 50 | $this->_caps_slug = 'question_groups'; |
| 51 | 51 | parent::__construct($timezone); |
@@ -16,38 +16,38 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class EEM_Question_Group_Question extends EEM_Base |
| 18 | 18 | { |
| 19 | - // private instance of the Attendee object |
|
| 20 | - protected static $_instance = null; |
|
| 19 | + // private instance of the Attendee object |
|
| 20 | + protected static $_instance = null; |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - protected function __construct($timezone = null) |
|
| 24 | - { |
|
| 25 | - $this->singular_item = esc_html__('Question Group to Question Link', 'event_espresso'); |
|
| 26 | - $this->plural_item = esc_html__('Question Group to Question Links', 'event_espresso'); |
|
| 27 | - $this->_tables = array( |
|
| 28 | - 'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID') |
|
| 29 | - ); |
|
| 30 | - $this->_fields = array( |
|
| 31 | - 'Question_Group_Question' => array( |
|
| 32 | - 'QGQ_ID' => new EE_Primary_Key_Int_Field('QGQ_ID', esc_html__('Question Group to Question Link ID', 'event_espresso')), |
|
| 33 | - 'QSG_ID' => new EE_Foreign_Key_Int_Field('QSG_ID', esc_html__('Question Group ID', 'event_espresso'), false, 0, 'Question_Group'), |
|
| 34 | - 'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question Id', 'event_espresso'), false, 0, 'Question'), |
|
| 35 | - 'QGQ_order' => new EE_Integer_Field('QGQ_order', esc_html__('Question Group Question Order', 'event_espresso'), false, 0) |
|
| 36 | - ) |
|
| 37 | - ); |
|
| 38 | - $this->_model_relations = array( |
|
| 39 | - 'Question_Group' => new EE_Belongs_To_Relation(), |
|
| 40 | - 'Question' => new EE_Belongs_To_Relation() |
|
| 41 | - ); |
|
| 23 | + protected function __construct($timezone = null) |
|
| 24 | + { |
|
| 25 | + $this->singular_item = esc_html__('Question Group to Question Link', 'event_espresso'); |
|
| 26 | + $this->plural_item = esc_html__('Question Group to Question Links', 'event_espresso'); |
|
| 27 | + $this->_tables = array( |
|
| 28 | + 'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID') |
|
| 29 | + ); |
|
| 30 | + $this->_fields = array( |
|
| 31 | + 'Question_Group_Question' => array( |
|
| 32 | + 'QGQ_ID' => new EE_Primary_Key_Int_Field('QGQ_ID', esc_html__('Question Group to Question Link ID', 'event_espresso')), |
|
| 33 | + 'QSG_ID' => new EE_Foreign_Key_Int_Field('QSG_ID', esc_html__('Question Group ID', 'event_espresso'), false, 0, 'Question_Group'), |
|
| 34 | + 'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question Id', 'event_espresso'), false, 0, 'Question'), |
|
| 35 | + 'QGQ_order' => new EE_Integer_Field('QGQ_order', esc_html__('Question Group Question Order', 'event_espresso'), false, 0) |
|
| 36 | + ) |
|
| 37 | + ); |
|
| 38 | + $this->_model_relations = array( |
|
| 39 | + 'Question_Group' => new EE_Belongs_To_Relation(), |
|
| 40 | + 'Question' => new EE_Belongs_To_Relation() |
|
| 41 | + ); |
|
| 42 | 42 | |
| 43 | - $this->_model_chain_to_wp_user = 'Question_Group'; |
|
| 44 | - // this model is generally available for reading |
|
| 45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 49 | - // use the caps for question groups |
|
| 50 | - $this->_caps_slug = 'question_groups'; |
|
| 51 | - parent::__construct($timezone); |
|
| 52 | - } |
|
| 43 | + $this->_model_chain_to_wp_user = 'Question_Group'; |
|
| 44 | + // this model is generally available for reading |
|
| 45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system'); |
|
| 49 | + // use the caps for question groups |
|
| 50 | + $this->_caps_slug = 'question_groups'; |
|
| 51 | + parent::__construct($timezone); |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -213,10 +213,10 @@ discard block |
||
| 213 | 213 | 'Question_Group_Question' => new EE_Has_Many_Relation() |
| 214 | 214 | ); |
| 215 | 215 | // this model is generally available for reading |
| 216 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 217 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 218 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 219 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 216 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
| 217 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 218 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 219 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 220 | 220 | parent::__construct($timezone); |
| 221 | 221 | } |
| 222 | 222 | |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function question_type_is_in_category($question_type, $category) |
| 258 | 258 | { |
| 259 | - if (!isset($this->_question_type_categories[ $category ])) { |
|
| 259 | + if ( ! isset($this->_question_type_categories[$category])) { |
|
| 260 | 260 | return false; |
| 261 | 261 | } |
| 262 | - return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
| 262 | + return in_array($question_type, $this->_question_type_categories[$category]); |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | */ |
| 271 | 271 | public function question_types_in_category($category) |
| 272 | 272 | { |
| 273 | - if (isset($this->_question_type_categories[ $category ])) { |
|
| 274 | - return $this->_question_type_categories[ $category ]; |
|
| 273 | + if (isset($this->_question_type_categories[$category])) { |
|
| 274 | + return $this->_question_type_categories[$category]; |
|
| 275 | 275 | } |
| 276 | 276 | return array(); |
| 277 | 277 | } |
@@ -410,8 +410,8 @@ discard block |
||
| 410 | 410 | public function absolute_max_for_system_question($system_question_value) |
| 411 | 411 | { |
| 412 | 412 | $maxes = $this->system_question_maxes(); |
| 413 | - if (isset($maxes[ $system_question_value ])) { |
|
| 414 | - return $maxes[ $system_question_value ]; |
|
| 413 | + if (isset($maxes[$system_question_value])) { |
|
| 414 | + return $maxes[$system_question_value]; |
|
| 415 | 415 | } else { |
| 416 | 416 | return EE_INF; |
| 417 | 417 | } |
@@ -10,437 +10,437 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class EEM_Question extends EEM_Soft_Delete_Base |
| 12 | 12 | { |
| 13 | - // constant used to indicate that the question type is COUNTRY |
|
| 14 | - const QST_type_country = 'COUNTRY'; |
|
| 13 | + // constant used to indicate that the question type is COUNTRY |
|
| 14 | + const QST_type_country = 'COUNTRY'; |
|
| 15 | 15 | |
| 16 | - // constant used to indicate that the question type is DATE |
|
| 17 | - const QST_type_date = 'DATE'; |
|
| 18 | - |
|
| 19 | - // constant used to indicate that the question type is DROPDOWN |
|
| 20 | - const QST_type_dropdown = 'DROPDOWN'; |
|
| 21 | - |
|
| 22 | - // constant used to indicate that the question type is CHECKBOX |
|
| 23 | - const QST_type_checkbox = 'CHECKBOX'; |
|
| 24 | - |
|
| 25 | - // constant used to indicate that the question type is RADIO_BTN |
|
| 26 | - const QST_type_radio = 'RADIO_BTN'; |
|
| 27 | - |
|
| 28 | - // constant used to indicate that the question type is STATE |
|
| 29 | - const QST_type_state = 'STATE'; |
|
| 30 | - |
|
| 31 | - // constant used to indicate that the question type is TEXT |
|
| 32 | - const QST_type_text = 'TEXT'; |
|
| 33 | - |
|
| 34 | - // constant used to indicate that the question type is TEXTAREA |
|
| 35 | - const QST_type_textarea = 'TEXTAREA'; |
|
| 36 | - |
|
| 37 | - // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
| 38 | - const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
| 39 | - |
|
| 40 | - // constant used to indicate that the question type is an email input |
|
| 41 | - const QST_type_email = 'EMAIL'; |
|
| 42 | - |
|
| 43 | - // constant used to indicate that the question type is an email input |
|
| 44 | - const QST_type_email_confirm = 'EMAIL_CONFIRM'; |
|
| 45 | - |
|
| 46 | - // constant used to indicate that the question type is a US-formatted phone number |
|
| 47 | - const QST_type_us_phone = 'US_PHONE'; |
|
| 48 | - |
|
| 49 | - // constant used to indicate that the question type is an integer (whole number) |
|
| 50 | - const QST_type_int = 'INTEGER'; |
|
| 51 | - |
|
| 52 | - // constant used to indicate that the question type is a decimal (float) |
|
| 53 | - const QST_type_decimal = 'DECIMAL'; |
|
| 54 | - |
|
| 55 | - // constant used to indicate that the question type is a valid URL |
|
| 56 | - const QST_type_url = 'URL'; |
|
| 57 | - |
|
| 58 | - // constant used to indicate that the question type is a YEAR |
|
| 59 | - const QST_type_year = 'YEAR'; |
|
| 60 | - |
|
| 61 | - // constant used to indicate that the question type is a multi-select |
|
| 62 | - const QST_type_multi_select = 'MULTI_SELECT'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Question types that are interchangeable, even after answers have been provided for them. |
|
| 66 | - * Top-level keys are category slugs, next level is an array of question types. If question types |
|
| 67 | - * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
| 68 | - * |
|
| 69 | - * @access protected |
|
| 70 | - * @var array $_question_type_categories { |
|
| 71 | - * @type string $text |
|
| 72 | - * @type string $single -answer-enum |
|
| 73 | - * @type string $multi -answer-enum |
|
| 74 | - * } |
|
| 75 | - */ |
|
| 76 | - protected $_question_type_categories = array(); |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
| 80 | - * |
|
| 81 | - * @access protected |
|
| 82 | - * @var array $_allowed_question_types |
|
| 83 | - */ |
|
| 84 | - protected $_allowed_question_types = array(); |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * brief descriptions for all the question types |
|
| 88 | - * |
|
| 89 | - * @access protected |
|
| 90 | - * @var EEM_Question $_instance |
|
| 91 | - */ |
|
| 92 | - protected $_question_descriptions; |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Question types that should have an admin-defined max input length |
|
| 97 | - * @var array |
|
| 98 | - */ |
|
| 99 | - protected $question_types_with_max_lengh; |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - // private instance of the Attendee object |
|
| 103 | - protected static $_instance = null; |
|
| 104 | - |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * EEM_Question constructor. |
|
| 108 | - * |
|
| 109 | - * @param null $timezone |
|
| 110 | - */ |
|
| 111 | - protected function __construct($timezone = null) |
|
| 112 | - { |
|
| 113 | - $this->singular_item = esc_html__('Question', 'event_espresso'); |
|
| 114 | - $this->plural_item = esc_html__('Questions', 'event_espresso'); |
|
| 115 | - $this->_allowed_question_types = apply_filters( |
|
| 116 | - 'FHEE__EEM_Question__construct__allowed_question_types', |
|
| 117 | - array( |
|
| 118 | - EEM_Question::QST_type_text => esc_html__('Text', 'event_espresso'), |
|
| 119 | - EEM_Question::QST_type_textarea => esc_html__('Textarea', 'event_espresso'), |
|
| 120 | - EEM_Question::QST_type_checkbox => esc_html__('Checkboxes', 'event_espresso'), |
|
| 121 | - EEM_Question::QST_type_radio => esc_html__('Radio Buttons', 'event_espresso'), |
|
| 122 | - EEM_Question::QST_type_dropdown => esc_html__('Dropdown', 'event_espresso'), |
|
| 123 | - EEM_Question::QST_type_state => esc_html__('State/Province Dropdown', 'event_espresso'), |
|
| 124 | - EEM_Question::QST_type_country => esc_html__('Country Dropdown', 'event_espresso'), |
|
| 125 | - EEM_Question::QST_type_date => esc_html__('Date Picker', 'event_espresso'), |
|
| 126 | - EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'), |
|
| 127 | - EEM_Question::QST_type_email => esc_html__('Email', 'event_espresso'), |
|
| 128 | - EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'), |
|
| 129 | - EEM_Question::QST_type_us_phone => esc_html__('USA - Format Phone', 'event_espresso'), |
|
| 130 | - EEM_Question::QST_type_decimal => esc_html__('Number', 'event_espresso'), |
|
| 131 | - EEM_Question::QST_type_int => esc_html__('Whole Number', 'event_espresso'), |
|
| 132 | - EEM_Question::QST_type_url => esc_html__('URL', 'event_espresso'), |
|
| 133 | - EEM_Question::QST_type_year => esc_html__('Year', 'event_espresso'), |
|
| 134 | - EEM_Question::QST_type_multi_select => esc_html__('Multi Select', 'event_espresso') |
|
| 135 | - ) |
|
| 136 | - ); |
|
| 137 | - $this->_question_descriptions = apply_filters( |
|
| 138 | - 'FHEE__EEM_Question__construct__question_descriptions', |
|
| 139 | - array( |
|
| 140 | - EEM_Question::QST_type_text => esc_html__('A single line text input field', 'event_espresso'), |
|
| 141 | - EEM_Question::QST_type_textarea => esc_html__('A multi line text input field', 'event_espresso'), |
|
| 142 | - EEM_Question::QST_type_checkbox => esc_html__('Allows multiple preset options to be selected', 'event_espresso'), |
|
| 143 | - EEM_Question::QST_type_radio => esc_html__('Allows a single preset option to be selected', 'event_espresso'), |
|
| 144 | - EEM_Question::QST_type_dropdown => esc_html__('A dropdown that allows a single selection', 'event_espresso'), |
|
| 145 | - EEM_Question::QST_type_state => esc_html__('A dropdown that lists states/provinces', 'event_espresso'), |
|
| 146 | - EEM_Question::QST_type_country => esc_html__('A dropdown that lists countries', 'event_espresso'), |
|
| 147 | - EEM_Question::QST_type_date => esc_html__('A popup calendar that allows date selections', 'event_espresso'), |
|
| 148 | - EEM_Question::QST_type_html_textarea => esc_html__('A multi line text input field that allows HTML', 'event_espresso'), |
|
| 149 | - EEM_Question::QST_type_email => esc_html__('A text field that must contain a valid Email address', 'event_espresso'), |
|
| 150 | - EEM_Question::QST_type_email_confirm => esc_html__('A text field that must contain a valid Email address and be equal to Email field', 'event_espresso'), |
|
| 151 | - EEM_Question::QST_type_us_phone => esc_html__('A text field that must contain a valid US phone number', 'event_espresso'), |
|
| 152 | - EEM_Question::QST_type_decimal => esc_html__('A text field that allows number values with decimals', 'event_espresso'), |
|
| 153 | - EEM_Question::QST_type_int => esc_html__('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
| 154 | - EEM_Question::QST_type_url => esc_html__('A text field that must contain a valid URL', 'event_espresso'), |
|
| 155 | - EEM_Question::QST_type_year => esc_html__('A dropdown that lists the last 100 years', 'event_espresso'), |
|
| 156 | - EEM_Question::QST_type_multi_select => esc_html__('A dropdown that allows multiple selections', 'event_espresso') |
|
| 157 | - ) |
|
| 158 | - ); |
|
| 159 | - $this->_question_type_categories = (array) apply_filters( |
|
| 160 | - 'FHEE__EEM_Question__construct__question_type_categories', |
|
| 161 | - array( |
|
| 162 | - 'text' => array( |
|
| 163 | - EEM_Question::QST_type_text, |
|
| 164 | - EEM_Question::QST_type_textarea, |
|
| 165 | - EEM_Question::QST_type_date, |
|
| 166 | - EEM_Question::QST_type_html_textarea, |
|
| 167 | - EEM_Question::QST_type_email, |
|
| 168 | - EEM_Question::QST_type_email_confirm, |
|
| 169 | - EEM_Question::QST_type_us_phone, |
|
| 170 | - EEM_Question::QST_type_decimal, |
|
| 171 | - EEM_Question::QST_type_int, |
|
| 172 | - EEM_Question::QST_type_url, |
|
| 173 | - EEM_Question::QST_type_year |
|
| 174 | - ), |
|
| 175 | - 'single-answer-enum' => array( |
|
| 176 | - EEM_Question::QST_type_radio, |
|
| 177 | - EEM_Question::QST_type_dropdown |
|
| 178 | - ), |
|
| 179 | - 'multi-answer-enum' => array( |
|
| 180 | - EEM_Question::QST_type_checkbox, |
|
| 181 | - EEM_Question::QST_type_multi_select |
|
| 182 | - ) |
|
| 183 | - ) |
|
| 184 | - ); |
|
| 185 | - $this->question_types_with_max_lengh = apply_filters( |
|
| 186 | - 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
| 187 | - array( |
|
| 188 | - EEM_Question::QST_type_text, |
|
| 189 | - EEM_Question::QST_type_textarea, |
|
| 190 | - EEM_Question::QST_type_html_textarea |
|
| 191 | - ) |
|
| 192 | - ); |
|
| 193 | - |
|
| 194 | - $this->_tables = array( |
|
| 195 | - 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
| 196 | - ); |
|
| 197 | - $this->_fields = array( |
|
| 198 | - 'Question' => array( |
|
| 199 | - 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso')), |
|
| 200 | - 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', esc_html__('Question Text', 'event_espresso'), true, ''), |
|
| 201 | - 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', esc_html__('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
| 202 | - 'QST_system' => new EE_Plain_Text_Field('QST_system', esc_html__('Internal string ID for question', 'event_espresso'), false, ''), |
|
| 203 | - 'QST_type' => new EE_Enum_Text_Field('QST_type', esc_html__('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
| 204 | - 'QST_required' => new EE_Boolean_Field('QST_required', esc_html__('Required Question?', 'event_espresso'), false, false), |
|
| 205 | - 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', esc_html__('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
| 206 | - 'QST_order' => new EE_Integer_Field('QST_order', esc_html__('Question Order', 'event_espresso'), false, 0), |
|
| 207 | - 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', esc_html__('Admin-Only Question?', 'event_espresso'), false, false), |
|
| 208 | - 'QST_max' => new EE_Infinite_Integer_Field('QST_max', esc_html__('Max Size', 'event_espresso'), false, EE_INF), |
|
| 209 | - 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', esc_html__('Question Creator ID', 'event_espresso'), false), |
|
| 210 | - 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', esc_html__('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
| 211 | - ) |
|
| 212 | - ); |
|
| 213 | - $this->_model_relations = array( |
|
| 214 | - 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
| 215 | - 'Question_Option' => new EE_Has_Many_Relation(), |
|
| 216 | - 'Answer' => new EE_Has_Many_Relation(), |
|
| 217 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 218 | - // for QST_order column |
|
| 219 | - 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
| 220 | - ); |
|
| 221 | - // this model is generally available for reading |
|
| 222 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 223 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 224 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 225 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 226 | - parent::__construct($timezone); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
| 231 | - * but they can be extended |
|
| 232 | - * @return string[] |
|
| 233 | - */ |
|
| 234 | - public function allowed_question_types() |
|
| 235 | - { |
|
| 236 | - return $this->_allowed_question_types; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Gets all the question types in the same category |
|
| 241 | - * @param string $question_type one of EEM_Question::allowed_question_types( |
|
| 242 | - * @return string[] like EEM_Question::allowed_question_types() |
|
| 243 | - */ |
|
| 244 | - public function question_types_in_same_category($question_type) |
|
| 245 | - { |
|
| 246 | - $question_types = array($question_type); |
|
| 247 | - foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
| 248 | - if (in_array($question_type, $question_types_in_category)) { |
|
| 249 | - $question_types = $question_types_in_category; |
|
| 250 | - break; |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Determines if the given question type is in the given question type category |
|
| 259 | - * @param string $question_type one of EEM_Question::allowed_question_types() |
|
| 260 | - * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
| 261 | - * @return boolean |
|
| 262 | - */ |
|
| 263 | - public function question_type_is_in_category($question_type, $category) |
|
| 264 | - { |
|
| 265 | - if (!isset($this->_question_type_categories[ $category ])) { |
|
| 266 | - return false; |
|
| 267 | - } |
|
| 268 | - return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Returns all the question types in the given category |
|
| 274 | - * @param string $category |
|
| 275 | - * @return array|mixed |
|
| 276 | - */ |
|
| 277 | - public function question_types_in_category($category) |
|
| 278 | - { |
|
| 279 | - if (isset($this->_question_type_categories[ $category ])) { |
|
| 280 | - return $this->_question_type_categories[ $category ]; |
|
| 281 | - } |
|
| 282 | - return array(); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Returns all the question types that should have question options |
|
| 288 | - * @return array |
|
| 289 | - */ |
|
| 290 | - public function question_types_with_options() |
|
| 291 | - { |
|
| 292 | - return array_merge( |
|
| 293 | - $this->question_types_in_category('single-answer-enum'), |
|
| 294 | - $this->question_types_in_category('multi-answer-enum') |
|
| 295 | - ); |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Returns the question type categories 2d array |
|
| 300 | - * @return array see EEM_Question::_question_type_categories |
|
| 301 | - */ |
|
| 302 | - public function question_type_categories() |
|
| 303 | - { |
|
| 304 | - return $this->_question_type_categories; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Returns an array of all the QST_system values that can be allowed in the system question group |
|
| 309 | - * identified by $system_question_group_id |
|
| 310 | - * @param string $system_question_group_id QSG_system |
|
| 311 | - * @return array of system question names (QST_system) |
|
| 312 | - */ |
|
| 313 | - public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
| 314 | - { |
|
| 315 | - $question_system_ids = array(); |
|
| 316 | - switch ($system_question_group_id) { |
|
| 317 | - case EEM_Question_Group::system_personal: |
|
| 318 | - $question_system_ids = array( |
|
| 319 | - EEM_Attendee::system_question_fname, |
|
| 320 | - EEM_Attendee::system_question_lname, |
|
| 321 | - EEM_Attendee::system_question_email, |
|
| 322 | - EEM_Attendee::system_question_email_confirm, |
|
| 323 | - EEM_Attendee::system_question_phone |
|
| 324 | - ); |
|
| 325 | - break; |
|
| 326 | - case EEM_Question_Group::system_address: |
|
| 327 | - $question_system_ids = array( |
|
| 328 | - EEM_Attendee::system_question_address, |
|
| 329 | - EEM_Attendee::system_question_address2, |
|
| 330 | - EEM_Attendee::system_question_city, |
|
| 331 | - EEM_Attendee::system_question_state, |
|
| 332 | - EEM_Attendee::system_question_country, |
|
| 333 | - EEM_Attendee::system_question_zip, |
|
| 334 | - EEM_Attendee::system_question_phone |
|
| 335 | - ); |
|
| 336 | - break; |
|
| 337 | - } |
|
| 338 | - return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Returns an array of all the QST_system values that are required in the system question group |
|
| 343 | - * identified by $system_question_group_id |
|
| 344 | - * @param string $system_question_group_id QSG_system |
|
| 345 | - * @return array of system question names (QST_system) |
|
| 346 | - */ |
|
| 347 | - public function required_system_questions_in_system_question_group($system_question_group_id) |
|
| 348 | - { |
|
| 349 | - $question_system_ids = null; |
|
| 350 | - switch ($system_question_group_id) { |
|
| 351 | - case EEM_Question_Group::system_personal: |
|
| 352 | - $question_system_ids = array( |
|
| 353 | - EEM_Attendee::system_question_fname, |
|
| 354 | - EEM_Attendee::system_question_email, |
|
| 355 | - ); |
|
| 356 | - break; |
|
| 357 | - default: |
|
| 358 | - $question_system_ids = array(); |
|
| 359 | - } |
|
| 360 | - return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
| 366 | - * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
| 367 | - * @param $QST_system |
|
| 368 | - * @return int of QST_ID for the question that corresponds to that QST_system |
|
| 369 | - */ |
|
| 370 | - public function get_Question_ID_from_system_string($QST_system) |
|
| 371 | - { |
|
| 372 | - return $this->get_var(array(array('QST_system' => $QST_system))); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * searches the db for the question with the latest question order and returns that value. |
|
| 378 | - * @access public |
|
| 379 | - * @return int |
|
| 380 | - */ |
|
| 381 | - public function get_latest_question_order() |
|
| 382 | - { |
|
| 383 | - $columns_to_select = array( |
|
| 384 | - 'max_order' => array("MAX(QST_order)", "%d") |
|
| 385 | - ); |
|
| 386 | - $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
| 387 | - return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Returns an array where keys are system question QST_system values, |
|
| 392 | - * and values are the highest question max the admin can set on the question |
|
| 393 | - * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
| 394 | - * of 5, but no larger than 12) |
|
| 395 | - * @return array |
|
| 396 | - */ |
|
| 397 | - public function system_question_maxes() |
|
| 398 | - { |
|
| 399 | - return array( |
|
| 400 | - 'fname' => 45, |
|
| 401 | - 'lname' => 45, |
|
| 402 | - 'address' => 255, |
|
| 403 | - 'address2' => 255, |
|
| 404 | - 'city' => 45, |
|
| 405 | - 'zip' => 12, |
|
| 406 | - 'email' => 255, |
|
| 407 | - 'email_confirm' => 255, |
|
| 408 | - 'phone' => 45, |
|
| 409 | - ); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * Given a QST_system value, gets the question's largest allowable max input. |
|
| 414 | - * @see Registration_Form_Admin_Page::system_question_maxes() |
|
| 415 | - * @param string $system_question_value |
|
| 416 | - * @return int|float |
|
| 417 | - */ |
|
| 418 | - public function absolute_max_for_system_question($system_question_value) |
|
| 419 | - { |
|
| 420 | - $maxes = $this->system_question_maxes(); |
|
| 421 | - if (isset($maxes[ $system_question_value ])) { |
|
| 422 | - return $maxes[ $system_question_value ]; |
|
| 423 | - } else { |
|
| 424 | - return EE_INF; |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * @return array |
|
| 431 | - */ |
|
| 432 | - public function question_descriptions() |
|
| 433 | - { |
|
| 434 | - return $this->_question_descriptions; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Returns all the question types that should have an admin-defined max input length |
|
| 440 | - * @return array |
|
| 441 | - */ |
|
| 442 | - public function questionTypesWithMaxLength() |
|
| 443 | - { |
|
| 444 | - return (array) $this->question_types_with_max_lengh; |
|
| 445 | - } |
|
| 16 | + // constant used to indicate that the question type is DATE |
|
| 17 | + const QST_type_date = 'DATE'; |
|
| 18 | + |
|
| 19 | + // constant used to indicate that the question type is DROPDOWN |
|
| 20 | + const QST_type_dropdown = 'DROPDOWN'; |
|
| 21 | + |
|
| 22 | + // constant used to indicate that the question type is CHECKBOX |
|
| 23 | + const QST_type_checkbox = 'CHECKBOX'; |
|
| 24 | + |
|
| 25 | + // constant used to indicate that the question type is RADIO_BTN |
|
| 26 | + const QST_type_radio = 'RADIO_BTN'; |
|
| 27 | + |
|
| 28 | + // constant used to indicate that the question type is STATE |
|
| 29 | + const QST_type_state = 'STATE'; |
|
| 30 | + |
|
| 31 | + // constant used to indicate that the question type is TEXT |
|
| 32 | + const QST_type_text = 'TEXT'; |
|
| 33 | + |
|
| 34 | + // constant used to indicate that the question type is TEXTAREA |
|
| 35 | + const QST_type_textarea = 'TEXTAREA'; |
|
| 36 | + |
|
| 37 | + // constant used to indicate that the question type is a TEXTAREA that allows simple html |
|
| 38 | + const QST_type_html_textarea = 'HTML_TEXTAREA'; |
|
| 39 | + |
|
| 40 | + // constant used to indicate that the question type is an email input |
|
| 41 | + const QST_type_email = 'EMAIL'; |
|
| 42 | + |
|
| 43 | + // constant used to indicate that the question type is an email input |
|
| 44 | + const QST_type_email_confirm = 'EMAIL_CONFIRM'; |
|
| 45 | + |
|
| 46 | + // constant used to indicate that the question type is a US-formatted phone number |
|
| 47 | + const QST_type_us_phone = 'US_PHONE'; |
|
| 48 | + |
|
| 49 | + // constant used to indicate that the question type is an integer (whole number) |
|
| 50 | + const QST_type_int = 'INTEGER'; |
|
| 51 | + |
|
| 52 | + // constant used to indicate that the question type is a decimal (float) |
|
| 53 | + const QST_type_decimal = 'DECIMAL'; |
|
| 54 | + |
|
| 55 | + // constant used to indicate that the question type is a valid URL |
|
| 56 | + const QST_type_url = 'URL'; |
|
| 57 | + |
|
| 58 | + // constant used to indicate that the question type is a YEAR |
|
| 59 | + const QST_type_year = 'YEAR'; |
|
| 60 | + |
|
| 61 | + // constant used to indicate that the question type is a multi-select |
|
| 62 | + const QST_type_multi_select = 'MULTI_SELECT'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Question types that are interchangeable, even after answers have been provided for them. |
|
| 66 | + * Top-level keys are category slugs, next level is an array of question types. If question types |
|
| 67 | + * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
|
| 68 | + * |
|
| 69 | + * @access protected |
|
| 70 | + * @var array $_question_type_categories { |
|
| 71 | + * @type string $text |
|
| 72 | + * @type string $single -answer-enum |
|
| 73 | + * @type string $multi -answer-enum |
|
| 74 | + * } |
|
| 75 | + */ |
|
| 76 | + protected $_question_type_categories = array(); |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * lists all the question types which should be allowed. Ideally, this will be extensible. |
|
| 80 | + * |
|
| 81 | + * @access protected |
|
| 82 | + * @var array $_allowed_question_types |
|
| 83 | + */ |
|
| 84 | + protected $_allowed_question_types = array(); |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * brief descriptions for all the question types |
|
| 88 | + * |
|
| 89 | + * @access protected |
|
| 90 | + * @var EEM_Question $_instance |
|
| 91 | + */ |
|
| 92 | + protected $_question_descriptions; |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Question types that should have an admin-defined max input length |
|
| 97 | + * @var array |
|
| 98 | + */ |
|
| 99 | + protected $question_types_with_max_lengh; |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + // private instance of the Attendee object |
|
| 103 | + protected static $_instance = null; |
|
| 104 | + |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * EEM_Question constructor. |
|
| 108 | + * |
|
| 109 | + * @param null $timezone |
|
| 110 | + */ |
|
| 111 | + protected function __construct($timezone = null) |
|
| 112 | + { |
|
| 113 | + $this->singular_item = esc_html__('Question', 'event_espresso'); |
|
| 114 | + $this->plural_item = esc_html__('Questions', 'event_espresso'); |
|
| 115 | + $this->_allowed_question_types = apply_filters( |
|
| 116 | + 'FHEE__EEM_Question__construct__allowed_question_types', |
|
| 117 | + array( |
|
| 118 | + EEM_Question::QST_type_text => esc_html__('Text', 'event_espresso'), |
|
| 119 | + EEM_Question::QST_type_textarea => esc_html__('Textarea', 'event_espresso'), |
|
| 120 | + EEM_Question::QST_type_checkbox => esc_html__('Checkboxes', 'event_espresso'), |
|
| 121 | + EEM_Question::QST_type_radio => esc_html__('Radio Buttons', 'event_espresso'), |
|
| 122 | + EEM_Question::QST_type_dropdown => esc_html__('Dropdown', 'event_espresso'), |
|
| 123 | + EEM_Question::QST_type_state => esc_html__('State/Province Dropdown', 'event_espresso'), |
|
| 124 | + EEM_Question::QST_type_country => esc_html__('Country Dropdown', 'event_espresso'), |
|
| 125 | + EEM_Question::QST_type_date => esc_html__('Date Picker', 'event_espresso'), |
|
| 126 | + EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'), |
|
| 127 | + EEM_Question::QST_type_email => esc_html__('Email', 'event_espresso'), |
|
| 128 | + EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'), |
|
| 129 | + EEM_Question::QST_type_us_phone => esc_html__('USA - Format Phone', 'event_espresso'), |
|
| 130 | + EEM_Question::QST_type_decimal => esc_html__('Number', 'event_espresso'), |
|
| 131 | + EEM_Question::QST_type_int => esc_html__('Whole Number', 'event_espresso'), |
|
| 132 | + EEM_Question::QST_type_url => esc_html__('URL', 'event_espresso'), |
|
| 133 | + EEM_Question::QST_type_year => esc_html__('Year', 'event_espresso'), |
|
| 134 | + EEM_Question::QST_type_multi_select => esc_html__('Multi Select', 'event_espresso') |
|
| 135 | + ) |
|
| 136 | + ); |
|
| 137 | + $this->_question_descriptions = apply_filters( |
|
| 138 | + 'FHEE__EEM_Question__construct__question_descriptions', |
|
| 139 | + array( |
|
| 140 | + EEM_Question::QST_type_text => esc_html__('A single line text input field', 'event_espresso'), |
|
| 141 | + EEM_Question::QST_type_textarea => esc_html__('A multi line text input field', 'event_espresso'), |
|
| 142 | + EEM_Question::QST_type_checkbox => esc_html__('Allows multiple preset options to be selected', 'event_espresso'), |
|
| 143 | + EEM_Question::QST_type_radio => esc_html__('Allows a single preset option to be selected', 'event_espresso'), |
|
| 144 | + EEM_Question::QST_type_dropdown => esc_html__('A dropdown that allows a single selection', 'event_espresso'), |
|
| 145 | + EEM_Question::QST_type_state => esc_html__('A dropdown that lists states/provinces', 'event_espresso'), |
|
| 146 | + EEM_Question::QST_type_country => esc_html__('A dropdown that lists countries', 'event_espresso'), |
|
| 147 | + EEM_Question::QST_type_date => esc_html__('A popup calendar that allows date selections', 'event_espresso'), |
|
| 148 | + EEM_Question::QST_type_html_textarea => esc_html__('A multi line text input field that allows HTML', 'event_espresso'), |
|
| 149 | + EEM_Question::QST_type_email => esc_html__('A text field that must contain a valid Email address', 'event_espresso'), |
|
| 150 | + EEM_Question::QST_type_email_confirm => esc_html__('A text field that must contain a valid Email address and be equal to Email field', 'event_espresso'), |
|
| 151 | + EEM_Question::QST_type_us_phone => esc_html__('A text field that must contain a valid US phone number', 'event_espresso'), |
|
| 152 | + EEM_Question::QST_type_decimal => esc_html__('A text field that allows number values with decimals', 'event_espresso'), |
|
| 153 | + EEM_Question::QST_type_int => esc_html__('A text field that only allows whole numbers (no decimals)', 'event_espresso'), |
|
| 154 | + EEM_Question::QST_type_url => esc_html__('A text field that must contain a valid URL', 'event_espresso'), |
|
| 155 | + EEM_Question::QST_type_year => esc_html__('A dropdown that lists the last 100 years', 'event_espresso'), |
|
| 156 | + EEM_Question::QST_type_multi_select => esc_html__('A dropdown that allows multiple selections', 'event_espresso') |
|
| 157 | + ) |
|
| 158 | + ); |
|
| 159 | + $this->_question_type_categories = (array) apply_filters( |
|
| 160 | + 'FHEE__EEM_Question__construct__question_type_categories', |
|
| 161 | + array( |
|
| 162 | + 'text' => array( |
|
| 163 | + EEM_Question::QST_type_text, |
|
| 164 | + EEM_Question::QST_type_textarea, |
|
| 165 | + EEM_Question::QST_type_date, |
|
| 166 | + EEM_Question::QST_type_html_textarea, |
|
| 167 | + EEM_Question::QST_type_email, |
|
| 168 | + EEM_Question::QST_type_email_confirm, |
|
| 169 | + EEM_Question::QST_type_us_phone, |
|
| 170 | + EEM_Question::QST_type_decimal, |
|
| 171 | + EEM_Question::QST_type_int, |
|
| 172 | + EEM_Question::QST_type_url, |
|
| 173 | + EEM_Question::QST_type_year |
|
| 174 | + ), |
|
| 175 | + 'single-answer-enum' => array( |
|
| 176 | + EEM_Question::QST_type_radio, |
|
| 177 | + EEM_Question::QST_type_dropdown |
|
| 178 | + ), |
|
| 179 | + 'multi-answer-enum' => array( |
|
| 180 | + EEM_Question::QST_type_checkbox, |
|
| 181 | + EEM_Question::QST_type_multi_select |
|
| 182 | + ) |
|
| 183 | + ) |
|
| 184 | + ); |
|
| 185 | + $this->question_types_with_max_lengh = apply_filters( |
|
| 186 | + 'FHEE__EEM_Question___construct__question_types_with_max_length', |
|
| 187 | + array( |
|
| 188 | + EEM_Question::QST_type_text, |
|
| 189 | + EEM_Question::QST_type_textarea, |
|
| 190 | + EEM_Question::QST_type_html_textarea |
|
| 191 | + ) |
|
| 192 | + ); |
|
| 193 | + |
|
| 194 | + $this->_tables = array( |
|
| 195 | + 'Question' => new EE_Primary_Table('esp_question', 'QST_ID') |
|
| 196 | + ); |
|
| 197 | + $this->_fields = array( |
|
| 198 | + 'Question' => array( |
|
| 199 | + 'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso')), |
|
| 200 | + 'QST_display_text' => new EE_Post_Content_Field('QST_display_text', esc_html__('Question Text', 'event_espresso'), true, ''), |
|
| 201 | + 'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', esc_html__('Question Label (admin-only)', 'event_espresso'), true, ''), |
|
| 202 | + 'QST_system' => new EE_Plain_Text_Field('QST_system', esc_html__('Internal string ID for question', 'event_espresso'), false, ''), |
|
| 203 | + 'QST_type' => new EE_Enum_Text_Field('QST_type', esc_html__('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types), |
|
| 204 | + 'QST_required' => new EE_Boolean_Field('QST_required', esc_html__('Required Question?', 'event_espresso'), false, false), |
|
| 205 | + 'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', esc_html__('Text to Display if Not Provided', 'event_espresso'), true, ''), |
|
| 206 | + 'QST_order' => new EE_Integer_Field('QST_order', esc_html__('Question Order', 'event_espresso'), false, 0), |
|
| 207 | + 'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', esc_html__('Admin-Only Question?', 'event_espresso'), false, false), |
|
| 208 | + 'QST_max' => new EE_Infinite_Integer_Field('QST_max', esc_html__('Max Size', 'event_espresso'), false, EE_INF), |
|
| 209 | + 'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', esc_html__('Question Creator ID', 'event_espresso'), false), |
|
| 210 | + 'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', esc_html__('Flag Indicating question was deleted', 'event_espresso'), false, false) |
|
| 211 | + ) |
|
| 212 | + ); |
|
| 213 | + $this->_model_relations = array( |
|
| 214 | + 'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'), |
|
| 215 | + 'Question_Option' => new EE_Has_Many_Relation(), |
|
| 216 | + 'Answer' => new EE_Has_Many_Relation(), |
|
| 217 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
| 218 | + // for QST_order column |
|
| 219 | + 'Question_Group_Question' => new EE_Has_Many_Relation() |
|
| 220 | + ); |
|
| 221 | + // this model is generally available for reading |
|
| 222 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
| 223 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 224 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 225 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system'); |
|
| 226 | + parent::__construct($timezone); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
|
| 231 | + * but they can be extended |
|
| 232 | + * @return string[] |
|
| 233 | + */ |
|
| 234 | + public function allowed_question_types() |
|
| 235 | + { |
|
| 236 | + return $this->_allowed_question_types; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Gets all the question types in the same category |
|
| 241 | + * @param string $question_type one of EEM_Question::allowed_question_types( |
|
| 242 | + * @return string[] like EEM_Question::allowed_question_types() |
|
| 243 | + */ |
|
| 244 | + public function question_types_in_same_category($question_type) |
|
| 245 | + { |
|
| 246 | + $question_types = array($question_type); |
|
| 247 | + foreach ($this->_question_type_categories as $category => $question_types_in_category) { |
|
| 248 | + if (in_array($question_type, $question_types_in_category)) { |
|
| 249 | + $question_types = $question_types_in_category; |
|
| 250 | + break; |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return array_intersect_key($this->allowed_question_types(), array_flip($question_types)); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Determines if the given question type is in the given question type category |
|
| 259 | + * @param string $question_type one of EEM_Question::allowed_question_types() |
|
| 260 | + * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
|
| 261 | + * @return boolean |
|
| 262 | + */ |
|
| 263 | + public function question_type_is_in_category($question_type, $category) |
|
| 264 | + { |
|
| 265 | + if (!isset($this->_question_type_categories[ $category ])) { |
|
| 266 | + return false; |
|
| 267 | + } |
|
| 268 | + return in_array($question_type, $this->_question_type_categories[ $category ]); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Returns all the question types in the given category |
|
| 274 | + * @param string $category |
|
| 275 | + * @return array|mixed |
|
| 276 | + */ |
|
| 277 | + public function question_types_in_category($category) |
|
| 278 | + { |
|
| 279 | + if (isset($this->_question_type_categories[ $category ])) { |
|
| 280 | + return $this->_question_type_categories[ $category ]; |
|
| 281 | + } |
|
| 282 | + return array(); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Returns all the question types that should have question options |
|
| 288 | + * @return array |
|
| 289 | + */ |
|
| 290 | + public function question_types_with_options() |
|
| 291 | + { |
|
| 292 | + return array_merge( |
|
| 293 | + $this->question_types_in_category('single-answer-enum'), |
|
| 294 | + $this->question_types_in_category('multi-answer-enum') |
|
| 295 | + ); |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Returns the question type categories 2d array |
|
| 300 | + * @return array see EEM_Question::_question_type_categories |
|
| 301 | + */ |
|
| 302 | + public function question_type_categories() |
|
| 303 | + { |
|
| 304 | + return $this->_question_type_categories; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Returns an array of all the QST_system values that can be allowed in the system question group |
|
| 309 | + * identified by $system_question_group_id |
|
| 310 | + * @param string $system_question_group_id QSG_system |
|
| 311 | + * @return array of system question names (QST_system) |
|
| 312 | + */ |
|
| 313 | + public function allowed_system_questions_in_system_question_group($system_question_group_id) |
|
| 314 | + { |
|
| 315 | + $question_system_ids = array(); |
|
| 316 | + switch ($system_question_group_id) { |
|
| 317 | + case EEM_Question_Group::system_personal: |
|
| 318 | + $question_system_ids = array( |
|
| 319 | + EEM_Attendee::system_question_fname, |
|
| 320 | + EEM_Attendee::system_question_lname, |
|
| 321 | + EEM_Attendee::system_question_email, |
|
| 322 | + EEM_Attendee::system_question_email_confirm, |
|
| 323 | + EEM_Attendee::system_question_phone |
|
| 324 | + ); |
|
| 325 | + break; |
|
| 326 | + case EEM_Question_Group::system_address: |
|
| 327 | + $question_system_ids = array( |
|
| 328 | + EEM_Attendee::system_question_address, |
|
| 329 | + EEM_Attendee::system_question_address2, |
|
| 330 | + EEM_Attendee::system_question_city, |
|
| 331 | + EEM_Attendee::system_question_state, |
|
| 332 | + EEM_Attendee::system_question_country, |
|
| 333 | + EEM_Attendee::system_question_zip, |
|
| 334 | + EEM_Attendee::system_question_phone |
|
| 335 | + ); |
|
| 336 | + break; |
|
| 337 | + } |
|
| 338 | + return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Returns an array of all the QST_system values that are required in the system question group |
|
| 343 | + * identified by $system_question_group_id |
|
| 344 | + * @param string $system_question_group_id QSG_system |
|
| 345 | + * @return array of system question names (QST_system) |
|
| 346 | + */ |
|
| 347 | + public function required_system_questions_in_system_question_group($system_question_group_id) |
|
| 348 | + { |
|
| 349 | + $question_system_ids = null; |
|
| 350 | + switch ($system_question_group_id) { |
|
| 351 | + case EEM_Question_Group::system_personal: |
|
| 352 | + $question_system_ids = array( |
|
| 353 | + EEM_Attendee::system_question_fname, |
|
| 354 | + EEM_Attendee::system_question_email, |
|
| 355 | + ); |
|
| 356 | + break; |
|
| 357 | + default: |
|
| 358 | + $question_system_ids = array(); |
|
| 359 | + } |
|
| 360 | + return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
|
| 366 | + * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
|
| 367 | + * @param $QST_system |
|
| 368 | + * @return int of QST_ID for the question that corresponds to that QST_system |
|
| 369 | + */ |
|
| 370 | + public function get_Question_ID_from_system_string($QST_system) |
|
| 371 | + { |
|
| 372 | + return $this->get_var(array(array('QST_system' => $QST_system))); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * searches the db for the question with the latest question order and returns that value. |
|
| 378 | + * @access public |
|
| 379 | + * @return int |
|
| 380 | + */ |
|
| 381 | + public function get_latest_question_order() |
|
| 382 | + { |
|
| 383 | + $columns_to_select = array( |
|
| 384 | + 'max_order' => array("MAX(QST_order)", "%d") |
|
| 385 | + ); |
|
| 386 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
| 387 | + return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Returns an array where keys are system question QST_system values, |
|
| 392 | + * and values are the highest question max the admin can set on the question |
|
| 393 | + * (aka the "max max"; eg, a site admin can change the zip question to have a max |
|
| 394 | + * of 5, but no larger than 12) |
|
| 395 | + * @return array |
|
| 396 | + */ |
|
| 397 | + public function system_question_maxes() |
|
| 398 | + { |
|
| 399 | + return array( |
|
| 400 | + 'fname' => 45, |
|
| 401 | + 'lname' => 45, |
|
| 402 | + 'address' => 255, |
|
| 403 | + 'address2' => 255, |
|
| 404 | + 'city' => 45, |
|
| 405 | + 'zip' => 12, |
|
| 406 | + 'email' => 255, |
|
| 407 | + 'email_confirm' => 255, |
|
| 408 | + 'phone' => 45, |
|
| 409 | + ); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * Given a QST_system value, gets the question's largest allowable max input. |
|
| 414 | + * @see Registration_Form_Admin_Page::system_question_maxes() |
|
| 415 | + * @param string $system_question_value |
|
| 416 | + * @return int|float |
|
| 417 | + */ |
|
| 418 | + public function absolute_max_for_system_question($system_question_value) |
|
| 419 | + { |
|
| 420 | + $maxes = $this->system_question_maxes(); |
|
| 421 | + if (isset($maxes[ $system_question_value ])) { |
|
| 422 | + return $maxes[ $system_question_value ]; |
|
| 423 | + } else { |
|
| 424 | + return EE_INF; |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * @return array |
|
| 431 | + */ |
|
| 432 | + public function question_descriptions() |
|
| 433 | + { |
|
| 434 | + return $this->_question_descriptions; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Returns all the question types that should have an admin-defined max input length |
|
| 440 | + * @return array |
|
| 441 | + */ |
|
| 442 | + public function questionTypesWithMaxLength() |
|
| 443 | + { |
|
| 444 | + return (array) $this->question_types_with_max_lengh; |
|
| 445 | + } |
|
| 446 | 446 | } |
@@ -35,19 +35,19 @@ |
||
| 35 | 35 | $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
| 36 | 36 | $model_relation_chain, |
| 37 | 37 | $this->get_this_model()->get_this_model_name() |
| 38 | - ) . $this_table_fk_field->get_table_alias(); |
|
| 39 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
| 38 | + ).$this_table_fk_field->get_table_alias(); |
|
| 39 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
| 40 | 40 | $model_relation_chain, |
| 41 | 41 | $this->get_other_model()->get_this_model_name() |
| 42 | - ) . $other_table_pk_field->get_table_alias(); |
|
| 43 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
| 42 | + ).$other_table_pk_field->get_table_alias(); |
|
| 43 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
| 44 | 44 | return $this->_left_join( |
| 45 | 45 | $other_table, |
| 46 | 46 | $other_table_alias, |
| 47 | 47 | $other_table_pk_field->get_table_column(), |
| 48 | 48 | $this_table_alias, |
| 49 | 49 | $this_table_fk_field->get_table_column(), |
| 50 | - $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
| 50 | + $field_with_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'" |
|
| 51 | 51 | ) |
| 52 | 52 | . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
| 53 | 53 | } |
@@ -14,94 +14,94 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class EE_Belongs_To_Any_Relation extends EE_Belongs_To_Relation |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * get_join_statement |
|
| 19 | - * |
|
| 20 | - * @param string $model_relation_chain |
|
| 21 | - * @return string |
|
| 22 | - * @throws \EE_Error |
|
| 23 | - */ |
|
| 24 | - public function get_join_statement($model_relation_chain) |
|
| 25 | - { |
|
| 26 | - // create the sql string like |
|
| 27 | - $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
| 28 | - // ALSO, need to get the field with the model name |
|
| 29 | - $field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name(); |
|
| 17 | + /** |
|
| 18 | + * get_join_statement |
|
| 19 | + * |
|
| 20 | + * @param string $model_relation_chain |
|
| 21 | + * @return string |
|
| 22 | + * @throws \EE_Error |
|
| 23 | + */ |
|
| 24 | + public function get_join_statement($model_relation_chain) |
|
| 25 | + { |
|
| 26 | + // create the sql string like |
|
| 27 | + $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
| 28 | + // ALSO, need to get the field with the model name |
|
| 29 | + $field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name(); |
|
| 30 | 30 | |
| 31 | 31 | |
| 32 | - $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
| 33 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
| 34 | - $model_relation_chain, |
|
| 35 | - $this->get_this_model()->get_this_model_name() |
|
| 36 | - ) . $this_table_fk_field->get_table_alias(); |
|
| 37 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
| 38 | - $model_relation_chain, |
|
| 39 | - $this->get_other_model()->get_this_model_name() |
|
| 40 | - ) . $other_table_pk_field->get_table_alias(); |
|
| 41 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
| 42 | - return $this->_left_join( |
|
| 43 | - $other_table, |
|
| 44 | - $other_table_alias, |
|
| 45 | - $other_table_pk_field->get_table_column(), |
|
| 46 | - $this_table_alias, |
|
| 47 | - $this_table_fk_field->get_table_column(), |
|
| 48 | - $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
| 49 | - ) |
|
| 50 | - . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
| 51 | - } |
|
| 32 | + $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
| 33 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
| 34 | + $model_relation_chain, |
|
| 35 | + $this->get_this_model()->get_this_model_name() |
|
| 36 | + ) . $this_table_fk_field->get_table_alias(); |
|
| 37 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
| 38 | + $model_relation_chain, |
|
| 39 | + $this->get_other_model()->get_this_model_name() |
|
| 40 | + ) . $other_table_pk_field->get_table_alias(); |
|
| 41 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
| 42 | + return $this->_left_join( |
|
| 43 | + $other_table, |
|
| 44 | + $other_table_alias, |
|
| 45 | + $other_table_pk_field->get_table_column(), |
|
| 46 | + $this_table_alias, |
|
| 47 | + $this_table_fk_field->get_table_column(), |
|
| 48 | + $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'" |
|
| 49 | + ) |
|
| 50 | + . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if |
|
| 56 | - * you like. |
|
| 57 | - * |
|
| 58 | - * @param EE_Base_Class|int $this_obj_or_id |
|
| 59 | - * @param EE_Base_Class|int $other_obj_or_id |
|
| 60 | - * @param array $extra_join_model_fields_n_values |
|
| 61 | - * @return \EE_Base_Class |
|
| 62 | - * @throws \EE_Error |
|
| 63 | - */ |
|
| 64 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
| 65 | - { |
|
| 66 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
| 67 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
| 68 | - // find the field on THIS model which a foreign key to the other model |
|
| 69 | - $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
| 70 | - // set that field on the other model to this model's ID |
|
| 71 | - $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID()); |
|
| 72 | - // and make sure this model's field with the foreign model name is set to the correct value |
|
| 73 | - $this_model_obj->set( |
|
| 74 | - $this->get_this_model()->get_field_containing_related_model_name()->get_name(), |
|
| 75 | - $this->get_other_model()->get_this_model_name() |
|
| 76 | - ); |
|
| 77 | - $this_model_obj->save(); |
|
| 78 | - return $other_model_obj; |
|
| 79 | - } |
|
| 54 | + /** |
|
| 55 | + * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if |
|
| 56 | + * you like. |
|
| 57 | + * |
|
| 58 | + * @param EE_Base_Class|int $this_obj_or_id |
|
| 59 | + * @param EE_Base_Class|int $other_obj_or_id |
|
| 60 | + * @param array $extra_join_model_fields_n_values |
|
| 61 | + * @return \EE_Base_Class |
|
| 62 | + * @throws \EE_Error |
|
| 63 | + */ |
|
| 64 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
| 65 | + { |
|
| 66 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
| 67 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
| 68 | + // find the field on THIS model which a foreign key to the other model |
|
| 69 | + $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
| 70 | + // set that field on the other model to this model's ID |
|
| 71 | + $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID()); |
|
| 72 | + // and make sure this model's field with the foreign model name is set to the correct value |
|
| 73 | + $this_model_obj->set( |
|
| 74 | + $this->get_this_model()->get_field_containing_related_model_name()->get_name(), |
|
| 75 | + $this->get_other_model()->get_this_model_name() |
|
| 76 | + ); |
|
| 77 | + $this_model_obj->save(); |
|
| 78 | + return $other_model_obj; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Sets the this model object's foreign key to its default, instead of pointing to the other model object |
|
| 84 | - * |
|
| 85 | - * @param EE_Base_Class|int $this_obj_or_id |
|
| 86 | - * @param EE_Base_Class|int $other_obj_or_id |
|
| 87 | - * @param array $where_query |
|
| 88 | - * @return \EE_Base_Class |
|
| 89 | - * @throws \EE_Error |
|
| 90 | - */ |
|
| 91 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
| 92 | - { |
|
| 93 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
| 94 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
| 95 | - // find the field on the other model which is a foreign key to this model |
|
| 96 | - $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
| 97 | - // set that field on the other model to this model's ID |
|
| 98 | - $this_model_obj->set($fk_on_this_model->get_name(), null, true); |
|
| 99 | - $this_model_obj->set( |
|
| 100 | - $this->get_this_model()->get_field_containing_related_model_name()->get_name(), |
|
| 101 | - null, |
|
| 102 | - true |
|
| 103 | - ); |
|
| 104 | - $this_model_obj->save(); |
|
| 105 | - return $other_model_obj; |
|
| 106 | - } |
|
| 82 | + /** |
|
| 83 | + * Sets the this model object's foreign key to its default, instead of pointing to the other model object |
|
| 84 | + * |
|
| 85 | + * @param EE_Base_Class|int $this_obj_or_id |
|
| 86 | + * @param EE_Base_Class|int $other_obj_or_id |
|
| 87 | + * @param array $where_query |
|
| 88 | + * @return \EE_Base_Class |
|
| 89 | + * @throws \EE_Error |
|
| 90 | + */ |
|
| 91 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
| 92 | + { |
|
| 93 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
| 94 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id); |
|
| 95 | + // find the field on the other model which is a foreign key to this model |
|
| 96 | + $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
| 97 | + // set that field on the other model to this model's ID |
|
| 98 | + $this_model_obj->set($fk_on_this_model->get_name(), null, true); |
|
| 99 | + $this_model_obj->set( |
|
| 100 | + $this->get_this_model()->get_field_containing_related_model_name()->get_name(), |
|
| 101 | + null, |
|
| 102 | + true |
|
| 103 | + ); |
|
| 104 | + $this_model_obj->save(); |
|
| 105 | + return $other_model_obj; |
|
| 106 | + } |
|
| 107 | 107 | } |