Completed
Branch master (44537d)
by
unknown
14:30 queued 10:03
created
core/db_models/EEM_Answer.model.php 2 patches
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -9,197 +9,197 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Answer extends EEM_Base
11 11
 {
12
-    /**
13
-     * private instance of the EEM_Answer object
14
-     *
15
-     * @type EEM_Answer
16
-     */
17
-    protected static $_instance = null;
12
+	/**
13
+	 * private instance of the EEM_Answer object
14
+	 *
15
+	 * @type EEM_Answer
16
+	 */
17
+	protected static $_instance = null;
18 18
 
19
-    /**
20
-     * Mapping from system question ids to attendee field names
21
-     *
22
-     * @type array
23
-     * @deprecated since version 4.8.8
24
-     */
25
-    protected $_question_id_to_att_field_map = [
26
-        EEM_Attendee::fname_question_id    => 'ATT_fname',
27
-        EEM_Attendee::lname_question_id    => 'ATT_lname',
28
-        EEM_Attendee::email_question_id    => 'ATT_email',
29
-        EEM_Attendee::address_question_id  => 'ATT_address',
30
-        EEM_Attendee::address2_question_id => 'ATT_address2',
31
-        EEM_Attendee::city_question_id     => 'ATT_city',
32
-        EEM_Attendee::state_question_id    => 'STA_ID',
33
-        EEM_Attendee::country_question_id  => 'CNT_ISO',
34
-        EEM_Attendee::zip_question_id      => 'ATT_zip',
35
-        EEM_Attendee::phone_question_id    => 'ATT_phone',
36
-    ];
19
+	/**
20
+	 * Mapping from system question ids to attendee field names
21
+	 *
22
+	 * @type array
23
+	 * @deprecated since version 4.8.8
24
+	 */
25
+	protected $_question_id_to_att_field_map = [
26
+		EEM_Attendee::fname_question_id    => 'ATT_fname',
27
+		EEM_Attendee::lname_question_id    => 'ATT_lname',
28
+		EEM_Attendee::email_question_id    => 'ATT_email',
29
+		EEM_Attendee::address_question_id  => 'ATT_address',
30
+		EEM_Attendee::address2_question_id => 'ATT_address2',
31
+		EEM_Attendee::city_question_id     => 'ATT_city',
32
+		EEM_Attendee::state_question_id    => 'STA_ID',
33
+		EEM_Attendee::country_question_id  => 'CNT_ISO',
34
+		EEM_Attendee::zip_question_id      => 'ATT_zip',
35
+		EEM_Attendee::phone_question_id    => 'ATT_phone',
36
+	];
37 37
 
38 38
 
39
-    /**
40
-     * @param string|null $timezone
41
-     * @throws EE_Error
42
-     */
43
-    protected function __construct(?string $timezone = '')
44
-    {
45
-        $this->singular_item           = esc_html__('Answer', 'event_espresso');
46
-        $this->plural_item             = esc_html__('Answers', 'event_espresso');
47
-        $this->_tables                 = [
48
-            'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID'),
49
-        ];
50
-        $this->_fields                 = [
51
-            'Answer' => [
52
-                'ANS_ID'    => new EE_Primary_Key_Int_Field('ANS_ID', esc_html__('Answer ID', 'event_espresso')),
53
-                'REG_ID'    => new EE_Foreign_Key_Int_Field(
54
-                    'REG_ID',
55
-                    esc_html__('Registration ID', 'event_espresso'),
56
-                    false,
57
-                    0,
58
-                    'Registration'
59
-                ),
60
-                'QST_ID'    => new EE_Foreign_Key_Int_Field(
61
-                    'QST_ID',
62
-                    esc_html__('Question ID', 'event_espresso'),
63
-                    false,
64
-                    0,
65
-                    'Question'
66
-                ),
67
-                'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field(
68
-                    'ANS_value',
69
-                    esc_html__('Answer Value', 'event_espresso'),
70
-                    false,
71
-                    ''
72
-                ),
73
-            ],
74
-        ];
75
-        $this->_model_relations        = [
76
-            'Registration' => new EE_Belongs_To_Relation(),
77
-            'Question'     => new EE_Belongs_To_Relation(),
78
-        ];
79
-        $this->_model_chain_to_wp_user = 'Registration.Event';
80
-        $this->_caps_slug              = 'registrations';
81
-        parent::__construct($timezone);
82
-    }
39
+	/**
40
+	 * @param string|null $timezone
41
+	 * @throws EE_Error
42
+	 */
43
+	protected function __construct(?string $timezone = '')
44
+	{
45
+		$this->singular_item           = esc_html__('Answer', 'event_espresso');
46
+		$this->plural_item             = esc_html__('Answers', 'event_espresso');
47
+		$this->_tables                 = [
48
+			'Answer' => new EE_Primary_Table('esp_answer', 'ANS_ID'),
49
+		];
50
+		$this->_fields                 = [
51
+			'Answer' => [
52
+				'ANS_ID'    => new EE_Primary_Key_Int_Field('ANS_ID', esc_html__('Answer ID', 'event_espresso')),
53
+				'REG_ID'    => new EE_Foreign_Key_Int_Field(
54
+					'REG_ID',
55
+					esc_html__('Registration ID', 'event_espresso'),
56
+					false,
57
+					0,
58
+					'Registration'
59
+				),
60
+				'QST_ID'    => new EE_Foreign_Key_Int_Field(
61
+					'QST_ID',
62
+					esc_html__('Question ID', 'event_espresso'),
63
+					false,
64
+					0,
65
+					'Question'
66
+				),
67
+				'ANS_value' => new EE_Maybe_Serialized_Simple_HTML_Field(
68
+					'ANS_value',
69
+					esc_html__('Answer Value', 'event_espresso'),
70
+					false,
71
+					''
72
+				),
73
+			],
74
+		];
75
+		$this->_model_relations        = [
76
+			'Registration' => new EE_Belongs_To_Relation(),
77
+			'Question'     => new EE_Belongs_To_Relation(),
78
+		];
79
+		$this->_model_chain_to_wp_user = 'Registration.Event';
80
+		$this->_caps_slug              = 'registrations';
81
+		parent::__construct($timezone);
82
+	}
83 83
 
84 84
 
85
-    /**
86
-     * Gets the string answer to the question for this registration (it could either be stored
87
-     * on the attendee or in the answer table. This function finds its value regardless)
88
-     *
89
-     * @param EE_Registration $registration
90
-     * @param int             $question_id
91
-     * @param boolean         $pretty_answer whether to call 'pretty_value' or just 'value'
92
-     * @return string
93
-     */
94
-    public function get_answer_value_to_question(
95
-        EE_Registration $registration,
96
-        $question_id = null,
97
-        $pretty_answer = false
98
-    ) {
99
-        $value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
100
-        if ($value === null) {
101
-            $answer_obj = $this->get_registration_question_answer_object($registration, $question_id);
102
-            if ($answer_obj instanceof EE_Answer) {
103
-                if ($pretty_answer) {
104
-                    $value = $answer_obj->pretty_value();
105
-                } else {
106
-                    $value = $answer_obj->value();
107
-                }
108
-            }
109
-        }
110
-        return apply_filters(
111
-            'FHEE__EEM_Answer__get_answer_value_to_question__answer_value',
112
-            $value,
113
-            $registration,
114
-            $question_id
115
-        );
116
-    }
85
+	/**
86
+	 * Gets the string answer to the question for this registration (it could either be stored
87
+	 * on the attendee or in the answer table. This function finds its value regardless)
88
+	 *
89
+	 * @param EE_Registration $registration
90
+	 * @param int             $question_id
91
+	 * @param boolean         $pretty_answer whether to call 'pretty_value' or just 'value'
92
+	 * @return string
93
+	 */
94
+	public function get_answer_value_to_question(
95
+		EE_Registration $registration,
96
+		$question_id = null,
97
+		$pretty_answer = false
98
+	) {
99
+		$value = $this->get_attendee_property_answer_value($registration, $question_id, $pretty_answer);
100
+		if ($value === null) {
101
+			$answer_obj = $this->get_registration_question_answer_object($registration, $question_id);
102
+			if ($answer_obj instanceof EE_Answer) {
103
+				if ($pretty_answer) {
104
+					$value = $answer_obj->pretty_value();
105
+				} else {
106
+					$value = $answer_obj->value();
107
+				}
108
+			}
109
+		}
110
+		return apply_filters(
111
+			'FHEE__EEM_Answer__get_answer_value_to_question__answer_value',
112
+			$value,
113
+			$registration,
114
+			$question_id
115
+		);
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * Gets the EE_Answer object for the question for this registration (if it exists)
121
-     *
122
-     * @param EE_Registration $registration
123
-     * @param int             $question_id
124
-     * @return EE_Answer
125
-     */
126
-    public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null)
127
-    {
128
-        $answer_obj = $this->get_one([['QST_ID' => $question_id, 'REG_ID' => $registration->ID()]]);
129
-        return apply_filters(
130
-            'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj',
131
-            $answer_obj,
132
-            $registration,
133
-            $question_id
134
-        );
135
-    }
119
+	/**
120
+	 * Gets the EE_Answer object for the question for this registration (if it exists)
121
+	 *
122
+	 * @param EE_Registration $registration
123
+	 * @param int             $question_id
124
+	 * @return EE_Answer
125
+	 */
126
+	public function get_registration_question_answer_object(EE_Registration $registration, $question_id = null)
127
+	{
128
+		$answer_obj = $this->get_one([['QST_ID' => $question_id, 'REG_ID' => $registration->ID()]]);
129
+		return apply_filters(
130
+			'FHEE__EEM_Answer__get_registration_question_answer_object__answer_obj',
131
+			$answer_obj,
132
+			$registration,
133
+			$question_id
134
+		);
135
+	}
136 136
 
137 137
 
138
-    /**
139
-     * Gets the string answer to the question for this registration's attendee
140
-     *
141
-     * @param EE_Registration $registration
142
-     * @param int|string      $question_system_id if an INT this is understood to be the question's ID; if a string
143
-     *                                            then it should be its QST_system value. Passing in the QST_system
144
-     *                                            value is more efficient
145
-     * @param boolean         $pretty_answer
146
-     * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or
147
-     *                                            QST_system for a question corresponding to an attendee field, returns
148
-     *                                            null)
149
-     * @throws EE_Error
150
-     * @throws ReflectionException
151
-     */
152
-    public function get_attendee_property_answer_value(
153
-        EE_Registration $registration,
154
-        $question_system_id = null,
155
-        $pretty_answer = false
156
-    ) {
157
-        $value = null;
158
-        // backward compat: we still want to find the question's ID
159
-        if (is_numeric($question_system_id)) {
160
-            // find this question's QST_system value
161
-            $question_id        = $question_system_id;
162
-            $question_system_id = EEM_Question::instance()->get_var([['QST_ID' => $question_system_id]], 'QST_system');
163
-        } else {
164
-            $question_id = (int) EEM_Question::instance()->get_var([['QST_system' => $question_system_id]], 'QST_ID');
165
-        }
166
-        // only bother checking if the registration has an attendee
167
-        if ($registration->attendee() instanceof EE_Attendee) {
168
-            $field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
169
-            if ($field_name) {
170
-                if ($pretty_answer) {
171
-                    if ($field_name === 'STA_ID') {
172
-                        $state = $registration->attendee()->state_obj();
173
-                        $value = $state instanceof EE_State
174
-                            ? $state->name()
175
-                            : sprintf(
176
-                                esc_html__('Unknown State (%s)', 'event_espresso'),
177
-                                $registration->attendee()->state_ID()
178
-                            );
179
-                    } elseif ($field_name === 'CNT_ISO') {
180
-                        $country = $registration->attendee()->country_obj();
181
-                        $value   = $country instanceof EE_Country
182
-                            ? $country->name()
183
-                            : sprintf(
184
-                                esc_html__('Unknown Country (%s)', "event_espresso"),
185
-                                $registration->attendee()->country_ID()
186
-                            );
187
-                    } else {
188
-                        $value = $registration->attendee()->get_pretty($field_name);
189
-                    }
190
-                    // if field name is blank, leave the value as null too
191
-                } else {
192
-                    $value = $registration->attendee()->get($field_name);
193
-                }
194
-            }
195
-            // if no field was found, leave value blank
196
-        }
197
-        return apply_filters(
198
-            'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value',
199
-            $value,
200
-            $registration,
201
-            $question_id,
202
-            $question_system_id
203
-        );
204
-    }
138
+	/**
139
+	 * Gets the string answer to the question for this registration's attendee
140
+	 *
141
+	 * @param EE_Registration $registration
142
+	 * @param int|string      $question_system_id if an INT this is understood to be the question's ID; if a string
143
+	 *                                            then it should be its QST_system value. Passing in the QST_system
144
+	 *                                            value is more efficient
145
+	 * @param boolean         $pretty_answer
146
+	 * @return string|null (if the registration has no attendee, or the question_system_id is not a QST_ID or
147
+	 *                                            QST_system for a question corresponding to an attendee field, returns
148
+	 *                                            null)
149
+	 * @throws EE_Error
150
+	 * @throws ReflectionException
151
+	 */
152
+	public function get_attendee_property_answer_value(
153
+		EE_Registration $registration,
154
+		$question_system_id = null,
155
+		$pretty_answer = false
156
+	) {
157
+		$value = null;
158
+		// backward compat: we still want to find the question's ID
159
+		if (is_numeric($question_system_id)) {
160
+			// find this question's QST_system value
161
+			$question_id        = $question_system_id;
162
+			$question_system_id = EEM_Question::instance()->get_var([['QST_ID' => $question_system_id]], 'QST_system');
163
+		} else {
164
+			$question_id = (int) EEM_Question::instance()->get_var([['QST_system' => $question_system_id]], 'QST_ID');
165
+		}
166
+		// only bother checking if the registration has an attendee
167
+		if ($registration->attendee() instanceof EE_Attendee) {
168
+			$field_name = EEM_Attendee::instance()->get_attendee_field_for_system_question($question_system_id);
169
+			if ($field_name) {
170
+				if ($pretty_answer) {
171
+					if ($field_name === 'STA_ID') {
172
+						$state = $registration->attendee()->state_obj();
173
+						$value = $state instanceof EE_State
174
+							? $state->name()
175
+							: sprintf(
176
+								esc_html__('Unknown State (%s)', 'event_espresso'),
177
+								$registration->attendee()->state_ID()
178
+							);
179
+					} elseif ($field_name === 'CNT_ISO') {
180
+						$country = $registration->attendee()->country_obj();
181
+						$value   = $country instanceof EE_Country
182
+							? $country->name()
183
+							: sprintf(
184
+								esc_html__('Unknown Country (%s)', "event_espresso"),
185
+								$registration->attendee()->country_ID()
186
+							);
187
+					} else {
188
+						$value = $registration->attendee()->get_pretty($field_name);
189
+					}
190
+					// if field name is blank, leave the value as null too
191
+				} else {
192
+					$value = $registration->attendee()->get($field_name);
193
+				}
194
+			}
195
+			// if no field was found, leave value blank
196
+		}
197
+		return apply_filters(
198
+			'FHEE__EEM_Answer__get_attendee_question_answer_value__answer_value',
199
+			$value,
200
+			$registration,
201
+			$question_id,
202
+			$question_system_id
203
+		);
204
+	}
205 205
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
72 72
                 ),
73 73
             ],
74 74
         ];
75
-        $this->_model_relations        = [
75
+        $this->_model_relations = [
76 76
             'Registration' => new EE_Belongs_To_Relation(),
77 77
             'Question'     => new EE_Belongs_To_Relation(),
78 78
         ];
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Message_Template.model.php 2 patches
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -11,138 +11,138 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Event_Message_Template extends EEM_Base
13 13
 {
14
-    // private instance of the EEM_Event_Message_Template object
15
-    protected static $_instance = null;
14
+	// private instance of the EEM_Event_Message_Template object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18
-    /**
19
-     * protected constructor to prevent direct creation
20
-     *
21
-     * @param string|null $timezone
22
-     * @throws EE_Error
23
-     */
24
-    protected function __construct(?string $timezone = '')
25
-    {
26
-        $this->singular_item = esc_html__('Event Message Template', 'event_espresso');
27
-        $this->plural_item   = esc_html__('Event Message Templates', 'event_espresso');
18
+	/**
19
+	 * protected constructor to prevent direct creation
20
+	 *
21
+	 * @param string|null $timezone
22
+	 * @throws EE_Error
23
+	 */
24
+	protected function __construct(?string $timezone = '')
25
+	{
26
+		$this->singular_item = esc_html__('Event Message Template', 'event_espresso');
27
+		$this->plural_item   = esc_html__('Event Message Templates', 'event_espresso');
28 28
 
29
-        $this->_tables                                                  = [
30
-            'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'),
31
-        ];
32
-        $this->_fields                                                  = [
33
-            'Event_Message_Template' => [
34
-                'EMT_ID' => new EE_Primary_Key_Int_Field(
35
-                    'EMT_ID',
36
-                    esc_html__('Event Message Template ID', 'event_espresso')
37
-                ),
38
-                'EVT_ID' => new EE_Foreign_Key_Int_Field(
39
-                    'EVT_ID',
40
-                    esc_html__('The ID to the Event', 'event_espresso'),
41
-                    false,
42
-                    0,
43
-                    'Event'
44
-                ),
45
-                'GRP_ID' => new EE_Foreign_Key_Int_Field(
46
-                    'GRP_ID',
47
-                    esc_html__('The ID to the Message Template Group', 'event_espresso'),
48
-                    false,
49
-                    0,
50
-                    'Message_Template_Group'
51
-                ),
52
-            ],
53
-        ];
54
-        $this->_model_relations                                         = [
55
-            'Event'                  => new EE_Belongs_To_Relation(),
56
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
57
-        ];
58
-        $path_to_event                                                  = 'Event';
59
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
60
-            new EE_Restriction_Generator_Event_Related_Public(
61
-                $path_to_event
62
-            );
63
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
64
-            new EE_Restriction_Generator_Event_Related_Protected(
65
-                $path_to_event
66
-            );
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
68
-            new EE_Restriction_Generator_Event_Related_Protected(
69
-                $path_to_event
70
-            );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
72
-            new EE_Restriction_Generator_Event_Related_Protected(
73
-                $path_to_event,
74
-                EEM_Base::caps_edit
75
-            );
76
-        parent::__construct($timezone);
77
-    }
29
+		$this->_tables                                                  = [
30
+			'Event_Message_Template' => new EE_Primary_Table('esp_event_message_template', 'EMT_ID'),
31
+		];
32
+		$this->_fields                                                  = [
33
+			'Event_Message_Template' => [
34
+				'EMT_ID' => new EE_Primary_Key_Int_Field(
35
+					'EMT_ID',
36
+					esc_html__('Event Message Template ID', 'event_espresso')
37
+				),
38
+				'EVT_ID' => new EE_Foreign_Key_Int_Field(
39
+					'EVT_ID',
40
+					esc_html__('The ID to the Event', 'event_espresso'),
41
+					false,
42
+					0,
43
+					'Event'
44
+				),
45
+				'GRP_ID' => new EE_Foreign_Key_Int_Field(
46
+					'GRP_ID',
47
+					esc_html__('The ID to the Message Template Group', 'event_espresso'),
48
+					false,
49
+					0,
50
+					'Message_Template_Group'
51
+				),
52
+			],
53
+		];
54
+		$this->_model_relations                                         = [
55
+			'Event'                  => new EE_Belongs_To_Relation(),
56
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
57
+		];
58
+		$path_to_event                                                  = 'Event';
59
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
60
+			new EE_Restriction_Generator_Event_Related_Public(
61
+				$path_to_event
62
+			);
63
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
64
+			new EE_Restriction_Generator_Event_Related_Protected(
65
+				$path_to_event
66
+			);
67
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
68
+			new EE_Restriction_Generator_Event_Related_Protected(
69
+				$path_to_event
70
+			);
71
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
72
+			new EE_Restriction_Generator_Event_Related_Protected(
73
+				$path_to_event,
74
+				EEM_Base::caps_edit
75
+			);
76
+		parent::__construct($timezone);
77
+	}
78 78
 
79 79
 
80
-    /**
81
-     * helper method to simply return an array of event ids for events attached to the given
82
-     * message template group.
83
-     *
84
-     * @param int $GRP_ID The MTP group we want attached events for.
85
-     * @return  array               An array of event ids.
86
-     * @throws EE_Error
87
-     * @since 4.3.0
88
-     */
89
-    public function get_attached_event_ids($GRP_ID)
90
-    {
91
-        $event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID');
92
-        $event_ids = call_user_func_array('array_merge', $event_ids);
93
-        return $event_ids;
94
-    }
80
+	/**
81
+	 * helper method to simply return an array of event ids for events attached to the given
82
+	 * message template group.
83
+	 *
84
+	 * @param int $GRP_ID The MTP group we want attached events for.
85
+	 * @return  array               An array of event ids.
86
+	 * @throws EE_Error
87
+	 * @since 4.3.0
88
+	 */
89
+	public function get_attached_event_ids($GRP_ID)
90
+	{
91
+		$event_ids = $this->_get_all_wpdb_results([['GRP_ID' => $GRP_ID]], ARRAY_N, 'EVT_ID');
92
+		$event_ids = call_user_func_array('array_merge', $event_ids);
93
+		return $event_ids;
94
+	}
95 95
 
96 96
 
97
-    /**
98
-     * helper method for clearing event/group relations for the given event ids and grp ids.
99
-     *
100
-     * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs.
101
-     * @param array $EVT_IDs An array of EVT_IDs.  Optional. If empty then there must be GRP IDs.
102
-     * @return int             How many rows were deleted.
103
-     * @throws EE_Error
104
-     * @throws EE_Error
105
-     */
106
-    public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = [])
107
-    {
108
-        if (empty($GRP_IDs) && empty($EVT_IDs)) {
109
-            throw new EE_Error(
110
-                sprintf(
111
-                    esc_html__(
112
-                        '%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.',
113
-                        'event_espresso'
114
-                    ),
115
-                    __METHOD__
116
-                )
117
-            );
118
-        }
97
+	/**
98
+	 * helper method for clearing event/group relations for the given event ids and grp ids.
99
+	 *
100
+	 * @param array $GRP_IDs An array of GRP_IDs. Optional. If empty then there must be EVT IDs.
101
+	 * @param array $EVT_IDs An array of EVT_IDs.  Optional. If empty then there must be GRP IDs.
102
+	 * @return int             How many rows were deleted.
103
+	 * @throws EE_Error
104
+	 * @throws EE_Error
105
+	 */
106
+	public function delete_event_group_relations($GRP_IDs = [], $EVT_IDs = [])
107
+	{
108
+		if (empty($GRP_IDs) && empty($EVT_IDs)) {
109
+			throw new EE_Error(
110
+				sprintf(
111
+					esc_html__(
112
+						'%s requires either an array of GRP_IDs or EVT_IDs or both, but both cannot be empty.',
113
+						'event_espresso'
114
+					),
115
+					__METHOD__
116
+				)
117
+			);
118
+		}
119 119
 
120
-        $where = [];
121
-        if (! empty($GRP_IDs)) {
122
-            $where['GRP_ID'] = ['IN', (array) $GRP_IDs];
123
-        }
124
-        if (! empty($EVT_IDs)) {
125
-            $where['EVT_ID'] = ['IN', (array) $EVT_IDs];
126
-        }
120
+		$where = [];
121
+		if (! empty($GRP_IDs)) {
122
+			$where['GRP_ID'] = ['IN', (array) $GRP_IDs];
123
+		}
124
+		if (! empty($EVT_IDs)) {
125
+			$where['EVT_ID'] = ['IN', (array) $EVT_IDs];
126
+		}
127 127
 
128
-        return $this->delete([$where], false);
129
-    }
128
+		return $this->delete([$where], false);
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * returns a numerically indexed array
134
-     * with values that correspond to the 'GRP_ID' column
135
-     * where the 'EVT_ID' column matches that of the supplied event
136
-     *
137
-     * @param EE_Event $event
138
-     * @return array
139
-     * @throws EE_Error
140
-     * @throws ReflectionException
141
-     * @since   5.0.0.p
142
-     */
143
-    public function messageTemplateGroupIDsForEvent(EE_Event $event): array
144
-    {
145
-        $results = $this->get_col([['EVT_ID' => $event->ID()]], 'GRP_ID');
146
-        return $results !== false ? $results : [];
147
-    }
132
+	/**
133
+	 * returns a numerically indexed array
134
+	 * with values that correspond to the 'GRP_ID' column
135
+	 * where the 'EVT_ID' column matches that of the supplied event
136
+	 *
137
+	 * @param EE_Event $event
138
+	 * @return array
139
+	 * @throws EE_Error
140
+	 * @throws ReflectionException
141
+	 * @since   5.0.0.p
142
+	 */
143
+	public function messageTemplateGroupIDsForEvent(EE_Event $event): array
144
+	{
145
+		$results = $this->get_col([['EVT_ID' => $event->ID()]], 'GRP_ID');
146
+		return $results !== false ? $results : [];
147
+	}
148 148
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -51,24 +51,24 @@  discard block
 block discarded – undo
51 51
                 ),
52 52
             ],
53 53
         ];
54
-        $this->_model_relations                                         = [
54
+        $this->_model_relations = [
55 55
             'Event'                  => new EE_Belongs_To_Relation(),
56 56
             'Message_Template_Group' => new EE_Belongs_To_Relation(),
57 57
         ];
58 58
         $path_to_event                                                  = 'Event';
59
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
59
+        $this->_cap_restriction_generators[EEM_Base::caps_read]       =
60 60
             new EE_Restriction_Generator_Event_Related_Public(
61 61
                 $path_to_event
62 62
             );
63
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
63
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
64 64
             new EE_Restriction_Generator_Event_Related_Protected(
65 65
                 $path_to_event
66 66
             );
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
67
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] =
68 68
             new EE_Restriction_Generator_Event_Related_Protected(
69 69
                 $path_to_event
70 70
             );
71
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
71
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] =
72 72
             new EE_Restriction_Generator_Event_Related_Protected(
73 73
                 $path_to_event,
74 74
                 EEM_Base::caps_edit
@@ -118,10 +118,10 @@  discard block
 block discarded – undo
118 118
         }
119 119
 
120 120
         $where = [];
121
-        if (! empty($GRP_IDs)) {
121
+        if ( ! empty($GRP_IDs)) {
122 122
             $where['GRP_ID'] = ['IN', (array) $GRP_IDs];
123 123
         }
124
-        if (! empty($EVT_IDs)) {
124
+        if ( ! empty($EVT_IDs)) {
125 125
             $where['EVT_ID'] = ['IN', (array) $EVT_IDs];
126 126
         }
127 127
 
Please login to merge, or discard this patch.
core/db_models/EEM_Question.model.php 2 patches
Indentation   +572 added lines, -572 removed lines patch added patch discarded remove patch
@@ -9,577 +9,577 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Question extends EEM_Soft_Delete_Base
11 11
 {
12
-    // constant used to indicate that the question type is CHECKBOX
13
-    const QST_type_checkbox = 'CHECKBOX';
12
+	// constant used to indicate that the question type is CHECKBOX
13
+	const QST_type_checkbox = 'CHECKBOX';
14 14
 
15
-    // constant used to indicate that the question type is COUNTRY
16
-    const QST_type_country = 'COUNTRY';
17
-
18
-    // constant used to indicate that the question type is DATE
19
-    const QST_type_date = 'DATE';
20
-
21
-    // constant used to indicate that the question type is a decimal (float)
22
-    const QST_type_decimal = 'DECIMAL';
23
-
24
-    // constant used to indicate that the question type is DROPDOWN
25
-    const QST_type_dropdown = 'DROPDOWN';
26
-
27
-    // constant used to indicate that the question type is an email input
28
-    const QST_type_email = 'EMAIL';
29
-
30
-    // constant used to indicate that the question type is an email input
31
-    const QST_type_email_confirm = 'EMAIL_CONFIRM';
32
-
33
-    // constant used to indicate that the question type is a TEXTAREA that allows simple html
34
-    const QST_type_html_textarea = 'HTML_TEXTAREA';
35
-
36
-    // constant used to indicate that the question type is an integer (whole number)
37
-    const QST_type_int = 'INTEGER';
38
-
39
-    // constant used to indicate that the question type is a multi-select
40
-    const QST_type_multi_select = 'MULTI_SELECT';
41
-
42
-    // constant used to indicate that the question type is RADIO_BTN
43
-    const QST_type_radio = 'RADIO_BTN';
44
-
45
-    // constant used to indicate that the question type is STATE
46
-    const QST_type_state = 'STATE';
47
-
48
-    // constant used to indicate that the question type is TEXT
49
-    const QST_type_text = 'TEXT';
50
-
51
-    // constant used to indicate that the question type is TEXTAREA
52
-    const QST_type_textarea = 'TEXTAREA';
53
-
54
-    // constant used to indicate that the question type is a valid URL
55
-    const QST_type_url = 'URL';
56
-
57
-    // constant used to indicate that the question type is a US-formatted phone number
58
-    const QST_type_us_phone = 'US_PHONE';
59
-
60
-    // constant used to indicate that the question type is a YEAR
61
-    const QST_type_year = 'YEAR';
62
-
63
-    /**
64
-     * lists all the question types which should be allowed. Ideally, this will be extensible.
65
-     *
66
-     * @var array $_allowed_question_types
67
-     */
68
-    protected $_allowed_question_types = [];
69
-
70
-
71
-    // private instance of the Attendee object
72
-    protected static $_instance = null;
73
-
74
-    /**
75
-     * brief descriptions for all the question types
76
-     *
77
-     * @var EEM_Question $_instance
78
-     */
79
-    protected $_question_descriptions;
80
-
81
-    /**
82
-     * Question types that are interchangeable, even after answers have been provided for them.
83
-     * Top-level keys are category slugs, next level is an array of question types. If question types
84
-     * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
85
-     *
86
-     * @var array   $_question_type_categories {
87
-     * @type string $text
88
-     * @type string $single                    -answer-enum
89
-     * @type string $multi                     -answer-enum
90
-     *                                         }
91
-     */
92
-    protected $_question_type_categories = [];
93
-
94
-
95
-    /**
96
-     * Question types that should have an admin-defined max input length
97
-     *
98
-     * @var array
99
-     */
100
-    protected $question_types_with_max_length;
101
-
102
-
103
-    /**
104
-     * EEM_Question constructor.
105
-     *
106
-     * @param string|null $timezone
107
-     * @throws EE_Error
108
-     */
109
-    protected function __construct(?string $timezone = '')
110
-    {
111
-        $this->singular_item                  = esc_html__('Question', 'event_espresso');
112
-        $this->plural_item                    = esc_html__('Questions', 'event_espresso');
113
-        $this->_allowed_question_types        = apply_filters(
114
-            'FHEE__EEM_Question__construct__allowed_question_types',
115
-            [
116
-                EEM_Question::QST_type_checkbox      => esc_html__('Checkboxes', 'event_espresso'),
117
-                EEM_Question::QST_type_country       => esc_html__('Country Dropdown', 'event_espresso'),
118
-                EEM_Question::QST_type_date          => esc_html__('Date Picker', 'event_espresso'),
119
-                EEM_Question::QST_type_decimal       => esc_html__('Number', 'event_espresso'),
120
-                EEM_Question::QST_type_dropdown      => esc_html__('Dropdown', 'event_espresso'),
121
-                EEM_Question::QST_type_email         => esc_html__('Email', 'event_espresso'),
122
-                EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'),
123
-                EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'),
124
-                EEM_Question::QST_type_int           => esc_html__('Whole Number', 'event_espresso'),
125
-                EEM_Question::QST_type_multi_select  => esc_html__('Multi Select', 'event_espresso'),
126
-                EEM_Question::QST_type_radio         => esc_html__('Radio Buttons', 'event_espresso'),
127
-                EEM_Question::QST_type_state         => esc_html__('State/Province Dropdown', 'event_espresso'),
128
-                EEM_Question::QST_type_text          => esc_html__('Text', 'event_espresso'),
129
-                EEM_Question::QST_type_textarea      => esc_html__('Textarea', 'event_espresso'),
130
-                EEM_Question::QST_type_url           => esc_html__('URL', 'event_espresso'),
131
-                EEM_Question::QST_type_us_phone      => esc_html__('USA - Format Phone', 'event_espresso'),
132
-                EEM_Question::QST_type_year          => esc_html__('Year', 'event_espresso'),
133
-            ]
134
-        );
135
-        $this->_question_descriptions         = apply_filters(
136
-            'FHEE__EEM_Question__construct__question_descriptions',
137
-            [
138
-                EEM_Question::QST_type_checkbox      => esc_html__(
139
-                    'Allows multiple preset options to be selected',
140
-                    'event_espresso'
141
-                ),
142
-                EEM_Question::QST_type_country       => esc_html__(
143
-                    'A dropdown that lists countries',
144
-                    'event_espresso'
145
-                ),
146
-                EEM_Question::QST_type_date          => esc_html__(
147
-                    'A popup calendar that allows date selections',
148
-                    'event_espresso'
149
-                ),
150
-                EEM_Question::QST_type_decimal       => esc_html__(
151
-                    'A text field that allows number values with decimals',
152
-                    'event_espresso'
153
-                ),
154
-                EEM_Question::QST_type_dropdown      => esc_html__(
155
-                    'A dropdown that allows a single selection',
156
-                    'event_espresso'
157
-                ),
158
-                EEM_Question::QST_type_email         => esc_html__(
159
-                    'A text field that must contain a valid Email address',
160
-                    'event_espresso'
161
-                ),
162
-                EEM_Question::QST_type_email_confirm => esc_html__(
163
-                    'A text field that must contain a valid Email address and be equal to Email field',
164
-                    'event_espresso'
165
-                ),
166
-                EEM_Question::QST_type_html_textarea => esc_html__(
167
-                    'A multi line text input field that allows HTML',
168
-                    'event_espresso'
169
-                ),
170
-                EEM_Question::QST_type_int           => esc_html__(
171
-                    'A text field that only allows whole numbers (no decimals)',
172
-                    'event_espresso'
173
-                ),
174
-                EEM_Question::QST_type_multi_select  => esc_html__(
175
-                    'A dropdown that allows multiple selections',
176
-                    'event_espresso'
177
-                ),
178
-                EEM_Question::QST_type_radio         => esc_html__(
179
-                    'Allows a single preset option to be selected',
180
-                    'event_espresso'
181
-                ),
182
-                EEM_Question::QST_type_state         => esc_html__(
183
-                    'A dropdown that lists states/provinces',
184
-                    'event_espresso'
185
-                ),
186
-                EEM_Question::QST_type_text          => esc_html__(
187
-                    'A single line text input field',
188
-                    'event_espresso'
189
-                ),
190
-                EEM_Question::QST_type_textarea      => esc_html__(
191
-                    'A multi line text input field',
192
-                    'event_espresso'
193
-                ),
194
-                EEM_Question::QST_type_url           => esc_html__(
195
-                    'A text field that must contain a valid URL',
196
-                    'event_espresso'
197
-                ),
198
-                EEM_Question::QST_type_us_phone      => esc_html__(
199
-                    'A text field that must contain a valid US phone number',
200
-                    'event_espresso'
201
-                ),
202
-                EEM_Question::QST_type_year          => esc_html__(
203
-                    'A dropdown that lists the last 100 years',
204
-                    'event_espresso'
205
-                ),
206
-            ]
207
-        );
208
-        $this->_question_type_categories      = (array) apply_filters(
209
-            'FHEE__EEM_Question__construct__question_type_categories',
210
-            [
211
-                'text'               => [
212
-                    EEM_Question::QST_type_date,
213
-                    EEM_Question::QST_type_decimal,
214
-                    EEM_Question::QST_type_email,
215
-                    EEM_Question::QST_type_email_confirm,
216
-                    EEM_Question::QST_type_html_textarea,
217
-                    EEM_Question::QST_type_int,
218
-                    EEM_Question::QST_type_text,
219
-                    EEM_Question::QST_type_textarea,
220
-                    EEM_Question::QST_type_url,
221
-                    EEM_Question::QST_type_us_phone,
222
-                    EEM_Question::QST_type_year,
223
-                ],
224
-                'single-answer-enum' => [
225
-                    EEM_Question::QST_type_dropdown,
226
-                    EEM_Question::QST_type_radio,
227
-                ],
228
-                'multi-answer-enum'  => [
229
-                    EEM_Question::QST_type_multi_select,
230
-                    EEM_Question::QST_type_checkbox,
231
-                ],
232
-            ]
233
-        );
234
-        $this->question_types_with_max_length = apply_filters(
235
-            'FHEE__EEM_Question___construct__question_types_with_max_length',
236
-            [
237
-                EEM_Question::QST_type_html_textarea,
238
-                EEM_Question::QST_type_text,
239
-                EEM_Question::QST_type_textarea,
240
-            ]
241
-        );
242
-
243
-        $this->_tables          = [
244
-            'Question' => new EE_Primary_Table('esp_question', 'QST_ID'),
245
-        ];
246
-        $this->_fields          = [
247
-            'Question' => [
248
-                'QST_ID'            => new EE_Primary_Key_Int_Field(
249
-                    'QST_ID',
250
-                    esc_html__('Question ID', 'event_espresso')
251
-                ),
252
-                'QST_admin_label'   => new EE_Plain_Text_Field(
253
-                    'QST_admin_label',
254
-                    esc_html__('Question Label (admin-only)', 'event_espresso'),
255
-                    true,
256
-                    ''
257
-                ),
258
-                'QST_admin_only'    => new EE_Boolean_Field(
259
-                    'QST_admin_only',
260
-                    esc_html__('Admin-Only Question?', 'event_espresso'),
261
-                    false,
262
-                    false
263
-                ),
264
-                'QST_deleted'       => new EE_Trashed_Flag_Field(
265
-                    'QST_deleted',
266
-                    esc_html__('Flag Indicating question was deleted', 'event_espresso'),
267
-                    false,
268
-                    false
269
-                ),
270
-                'QST_display_text'  => new EE_Post_Content_Field(
271
-                    'QST_display_text',
272
-                    esc_html__('Question Text', 'event_espresso'),
273
-                    true,
274
-                    ''
275
-                ),
276
-                'QST_max'           => new EE_Infinite_Integer_Field(
277
-                    'QST_max',
278
-                    esc_html__('Max Size', 'event_espresso'),
279
-                    false,
280
-                    EE_INF
281
-                ),
282
-                'QST_order'         => new EE_Integer_Field(
283
-                    'QST_order',
284
-                    esc_html__('Question Order', 'event_espresso'),
285
-                    false,
286
-                    0
287
-                ),
288
-                'QST_required'      => new EE_Boolean_Field(
289
-                    'QST_required',
290
-                    esc_html__('Required Question?', 'event_espresso'),
291
-                    false,
292
-                    false
293
-                ),
294
-                'QST_required_text' => new EE_Simple_HTML_Field(
295
-                    'QST_required_text',
296
-                    esc_html__('Text to Display if Not Provided', 'event_espresso'),
297
-                    true,
298
-                    ''
299
-                ),
300
-                'QST_system'        => new EE_Plain_Text_Field(
301
-                    'QST_system',
302
-                    esc_html__('Internal string ID for question', 'event_espresso'),
303
-                    false,
304
-                    ''
305
-                ),
306
-                'QST_type'          => new EE_Enum_Text_Field(
307
-                    'QST_type',
308
-                    esc_html__('Question Type', 'event_espresso'),
309
-                    false,
310
-                    'TEXT',
311
-                    $this->_allowed_question_types
312
-                ),
313
-                'QST_wp_user'       => new EE_WP_User_Field(
314
-                    'QST_wp_user',
315
-                    esc_html__('Question Creator ID', 'event_espresso'),
316
-                    false
317
-                ),
318
-            ],
319
-        ];
320
-        $this->_model_relations = [
321
-            'Answer'                  => new EE_Has_Many_Relation(),
322
-            'Question_Group'          => new EE_HABTM_Relation('Question_Group_Question'),
323
-            // for QST_order column
324
-            'Question_Group_Question' => new EE_Has_Many_Relation(),
325
-            'Question_Option'         => new EE_Has_Many_Relation(),
326
-            'WP_User'                 => new EE_Belongs_To_Relation(),
327
-        ];
328
-        // this model is generally available for reading
329
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
330
-            new EE_Restriction_Generator_Public();
331
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
332
-            new EE_Restriction_Generator_Reg_Form('QST_system');
333
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
334
-            new EE_Restriction_Generator_Reg_Form('QST_system');
335
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
336
-            new EE_Restriction_Generator_Reg_Form('QST_system');
337
-
338
-        parent::__construct($timezone);
339
-    }
340
-
341
-
342
-    /**
343
-     * Returns the list of allowed question types, which are normally:
344
-     * 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' but they can be extended
345
-     *
346
-     * @return string[]
347
-     */
348
-    public function allowed_question_types(): array
349
-    {
350
-        return $this->_allowed_question_types;
351
-    }
352
-
353
-
354
-    /**
355
-     * Gets all the question types in the same category
356
-     *
357
-     * @param string $question_type one of EEM_Question::allowed_question_types(
358
-     * @return string[] like EEM_Question::allowed_question_types()
359
-     */
360
-    public function question_types_in_same_category(string $question_type): array
361
-    {
362
-        $question_types = [$question_type];
363
-        foreach ($this->_question_type_categories as $category => $question_types_in_category) {
364
-            if (in_array($question_type, $question_types_in_category)) {
365
-                $question_types = $question_types_in_category;
366
-                break;
367
-            }
368
-        }
369
-
370
-        return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
371
-    }
372
-
373
-
374
-    /**
375
-     * Determines if the given question type is in the given question type category
376
-     *
377
-     * @param string $question_type one of EEM_Question::allowed_question_types()
378
-     * @param string $category      one of the top-level keys of EEM_Question::question_type_categories()
379
-     * @return boolean
380
-     */
381
-    public function question_type_is_in_category(string $question_type, string $category): bool
382
-    {
383
-        if (! isset($this->_question_type_categories[ $category ])) {
384
-            return false;
385
-        }
386
-        return in_array($question_type, $this->_question_type_categories[ $category ]);
387
-    }
388
-
389
-
390
-    /**
391
-     * Returns all the question types in the given category
392
-     *
393
-     * @param string $category
394
-     * @return array|mixed
395
-     */
396
-    public function question_types_in_category(string $category): array
397
-    {
398
-        if (isset($this->_question_type_categories[ $category ])) {
399
-            return $this->_question_type_categories[ $category ];
400
-        }
401
-        return [];
402
-    }
403
-
404
-
405
-    /**
406
-     * Returns all the question types that should have question options
407
-     *
408
-     * @return array
409
-     */
410
-    public function question_types_with_options(): array
411
-    {
412
-        return array_merge(
413
-            $this->question_types_in_category('single-answer-enum'),
414
-            $this->question_types_in_category('multi-answer-enum')
415
-        );
416
-    }
417
-
418
-
419
-    /**
420
-     * Returns the question type categories 2d array
421
-     *
422
-     * @return array see EEM_Question::_question_type_categories
423
-     */
424
-    public function question_type_categories(): array
425
-    {
426
-        return $this->_question_type_categories;
427
-    }
428
-
429
-
430
-    /**
431
-     * Returns an array of all the QST_system values that can be allowed in the system question group
432
-     * identified by $system_question_group_id
433
-     *
434
-     * @param string $system_question_group_id QSG_system
435
-     * @return array of system question names (QST_system)
436
-     */
437
-    public function allowed_system_questions_in_system_question_group(string $system_question_group_id): array
438
-    {
439
-        $question_system_ids = [];
440
-        switch ($system_question_group_id) {
441
-            case EEM_Question_Group::system_personal:
442
-                $question_system_ids = [
443
-                    EEM_Attendee::system_question_fname,
444
-                    EEM_Attendee::system_question_lname,
445
-                    EEM_Attendee::system_question_email,
446
-                    EEM_Attendee::system_question_email_confirm,
447
-                    EEM_Attendee::system_question_phone,
448
-                ];
449
-                break;
450
-            case EEM_Question_Group::system_address:
451
-                $question_system_ids = [
452
-                    EEM_Attendee::system_question_address,
453
-                    EEM_Attendee::system_question_address2,
454
-                    EEM_Attendee::system_question_city,
455
-                    EEM_Attendee::system_question_state,
456
-                    EEM_Attendee::system_question_country,
457
-                    EEM_Attendee::system_question_zip,
458
-                    EEM_Attendee::system_question_phone,
459
-                ];
460
-                break;
461
-        }
462
-        return apply_filters(
463
-            'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return',
464
-            $question_system_ids,
465
-            $system_question_group_id
466
-        );
467
-    }
468
-
469
-
470
-    /**
471
-     * Returns an array of all the QST_system values that are required in the system question group
472
-     * identified by $system_question_group_id
473
-     *
474
-     * @param string $system_question_group_id QSG_system
475
-     * @return array of system question names (QST_system)
476
-     */
477
-    public function required_system_questions_in_system_question_group(string $system_question_group_id): array
478
-    {
479
-        $question_system_ids = null;
480
-        switch ($system_question_group_id) {
481
-            case EEM_Question_Group::system_personal:
482
-                $question_system_ids = [
483
-                    EEM_Attendee::system_question_fname,
484
-                    EEM_Attendee::system_question_email,
485
-                ];
486
-                break;
487
-            default:
488
-                $question_system_ids = [];
489
-        }
490
-        return apply_filters(
491
-            'FHEE__EEM_Question__system_questions_required_in_system_question_group',
492
-            $question_system_ids,
493
-            $system_question_group_id
494
-        );
495
-    }
496
-
497
-
498
-    /**
499
-     * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
500
-     * which system question QST_ID corresponds to the QST_system 'city', use
501
-     * EEM_Question::instance()->get_Question_ID_from_system_string('city');
502
-     *
503
-     * @param $QST_system
504
-     * @return int of QST_ID for the question that corresponds to that QST_system
505
-     * @throws EE_Error
506
-     */
507
-    public function get_Question_ID_from_system_string($QST_system): int
508
-    {
509
-        return $this->get_var([['QST_system' => $QST_system]]);
510
-    }
511
-
512
-
513
-    /**
514
-     * searches the db for the question with the latest question order and returns that value.
515
-     *
516
-     * @return int
517
-     * @throws EE_Error
518
-     */
519
-    public function get_latest_question_order(): int
520
-    {
521
-        $columns_to_select = [
522
-            'max_order' => ["MAX(QST_order)", "%d"],
523
-        ];
524
-        $max               = $this->_get_all_wpdb_results([], ARRAY_A, $columns_to_select);
525
-        return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
526
-    }
527
-
528
-
529
-    /**
530
-     * Returns an array where keys are system question QST_system values,
531
-     * and values are the highest question max the admin can set on the question
532
-     * (aka the "max max"; eg, a site admin can change the zip question to have a max
533
-     * of 5, but no larger than 12)
534
-     *
535
-     * @return array
536
-     */
537
-    public function system_question_maxes(): array
538
-    {
539
-        return [
540
-            'fname'         => 45,
541
-            'lname'         => 45,
542
-            'address'       => 255,
543
-            'address2'      => 255,
544
-            'city'          => 45,
545
-            'zip'           => 12,
546
-            'email'         => 255,
547
-            'email_confirm' => 255,
548
-            'phone'         => 45,
549
-        ];
550
-    }
551
-
552
-
553
-    /**
554
-     * Given a QST_system value, gets the question's largest allowable max input.
555
-     *
556
-     * @param string $system_question_value
557
-     * @return int|float
558
-     * @see Registration_Form_Admin_Page::system_question_maxes()
559
-     */
560
-    public function absolute_max_for_system_question(string $system_question_value)
561
-    {
562
-        $maxes = $this->system_question_maxes();
563
-        return $maxes[ $system_question_value ] ?? EE_INF;
564
-    }
565
-
566
-
567
-    /**
568
-     * @return array
569
-     */
570
-    public function question_descriptions(): array
571
-    {
572
-        return $this->_question_descriptions;
573
-    }
574
-
575
-
576
-    /**
577
-     * Returns all the question types that should have an admin-defined max input length
578
-     *
579
-     * @return array
580
-     */
581
-    public function questionTypesWithMaxLength(): array
582
-    {
583
-        return (array) $this->question_types_with_max_length;
584
-    }
15
+	// constant used to indicate that the question type is COUNTRY
16
+	const QST_type_country = 'COUNTRY';
17
+
18
+	// constant used to indicate that the question type is DATE
19
+	const QST_type_date = 'DATE';
20
+
21
+	// constant used to indicate that the question type is a decimal (float)
22
+	const QST_type_decimal = 'DECIMAL';
23
+
24
+	// constant used to indicate that the question type is DROPDOWN
25
+	const QST_type_dropdown = 'DROPDOWN';
26
+
27
+	// constant used to indicate that the question type is an email input
28
+	const QST_type_email = 'EMAIL';
29
+
30
+	// constant used to indicate that the question type is an email input
31
+	const QST_type_email_confirm = 'EMAIL_CONFIRM';
32
+
33
+	// constant used to indicate that the question type is a TEXTAREA that allows simple html
34
+	const QST_type_html_textarea = 'HTML_TEXTAREA';
35
+
36
+	// constant used to indicate that the question type is an integer (whole number)
37
+	const QST_type_int = 'INTEGER';
38
+
39
+	// constant used to indicate that the question type is a multi-select
40
+	const QST_type_multi_select = 'MULTI_SELECT';
41
+
42
+	// constant used to indicate that the question type is RADIO_BTN
43
+	const QST_type_radio = 'RADIO_BTN';
44
+
45
+	// constant used to indicate that the question type is STATE
46
+	const QST_type_state = 'STATE';
47
+
48
+	// constant used to indicate that the question type is TEXT
49
+	const QST_type_text = 'TEXT';
50
+
51
+	// constant used to indicate that the question type is TEXTAREA
52
+	const QST_type_textarea = 'TEXTAREA';
53
+
54
+	// constant used to indicate that the question type is a valid URL
55
+	const QST_type_url = 'URL';
56
+
57
+	// constant used to indicate that the question type is a US-formatted phone number
58
+	const QST_type_us_phone = 'US_PHONE';
59
+
60
+	// constant used to indicate that the question type is a YEAR
61
+	const QST_type_year = 'YEAR';
62
+
63
+	/**
64
+	 * lists all the question types which should be allowed. Ideally, this will be extensible.
65
+	 *
66
+	 * @var array $_allowed_question_types
67
+	 */
68
+	protected $_allowed_question_types = [];
69
+
70
+
71
+	// private instance of the Attendee object
72
+	protected static $_instance = null;
73
+
74
+	/**
75
+	 * brief descriptions for all the question types
76
+	 *
77
+	 * @var EEM_Question $_instance
78
+	 */
79
+	protected $_question_descriptions;
80
+
81
+	/**
82
+	 * Question types that are interchangeable, even after answers have been provided for them.
83
+	 * Top-level keys are category slugs, next level is an array of question types. If question types
84
+	 * aren't in this array, it is assumed they AREN'T interchangeable with any other question types.
85
+	 *
86
+	 * @var array   $_question_type_categories {
87
+	 * @type string $text
88
+	 * @type string $single                    -answer-enum
89
+	 * @type string $multi                     -answer-enum
90
+	 *                                         }
91
+	 */
92
+	protected $_question_type_categories = [];
93
+
94
+
95
+	/**
96
+	 * Question types that should have an admin-defined max input length
97
+	 *
98
+	 * @var array
99
+	 */
100
+	protected $question_types_with_max_length;
101
+
102
+
103
+	/**
104
+	 * EEM_Question constructor.
105
+	 *
106
+	 * @param string|null $timezone
107
+	 * @throws EE_Error
108
+	 */
109
+	protected function __construct(?string $timezone = '')
110
+	{
111
+		$this->singular_item                  = esc_html__('Question', 'event_espresso');
112
+		$this->plural_item                    = esc_html__('Questions', 'event_espresso');
113
+		$this->_allowed_question_types        = apply_filters(
114
+			'FHEE__EEM_Question__construct__allowed_question_types',
115
+			[
116
+				EEM_Question::QST_type_checkbox      => esc_html__('Checkboxes', 'event_espresso'),
117
+				EEM_Question::QST_type_country       => esc_html__('Country Dropdown', 'event_espresso'),
118
+				EEM_Question::QST_type_date          => esc_html__('Date Picker', 'event_espresso'),
119
+				EEM_Question::QST_type_decimal       => esc_html__('Number', 'event_espresso'),
120
+				EEM_Question::QST_type_dropdown      => esc_html__('Dropdown', 'event_espresso'),
121
+				EEM_Question::QST_type_email         => esc_html__('Email', 'event_espresso'),
122
+				EEM_Question::QST_type_email_confirm => esc_html__('Confirm Email', 'event_espresso'),
123
+				EEM_Question::QST_type_html_textarea => esc_html__('HTML Textarea', 'event_espresso'),
124
+				EEM_Question::QST_type_int           => esc_html__('Whole Number', 'event_espresso'),
125
+				EEM_Question::QST_type_multi_select  => esc_html__('Multi Select', 'event_espresso'),
126
+				EEM_Question::QST_type_radio         => esc_html__('Radio Buttons', 'event_espresso'),
127
+				EEM_Question::QST_type_state         => esc_html__('State/Province Dropdown', 'event_espresso'),
128
+				EEM_Question::QST_type_text          => esc_html__('Text', 'event_espresso'),
129
+				EEM_Question::QST_type_textarea      => esc_html__('Textarea', 'event_espresso'),
130
+				EEM_Question::QST_type_url           => esc_html__('URL', 'event_espresso'),
131
+				EEM_Question::QST_type_us_phone      => esc_html__('USA - Format Phone', 'event_espresso'),
132
+				EEM_Question::QST_type_year          => esc_html__('Year', 'event_espresso'),
133
+			]
134
+		);
135
+		$this->_question_descriptions         = apply_filters(
136
+			'FHEE__EEM_Question__construct__question_descriptions',
137
+			[
138
+				EEM_Question::QST_type_checkbox      => esc_html__(
139
+					'Allows multiple preset options to be selected',
140
+					'event_espresso'
141
+				),
142
+				EEM_Question::QST_type_country       => esc_html__(
143
+					'A dropdown that lists countries',
144
+					'event_espresso'
145
+				),
146
+				EEM_Question::QST_type_date          => esc_html__(
147
+					'A popup calendar that allows date selections',
148
+					'event_espresso'
149
+				),
150
+				EEM_Question::QST_type_decimal       => esc_html__(
151
+					'A text field that allows number values with decimals',
152
+					'event_espresso'
153
+				),
154
+				EEM_Question::QST_type_dropdown      => esc_html__(
155
+					'A dropdown that allows a single selection',
156
+					'event_espresso'
157
+				),
158
+				EEM_Question::QST_type_email         => esc_html__(
159
+					'A text field that must contain a valid Email address',
160
+					'event_espresso'
161
+				),
162
+				EEM_Question::QST_type_email_confirm => esc_html__(
163
+					'A text field that must contain a valid Email address and be equal to Email field',
164
+					'event_espresso'
165
+				),
166
+				EEM_Question::QST_type_html_textarea => esc_html__(
167
+					'A multi line text input field that allows HTML',
168
+					'event_espresso'
169
+				),
170
+				EEM_Question::QST_type_int           => esc_html__(
171
+					'A text field that only allows whole numbers (no decimals)',
172
+					'event_espresso'
173
+				),
174
+				EEM_Question::QST_type_multi_select  => esc_html__(
175
+					'A dropdown that allows multiple selections',
176
+					'event_espresso'
177
+				),
178
+				EEM_Question::QST_type_radio         => esc_html__(
179
+					'Allows a single preset option to be selected',
180
+					'event_espresso'
181
+				),
182
+				EEM_Question::QST_type_state         => esc_html__(
183
+					'A dropdown that lists states/provinces',
184
+					'event_espresso'
185
+				),
186
+				EEM_Question::QST_type_text          => esc_html__(
187
+					'A single line text input field',
188
+					'event_espresso'
189
+				),
190
+				EEM_Question::QST_type_textarea      => esc_html__(
191
+					'A multi line text input field',
192
+					'event_espresso'
193
+				),
194
+				EEM_Question::QST_type_url           => esc_html__(
195
+					'A text field that must contain a valid URL',
196
+					'event_espresso'
197
+				),
198
+				EEM_Question::QST_type_us_phone      => esc_html__(
199
+					'A text field that must contain a valid US phone number',
200
+					'event_espresso'
201
+				),
202
+				EEM_Question::QST_type_year          => esc_html__(
203
+					'A dropdown that lists the last 100 years',
204
+					'event_espresso'
205
+				),
206
+			]
207
+		);
208
+		$this->_question_type_categories      = (array) apply_filters(
209
+			'FHEE__EEM_Question__construct__question_type_categories',
210
+			[
211
+				'text'               => [
212
+					EEM_Question::QST_type_date,
213
+					EEM_Question::QST_type_decimal,
214
+					EEM_Question::QST_type_email,
215
+					EEM_Question::QST_type_email_confirm,
216
+					EEM_Question::QST_type_html_textarea,
217
+					EEM_Question::QST_type_int,
218
+					EEM_Question::QST_type_text,
219
+					EEM_Question::QST_type_textarea,
220
+					EEM_Question::QST_type_url,
221
+					EEM_Question::QST_type_us_phone,
222
+					EEM_Question::QST_type_year,
223
+				],
224
+				'single-answer-enum' => [
225
+					EEM_Question::QST_type_dropdown,
226
+					EEM_Question::QST_type_radio,
227
+				],
228
+				'multi-answer-enum'  => [
229
+					EEM_Question::QST_type_multi_select,
230
+					EEM_Question::QST_type_checkbox,
231
+				],
232
+			]
233
+		);
234
+		$this->question_types_with_max_length = apply_filters(
235
+			'FHEE__EEM_Question___construct__question_types_with_max_length',
236
+			[
237
+				EEM_Question::QST_type_html_textarea,
238
+				EEM_Question::QST_type_text,
239
+				EEM_Question::QST_type_textarea,
240
+			]
241
+		);
242
+
243
+		$this->_tables          = [
244
+			'Question' => new EE_Primary_Table('esp_question', 'QST_ID'),
245
+		];
246
+		$this->_fields          = [
247
+			'Question' => [
248
+				'QST_ID'            => new EE_Primary_Key_Int_Field(
249
+					'QST_ID',
250
+					esc_html__('Question ID', 'event_espresso')
251
+				),
252
+				'QST_admin_label'   => new EE_Plain_Text_Field(
253
+					'QST_admin_label',
254
+					esc_html__('Question Label (admin-only)', 'event_espresso'),
255
+					true,
256
+					''
257
+				),
258
+				'QST_admin_only'    => new EE_Boolean_Field(
259
+					'QST_admin_only',
260
+					esc_html__('Admin-Only Question?', 'event_espresso'),
261
+					false,
262
+					false
263
+				),
264
+				'QST_deleted'       => new EE_Trashed_Flag_Field(
265
+					'QST_deleted',
266
+					esc_html__('Flag Indicating question was deleted', 'event_espresso'),
267
+					false,
268
+					false
269
+				),
270
+				'QST_display_text'  => new EE_Post_Content_Field(
271
+					'QST_display_text',
272
+					esc_html__('Question Text', 'event_espresso'),
273
+					true,
274
+					''
275
+				),
276
+				'QST_max'           => new EE_Infinite_Integer_Field(
277
+					'QST_max',
278
+					esc_html__('Max Size', 'event_espresso'),
279
+					false,
280
+					EE_INF
281
+				),
282
+				'QST_order'         => new EE_Integer_Field(
283
+					'QST_order',
284
+					esc_html__('Question Order', 'event_espresso'),
285
+					false,
286
+					0
287
+				),
288
+				'QST_required'      => new EE_Boolean_Field(
289
+					'QST_required',
290
+					esc_html__('Required Question?', 'event_espresso'),
291
+					false,
292
+					false
293
+				),
294
+				'QST_required_text' => new EE_Simple_HTML_Field(
295
+					'QST_required_text',
296
+					esc_html__('Text to Display if Not Provided', 'event_espresso'),
297
+					true,
298
+					''
299
+				),
300
+				'QST_system'        => new EE_Plain_Text_Field(
301
+					'QST_system',
302
+					esc_html__('Internal string ID for question', 'event_espresso'),
303
+					false,
304
+					''
305
+				),
306
+				'QST_type'          => new EE_Enum_Text_Field(
307
+					'QST_type',
308
+					esc_html__('Question Type', 'event_espresso'),
309
+					false,
310
+					'TEXT',
311
+					$this->_allowed_question_types
312
+				),
313
+				'QST_wp_user'       => new EE_WP_User_Field(
314
+					'QST_wp_user',
315
+					esc_html__('Question Creator ID', 'event_espresso'),
316
+					false
317
+				),
318
+			],
319
+		];
320
+		$this->_model_relations = [
321
+			'Answer'                  => new EE_Has_Many_Relation(),
322
+			'Question_Group'          => new EE_HABTM_Relation('Question_Group_Question'),
323
+			// for QST_order column
324
+			'Question_Group_Question' => new EE_Has_Many_Relation(),
325
+			'Question_Option'         => new EE_Has_Many_Relation(),
326
+			'WP_User'                 => new EE_Belongs_To_Relation(),
327
+		];
328
+		// this model is generally available for reading
329
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
330
+			new EE_Restriction_Generator_Public();
331
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
332
+			new EE_Restriction_Generator_Reg_Form('QST_system');
333
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
334
+			new EE_Restriction_Generator_Reg_Form('QST_system');
335
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
336
+			new EE_Restriction_Generator_Reg_Form('QST_system');
337
+
338
+		parent::__construct($timezone);
339
+	}
340
+
341
+
342
+	/**
343
+	 * Returns the list of allowed question types, which are normally:
344
+	 * 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' but they can be extended
345
+	 *
346
+	 * @return string[]
347
+	 */
348
+	public function allowed_question_types(): array
349
+	{
350
+		return $this->_allowed_question_types;
351
+	}
352
+
353
+
354
+	/**
355
+	 * Gets all the question types in the same category
356
+	 *
357
+	 * @param string $question_type one of EEM_Question::allowed_question_types(
358
+	 * @return string[] like EEM_Question::allowed_question_types()
359
+	 */
360
+	public function question_types_in_same_category(string $question_type): array
361
+	{
362
+		$question_types = [$question_type];
363
+		foreach ($this->_question_type_categories as $category => $question_types_in_category) {
364
+			if (in_array($question_type, $question_types_in_category)) {
365
+				$question_types = $question_types_in_category;
366
+				break;
367
+			}
368
+		}
369
+
370
+		return array_intersect_key($this->allowed_question_types(), array_flip($question_types));
371
+	}
372
+
373
+
374
+	/**
375
+	 * Determines if the given question type is in the given question type category
376
+	 *
377
+	 * @param string $question_type one of EEM_Question::allowed_question_types()
378
+	 * @param string $category      one of the top-level keys of EEM_Question::question_type_categories()
379
+	 * @return boolean
380
+	 */
381
+	public function question_type_is_in_category(string $question_type, string $category): bool
382
+	{
383
+		if (! isset($this->_question_type_categories[ $category ])) {
384
+			return false;
385
+		}
386
+		return in_array($question_type, $this->_question_type_categories[ $category ]);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Returns all the question types in the given category
392
+	 *
393
+	 * @param string $category
394
+	 * @return array|mixed
395
+	 */
396
+	public function question_types_in_category(string $category): array
397
+	{
398
+		if (isset($this->_question_type_categories[ $category ])) {
399
+			return $this->_question_type_categories[ $category ];
400
+		}
401
+		return [];
402
+	}
403
+
404
+
405
+	/**
406
+	 * Returns all the question types that should have question options
407
+	 *
408
+	 * @return array
409
+	 */
410
+	public function question_types_with_options(): array
411
+	{
412
+		return array_merge(
413
+			$this->question_types_in_category('single-answer-enum'),
414
+			$this->question_types_in_category('multi-answer-enum')
415
+		);
416
+	}
417
+
418
+
419
+	/**
420
+	 * Returns the question type categories 2d array
421
+	 *
422
+	 * @return array see EEM_Question::_question_type_categories
423
+	 */
424
+	public function question_type_categories(): array
425
+	{
426
+		return $this->_question_type_categories;
427
+	}
428
+
429
+
430
+	/**
431
+	 * Returns an array of all the QST_system values that can be allowed in the system question group
432
+	 * identified by $system_question_group_id
433
+	 *
434
+	 * @param string $system_question_group_id QSG_system
435
+	 * @return array of system question names (QST_system)
436
+	 */
437
+	public function allowed_system_questions_in_system_question_group(string $system_question_group_id): array
438
+	{
439
+		$question_system_ids = [];
440
+		switch ($system_question_group_id) {
441
+			case EEM_Question_Group::system_personal:
442
+				$question_system_ids = [
443
+					EEM_Attendee::system_question_fname,
444
+					EEM_Attendee::system_question_lname,
445
+					EEM_Attendee::system_question_email,
446
+					EEM_Attendee::system_question_email_confirm,
447
+					EEM_Attendee::system_question_phone,
448
+				];
449
+				break;
450
+			case EEM_Question_Group::system_address:
451
+				$question_system_ids = [
452
+					EEM_Attendee::system_question_address,
453
+					EEM_Attendee::system_question_address2,
454
+					EEM_Attendee::system_question_city,
455
+					EEM_Attendee::system_question_state,
456
+					EEM_Attendee::system_question_country,
457
+					EEM_Attendee::system_question_zip,
458
+					EEM_Attendee::system_question_phone,
459
+				];
460
+				break;
461
+		}
462
+		return apply_filters(
463
+			'FHEE__EEM_Question__system_questions_allowed_in_system_question_group__return',
464
+			$question_system_ids,
465
+			$system_question_group_id
466
+		);
467
+	}
468
+
469
+
470
+	/**
471
+	 * Returns an array of all the QST_system values that are required in the system question group
472
+	 * identified by $system_question_group_id
473
+	 *
474
+	 * @param string $system_question_group_id QSG_system
475
+	 * @return array of system question names (QST_system)
476
+	 */
477
+	public function required_system_questions_in_system_question_group(string $system_question_group_id): array
478
+	{
479
+		$question_system_ids = null;
480
+		switch ($system_question_group_id) {
481
+			case EEM_Question_Group::system_personal:
482
+				$question_system_ids = [
483
+					EEM_Attendee::system_question_fname,
484
+					EEM_Attendee::system_question_email,
485
+				];
486
+				break;
487
+			default:
488
+				$question_system_ids = [];
489
+		}
490
+		return apply_filters(
491
+			'FHEE__EEM_Question__system_questions_required_in_system_question_group',
492
+			$question_system_ids,
493
+			$system_question_group_id
494
+		);
495
+	}
496
+
497
+
498
+	/**
499
+	 * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know
500
+	 * which system question QST_ID corresponds to the QST_system 'city', use
501
+	 * EEM_Question::instance()->get_Question_ID_from_system_string('city');
502
+	 *
503
+	 * @param $QST_system
504
+	 * @return int of QST_ID for the question that corresponds to that QST_system
505
+	 * @throws EE_Error
506
+	 */
507
+	public function get_Question_ID_from_system_string($QST_system): int
508
+	{
509
+		return $this->get_var([['QST_system' => $QST_system]]);
510
+	}
511
+
512
+
513
+	/**
514
+	 * searches the db for the question with the latest question order and returns that value.
515
+	 *
516
+	 * @return int
517
+	 * @throws EE_Error
518
+	 */
519
+	public function get_latest_question_order(): int
520
+	{
521
+		$columns_to_select = [
522
+			'max_order' => ["MAX(QST_order)", "%d"],
523
+		];
524
+		$max               = $this->_get_all_wpdb_results([], ARRAY_A, $columns_to_select);
525
+		return isset($max[0], $max[0]['max_order']) ? $max[0]['max_order'] : 0;
526
+	}
527
+
528
+
529
+	/**
530
+	 * Returns an array where keys are system question QST_system values,
531
+	 * and values are the highest question max the admin can set on the question
532
+	 * (aka the "max max"; eg, a site admin can change the zip question to have a max
533
+	 * of 5, but no larger than 12)
534
+	 *
535
+	 * @return array
536
+	 */
537
+	public function system_question_maxes(): array
538
+	{
539
+		return [
540
+			'fname'         => 45,
541
+			'lname'         => 45,
542
+			'address'       => 255,
543
+			'address2'      => 255,
544
+			'city'          => 45,
545
+			'zip'           => 12,
546
+			'email'         => 255,
547
+			'email_confirm' => 255,
548
+			'phone'         => 45,
549
+		];
550
+	}
551
+
552
+
553
+	/**
554
+	 * Given a QST_system value, gets the question's largest allowable max input.
555
+	 *
556
+	 * @param string $system_question_value
557
+	 * @return int|float
558
+	 * @see Registration_Form_Admin_Page::system_question_maxes()
559
+	 */
560
+	public function absolute_max_for_system_question(string $system_question_value)
561
+	{
562
+		$maxes = $this->system_question_maxes();
563
+		return $maxes[ $system_question_value ] ?? EE_INF;
564
+	}
565
+
566
+
567
+	/**
568
+	 * @return array
569
+	 */
570
+	public function question_descriptions(): array
571
+	{
572
+		return $this->_question_descriptions;
573
+	}
574
+
575
+
576
+	/**
577
+	 * Returns all the question types that should have an admin-defined max input length
578
+	 *
579
+	 * @return array
580
+	 */
581
+	public function questionTypesWithMaxLength(): array
582
+	{
583
+		return (array) $this->question_types_with_max_length;
584
+	}
585 585
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
                 EEM_Question::QST_type_year          => esc_html__('Year', 'event_espresso'),
133 133
             ]
134 134
         );
135
-        $this->_question_descriptions         = apply_filters(
135
+        $this->_question_descriptions = apply_filters(
136 136
             'FHEE__EEM_Question__construct__question_descriptions',
137 137
             [
138 138
                 EEM_Question::QST_type_checkbox      => esc_html__(
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
                 ),
206 206
             ]
207 207
         );
208
-        $this->_question_type_categories      = (array) apply_filters(
208
+        $this->_question_type_categories = (array) apply_filters(
209 209
             'FHEE__EEM_Question__construct__question_type_categories',
210 210
             [
211 211
                 'text'               => [
@@ -326,13 +326,13 @@  discard block
 block discarded – undo
326 326
             'WP_User'                 => new EE_Belongs_To_Relation(),
327 327
         ];
328 328
         // this model is generally available for reading
329
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
329
+        $this->_cap_restriction_generators[EEM_Base::caps_read]       =
330 330
             new EE_Restriction_Generator_Public();
331
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
331
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
332 332
             new EE_Restriction_Generator_Reg_Form('QST_system');
333
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
333
+        $this->_cap_restriction_generators[EEM_Base::caps_edit]       =
334 334
             new EE_Restriction_Generator_Reg_Form('QST_system');
335
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
335
+        $this->_cap_restriction_generators[EEM_Base::caps_delete]     =
336 336
             new EE_Restriction_Generator_Reg_Form('QST_system');
337 337
 
338 338
         parent::__construct($timezone);
@@ -380,10 +380,10 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function question_type_is_in_category(string $question_type, string $category): bool
382 382
     {
383
-        if (! isset($this->_question_type_categories[ $category ])) {
383
+        if ( ! isset($this->_question_type_categories[$category])) {
384 384
             return false;
385 385
         }
386
-        return in_array($question_type, $this->_question_type_categories[ $category ]);
386
+        return in_array($question_type, $this->_question_type_categories[$category]);
387 387
     }
388 388
 
389 389
 
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
      */
396 396
     public function question_types_in_category(string $category): array
397 397
     {
398
-        if (isset($this->_question_type_categories[ $category ])) {
399
-            return $this->_question_type_categories[ $category ];
398
+        if (isset($this->_question_type_categories[$category])) {
399
+            return $this->_question_type_categories[$category];
400 400
         }
401 401
         return [];
402 402
     }
@@ -560,7 +560,7 @@  discard block
 block discarded – undo
560 560
     public function absolute_max_for_system_question(string $system_question_value)
561 561
     {
562 562
         $maxes = $this->system_question_maxes();
563
-        return $maxes[ $system_question_value ] ?? EE_INF;
563
+        return $maxes[$system_question_value] ?? EE_INF;
564 564
     }
565 565
 
566 566
 
Please login to merge, or discard this patch.
core/db_models/EEM_Currency.model.php 1 patch
Indentation   +99 added lines, -99 removed lines patch added patch discarded remove patch
@@ -9,110 +9,110 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Currency extends EEM_Base
11 11
 {
12
-    // private instance of the Attendee object
13
-    protected static $_instance = null;
12
+	// private instance of the Attendee object
13
+	protected static $_instance = null;
14 14
 
15 15
 
16
-    /**
17
-     * @param string|null $timezone
18
-     * @throws EE_Error
19
-     */
20
-    protected function __construct(?string $timezone = '')
21
-    {
22
-        $this->singular_item    = esc_html__('Currency', 'event_espresso');
23
-        $this->plural_item      = esc_html__('Currencies', 'event_espresso');
24
-        $this->_tables          = [
25
-            'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code'),
26
-        ];
27
-        $this->_fields          = [
28
-            'Currency' => [
29
-                'CUR_code'    => new EE_Primary_Key_String_Field(
30
-                    'CUR_code',
31
-                    esc_html__('Currency Code', 'event_espresso')
32
-                )
33
-                ,
34
-                'CUR_single'  => new EE_Plain_Text_Field(
35
-                    'CUR_single',
36
-                    esc_html__('Currency Name Singular', 'event_espresso'),
37
-                    false
38
-                ),
39
-                'CUR_plural'  => new EE_Plain_Text_Field(
40
-                    'CUR_plural',
41
-                    esc_html__('Currency Name Plural', 'event_espresso'),
42
-                    false
43
-                ),
44
-                'CUR_sign'    => new EE_Plain_Text_Field(
45
-                    'CUR_sign',
46
-                    esc_html__('Currency Sign', 'event_espresso'),
47
-                    false
48
-                ),
49
-                'CUR_dec_plc' => new EE_Integer_Field(
50
-                    'CUR_dec_plc',
51
-                    esc_html__('Currency Decimal Places', 'event_espresso'),
52
-                    false,
53
-                    2
54
-                ),
55
-                'CUR_active'  => new EE_Boolean_Field(
56
-                    'CUR_active',
57
-                    esc_html__('Active?', 'event_espresso'),
58
-                    false,
59
-                    true
60
-                ),
61
-            ],
62
-        ];
63
-        $this->_model_relations = [
64
-            'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
65
-        ];
66
-        // this model is generally available for reading
67
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
16
+	/**
17
+	 * @param string|null $timezone
18
+	 * @throws EE_Error
19
+	 */
20
+	protected function __construct(?string $timezone = '')
21
+	{
22
+		$this->singular_item    = esc_html__('Currency', 'event_espresso');
23
+		$this->plural_item      = esc_html__('Currencies', 'event_espresso');
24
+		$this->_tables          = [
25
+			'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code'),
26
+		];
27
+		$this->_fields          = [
28
+			'Currency' => [
29
+				'CUR_code'    => new EE_Primary_Key_String_Field(
30
+					'CUR_code',
31
+					esc_html__('Currency Code', 'event_espresso')
32
+				)
33
+				,
34
+				'CUR_single'  => new EE_Plain_Text_Field(
35
+					'CUR_single',
36
+					esc_html__('Currency Name Singular', 'event_espresso'),
37
+					false
38
+				),
39
+				'CUR_plural'  => new EE_Plain_Text_Field(
40
+					'CUR_plural',
41
+					esc_html__('Currency Name Plural', 'event_espresso'),
42
+					false
43
+				),
44
+				'CUR_sign'    => new EE_Plain_Text_Field(
45
+					'CUR_sign',
46
+					esc_html__('Currency Sign', 'event_espresso'),
47
+					false
48
+				),
49
+				'CUR_dec_plc' => new EE_Integer_Field(
50
+					'CUR_dec_plc',
51
+					esc_html__('Currency Decimal Places', 'event_espresso'),
52
+					false,
53
+					2
54
+				),
55
+				'CUR_active'  => new EE_Boolean_Field(
56
+					'CUR_active',
57
+					esc_html__('Active?', 'event_espresso'),
58
+					false,
59
+					true
60
+				),
61
+			],
62
+		];
63
+		$this->_model_relations = [
64
+			'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
65
+		];
66
+		// this model is generally available for reading
67
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
68 68
 
69
-        parent::__construct($timezone);
70
-    }
69
+		parent::__construct($timezone);
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * Gets all the active currencies, and orders them by their singular name, and then their code
75
-     * (may be overridden)
76
-     *
77
-     * @param array $query_params
78
-     * @return EE_Currency[]
79
-     * @throws EE_Error
80
-     * @throws ReflectionException
81
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
82
-     */
83
-    public function get_all_active($query_params = [])
84
-    {
85
-        $query_params[0]['CUR_active'] = true;
86
-        if (! isset($query_params['order_by'])) {
87
-            $query_params['order_by'] = ['CUR_code' => 'ASC', 'CUR_single' => 'ASC'];
88
-        }
89
-        return $this->get_all($query_params);
90
-    }
73
+	/**
74
+	 * Gets all the active currencies, and orders them by their singular name, and then their code
75
+	 * (may be overridden)
76
+	 *
77
+	 * @param array $query_params
78
+	 * @return EE_Currency[]
79
+	 * @throws EE_Error
80
+	 * @throws ReflectionException
81
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
82
+	 */
83
+	public function get_all_active($query_params = [])
84
+	{
85
+		$query_params[0]['CUR_active'] = true;
86
+		if (! isset($query_params['order_by'])) {
87
+			$query_params['order_by'] = ['CUR_code' => 'ASC', 'CUR_single' => 'ASC'];
88
+		}
89
+		return $this->get_all($query_params);
90
+	}
91 91
 
92 92
 
93
-    /**
94
-     * Gets all the currencies which can be used by that payment method type
95
-     *
96
-     * @param EE_PMT_Base $payment_method_type
97
-     * @return EE_Currency[]
98
-     * @throws EE_Error
99
-     * @throws ReflectionException
100
-     */
101
-    public function get_all_currencies_usable_by($payment_method_type)
102
-    {
103
-        if (
104
-            $payment_method_type instanceof EE_PMT_Base
105
-            && $payment_method_type->get_gateway()
106
-        ) {
107
-            $currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
108
-        } else {
109
-            $currencies_supported = EE_Gateway::all_currencies_supported;
110
-        }
111
-        if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
112
-            $currencies = $this->get_all_active();
113
-        } else {
114
-            $currencies = $this->get_all_active([['CUR_code' => ['IN', $currencies_supported]]]);
115
-        }
116
-        return $currencies;
117
-    }
93
+	/**
94
+	 * Gets all the currencies which can be used by that payment method type
95
+	 *
96
+	 * @param EE_PMT_Base $payment_method_type
97
+	 * @return EE_Currency[]
98
+	 * @throws EE_Error
99
+	 * @throws ReflectionException
100
+	 */
101
+	public function get_all_currencies_usable_by($payment_method_type)
102
+	{
103
+		if (
104
+			$payment_method_type instanceof EE_PMT_Base
105
+			&& $payment_method_type->get_gateway()
106
+		) {
107
+			$currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
108
+		} else {
109
+			$currencies_supported = EE_Gateway::all_currencies_supported;
110
+		}
111
+		if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
112
+			$currencies = $this->get_all_active();
113
+		} else {
114
+			$currencies = $this->get_all_active([['CUR_code' => ['IN', $currencies_supported]]]);
115
+		}
116
+		return $currencies;
117
+	}
118 118
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Term_Taxonomy.model.php 2 patches
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -10,139 +10,139 @@
 block discarded – undo
10 10
  */
11 11
 class EEM_Term_Taxonomy extends EEM_Base
12 12
 {
13
-    /**
14
-     * @var EEM_Term_Taxonomy
15
-     */
16
-    protected static $_instance = null;
13
+	/**
14
+	 * @var EEM_Term_Taxonomy
15
+	 */
16
+	protected static $_instance = null;
17 17
 
18 18
 
19
-    /**
20
-     * @param string|null $timezone
21
-     * @throws EE_Error
22
-     */
23
-    protected function __construct(?string $timezone = '')
24
-    {
25
-        $this->singular_item    = esc_html__('Term Taxonomy', 'event_espresso');
26
-        $this->plural_item      = esc_html__('Term Taxonomy', 'event_espresso');
27
-        $this->_tables          = [
28
-            'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'),
29
-        ];
30
-        $this->_fields          = [
31
-            'Term_Taxonomy' => [
32
-                'term_taxonomy_id' => new EE_Primary_Key_Int_Field(
33
-                    'term_taxonomy_id',
34
-                    esc_html__('Term-Taxonomy ID', 'event_espresso')
35
-                ),
36
-                'term_id'          => new EE_Foreign_Key_Int_Field(
37
-                    'term_id',
38
-                    esc_html__("Term Id", "event_espresso"),
39
-                    false,
40
-                    0,
41
-                    'Term'
42
-                ),
43
-                'taxonomy'         => new EE_Plain_Text_Field(
44
-                    'taxonomy',
45
-                    esc_html__('Taxonomy Name', 'event_espresso'),
46
-                    false,
47
-                    'category'
48
-                ),
49
-                'description'      => new EE_Post_Content_Field(
50
-                    'description',
51
-                    esc_html__("Description of Term", "event_espresso"),
52
-                    false,
53
-                    ''
54
-                ),
55
-                'parent'           => new EE_Integer_Field(
56
-                    'parent',
57
-                    esc_html__("Parent Term ID", "event_espresso"),
58
-                    false,
59
-                    0
60
-                ),
61
-                'term_count'       => new EE_Integer_Field(
62
-                    'count',
63
-                    esc_html__("Count of Objects attached", 'event_espresso'),
64
-                    false,
65
-                    0
66
-                ),
67
-            ],
68
-        ];
69
-        $this->_model_relations = [
70
-            'Term_Relationship' => new EE_Has_Many_Relation(),
71
-            'Term'              => new EE_Belongs_To_Relation(),
72
-        ];
73
-        $cpt_models             = array_keys(EE_Registry::instance()->cpt_models());
74
-        foreach ($cpt_models as $model_name) {
75
-            $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship');
76
-        }
77
-        $this->_wp_core_model                                           = true;
78
-        $this->_indexes                                                 = [
79
-            'term_id_taxonomy' => new EE_Unique_Index(['term_id', 'taxonomy']),
80
-        ];
81
-        $path_to_tax_model                                              = '';
82
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Public();
83
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
84
-            new EE_Restriction_Generator_Taxonomy_Protected(
85
-                $path_to_tax_model
86
-            );
87
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = false;
88
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = false;
89
-        // add cap restrictions for editing relating to the "ee_edit_*"
90
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
91
-            [
92
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
93
-            ]
94
-        );
95
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
96
-            [
97
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
98
-            ]
99
-        );
100
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type']     = new EE_Default_Where_Conditions(
101
-            [
102
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
103
-            ]
104
-        );
105
-        // add cap restrictions for deleting relating to the "ee_deleting_*"
106
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
107
-            [
108
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
109
-            ]
110
-        );
111
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
112
-            [
113
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
114
-            ]
115
-        );
116
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type']     = new EE_Default_Where_Conditions(
117
-            [
118
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
119
-            ]
120
-        );
121
-        parent::__construct($timezone);
122
-        add_filter('FHEE__Read__create_model_query_params', ['EEM_Term_Taxonomy', 'rest_api_query_params'], 10, 3);
123
-    }
19
+	/**
20
+	 * @param string|null $timezone
21
+	 * @throws EE_Error
22
+	 */
23
+	protected function __construct(?string $timezone = '')
24
+	{
25
+		$this->singular_item    = esc_html__('Term Taxonomy', 'event_espresso');
26
+		$this->plural_item      = esc_html__('Term Taxonomy', 'event_espresso');
27
+		$this->_tables          = [
28
+			'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'),
29
+		];
30
+		$this->_fields          = [
31
+			'Term_Taxonomy' => [
32
+				'term_taxonomy_id' => new EE_Primary_Key_Int_Field(
33
+					'term_taxonomy_id',
34
+					esc_html__('Term-Taxonomy ID', 'event_espresso')
35
+				),
36
+				'term_id'          => new EE_Foreign_Key_Int_Field(
37
+					'term_id',
38
+					esc_html__("Term Id", "event_espresso"),
39
+					false,
40
+					0,
41
+					'Term'
42
+				),
43
+				'taxonomy'         => new EE_Plain_Text_Field(
44
+					'taxonomy',
45
+					esc_html__('Taxonomy Name', 'event_espresso'),
46
+					false,
47
+					'category'
48
+				),
49
+				'description'      => new EE_Post_Content_Field(
50
+					'description',
51
+					esc_html__("Description of Term", "event_espresso"),
52
+					false,
53
+					''
54
+				),
55
+				'parent'           => new EE_Integer_Field(
56
+					'parent',
57
+					esc_html__("Parent Term ID", "event_espresso"),
58
+					false,
59
+					0
60
+				),
61
+				'term_count'       => new EE_Integer_Field(
62
+					'count',
63
+					esc_html__("Count of Objects attached", 'event_espresso'),
64
+					false,
65
+					0
66
+				),
67
+			],
68
+		];
69
+		$this->_model_relations = [
70
+			'Term_Relationship' => new EE_Has_Many_Relation(),
71
+			'Term'              => new EE_Belongs_To_Relation(),
72
+		];
73
+		$cpt_models             = array_keys(EE_Registry::instance()->cpt_models());
74
+		foreach ($cpt_models as $model_name) {
75
+			$this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship');
76
+		}
77
+		$this->_wp_core_model                                           = true;
78
+		$this->_indexes                                                 = [
79
+			'term_id_taxonomy' => new EE_Unique_Index(['term_id', 'taxonomy']),
80
+		];
81
+		$path_to_tax_model                                              = '';
82
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Public();
83
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
84
+			new EE_Restriction_Generator_Taxonomy_Protected(
85
+				$path_to_tax_model
86
+			);
87
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = false;
88
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = false;
89
+		// add cap restrictions for editing relating to the "ee_edit_*"
90
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
91
+			[
92
+				$path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
93
+			]
94
+		);
95
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
96
+			[
97
+				$path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
98
+			]
99
+		);
100
+		$this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type']     = new EE_Default_Where_Conditions(
101
+			[
102
+				$path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
103
+			]
104
+		);
105
+		// add cap restrictions for deleting relating to the "ee_deleting_*"
106
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
107
+			[
108
+				$path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
109
+			]
110
+		);
111
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
112
+			[
113
+				$path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
114
+			]
115
+		);
116
+		$this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type']     = new EE_Default_Where_Conditions(
117
+			[
118
+				$path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
119
+			]
120
+		);
121
+		parent::__construct($timezone);
122
+		add_filter('FHEE__Read__create_model_query_params', ['EEM_Term_Taxonomy', 'rest_api_query_params'], 10, 3);
123
+	}
124 124
 
125 125
 
126
-    /**
127
-     * Makes sure that during REST API queries, we only return term-taxonomies
128
-     * for term taxonomies which should be shown in the rest api
129
-     *
130
-     * @param array    $model_query_params
131
-     * @param array    $querystring_query_params
132
-     * @param EEM_Base $model
133
-     * @return array
134
-     * @throws EE_Error
135
-     */
136
-    public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
137
-    {
138
-        if ($model === EEM_Term_Taxonomy::instance()) {
139
-            $taxonomies = get_taxonomies(['show_in_rest' => true]);
140
-            if (! empty($taxonomies)) {
141
-                $model_query_params[0]['taxonomy'] = ['IN', $taxonomies];
142
-            }
143
-        }
144
-        return $model_query_params;
145
-    }
126
+	/**
127
+	 * Makes sure that during REST API queries, we only return term-taxonomies
128
+	 * for term taxonomies which should be shown in the rest api
129
+	 *
130
+	 * @param array    $model_query_params
131
+	 * @param array    $querystring_query_params
132
+	 * @param EEM_Base $model
133
+	 * @return array
134
+	 * @throws EE_Error
135
+	 */
136
+	public static function rest_api_query_params($model_query_params, $querystring_query_params, $model)
137
+	{
138
+		if ($model === EEM_Term_Taxonomy::instance()) {
139
+			$taxonomies = get_taxonomies(['show_in_rest' => true]);
140
+			if (! empty($taxonomies)) {
141
+				$model_query_params[0]['taxonomy'] = ['IN', $taxonomies];
142
+			}
143
+		}
144
+		return $model_query_params;
145
+	}
146 146
 }
147 147
 // End of file EEM_Term_Taxonomy.model.php
148 148
 // Location: /includes/models/EEM_Term_Taxonomy.model.php
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -70,52 +70,52 @@  discard block
 block discarded – undo
70 70
             'Term_Relationship' => new EE_Has_Many_Relation(),
71 71
             'Term'              => new EE_Belongs_To_Relation(),
72 72
         ];
73
-        $cpt_models             = array_keys(EE_Registry::instance()->cpt_models());
73
+        $cpt_models = array_keys(EE_Registry::instance()->cpt_models());
74 74
         foreach ($cpt_models as $model_name) {
75
-            $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship');
75
+            $this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship');
76 76
         }
77 77
         $this->_wp_core_model                                           = true;
78 78
         $this->_indexes                                                 = [
79 79
             'term_id_taxonomy' => new EE_Unique_Index(['term_id', 'taxonomy']),
80 80
         ];
81 81
         $path_to_tax_model                                              = '';
82
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       = new EE_Restriction_Generator_Public();
83
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
82
+        $this->_cap_restriction_generators[EEM_Base::caps_read]       = new EE_Restriction_Generator_Public();
83
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] =
84 84
             new EE_Restriction_Generator_Taxonomy_Protected(
85 85
                 $path_to_tax_model
86 86
             );
87
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       = false;
88
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     = false;
87
+        $this->_cap_restriction_generators[EEM_Base::caps_edit]       = false;
88
+        $this->_cap_restriction_generators[EEM_Base::caps_delete]     = false;
89 89
         // add cap restrictions for editing relating to the "ee_edit_*"
90
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
90
+        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions(
91 91
             [
92
-                $path_to_tax_model . 'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
92
+                $path_to_tax_model.'taxonomy*ee_edit_event_category' => ['!=', 'espresso_event_categories'],
93 93
             ]
94 94
         );
95
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
95
+        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions(
96 96
             [
97
-                $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
97
+                $path_to_tax_model.'taxonomy*ee_edit_venue_category' => ['!=', 'espresso_venue_categories'],
98 98
             ]
99 99
         );
100
-        $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type']     = new EE_Default_Where_Conditions(
100
+        $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions(
101 101
             [
102
-                $path_to_tax_model . 'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
102
+                $path_to_tax_model.'taxonomy*ee_edit_event_type' => ['!=', 'espresso_event_type'],
103 103
             ]
104 104
         );
105 105
         // add cap restrictions for deleting relating to the "ee_deleting_*"
106
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
106
+        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions(
107 107
             [
108
-                $path_to_tax_model . 'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
108
+                $path_to_tax_model.'taxonomy*ee_delete_event_category' => ['!=', 'espresso_event_categories'],
109 109
             ]
110 110
         );
111
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
111
+        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions(
112 112
             [
113
-                $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
113
+                $path_to_tax_model.'taxonomy*ee_delete_venue_category' => ['!=', 'espresso_venue_categories'],
114 114
             ]
115 115
         );
116
-        $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type']     = new EE_Default_Where_Conditions(
116
+        $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions(
117 117
             [
118
-                $path_to_tax_model . 'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
118
+                $path_to_tax_model.'taxonomy*ee_delete_event_type' => ['!=', 'espresso_event_type'],
119 119
             ]
120 120
         );
121 121
         parent::__construct($timezone);
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
     {
138 138
         if ($model === EEM_Term_Taxonomy::instance()) {
139 139
             $taxonomies = get_taxonomies(['show_in_rest' => true]);
140
-            if (! empty($taxonomies)) {
140
+            if ( ! empty($taxonomies)) {
141 141
                 $model_query_params[0]['taxonomy'] = ['IN', $taxonomies];
142 142
             }
143 143
         }
Please login to merge, or discard this patch.
core/db_models/relations/EE_HABTM_Any_Relation.php 2 patches
Indentation   +262 added lines, -262 removed lines patch added patch discarded remove patch
@@ -10,291 +10,291 @@
 block discarded – undo
10 10
  */
11 11
 class EE_HABTM_Any_Relation extends EE_HABTM_Relation
12 12
 {
13
-    protected string $_alphabetically_first_model_name = '';
13
+	protected string $_alphabetically_first_model_name = '';
14 14
 
15 15
 
16
-    /**
17
-     * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
18
-     * (and an ee joining-model.) This knows how to join the models,
19
-     * get related models across the relation, and add-and-remove the relationships.
20
-     *
21
-     * @param bool   $block_deletes                  for this type of relation, we block by default for now. if there
22
-     *                                               are related models across this relation, block (prevent and add an
23
-     *                                               error) the deletion of this model
24
-     * @param string $blocking_delete_error_message  a customized error message on blocking deletes instead of the
25
-     *                                               default
26
-     */
27
-    public function __construct(bool $block_deletes = true, string $blocking_delete_error_message = '')
28
-    {
29
-        parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
30
-    }
16
+	/**
17
+	 * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
18
+	 * (and an ee joining-model.) This knows how to join the models,
19
+	 * get related models across the relation, and add-and-remove the relationships.
20
+	 *
21
+	 * @param bool   $block_deletes                  for this type of relation, we block by default for now. if there
22
+	 *                                               are related models across this relation, block (prevent and add an
23
+	 *                                               error) the deletion of this model
24
+	 * @param string $blocking_delete_error_message  a customized error message on blocking deletes instead of the
25
+	 *                                               default
26
+	 */
27
+	public function __construct(bool $block_deletes = true, string $blocking_delete_error_message = '')
28
+	{
29
+		parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
30
+	}
31 31
 
32 32
 
33
-    /**
34
-     * @param $this_model_name
35
-     * @param $other_model_name
36
-     */
37
-    public function _construct_finalize_set_models($this_model_name, $other_model_name)
38
-    {
39
-        $this->_alphabetically_first_model_name = min($this_model_name, $other_model_name);
40
-        parent::_construct_finalize_set_models($this_model_name, $other_model_name);
41
-    }
33
+	/**
34
+	 * @param $this_model_name
35
+	 * @param $other_model_name
36
+	 */
37
+	public function _construct_finalize_set_models($this_model_name, $other_model_name)
38
+	{
39
+		$this->_alphabetically_first_model_name = min($this_model_name, $other_model_name);
40
+		parent::_construct_finalize_set_models($this_model_name, $other_model_name);
41
+	}
42 42
 
43 43
 
44
-    /**
45
-     * @param string $model_name
46
-     * @param string $id_or_name_field should be the string 'ID' or 'name' only
47
-     * @return EE_Model_Field_Base
48
-     * @throws EE_Error
49
-     * @throws Exception
50
-     */
51
-    public function get_join_table_fk_field_to(string $model_name, string $id_or_name_field): EE_Model_Field_Base
52
-    {
53
-        $order = $model_name === $this->_alphabetically_first_model_name ? 'first' : 'second';
54
-        return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
55
-    }
44
+	/**
45
+	 * @param string $model_name
46
+	 * @param string $id_or_name_field should be the string 'ID' or 'name' only
47
+	 * @return EE_Model_Field_Base
48
+	 * @throws EE_Error
49
+	 * @throws Exception
50
+	 */
51
+	public function get_join_table_fk_field_to(string $model_name, string $id_or_name_field): EE_Model_Field_Base
52
+	{
53
+		$order = $model_name === $this->_alphabetically_first_model_name ? 'first' : 'second';
54
+		return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
55
+	}
56 56
 
57 57
 
58
-    /**
59
-     * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
60
-     * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
61
-     *
62
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
63
-     * @return string of SQL
64
-     * @throws EE_Error
65
-     * @throws Exception
66
-     */
67
-    public function get_join_to_intermediate_model_statement(string $model_relation_chain): string
68
-    {
69
-        // create sql like
70
-        // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
71
-        // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
72
-        // remember the model relation chain to the JOIN model, because we'll
73
-        // need it for get_join_statement()
74
-        $this->_model_relation_chain_to_join_model = $model_relation_chain;
75
-        $this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();
76
-        $join_table_fk_field_to_this_table         = $this->get_join_table_fk_field_to(
77
-            $this->get_this_model()->get_this_model_name(),
78
-            'ID'
79
-        );
80
-        $field_with_model_name                     = $this->get_join_table_fk_field_to(
81
-            $this->get_this_model()->get_this_model_name(),
82
-            'name'
83
-        );
84
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
85
-                $model_relation_chain,
86
-                $this->get_this_model()->get_this_model_name()
87
-            ) . $this_table_pk_field->get_table_alias();
88
-        $join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
89
-                $model_relation_chain,
90
-                $this->get_join_model()->get_this_model_name()
91
-            ) . $join_table_fk_field_to_this_table->get_table_alias();
92
-        $join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
93
-        // phew! ok, we have all the info we need, now we can create the SQL join string
94
-        return $this->_left_join(
95
-                $join_table,
96
-                $join_table_alias,
97
-                $join_table_fk_field_to_this_table->get_table_column(),
98
-                $this_table_alias,
99
-                $this_table_pk_field->get_table_column(),
100
-                $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name(
101
-                ) . "'"
102
-            ) .
103
-               $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
104
-    }
58
+	/**
59
+	 * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
60
+	 * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
61
+	 *
62
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
63
+	 * @return string of SQL
64
+	 * @throws EE_Error
65
+	 * @throws Exception
66
+	 */
67
+	public function get_join_to_intermediate_model_statement(string $model_relation_chain): string
68
+	{
69
+		// create sql like
70
+		// LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
71
+		// LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
72
+		// remember the model relation chain to the JOIN model, because we'll
73
+		// need it for get_join_statement()
74
+		$this->_model_relation_chain_to_join_model = $model_relation_chain;
75
+		$this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();
76
+		$join_table_fk_field_to_this_table         = $this->get_join_table_fk_field_to(
77
+			$this->get_this_model()->get_this_model_name(),
78
+			'ID'
79
+		);
80
+		$field_with_model_name                     = $this->get_join_table_fk_field_to(
81
+			$this->get_this_model()->get_this_model_name(),
82
+			'name'
83
+		);
84
+		$this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
85
+				$model_relation_chain,
86
+				$this->get_this_model()->get_this_model_name()
87
+			) . $this_table_pk_field->get_table_alias();
88
+		$join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
89
+				$model_relation_chain,
90
+				$this->get_join_model()->get_this_model_name()
91
+			) . $join_table_fk_field_to_this_table->get_table_alias();
92
+		$join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
93
+		// phew! ok, we have all the info we need, now we can create the SQL join string
94
+		return $this->_left_join(
95
+				$join_table,
96
+				$join_table_alias,
97
+				$join_table_fk_field_to_this_table->get_table_column(),
98
+				$this_table_alias,
99
+				$this_table_pk_field->get_table_column(),
100
+				$field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name(
101
+				) . "'"
102
+			) .
103
+			   $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
109
-     * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
110
-     * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
111
-     * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
112
-     * the intermediate join table, and then to the other model's pk's table
113
-     *
114
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
115
-     * @return string of SQL
116
-     * @throws EE_Error
117
-     * @throws Exception
118
-     */
119
-    public function get_join_statement(string $model_relation_chain): string
120
-    {
121
-        if (empty($this->_model_relation_chain_to_join_model)) {
122
-            throw new EE_Error(
123
-                esc_html__(
124
-                    'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
125
-                    'event_espresso'
126
-                )
127
-            );
128
-        }
129
-        $join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
130
-            $this->get_this_model()->get_this_model_name(),
131
-            'ID'
132
-        );
133
-        $join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to(
134
-            $this->get_other_model()->get_this_model_name(),
135
-            'ID'
136
-        );
137
-        $field_with_other_model_name        = $this->get_join_table_fk_field_to(
138
-            $this->get_other_model()->get_this_model_name(),
139
-            'name'
140
-        );
107
+	/**
108
+	 * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
109
+	 * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
110
+	 * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
111
+	 * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
112
+	 * the intermediate join table, and then to the other model's pk's table
113
+	 *
114
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
115
+	 * @return string of SQL
116
+	 * @throws EE_Error
117
+	 * @throws Exception
118
+	 */
119
+	public function get_join_statement(string $model_relation_chain): string
120
+	{
121
+		if (empty($this->_model_relation_chain_to_join_model)) {
122
+			throw new EE_Error(
123
+				esc_html__(
124
+					'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
125
+					'event_espresso'
126
+				)
127
+			);
128
+		}
129
+		$join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
130
+			$this->get_this_model()->get_this_model_name(),
131
+			'ID'
132
+		);
133
+		$join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to(
134
+			$this->get_other_model()->get_this_model_name(),
135
+			'ID'
136
+		);
137
+		$field_with_other_model_name        = $this->get_join_table_fk_field_to(
138
+			$this->get_other_model()->get_this_model_name(),
139
+			'name'
140
+		);
141 141
 
142
-        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
143
-                $this->_model_relation_chain_to_join_model,
144
-                $this->get_join_model()->get_this_model_name()
145
-            ) . $join_table_fk_field_to_this_table->get_table_alias();
142
+		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
143
+				$this->_model_relation_chain_to_join_model,
144
+				$this->get_join_model()->get_this_model_name()
145
+			) . $join_table_fk_field_to_this_table->get_table_alias();
146 146
 
147
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
148
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
149
-                $model_relation_chain,
150
-                $this->get_other_model()->get_this_model_name()
151
-            ) . $other_table_pk_field->get_table_alias();
152
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
147
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
148
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
149
+				$model_relation_chain,
150
+				$this->get_other_model()->get_this_model_name()
151
+			) . $other_table_pk_field->get_table_alias();
152
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
153 153
 
154
-        return $this->_left_join(
155
-                $other_table,
156
-                $other_table_alias,
157
-                $other_table_pk_field->get_table_column(),
158
-                $join_table_alias,
159
-                $join_table_fk_field_to_other_table->get_table_column(),
160
-                $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()
161
-                                                                                   ->get_this_model_name() . "'"
162
-            ) .
163
-               $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
164
-    }
154
+		return $this->_left_join(
155
+				$other_table,
156
+				$other_table_alias,
157
+				$other_table_pk_field->get_table_column(),
158
+				$join_table_alias,
159
+				$join_table_fk_field_to_other_table->get_table_column(),
160
+				$field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()
161
+																				   ->get_this_model_name() . "'"
162
+			) .
163
+			   $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
169
-     *
170
-     * @param EE_Base_Class|int $this_obj_or_id
171
-     * @param EE_Base_Class|int $other_obj_or_id
172
-     * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
173
-     *                                                            checking existing values and for setting new rows if
174
-     *                                                            no exact matches.
175
-     * @return EE_Base_Class
176
-     * @throws EE_Error
177
-     * @throws Exception
178
-     */
179
-    public function add_relation_to(
180
-        $this_obj_or_id,
181
-        $other_obj_or_id,
182
-        array $extra_join_model_fields_n_values = []
183
-    ): EE_Base_Class {
184
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
185
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
186
-        // check if such a relationship already exists
187
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
188
-            $this->get_this_model()->get_this_model_name(),
189
-            'ID'
190
-        );
191
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
192
-            $this->get_this_model()->get_this_model_name(),
193
-            'name'
194
-        );
195
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
196
-            $this->get_other_model()->get_this_model_name(),
197
-            'ID'
198
-        );
199
-        $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
200
-            $this->get_other_model()->get_this_model_name(),
201
-            'name'
202
-        );
167
+	/**
168
+	 * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
169
+	 *
170
+	 * @param EE_Base_Class|int $this_obj_or_id
171
+	 * @param EE_Base_Class|int $other_obj_or_id
172
+	 * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
173
+	 *                                                            checking existing values and for setting new rows if
174
+	 *                                                            no exact matches.
175
+	 * @return EE_Base_Class
176
+	 * @throws EE_Error
177
+	 * @throws Exception
178
+	 */
179
+	public function add_relation_to(
180
+		$this_obj_or_id,
181
+		$other_obj_or_id,
182
+		array $extra_join_model_fields_n_values = []
183
+	): EE_Base_Class {
184
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
185
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
186
+		// check if such a relationship already exists
187
+		$join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
188
+			$this->get_this_model()->get_this_model_name(),
189
+			'ID'
190
+		);
191
+		$join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
192
+			$this->get_this_model()->get_this_model_name(),
193
+			'name'
194
+		);
195
+		$join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
196
+			$this->get_other_model()->get_this_model_name(),
197
+			'ID'
198
+		);
199
+		$join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
200
+			$this->get_other_model()->get_this_model_name(),
201
+			'name'
202
+		);
203 203
 
204
-        $cols_n_values = [
205
-            $join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
206
-            $join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
207
-            $join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
208
-            $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
209
-        ];
204
+		$cols_n_values = [
205
+			$join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
206
+			$join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
207
+			$join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
208
+			$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
209
+		];
210 210
 
211
-        // if $where_query exists lets add them to the query_params.
212
-        if (! empty($extra_join_model_fields_n_values)) {
213
-            // 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)
214
-            // make sure we strip THIS models name from the query param
215
-            $parsed_query = [];
216
-            foreach ($extra_join_model_fields_n_values as $query_param => $val) {
217
-                $query_param                  = str_replace(
218
-                    $this->get_join_model()->get_this_model_name() . ".",
219
-                    "",
220
-                    $query_param
221
-                );
222
-                $parsed_query[ $query_param ] = $val;
223
-            }
224
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
225
-        }
211
+		// if $where_query exists lets add them to the query_params.
212
+		if (! empty($extra_join_model_fields_n_values)) {
213
+			// 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)
214
+			// make sure we strip THIS models name from the query param
215
+			$parsed_query = [];
216
+			foreach ($extra_join_model_fields_n_values as $query_param => $val) {
217
+				$query_param                  = str_replace(
218
+					$this->get_join_model()->get_this_model_name() . ".",
219
+					"",
220
+					$query_param
221
+				);
222
+				$parsed_query[ $query_param ] = $val;
223
+			}
224
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
225
+		}
226 226
 
227
-        $query_params = [$cols_n_values];
227
+		$query_params = [$cols_n_values];
228 228
 
229 229
 
230
-        $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
231
-        // if there is already an entry in the join table, indicating a relationship, we're done
232
-        // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
233
-        // the other tables, use the joining model directly!
234
-        if (! $existing_entry_in_join_table) {
235
-            $this->get_join_model()->insert($cols_n_values);
236
-        }
237
-        return $other_model_obj;
238
-    }
230
+		$existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
231
+		// if there is already an entry in the join table, indicating a relationship, we're done
232
+		// again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
233
+		// the other tables, use the joining model directly!
234
+		if (! $existing_entry_in_join_table) {
235
+			$this->get_join_model()->insert($cols_n_values);
236
+		}
237
+		return $other_model_obj;
238
+	}
239 239
 
240 240
 
241
-    /**
242
-     * Deletes any rows in the join table that have foreign keys matching the other model objects specified
243
-     *
244
-     * @param EE_Base_Class|int $this_obj_or_id
245
-     * @param EE_Base_Class|int $other_obj_or_id
246
-     * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
247
-     *                                       values and for removing existing rows if exact matches exist.
248
-     * @return EE_Base_Class
249
-     * @throws EE_Error
250
-     * @throws Exception
251
-     */
252
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, array $where_query = []): EE_Base_Class
253
-    {
254
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
255
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
256
-        // check if such a relationship already exists
257
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
258
-            $this->get_this_model()->get_this_model_name(),
259
-            'ID'
260
-        );
261
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
262
-            $this->get_this_model()->get_this_model_name(),
263
-            'name'
264
-        );
265
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
266
-            $this->get_other_model()->get_this_model_name(),
267
-            'ID'
268
-        );
269
-        $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
270
-            $this->get_other_model()->get_this_model_name(),
271
-            'name'
272
-        );
241
+	/**
242
+	 * Deletes any rows in the join table that have foreign keys matching the other model objects specified
243
+	 *
244
+	 * @param EE_Base_Class|int $this_obj_or_id
245
+	 * @param EE_Base_Class|int $other_obj_or_id
246
+	 * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
247
+	 *                                       values and for removing existing rows if exact matches exist.
248
+	 * @return EE_Base_Class
249
+	 * @throws EE_Error
250
+	 * @throws Exception
251
+	 */
252
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, array $where_query = []): EE_Base_Class
253
+	{
254
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
255
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
256
+		// check if such a relationship already exists
257
+		$join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
258
+			$this->get_this_model()->get_this_model_name(),
259
+			'ID'
260
+		);
261
+		$join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
262
+			$this->get_this_model()->get_this_model_name(),
263
+			'name'
264
+		);
265
+		$join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
266
+			$this->get_other_model()->get_this_model_name(),
267
+			'ID'
268
+		);
269
+		$join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
270
+			$this->get_other_model()->get_this_model_name(),
271
+			'name'
272
+		);
273 273
 
274
-        $cols_n_values = [
275
-            $join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
276
-            $join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
277
-            $join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
278
-            $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
279
-        ];
274
+		$cols_n_values = [
275
+			$join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
276
+			$join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
277
+			$join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
278
+			$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
279
+		];
280 280
 
281
-        // if $where_query exists lets add them to the query_params.
282
-        if (! empty($where_query)) {
283
-            // 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)
284
-            // make sure we strip THIS models name from the query param
285
-            $parsed_query = [];
286
-            foreach ($where_query as $query_param => $val) {
287
-                $query_param                  = str_replace(
288
-                    $this->get_join_model()->get_this_model_name() . ".",
289
-                    "",
290
-                    $query_param
291
-                );
292
-                $parsed_query[ $query_param ] = $val;
293
-            }
294
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
295
-        }
281
+		// if $where_query exists lets add them to the query_params.
282
+		if (! empty($where_query)) {
283
+			// 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)
284
+			// make sure we strip THIS models name from the query param
285
+			$parsed_query = [];
286
+			foreach ($where_query as $query_param => $val) {
287
+				$query_param                  = str_replace(
288
+					$this->get_join_model()->get_this_model_name() . ".",
289
+					"",
290
+					$query_param
291
+				);
292
+				$parsed_query[ $query_param ] = $val;
293
+			}
294
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
295
+		}
296 296
 
297
-        $this->get_join_model()->delete([$cols_n_values]);
298
-        return $other_model_obj;
299
-    }
297
+		$this->get_join_model()->delete([$cols_n_values]);
298
+		return $other_model_obj;
299
+	}
300 300
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
     public function get_join_table_fk_field_to(string $model_name, string $id_or_name_field): EE_Model_Field_Base
52 52
     {
53 53
         $order = $model_name === $this->_alphabetically_first_model_name ? 'first' : 'second';
54
-        return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
54
+        return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field);
55 55
     }
56 56
 
57 57
 
@@ -77,19 +77,19 @@  discard block
 block discarded – undo
77 77
             $this->get_this_model()->get_this_model_name(),
78 78
             'ID'
79 79
         );
80
-        $field_with_model_name                     = $this->get_join_table_fk_field_to(
80
+        $field_with_model_name = $this->get_join_table_fk_field_to(
81 81
             $this->get_this_model()->get_this_model_name(),
82 82
             'name'
83 83
         );
84
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
84
+        $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
85 85
                 $model_relation_chain,
86 86
                 $this->get_this_model()->get_this_model_name()
87
-            ) . $this_table_pk_field->get_table_alias();
88
-        $join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
87
+            ).$this_table_pk_field->get_table_alias();
88
+        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
89 89
                 $model_relation_chain,
90 90
                 $this->get_join_model()->get_this_model_name()
91
-            ) . $join_table_fk_field_to_this_table->get_table_alias();
92
-        $join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
91
+            ).$join_table_fk_field_to_this_table->get_table_alias();
92
+        $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias);
93 93
         // phew! ok, we have all the info we need, now we can create the SQL join string
94 94
         return $this->_left_join(
95 95
                 $join_table,
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
                 $join_table_fk_field_to_this_table->get_table_column(),
98 98
                 $this_table_alias,
99 99
                 $this_table_pk_field->get_table_column(),
100
-                $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name(
101
-                ) . "'"
102
-            ) .
100
+                $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name(
101
+                )."'"
102
+            ).
103 103
                $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
104 104
     }
105 105
 
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
                 )
127 127
             );
128 128
         }
129
-        $join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
129
+        $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to(
130 130
             $this->get_this_model()->get_this_model_name(),
131 131
             'ID'
132 132
         );
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
             $this->get_other_model()->get_this_model_name(),
135 135
             'ID'
136 136
         );
137
-        $field_with_other_model_name        = $this->get_join_table_fk_field_to(
137
+        $field_with_other_model_name = $this->get_join_table_fk_field_to(
138 138
             $this->get_other_model()->get_this_model_name(),
139 139
             'name'
140 140
         );
@@ -142,14 +142,14 @@  discard block
 block discarded – undo
142 142
         $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
143 143
                 $this->_model_relation_chain_to_join_model,
144 144
                 $this->get_join_model()->get_this_model_name()
145
-            ) . $join_table_fk_field_to_this_table->get_table_alias();
145
+            ).$join_table_fk_field_to_this_table->get_table_alias();
146 146
 
147 147
         $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
148 148
         $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
149 149
                 $model_relation_chain,
150 150
                 $this->get_other_model()->get_this_model_name()
151
-            ) . $other_table_pk_field->get_table_alias();
152
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
151
+            ).$other_table_pk_field->get_table_alias();
152
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
153 153
 
154 154
         return $this->_left_join(
155 155
                 $other_table,
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
                 $other_table_pk_field->get_table_column(),
158 158
                 $join_table_alias,
159 159
                 $join_table_fk_field_to_other_table->get_table_column(),
160
-                $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()
161
-                                                                                   ->get_this_model_name() . "'"
162
-            ) .
160
+                $field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()
161
+                                                                                   ->get_this_model_name()."'"
162
+            ).
163 163
                $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
164 164
     }
165 165
 
@@ -184,15 +184,15 @@  discard block
 block discarded – undo
184 184
         $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
185 185
         $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
186 186
         // check if such a relationship already exists
187
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
187
+        $join_model_fk_to_this_model = $this->get_join_table_fk_field_to(
188 188
             $this->get_this_model()->get_this_model_name(),
189 189
             'ID'
190 190
         );
191
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
191
+        $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to(
192 192
             $this->get_this_model()->get_this_model_name(),
193 193
             'name'
194 194
         );
195
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
195
+        $join_model_fk_to_other_model = $this->get_join_table_fk_field_to(
196 196
             $this->get_other_model()->get_this_model_name(),
197 197
             'ID'
198 198
         );
@@ -209,17 +209,17 @@  discard block
 block discarded – undo
209 209
         ];
210 210
 
211 211
         // if $where_query exists lets add them to the query_params.
212
-        if (! empty($extra_join_model_fields_n_values)) {
212
+        if ( ! empty($extra_join_model_fields_n_values)) {
213 213
             // 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)
214 214
             // make sure we strip THIS models name from the query param
215 215
             $parsed_query = [];
216 216
             foreach ($extra_join_model_fields_n_values as $query_param => $val) {
217
-                $query_param                  = str_replace(
218
-                    $this->get_join_model()->get_this_model_name() . ".",
217
+                $query_param = str_replace(
218
+                    $this->get_join_model()->get_this_model_name().".",
219 219
                     "",
220 220
                     $query_param
221 221
                 );
222
-                $parsed_query[ $query_param ] = $val;
222
+                $parsed_query[$query_param] = $val;
223 223
             }
224 224
             $cols_n_values = array_merge($cols_n_values, $parsed_query);
225 225
         }
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
         // if there is already an entry in the join table, indicating a relationship, we're done
232 232
         // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
233 233
         // the other tables, use the joining model directly!
234
-        if (! $existing_entry_in_join_table) {
234
+        if ( ! $existing_entry_in_join_table) {
235 235
             $this->get_join_model()->insert($cols_n_values);
236 236
         }
237 237
         return $other_model_obj;
@@ -254,15 +254,15 @@  discard block
 block discarded – undo
254 254
         $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
255 255
         $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
256 256
         // check if such a relationship already exists
257
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
257
+        $join_model_fk_to_this_model = $this->get_join_table_fk_field_to(
258 258
             $this->get_this_model()->get_this_model_name(),
259 259
             'ID'
260 260
         );
261
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
261
+        $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to(
262 262
             $this->get_this_model()->get_this_model_name(),
263 263
             'name'
264 264
         );
265
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
265
+        $join_model_fk_to_other_model = $this->get_join_table_fk_field_to(
266 266
             $this->get_other_model()->get_this_model_name(),
267 267
             'ID'
268 268
         );
@@ -279,17 +279,17 @@  discard block
 block discarded – undo
279 279
         ];
280 280
 
281 281
         // if $where_query exists lets add them to the query_params.
282
-        if (! empty($where_query)) {
282
+        if ( ! empty($where_query)) {
283 283
             // 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)
284 284
             // make sure we strip THIS models name from the query param
285 285
             $parsed_query = [];
286 286
             foreach ($where_query as $query_param => $val) {
287
-                $query_param                  = str_replace(
288
-                    $this->get_join_model()->get_this_model_name() . ".",
287
+                $query_param = str_replace(
288
+                    $this->get_join_model()->get_this_model_name().".",
289 289
                     "",
290 290
                     $query_param
291 291
                 );
292
-                $parsed_query[ $query_param ] = $val;
292
+                $parsed_query[$query_param] = $val;
293 293
             }
294 294
             $cols_n_values = array_merge($cols_n_values, $parsed_query);
295 295
         }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Any_Relation.php 2 patches
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -14,106 +14,106 @@
 block discarded – undo
14 14
  */
15 15
 class EE_Has_Many_Any_Relation extends EE_Has_Many_Relation
16 16
 {
17
-    /**
18
-     * Gets the SQL string for performing the join between this model and the other model.
19
-     *
20
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
21
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
22
-     *                                     other_model_primary_table.fk" etc
23
-     * @throws EE_Error
24
-     * @throws Exception
25
-     */
26
-    public function get_join_statement(string $model_relation_chain): string
27
-    {
28
-        // create the sql string like
29
-        // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
30
-        $this_table_pk_field   = $this->get_this_model()->get_primary_key_field();
31
-        $other_table_fk_field  =
32
-            $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
33
-        $pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
34
-                $model_relation_chain,
35
-                $this->get_this_model()->get_this_model_name()
36
-            ) . $this_table_pk_field->get_table_alias();
37
-        $fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
38
-                $model_relation_chain,
39
-                $this->get_other_model()->get_this_model_name()
40
-            ) . $other_table_fk_field->get_table_alias();
41
-        $fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
42
-        $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
17
+	/**
18
+	 * Gets the SQL string for performing the join between this model and the other model.
19
+	 *
20
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
21
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
22
+	 *                                     other_model_primary_table.fk" etc
23
+	 * @throws EE_Error
24
+	 * @throws Exception
25
+	 */
26
+	public function get_join_statement(string $model_relation_chain): string
27
+	{
28
+		// create the sql string like
29
+		// LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
30
+		$this_table_pk_field   = $this->get_this_model()->get_primary_key_field();
31
+		$other_table_fk_field  =
32
+			$this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
33
+		$pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
34
+				$model_relation_chain,
35
+				$this->get_this_model()->get_this_model_name()
36
+			) . $this_table_pk_field->get_table_alias();
37
+		$fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
38
+				$model_relation_chain,
39
+				$this->get_other_model()->get_this_model_name()
40
+			) . $other_table_fk_field->get_table_alias();
41
+		$fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
42
+		$field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
43 43
 
44
-        return $this->_left_join(
45
-                $fk_table,
46
-                $fk_table_alias,
47
-                $other_table_fk_field->get_table_column(),
48
-                $pk_table_alias,
49
-                $this_table_pk_field->get_table_column(),
50
-                $fk_table_alias . '.' . $field_with_model_name->get_table_column()
51
-                . "='" . $this->get_this_model()->get_this_model_name() . "'"
52
-            )
53
-               . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
54
-    }
44
+		return $this->_left_join(
45
+				$fk_table,
46
+				$fk_table_alias,
47
+				$other_table_fk_field->get_table_column(),
48
+				$pk_table_alias,
49
+				$this_table_pk_field->get_table_column(),
50
+				$fk_table_alias . '.' . $field_with_model_name->get_table_column()
51
+				. "='" . $this->get_this_model()->get_this_model_name() . "'"
52
+			)
53
+			   . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
54
+	}
55 55
 
56 56
 
57
-    /**
58
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
59
-     * you like.
60
-     *
61
-     * @param EE_Base_Class|int $this_obj_or_id
62
-     * @param EE_Base_Class|int $other_obj_or_id
63
-     * @param array             $extra_join_model_fields_n_values
64
-     * @return EE_Base_Class
65
-     * @throws EE_Error
66
-     * @throws Exception
67
-     */
68
-    public function add_relation_to(
69
-        $this_obj_or_id,
70
-        $other_obj_or_id,
71
-        array $extra_join_model_fields_n_values = []
72
-    ): EE_Base_Class {
73
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
74
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
57
+	/**
58
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
59
+	 * you like.
60
+	 *
61
+	 * @param EE_Base_Class|int $this_obj_or_id
62
+	 * @param EE_Base_Class|int $other_obj_or_id
63
+	 * @param array             $extra_join_model_fields_n_values
64
+	 * @return EE_Base_Class
65
+	 * @throws EE_Error
66
+	 * @throws Exception
67
+	 */
68
+	public function add_relation_to(
69
+		$this_obj_or_id,
70
+		$other_obj_or_id,
71
+		array $extra_join_model_fields_n_values = []
72
+	): EE_Base_Class {
73
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
74
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
75 75
 
76
-        // find the field on the other model which is a foreign key to this model
77
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to(
78
-            $this->get_this_model()->get_this_model_name()
79
-        );
80
-        // set that field on the other model to this model's ID
81
-        $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
82
-        $other_model_obj->set(
83
-            $this->get_other_model()->get_field_containing_related_model_name()->get_name(),
84
-            $this->get_this_model()->get_this_model_name()
85
-        );
86
-        $other_model_obj->save();
87
-        return $other_model_obj;
88
-    }
76
+		// find the field on the other model which is a foreign key to this model
77
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to(
78
+			$this->get_this_model()->get_this_model_name()
79
+		);
80
+		// set that field on the other model to this model's ID
81
+		$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
82
+		$other_model_obj->set(
83
+			$this->get_other_model()->get_field_containing_related_model_name()->get_name(),
84
+			$this->get_this_model()->get_this_model_name()
85
+		);
86
+		$other_model_obj->save();
87
+		return $other_model_obj;
88
+	}
89 89
 
90 90
 
91
-    /**
92
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
93
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
94
-     *
95
-     * @param EE_Base_Class|int $this_obj_or_id
96
-     * @param EE_Base_Class|int $other_obj_or_id
97
-     * @param array             $where_query
98
-     * @return EE_Base_Class
99
-     * @throws EE_Error
100
-     * @throws Exception
101
-     */
102
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, array $where_query = []): EE_Base_Class
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(
107
-            $this->get_this_model()->get_this_model_name()
108
-        );
109
-        // set that field on the other model to this model's ID
110
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
111
-        $other_model_obj->set(
112
-            $this->get_other_model()->get_field_containing_related_model_name()->get_name(),
113
-            null,
114
-            true
115
-        );
116
-        $other_model_obj->save();
117
-        return $other_model_obj;
118
-    }
91
+	/**
92
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
93
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
94
+	 *
95
+	 * @param EE_Base_Class|int $this_obj_or_id
96
+	 * @param EE_Base_Class|int $other_obj_or_id
97
+	 * @param array             $where_query
98
+	 * @return EE_Base_Class
99
+	 * @throws EE_Error
100
+	 * @throws Exception
101
+	 */
102
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, array $where_query = []): EE_Base_Class
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(
107
+			$this->get_this_model()->get_this_model_name()
108
+		);
109
+		// set that field on the other model to this model's ID
110
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
111
+		$other_model_obj->set(
112
+			$this->get_other_model()->get_field_containing_related_model_name()->get_name(),
113
+			null,
114
+			true
115
+		);
116
+		$other_model_obj->save();
117
+		return $other_model_obj;
118
+	}
119 119
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@  discard block
 block discarded – undo
33 33
         $pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
34 34
                 $model_relation_chain,
35 35
                 $this->get_this_model()->get_this_model_name()
36
-            ) . $this_table_pk_field->get_table_alias();
37
-        $fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
36
+            ).$this_table_pk_field->get_table_alias();
37
+        $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
38 38
                 $model_relation_chain,
39 39
                 $this->get_other_model()->get_this_model_name()
40
-            ) . $other_table_fk_field->get_table_alias();
40
+            ).$other_table_fk_field->get_table_alias();
41 41
         $fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
42 42
         $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
43 43
 
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
                 $other_table_fk_field->get_table_column(),
48 48
                 $pk_table_alias,
49 49
                 $this_table_pk_field->get_table_column(),
50
-                $fk_table_alias . '.' . $field_with_model_name->get_table_column()
51
-                . "='" . $this->get_this_model()->get_this_model_name() . "'"
50
+                $fk_table_alias.'.'.$field_with_model_name->get_table_column()
51
+                . "='".$this->get_this_model()->get_this_model_name()."'"
52 52
             )
53 53
                . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
54 54
     }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Relation.php 2 patches
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -10,113 +10,113 @@
 block discarded – undo
10 10
  */
11 11
 class EE_Has_Many_Relation extends EE_Model_Relation_Base
12 12
 {
13
-    /**
14
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
15
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
16
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
17
-     * related models across the relation, and add-and-remove the relationships.
18
-     *
19
-     * @param bool   $block_deletes                  For this type of r elation, we block by default. If there are
20
-     *                                               related models across this relation, block (prevent and add an
21
-     *                                               error) the deletion of this model
22
-     * @param string $blocking_delete_error_message  a customized error message on blocking deletes instead of the
23
-     *                                               default
24
-     */
25
-    public function __construct(bool $block_deletes = true, string $blocking_delete_error_message = '')
26
-    {
27
-        parent::__construct($block_deletes, $blocking_delete_error_message);
28
-    }
13
+	/**
14
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
15
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
16
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
17
+	 * related models across the relation, and add-and-remove the relationships.
18
+	 *
19
+	 * @param bool   $block_deletes                  For this type of r elation, we block by default. If there are
20
+	 *                                               related models across this relation, block (prevent and add an
21
+	 *                                               error) the deletion of this model
22
+	 * @param string $blocking_delete_error_message  a customized error message on blocking deletes instead of the
23
+	 *                                               default
24
+	 */
25
+	public function __construct(bool $block_deletes = true, string $blocking_delete_error_message = '')
26
+	{
27
+		parent::__construct($block_deletes, $blocking_delete_error_message);
28
+	}
29 29
 
30 30
 
31
-    /**
32
-     * Gets the SQL string for performing the join between this model and the other model.
33
-     *
34
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
35
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
36
-     *                                     other_model_primary_table.fk" etc
37
-     * @throws EE_Error
38
-     * @throws Exception
39
-     */
40
-    public function get_join_statement(string $model_relation_chain): string
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 =
46
-            $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
47
-        $pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
48
-                $model_relation_chain,
49
-                $this->get_this_model()->get_this_model_name()
50
-            ) . $this_table_pk_field->get_table_alias();
51
-        $fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
52
-                $model_relation_chain,
53
-                $this->get_other_model()->get_this_model_name()
54
-            ) . $other_table_fk_field->get_table_alias();
55
-        $fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
31
+	/**
32
+	 * Gets the SQL string for performing the join between this model and the other model.
33
+	 *
34
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
35
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
36
+	 *                                     other_model_primary_table.fk" etc
37
+	 * @throws EE_Error
38
+	 * @throws Exception
39
+	 */
40
+	public function get_join_statement(string $model_relation_chain): string
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 =
46
+			$this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
47
+		$pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
48
+				$model_relation_chain,
49
+				$this->get_this_model()->get_this_model_name()
50
+			) . $this_table_pk_field->get_table_alias();
51
+		$fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
52
+				$model_relation_chain,
53
+				$this->get_other_model()->get_this_model_name()
54
+			) . $other_table_fk_field->get_table_alias();
55
+		$fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
56 56
 
57
-        return $this->_left_join(
58
-                $fk_table,
59
-                $fk_table_alias,
60
-                $other_table_fk_field->get_table_column(),
61
-                $pk_table_alias,
62
-                $this_table_pk_field->get_table_column()
63
-            ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
64
-    }
57
+		return $this->_left_join(
58
+				$fk_table,
59
+				$fk_table_alias,
60
+				$other_table_fk_field->get_table_column(),
61
+				$pk_table_alias,
62
+				$this_table_pk_field->get_table_column()
63
+			) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
69
-     * you like.
70
-     *
71
-     * @param EE_Base_Class|int $this_obj_or_id
72
-     * @param EE_Base_Class|int $other_obj_or_id
73
-     * @param array             $extra_join_model_fields_n_values
74
-     * @return EE_Base_Class
75
-     * @throws EE_Error
76
-     * @throws Exception
77
-     */
78
-    public function add_relation_to(
79
-        $this_obj_or_id,
80
-        $other_obj_or_id,
81
-        array $extra_join_model_fields_n_values = []
82
-    ): EE_Base_Class {
83
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
84
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
67
+	/**
68
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
69
+	 * you like.
70
+	 *
71
+	 * @param EE_Base_Class|int $this_obj_or_id
72
+	 * @param EE_Base_Class|int $other_obj_or_id
73
+	 * @param array             $extra_join_model_fields_n_values
74
+	 * @return EE_Base_Class
75
+	 * @throws EE_Error
76
+	 * @throws Exception
77
+	 */
78
+	public function add_relation_to(
79
+		$this_obj_or_id,
80
+		$other_obj_or_id,
81
+		array $extra_join_model_fields_n_values = []
82
+	): EE_Base_Class {
83
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
84
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
85 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(
88
-            $this->get_this_model()->get_this_model_name()
89
-        );
90
-        if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
91
-            // set that field on the other model to this model's ID
92
-            $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
93
-            $other_model_obj->save();
94
-        }
95
-        return $other_model_obj;
96
-    }
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(
88
+			$this->get_this_model()->get_this_model_name()
89
+		);
90
+		if ($other_model_obj->get($fk_field_on_other_model->get_name()) != $this_model_obj->ID()) {
91
+			// set that field on the other model to this model's ID
92
+			$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
93
+			$other_model_obj->save();
94
+		}
95
+		return $other_model_obj;
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
101
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
102
-     *
103
-     * @param EE_Base_Class|int $this_obj_or_id
104
-     * @param EE_Base_Class|int $other_obj_or_id
105
-     * @param array             $where_query
106
-     * @return EE_Base_Class
107
-     * @throws EE_Error
108
-     * @throws Exception
109
-     */
110
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, array $where_query = []): EE_Base_Class
111
-    {
112
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
113
-        // find the field on the other model which is a foreign key to this model
114
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to(
115
-            $this->get_this_model()->get_this_model_name()
116
-        );
117
-        // set that field on the other model to this model's ID
118
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
119
-        $other_model_obj->save();
120
-        return $other_model_obj;
121
-    }
99
+	/**
100
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
101
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
102
+	 *
103
+	 * @param EE_Base_Class|int $this_obj_or_id
104
+	 * @param EE_Base_Class|int $other_obj_or_id
105
+	 * @param array             $where_query
106
+	 * @return EE_Base_Class
107
+	 * @throws EE_Error
108
+	 * @throws Exception
109
+	 */
110
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, array $where_query = []): EE_Base_Class
111
+	{
112
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
113
+		// find the field on the other model which is a foreign key to this model
114
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to(
115
+			$this->get_this_model()->get_this_model_name()
116
+		);
117
+		// set that field on the other model to this model's ID
118
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
119
+		$other_model_obj->save();
120
+		return $other_model_obj;
121
+	}
122 122
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
         $pk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
48 48
                 $model_relation_chain,
49 49
                 $this->get_this_model()->get_this_model_name()
50
-            ) . $this_table_pk_field->get_table_alias();
51
-        $fk_table_alias       = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
50
+            ).$this_table_pk_field->get_table_alias();
51
+        $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
52 52
                 $model_relation_chain,
53 53
                 $this->get_other_model()->get_this_model_name()
54
-            ) . $other_table_fk_field->get_table_alias();
55
-        $fk_table             = $this->get_other_model()->get_table_for_alias($fk_table_alias);
54
+            ).$other_table_fk_field->get_table_alias();
55
+        $fk_table = $this->get_other_model()->get_table_for_alias($fk_table_alias);
56 56
 
57 57
         return $this->_left_join(
58 58
                 $fk_table,
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
                 $other_table_fk_field->get_table_column(),
61 61
                 $pk_table_alias,
62 62
                 $this_table_pk_field->get_table_column()
63
-            ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
63
+            ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
64 64
     }
65 65
 
66 66
 
Please login to merge, or discard this patch.
core/db_models/relations/EE_Model_Relation_Base.php 2 patches
Indentation   +524 added lines, -524 removed lines patch added patch discarded remove patch
@@ -16,531 +16,531 @@
 block discarded – undo
16 16
  */
17 17
 abstract class EE_Model_Relation_Base implements HasSchemaInterface
18 18
 {
19
-    /**
20
-     * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base)
21
-     *
22
-     * @var string eg Event, Question_Group, Registration
23
-     */
24
-    private string $_this_model_name = '';
25
-
26
-    /**
27
-     * The model name pointed to by this relation (ie, the model we want to establish a relationship to)
28
-     *
29
-     * @var string eg Event, Question_Group, Registration
30
-     */
31
-    private string $_other_model_name = '';
32
-
33
-    /**
34
-     * this is typically used when calling the relation models to make sure they inherit any set timezone from the
35
-     * initiating model.
36
-     *
37
-     * @var string
38
-     */
39
-    protected string $_timezone = '';
40
-
41
-    /**
42
-     * If you try to delete "this_model", and there are related "other_models",
43
-     * and this isn't null, then abandon the deletion and add this warning.
44
-     * This effectively makes it impossible to delete "this_model" while there are
45
-     * related "other_models" along this relation.
46
-     *
47
-     * @var string (internationalized)
48
-     */
49
-    protected string $_blocking_delete_error_message;
50
-
51
-    protected bool   $_blocking_delete = false;
52
-
53
-
54
-    /**
55
-     * Object representing the relationship between two models. This knows how to join the models,
56
-     * get related models across the relation, and add-and-remove the relationships.
57
-     *
58
-     * @param bool   $block_deletes                  if there are related models across this relation, block (prevent
59
-     *                                               and add an error) the deletion of this model
60
-     * @param string $blocking_delete_error_message  a customized error message on blocking deletes instead of the
61
-     *                                               default
62
-     */
63
-    public function __construct(bool $block_deletes = false, string $blocking_delete_error_message = '')
64
-    {
65
-        $this->_blocking_delete               = filter_var($block_deletes, FILTER_VALIDATE_BOOLEAN);
66
-        $this->_blocking_delete_error_message = $blocking_delete_error_message;
67
-    }
68
-
69
-
70
-    /**
71
-     * @param $this_model_name
72
-     * @param $other_model_name
73
-     */
74
-    public function _construct_finalize_set_models($this_model_name, $other_model_name)
75
-    {
76
-        $this->_this_model_name  = $this_model_name;
77
-        $this->_other_model_name = $other_model_name;
78
-    }
79
-
80
-
81
-    /**
82
-     * Gets the model where this relation is defined.
83
-     *
84
-     * @return EEM_Base
85
-     * @throws Exception
86
-     */
87
-    public function get_this_model(): EEM_Base
88
-    {
89
-        return $this->_get_model($this->_this_model_name);
90
-    }
91
-
92
-
93
-    /**
94
-     * Gets the model which this relation establishes the relation TO (ie,
95
-     * this relation object was defined on get_this_model(), get_other_model() is the other one)
96
-     *
97
-     * @return EEM_Base
98
-     * @throws Exception
99
-     */
100
-    public function get_other_model(): EEM_Base
101
-    {
102
-        return $this->_get_model($this->_other_model_name);
103
-    }
104
-
105
-
106
-    /**
107
-     * Internally used by get_this_model() and get_other_model()
108
-     *
109
-     * @param string $model_name like Event, Question_Group, etc. omit the EEM_
110
-     * @return EEM_Base
111
-     * @throws Exception
112
-     */
113
-    protected function _get_model(string $model_name): EEM_Base
114
-    {
115
-        /** @var EEM_Base $modelInstance */
116
-        $modelInstance = EE_Registry::instance()->load_model($model_name);
117
-        $modelInstance->set_timezone($this->_timezone);
118
-        return $modelInstance;
119
-    }
120
-
121
-
122
-    /**
123
-     * entirely possible that relations may be called from a model and we need to make sure those relations have their
124
-     * timezone set correctly.
125
-     *
126
-     * @param string|null $timezone timezone to set.
127
-     */
128
-    public function set_timezone(?string $timezone = '')
129
-    {
130
-        if ($timezone) {
131
-            $this->_timezone = $timezone;
132
-        }
133
-    }
134
-
135
-
136
-    /**
137
-     * @param string $other_table
138
-     * @param string $other_table_alias
139
-     * @param string $other_table_column
140
-     * @param string $this_table_alias
141
-     * @param string $this_table_join_column
142
-     * @param string $extra_join_sql
143
-     * @return string
144
-     */
145
-    protected function _left_join(
146
-        string $other_table,
147
-        string $other_table_alias,
148
-        string $other_table_column,
149
-        string $this_table_alias,
150
-        string $this_table_join_column,
151
-        string $extra_join_sql = ''
152
-    ): string {
153
-        return " 
19
+	/**
20
+	 * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base)
21
+	 *
22
+	 * @var string eg Event, Question_Group, Registration
23
+	 */
24
+	private string $_this_model_name = '';
25
+
26
+	/**
27
+	 * The model name pointed to by this relation (ie, the model we want to establish a relationship to)
28
+	 *
29
+	 * @var string eg Event, Question_Group, Registration
30
+	 */
31
+	private string $_other_model_name = '';
32
+
33
+	/**
34
+	 * this is typically used when calling the relation models to make sure they inherit any set timezone from the
35
+	 * initiating model.
36
+	 *
37
+	 * @var string
38
+	 */
39
+	protected string $_timezone = '';
40
+
41
+	/**
42
+	 * If you try to delete "this_model", and there are related "other_models",
43
+	 * and this isn't null, then abandon the deletion and add this warning.
44
+	 * This effectively makes it impossible to delete "this_model" while there are
45
+	 * related "other_models" along this relation.
46
+	 *
47
+	 * @var string (internationalized)
48
+	 */
49
+	protected string $_blocking_delete_error_message;
50
+
51
+	protected bool   $_blocking_delete = false;
52
+
53
+
54
+	/**
55
+	 * Object representing the relationship between two models. This knows how to join the models,
56
+	 * get related models across the relation, and add-and-remove the relationships.
57
+	 *
58
+	 * @param bool   $block_deletes                  if there are related models across this relation, block (prevent
59
+	 *                                               and add an error) the deletion of this model
60
+	 * @param string $blocking_delete_error_message  a customized error message on blocking deletes instead of the
61
+	 *                                               default
62
+	 */
63
+	public function __construct(bool $block_deletes = false, string $blocking_delete_error_message = '')
64
+	{
65
+		$this->_blocking_delete               = filter_var($block_deletes, FILTER_VALIDATE_BOOLEAN);
66
+		$this->_blocking_delete_error_message = $blocking_delete_error_message;
67
+	}
68
+
69
+
70
+	/**
71
+	 * @param $this_model_name
72
+	 * @param $other_model_name
73
+	 */
74
+	public function _construct_finalize_set_models($this_model_name, $other_model_name)
75
+	{
76
+		$this->_this_model_name  = $this_model_name;
77
+		$this->_other_model_name = $other_model_name;
78
+	}
79
+
80
+
81
+	/**
82
+	 * Gets the model where this relation is defined.
83
+	 *
84
+	 * @return EEM_Base
85
+	 * @throws Exception
86
+	 */
87
+	public function get_this_model(): EEM_Base
88
+	{
89
+		return $this->_get_model($this->_this_model_name);
90
+	}
91
+
92
+
93
+	/**
94
+	 * Gets the model which this relation establishes the relation TO (ie,
95
+	 * this relation object was defined on get_this_model(), get_other_model() is the other one)
96
+	 *
97
+	 * @return EEM_Base
98
+	 * @throws Exception
99
+	 */
100
+	public function get_other_model(): EEM_Base
101
+	{
102
+		return $this->_get_model($this->_other_model_name);
103
+	}
104
+
105
+
106
+	/**
107
+	 * Internally used by get_this_model() and get_other_model()
108
+	 *
109
+	 * @param string $model_name like Event, Question_Group, etc. omit the EEM_
110
+	 * @return EEM_Base
111
+	 * @throws Exception
112
+	 */
113
+	protected function _get_model(string $model_name): EEM_Base
114
+	{
115
+		/** @var EEM_Base $modelInstance */
116
+		$modelInstance = EE_Registry::instance()->load_model($model_name);
117
+		$modelInstance->set_timezone($this->_timezone);
118
+		return $modelInstance;
119
+	}
120
+
121
+
122
+	/**
123
+	 * entirely possible that relations may be called from a model and we need to make sure those relations have their
124
+	 * timezone set correctly.
125
+	 *
126
+	 * @param string|null $timezone timezone to set.
127
+	 */
128
+	public function set_timezone(?string $timezone = '')
129
+	{
130
+		if ($timezone) {
131
+			$this->_timezone = $timezone;
132
+		}
133
+	}
134
+
135
+
136
+	/**
137
+	 * @param string $other_table
138
+	 * @param string $other_table_alias
139
+	 * @param string $other_table_column
140
+	 * @param string $this_table_alias
141
+	 * @param string $this_table_join_column
142
+	 * @param string $extra_join_sql
143
+	 * @return string
144
+	 */
145
+	protected function _left_join(
146
+		string $other_table,
147
+		string $other_table_alias,
148
+		string $other_table_column,
149
+		string $this_table_alias,
150
+		string $this_table_join_column,
151
+		string $extra_join_sql = ''
152
+	): string {
153
+		return " 
154 154
         LEFT JOIN " . $other_table . " AS " . $other_table_alias . " 
155 155
         ON " . $other_table_alias . "." . $other_table_column
156
-               . "=" . $this_table_alias . "." . $this_table_join_column
157
-               . ($extra_join_sql ? " AND $extra_join_sql" : '');
158
-    }
159
-
160
-
161
-    /**
162
-     * Gets all the model objects of type of other model related to $model_object,
163
-     * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation.
164
-     * For both of those child classes, $model_object must be saved so that it has an ID before querying,
165
-     * otherwise an error will be thrown. Note: by default we disable default_where_conditions
166
-     * EE_Belongs_To_Relation doesn't need to be saved before querying.
167
-     *
168
-     * @param EE_Base_Class|int|string $model_object_or_id                      or the primary key of this model
169
-     * @param array|null               $query_params
170
-     * @param boolean                  $values_already_prepared_by_model_object @deprecated 4.8.1
171
-     * @return EE_Base_Class[]
172
-     * @throws EE_Error
173
-     * @throws ReflectionException
174
-     * @throws Exception
175
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
176
-     */
177
-    public function get_all_related(
178
-        $model_object_or_id,
179
-        ?array $query_params = [],
180
-        bool $values_already_prepared_by_model_object = false
181
-    ): array {
182
-        if ($values_already_prepared_by_model_object !== false) {
183
-            EE_Error::doing_it_wrong(
184
-                'EE_Model_Relation_Base::get_all_related',
185
-                esc_html__(
186
-                    'The argument $values_already_prepared_by_model_object is no longer used.',
187
-                    'event_espresso'
188
-                ),
189
-                '4.8.1'
190
-            );
191
-        }
192
-        $query_params = $this->_disable_default_where_conditions_on_query_param($query_params);
193
-
194
-        $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name()
195
-                                           . "." . $this->get_this_model()->get_primary_key_field()->get_name();
196
-
197
-        $model_object_id = $this->_get_model_object_id($model_object_or_id);
198
-
199
-        $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
200
-        return $this->get_other_model()->get_all($query_params);
201
-    }
202
-
203
-
204
-    /**
205
-     * Alters the $query_params to disable default where conditions, unless otherwise specified
206
-     *
207
-     * @param array $query_params
208
-     * @return array
209
-     */
210
-    protected function _disable_default_where_conditions_on_query_param(array $query_params): array
211
-    {
212
-        if (! isset($query_params['default_where_conditions'])) {
213
-            $query_params['default_where_conditions'] = 'none';
214
-        }
215
-        return $query_params;
216
-    }
217
-
218
-
219
-    /**
220
-     * Deletes the related model objects which meet the query parameters. If no
221
-     * parameters are specified, then all related model objects will be deleted.
222
-     * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
223
-     * model objects will only be soft-deleted.
224
-     *
225
-     * @param EE_Base_Class|int|string $model_object_or_id
226
-     * @param array                    $query_params
227
-     * @return int of how many related models got deleted
228
-     * @throws EE_Error
229
-     * @throws ReflectionException
230
-     * @throws Exception
231
-     */
232
-    public function delete_all_related($model_object_or_id, array $query_params = []): int
233
-    {
234
-        // for each thing we would delete,
235
-        $related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
236
-        // determine if it's blocked by anything else before it can be deleted
237
-        $deleted_count = 0;
238
-        foreach ($related_model_objects as $related_model_object) {
239
-            $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
240
-                $related_model_object,
241
-                $model_object_or_id
242
-            );
243
-            /* @var $model_object_or_id EE_Base_Class */
244
-            if (! $delete_is_blocked) {
245
-                $this->remove_relation_to($model_object_or_id, $related_model_object);
246
-                $related_model_object->delete();
247
-                $deleted_count++;
248
-            }
249
-        }
250
-        return $deleted_count;
251
-    }
252
-
253
-
254
-    /**
255
-     * Deletes the related model objects which meet the query parameters. If no
256
-     * parameters are specified, then all related model objects will be deleted.
257
-     * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
258
-     * model objects will only be soft-deleted.
259
-     *
260
-     * @param EE_Base_Class|int|string $model_object_or_id
261
-     * @param array                    $query_params
262
-     * @return int of how many related models got deleted
263
-     * @throws EE_Error
264
-     * @throws ReflectionException
265
-     * @throws Exception
266
-     */
267
-    public function delete_related_permanently($model_object_or_id, array $query_params = []): int
268
-    {
269
-        // for each thing we would delete,
270
-        $related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
271
-        // determine if it's blocked by anything else before it can be deleted
272
-        $deleted_count = 0;
273
-        foreach ($related_model_objects as $related_model_object) {
274
-            $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
275
-                $related_model_object,
276
-                $model_object_or_id
277
-            );
278
-            /* @var $model_object_or_id EE_Base_Class */
279
-            if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
280
-                $this->remove_relation_to($model_object_or_id, $related_model_object);
281
-                $deleted_count++;
282
-                if (! $delete_is_blocked) {
283
-                    $related_model_object->delete_permanently();
284
-                } else {
285
-                    // delete is blocked
286
-                    // brent and darren, in this case, wanted to just soft delete it then
287
-                    $related_model_object->delete();
288
-                }
289
-            } else {
290
-                // its not a soft-deletable thing anyways. do the normal logic.
291
-                if (! $delete_is_blocked) {
292
-                    $this->remove_relation_to($model_object_or_id, $related_model_object);
293
-                    $related_model_object->delete();
294
-                    $deleted_count++;
295
-                }
296
-            }
297
-        }
298
-        return $deleted_count;
299
-    }
300
-
301
-
302
-    /**
303
-     * this just returns a model_object_id for incoming item that could be an object or id.
304
-     *
305
-     * @param EE_Base_Class|int|string $model_object_or_id model object or the primary key of this model
306
-     * @return int
307
-     * @throws EE_Error
308
-     * @throws ReflectionException
309
-     * @throws Exception
310
-     */
311
-    protected function _get_model_object_id($model_object_or_id)
312
-    {
313
-        $model_object_id = $model_object_or_id;
314
-        if ($model_object_or_id instanceof EE_Base_Class) {
315
-            $model_object_id = $model_object_or_id->ID();
316
-        }
317
-        if (! $model_object_id) {
318
-            throw new EE_Error(
319
-                sprintf(
320
-                    esc_html__(
321
-                        "Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects",
322
-                        "event_espresso"
323
-                    ),
324
-                    $this->get_other_model()->get_this_model_name(),
325
-                    $this->get_this_model()->get_this_model_name()
326
-                )
327
-            );
328
-        }
329
-        return $model_object_id;
330
-    }
331
-
332
-
333
-    /**
334
-     * Gets the SQL string for performing the join between this model and the other model.
335
-     *
336
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
337
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
338
-     *                                     other_model_primary_table.fk" etc
339
-     */
340
-    abstract public function get_join_statement(string $model_relation_chain): string;
341
-
342
-
343
-    /**
344
-     * Adds a relationships between the two model objects provided. Each type of relationship handles this differently
345
-     * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this
346
-     * relationship only allows this model to be related to a single other model of this type)
347
-     *
348
-     * @param EE_Base_Class|int|string $this_obj_or_id
349
-     * @param EE_Base_Class|int|string $other_obj_or_id
350
-     * @param array                    $extra_join_model_fields_n_values
351
-     * @return EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for
352
-     *                        $other_obj_or_id)
353
-     */
354
-    abstract public function add_relation_to(
355
-        $this_obj_or_id,
356
-        $other_obj_or_id,
357
-        array $extra_join_model_fields_n_values = []
358
-    ): EE_Base_Class;
359
-
360
-
361
-    /**
362
-     * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two
363
-     * model objects
364
-     *
365
-     * @param EE_Base_Class|int|string $this_obj_or_id
366
-     * @param EE_Base_Class|int|string $other_obj_or_id
367
-     * @param array                    $where_query
368
-     * @return EE_Base_Class
369
-     */
370
-    abstract public function remove_relation_to(
371
-        $this_obj_or_id,
372
-        $other_obj_or_id,
373
-        array $where_query = []
374
-    ): EE_Base_Class;
375
-
376
-
377
-    /**
378
-     * Removes ALL relation instances for this relation obj
379
-     *
380
-     * @param EE_Base_Class|int|string $this_obj_or_id
381
-     * @param array                    $where_query_param @see
382
-     *                                                    https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
383
-     * @return EE_Base_Class[]
384
-     * @throws EE_Error
385
-     * @throws ReflectionException
386
-     */
387
-    public function remove_relations($this_obj_or_id, array $where_query_param = []): array
388
-    {
389
-        $related_things = $this->get_all_related($this_obj_or_id, [$where_query_param]);
390
-        $objs_removed   = [];
391
-        foreach ($related_things as $related_thing) {
392
-            $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing);
393
-        }
394
-        return $objs_removed;
395
-    }
396
-
397
-
398
-    /**
399
-     * If you aren't allowed to delete this model when there are related models across this
400
-     * relation object, return true. Otherwise, if you can delete this model even though
401
-     * related objects exist, returns false.
402
-     *
403
-     * @return boolean
404
-     */
405
-    public function block_delete_if_related_models_exist(): bool
406
-    {
407
-        return $this->_blocking_delete;
408
-    }
409
-
410
-
411
-    /**
412
-     * Gets the error message to show
413
-     *
414
-     * @return string
415
-     * @throws Exception
416
-     */
417
-    public function get_deletion_error_message(): string
418
-    {
419
-        if ($this->_blocking_delete_error_message) {
420
-            return $this->_blocking_delete_error_message;
421
-        } else {
156
+			   . "=" . $this_table_alias . "." . $this_table_join_column
157
+			   . ($extra_join_sql ? " AND $extra_join_sql" : '');
158
+	}
159
+
160
+
161
+	/**
162
+	 * Gets all the model objects of type of other model related to $model_object,
163
+	 * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation.
164
+	 * For both of those child classes, $model_object must be saved so that it has an ID before querying,
165
+	 * otherwise an error will be thrown. Note: by default we disable default_where_conditions
166
+	 * EE_Belongs_To_Relation doesn't need to be saved before querying.
167
+	 *
168
+	 * @param EE_Base_Class|int|string $model_object_or_id                      or the primary key of this model
169
+	 * @param array|null               $query_params
170
+	 * @param boolean                  $values_already_prepared_by_model_object @deprecated 4.8.1
171
+	 * @return EE_Base_Class[]
172
+	 * @throws EE_Error
173
+	 * @throws ReflectionException
174
+	 * @throws Exception
175
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
176
+	 */
177
+	public function get_all_related(
178
+		$model_object_or_id,
179
+		?array $query_params = [],
180
+		bool $values_already_prepared_by_model_object = false
181
+	): array {
182
+		if ($values_already_prepared_by_model_object !== false) {
183
+			EE_Error::doing_it_wrong(
184
+				'EE_Model_Relation_Base::get_all_related',
185
+				esc_html__(
186
+					'The argument $values_already_prepared_by_model_object is no longer used.',
187
+					'event_espresso'
188
+				),
189
+				'4.8.1'
190
+			);
191
+		}
192
+		$query_params = $this->_disable_default_where_conditions_on_query_param($query_params);
193
+
194
+		$query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name()
195
+										   . "." . $this->get_this_model()->get_primary_key_field()->get_name();
196
+
197
+		$model_object_id = $this->_get_model_object_id($model_object_or_id);
198
+
199
+		$query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
200
+		return $this->get_other_model()->get_all($query_params);
201
+	}
202
+
203
+
204
+	/**
205
+	 * Alters the $query_params to disable default where conditions, unless otherwise specified
206
+	 *
207
+	 * @param array $query_params
208
+	 * @return array
209
+	 */
210
+	protected function _disable_default_where_conditions_on_query_param(array $query_params): array
211
+	{
212
+		if (! isset($query_params['default_where_conditions'])) {
213
+			$query_params['default_where_conditions'] = 'none';
214
+		}
215
+		return $query_params;
216
+	}
217
+
218
+
219
+	/**
220
+	 * Deletes the related model objects which meet the query parameters. If no
221
+	 * parameters are specified, then all related model objects will be deleted.
222
+	 * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
223
+	 * model objects will only be soft-deleted.
224
+	 *
225
+	 * @param EE_Base_Class|int|string $model_object_or_id
226
+	 * @param array                    $query_params
227
+	 * @return int of how many related models got deleted
228
+	 * @throws EE_Error
229
+	 * @throws ReflectionException
230
+	 * @throws Exception
231
+	 */
232
+	public function delete_all_related($model_object_or_id, array $query_params = []): int
233
+	{
234
+		// for each thing we would delete,
235
+		$related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
236
+		// determine if it's blocked by anything else before it can be deleted
237
+		$deleted_count = 0;
238
+		foreach ($related_model_objects as $related_model_object) {
239
+			$delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
240
+				$related_model_object,
241
+				$model_object_or_id
242
+			);
243
+			/* @var $model_object_or_id EE_Base_Class */
244
+			if (! $delete_is_blocked) {
245
+				$this->remove_relation_to($model_object_or_id, $related_model_object);
246
+				$related_model_object->delete();
247
+				$deleted_count++;
248
+			}
249
+		}
250
+		return $deleted_count;
251
+	}
252
+
253
+
254
+	/**
255
+	 * Deletes the related model objects which meet the query parameters. If no
256
+	 * parameters are specified, then all related model objects will be deleted.
257
+	 * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
258
+	 * model objects will only be soft-deleted.
259
+	 *
260
+	 * @param EE_Base_Class|int|string $model_object_or_id
261
+	 * @param array                    $query_params
262
+	 * @return int of how many related models got deleted
263
+	 * @throws EE_Error
264
+	 * @throws ReflectionException
265
+	 * @throws Exception
266
+	 */
267
+	public function delete_related_permanently($model_object_or_id, array $query_params = []): int
268
+	{
269
+		// for each thing we would delete,
270
+		$related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
271
+		// determine if it's blocked by anything else before it can be deleted
272
+		$deleted_count = 0;
273
+		foreach ($related_model_objects as $related_model_object) {
274
+			$delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
275
+				$related_model_object,
276
+				$model_object_or_id
277
+			);
278
+			/* @var $model_object_or_id EE_Base_Class */
279
+			if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
280
+				$this->remove_relation_to($model_object_or_id, $related_model_object);
281
+				$deleted_count++;
282
+				if (! $delete_is_blocked) {
283
+					$related_model_object->delete_permanently();
284
+				} else {
285
+					// delete is blocked
286
+					// brent and darren, in this case, wanted to just soft delete it then
287
+					$related_model_object->delete();
288
+				}
289
+			} else {
290
+				// its not a soft-deletable thing anyways. do the normal logic.
291
+				if (! $delete_is_blocked) {
292
+					$this->remove_relation_to($model_object_or_id, $related_model_object);
293
+					$related_model_object->delete();
294
+					$deleted_count++;
295
+				}
296
+			}
297
+		}
298
+		return $deleted_count;
299
+	}
300
+
301
+
302
+	/**
303
+	 * this just returns a model_object_id for incoming item that could be an object or id.
304
+	 *
305
+	 * @param EE_Base_Class|int|string $model_object_or_id model object or the primary key of this model
306
+	 * @return int
307
+	 * @throws EE_Error
308
+	 * @throws ReflectionException
309
+	 * @throws Exception
310
+	 */
311
+	protected function _get_model_object_id($model_object_or_id)
312
+	{
313
+		$model_object_id = $model_object_or_id;
314
+		if ($model_object_or_id instanceof EE_Base_Class) {
315
+			$model_object_id = $model_object_or_id->ID();
316
+		}
317
+		if (! $model_object_id) {
318
+			throw new EE_Error(
319
+				sprintf(
320
+					esc_html__(
321
+						"Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects",
322
+						"event_espresso"
323
+					),
324
+					$this->get_other_model()->get_this_model_name(),
325
+					$this->get_this_model()->get_this_model_name()
326
+				)
327
+			);
328
+		}
329
+		return $model_object_id;
330
+	}
331
+
332
+
333
+	/**
334
+	 * Gets the SQL string for performing the join between this model and the other model.
335
+	 *
336
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
337
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
338
+	 *                                     other_model_primary_table.fk" etc
339
+	 */
340
+	abstract public function get_join_statement(string $model_relation_chain): string;
341
+
342
+
343
+	/**
344
+	 * Adds a relationships between the two model objects provided. Each type of relationship handles this differently
345
+	 * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this
346
+	 * relationship only allows this model to be related to a single other model of this type)
347
+	 *
348
+	 * @param EE_Base_Class|int|string $this_obj_or_id
349
+	 * @param EE_Base_Class|int|string $other_obj_or_id
350
+	 * @param array                    $extra_join_model_fields_n_values
351
+	 * @return EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for
352
+	 *                        $other_obj_or_id)
353
+	 */
354
+	abstract public function add_relation_to(
355
+		$this_obj_or_id,
356
+		$other_obj_or_id,
357
+		array $extra_join_model_fields_n_values = []
358
+	): EE_Base_Class;
359
+
360
+
361
+	/**
362
+	 * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two
363
+	 * model objects
364
+	 *
365
+	 * @param EE_Base_Class|int|string $this_obj_or_id
366
+	 * @param EE_Base_Class|int|string $other_obj_or_id
367
+	 * @param array                    $where_query
368
+	 * @return EE_Base_Class
369
+	 */
370
+	abstract public function remove_relation_to(
371
+		$this_obj_or_id,
372
+		$other_obj_or_id,
373
+		array $where_query = []
374
+	): EE_Base_Class;
375
+
376
+
377
+	/**
378
+	 * Removes ALL relation instances for this relation obj
379
+	 *
380
+	 * @param EE_Base_Class|int|string $this_obj_or_id
381
+	 * @param array                    $where_query_param @see
382
+	 *                                                    https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
383
+	 * @return EE_Base_Class[]
384
+	 * @throws EE_Error
385
+	 * @throws ReflectionException
386
+	 */
387
+	public function remove_relations($this_obj_or_id, array $where_query_param = []): array
388
+	{
389
+		$related_things = $this->get_all_related($this_obj_or_id, [$where_query_param]);
390
+		$objs_removed   = [];
391
+		foreach ($related_things as $related_thing) {
392
+			$objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing);
393
+		}
394
+		return $objs_removed;
395
+	}
396
+
397
+
398
+	/**
399
+	 * If you aren't allowed to delete this model when there are related models across this
400
+	 * relation object, return true. Otherwise, if you can delete this model even though
401
+	 * related objects exist, returns false.
402
+	 *
403
+	 * @return boolean
404
+	 */
405
+	public function block_delete_if_related_models_exist(): bool
406
+	{
407
+		return $this->_blocking_delete;
408
+	}
409
+
410
+
411
+	/**
412
+	 * Gets the error message to show
413
+	 *
414
+	 * @return string
415
+	 * @throws Exception
416
+	 */
417
+	public function get_deletion_error_message(): string
418
+	{
419
+		if ($this->_blocking_delete_error_message) {
420
+			return $this->_blocking_delete_error_message;
421
+		} else {
422 422
 //          return sprintf(esc_html__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2));
423
-            return sprintf(
424
-                esc_html__(
425
-                    'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.',
426
-                    "event_espresso"
427
-                ),
428
-                $this->get_this_model()->item_name(),
429
-                $this->get_other_model()->item_name(),
430
-                $this->get_other_model()->item_name(2)
431
-            );
432
-        }
433
-    }
434
-
435
-
436
-    /**
437
-     * Returns whatever is set as the nicename for the object.
438
-     *
439
-     * @return string
440
-     * @throws Exception
441
-     */
442
-    public function getSchemaDescription(): string
443
-    {
444
-        $description = $this instanceof EE_Belongs_To_Relation
445
-            ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso')
446
-            : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso');
447
-        return sprintf(
448
-            $description,
449
-            $this->get_other_model()->get_this_model_name(),
450
-            $this->get_this_model()->get_this_model_name()
451
-        );
452
-    }
453
-
454
-
455
-    /**
456
-     * Returns whatever is set as the $_schema_type property for the object.
457
-     * Note: this will automatically add 'null' to the schema if the object is_nullable()
458
-     *
459
-     * @return string
460
-     */
461
-    public function getSchemaType(): string
462
-    {
463
-        return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array';
464
-    }
465
-
466
-
467
-    /**
468
-     * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
469
-     * this method and return the properties for the schema.
470
-     * The reason this is not a property on the class is because there may be filters set on the values for the property
471
-     * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
472
-     *
473
-     * @return array
474
-     */
475
-    public function getSchemaProperties(): array
476
-    {
477
-        return [];
478
-    }
479
-
480
-
481
-    /**
482
-     * If a child class has enum values, they should override this method and provide a simple array
483
-     * of the enum values.
484
-     * The reason this is not a property on the class is because there may be filterable enum values that
485
-     * are set on the instantiated object that could be filtered after construct.
486
-     *
487
-     * @return array
488
-     */
489
-    public function getSchemaEnum(): array
490
-    {
491
-        return [];
492
-    }
493
-
494
-
495
-    /**
496
-     * This returns the value of the $_schema_format property on the object.
497
-     *
498
-     * @return array
499
-     */
500
-    public function getSchemaFormat(): array
501
-    {
502
-        return [];
503
-    }
504
-
505
-
506
-    /**
507
-     * This returns the value of the $_schema_readonly property on the object.
508
-     *
509
-     * @return bool
510
-     */
511
-    public function getSchemaReadonly(): bool
512
-    {
513
-        return true;
514
-    }
515
-
516
-
517
-    /**
518
-     * This returns elements used to represent this field in the json schema.
519
-     *
520
-     * @link http://json-schema.org/
521
-     * @return array
522
-     * @throws Exception
523
-     */
524
-    public function getSchema(): array
525
-    {
526
-        $schema = [
527
-            'description'   => $this->getSchemaDescription(),
528
-            'type'          => $this->getSchemaType(),
529
-            'relation'      => true,
530
-            'relation_type' => get_class($this),
531
-            'readonly'      => $this->getSchemaReadonly(),
532
-        ];
533
-
534
-        if ($this instanceof EE_HABTM_Relation) {
535
-            $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name();
536
-        }
537
-
538
-        if ($this->getSchemaType() === 'array') {
539
-            $schema['items'] = [
540
-                'type' => 'object',
541
-            ];
542
-        }
543
-
544
-        return $schema;
545
-    }
423
+			return sprintf(
424
+				esc_html__(
425
+					'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.',
426
+					"event_espresso"
427
+				),
428
+				$this->get_this_model()->item_name(),
429
+				$this->get_other_model()->item_name(),
430
+				$this->get_other_model()->item_name(2)
431
+			);
432
+		}
433
+	}
434
+
435
+
436
+	/**
437
+	 * Returns whatever is set as the nicename for the object.
438
+	 *
439
+	 * @return string
440
+	 * @throws Exception
441
+	 */
442
+	public function getSchemaDescription(): string
443
+	{
444
+		$description = $this instanceof EE_Belongs_To_Relation
445
+			? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso')
446
+			: esc_html__('The related %1$s entities to the %2$s.', 'event_espresso');
447
+		return sprintf(
448
+			$description,
449
+			$this->get_other_model()->get_this_model_name(),
450
+			$this->get_this_model()->get_this_model_name()
451
+		);
452
+	}
453
+
454
+
455
+	/**
456
+	 * Returns whatever is set as the $_schema_type property for the object.
457
+	 * Note: this will automatically add 'null' to the schema if the object is_nullable()
458
+	 *
459
+	 * @return string
460
+	 */
461
+	public function getSchemaType(): string
462
+	{
463
+		return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array';
464
+	}
465
+
466
+
467
+	/**
468
+	 * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
469
+	 * this method and return the properties for the schema.
470
+	 * The reason this is not a property on the class is because there may be filters set on the values for the property
471
+	 * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
472
+	 *
473
+	 * @return array
474
+	 */
475
+	public function getSchemaProperties(): array
476
+	{
477
+		return [];
478
+	}
479
+
480
+
481
+	/**
482
+	 * If a child class has enum values, they should override this method and provide a simple array
483
+	 * of the enum values.
484
+	 * The reason this is not a property on the class is because there may be filterable enum values that
485
+	 * are set on the instantiated object that could be filtered after construct.
486
+	 *
487
+	 * @return array
488
+	 */
489
+	public function getSchemaEnum(): array
490
+	{
491
+		return [];
492
+	}
493
+
494
+
495
+	/**
496
+	 * This returns the value of the $_schema_format property on the object.
497
+	 *
498
+	 * @return array
499
+	 */
500
+	public function getSchemaFormat(): array
501
+	{
502
+		return [];
503
+	}
504
+
505
+
506
+	/**
507
+	 * This returns the value of the $_schema_readonly property on the object.
508
+	 *
509
+	 * @return bool
510
+	 */
511
+	public function getSchemaReadonly(): bool
512
+	{
513
+		return true;
514
+	}
515
+
516
+
517
+	/**
518
+	 * This returns elements used to represent this field in the json schema.
519
+	 *
520
+	 * @link http://json-schema.org/
521
+	 * @return array
522
+	 * @throws Exception
523
+	 */
524
+	public function getSchema(): array
525
+	{
526
+		$schema = [
527
+			'description'   => $this->getSchemaDescription(),
528
+			'type'          => $this->getSchemaType(),
529
+			'relation'      => true,
530
+			'relation_type' => get_class($this),
531
+			'readonly'      => $this->getSchemaReadonly(),
532
+		];
533
+
534
+		if ($this instanceof EE_HABTM_Relation) {
535
+			$schema['joining_model_name'] = $this->get_join_model()->get_this_model_name();
536
+		}
537
+
538
+		if ($this->getSchemaType() === 'array') {
539
+			$schema['items'] = [
540
+				'type' => 'object',
541
+			];
542
+		}
543
+
544
+		return $schema;
545
+	}
546 546
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -151,9 +151,9 @@  discard block
 block discarded – undo
151 151
         string $extra_join_sql = ''
152 152
     ): string {
153 153
         return " 
154
-        LEFT JOIN " . $other_table . " AS " . $other_table_alias . " 
155
-        ON " . $other_table_alias . "." . $other_table_column
156
-               . "=" . $this_table_alias . "." . $this_table_join_column
154
+        LEFT JOIN " . $other_table." AS ".$other_table_alias." 
155
+        ON " . $other_table_alias.".".$other_table_column
156
+               . "=".$this_table_alias.".".$this_table_join_column
157 157
                . ($extra_join_sql ? " AND $extra_join_sql" : '');
158 158
     }
159 159
 
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
         $query_params = $this->_disable_default_where_conditions_on_query_param($query_params);
193 193
 
194 194
         $query_param_where_this_model_pk = $this->get_this_model()->get_this_model_name()
195
-                                           . "." . $this->get_this_model()->get_primary_key_field()->get_name();
195
+                                           . ".".$this->get_this_model()->get_primary_key_field()->get_name();
196 196
 
197 197
         $model_object_id = $this->_get_model_object_id($model_object_or_id);
198 198
 
199
-        $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
199
+        $query_params[0][$query_param_where_this_model_pk] = $model_object_id;
200 200
         return $this->get_other_model()->get_all($query_params);
201 201
     }
202 202
 
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
      */
210 210
     protected function _disable_default_where_conditions_on_query_param(array $query_params): array
211 211
     {
212
-        if (! isset($query_params['default_where_conditions'])) {
212
+        if ( ! isset($query_params['default_where_conditions'])) {
213 213
             $query_params['default_where_conditions'] = 'none';
214 214
         }
215 215
         return $query_params;
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
                 $model_object_or_id
242 242
             );
243 243
             /* @var $model_object_or_id EE_Base_Class */
244
-            if (! $delete_is_blocked) {
244
+            if ( ! $delete_is_blocked) {
245 245
                 $this->remove_relation_to($model_object_or_id, $related_model_object);
246 246
                 $related_model_object->delete();
247 247
                 $deleted_count++;
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
             if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
280 280
                 $this->remove_relation_to($model_object_or_id, $related_model_object);
281 281
                 $deleted_count++;
282
-                if (! $delete_is_blocked) {
282
+                if ( ! $delete_is_blocked) {
283 283
                     $related_model_object->delete_permanently();
284 284
                 } else {
285 285
                     // delete is blocked
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
                 }
289 289
             } else {
290 290
                 // its not a soft-deletable thing anyways. do the normal logic.
291
-                if (! $delete_is_blocked) {
291
+                if ( ! $delete_is_blocked) {
292 292
                     $this->remove_relation_to($model_object_or_id, $related_model_object);
293 293
                     $related_model_object->delete();
294 294
                     $deleted_count++;
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
         if ($model_object_or_id instanceof EE_Base_Class) {
315 315
             $model_object_id = $model_object_or_id->ID();
316 316
         }
317
-        if (! $model_object_id) {
317
+        if ( ! $model_object_id) {
318 318
             throw new EE_Error(
319 319
                 sprintf(
320 320
                     esc_html__(
Please login to merge, or discard this patch.