Completed
Branch fix-dummy-related-question-qst... (e5efcf)
by
unknown
07:49 queued 03:45
created
strategies/EE_Restriction_Generator_Taxonomy_Protected.strategy.php 2 patches
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.
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -12,40 +12,40 @@
 block discarded – undo
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
 }
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/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
@@ -11,39 +11,39 @@
 block discarded – undo
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
 }
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
@@ -16,38 +16,38 @@
 block discarded – undo
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
 }
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
@@ -10,437 +10,437 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Belongs_To_Any_Relation.php 2 patches
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.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -14,94 +14,94 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Relation.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
         $pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47 47
             $model_relation_chain,
48 48
             $this->get_this_model()->get_this_model_name()
49
-        ) . $this_table_pk_field->get_table_alias();
50
-        $fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
49
+        ).$this_table_pk_field->get_table_alias();
50
+        $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
51 51
             $model_relation_chain,
52 52
             $this->get_other_model()->get_this_model_name()
53
-        ) . $other_table_fk_field->get_table_alias();
54
-        $fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
53
+        ).$other_table_fk_field->get_table_alias();
54
+        $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias);
55 55
 
56 56
         return $this->_left_join(
57 57
             $fk_table,
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             $other_table_fk_field->get_table_column(),
60 60
             $pk_table_alias,
61 61
             $this_table_pk_field->get_table_column()
62
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
62
+        ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
63 63
     }
64 64
 
65 65
 
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -10,102 +10,102 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Has_Many_Relation extends EE_Model_Relation_Base
12 12
 {
13
-    /**
14
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
15
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
16
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
17
-     * related models across the relation, and add-and-remove the relationships.
18
-     *
19
-     * @param boolean $block_deletes                 For this type of r elation, we block by default. If there are
20
-     *                                               related models across this relation, block (prevent and add an
21
-     *                                               error) the deletion of this model
22
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
23
-     *                                               default
24
-     */
25
-    public function __construct($block_deletes = true, $blocking_delete_error_message = null)
26
-    {
27
-        parent::__construct($block_deletes, $blocking_delete_error_message);
28
-    }
13
+	/**
14
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
15
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
16
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
17
+	 * related models across the relation, and add-and-remove the relationships.
18
+	 *
19
+	 * @param boolean $block_deletes                 For this type of r elation, we block by default. If there are
20
+	 *                                               related models across this relation, block (prevent and add an
21
+	 *                                               error) the deletion of this model
22
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
23
+	 *                                               default
24
+	 */
25
+	public function __construct($block_deletes = true, $blocking_delete_error_message = null)
26
+	{
27
+		parent::__construct($block_deletes, $blocking_delete_error_message);
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * Gets the SQL string for performing the join between this model and the other model.
33
-     *
34
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
35
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
36
-     *                other_model_primary_table.fk" etc
37
-     * @throws \EE_Error
38
-     */
39
-    public function get_join_statement($model_relation_chain)
40
-    {
41
-        // create the sql string like
42
-        // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
43
-        $this_table_pk_field  = $this->get_this_model()->get_primary_key_field();
44
-        $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
45
-        $pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
46
-            $model_relation_chain,
47
-            $this->get_this_model()->get_this_model_name()
48
-        ) . $this_table_pk_field->get_table_alias();
49
-        $fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
50
-            $model_relation_chain,
51
-            $this->get_other_model()->get_this_model_name()
52
-        ) . $other_table_fk_field->get_table_alias();
53
-        $fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
31
+	/**
32
+	 * Gets the SQL string for performing the join between this model and the other model.
33
+	 *
34
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
35
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
36
+	 *                other_model_primary_table.fk" etc
37
+	 * @throws \EE_Error
38
+	 */
39
+	public function get_join_statement($model_relation_chain)
40
+	{
41
+		// create the sql string like
42
+		// LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
43
+		$this_table_pk_field  = $this->get_this_model()->get_primary_key_field();
44
+		$other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
45
+		$pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
46
+			$model_relation_chain,
47
+			$this->get_this_model()->get_this_model_name()
48
+		) . $this_table_pk_field->get_table_alias();
49
+		$fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
50
+			$model_relation_chain,
51
+			$this->get_other_model()->get_this_model_name()
52
+		) . $other_table_fk_field->get_table_alias();
53
+		$fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
54 54
 
55
-        return $this->_left_join(
56
-            $fk_table,
57
-            $fk_table_alias,
58
-            $other_table_fk_field->get_table_column(),
59
-            $pk_table_alias,
60
-            $this_table_pk_field->get_table_column()
61
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
62
-    }
55
+		return $this->_left_join(
56
+			$fk_table,
57
+			$fk_table_alias,
58
+			$other_table_fk_field->get_table_column(),
59
+			$pk_table_alias,
60
+			$this_table_pk_field->get_table_column()
61
+		) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
62
+	}
63 63
 
64 64
 
65
-    /**
66
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
67
-     * you like.
68
-     *
69
-     * @param EE_Base_Class|int $this_obj_or_id
70
-     * @param EE_Base_Class|int $other_obj_or_id
71
-     * @param array             $extra_join_model_fields_n_values
72
-     * @return \EE_Base_Class
73
-     * @throws \EE_Error
74
-     */
75
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
76
-    {
77
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
78
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
65
+	/**
66
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
67
+	 * you like.
68
+	 *
69
+	 * @param EE_Base_Class|int $this_obj_or_id
70
+	 * @param EE_Base_Class|int $other_obj_or_id
71
+	 * @param array             $extra_join_model_fields_n_values
72
+	 * @return \EE_Base_Class
73
+	 * @throws \EE_Error
74
+	 */
75
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
76
+	{
77
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
78
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
79 79
 
80
-        // find the field on the other model which is a foreign key to this model
81
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
82
-        if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
83
-            // set that field on the other model to this model's ID
84
-            $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
85
-            $other_model_obj->save();
86
-        }
87
-        return $other_model_obj;
88
-    }
80
+		// find the field on the other model which is a foreign key to this model
81
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
82
+		if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
83
+			// set that field on the other model to this model's ID
84
+			$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
85
+			$other_model_obj->save();
86
+		}
87
+		return $other_model_obj;
88
+	}
89 89
 
90 90
 
91
-    /**
92
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
93
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
94
-     *
95
-     * @param EE_Base_Class|int $this_obj_or_id
96
-     * @param EE_Base_Class|int $other_obj_or_id
97
-     * @param array             $where_query
98
-     * @return \EE_Base_Class
99
-     * @throws \EE_Error
100
-     */
101
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
102
-    {
103
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
104
-        // find the field on the other model which is a foreign key to this model
105
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
106
-        // set that field on the other model to this model's ID
107
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
108
-        $other_model_obj->save();
109
-        return $other_model_obj;
110
-    }
91
+	/**
92
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
93
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
94
+	 *
95
+	 * @param EE_Base_Class|int $this_obj_or_id
96
+	 * @param EE_Base_Class|int $other_obj_or_id
97
+	 * @param array             $where_query
98
+	 * @return \EE_Base_Class
99
+	 * @throws \EE_Error
100
+	 */
101
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
102
+	{
103
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
104
+		// find the field on the other model which is a foreign key to this model
105
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
106
+		// set that field on the other model to this model's ID
107
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
108
+		$other_model_obj->save();
109
+		return $other_model_obj;
110
+	}
111 111
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Belongs_To_Relation.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
         $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
46 46
             $model_relation_chain,
47 47
             $this->get_this_model()->get_this_model_name()
48
-        ) . $this_table_fk_field->get_table_alias();
49
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
48
+        ).$this_table_fk_field->get_table_alias();
49
+        $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
50 50
             $model_relation_chain,
51 51
             $this->get_other_model()->get_this_model_name()
52
-        ) . $other_table_pk_field->get_table_alias();
53
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
52
+        ).$other_table_pk_field->get_table_alias();
53
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
54 54
         return $this->_left_join(
55 55
             $other_table,
56 56
             $other_table_alias,
57 57
             $other_table_pk_field->get_table_column(),
58 58
             $this_table_alias,
59 59
             $this_table_fk_field->get_table_column()
60
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
60
+        ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
61 61
     }
62 62
 
63 63
 
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
         }
140 140
         $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
141 141
         // get all where their PK matches that value
142
-        $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
143
-        $query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
142
+        $query_params[0][$this->get_other_model()->get_primary_key_field()->get_name()] = $ID_value_on_other_model;
143
+        $query_params = $this->_disable_default_where_conditions_on_query_param($query_params);
144 144
 //      echo '$query_params';
145 145
 //      var_dump($query_params);
146 146
         return $this->get_other_model()->get_all($query_params);
Please login to merge, or discard this patch.
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -11,137 +11,137 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Belongs_To_Relation extends EE_Model_Relation_Base
13 13
 {
14
-    /**
15
-     * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
16
-     * to the other model. This knows how to join the models,
17
-     * get related models across the relation, and add-and-remove the relationships.
18
-     *
19
-     * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
20
-     *                                                              default. if there are related models across this
21
-     *                                                              relation, block (prevent and add an error) the
22
-     *                                                              deletion of this model
23
-     * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
24
-     *                                                              instead of the default
25
-     */
26
-    public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
27
-    {
28
-        parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
29
-    }
14
+	/**
15
+	 * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
16
+	 * to the other model. This knows how to join the models,
17
+	 * get related models across the relation, and add-and-remove the relationships.
18
+	 *
19
+	 * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
20
+	 *                                                              default. if there are related models across this
21
+	 *                                                              relation, block (prevent and add an error) the
22
+	 *                                                              deletion of this model
23
+	 * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
24
+	 *                                                              instead of the default
25
+	 */
26
+	public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
27
+	{
28
+		parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * get_join_statement
34
-     *
35
-     * @param string $model_relation_chain
36
-     * @return string
37
-     * @throws \EE_Error
38
-     */
39
-    public function get_join_statement($model_relation_chain)
40
-    {
41
-        // create the sql string like
42
-        $this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
43
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
44
-        $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
45
-            $model_relation_chain,
46
-            $this->get_this_model()->get_this_model_name()
47
-        ) . $this_table_fk_field->get_table_alias();
48
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
49
-            $model_relation_chain,
50
-            $this->get_other_model()->get_this_model_name()
51
-        ) . $other_table_pk_field->get_table_alias();
52
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
53
-        return $this->_left_join(
54
-            $other_table,
55
-            $other_table_alias,
56
-            $other_table_pk_field->get_table_column(),
57
-            $this_table_alias,
58
-            $this_table_fk_field->get_table_column()
59
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
60
-    }
32
+	/**
33
+	 * get_join_statement
34
+	 *
35
+	 * @param string $model_relation_chain
36
+	 * @return string
37
+	 * @throws \EE_Error
38
+	 */
39
+	public function get_join_statement($model_relation_chain)
40
+	{
41
+		// create the sql string like
42
+		$this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
43
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
44
+		$this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
45
+			$model_relation_chain,
46
+			$this->get_this_model()->get_this_model_name()
47
+		) . $this_table_fk_field->get_table_alias();
48
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
49
+			$model_relation_chain,
50
+			$this->get_other_model()->get_this_model_name()
51
+		) . $other_table_pk_field->get_table_alias();
52
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
53
+		return $this->_left_join(
54
+			$other_table,
55
+			$other_table_alias,
56
+			$other_table_pk_field->get_table_column(),
57
+			$this_table_alias,
58
+			$this_table_fk_field->get_table_column()
59
+		) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
65
-     * you like.
66
-     *
67
-     * @param EE_Base_Class|int $this_obj_or_id
68
-     * @param EE_Base_Class|int $other_obj_or_id
69
-     * @param array             $extra_join_model_fields_n_values
70
-     * @return \EE_Base_Class
71
-     * @throws \EE_Error
72
-     */
73
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
74
-    {
75
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
76
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
77
-        // find the field on the other model which is a foreign key to this model
78
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
79
-        if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
80
-            // set that field on the other model to this model's ID
81
-            $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
82
-            $this_model_obj->save();
83
-        }
84
-        return $other_model_obj;
85
-    }
63
+	/**
64
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
65
+	 * you like.
66
+	 *
67
+	 * @param EE_Base_Class|int $this_obj_or_id
68
+	 * @param EE_Base_Class|int $other_obj_or_id
69
+	 * @param array             $extra_join_model_fields_n_values
70
+	 * @return \EE_Base_Class
71
+	 * @throws \EE_Error
72
+	 */
73
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
74
+	{
75
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
76
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
77
+		// find the field on the other model which is a foreign key to this model
78
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
79
+		if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
80
+			// set that field on the other model to this model's ID
81
+			$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
82
+			$this_model_obj->save();
83
+		}
84
+		return $other_model_obj;
85
+	}
86 86
 
87 87
 
88
-    /**
89
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
90
-     *
91
-     * @param EE_Base_Class|int $this_obj_or_id
92
-     * @param EE_Base_Class|int $other_obj_or_id
93
-     * @param array             $where_query
94
-     * @return \EE_Base_Class
95
-     * @throws \EE_Error
96
-     */
97
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
98
-    {
99
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
100
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
101
-        // find the field on the other model which is a foreign key to this model
102
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
103
-        // set that field on the other model to this model's ID
104
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
105
-        $this_model_obj->save();
106
-        return $other_model_obj;
107
-    }
88
+	/**
89
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
90
+	 *
91
+	 * @param EE_Base_Class|int $this_obj_or_id
92
+	 * @param EE_Base_Class|int $other_obj_or_id
93
+	 * @param array             $where_query
94
+	 * @return \EE_Base_Class
95
+	 * @throws \EE_Error
96
+	 */
97
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
98
+	{
99
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
100
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
101
+		// find the field on the other model which is a foreign key to this model
102
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
103
+		// set that field on the other model to this model's ID
104
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
105
+		$this_model_obj->save();
106
+		return $other_model_obj;
107
+	}
108 108
 
109 109
 
110
-    /**
111
-     * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
112
-     *
113
-     * @param EE_Base_Class $model_obj_or_id
114
-     * @param array         $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
115
-     * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
116
-     * @return EE_Base_Class[]
117
-     * @throws \EE_Error
118
-     */
119
-    public function get_all_related(
120
-        $model_obj_or_id,
121
-        $query_params = array(),
122
-        $values_already_prepared_by_model_object = false
123
-    ) {
124
-        if ($values_already_prepared_by_model_object !== false) {
125
-            EE_Error::doing_it_wrong(
126
-                'EE_Model_Relation_Base::get_all_related',
127
-                esc_html__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
128
-                '4.8.1'
129
-            );
130
-        }
131
-        // get column on this model object which is a foreign key to the other model
132
-        $fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
133
-        // get its value
134
-        if ($model_obj_or_id instanceof EE_Base_Class) {
135
-            $model_obj = $model_obj_or_id;
136
-        } else {
137
-            $model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
138
-        }
139
-        $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
140
-        // get all where their PK matches that value
141
-        $query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
142
-        $query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
110
+	/**
111
+	 * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
112
+	 *
113
+	 * @param EE_Base_Class $model_obj_or_id
114
+	 * @param array         $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
115
+	 * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
116
+	 * @return EE_Base_Class[]
117
+	 * @throws \EE_Error
118
+	 */
119
+	public function get_all_related(
120
+		$model_obj_or_id,
121
+		$query_params = array(),
122
+		$values_already_prepared_by_model_object = false
123
+	) {
124
+		if ($values_already_prepared_by_model_object !== false) {
125
+			EE_Error::doing_it_wrong(
126
+				'EE_Model_Relation_Base::get_all_related',
127
+				esc_html__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
128
+				'4.8.1'
129
+			);
130
+		}
131
+		// get column on this model object which is a foreign key to the other model
132
+		$fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
133
+		// get its value
134
+		if ($model_obj_or_id instanceof EE_Base_Class) {
135
+			$model_obj = $model_obj_or_id;
136
+		} else {
137
+			$model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
138
+		}
139
+		$ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
140
+		// get all where their PK matches that value
141
+		$query_params[0][ $this->get_other_model()->get_primary_key_field()->get_name() ] = $ID_value_on_other_model;
142
+		$query_params                                                                   = $this->_disable_default_where_conditions_on_query_param($query_params);
143 143
 //      echo '$query_params';
144 144
 //      var_dump($query_params);
145
-        return $this->get_other_model()->get_all($query_params);
146
-    }
145
+		return $this->get_other_model()->get_all($query_params);
146
+	}
147 147
 }
Please login to merge, or discard this patch.