Completed
Branch 973/fix-visible-recaptcha (0580c7)
by
unknown
03:03 queued 30s
created
core/db_models/EEM_Question_Option.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,10 +39,10 @@
 block discarded – undo
39 39
 
40 40
         $this->_model_chain_to_wp_user = 'Question';
41 41
         // this model is generally available for reading
42
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
43
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
42
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
43
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QSO_system');
44
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QSO_system');
45
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QSO_system');
46 46
         $this->_caps_slug = 'questions';
47 47
         parent::__construct($timezone);
48 48
     }
Please login to merge, or discard this patch.
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -12,39 +12,39 @@
 block discarded – undo
12 12
 class EEM_Question_Option extends EEM_Soft_Delete_Base
13 13
 {
14 14
 
15
-    // private instance of the Attendee object
16
-    protected static $_instance = null;
15
+	// private instance of the Attendee object
16
+	protected static $_instance = null;
17 17
 
18
-    protected function __construct($timezone = null)
19
-    {
20
-        $this->singular_item = esc_html__('Question Option', 'event_espresso');
21
-        $this->plural_item = esc_html__('Question Options', 'event_espresso');
18
+	protected function __construct($timezone = null)
19
+	{
20
+		$this->singular_item = esc_html__('Question Option', 'event_espresso');
21
+		$this->plural_item = esc_html__('Question Options', 'event_espresso');
22 22
 
23
-        $this->_tables = array(
24
-            'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID')
25
-        );
26
-        $this->_fields = array(
27
-            'Question_Option' => array(
28
-                    'QSO_ID' => new EE_Primary_Key_Int_Field('QSO_ID', esc_html__('Question Option ID', 'event_espresso')),
29
-                    'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso'), false, 0, 'Question'),
30
-                    'QSO_value' => new EE_Plain_Text_Field('QSO_value', esc_html__("Question Option Value", "event_espresso"), false, ''),
31
-                    'QSO_desc' => new EE_Post_Content_Field('QSO_desc', esc_html__('Question Option Description', 'event_espresso'), false, ''),
32
-                    'QSO_order' => new EE_Integer_Field('QSO_order', esc_html__('Question Option Order', 'event_espresso'), false, 0),
33
-                    'QSO_system' => new EE_Plain_Text_Field('QSO_system', esc_html__('Internal string ID for question option', 'event_espresso'), true, null),
34
-                    'QSO_deleted' => new EE_Trashed_Flag_Field('QSO_deleted', esc_html__('Flag indicating Option was trashed', 'event_espresso'), false, false)
35
-                )
36
-        );
37
-        $this->_model_relations = array(
38
-            'Question' => new EE_Belongs_To_Relation()
39
-        );
23
+		$this->_tables = array(
24
+			'Question_Option' => new EE_Primary_Table('esp_question_option', 'QSO_ID')
25
+		);
26
+		$this->_fields = array(
27
+			'Question_Option' => array(
28
+					'QSO_ID' => new EE_Primary_Key_Int_Field('QSO_ID', esc_html__('Question Option ID', 'event_espresso')),
29
+					'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso'), false, 0, 'Question'),
30
+					'QSO_value' => new EE_Plain_Text_Field('QSO_value', esc_html__("Question Option Value", "event_espresso"), false, ''),
31
+					'QSO_desc' => new EE_Post_Content_Field('QSO_desc', esc_html__('Question Option Description', 'event_espresso'), false, ''),
32
+					'QSO_order' => new EE_Integer_Field('QSO_order', esc_html__('Question Option Order', 'event_espresso'), false, 0),
33
+					'QSO_system' => new EE_Plain_Text_Field('QSO_system', esc_html__('Internal string ID for question option', 'event_espresso'), true, null),
34
+					'QSO_deleted' => new EE_Trashed_Flag_Field('QSO_deleted', esc_html__('Flag indicating Option was trashed', 'event_espresso'), false, false)
35
+				)
36
+		);
37
+		$this->_model_relations = array(
38
+			'Question' => new EE_Belongs_To_Relation()
39
+		);
40 40
 
41
-        $this->_model_chain_to_wp_user = 'Question';
42
-        // this model is generally available for reading
43
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
47
-        $this->_caps_slug = 'questions';
48
-        parent::__construct($timezone);
49
-    }
41
+		$this->_model_chain_to_wp_user = 'Question';
42
+		// this model is generally available for reading
43
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
44
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
45
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSO_system');
47
+		$this->_caps_slug = 'questions';
48
+		parent::__construct($timezone);
49
+	}
50 50
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message_Template.model.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
             );
50 50
         $this->_model_chain_to_wp_user = 'Message_Template_Group';
51 51
         foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
52
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
52
+            $this->_cap_restriction_generators[$context] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
53 53
         }
54 54
         $this->_caps_slug = 'messages';
55 55
         parent::__construct($timezone);
Please login to merge, or discard this patch.
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -14,45 +14,45 @@
 block discarded – undo
14 14
  */
15 15
 class EEM_Message_Template extends EEM_Base
16 16
 {
17
-    // private instance of the EEM_Message_Template object
18
-    protected static $_instance = null;
17
+	// private instance of the EEM_Message_Template object
18
+	protected static $_instance = null;
19 19
 
20 20
 
21 21
 
22
-    /**
23
-     * private constructor to prevent direct creation
24
-     *
25
-     * @Constructor
26
-     * @access protected
27
-     * @param string $timezone
28
-     * @throws \EE_Error
29
-     */
30
-    protected function __construct($timezone = null)
31
-    {
32
-        $this->singular_item = esc_html__('Message Template', 'event_espresso');
33
-        $this->plural_item = esc_html__('Message Templates', 'event_espresso');
22
+	/**
23
+	 * private constructor to prevent direct creation
24
+	 *
25
+	 * @Constructor
26
+	 * @access protected
27
+	 * @param string $timezone
28
+	 * @throws \EE_Error
29
+	 */
30
+	protected function __construct($timezone = null)
31
+	{
32
+		$this->singular_item = esc_html__('Message Template', 'event_espresso');
33
+		$this->plural_item = esc_html__('Message Templates', 'event_espresso');
34 34
 
35
-        $this->_tables = array(
36
-            'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID')
37
-        );
38
-        $this->_fields = array(
39
-            'Message_Template' => array(
40
-                'MTP_ID' => new EE_Primary_Key_Int_Field('MTP_ID', esc_html__('Message Template ID', 'event_espresso')),
41
-                'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso'), false, 0, 'Message_Template_Group'),
42
-                'MTP_template_field' => new EE_Plain_Text_Field('MTP_template_field', esc_html__('Field Name for this Template', 'event_espresso'), false, 'default'),
43
-                'MTP_context' => new EE_Plain_Text_Field('MTP_context', esc_html__('Message Type Context for this field', 'event_espresso'), false, 'admin'),
44
-                'MTP_content' => new EE_Serialized_Text_Field('MTP_content', esc_html__('The field content for the template', 'event_espresso'), false, ''),
45
-            )
46
-        );
35
+		$this->_tables = array(
36
+			'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID')
37
+		);
38
+		$this->_fields = array(
39
+			'Message_Template' => array(
40
+				'MTP_ID' => new EE_Primary_Key_Int_Field('MTP_ID', esc_html__('Message Template ID', 'event_espresso')),
41
+				'GRP_ID' => new EE_Foreign_Key_Int_Field('GRP_ID', esc_html__('Message Template Group ID', 'event_espresso'), false, 0, 'Message_Template_Group'),
42
+				'MTP_template_field' => new EE_Plain_Text_Field('MTP_template_field', esc_html__('Field Name for this Template', 'event_espresso'), false, 'default'),
43
+				'MTP_context' => new EE_Plain_Text_Field('MTP_context', esc_html__('Message Type Context for this field', 'event_espresso'), false, 'admin'),
44
+				'MTP_content' => new EE_Serialized_Text_Field('MTP_content', esc_html__('The field content for the template', 'event_espresso'), false, ''),
45
+			)
46
+		);
47 47
 
48
-        $this->_model_relations = array(
49
-            'Message_Template_Group' => new EE_Belongs_To_Relation()
50
-            );
51
-        $this->_model_chain_to_wp_user = 'Message_Template_Group';
52
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
53
-            $this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
54
-        }
55
-        $this->_caps_slug = 'messages';
56
-        parent::__construct($timezone);
57
-    }
48
+		$this->_model_relations = array(
49
+			'Message_Template_Group' => new EE_Belongs_To_Relation()
50
+			);
51
+		$this->_model_chain_to_wp_user = 'Message_Template_Group';
52
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
53
+			$this->_cap_restriction_generators[ $context ] = new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
54
+		}
55
+		$this->_caps_slug = 'messages';
56
+		parent::__construct($timezone);
57
+	}
58 58
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Question_Group_Question.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -42,10 +42,10 @@
 block discarded – undo
42 42
 
43 43
         $this->_model_chain_to_wp_user = 'Question_Group';
44 44
         // this model is generally available for reading
45
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
45
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
46
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
47
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
48
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
49 49
         // use the caps for question groups
50 50
         $this->_caps_slug = 'question_groups';
51 51
         parent::__construct($timezone);
Please login to merge, or discard this patch.
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -17,38 +17,38 @@
 block discarded – undo
17 17
 class EEM_Question_Group_Question extends EEM_Base
18 18
 {
19 19
 
20
-    // private instance of the Attendee object
21
-    protected static $_instance = null;
20
+	// private instance of the Attendee object
21
+	protected static $_instance = null;
22 22
 
23 23
 
24
-    protected function __construct($timezone = null)
25
-    {
26
-        $this->singular_item = esc_html__('Question Group to Question Link', 'event_espresso');
27
-        $this->plural_item = esc_html__('Question Group to Question Links', 'event_espresso');
28
-        $this->_tables = array(
29
-            'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID')
30
-        );
31
-        $this->_fields = array(
32
-            'Question_Group_Question' => array(
33
-                'QGQ_ID' => new EE_Primary_Key_Int_Field('QGQ_ID', esc_html__('Question Group to Question Link ID', 'event_espresso')),
34
-                'QSG_ID' => new EE_Foreign_Key_Int_Field('QSG_ID', esc_html__('Question Group ID', 'event_espresso'), false, 0, 'Question_Group'),
35
-                'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question Id', 'event_espresso'), false, 0, 'Question'),
36
-                'QGQ_order' => new EE_Integer_Field('QGQ_order', esc_html__('Question Group Question Order', 'event_espresso'), false, 0)
37
-            )
38
-        );
39
-        $this->_model_relations = array(
40
-            'Question_Group' => new EE_Belongs_To_Relation(),
41
-            'Question' => new EE_Belongs_To_Relation()
42
-        );
24
+	protected function __construct($timezone = null)
25
+	{
26
+		$this->singular_item = esc_html__('Question Group to Question Link', 'event_espresso');
27
+		$this->plural_item = esc_html__('Question Group to Question Links', 'event_espresso');
28
+		$this->_tables = array(
29
+			'Question_Group_Question' => new EE_Primary_Table('esp_question_group_question', 'QGQ_ID')
30
+		);
31
+		$this->_fields = array(
32
+			'Question_Group_Question' => array(
33
+				'QGQ_ID' => new EE_Primary_Key_Int_Field('QGQ_ID', esc_html__('Question Group to Question Link ID', 'event_espresso')),
34
+				'QSG_ID' => new EE_Foreign_Key_Int_Field('QSG_ID', esc_html__('Question Group ID', 'event_espresso'), false, 0, 'Question_Group'),
35
+				'QST_ID' => new EE_Foreign_Key_Int_Field('QST_ID', esc_html__('Question Id', 'event_espresso'), false, 0, 'Question'),
36
+				'QGQ_order' => new EE_Integer_Field('QGQ_order', esc_html__('Question Group Question Order', 'event_espresso'), false, 0)
37
+			)
38
+		);
39
+		$this->_model_relations = array(
40
+			'Question_Group' => new EE_Belongs_To_Relation(),
41
+			'Question' => new EE_Belongs_To_Relation()
42
+		);
43 43
 
44
-        $this->_model_chain_to_wp_user = 'Question_Group';
45
-        // this model is generally available for reading
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
50
-        // use the caps for question groups
51
-        $this->_caps_slug = 'question_groups';
52
-        parent::__construct($timezone);
53
-    }
44
+		$this->_model_chain_to_wp_user = 'Question_Group';
45
+		// this model is generally available for reading
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
49
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('Question_Group.QSG_system');
50
+		// use the caps for question groups
51
+		$this->_caps_slug = 'question_groups';
52
+		parent::__construct($timezone);
53
+	}
54 54
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Question.model.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
             'Question_Group_Question' => new EE_Has_Many_Relation()
214 214
         );
215 215
         // this model is generally available for reading
216
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
217
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system');
218
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system');
219
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system');
216
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
217
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QST_system');
218
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QST_system');
219
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QST_system');
220 220
         parent::__construct($timezone);
221 221
     }
222 222
 
@@ -256,10 +256,10 @@  discard block
 block discarded – undo
256 256
      */
257 257
     public function question_type_is_in_category($question_type, $category)
258 258
     {
259
-        if (!isset($this->_question_type_categories[ $category ])) {
259
+        if ( ! isset($this->_question_type_categories[$category])) {
260 260
             return false;
261 261
         }
262
-        return in_array($question_type, $this->_question_type_categories[ $category ]);
262
+        return in_array($question_type, $this->_question_type_categories[$category]);
263 263
     }
264 264
 
265 265
 
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
      */
271 271
     public function question_types_in_category($category)
272 272
     {
273
-        if (isset($this->_question_type_categories[ $category ])) {
274
-            return $this->_question_type_categories[ $category ];
273
+        if (isset($this->_question_type_categories[$category])) {
274
+            return $this->_question_type_categories[$category];
275 275
         }
276 276
         return array();
277 277
     }
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
     public function absolute_max_for_system_question($system_question_value)
411 411
     {
412 412
         $maxes = $this->system_question_maxes();
413
-        if (isset($maxes[ $system_question_value ])) {
414
-            return $maxes[ $system_question_value ];
413
+        if (isset($maxes[$system_question_value])) {
414
+            return $maxes[$system_question_value];
415 415
         } else {
416 416
             return EE_INF;
417 417
         }
Please login to merge, or discard this patch.
Indentation   +432 added lines, -432 removed lines patch added patch discarded remove patch
@@ -11,437 +11,437 @@
 block discarded – undo
11 11
 class EEM_Question extends EEM_Soft_Delete_Base
12 12
 {
13 13
 
14
-    // constant used to indicate that the question type is COUNTRY
15
-    const QST_type_country = 'COUNTRY';
14
+	// constant used to indicate that the question type is COUNTRY
15
+	const QST_type_country = 'COUNTRY';
16 16
 
17
-    // constant used to indicate that the question type is DATE
18
-    const QST_type_date = 'DATE';
19
-
20
-    // constant used to indicate that the question type is DROPDOWN
21
-    const QST_type_dropdown = 'DROPDOWN';
22
-
23
-    // constant used to indicate that the question type is CHECKBOX
24
-    const QST_type_checkbox = 'CHECKBOX';
25
-
26
-    // constant used to indicate that the question type is RADIO_BTN
27
-    const QST_type_radio = 'RADIO_BTN';
28
-
29
-    // constant used to indicate that the question type is STATE
30
-    const QST_type_state = 'STATE';
31
-
32
-    // constant used to indicate that the question type is TEXT
33
-    const QST_type_text = 'TEXT';
34
-
35
-    // constant used to indicate that the question type is TEXTAREA
36
-    const QST_type_textarea = 'TEXTAREA';
37
-
38
-    // constant used to indicate that the question type is a TEXTAREA that allows simple html
39
-    const QST_type_html_textarea = 'HTML_TEXTAREA';
40
-
41
-    // constant used to indicate that the question type is an email input
42
-    const QST_type_email = 'EMAIL';
43
-
44
-    // constant used to indicate that the question type is an email input
45
-    const QST_type_email_confirm = 'EMAIL_CONFIRM';
46
-
47
-    // constant used to indicate that the question type is a US-formatted phone number
48
-    const QST_type_us_phone = 'US_PHONE';
49
-
50
-    // constant used to indicate that the question type is an integer (whole number)
51
-    const QST_type_int = 'INTEGER';
52
-
53
-    // constant used to indicate that the question type is a decimal (float)
54
-    const QST_type_decimal = 'DECIMAL';
55
-
56
-    // constant used to indicate that the question type is a valid URL
57
-    const QST_type_url = 'URL';
58
-
59
-    // constant used to indicate that the question type is a YEAR
60
-    const QST_type_year = 'YEAR';
61
-
62
-    // constant used to indicate that the question type is a multi-select
63
-    const QST_type_multi_select = 'MULTI_SELECT';
64
-
65
-    /**
66
-     * Question types that are interchangeable, even after answers have been provided for them.
67
-     * Top-level keys are category slugs, next level is an array of question types. If question types
68
-     * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
69
-     *
70
-     * @access protected
71
-     * @var array $_question_type_categories {
72
-     * @type string $text
73
-     * @type string $single -answer-enum
74
-     * @type string $multi -answer-enum
75
-     *                    }
76
-     */
77
-    protected $_question_type_categories = array();
78
-
79
-    /**
80
-     * lists all the question types which should be allowed. Ideally, this will be extensible.
81
-     *
82
-     * @access protected
83
-     * @var array $_allowed_question_types
84
-     */
85
-    protected $_allowed_question_types = array();
86
-
87
-    /**
88
-     * brief descriptions for all the question types
89
-     *
90
-     * @access protected
91
-     * @var EEM_Question $_instance
92
-     */
93
-    protected $_question_descriptions;
94
-
95
-
96
-    /**
97
-     * Question types that should have an admin-defined max input length
98
-     * @var array
99
-     */
100
-    protected $question_types_with_max_lengh;
101
-
102
-
103
-    // private instance of the Attendee object
104
-    protected static $_instance = null;
105
-
106
-
107
-    /**
108
-     * EEM_Question constructor.
109
-     *
110
-     * @param null $timezone
111
-     */
112
-    protected function __construct($timezone = null)
113
-    {
114
-        $this->singular_item = esc_html__('Question', 'event_espresso');
115
-        $this->plural_item = esc_html__('Questions', 'event_espresso');
116
-        $this->_allowed_question_types = apply_filters(
117
-            'FHEE__EEM_Question__construct__allowed_question_types',
118
-            array(
119
-                EEM_Question::QST_type_text => esc_html__('Text', 'event_espresso'),
120
-                EEM_Question::QST_type_textarea => esc_html__('Textarea', 'event_espresso'),
121
-                EEM_Question::QST_type_checkbox => esc_html__('Checkboxes', 'event_espresso'),
122
-                EEM_Question::QST_type_radio => esc_html__('Radio Buttons', 'event_espresso'),
123
-                EEM_Question::QST_type_dropdown => esc_html__('Dropdown', 'event_espresso'),
124
-                EEM_Question::QST_type_state => esc_html__('State/Province Dropdown', 'event_espresso'),
125
-                EEM_Question::QST_type_country => esc_html__('Country Dropdown', 'event_espresso'),
126
-                EEM_Question::QST_type_date => esc_html__('Date Picker', 'event_espresso'),
127
-                EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'),
128
-                EEM_Question::QST_type_email => esc_html__('Email', 'event_espresso'),
129
-                EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'),
130
-                EEM_Question::QST_type_us_phone => esc_html__('USA - Format Phone', 'event_espresso'),
131
-                EEM_Question::QST_type_decimal => esc_html__('Number', 'event_espresso'),
132
-                EEM_Question::QST_type_int => esc_html__('Whole Number', 'event_espresso'),
133
-                EEM_Question::QST_type_url => esc_html__('URL', 'event_espresso'),
134
-                EEM_Question::QST_type_year => esc_html__('Year', 'event_espresso'),
135
-                EEM_Question::QST_type_multi_select => esc_html__('Multi Select', 'event_espresso')
136
-            )
137
-        );
138
-        $this->_question_descriptions = apply_filters(
139
-            'FHEE__EEM_Question__construct__question_descriptions',
140
-            array(
141
-                EEM_Question::QST_type_text => esc_html__('A single line text input field', 'event_espresso'),
142
-                EEM_Question::QST_type_textarea => esc_html__('A multi line text input field', 'event_espresso'),
143
-                EEM_Question::QST_type_checkbox => esc_html__('Allows multiple preset options to be selected', 'event_espresso'),
144
-                EEM_Question::QST_type_radio => esc_html__('Allows a single preset option to be selected', 'event_espresso'),
145
-                EEM_Question::QST_type_dropdown => esc_html__('A dropdown that allows a single selection', 'event_espresso'),
146
-                EEM_Question::QST_type_state => esc_html__('A dropdown that lists states/provinces', 'event_espresso'),
147
-                EEM_Question::QST_type_country => esc_html__('A dropdown that lists countries', 'event_espresso'),
148
-                EEM_Question::QST_type_date => esc_html__('A popup calendar that allows date selections', 'event_espresso'),
149
-                EEM_Question::QST_type_html_textarea => esc_html__('A multi line text input field that allows HTML', 'event_espresso'),
150
-                EEM_Question::QST_type_email => esc_html__('A text field that must contain a valid Email address', 'event_espresso'),
151
-                EEM_Question::QST_type_email_confirm => esc_html__('A text field that must contain a valid Email address and be equal to Email field', 'event_espresso'),
152
-                EEM_Question::QST_type_us_phone => esc_html__('A text field that must contain a valid US phone number', 'event_espresso'),
153
-                EEM_Question::QST_type_decimal => esc_html__('A text field that allows number values with decimals', 'event_espresso'),
154
-                EEM_Question::QST_type_int => esc_html__('A text field that only allows whole numbers (no decimals)', 'event_espresso'),
155
-                EEM_Question::QST_type_url => esc_html__('A text field that must contain a valid URL', 'event_espresso'),
156
-                EEM_Question::QST_type_year => esc_html__('A dropdown that lists the last 100 years', 'event_espresso'),
157
-                EEM_Question::QST_type_multi_select => esc_html__('A dropdown that allows multiple selections', 'event_espresso')
158
-            )
159
-        );
160
-        $this->_question_type_categories = (array) apply_filters(
161
-            'FHEE__EEM_Question__construct__question_type_categories',
162
-            array(
163
-                'text' => array(
164
-                    EEM_Question::QST_type_text,
165
-                    EEM_Question::QST_type_textarea,
166
-                    EEM_Question::QST_type_date,
167
-                    EEM_Question::QST_type_html_textarea,
168
-                    EEM_Question::QST_type_email,
169
-                    EEM_Question::QST_type_email_confirm,
170
-                    EEM_Question::QST_type_us_phone,
171
-                    EEM_Question::QST_type_decimal,
172
-                    EEM_Question::QST_type_int,
173
-                    EEM_Question::QST_type_url,
174
-                    EEM_Question::QST_type_year
175
-                ),
176
-                'single-answer-enum' => array(
177
-                    EEM_Question::QST_type_radio,
178
-                    EEM_Question::QST_type_dropdown
179
-                ),
180
-                'multi-answer-enum' => array(
181
-                    EEM_Question::QST_type_checkbox,
182
-                    EEM_Question::QST_type_multi_select
183
-                )
184
-            )
185
-        );
186
-        $this->question_types_with_max_lengh = apply_filters(
187
-            'FHEE__EEM_Question___construct__question_types_with_max_length',
188
-            array(
189
-                EEM_Question::QST_type_text,
190
-                EEM_Question::QST_type_textarea,
191
-                EEM_Question::QST_type_html_textarea
192
-            )
193
-        );
194
-
195
-        $this->_tables = array(
196
-            'Question' => new EE_Primary_Table('esp_question', 'QST_ID')
197
-        );
198
-        $this->_fields = array(
199
-            'Question' => array(
200
-                'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso')),
201
-                'QST_display_text' => new EE_Post_Content_Field('QST_display_text', esc_html__('Question Text', 'event_espresso'), true, ''),
202
-                'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', esc_html__('Question Label (admin-only)', 'event_espresso'), true, ''),
203
-                'QST_system' => new EE_Plain_Text_Field('QST_system', esc_html__('Internal string ID for question', 'event_espresso'), false, ''),
204
-                'QST_type' => new EE_Enum_Text_Field('QST_type', esc_html__('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types),
205
-                'QST_required' => new EE_Boolean_Field('QST_required', esc_html__('Required Question?', 'event_espresso'), false, false),
206
-                'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', esc_html__('Text to Display if Not Provided', 'event_espresso'), true, ''),
207
-                'QST_order' => new EE_Integer_Field('QST_order', esc_html__('Question Order', 'event_espresso'), false, 0),
208
-                'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', esc_html__('Admin-Only Question?', 'event_espresso'), false, false),
209
-                'QST_max' => new EE_Infinite_Integer_Field('QST_max', esc_html__('Max Size', 'event_espresso'), false, EE_INF),
210
-                'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', esc_html__('Question Creator ID', 'event_espresso'), false),
211
-                'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', esc_html__('Flag Indicating question was deleted', 'event_espresso'), false, false)
212
-            )
213
-        );
214
-        $this->_model_relations = array(
215
-            'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'),
216
-            'Question_Option' => new EE_Has_Many_Relation(),
217
-            'Answer' => new EE_Has_Many_Relation(),
218
-            'WP_User' => new EE_Belongs_To_Relation(),
219
-            // for QST_order column
220
-            'Question_Group_Question' => new EE_Has_Many_Relation()
221
-        );
222
-        // this model is generally available for reading
223
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
224
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system');
225
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system');
226
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system');
227
-        parent::__construct($timezone);
228
-    }
229
-
230
-    /**
231
-     * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE'
232
-     * but they can be extended
233
-     * @return string[]
234
-     */
235
-    public function allowed_question_types()
236
-    {
237
-        return $this->_allowed_question_types;
238
-    }
239
-
240
-    /**
241
-     * Gets all the question types in the same category
242
-     * @param string $question_type one of EEM_Question::allowed_question_types(
243
-     * @return string[] like EEM_Question::allowed_question_types()
244
-     */
245
-    public function question_types_in_same_category($question_type)
246
-    {
247
-        $question_types = array($question_type);
248
-        foreach ($this->_question_type_categories as $category => $question_types_in_category) {
249
-            if (in_array($question_type, $question_types_in_category)) {
250
-                $question_types = $question_types_in_category;
251
-                break;
252
-            }
253
-        }
254
-
255
-        return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
256
-    }
257
-
258
-    /**
259
-     * Determines if the given question type is in the given question type category
260
-     * @param string $question_type one of EEM_Question::allowed_question_types()
261
-     * @param string $category one of the top-level keys of EEM_Question::question_type_categories()
262
-     * @return boolean
263
-     */
264
-    public function question_type_is_in_category($question_type, $category)
265
-    {
266
-        if (!isset($this->_question_type_categories[ $category ])) {
267
-            return false;
268
-        }
269
-        return in_array($question_type, $this->_question_type_categories[ $category ]);
270
-    }
271
-
272
-
273
-    /**
274
-     * Returns all the question types in the given category
275
-     * @param string $category
276
-     * @return array|mixed
277
-     */
278
-    public function question_types_in_category($category)
279
-    {
280
-        if (isset($this->_question_type_categories[ $category ])) {
281
-            return $this->_question_type_categories[ $category ];
282
-        }
283
-        return array();
284
-    }
285
-
286
-
287
-    /**
288
-     * Returns all the question types that should have question options
289
-     * @return array
290
-     */
291
-    public function question_types_with_options()
292
-    {
293
-        return array_merge(
294
-            $this->question_types_in_category('single-answer-enum'),
295
-            $this->question_types_in_category('multi-answer-enum')
296
-        );
297
-    }
298
-
299
-    /**
300
-     * Returns the question type categories 2d array
301
-     * @return array see EEM_Question::_question_type_categories
302
-     */
303
-    public function question_type_categories()
304
-    {
305
-        return $this->_question_type_categories;
306
-    }
307
-
308
-    /**
309
-     * Returns an array of all the QST_system values that can be allowed in the system question group
310
-     * identified by $system_question_group_id
311
-     * @param string $system_question_group_id QSG_system
312
-     * @return array of system question names (QST_system)
313
-     */
314
-    public function allowed_system_questions_in_system_question_group($system_question_group_id)
315
-    {
316
-        $question_system_ids = array();
317
-        switch ($system_question_group_id) {
318
-            case EEM_Question_Group::system_personal:
319
-                $question_system_ids = array(
320
-                    EEM_Attendee::system_question_fname,
321
-                    EEM_Attendee::system_question_lname,
322
-                    EEM_Attendee::system_question_email,
323
-                    EEM_Attendee::system_question_email_confirm,
324
-                    EEM_Attendee::system_question_phone
325
-                );
326
-                break;
327
-            case EEM_Question_Group::system_address:
328
-                $question_system_ids = array(
329
-                    EEM_Attendee::system_question_address,
330
-                    EEM_Attendee::system_question_address2,
331
-                    EEM_Attendee::system_question_city,
332
-                    EEM_Attendee::system_question_state,
333
-                    EEM_Attendee::system_question_country,
334
-                    EEM_Attendee::system_question_zip,
335
-                    EEM_Attendee::system_question_phone
336
-                );
337
-                break;
338
-        }
339
-        return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id);
340
-    }
341
-
342
-    /**
343
-     * Returns an array of all the QST_system values that are required in the system question group
344
-     * identified by $system_question_group_id
345
-     * @param string $system_question_group_id QSG_system
346
-     * @return array of system question names (QST_system)
347
-     */
348
-    public function required_system_questions_in_system_question_group($system_question_group_id)
349
-    {
350
-        $question_system_ids = null;
351
-        switch ($system_question_group_id) {
352
-            case EEM_Question_Group::system_personal:
353
-                $question_system_ids = array(
354
-                    EEM_Attendee::system_question_fname,
355
-                    EEM_Attendee::system_question_email,
356
-                );
357
-                break;
358
-            default:
359
-                $question_system_ids = array();
360
-        }
361
-        return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id);
362
-    }
363
-
364
-
365
-    /**
366
-     * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
367
-     * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city');
368
-     * @param $QST_system
369
-     * @return int of QST_ID for the question that corresponds to that QST_system
370
-     */
371
-    public function get_Question_ID_from_system_string($QST_system)
372
-    {
373
-        return $this->get_var(array(array('QST_system' => $QST_system)));
374
-    }
375
-
376
-
377
-    /**
378
-     * searches the db for the question with the latest question order and returns that value.
379
-     * @access public
380
-     * @return int
381
-     */
382
-    public function get_latest_question_order()
383
-    {
384
-        $columns_to_select = array(
385
-            'max_order' => array("MAX(QST_order)", "%d")
386
-        );
387
-        $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select);
388
-        return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
389
-    }
390
-
391
-    /**
392
-     * Returns an array where keys are system question QST_system values,
393
-     * and values are the highest question max the admin can set on the question
394
-     * (aka the "max max"; eg, a site admin can change the zip question to have a max
395
-     * of 5, but no larger than 12)
396
-     * @return array
397
-     */
398
-    public function system_question_maxes()
399
-    {
400
-        return array(
401
-            'fname' => 45,
402
-            'lname' => 45,
403
-            'address' => 255,
404
-            'address2' => 255,
405
-            'city' => 45,
406
-            'zip' => 12,
407
-            'email' => 255,
408
-            'email_confirm' => 255,
409
-            'phone' => 45,
410
-        );
411
-    }
412
-
413
-    /**
414
-     * Given a QST_system value, gets the question's largest allowable max input.
415
-     * @see Registration_Form_Admin_Page::system_question_maxes()
416
-     * @param string $system_question_value
417
-     * @return int|float
418
-     */
419
-    public function absolute_max_for_system_question($system_question_value)
420
-    {
421
-        $maxes = $this->system_question_maxes();
422
-        if (isset($maxes[ $system_question_value ])) {
423
-            return $maxes[ $system_question_value ];
424
-        } else {
425
-            return EE_INF;
426
-        }
427
-    }
428
-
429
-
430
-    /**
431
-     * @return array
432
-     */
433
-    public function question_descriptions()
434
-    {
435
-        return $this->_question_descriptions;
436
-    }
437
-
438
-
439
-    /**
440
-     * Returns all the question types that should have an admin-defined max input length
441
-     * @return array
442
-     */
443
-    public function questionTypesWithMaxLength()
444
-    {
445
-        return (array) $this->question_types_with_max_lengh;
446
-    }
17
+	// constant used to indicate that the question type is DATE
18
+	const QST_type_date = 'DATE';
19
+
20
+	// constant used to indicate that the question type is DROPDOWN
21
+	const QST_type_dropdown = 'DROPDOWN';
22
+
23
+	// constant used to indicate that the question type is CHECKBOX
24
+	const QST_type_checkbox = 'CHECKBOX';
25
+
26
+	// constant used to indicate that the question type is RADIO_BTN
27
+	const QST_type_radio = 'RADIO_BTN';
28
+
29
+	// constant used to indicate that the question type is STATE
30
+	const QST_type_state = 'STATE';
31
+
32
+	// constant used to indicate that the question type is TEXT
33
+	const QST_type_text = 'TEXT';
34
+
35
+	// constant used to indicate that the question type is TEXTAREA
36
+	const QST_type_textarea = 'TEXTAREA';
37
+
38
+	// constant used to indicate that the question type is a TEXTAREA that allows simple html
39
+	const QST_type_html_textarea = 'HTML_TEXTAREA';
40
+
41
+	// constant used to indicate that the question type is an email input
42
+	const QST_type_email = 'EMAIL';
43
+
44
+	// constant used to indicate that the question type is an email input
45
+	const QST_type_email_confirm = 'EMAIL_CONFIRM';
46
+
47
+	// constant used to indicate that the question type is a US-formatted phone number
48
+	const QST_type_us_phone = 'US_PHONE';
49
+
50
+	// constant used to indicate that the question type is an integer (whole number)
51
+	const QST_type_int = 'INTEGER';
52
+
53
+	// constant used to indicate that the question type is a decimal (float)
54
+	const QST_type_decimal = 'DECIMAL';
55
+
56
+	// constant used to indicate that the question type is a valid URL
57
+	const QST_type_url = 'URL';
58
+
59
+	// constant used to indicate that the question type is a YEAR
60
+	const QST_type_year = 'YEAR';
61
+
62
+	// constant used to indicate that the question type is a multi-select
63
+	const QST_type_multi_select = 'MULTI_SELECT';
64
+
65
+	/**
66
+	 * Question types that are interchangeable, even after answers have been provided for them.
67
+	 * Top-level keys are category slugs, next level is an array of question types. If question types
68
+	 * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
69
+	 *
70
+	 * @access protected
71
+	 * @var array $_question_type_categories {
72
+	 * @type string $text
73
+	 * @type string $single -answer-enum
74
+	 * @type string $multi -answer-enum
75
+	 *                    }
76
+	 */
77
+	protected $_question_type_categories = array();
78
+
79
+	/**
80
+	 * lists all the question types which should be allowed. Ideally, this will be extensible.
81
+	 *
82
+	 * @access protected
83
+	 * @var array $_allowed_question_types
84
+	 */
85
+	protected $_allowed_question_types = array();
86
+
87
+	/**
88
+	 * brief descriptions for all the question types
89
+	 *
90
+	 * @access protected
91
+	 * @var EEM_Question $_instance
92
+	 */
93
+	protected $_question_descriptions;
94
+
95
+
96
+	/**
97
+	 * Question types that should have an admin-defined max input length
98
+	 * @var array
99
+	 */
100
+	protected $question_types_with_max_lengh;
101
+
102
+
103
+	// private instance of the Attendee object
104
+	protected static $_instance = null;
105
+
106
+
107
+	/**
108
+	 * EEM_Question constructor.
109
+	 *
110
+	 * @param null $timezone
111
+	 */
112
+	protected function __construct($timezone = null)
113
+	{
114
+		$this->singular_item = esc_html__('Question', 'event_espresso');
115
+		$this->plural_item = esc_html__('Questions', 'event_espresso');
116
+		$this->_allowed_question_types = apply_filters(
117
+			'FHEE__EEM_Question__construct__allowed_question_types',
118
+			array(
119
+				EEM_Question::QST_type_text => esc_html__('Text', 'event_espresso'),
120
+				EEM_Question::QST_type_textarea => esc_html__('Textarea', 'event_espresso'),
121
+				EEM_Question::QST_type_checkbox => esc_html__('Checkboxes', 'event_espresso'),
122
+				EEM_Question::QST_type_radio => esc_html__('Radio Buttons', 'event_espresso'),
123
+				EEM_Question::QST_type_dropdown => esc_html__('Dropdown', 'event_espresso'),
124
+				EEM_Question::QST_type_state => esc_html__('State/Province Dropdown', 'event_espresso'),
125
+				EEM_Question::QST_type_country => esc_html__('Country Dropdown', 'event_espresso'),
126
+				EEM_Question::QST_type_date => esc_html__('Date Picker', 'event_espresso'),
127
+				EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'),
128
+				EEM_Question::QST_type_email => esc_html__('Email', 'event_espresso'),
129
+				EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'),
130
+				EEM_Question::QST_type_us_phone => esc_html__('USA - Format Phone', 'event_espresso'),
131
+				EEM_Question::QST_type_decimal => esc_html__('Number', 'event_espresso'),
132
+				EEM_Question::QST_type_int => esc_html__('Whole Number', 'event_espresso'),
133
+				EEM_Question::QST_type_url => esc_html__('URL', 'event_espresso'),
134
+				EEM_Question::QST_type_year => esc_html__('Year', 'event_espresso'),
135
+				EEM_Question::QST_type_multi_select => esc_html__('Multi Select', 'event_espresso')
136
+			)
137
+		);
138
+		$this->_question_descriptions = apply_filters(
139
+			'FHEE__EEM_Question__construct__question_descriptions',
140
+			array(
141
+				EEM_Question::QST_type_text => esc_html__('A single line text input field', 'event_espresso'),
142
+				EEM_Question::QST_type_textarea => esc_html__('A multi line text input field', 'event_espresso'),
143
+				EEM_Question::QST_type_checkbox => esc_html__('Allows multiple preset options to be selected', 'event_espresso'),
144
+				EEM_Question::QST_type_radio => esc_html__('Allows a single preset option to be selected', 'event_espresso'),
145
+				EEM_Question::QST_type_dropdown => esc_html__('A dropdown that allows a single selection', 'event_espresso'),
146
+				EEM_Question::QST_type_state => esc_html__('A dropdown that lists states/provinces', 'event_espresso'),
147
+				EEM_Question::QST_type_country => esc_html__('A dropdown that lists countries', 'event_espresso'),
148
+				EEM_Question::QST_type_date => esc_html__('A popup calendar that allows date selections', 'event_espresso'),
149
+				EEM_Question::QST_type_html_textarea => esc_html__('A multi line text input field that allows HTML', 'event_espresso'),
150
+				EEM_Question::QST_type_email => esc_html__('A text field that must contain a valid Email address', 'event_espresso'),
151
+				EEM_Question::QST_type_email_confirm => esc_html__('A text field that must contain a valid Email address and be equal to Email field', 'event_espresso'),
152
+				EEM_Question::QST_type_us_phone => esc_html__('A text field that must contain a valid US phone number', 'event_espresso'),
153
+				EEM_Question::QST_type_decimal => esc_html__('A text field that allows number values with decimals', 'event_espresso'),
154
+				EEM_Question::QST_type_int => esc_html__('A text field that only allows whole numbers (no decimals)', 'event_espresso'),
155
+				EEM_Question::QST_type_url => esc_html__('A text field that must contain a valid URL', 'event_espresso'),
156
+				EEM_Question::QST_type_year => esc_html__('A dropdown that lists the last 100 years', 'event_espresso'),
157
+				EEM_Question::QST_type_multi_select => esc_html__('A dropdown that allows multiple selections', 'event_espresso')
158
+			)
159
+		);
160
+		$this->_question_type_categories = (array) apply_filters(
161
+			'FHEE__EEM_Question__construct__question_type_categories',
162
+			array(
163
+				'text' => array(
164
+					EEM_Question::QST_type_text,
165
+					EEM_Question::QST_type_textarea,
166
+					EEM_Question::QST_type_date,
167
+					EEM_Question::QST_type_html_textarea,
168
+					EEM_Question::QST_type_email,
169
+					EEM_Question::QST_type_email_confirm,
170
+					EEM_Question::QST_type_us_phone,
171
+					EEM_Question::QST_type_decimal,
172
+					EEM_Question::QST_type_int,
173
+					EEM_Question::QST_type_url,
174
+					EEM_Question::QST_type_year
175
+				),
176
+				'single-answer-enum' => array(
177
+					EEM_Question::QST_type_radio,
178
+					EEM_Question::QST_type_dropdown
179
+				),
180
+				'multi-answer-enum' => array(
181
+					EEM_Question::QST_type_checkbox,
182
+					EEM_Question::QST_type_multi_select
183
+				)
184
+			)
185
+		);
186
+		$this->question_types_with_max_lengh = apply_filters(
187
+			'FHEE__EEM_Question___construct__question_types_with_max_length',
188
+			array(
189
+				EEM_Question::QST_type_text,
190
+				EEM_Question::QST_type_textarea,
191
+				EEM_Question::QST_type_html_textarea
192
+			)
193
+		);
194
+
195
+		$this->_tables = array(
196
+			'Question' => new EE_Primary_Table('esp_question', 'QST_ID')
197
+		);
198
+		$this->_fields = array(
199
+			'Question' => array(
200
+				'QST_ID' => new EE_Primary_Key_Int_Field('QST_ID', esc_html__('Question ID', 'event_espresso')),
201
+				'QST_display_text' => new EE_Post_Content_Field('QST_display_text', esc_html__('Question Text', 'event_espresso'), true, ''),
202
+				'QST_admin_label' => new EE_Plain_Text_Field('QST_admin_label', esc_html__('Question Label (admin-only)', 'event_espresso'), true, ''),
203
+				'QST_system' => new EE_Plain_Text_Field('QST_system', esc_html__('Internal string ID for question', 'event_espresso'), false, ''),
204
+				'QST_type' => new EE_Enum_Text_Field('QST_type', esc_html__('Question Type', 'event_espresso'), false, 'TEXT', $this->_allowed_question_types),
205
+				'QST_required' => new EE_Boolean_Field('QST_required', esc_html__('Required Question?', 'event_espresso'), false, false),
206
+				'QST_required_text' => new EE_Simple_HTML_Field('QST_required_text', esc_html__('Text to Display if Not Provided', 'event_espresso'), true, ''),
207
+				'QST_order' => new EE_Integer_Field('QST_order', esc_html__('Question Order', 'event_espresso'), false, 0),
208
+				'QST_admin_only' => new EE_Boolean_Field('QST_admin_only', esc_html__('Admin-Only Question?', 'event_espresso'), false, false),
209
+				'QST_max' => new EE_Infinite_Integer_Field('QST_max', esc_html__('Max Size', 'event_espresso'), false, EE_INF),
210
+				'QST_wp_user' => new EE_WP_User_Field('QST_wp_user', esc_html__('Question Creator ID', 'event_espresso'), false),
211
+				'QST_deleted' => new EE_Trashed_Flag_Field('QST_deleted', esc_html__('Flag Indicating question was deleted', 'event_espresso'), false, false)
212
+			)
213
+		);
214
+		$this->_model_relations = array(
215
+			'Question_Group' => new EE_HABTM_Relation('Question_Group_Question'),
216
+			'Question_Option' => new EE_Has_Many_Relation(),
217
+			'Answer' => new EE_Has_Many_Relation(),
218
+			'WP_User' => new EE_Belongs_To_Relation(),
219
+			// for QST_order column
220
+			'Question_Group_Question' => new EE_Has_Many_Relation()
221
+		);
222
+		// this model is generally available for reading
223
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
224
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QST_system');
225
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QST_system');
226
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QST_system');
227
+		parent::__construct($timezone);
228
+	}
229
+
230
+	/**
231
+	 * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE'
232
+	 * but they can be extended
233
+	 * @return string[]
234
+	 */
235
+	public function allowed_question_types()
236
+	{
237
+		return $this->_allowed_question_types;
238
+	}
239
+
240
+	/**
241
+	 * Gets all the question types in the same category
242
+	 * @param string $question_type one of EEM_Question::allowed_question_types(
243
+	 * @return string[] like EEM_Question::allowed_question_types()
244
+	 */
245
+	public function question_types_in_same_category($question_type)
246
+	{
247
+		$question_types = array($question_type);
248
+		foreach ($this->_question_type_categories as $category => $question_types_in_category) {
249
+			if (in_array($question_type, $question_types_in_category)) {
250
+				$question_types = $question_types_in_category;
251
+				break;
252
+			}
253
+		}
254
+
255
+		return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
256
+	}
257
+
258
+	/**
259
+	 * Determines if the given question type is in the given question type category
260
+	 * @param string $question_type one of EEM_Question::allowed_question_types()
261
+	 * @param string $category one of the top-level keys of EEM_Question::question_type_categories()
262
+	 * @return boolean
263
+	 */
264
+	public function question_type_is_in_category($question_type, $category)
265
+	{
266
+		if (!isset($this->_question_type_categories[ $category ])) {
267
+			return false;
268
+		}
269
+		return in_array($question_type, $this->_question_type_categories[ $category ]);
270
+	}
271
+
272
+
273
+	/**
274
+	 * Returns all the question types in the given category
275
+	 * @param string $category
276
+	 * @return array|mixed
277
+	 */
278
+	public function question_types_in_category($category)
279
+	{
280
+		if (isset($this->_question_type_categories[ $category ])) {
281
+			return $this->_question_type_categories[ $category ];
282
+		}
283
+		return array();
284
+	}
285
+
286
+
287
+	/**
288
+	 * Returns all the question types that should have question options
289
+	 * @return array
290
+	 */
291
+	public function question_types_with_options()
292
+	{
293
+		return array_merge(
294
+			$this->question_types_in_category('single-answer-enum'),
295
+			$this->question_types_in_category('multi-answer-enum')
296
+		);
297
+	}
298
+
299
+	/**
300
+	 * Returns the question type categories 2d array
301
+	 * @return array see EEM_Question::_question_type_categories
302
+	 */
303
+	public function question_type_categories()
304
+	{
305
+		return $this->_question_type_categories;
306
+	}
307
+
308
+	/**
309
+	 * Returns an array of all the QST_system values that can be allowed in the system question group
310
+	 * identified by $system_question_group_id
311
+	 * @param string $system_question_group_id QSG_system
312
+	 * @return array of system question names (QST_system)
313
+	 */
314
+	public function allowed_system_questions_in_system_question_group($system_question_group_id)
315
+	{
316
+		$question_system_ids = array();
317
+		switch ($system_question_group_id) {
318
+			case EEM_Question_Group::system_personal:
319
+				$question_system_ids = array(
320
+					EEM_Attendee::system_question_fname,
321
+					EEM_Attendee::system_question_lname,
322
+					EEM_Attendee::system_question_email,
323
+					EEM_Attendee::system_question_email_confirm,
324
+					EEM_Attendee::system_question_phone
325
+				);
326
+				break;
327
+			case EEM_Question_Group::system_address:
328
+				$question_system_ids = array(
329
+					EEM_Attendee::system_question_address,
330
+					EEM_Attendee::system_question_address2,
331
+					EEM_Attendee::system_question_city,
332
+					EEM_Attendee::system_question_state,
333
+					EEM_Attendee::system_question_country,
334
+					EEM_Attendee::system_question_zip,
335
+					EEM_Attendee::system_question_phone
336
+				);
337
+				break;
338
+		}
339
+		return apply_filters('FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return', $question_system_ids, $system_question_group_id);
340
+	}
341
+
342
+	/**
343
+	 * Returns an array of all the QST_system values that are required in the system question group
344
+	 * identified by $system_question_group_id
345
+	 * @param string $system_question_group_id QSG_system
346
+	 * @return array of system question names (QST_system)
347
+	 */
348
+	public function required_system_questions_in_system_question_group($system_question_group_id)
349
+	{
350
+		$question_system_ids = null;
351
+		switch ($system_question_group_id) {
352
+			case EEM_Question_Group::system_personal:
353
+				$question_system_ids = array(
354
+					EEM_Attendee::system_question_fname,
355
+					EEM_Attendee::system_question_email,
356
+				);
357
+				break;
358
+			default:
359
+				$question_system_ids = array();
360
+		}
361
+		return apply_filters('FHEE__EEM_Question__system_questions_required_in_system_question_group', $question_system_ids, $system_question_group_id);
362
+	}
363
+
364
+
365
+	/**
366
+	 * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
367
+	 * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city');
368
+	 * @param $QST_system
369
+	 * @return int of QST_ID for the question that corresponds to that QST_system
370
+	 */
371
+	public function get_Question_ID_from_system_string($QST_system)
372
+	{
373
+		return $this->get_var(array(array('QST_system' => $QST_system)));
374
+	}
375
+
376
+
377
+	/**
378
+	 * searches the db for the question with the latest question order and returns that value.
379
+	 * @access public
380
+	 * @return int
381
+	 */
382
+	public function get_latest_question_order()
383
+	{
384
+		$columns_to_select = array(
385
+			'max_order' => array("MAX(QST_order)", "%d")
386
+		);
387
+		$max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select);
388
+		return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
389
+	}
390
+
391
+	/**
392
+	 * Returns an array where keys are system question QST_system values,
393
+	 * and values are the highest question max the admin can set on the question
394
+	 * (aka the "max max"; eg, a site admin can change the zip question to have a max
395
+	 * of 5, but no larger than 12)
396
+	 * @return array
397
+	 */
398
+	public function system_question_maxes()
399
+	{
400
+		return array(
401
+			'fname' => 45,
402
+			'lname' => 45,
403
+			'address' => 255,
404
+			'address2' => 255,
405
+			'city' => 45,
406
+			'zip' => 12,
407
+			'email' => 255,
408
+			'email_confirm' => 255,
409
+			'phone' => 45,
410
+		);
411
+	}
412
+
413
+	/**
414
+	 * Given a QST_system value, gets the question's largest allowable max input.
415
+	 * @see Registration_Form_Admin_Page::system_question_maxes()
416
+	 * @param string $system_question_value
417
+	 * @return int|float
418
+	 */
419
+	public function absolute_max_for_system_question($system_question_value)
420
+	{
421
+		$maxes = $this->system_question_maxes();
422
+		if (isset($maxes[ $system_question_value ])) {
423
+			return $maxes[ $system_question_value ];
424
+		} else {
425
+			return EE_INF;
426
+		}
427
+	}
428
+
429
+
430
+	/**
431
+	 * @return array
432
+	 */
433
+	public function question_descriptions()
434
+	{
435
+		return $this->_question_descriptions;
436
+	}
437
+
438
+
439
+	/**
440
+	 * Returns all the question types that should have an admin-defined max input length
441
+	 * @return array
442
+	 */
443
+	public function questionTypesWithMaxLength()
444
+	{
445
+		return (array) $this->question_types_with_max_lengh;
446
+	}
447 447
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Belongs_To_Any_Relation.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -16,94 +16,94 @@
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     * get_join_statement
21
-     *
22
-     * @param string $model_relation_chain
23
-     * @return string
24
-     * @throws \EE_Error
25
-     */
26
-    public function get_join_statement($model_relation_chain)
27
-    {
28
-        // create the sql string like
29
-        $this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
30
-        // ALSO, need to get the field with the model name
31
-        $field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name();
19
+	/**
20
+	 * get_join_statement
21
+	 *
22
+	 * @param string $model_relation_chain
23
+	 * @return string
24
+	 * @throws \EE_Error
25
+	 */
26
+	public function get_join_statement($model_relation_chain)
27
+	{
28
+		// create the sql string like
29
+		$this_table_fk_field = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
30
+		// ALSO, need to get the field with the model name
31
+		$field_with_model_name = $this->get_this_model()->get_field_containing_related_model_name();
32 32
 
33 33
 
34
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
35
-        $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
36
-            $model_relation_chain,
37
-            $this->get_this_model()->get_this_model_name()
38
-        ) . $this_table_fk_field->get_table_alias();
39
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
40
-            $model_relation_chain,
41
-            $this->get_other_model()->get_this_model_name()
42
-        ) . $other_table_pk_field->get_table_alias();
43
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
44
-        return $this->_left_join(
45
-            $other_table,
46
-            $other_table_alias,
47
-            $other_table_pk_field->get_table_column(),
48
-            $this_table_alias,
49
-            $this_table_fk_field->get_table_column(),
50
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
51
-        )
52
-               . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
53
-    }
34
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
35
+		$this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
36
+			$model_relation_chain,
37
+			$this->get_this_model()->get_this_model_name()
38
+		) . $this_table_fk_field->get_table_alias();
39
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
40
+			$model_relation_chain,
41
+			$this->get_other_model()->get_this_model_name()
42
+		) . $other_table_pk_field->get_table_alias();
43
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
44
+		return $this->_left_join(
45
+			$other_table,
46
+			$other_table_alias,
47
+			$other_table_pk_field->get_table_column(),
48
+			$this_table_alias,
49
+			$this_table_fk_field->get_table_column(),
50
+			$field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
51
+		)
52
+			   . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
53
+	}
54 54
 
55 55
 
56
-    /**
57
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
58
-     * you like.
59
-     *
60
-     * @param EE_Base_Class|int $this_obj_or_id
61
-     * @param EE_Base_Class|int $other_obj_or_id
62
-     * @param array             $extra_join_model_fields_n_values
63
-     * @return \EE_Base_Class
64
-     * @throws \EE_Error
65
-     */
66
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
67
-    {
68
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
69
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
70
-        // find the field on THIS model which a foreign key to the other model
71
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
72
-        // set that field on the other model to this model's ID
73
-        $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
74
-        // and make sure this model's field with the foreign model name is set to the correct value
75
-        $this_model_obj->set(
76
-            $this->get_this_model()->get_field_containing_related_model_name()->get_name(),
77
-            $this->get_other_model()->get_this_model_name()
78
-        );
79
-        $this_model_obj->save();
80
-        return $other_model_obj;
81
-    }
56
+	/**
57
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
58
+	 * you like.
59
+	 *
60
+	 * @param EE_Base_Class|int $this_obj_or_id
61
+	 * @param EE_Base_Class|int $other_obj_or_id
62
+	 * @param array             $extra_join_model_fields_n_values
63
+	 * @return \EE_Base_Class
64
+	 * @throws \EE_Error
65
+	 */
66
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
67
+	{
68
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
69
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
70
+		// find the field on THIS model which a foreign key to the other model
71
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
72
+		// set that field on the other model to this model's ID
73
+		$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
74
+		// and make sure this model's field with the foreign model name is set to the correct value
75
+		$this_model_obj->set(
76
+			$this->get_this_model()->get_field_containing_related_model_name()->get_name(),
77
+			$this->get_other_model()->get_this_model_name()
78
+		);
79
+		$this_model_obj->save();
80
+		return $other_model_obj;
81
+	}
82 82
 
83 83
 
84
-    /**
85
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
86
-     *
87
-     * @param EE_Base_Class|int $this_obj_or_id
88
-     * @param EE_Base_Class|int $other_obj_or_id
89
-     * @param array             $where_query
90
-     * @return \EE_Base_Class
91
-     * @throws \EE_Error
92
-     */
93
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
-    {
95
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
96
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
97
-        // find the field on the other model which is a foreign key to this model
98
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
99
-        // set that field on the other model to this model's ID
100
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
101
-        $this_model_obj->set(
102
-            $this->get_this_model()->get_field_containing_related_model_name()->get_name(),
103
-            null,
104
-            true
105
-        );
106
-        $this_model_obj->save();
107
-        return $other_model_obj;
108
-    }
84
+	/**
85
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
86
+	 *
87
+	 * @param EE_Base_Class|int $this_obj_or_id
88
+	 * @param EE_Base_Class|int $other_obj_or_id
89
+	 * @param array             $where_query
90
+	 * @return \EE_Base_Class
91
+	 * @throws \EE_Error
92
+	 */
93
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
+	{
95
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
96
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
97
+		// find the field on the other model which is a foreign key to this model
98
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
99
+		// set that field on the other model to this model's ID
100
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
101
+		$this_model_obj->set(
102
+			$this->get_this_model()->get_field_containing_related_model_name()->get_name(),
103
+			null,
104
+			true
105
+		);
106
+		$this_model_obj->save();
107
+		return $other_model_obj;
108
+	}
109 109
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -35,19 +35,19 @@
 block discarded – undo
35 35
         $this_table_alias     = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
36 36
             $model_relation_chain,
37 37
             $this->get_this_model()->get_this_model_name()
38
-        ) . $this_table_fk_field->get_table_alias();
39
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
38
+        ).$this_table_fk_field->get_table_alias();
39
+        $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
40 40
             $model_relation_chain,
41 41
             $this->get_other_model()->get_this_model_name()
42
-        ) . $other_table_pk_field->get_table_alias();
43
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
42
+        ).$other_table_pk_field->get_table_alias();
43
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
44 44
         return $this->_left_join(
45 45
             $other_table,
46 46
             $other_table_alias,
47 47
             $other_table_pk_field->get_table_column(),
48 48
             $this_table_alias,
49 49
             $this_table_fk_field->get_table_column(),
50
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
50
+            $field_with_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'"
51 51
         )
52 52
                . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
53 53
     }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Relation.php 2 patches
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -11,102 +11,102 @@
 block discarded – undo
11 11
 class EE_Has_Many_Relation extends EE_Model_Relation_Base
12 12
 {
13 13
 
14
-    /**
15
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
16
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
17
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
18
-     * related models across the relation, and add-and-remove the relationships.
19
-     *
20
-     * @param boolean $block_deletes                 For this type of r elation, we block by default. If there are
21
-     *                                               related models across this relation, block (prevent and add an
22
-     *                                               error) the deletion of this model
23
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
24
-     *                                               default
25
-     */
26
-    public function __construct($block_deletes = true, $blocking_delete_error_message = null)
27
-    {
28
-        parent::__construct($block_deletes, $blocking_delete_error_message);
29
-    }
14
+	/**
15
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
16
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
17
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
18
+	 * related models across the relation, and add-and-remove the relationships.
19
+	 *
20
+	 * @param boolean $block_deletes                 For this type of r elation, we block by default. If there are
21
+	 *                                               related models across this relation, block (prevent and add an
22
+	 *                                               error) the deletion of this model
23
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
24
+	 *                                               default
25
+	 */
26
+	public function __construct($block_deletes = true, $blocking_delete_error_message = null)
27
+	{
28
+		parent::__construct($block_deletes, $blocking_delete_error_message);
29
+	}
30 30
 
31 31
 
32
-    /**
33
-     * Gets the SQL string for performing the join between this model and the other model.
34
-     *
35
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
36
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
37
-     *                other_model_primary_table.fk" etc
38
-     * @throws \EE_Error
39
-     */
40
-    public function get_join_statement($model_relation_chain)
41
-    {
42
-        // create the sql string like
43
-        // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
44
-        $this_table_pk_field  = $this->get_this_model()->get_primary_key_field();
45
-        $other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
46
-        $pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47
-            $model_relation_chain,
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(
51
-            $model_relation_chain,
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);
32
+	/**
33
+	 * Gets the SQL string for performing the join between this model and the other model.
34
+	 *
35
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
36
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
37
+	 *                other_model_primary_table.fk" etc
38
+	 * @throws \EE_Error
39
+	 */
40
+	public function get_join_statement($model_relation_chain)
41
+	{
42
+		// create the sql string like
43
+		// LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
44
+		$this_table_pk_field  = $this->get_this_model()->get_primary_key_field();
45
+		$other_table_fk_field = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
46
+		$pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
47
+			$model_relation_chain,
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(
51
+			$model_relation_chain,
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);
55 55
 
56
-        return $this->_left_join(
57
-            $fk_table,
58
-            $fk_table_alias,
59
-            $other_table_fk_field->get_table_column(),
60
-            $pk_table_alias,
61
-            $this_table_pk_field->get_table_column()
62
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
63
-    }
56
+		return $this->_left_join(
57
+			$fk_table,
58
+			$fk_table_alias,
59
+			$other_table_fk_field->get_table_column(),
60
+			$pk_table_alias,
61
+			$this_table_pk_field->get_table_column()
62
+		) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
63
+	}
64 64
 
65 65
 
66
-    /**
67
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
68
-     * you like.
69
-     *
70
-     * @param EE_Base_Class|int $this_obj_or_id
71
-     * @param EE_Base_Class|int $other_obj_or_id
72
-     * @param array             $extra_join_model_fields_n_values
73
-     * @return \EE_Base_Class
74
-     * @throws \EE_Error
75
-     */
76
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
77
-    {
78
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
79
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
66
+	/**
67
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
68
+	 * you like.
69
+	 *
70
+	 * @param EE_Base_Class|int $this_obj_or_id
71
+	 * @param EE_Base_Class|int $other_obj_or_id
72
+	 * @param array             $extra_join_model_fields_n_values
73
+	 * @return \EE_Base_Class
74
+	 * @throws \EE_Error
75
+	 */
76
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
77
+	{
78
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
79
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
80 80
 
81
-        // find the field on the other model which is a foreign key to this model
82
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
83
-        if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
84
-            // set that field on the other model to this model's ID
85
-            $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
86
-            $other_model_obj->save();
87
-        }
88
-        return $other_model_obj;
89
-    }
81
+		// find the field on the other model which is a foreign key to this model
82
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
83
+		if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
84
+			// set that field on the other model to this model's ID
85
+			$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
86
+			$other_model_obj->save();
87
+		}
88
+		return $other_model_obj;
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
94
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
95
-     *
96
-     * @param EE_Base_Class|int $this_obj_or_id
97
-     * @param EE_Base_Class|int $other_obj_or_id
98
-     * @param array             $where_query
99
-     * @return \EE_Base_Class
100
-     * @throws \EE_Error
101
-     */
102
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
103
-    {
104
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
105
-        // find the field on the other model which is a foreign key to this model
106
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
107
-        // set that field on the other model to this model's ID
108
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
109
-        $other_model_obj->save();
110
-        return $other_model_obj;
111
-    }
92
+	/**
93
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
94
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
95
+	 *
96
+	 * @param EE_Base_Class|int $this_obj_or_id
97
+	 * @param EE_Base_Class|int $other_obj_or_id
98
+	 * @param array             $where_query
99
+	 * @return \EE_Base_Class
100
+	 * @throws \EE_Error
101
+	 */
102
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
103
+	{
104
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
105
+		// find the field on the other model which is a foreign key to this model
106
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
107
+		// set that field on the other model to this model's ID
108
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
109
+		$other_model_obj->save();
110
+		return $other_model_obj;
111
+	}
112 112
 }
Please login to merge, or discard this patch.
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.
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
@@ -12,137 +12,137 @@
 block discarded – undo
12 12
 class EE_Belongs_To_Relation extends EE_Model_Relation_Base
13 13
 {
14 14
 
15
-    /**
16
-     * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
17
-     * to the other model. This knows how to join the models,
18
-     * get related models across the relation, and add-and-remove the relationships.
19
-     *
20
-     * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
21
-     *                                                              default. if there are related models across this
22
-     *                                                              relation, block (prevent and add an error) the
23
-     *                                                              deletion of this model
24
-     * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
25
-     *                                                              instead of the default
26
-     */
27
-    public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
28
-    {
29
-        parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
30
-    }
15
+	/**
16
+	 * Object representing the relationship between two models. Belongs_To means that THIS model has the foreign key
17
+	 * to the other model. This knows how to join the models,
18
+	 * get related models across the relation, and add-and-remove the relationships.
19
+	 *
20
+	 * @param boolean $block_deletes                                For Belongs_To relations, this is set to FALSE by
21
+	 *                                                              default. if there are related models across this
22
+	 *                                                              relation, block (prevent and add an error) the
23
+	 *                                                              deletion of this model
24
+	 * @param string  $related_model_objects_deletion_error_message a customized error message on blocking deletes
25
+	 *                                                              instead of the default
26
+	 */
27
+	public function __construct($block_deletes = false, $related_model_objects_deletion_error_message = null)
28
+	{
29
+		parent::__construct($block_deletes, $related_model_objects_deletion_error_message);
30
+	}
31 31
 
32 32
 
33
-    /**
34
-     * get_join_statement
35
-     *
36
-     * @param string $model_relation_chain
37
-     * @return string
38
-     * @throws \EE_Error
39
-     */
40
-    public function get_join_statement($model_relation_chain)
41
-    {
42
-        // create the sql string like
43
-        $this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
44
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
45
-        $this_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_fk_field->get_table_alias();
49
-        $other_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_pk_field->get_table_alias();
53
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
54
-        return $this->_left_join(
55
-            $other_table,
56
-            $other_table_alias,
57
-            $other_table_pk_field->get_table_column(),
58
-            $this_table_alias,
59
-            $this_table_fk_field->get_table_column()
60
-        ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
61
-    }
33
+	/**
34
+	 * get_join_statement
35
+	 *
36
+	 * @param string $model_relation_chain
37
+	 * @return string
38
+	 * @throws \EE_Error
39
+	 */
40
+	public function get_join_statement($model_relation_chain)
41
+	{
42
+		// create the sql string like
43
+		$this_table_fk_field  = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
44
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
45
+		$this_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_fk_field->get_table_alias();
49
+		$other_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_pk_field->get_table_alias();
53
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
54
+		return $this->_left_join(
55
+			$other_table,
56
+			$other_table_alias,
57
+			$other_table_pk_field->get_table_column(),
58
+			$this_table_alias,
59
+			$this_table_fk_field->get_table_column()
60
+		) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
61
+	}
62 62
 
63 63
 
64
-    /**
65
-     * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
66
-     * you like.
67
-     *
68
-     * @param EE_Base_Class|int $this_obj_or_id
69
-     * @param EE_Base_Class|int $other_obj_or_id
70
-     * @param array             $extra_join_model_fields_n_values
71
-     * @return \EE_Base_Class
72
-     * @throws \EE_Error
73
-     */
74
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
-    {
76
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
78
-        // find the field on the other model which is a foreign key to this model
79
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
80
-        if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
81
-            // set that field on the other model to this model's ID
82
-            $this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
83
-            $this_model_obj->save();
84
-        }
85
-        return $other_model_obj;
86
-    }
64
+	/**
65
+	 * Sets this model object's foreign key to the other model object's primary key. Feel free to do this manually if
66
+	 * you like.
67
+	 *
68
+	 * @param EE_Base_Class|int $this_obj_or_id
69
+	 * @param EE_Base_Class|int $other_obj_or_id
70
+	 * @param array             $extra_join_model_fields_n_values
71
+	 * @return \EE_Base_Class
72
+	 * @throws \EE_Error
73
+	 */
74
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
+	{
76
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
78
+		// find the field on the other model which is a foreign key to this model
79
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
80
+		if ($this_model_obj->get($fk_on_this_model->get_name()) != $other_model_obj->ID()) {
81
+			// set that field on the other model to this model's ID
82
+			$this_model_obj->set($fk_on_this_model->get_name(), $other_model_obj->ID());
83
+			$this_model_obj->save();
84
+		}
85
+		return $other_model_obj;
86
+	}
87 87
 
88 88
 
89
-    /**
90
-     * Sets the this model object's foreign key to its default, instead of pointing to the other model object
91
-     *
92
-     * @param EE_Base_Class|int $this_obj_or_id
93
-     * @param EE_Base_Class|int $other_obj_or_id
94
-     * @param array             $where_query
95
-     * @return \EE_Base_Class
96
-     * @throws \EE_Error
97
-     */
98
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
99
-    {
100
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
101
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
102
-        // find the field on the other model which is a foreign key to this model
103
-        $fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
104
-        // set that field on the other model to this model's ID
105
-        $this_model_obj->set($fk_on_this_model->get_name(), null, true);
106
-        $this_model_obj->save();
107
-        return $other_model_obj;
108
-    }
89
+	/**
90
+	 * Sets the this model object's foreign key to its default, instead of pointing to the other model object
91
+	 *
92
+	 * @param EE_Base_Class|int $this_obj_or_id
93
+	 * @param EE_Base_Class|int $other_obj_or_id
94
+	 * @param array             $where_query
95
+	 * @return \EE_Base_Class
96
+	 * @throws \EE_Error
97
+	 */
98
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
99
+	{
100
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
101
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
102
+		// find the field on the other model which is a foreign key to this model
103
+		$fk_on_this_model = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
104
+		// set that field on the other model to this model's ID
105
+		$this_model_obj->set($fk_on_this_model->get_name(), null, true);
106
+		$this_model_obj->save();
107
+		return $other_model_obj;
108
+	}
109 109
 
110 110
 
111
-    /**
112
-     * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
113
-     *
114
-     * @param EE_Base_Class $model_obj_or_id
115
-     * @param array         $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
116
-     * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
117
-     * @return EE_Base_Class[]
118
-     * @throws \EE_Error
119
-     */
120
-    public function get_all_related(
121
-        $model_obj_or_id,
122
-        $query_params = array(),
123
-        $values_already_prepared_by_model_object = false
124
-    ) {
125
-        if ($values_already_prepared_by_model_object !== false) {
126
-            EE_Error::doing_it_wrong(
127
-                'EE_Model_Relation_Base::get_all_related',
128
-                esc_html__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
129
-                '4.8.1'
130
-            );
131
-        }
132
-        // get column on this model object which is a foreign key to the other model
133
-        $fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
134
-        // get its value
135
-        if ($model_obj_or_id instanceof EE_Base_Class) {
136
-            $model_obj = $model_obj_or_id;
137
-        } else {
138
-            $model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
139
-        }
140
-        $ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
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);
111
+	/**
112
+	 * Overrides parent so that we don't NEED to save the $model_object before getting the related objects.
113
+	 *
114
+	 * @param EE_Base_Class $model_obj_or_id
115
+	 * @param array         $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
116
+	 * @param boolean       $values_already_prepared_by_model_object @deprecated since 4.8.1
117
+	 * @return EE_Base_Class[]
118
+	 * @throws \EE_Error
119
+	 */
120
+	public function get_all_related(
121
+		$model_obj_or_id,
122
+		$query_params = array(),
123
+		$values_already_prepared_by_model_object = false
124
+	) {
125
+		if ($values_already_prepared_by_model_object !== false) {
126
+			EE_Error::doing_it_wrong(
127
+				'EE_Model_Relation_Base::get_all_related',
128
+				esc_html__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
129
+				'4.8.1'
130
+			);
131
+		}
132
+		// get column on this model object which is a foreign key to the other model
133
+		$fk_field_obj = $this->get_this_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name());
134
+		// get its value
135
+		if ($model_obj_or_id instanceof EE_Base_Class) {
136
+			$model_obj = $model_obj_or_id;
137
+		} else {
138
+			$model_obj = $this->get_this_model()->ensure_is_obj($model_obj_or_id);
139
+		}
140
+		$ID_value_on_other_model = $model_obj->get($fk_field_obj->get_name());
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);
144 144
 //      echo '$query_params';
145 145
 //      var_dump($query_params);
146
-        return $this->get_other_model()->get_all($query_params);
147
-    }
146
+		return $this->get_other_model()->get_all($query_params);
147
+	}
148 148
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_HABTM_Any_Relation.php 2 patches
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         } else {
63 63
             $order = 'second';
64 64
         }
65
-        return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
65
+        return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field);
66 66
     }
67 67
 
68 68
 
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
             $this->get_this_model()->get_this_model_name(),
88 88
             'ID'
89 89
         );
90
-        $field_with_model_name                     = $this->get_join_table_fk_field_to(
90
+        $field_with_model_name = $this->get_join_table_fk_field_to(
91 91
             $this->get_this_model()->get_this_model_name(),
92 92
             'name'
93 93
         );
94
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
94
+        $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95 95
             $model_relation_chain,
96 96
             $this->get_this_model()->get_this_model_name()
97
-        ) . $this_table_pk_field->get_table_alias();
98
-        $join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
97
+        ).$this_table_pk_field->get_table_alias();
98
+        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99 99
             $model_relation_chain,
100 100
             $this->get_join_model()->get_this_model_name()
101
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
102
-        $join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
101
+        ).$join_table_fk_field_to_this_table->get_table_alias();
102
+        $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias);
103 103
         // phew! ok, we have all the info we need, now we can create the SQL join string
104 104
         $SQL = $this->_left_join(
105 105
             $join_table,
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
             $join_table_fk_field_to_this_table->get_table_column(),
108 108
             $this_table_alias,
109 109
             $this_table_pk_field->get_table_column(),
110
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
-        ) .
110
+            $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'"
111
+        ).
112 112
                $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
113 113
 
114 114
         return $SQL;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                 'event_espresso'
135 135
             )));
136 136
         }
137
-        $join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
137
+        $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to(
138 138
             $this->get_this_model()->get_this_model_name(),
139 139
             'ID'
140 140
         );
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
             $this->get_other_model()->get_this_model_name(),
143 143
             'ID'
144 144
         );
145
-        $field_with_other_model_name        = $this->get_join_table_fk_field_to(
145
+        $field_with_other_model_name = $this->get_join_table_fk_field_to(
146 146
             $this->get_other_model()->get_this_model_name(),
147 147
             'name'
148 148
         );
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
         $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151 151
             $this->_model_relation_chain_to_join_model,
152 152
             $this->get_join_model()->get_this_model_name()
153
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
153
+        ).$join_table_fk_field_to_this_table->get_table_alias();
154 154
 
155 155
         $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156 156
         $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157 157
             $model_relation_chain,
158 158
             $this->get_other_model()->get_this_model_name()
159
-        ) . $other_table_pk_field->get_table_alias();
160
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
159
+        ).$other_table_pk_field->get_table_alias();
160
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
161 161
 
162 162
         $SQL = $this->_left_join(
163 163
             $other_table,
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
             $other_table_pk_field->get_table_column(),
166 166
             $join_table_alias,
167 167
             $join_table_fk_field_to_other_table->get_table_column(),
168
-            $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
-        ) .
168
+            $field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'"
169
+        ).
170 170
                $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171 171
         return $SQL;
172 172
     }
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
         $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189 189
         $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190 190
         // check if such a relationship already exists
191
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
191
+        $join_model_fk_to_this_model = $this->get_join_table_fk_field_to(
192 192
             $this->get_this_model()->get_this_model_name(),
193 193
             'ID'
194 194
         );
195
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
195
+        $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to(
196 196
             $this->get_this_model()->get_this_model_name(),
197 197
             'name'
198 198
         );
199
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
199
+        $join_model_fk_to_other_model = $this->get_join_table_fk_field_to(
200 200
             $this->get_other_model()->get_this_model_name(),
201 201
             'ID'
202 202
         );
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
         );
214 214
 
215 215
         // if $where_query exists lets add them to the query_params.
216
-        if (! empty($extra_join_model_fields_n_values)) {
216
+        if ( ! empty($extra_join_model_fields_n_values)) {
217 217
             // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
218 218
             // make sure we strip THIS models name from the query param
219 219
             $parsed_query = array();
220 220
             foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
-                $query_param                = str_replace(
222
-                    $this->get_join_model()->get_this_model_name() . ".",
221
+                $query_param = str_replace(
222
+                    $this->get_join_model()->get_this_model_name().".",
223 223
                     "",
224 224
                     $query_param
225 225
                 );
226
-                $parsed_query[ $query_param ] = $val;
226
+                $parsed_query[$query_param] = $val;
227 227
             }
228 228
             $cols_n_values = array_merge($cols_n_values, $parsed_query);
229 229
         }
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         // if there is already an entry in the join table, indicating a relationship, we're done
236 236
         // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237 237
         // the other tables, use the joining model directly!
238
-        if (! $existing_entry_in_join_table) {
238
+        if ( ! $existing_entry_in_join_table) {
239 239
             $this->get_join_model()->insert($cols_n_values);
240 240
         }
241 241
         return $other_model_obj;
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
         $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258 258
         $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259 259
         // check if such a relationship already exists
260
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
260
+        $join_model_fk_to_this_model = $this->get_join_table_fk_field_to(
261 261
             $this->get_this_model()->get_this_model_name(),
262 262
             'ID'
263 263
         );
264
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
264
+        $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to(
265 265
             $this->get_this_model()->get_this_model_name(),
266 266
             'name'
267 267
         );
268
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
268
+        $join_model_fk_to_other_model = $this->get_join_table_fk_field_to(
269 269
             $this->get_other_model()->get_this_model_name(),
270 270
             'ID'
271 271
         );
@@ -282,17 +282,17 @@  discard block
 block discarded – undo
282 282
         );
283 283
 
284 284
         // if $where_query exists lets add them to the query_params.
285
-        if (! empty($where_query)) {
285
+        if ( ! empty($where_query)) {
286 286
             // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
287 287
             // make sure we strip THIS models name from the query param
288 288
             $parsed_query = array();
289 289
             foreach ($where_query as $query_param => $val) {
290
-                $query_param                = str_replace(
291
-                    $this->get_join_model()->get_this_model_name() . ".",
290
+                $query_param = str_replace(
291
+                    $this->get_join_model()->get_this_model_name().".",
292 292
                     "",
293 293
                     $query_param
294 294
                 );
295
-                $parsed_query[ $query_param ] = $val;
295
+                $parsed_query[$query_param] = $val;
296 296
             }
297 297
             $cols_n_values = array_merge($cols_n_values, $parsed_query);
298 298
         }
Please login to merge, or discard this patch.
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -10,294 +10,294 @@
 block discarded – undo
10 10
  */
11 11
 class EE_HABTM_Any_Relation extends EE_HABTM_Relation
12 12
 {
13
-    /**
14
-     * @var string
15
-     */
16
-    protected $_alphabetically_first_model_name;
13
+	/**
14
+	 * @var string
15
+	 */
16
+	protected $_alphabetically_first_model_name;
17 17
 
18
-    /**
19
-     * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
20
-     * (and an ee joining-model.) This knows how to join the models,
21
-     * get related models across the relation, and add-and-remove the relationships.
22
-     *
23
-     * @param boolean $block_deletes                 for this type of relation, we block by default for now. if there
24
-     *                                               are related models across this relation, block (prevent and add an
25
-     *                                               error) the deletion of this model
26
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
27
-     *                                               default
28
-     */
29
-    public function __construct($block_deletes = true, $blocking_delete_error_message = '')
30
-    {
31
-        parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
32
-    }
18
+	/**
19
+	 * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
20
+	 * (and an ee joining-model.) This knows how to join the models,
21
+	 * get related models across the relation, and add-and-remove the relationships.
22
+	 *
23
+	 * @param boolean $block_deletes                 for this type of relation, we block by default for now. if there
24
+	 *                                               are related models across this relation, block (prevent and add an
25
+	 *                                               error) the deletion of this model
26
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
27
+	 *                                               default
28
+	 */
29
+	public function __construct($block_deletes = true, $blocking_delete_error_message = '')
30
+	{
31
+		parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * @param $this_model_name
37
-     * @param $other_model_name
38
-     * @throws EE_Error
39
-     */
40
-    public function _construct_finalize_set_models($this_model_name, $other_model_name)
41
-    {
42
-        if ($this_model_name < $other_model_name) {
43
-            $this->_alphabetically_first_model_name = $this_model_name;
44
-        } else {
45
-            $this->_alphabetically_first_model_name = $other_model_name;
46
-        }
47
-        parent::_construct_finalize_set_models($this_model_name, $other_model_name);
48
-    }
35
+	/**
36
+	 * @param $this_model_name
37
+	 * @param $other_model_name
38
+	 * @throws EE_Error
39
+	 */
40
+	public function _construct_finalize_set_models($this_model_name, $other_model_name)
41
+	{
42
+		if ($this_model_name < $other_model_name) {
43
+			$this->_alphabetically_first_model_name = $this_model_name;
44
+		} else {
45
+			$this->_alphabetically_first_model_name = $other_model_name;
46
+		}
47
+		parent::_construct_finalize_set_models($this_model_name, $other_model_name);
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @param string $model_name
53
-     * @param string $id_or_name_field should be the string 'ID' or 'name' only
54
-     * @return EE_Model_Field_Base
55
-     * @throws \EE_Error
56
-     */
57
-    public function get_join_table_fk_field_to($model_name, $id_or_name_field)
58
-    {
59
-        $order = null;
60
-        if ($model_name === $this->_alphabetically_first_model_name) {
61
-            $order = 'first';
62
-        } else {
63
-            $order = 'second';
64
-        }
65
-        return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
66
-    }
51
+	/**
52
+	 * @param string $model_name
53
+	 * @param string $id_or_name_field should be the string 'ID' or 'name' only
54
+	 * @return EE_Model_Field_Base
55
+	 * @throws \EE_Error
56
+	 */
57
+	public function get_join_table_fk_field_to($model_name, $id_or_name_field)
58
+	{
59
+		$order = null;
60
+		if ($model_name === $this->_alphabetically_first_model_name) {
61
+			$order = 'first';
62
+		} else {
63
+			$order = 'second';
64
+		}
65
+		return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
71
-     * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
72
-     *
73
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
74
-     * @return string of SQL
75
-     * @throws \EE_Error
76
-     */
77
-    public function get_join_to_intermediate_model_statement($model_relation_chain)
78
-    {
79
-        // create sql like
80
-        // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
81
-        // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
82
-        // remember the model relation chain to the JOIN model, because we'll
83
-        // need it for get_join_statement()
84
-        $this->_model_relation_chain_to_join_model = $model_relation_chain;
85
-        $this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();
86
-        $join_table_fk_field_to_this_table         = $this->get_join_table_fk_field_to(
87
-            $this->get_this_model()->get_this_model_name(),
88
-            'ID'
89
-        );
90
-        $field_with_model_name                     = $this->get_join_table_fk_field_to(
91
-            $this->get_this_model()->get_this_model_name(),
92
-            'name'
93
-        );
94
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95
-            $model_relation_chain,
96
-            $this->get_this_model()->get_this_model_name()
97
-        ) . $this_table_pk_field->get_table_alias();
98
-        $join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99
-            $model_relation_chain,
100
-            $this->get_join_model()->get_this_model_name()
101
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
102
-        $join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
103
-        // phew! ok, we have all the info we need, now we can create the SQL join string
104
-        $SQL = $this->_left_join(
105
-            $join_table,
106
-            $join_table_alias,
107
-            $join_table_fk_field_to_this_table->get_table_column(),
108
-            $this_table_alias,
109
-            $this_table_pk_field->get_table_column(),
110
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
-        ) .
112
-               $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
69
+	/**
70
+	 * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
71
+	 * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
72
+	 *
73
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
74
+	 * @return string of SQL
75
+	 * @throws \EE_Error
76
+	 */
77
+	public function get_join_to_intermediate_model_statement($model_relation_chain)
78
+	{
79
+		// create sql like
80
+		// LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
81
+		// LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
82
+		// remember the model relation chain to the JOIN model, because we'll
83
+		// need it for get_join_statement()
84
+		$this->_model_relation_chain_to_join_model = $model_relation_chain;
85
+		$this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();
86
+		$join_table_fk_field_to_this_table         = $this->get_join_table_fk_field_to(
87
+			$this->get_this_model()->get_this_model_name(),
88
+			'ID'
89
+		);
90
+		$field_with_model_name                     = $this->get_join_table_fk_field_to(
91
+			$this->get_this_model()->get_this_model_name(),
92
+			'name'
93
+		);
94
+		$this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95
+			$model_relation_chain,
96
+			$this->get_this_model()->get_this_model_name()
97
+		) . $this_table_pk_field->get_table_alias();
98
+		$join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99
+			$model_relation_chain,
100
+			$this->get_join_model()->get_this_model_name()
101
+		) . $join_table_fk_field_to_this_table->get_table_alias();
102
+		$join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
103
+		// phew! ok, we have all the info we need, now we can create the SQL join string
104
+		$SQL = $this->_left_join(
105
+			$join_table,
106
+			$join_table_alias,
107
+			$join_table_fk_field_to_this_table->get_table_column(),
108
+			$this_table_alias,
109
+			$this_table_pk_field->get_table_column(),
110
+			$field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
+		) .
112
+			   $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
113 113
 
114
-        return $SQL;
115
-    }
114
+		return $SQL;
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
120
-     * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
121
-     * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
122
-     * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
123
-     * the intermediate join table, and then to the other model's pk's table
124
-     *
125
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
126
-     * @return string of SQL
127
-     * @throws \EE_Error
128
-     */
129
-    public function get_join_statement($model_relation_chain)
130
-    {
131
-        if ($this->_model_relation_chain_to_join_model === null) {
132
-            throw new EE_Error(sprintf(esc_html__(
133
-                'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
134
-                'event_espresso'
135
-            )));
136
-        }
137
-        $join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
138
-            $this->get_this_model()->get_this_model_name(),
139
-            'ID'
140
-        );
141
-        $join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to(
142
-            $this->get_other_model()->get_this_model_name(),
143
-            'ID'
144
-        );
145
-        $field_with_other_model_name        = $this->get_join_table_fk_field_to(
146
-            $this->get_other_model()->get_this_model_name(),
147
-            'name'
148
-        );
118
+	/**
119
+	 * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
120
+	 * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
121
+	 * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
122
+	 * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
123
+	 * the intermediate join table, and then to the other model's pk's table
124
+	 *
125
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
126
+	 * @return string of SQL
127
+	 * @throws \EE_Error
128
+	 */
129
+	public function get_join_statement($model_relation_chain)
130
+	{
131
+		if ($this->_model_relation_chain_to_join_model === null) {
132
+			throw new EE_Error(sprintf(esc_html__(
133
+				'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
134
+				'event_espresso'
135
+			)));
136
+		}
137
+		$join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
138
+			$this->get_this_model()->get_this_model_name(),
139
+			'ID'
140
+		);
141
+		$join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to(
142
+			$this->get_other_model()->get_this_model_name(),
143
+			'ID'
144
+		);
145
+		$field_with_other_model_name        = $this->get_join_table_fk_field_to(
146
+			$this->get_other_model()->get_this_model_name(),
147
+			'name'
148
+		);
149 149
 
150
-        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151
-            $this->_model_relation_chain_to_join_model,
152
-            $this->get_join_model()->get_this_model_name()
153
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
150
+		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151
+			$this->_model_relation_chain_to_join_model,
152
+			$this->get_join_model()->get_this_model_name()
153
+		) . $join_table_fk_field_to_this_table->get_table_alias();
154 154
 
155
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157
-            $model_relation_chain,
158
-            $this->get_other_model()->get_this_model_name()
159
-        ) . $other_table_pk_field->get_table_alias();
160
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
155
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157
+			$model_relation_chain,
158
+			$this->get_other_model()->get_this_model_name()
159
+		) . $other_table_pk_field->get_table_alias();
160
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
161 161
 
162
-        $SQL = $this->_left_join(
163
-            $other_table,
164
-            $other_table_alias,
165
-            $other_table_pk_field->get_table_column(),
166
-            $join_table_alias,
167
-            $join_table_fk_field_to_other_table->get_table_column(),
168
-            $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
-        ) .
170
-               $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171
-        return $SQL;
172
-    }
162
+		$SQL = $this->_left_join(
163
+			$other_table,
164
+			$other_table_alias,
165
+			$other_table_pk_field->get_table_column(),
166
+			$join_table_alias,
167
+			$join_table_fk_field_to_other_table->get_table_column(),
168
+			$field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
+		) .
170
+			   $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171
+		return $SQL;
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
177
-     *
178
-     * @param EE_Base_Class|int $this_obj_or_id
179
-     * @param EE_Base_Class|int $other_obj_or_id
180
-     * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
181
-     *                                                            checking existing values and for setting new rows if
182
-     *                                                            no exact matches.
183
-     * @return EE_Base_Class
184
-     * @throws \EE_Error
185
-     */
186
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
187
-    {
188
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190
-        // check if such a relationship already exists
191
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
192
-            $this->get_this_model()->get_this_model_name(),
193
-            'ID'
194
-        );
195
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
196
-            $this->get_this_model()->get_this_model_name(),
197
-            'name'
198
-        );
199
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
200
-            $this->get_other_model()->get_this_model_name(),
201
-            'ID'
202
-        );
203
-        $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
204
-            $this->get_other_model()->get_this_model_name(),
205
-            'name'
206
-        );
175
+	/**
176
+	 * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
177
+	 *
178
+	 * @param EE_Base_Class|int $this_obj_or_id
179
+	 * @param EE_Base_Class|int $other_obj_or_id
180
+	 * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
181
+	 *                                                            checking existing values and for setting new rows if
182
+	 *                                                            no exact matches.
183
+	 * @return EE_Base_Class
184
+	 * @throws \EE_Error
185
+	 */
186
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
187
+	{
188
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190
+		// check if such a relationship already exists
191
+		$join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
192
+			$this->get_this_model()->get_this_model_name(),
193
+			'ID'
194
+		);
195
+		$join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
196
+			$this->get_this_model()->get_this_model_name(),
197
+			'name'
198
+		);
199
+		$join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
200
+			$this->get_other_model()->get_this_model_name(),
201
+			'ID'
202
+		);
203
+		$join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
204
+			$this->get_other_model()->get_this_model_name(),
205
+			'name'
206
+		);
207 207
 
208
-        $cols_n_values = array(
209
-            $join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
210
-            $join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
211
-            $join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
212
-            $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
213
-        );
208
+		$cols_n_values = array(
209
+			$join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
210
+			$join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
211
+			$join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
212
+			$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
213
+		);
214 214
 
215
-        // if $where_query exists lets add them to the query_params.
216
-        if (! empty($extra_join_model_fields_n_values)) {
217
-            // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
218
-            // make sure we strip THIS models name from the query param
219
-            $parsed_query = array();
220
-            foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
-                $query_param                = str_replace(
222
-                    $this->get_join_model()->get_this_model_name() . ".",
223
-                    "",
224
-                    $query_param
225
-                );
226
-                $parsed_query[ $query_param ] = $val;
227
-            }
228
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
229
-        }
215
+		// if $where_query exists lets add them to the query_params.
216
+		if (! empty($extra_join_model_fields_n_values)) {
217
+			// make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
218
+			// make sure we strip THIS models name from the query param
219
+			$parsed_query = array();
220
+			foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
+				$query_param                = str_replace(
222
+					$this->get_join_model()->get_this_model_name() . ".",
223
+					"",
224
+					$query_param
225
+				);
226
+				$parsed_query[ $query_param ] = $val;
227
+			}
228
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
229
+		}
230 230
 
231
-        $query_params = array($cols_n_values);
231
+		$query_params = array($cols_n_values);
232 232
 
233 233
 
234
-        $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
235
-        // if there is already an entry in the join table, indicating a relationship, we're done
236
-        // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237
-        // the other tables, use the joining model directly!
238
-        if (! $existing_entry_in_join_table) {
239
-            $this->get_join_model()->insert($cols_n_values);
240
-        }
241
-        return $other_model_obj;
242
-    }
234
+		$existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
235
+		// if there is already an entry in the join table, indicating a relationship, we're done
236
+		// again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237
+		// the other tables, use the joining model directly!
238
+		if (! $existing_entry_in_join_table) {
239
+			$this->get_join_model()->insert($cols_n_values);
240
+		}
241
+		return $other_model_obj;
242
+	}
243 243
 
244 244
 
245
-    /**
246
-     * Deletes any rows in the join table that have foreign keys matching the other model objects specified
247
-     *
248
-     * @param EE_Base_Class|int $this_obj_or_id
249
-     * @param EE_Base_Class|int $other_obj_or_id
250
-     * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
251
-     *                                       values and for removing existing rows if exact matches exist.
252
-     * @return EE_Base_Class
253
-     * @throws \EE_Error
254
-     */
255
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
256
-    {
257
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259
-        // check if such a relationship already exists
260
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
261
-            $this->get_this_model()->get_this_model_name(),
262
-            'ID'
263
-        );
264
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
265
-            $this->get_this_model()->get_this_model_name(),
266
-            'name'
267
-        );
268
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
269
-            $this->get_other_model()->get_this_model_name(),
270
-            'ID'
271
-        );
272
-        $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
273
-            $this->get_other_model()->get_this_model_name(),
274
-            'name'
275
-        );
245
+	/**
246
+	 * Deletes any rows in the join table that have foreign keys matching the other model objects specified
247
+	 *
248
+	 * @param EE_Base_Class|int $this_obj_or_id
249
+	 * @param EE_Base_Class|int $other_obj_or_id
250
+	 * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
251
+	 *                                       values and for removing existing rows if exact matches exist.
252
+	 * @return EE_Base_Class
253
+	 * @throws \EE_Error
254
+	 */
255
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
256
+	{
257
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259
+		// check if such a relationship already exists
260
+		$join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
261
+			$this->get_this_model()->get_this_model_name(),
262
+			'ID'
263
+		);
264
+		$join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
265
+			$this->get_this_model()->get_this_model_name(),
266
+			'name'
267
+		);
268
+		$join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
269
+			$this->get_other_model()->get_this_model_name(),
270
+			'ID'
271
+		);
272
+		$join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
273
+			$this->get_other_model()->get_this_model_name(),
274
+			'name'
275
+		);
276 276
 
277
-        $cols_n_values = array(
278
-            $join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
279
-            $join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
280
-            $join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
281
-            $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
282
-        );
277
+		$cols_n_values = array(
278
+			$join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
279
+			$join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
280
+			$join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
281
+			$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
282
+		);
283 283
 
284
-        // if $where_query exists lets add them to the query_params.
285
-        if (! empty($where_query)) {
286
-            // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
287
-            // make sure we strip THIS models name from the query param
288
-            $parsed_query = array();
289
-            foreach ($where_query as $query_param => $val) {
290
-                $query_param                = str_replace(
291
-                    $this->get_join_model()->get_this_model_name() . ".",
292
-                    "",
293
-                    $query_param
294
-                );
295
-                $parsed_query[ $query_param ] = $val;
296
-            }
297
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
298
-        }
284
+		// if $where_query exists lets add them to the query_params.
285
+		if (! empty($where_query)) {
286
+			// make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
287
+			// make sure we strip THIS models name from the query param
288
+			$parsed_query = array();
289
+			foreach ($where_query as $query_param => $val) {
290
+				$query_param                = str_replace(
291
+					$this->get_join_model()->get_this_model_name() . ".",
292
+					"",
293
+					$query_param
294
+				);
295
+				$parsed_query[ $query_param ] = $val;
296
+			}
297
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
298
+		}
299 299
 
300
-        $this->get_join_model()->delete(array($cols_n_values));
301
-        return $other_model_obj;
302
-    }
300
+		$this->get_join_model()->delete(array($cols_n_values));
301
+		return $other_model_obj;
302
+	}
303 303
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Revision_Relation.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191 191
         foreach ($autosave_relations as $a_r) {
192 192
             $pid = $a_r->parent();
193
-            if (! empty($pid)) {
193
+            if ( ! empty($pid)) {
194 194
                 $parent_ids[] = $pid;
195 195
             } else {
196 196
                 $return_objs[] = $a_r;
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
         }
207 207
 
208 208
         // now we setup the query to get all the parents
209
-        if (! empty($parent_ids)) {
210
-            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
-            $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
209
+        if ( ! empty($parent_ids)) {
210
+            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name().".".$this->get_this_model()->get_primary_key_field()->get_name();
211
+            $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids);
212 212
             $parents                                          = $this->get_other_model()->get_all($query_params);
213 213
         }
214 214
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
             var_dump($this_obj);
244 244
             var_dump($other_obj);/**/
245 245
 
246
-            if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
246
+            if ( ! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247 247
                 // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248 248
                 $has_parent_obj = $this->get_other_model()->get_one(array(
249 249
                     array(
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                     $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260 260
                     $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261 261
 
262
-                    if (! $remove_relation) {
262
+                    if ( ! $remove_relation) {
263 263
                         $other_obj->save();
264 264
                         return array($other_obj);
265 265
                     } elseif ($remove_relation && ! $this->_blocking_delete) {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288 288
         } else {
289 289
             // we only need to do the below IF this is not a remove relation
290
-            if (! $remove_relation) {
290
+            if ( ! $remove_relation) {
291 291
                 // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292 292
                 // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293 293
                 $existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
Please login to merge, or discard this patch.
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -12,303 +12,303 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for
17
-     * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this
18
-     * value).  The _primary_cpt_field is what is equivalent to the post_id field on a cpt join.
19
-     *
20
-     * @var string
21
-     */
22
-    private $_primary_cpt_field;
23
-
24
-
25
-    /**
26
-     * This is what field serves as the "parent" column that is linked with whatever the main model's calling this
27
-     * relation has as a primary key.  In other words EEM_Event has 'Datetime' => new
28
-     * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent').  That means that in the EEM_Datetime model the
29
-     * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the
30
-     * primary key in the other model (EEM_Datetime).
31
-     *
32
-     * @var string
33
-     */
34
-    private $_parent_pk_relation_field;
35
-
36
-
37
-    /**
38
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
39
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
40
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
41
-     * related models across the relation, and add-and-remove the relationships.
42
-     *
43
-     * @param string  $primary_cpt_field             See property description for details
44
-     * @param string  $parent_pk_relation_field      This is the field that is "connected" to the $primary_cpt_field.
45
-     *                                               See property desc for details.
46
-     * @param boolean $block_deletes                 For this type of relation, we block by default. If there are
47
-     *                                               related models across this relation, block (prevent and add an
48
-     *                                               error) the deletion of this model
49
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
50
-     *                                               default
51
-     */
52
-    public function __construct(
53
-        $primary_cpt_field,
54
-        $parent_pk_relation_field,
55
-        $block_deletes = true,
56
-        $blocking_delete_error_message = null
57
-    ) {
58
-        $this->_primary_cpt_field        = $primary_cpt_field;
59
-        $this->_parent_pk_relation_field = $parent_pk_relation_field;
60
-        parent::__construct($block_deletes, $blocking_delete_error_message);
61
-    }
62
-
63
-
64
-    /**
65
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
66
-     * you like.
67
-     *
68
-     * @param EE_Base_Class|int $this_obj_or_id
69
-     * @param EE_Base_Class|int $other_obj_or_id
70
-     * @param array             $extra_join_model_fields_n_values
71
-     * @return \EE_Base_Class
72
-     * @throws \EE_Error
73
-     */
74
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
-    {
76
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
78
-
79
-        // handle possible revisions
80
-        $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj);
81
-
82
-        // if is array, then we've already done the add_relation so let's get out
83
-        if (is_array($other_model_obj)) {
84
-            return $other_model_obj[0];
85
-        }
86
-        // find the field on the other model which is a foreign key to this model
87
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
88
-        // set that field on the other model to this model's ID
89
-        $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
90
-        $other_model_obj->save();
91
-        return $other_model_obj;
92
-    }
93
-
94
-
95
-    /**
96
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object
97
-     *
98
-     * @param EE_Base_Class|int $this_obj_or_id
99
-     * @param EE_Base_Class|int $other_obj_or_id
100
-     * @param array             $where_query
101
-     * @return \EE_Base_Class
102
-     * @throws \EE_Error
103
-     */
104
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
105
-    {
106
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id);
107
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
108
-        // handle possible revisions
109
-        $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true);
110
-
111
-
112
-        // if is array, then we've already done the add_relation so let's get out
113
-        if (is_array($other_model_obj)) {
114
-            return $other_model_obj[0];
115
-        }
116
-
117
-        // find the field on the other model which is a foreign key to this model
118
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
119
-
120
-
121
-        // set that field on the other model to this model's ID
122
-        if ($this->_blocking_delete) {
123
-            $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
124
-            $other_model_obj->save();
125
-        } else {
126
-            $other_model_obj->delete();
127
-            $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
128
-            return $other_model_obj;
129
-        }
130
-        return $other_model_obj;
131
-    }
132
-
133
-
134
-    /**
135
-     * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions
136
-     * in here.
137
-     *
138
-     * @param  EE_Base_Class|int $model_object_or_id
139
-     * @param  array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
140
-     * @param  boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
141
-     * @return EE_Base_Class[]
142
-     * @throws \EE_Error
143
-     */
144
-    public function get_all_related(
145
-        $model_object_or_id,
146
-        $query_params = array(),
147
-        $values_already_prepared_by_model_object = false
148
-    ) {
149
-        if ($values_already_prepared_by_model_object !== false) {
150
-            EE_Error::doing_it_wrong(
151
-                'EE_Model_Relation_Base::get_all_related',
152
-                esc_html__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
153
-                '4.8.1'
154
-            );
155
-        }
156
-
157
-        // if this is an autosave then we're going to get things differently
158
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
159
-            return $this->_do_autosave_get_all($model_object_or_id, $query_params);
160
-        }
161
-
162
-        return parent::get_all_related($model_object_or_id, $query_params);
163
-    }
164
-
165
-
166
-    /**
167
-     * If we're in the midst of an autosave then we're going to do things a bit differently than the usual
168
-     * get_all_related (commenting within).  For description of params see the get_all_related() comments
169
-     *
170
-     * @access protected
171
-     * @param      $model_object_or_id
172
-     * @param      $query_params
173
-     * @param bool $deprecated
174
-     * @return \EE_Base_Class[]
175
-     * @throws \EE_Error
176
-     */
177
-    protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false)
178
-    {
179
-
180
-        // first we check if the post_id for the incoming query is for an autosave.  If it isn't that's what we want!
181
-        $model_object_id = $this->_get_model_object_id($model_object_or_id);
182
-
183
-        $autosave  = wp_get_post_autosave($model_object_id);
184
-        $id_to_use = $autosave ? $autosave->ID : $model_object_id;
185
-
186
-        $autosave_relations = parent::get_all_related($id_to_use, $query_params);
187
-        $parent_ids         = $parents = array();
188
-        $return_objs        = array();
189
-
190
-        // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191
-        foreach ($autosave_relations as $a_r) {
192
-            $pid = $a_r->parent();
193
-            if (! empty($pid)) {
194
-                $parent_ids[] = $pid;
195
-            } else {
196
-                $return_objs[] = $a_r;
197
-            }
198
-        }
199
-
200
-        // we have to make sure we also include the ORIGINAL values
201
-        $originals = parent::get_all_related($model_object_or_id, $query_params);
202
-
203
-        // merge $originals with $return_objs
204
-        if ($originals) {
205
-            $return_objs = array_merge($originals, $return_objs);
206
-        }
207
-
208
-        // now we setup the query to get all the parents
209
-        if (! empty($parent_ids)) {
210
-            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
-            $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
212
-            $parents                                          = $this->get_other_model()->get_all($query_params);
213
-        }
214
-
215
-        // var_dump($parents);
216
-
217
-
218
-        // now merge parents with our current $return_objs and send back
219
-        return array_merge($parents, $return_objs);
220
-    }
221
-
222
-
223
-    /**
224
-     * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it
225
-     * is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS
226
-     * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is
227
-     * sometime delayed if the object is created/saved first by the autosave)
228
-     *
229
-     * @param  EE_Base_Class $this_obj
230
-     * @param  EE_Base_Class $other_obj
231
-     * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
232
-     * @return EE_Base_Class. ($other_obj);
233
-     * @throws \EE_Error
234
-     */
235
-    protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false)
236
-    {
237
-        $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
238
-        // now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
239
-        if ($this_obj->post_type() === 'revision') {
240
-            // first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
241
-            $parent_evt_id = $this_obj->parent();
242
-            /*var_dump($parent_evt_id);
15
+	/**
16
+	 * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for
17
+	 * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this
18
+	 * value).  The _primary_cpt_field is what is equivalent to the post_id field on a cpt join.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	private $_primary_cpt_field;
23
+
24
+
25
+	/**
26
+	 * This is what field serves as the "parent" column that is linked with whatever the main model's calling this
27
+	 * relation has as a primary key.  In other words EEM_Event has 'Datetime' => new
28
+	 * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent').  That means that in the EEM_Datetime model the
29
+	 * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the
30
+	 * primary key in the other model (EEM_Datetime).
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $_parent_pk_relation_field;
35
+
36
+
37
+	/**
38
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
39
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
40
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
41
+	 * related models across the relation, and add-and-remove the relationships.
42
+	 *
43
+	 * @param string  $primary_cpt_field             See property description for details
44
+	 * @param string  $parent_pk_relation_field      This is the field that is "connected" to the $primary_cpt_field.
45
+	 *                                               See property desc for details.
46
+	 * @param boolean $block_deletes                 For this type of relation, we block by default. If there are
47
+	 *                                               related models across this relation, block (prevent and add an
48
+	 *                                               error) the deletion of this model
49
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
50
+	 *                                               default
51
+	 */
52
+	public function __construct(
53
+		$primary_cpt_field,
54
+		$parent_pk_relation_field,
55
+		$block_deletes = true,
56
+		$blocking_delete_error_message = null
57
+	) {
58
+		$this->_primary_cpt_field        = $primary_cpt_field;
59
+		$this->_parent_pk_relation_field = $parent_pk_relation_field;
60
+		parent::__construct($block_deletes, $blocking_delete_error_message);
61
+	}
62
+
63
+
64
+	/**
65
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
66
+	 * you like.
67
+	 *
68
+	 * @param EE_Base_Class|int $this_obj_or_id
69
+	 * @param EE_Base_Class|int $other_obj_or_id
70
+	 * @param array             $extra_join_model_fields_n_values
71
+	 * @return \EE_Base_Class
72
+	 * @throws \EE_Error
73
+	 */
74
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
+	{
76
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
78
+
79
+		// handle possible revisions
80
+		$other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj);
81
+
82
+		// if is array, then we've already done the add_relation so let's get out
83
+		if (is_array($other_model_obj)) {
84
+			return $other_model_obj[0];
85
+		}
86
+		// find the field on the other model which is a foreign key to this model
87
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
88
+		// set that field on the other model to this model's ID
89
+		$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
90
+		$other_model_obj->save();
91
+		return $other_model_obj;
92
+	}
93
+
94
+
95
+	/**
96
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object
97
+	 *
98
+	 * @param EE_Base_Class|int $this_obj_or_id
99
+	 * @param EE_Base_Class|int $other_obj_or_id
100
+	 * @param array             $where_query
101
+	 * @return \EE_Base_Class
102
+	 * @throws \EE_Error
103
+	 */
104
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
105
+	{
106
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id);
107
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
108
+		// handle possible revisions
109
+		$other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true);
110
+
111
+
112
+		// if is array, then we've already done the add_relation so let's get out
113
+		if (is_array($other_model_obj)) {
114
+			return $other_model_obj[0];
115
+		}
116
+
117
+		// find the field on the other model which is a foreign key to this model
118
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
119
+
120
+
121
+		// set that field on the other model to this model's ID
122
+		if ($this->_blocking_delete) {
123
+			$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
124
+			$other_model_obj->save();
125
+		} else {
126
+			$other_model_obj->delete();
127
+			$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
128
+			return $other_model_obj;
129
+		}
130
+		return $other_model_obj;
131
+	}
132
+
133
+
134
+	/**
135
+	 * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions
136
+	 * in here.
137
+	 *
138
+	 * @param  EE_Base_Class|int $model_object_or_id
139
+	 * @param  array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
140
+	 * @param  boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
141
+	 * @return EE_Base_Class[]
142
+	 * @throws \EE_Error
143
+	 */
144
+	public function get_all_related(
145
+		$model_object_or_id,
146
+		$query_params = array(),
147
+		$values_already_prepared_by_model_object = false
148
+	) {
149
+		if ($values_already_prepared_by_model_object !== false) {
150
+			EE_Error::doing_it_wrong(
151
+				'EE_Model_Relation_Base::get_all_related',
152
+				esc_html__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
153
+				'4.8.1'
154
+			);
155
+		}
156
+
157
+		// if this is an autosave then we're going to get things differently
158
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
159
+			return $this->_do_autosave_get_all($model_object_or_id, $query_params);
160
+		}
161
+
162
+		return parent::get_all_related($model_object_or_id, $query_params);
163
+	}
164
+
165
+
166
+	/**
167
+	 * If we're in the midst of an autosave then we're going to do things a bit differently than the usual
168
+	 * get_all_related (commenting within).  For description of params see the get_all_related() comments
169
+	 *
170
+	 * @access protected
171
+	 * @param      $model_object_or_id
172
+	 * @param      $query_params
173
+	 * @param bool $deprecated
174
+	 * @return \EE_Base_Class[]
175
+	 * @throws \EE_Error
176
+	 */
177
+	protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false)
178
+	{
179
+
180
+		// first we check if the post_id for the incoming query is for an autosave.  If it isn't that's what we want!
181
+		$model_object_id = $this->_get_model_object_id($model_object_or_id);
182
+
183
+		$autosave  = wp_get_post_autosave($model_object_id);
184
+		$id_to_use = $autosave ? $autosave->ID : $model_object_id;
185
+
186
+		$autosave_relations = parent::get_all_related($id_to_use, $query_params);
187
+		$parent_ids         = $parents = array();
188
+		$return_objs        = array();
189
+
190
+		// k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191
+		foreach ($autosave_relations as $a_r) {
192
+			$pid = $a_r->parent();
193
+			if (! empty($pid)) {
194
+				$parent_ids[] = $pid;
195
+			} else {
196
+				$return_objs[] = $a_r;
197
+			}
198
+		}
199
+
200
+		// we have to make sure we also include the ORIGINAL values
201
+		$originals = parent::get_all_related($model_object_or_id, $query_params);
202
+
203
+		// merge $originals with $return_objs
204
+		if ($originals) {
205
+			$return_objs = array_merge($originals, $return_objs);
206
+		}
207
+
208
+		// now we setup the query to get all the parents
209
+		if (! empty($parent_ids)) {
210
+			$query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
+			$query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
212
+			$parents                                          = $this->get_other_model()->get_all($query_params);
213
+		}
214
+
215
+		// var_dump($parents);
216
+
217
+
218
+		// now merge parents with our current $return_objs and send back
219
+		return array_merge($parents, $return_objs);
220
+	}
221
+
222
+
223
+	/**
224
+	 * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it
225
+	 * is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS
226
+	 * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is
227
+	 * sometime delayed if the object is created/saved first by the autosave)
228
+	 *
229
+	 * @param  EE_Base_Class $this_obj
230
+	 * @param  EE_Base_Class $other_obj
231
+	 * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
232
+	 * @return EE_Base_Class. ($other_obj);
233
+	 * @throws \EE_Error
234
+	 */
235
+	protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false)
236
+	{
237
+		$pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
238
+		// now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
239
+		if ($this_obj->post_type() === 'revision') {
240
+			// first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
241
+			$parent_evt_id = $this_obj->parent();
242
+			/*var_dump($parent_evt_id);
243 243
             var_dump($this_obj);
244 244
             var_dump($other_obj);/**/
245 245
 
246
-            if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247
-                // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248
-                $has_parent_obj = $this->get_other_model()->get_one(array(
249
-                    array(
250
-                        $this->_parent_pk_relation_field => $other_obj->ID(),
251
-                        $this->_primary_cpt_field        => $this_obj->ID(),
252
-                    ),
253
-                ));
254
-
255
-                if ($has_parent_obj) {
256
-                    // this makes sure the update on the current obj happens to the revision's row NOT the parent row.
257
-
258
-                    $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
259
-                    $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261
-
262
-                    if (! $remove_relation) {
263
-                        $other_obj->save();
264
-                        return array($other_obj);
265
-                    } elseif ($remove_relation && ! $this->_blocking_delete) {
266
-                        $other_obj->delete();
267
-                        $other_obj->set($this->_parent_pk_relation_field, null, true);
268
-                        return array($other_obj);
269
-                    }
270
-                } else {
271
-                    $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
272
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
273
-                    $other_obj->set(
274
-                        $pk_on_related_model,
275
-                        null,
276
-                        true
277
-                    ); // ensure we create a new row for the autosave with parent id the same as the incoming ID.
278
-                    $other_obj->save(); // make sure we insert.
279
-                    return array($other_obj);
280
-                }
281
-            }
282
-
283
-            // var_dump('what makes it here');
284
-            // var_dump($other_obj);
285
-            // the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
286
-
287
-            // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288
-        } else {
289
-            // we only need to do the below IF this is not a remove relation
290
-            if (! $remove_relation) {
291
-                // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292
-                // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293
-                $existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
294
-                $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null;
295
-
296
-                if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
297
-                    // yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
298
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
299
-                    $other_obj->save();
300
-
301
-                    // now create a new other_obj and fill with details from existing object
302
-                    $new_obj = $other_obj;
303
-                    $new_obj->set($this->_primary_cpt_field, $potential_revision_id);
304
-                    $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
305
-                    $new_obj->set($pk_on_related_model, null);
306
-                    $new_obj->save();
307
-                    return array($new_obj);
308
-                }
309
-            }
310
-        }
311
-
312
-        return $other_obj;
313
-    }
246
+			if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247
+				// let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248
+				$has_parent_obj = $this->get_other_model()->get_one(array(
249
+					array(
250
+						$this->_parent_pk_relation_field => $other_obj->ID(),
251
+						$this->_primary_cpt_field        => $this_obj->ID(),
252
+					),
253
+				));
254
+
255
+				if ($has_parent_obj) {
256
+					// this makes sure the update on the current obj happens to the revision's row NOT the parent row.
257
+
258
+					$other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
259
+					$other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261
+
262
+					if (! $remove_relation) {
263
+						$other_obj->save();
264
+						return array($other_obj);
265
+					} elseif ($remove_relation && ! $this->_blocking_delete) {
266
+						$other_obj->delete();
267
+						$other_obj->set($this->_parent_pk_relation_field, null, true);
268
+						return array($other_obj);
269
+					}
270
+				} else {
271
+					$other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
272
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
273
+					$other_obj->set(
274
+						$pk_on_related_model,
275
+						null,
276
+						true
277
+					); // ensure we create a new row for the autosave with parent id the same as the incoming ID.
278
+					$other_obj->save(); // make sure we insert.
279
+					return array($other_obj);
280
+				}
281
+			}
282
+
283
+			// var_dump('what makes it here');
284
+			// var_dump($other_obj);
285
+			// the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
286
+
287
+			// the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288
+		} else {
289
+			// we only need to do the below IF this is not a remove relation
290
+			if (! $remove_relation) {
291
+				// okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292
+				// the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293
+				$existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
294
+				$potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null;
295
+
296
+				if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
297
+					// yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
298
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
299
+					$other_obj->save();
300
+
301
+					// now create a new other_obj and fill with details from existing object
302
+					$new_obj = $other_obj;
303
+					$new_obj->set($this->_primary_cpt_field, $potential_revision_id);
304
+					$new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
305
+					$new_obj->set($pk_on_related_model, null);
306
+					$new_obj->save();
307
+					return array($new_obj);
308
+				}
309
+			}
310
+		}
311
+
312
+		return $other_obj;
313
+	}
314 314
 }
Please login to merge, or discard this patch.