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