Completed
Branch FET/extra-logging-when-trashin... (b6e112)
by
unknown
36:04 queued 27:41
created
core/db_models/relations/EE_HABTM_Any_Relation.php 2 patches
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -10,294 +10,294 @@
 block discarded – undo
10 10
  */
11 11
 class EE_HABTM_Any_Relation extends EE_HABTM_Relation
12 12
 {
13
-    /**
14
-     * @var string
15
-     */
16
-    protected $_alphabetically_first_model_name;
13
+	/**
14
+	 * @var string
15
+	 */
16
+	protected $_alphabetically_first_model_name;
17 17
 
18
-    /**
19
-     * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
20
-     * (and an ee joining-model.) This knows how to join the models,
21
-     * get related models across the relation, and add-and-remove the relationships.
22
-     *
23
-     * @param boolean $block_deletes                 for this type of relation, we block by default for now. if there
24
-     *                                               are related models across this relation, block (prevent and add an
25
-     *                                               error) the deletion of this model
26
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
27
-     *                                               default
28
-     */
29
-    public function __construct($block_deletes = true, $blocking_delete_error_message = '')
30
-    {
31
-        parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
32
-    }
18
+	/**
19
+	 * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table
20
+	 * (and an ee joining-model.) This knows how to join the models,
21
+	 * get related models across the relation, and add-and-remove the relationships.
22
+	 *
23
+	 * @param boolean $block_deletes                 for this type of relation, we block by default for now. if there
24
+	 *                                               are related models across this relation, block (prevent and add an
25
+	 *                                               error) the deletion of this model
26
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
27
+	 *                                               default
28
+	 */
29
+	public function __construct($block_deletes = true, $blocking_delete_error_message = '')
30
+	{
31
+		parent::__construct('Extra_Join', $block_deletes, $blocking_delete_error_message);
32
+	}
33 33
 
34 34
 
35
-    /**
36
-     * @param $this_model_name
37
-     * @param $other_model_name
38
-     * @throws EE_Error
39
-     */
40
-    public function _construct_finalize_set_models($this_model_name, $other_model_name)
41
-    {
42
-        if ($this_model_name < $other_model_name) {
43
-            $this->_alphabetically_first_model_name = $this_model_name;
44
-        } else {
45
-            $this->_alphabetically_first_model_name = $other_model_name;
46
-        }
47
-        parent::_construct_finalize_set_models($this_model_name, $other_model_name);
48
-    }
35
+	/**
36
+	 * @param $this_model_name
37
+	 * @param $other_model_name
38
+	 * @throws EE_Error
39
+	 */
40
+	public function _construct_finalize_set_models($this_model_name, $other_model_name)
41
+	{
42
+		if ($this_model_name < $other_model_name) {
43
+			$this->_alphabetically_first_model_name = $this_model_name;
44
+		} else {
45
+			$this->_alphabetically_first_model_name = $other_model_name;
46
+		}
47
+		parent::_construct_finalize_set_models($this_model_name, $other_model_name);
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @param string $model_name
53
-     * @param string $id_or_name_field should be the string 'ID' or 'name' only
54
-     * @return EE_Model_Field_Base
55
-     * @throws \EE_Error
56
-     */
57
-    public function get_join_table_fk_field_to($model_name, $id_or_name_field)
58
-    {
59
-        $order = null;
60
-        if ($model_name === $this->_alphabetically_first_model_name) {
61
-            $order = 'first';
62
-        } else {
63
-            $order = 'second';
64
-        }
65
-        return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
66
-    }
51
+	/**
52
+	 * @param string $model_name
53
+	 * @param string $id_or_name_field should be the string 'ID' or 'name' only
54
+	 * @return EE_Model_Field_Base
55
+	 * @throws \EE_Error
56
+	 */
57
+	public function get_join_table_fk_field_to($model_name, $id_or_name_field)
58
+	{
59
+		$order = null;
60
+		if ($model_name === $this->_alphabetically_first_model_name) {
61
+			$order = 'first';
62
+		} else {
63
+			$order = 'second';
64
+		}
65
+		return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
66
+	}
67 67
 
68 68
 
69
-    /**
70
-     * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
71
-     * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
72
-     *
73
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
74
-     * @return string of SQL
75
-     * @throws \EE_Error
76
-     */
77
-    public function get_join_to_intermediate_model_statement($model_relation_chain)
78
-    {
79
-        // create sql like
80
-        // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
81
-        // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
82
-        // remember the model relation chain to the JOIN model, because we'll
83
-        // need it for get_join_statement()
84
-        $this->_model_relation_chain_to_join_model = $model_relation_chain;
85
-        $this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();
86
-        $join_table_fk_field_to_this_table         = $this->get_join_table_fk_field_to(
87
-            $this->get_this_model()->get_this_model_name(),
88
-            'ID'
89
-        );
90
-        $field_with_model_name                     = $this->get_join_table_fk_field_to(
91
-            $this->get_this_model()->get_this_model_name(),
92
-            'name'
93
-        );
94
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95
-            $model_relation_chain,
96
-            $this->get_this_model()->get_this_model_name()
97
-        ) . $this_table_pk_field->get_table_alias();
98
-        $join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99
-            $model_relation_chain,
100
-            $this->get_join_model()->get_this_model_name()
101
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
102
-        $join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
103
-        // phew! ok, we have all the info we need, now we can create the SQL join string
104
-        $SQL = $this->_left_join(
105
-            $join_table,
106
-            $join_table_alias,
107
-            $join_table_fk_field_to_this_table->get_table_column(),
108
-            $this_table_alias,
109
-            $this_table_pk_field->get_table_column(),
110
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
-        ) .
112
-               $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
69
+	/**
70
+	 * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN
71
+	 * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table"
72
+	 *
73
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
74
+	 * @return string of SQL
75
+	 * @throws \EE_Error
76
+	 */
77
+	public function get_join_to_intermediate_model_statement($model_relation_chain)
78
+	{
79
+		// create sql like
80
+		// LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this
81
+		// LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk
82
+		// remember the model relation chain to the JOIN model, because we'll
83
+		// need it for get_join_statement()
84
+		$this->_model_relation_chain_to_join_model = $model_relation_chain;
85
+		$this_table_pk_field                       = $this->get_this_model()->get_primary_key_field();
86
+		$join_table_fk_field_to_this_table         = $this->get_join_table_fk_field_to(
87
+			$this->get_this_model()->get_this_model_name(),
88
+			'ID'
89
+		);
90
+		$field_with_model_name                     = $this->get_join_table_fk_field_to(
91
+			$this->get_this_model()->get_this_model_name(),
92
+			'name'
93
+		);
94
+		$this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95
+			$model_relation_chain,
96
+			$this->get_this_model()->get_this_model_name()
97
+		) . $this_table_pk_field->get_table_alias();
98
+		$join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99
+			$model_relation_chain,
100
+			$this->get_join_model()->get_this_model_name()
101
+		) . $join_table_fk_field_to_this_table->get_table_alias();
102
+		$join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
103
+		// phew! ok, we have all the info we need, now we can create the SQL join string
104
+		$SQL = $this->_left_join(
105
+			$join_table,
106
+			$join_table_alias,
107
+			$join_table_fk_field_to_this_table->get_table_column(),
108
+			$this_table_alias,
109
+			$this_table_pk_field->get_table_column(),
110
+			$field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
+		) .
112
+			   $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
113 113
 
114
-        return $SQL;
115
-    }
114
+		return $SQL;
115
+	}
116 116
 
117 117
 
118
-    /**
119
-     * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
120
-     * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
121
-     * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
122
-     * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
123
-     * the intermediate join table, and then to the other model's pk's table
124
-     *
125
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
126
-     * @return string of SQL
127
-     * @throws \EE_Error
128
-     */
129
-    public function get_join_statement($model_relation_chain)
130
-    {
131
-        if ($this->_model_relation_chain_to_join_model === null) {
132
-            throw new EE_Error(sprintf(__(
133
-                'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
134
-                'event_espresso'
135
-            )));
136
-        }
137
-        $join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
138
-            $this->get_this_model()->get_this_model_name(),
139
-            'ID'
140
-        );
141
-        $join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to(
142
-            $this->get_other_model()->get_this_model_name(),
143
-            'ID'
144
-        );
145
-        $field_with_other_model_name        = $this->get_join_table_fk_field_to(
146
-            $this->get_other_model()->get_this_model_name(),
147
-            'name'
148
-        );
118
+	/**
119
+	 * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table
120
+	 * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between
121
+	 * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the
122
+	 * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to
123
+	 * the intermediate join table, and then to the other model's pk's table
124
+	 *
125
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
126
+	 * @return string of SQL
127
+	 * @throws \EE_Error
128
+	 */
129
+	public function get_join_statement($model_relation_chain)
130
+	{
131
+		if ($this->_model_relation_chain_to_join_model === null) {
132
+			throw new EE_Error(sprintf(__(
133
+				'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement',
134
+				'event_espresso'
135
+			)));
136
+		}
137
+		$join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
138
+			$this->get_this_model()->get_this_model_name(),
139
+			'ID'
140
+		);
141
+		$join_table_fk_field_to_other_table = $this->get_join_table_fk_field_to(
142
+			$this->get_other_model()->get_this_model_name(),
143
+			'ID'
144
+		);
145
+		$field_with_other_model_name        = $this->get_join_table_fk_field_to(
146
+			$this->get_other_model()->get_this_model_name(),
147
+			'name'
148
+		);
149 149
 
150
-        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151
-            $this->_model_relation_chain_to_join_model,
152
-            $this->get_join_model()->get_this_model_name()
153
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
150
+		$join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151
+			$this->_model_relation_chain_to_join_model,
152
+			$this->get_join_model()->get_this_model_name()
153
+		) . $join_table_fk_field_to_this_table->get_table_alias();
154 154
 
155
-        $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156
-        $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157
-            $model_relation_chain,
158
-            $this->get_other_model()->get_this_model_name()
159
-        ) . $other_table_pk_field->get_table_alias();
160
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
155
+		$other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156
+		$other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157
+			$model_relation_chain,
158
+			$this->get_other_model()->get_this_model_name()
159
+		) . $other_table_pk_field->get_table_alias();
160
+		$other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
161 161
 
162
-        $SQL = $this->_left_join(
163
-            $other_table,
164
-            $other_table_alias,
165
-            $other_table_pk_field->get_table_column(),
166
-            $join_table_alias,
167
-            $join_table_fk_field_to_other_table->get_table_column(),
168
-            $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
-        ) .
170
-               $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171
-        return $SQL;
172
-    }
162
+		$SQL = $this->_left_join(
163
+			$other_table,
164
+			$other_table_alias,
165
+			$other_table_pk_field->get_table_column(),
166
+			$join_table_alias,
167
+			$join_table_fk_field_to_other_table->get_table_column(),
168
+			$field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
+		) .
170
+			   $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171
+		return $SQL;
172
+	}
173 173
 
174 174
 
175
-    /**
176
-     * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
177
-     *
178
-     * @param EE_Base_Class|int $this_obj_or_id
179
-     * @param EE_Base_Class|int $other_obj_or_id
180
-     * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
181
-     *                                                            checking existing values and for setting new rows if
182
-     *                                                            no exact matches.
183
-     * @return EE_Base_Class
184
-     * @throws \EE_Error
185
-     */
186
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
187
-    {
188
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190
-        // check if such a relationship already exists
191
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
192
-            $this->get_this_model()->get_this_model_name(),
193
-            'ID'
194
-        );
195
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
196
-            $this->get_this_model()->get_this_model_name(),
197
-            'name'
198
-        );
199
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
200
-            $this->get_other_model()->get_this_model_name(),
201
-            'ID'
202
-        );
203
-        $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
204
-            $this->get_other_model()->get_this_model_name(),
205
-            'name'
206
-        );
175
+	/**
176
+	 * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like.
177
+	 *
178
+	 * @param EE_Base_Class|int $this_obj_or_id
179
+	 * @param EE_Base_Class|int $other_obj_or_id
180
+	 * @param array             $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for
181
+	 *                                                            checking existing values and for setting new rows if
182
+	 *                                                            no exact matches.
183
+	 * @return EE_Base_Class
184
+	 * @throws \EE_Error
185
+	 */
186
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
187
+	{
188
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190
+		// check if such a relationship already exists
191
+		$join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
192
+			$this->get_this_model()->get_this_model_name(),
193
+			'ID'
194
+		);
195
+		$join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
196
+			$this->get_this_model()->get_this_model_name(),
197
+			'name'
198
+		);
199
+		$join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
200
+			$this->get_other_model()->get_this_model_name(),
201
+			'ID'
202
+		);
203
+		$join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
204
+			$this->get_other_model()->get_this_model_name(),
205
+			'name'
206
+		);
207 207
 
208
-        $cols_n_values = array(
209
-            $join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
210
-            $join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
211
-            $join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
212
-            $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
213
-        );
208
+		$cols_n_values = array(
209
+			$join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
210
+			$join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
211
+			$join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
212
+			$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
213
+		);
214 214
 
215
-        // if $where_query exists lets add them to the query_params.
216
-        if (! empty($extra_join_model_fields_n_values)) {
217
-            // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
218
-            // make sure we strip THIS models name from the query param
219
-            $parsed_query = array();
220
-            foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
-                $query_param                = str_replace(
222
-                    $this->get_join_model()->get_this_model_name() . ".",
223
-                    "",
224
-                    $query_param
225
-                );
226
-                $parsed_query[ $query_param ] = $val;
227
-            }
228
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
229
-        }
215
+		// if $where_query exists lets add them to the query_params.
216
+		if (! empty($extra_join_model_fields_n_values)) {
217
+			// make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
218
+			// make sure we strip THIS models name from the query param
219
+			$parsed_query = array();
220
+			foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
+				$query_param                = str_replace(
222
+					$this->get_join_model()->get_this_model_name() . ".",
223
+					"",
224
+					$query_param
225
+				);
226
+				$parsed_query[ $query_param ] = $val;
227
+			}
228
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
229
+		}
230 230
 
231
-        $query_params = array($cols_n_values);
231
+		$query_params = array($cols_n_values);
232 232
 
233 233
 
234
-        $existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
235
-        // if there is already an entry in the join table, indicating a relationship, we're done
236
-        // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237
-        // the other tables, use the joining model directly!
238
-        if (! $existing_entry_in_join_table) {
239
-            $this->get_join_model()->insert($cols_n_values);
240
-        }
241
-        return $other_model_obj;
242
-    }
234
+		$existing_entry_in_join_table = $this->get_join_model()->get_one($query_params);
235
+		// if there is already an entry in the join table, indicating a relationship, we're done
236
+		// again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237
+		// the other tables, use the joining model directly!
238
+		if (! $existing_entry_in_join_table) {
239
+			$this->get_join_model()->insert($cols_n_values);
240
+		}
241
+		return $other_model_obj;
242
+	}
243 243
 
244 244
 
245
-    /**
246
-     * Deletes any rows in the join table that have foreign keys matching the other model objects specified
247
-     *
248
-     * @param EE_Base_Class|int $this_obj_or_id
249
-     * @param EE_Base_Class|int $other_obj_or_id
250
-     * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
251
-     *                                       values and for removing existing rows if exact matches exist.
252
-     * @return EE_Base_Class
253
-     * @throws \EE_Error
254
-     */
255
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
256
-    {
257
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259
-        // check if such a relationship already exists
260
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
261
-            $this->get_this_model()->get_this_model_name(),
262
-            'ID'
263
-        );
264
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
265
-            $this->get_this_model()->get_this_model_name(),
266
-            'name'
267
-        );
268
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
269
-            $this->get_other_model()->get_this_model_name(),
270
-            'ID'
271
-        );
272
-        $join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
273
-            $this->get_other_model()->get_this_model_name(),
274
-            'name'
275
-        );
245
+	/**
246
+	 * Deletes any rows in the join table that have foreign keys matching the other model objects specified
247
+	 *
248
+	 * @param EE_Base_Class|int $this_obj_or_id
249
+	 * @param EE_Base_Class|int $other_obj_or_id
250
+	 * @param array             $where_query col=>val pairs that are used as extra conditions for checking existing
251
+	 *                                       values and for removing existing rows if exact matches exist.
252
+	 * @return EE_Base_Class
253
+	 * @throws \EE_Error
254
+	 */
255
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
256
+	{
257
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259
+		// check if such a relationship already exists
260
+		$join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
261
+			$this->get_this_model()->get_this_model_name(),
262
+			'ID'
263
+		);
264
+		$join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
265
+			$this->get_this_model()->get_this_model_name(),
266
+			'name'
267
+		);
268
+		$join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
269
+			$this->get_other_model()->get_this_model_name(),
270
+			'ID'
271
+		);
272
+		$join_model_name_field_to_other_model = $this->get_join_table_fk_field_to(
273
+			$this->get_other_model()->get_this_model_name(),
274
+			'name'
275
+		);
276 276
 
277
-        $cols_n_values = array(
278
-            $join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
279
-            $join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
280
-            $join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
281
-            $join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
282
-        );
277
+		$cols_n_values = array(
278
+			$join_model_fk_to_this_model->get_name()          => $this_model_obj->ID(),
279
+			$join_model_name_field_to_this_model->get_name()  => $this_model_obj->get_model()->get_this_model_name(),
280
+			$join_model_fk_to_other_model->get_name()         => $other_model_obj->ID(),
281
+			$join_model_name_field_to_other_model->get_name() => $other_model_obj->get_model()->get_this_model_name(),
282
+		);
283 283
 
284
-        // if $where_query exists lets add them to the query_params.
285
-        if (! empty($where_query)) {
286
-            // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
287
-            // make sure we strip THIS models name from the query param
288
-            $parsed_query = array();
289
-            foreach ($where_query as $query_param => $val) {
290
-                $query_param                = str_replace(
291
-                    $this->get_join_model()->get_this_model_name() . ".",
292
-                    "",
293
-                    $query_param
294
-                );
295
-                $parsed_query[ $query_param ] = $val;
296
-            }
297
-            $cols_n_values = array_merge($cols_n_values, $parsed_query);
298
-        }
284
+		// if $where_query exists lets add them to the query_params.
285
+		if (! empty($where_query)) {
286
+			// make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
287
+			// make sure we strip THIS models name from the query param
288
+			$parsed_query = array();
289
+			foreach ($where_query as $query_param => $val) {
290
+				$query_param                = str_replace(
291
+					$this->get_join_model()->get_this_model_name() . ".",
292
+					"",
293
+					$query_param
294
+				);
295
+				$parsed_query[ $query_param ] = $val;
296
+			}
297
+			$cols_n_values = array_merge($cols_n_values, $parsed_query);
298
+		}
299 299
 
300
-        $this->get_join_model()->delete(array($cols_n_values));
301
-        return $other_model_obj;
302
-    }
300
+		$this->get_join_model()->delete(array($cols_n_values));
301
+		return $other_model_obj;
302
+	}
303 303
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         } else {
63 63
             $order = 'second';
64 64
         }
65
-        return $this->get_join_model()->field_settings_for('EXJ_' . $order . '_model_' . $id_or_name_field);
65
+        return $this->get_join_model()->field_settings_for('EXJ_'.$order.'_model_'.$id_or_name_field);
66 66
     }
67 67
 
68 68
 
@@ -87,19 +87,19 @@  discard block
 block discarded – undo
87 87
             $this->get_this_model()->get_this_model_name(),
88 88
             'ID'
89 89
         );
90
-        $field_with_model_name                     = $this->get_join_table_fk_field_to(
90
+        $field_with_model_name = $this->get_join_table_fk_field_to(
91 91
             $this->get_this_model()->get_this_model_name(),
92 92
             'name'
93 93
         );
94
-        $this_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
94
+        $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
95 95
             $model_relation_chain,
96 96
             $this->get_this_model()->get_this_model_name()
97
-        ) . $this_table_pk_field->get_table_alias();
98
-        $join_table_alias                          = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
97
+        ).$this_table_pk_field->get_table_alias();
98
+        $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
99 99
             $model_relation_chain,
100 100
             $this->get_join_model()->get_this_model_name()
101
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
102
-        $join_table                                = $this->get_join_model()->get_table_for_alias($join_table_alias);
101
+        ).$join_table_fk_field_to_this_table->get_table_alias();
102
+        $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias);
103 103
         // phew! ok, we have all the info we need, now we can create the SQL join string
104 104
         $SQL = $this->_left_join(
105 105
             $join_table,
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
             $join_table_fk_field_to_this_table->get_table_column(),
108 108
             $this_table_alias,
109 109
             $this_table_pk_field->get_table_column(),
110
-            $field_with_model_name->get_qualified_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
111
-        ) .
110
+            $field_with_model_name->get_qualified_column()."='".$this->get_this_model()->get_this_model_name()."'"
111
+        ).
112 112
                $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias);
113 113
 
114 114
         return $SQL;
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                 'event_espresso'
135 135
             )));
136 136
         }
137
-        $join_table_fk_field_to_this_table  = $this->get_join_table_fk_field_to(
137
+        $join_table_fk_field_to_this_table = $this->get_join_table_fk_field_to(
138 138
             $this->get_this_model()->get_this_model_name(),
139 139
             'ID'
140 140
         );
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
             $this->get_other_model()->get_this_model_name(),
143 143
             'ID'
144 144
         );
145
-        $field_with_other_model_name        = $this->get_join_table_fk_field_to(
145
+        $field_with_other_model_name = $this->get_join_table_fk_field_to(
146 146
             $this->get_other_model()->get_this_model_name(),
147 147
             'name'
148 148
         );
@@ -150,14 +150,14 @@  discard block
 block discarded – undo
150 150
         $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
151 151
             $this->_model_relation_chain_to_join_model,
152 152
             $this->get_join_model()->get_this_model_name()
153
-        ) . $join_table_fk_field_to_this_table->get_table_alias();
153
+        ).$join_table_fk_field_to_this_table->get_table_alias();
154 154
 
155 155
         $other_table_pk_field = $this->get_other_model()->get_primary_key_field();
156 156
         $other_table_alias    = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
157 157
             $model_relation_chain,
158 158
             $this->get_other_model()->get_this_model_name()
159
-        ) . $other_table_pk_field->get_table_alias();
160
-        $other_table          = $this->get_other_model()->get_table_for_alias($other_table_alias);
159
+        ).$other_table_pk_field->get_table_alias();
160
+        $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias);
161 161
 
162 162
         $SQL = $this->_left_join(
163 163
             $other_table,
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
             $other_table_pk_field->get_table_column(),
166 166
             $join_table_alias,
167 167
             $join_table_fk_field_to_other_table->get_table_column(),
168
-            $field_with_other_model_name->get_qualified_column() . "='" . $this->get_other_model()->get_this_model_name() . "'"
169
-        ) .
168
+            $field_with_other_model_name->get_qualified_column()."='".$this->get_other_model()->get_this_model_name()."'"
169
+        ).
170 170
                $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias);
171 171
         return $SQL;
172 172
     }
@@ -188,15 +188,15 @@  discard block
 block discarded – undo
188 188
         $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
189 189
         $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
190 190
         // check if such a relationship already exists
191
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
191
+        $join_model_fk_to_this_model = $this->get_join_table_fk_field_to(
192 192
             $this->get_this_model()->get_this_model_name(),
193 193
             'ID'
194 194
         );
195
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
195
+        $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to(
196 196
             $this->get_this_model()->get_this_model_name(),
197 197
             'name'
198 198
         );
199
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
199
+        $join_model_fk_to_other_model = $this->get_join_table_fk_field_to(
200 200
             $this->get_other_model()->get_this_model_name(),
201 201
             'ID'
202 202
         );
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
         );
214 214
 
215 215
         // if $where_query exists lets add them to the query_params.
216
-        if (! empty($extra_join_model_fields_n_values)) {
216
+        if ( ! empty($extra_join_model_fields_n_values)) {
217 217
             // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
218 218
             // make sure we strip THIS models name from the query param
219 219
             $parsed_query = array();
220 220
             foreach ($extra_join_model_fields_n_values as $query_param => $val) {
221
-                $query_param                = str_replace(
222
-                    $this->get_join_model()->get_this_model_name() . ".",
221
+                $query_param = str_replace(
222
+                    $this->get_join_model()->get_this_model_name().".",
223 223
                     "",
224 224
                     $query_param
225 225
                 );
226
-                $parsed_query[ $query_param ] = $val;
226
+                $parsed_query[$query_param] = $val;
227 227
             }
228 228
             $cols_n_values = array_merge($cols_n_values, $parsed_query);
229 229
         }
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         // if there is already an entry in the join table, indicating a relationship, we're done
236 236
         // again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to
237 237
         // the other tables, use the joining model directly!
238
-        if (! $existing_entry_in_join_table) {
238
+        if ( ! $existing_entry_in_join_table) {
239 239
             $this->get_join_model()->insert($cols_n_values);
240 240
         }
241 241
         return $other_model_obj;
@@ -257,15 +257,15 @@  discard block
 block discarded – undo
257 257
         $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
258 258
         $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
259 259
         // check if such a relationship already exists
260
-        $join_model_fk_to_this_model          = $this->get_join_table_fk_field_to(
260
+        $join_model_fk_to_this_model = $this->get_join_table_fk_field_to(
261 261
             $this->get_this_model()->get_this_model_name(),
262 262
             'ID'
263 263
         );
264
-        $join_model_name_field_to_this_model  = $this->get_join_table_fk_field_to(
264
+        $join_model_name_field_to_this_model = $this->get_join_table_fk_field_to(
265 265
             $this->get_this_model()->get_this_model_name(),
266 266
             'name'
267 267
         );
268
-        $join_model_fk_to_other_model         = $this->get_join_table_fk_field_to(
268
+        $join_model_fk_to_other_model = $this->get_join_table_fk_field_to(
269 269
             $this->get_other_model()->get_this_model_name(),
270 270
             'ID'
271 271
         );
@@ -282,17 +282,17 @@  discard block
 block discarded – undo
282 282
         );
283 283
 
284 284
         // if $where_query exists lets add them to the query_params.
285
-        if (! empty($where_query)) {
285
+        if ( ! empty($where_query)) {
286 286
             // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name)
287 287
             // make sure we strip THIS models name from the query param
288 288
             $parsed_query = array();
289 289
             foreach ($where_query as $query_param => $val) {
290
-                $query_param                = str_replace(
291
-                    $this->get_join_model()->get_this_model_name() . ".",
290
+                $query_param = str_replace(
291
+                    $this->get_join_model()->get_this_model_name().".",
292 292
                     "",
293 293
                     $query_param
294 294
                 );
295
-                $parsed_query[ $query_param ] = $val;
295
+                $parsed_query[$query_param] = $val;
296 296
             }
297 297
             $cols_n_values = array_merge($cols_n_values, $parsed_query);
298 298
         }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Revision_Relation.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191 191
         foreach ($autosave_relations as $a_r) {
192 192
             $pid = $a_r->parent();
193
-            if (! empty($pid)) {
193
+            if ( ! empty($pid)) {
194 194
                 $parent_ids[] = $pid;
195 195
             } else {
196 196
                 $return_objs[] = $a_r;
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
         }
207 207
 
208 208
         // now we setup the query to get all the parents
209
-        if (! empty($parent_ids)) {
210
-            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
-            $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
209
+        if ( ! empty($parent_ids)) {
210
+            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name().".".$this->get_this_model()->get_primary_key_field()->get_name();
211
+            $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids);
212 212
             $parents                                          = $this->get_other_model()->get_all($query_params);
213 213
         }
214 214
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
             var_dump($this_obj);
244 244
             var_dump($other_obj);/**/
245 245
 
246
-            if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
246
+            if ( ! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247 247
                 // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248 248
                 $has_parent_obj = $this->get_other_model()->get_one(array(
249 249
                     array(
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                     $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260 260
                     $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261 261
 
262
-                    if (! $remove_relation) {
262
+                    if ( ! $remove_relation) {
263 263
                         $other_obj->save();
264 264
                         return array($other_obj);
265 265
                     } elseif ($remove_relation && ! $this->_blocking_delete) {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288 288
         } else {
289 289
             // we only need to do the below IF this is not a remove relation
290
-            if (! $remove_relation) {
290
+            if ( ! $remove_relation) {
291 291
                 // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292 292
                 // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293 293
                 $existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
Please login to merge, or discard this patch.
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -12,303 +12,303 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for
17
-     * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this
18
-     * value).  The _primary_cpt_field is what is equivalent to the post_id field on a cpt join.
19
-     *
20
-     * @var string
21
-     */
22
-    private $_primary_cpt_field;
23
-
24
-
25
-    /**
26
-     * This is what field serves as the "parent" column that is linked with whatever the main model's calling this
27
-     * relation has as a primary key.  In other words EEM_Event has 'Datetime' => new
28
-     * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent').  That means that in the EEM_Datetime model the
29
-     * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the
30
-     * primary key in the other model (EEM_Datetime).
31
-     *
32
-     * @var string
33
-     */
34
-    private $_parent_pk_relation_field;
35
-
36
-
37
-    /**
38
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
39
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
40
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
41
-     * related models across the relation, and add-and-remove the relationships.
42
-     *
43
-     * @param string  $primary_cpt_field             See property description for details
44
-     * @param string  $parent_pk_relation_field      This is the field that is "connected" to the $primary_cpt_field.
45
-     *                                               See property desc for details.
46
-     * @param boolean $block_deletes                 For this type of relation, we block by default. If there are
47
-     *                                               related models across this relation, block (prevent and add an
48
-     *                                               error) the deletion of this model
49
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
50
-     *                                               default
51
-     */
52
-    public function __construct(
53
-        $primary_cpt_field,
54
-        $parent_pk_relation_field,
55
-        $block_deletes = true,
56
-        $blocking_delete_error_message = null
57
-    ) {
58
-        $this->_primary_cpt_field        = $primary_cpt_field;
59
-        $this->_parent_pk_relation_field = $parent_pk_relation_field;
60
-        parent::__construct($block_deletes, $blocking_delete_error_message);
61
-    }
62
-
63
-
64
-    /**
65
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
66
-     * you like.
67
-     *
68
-     * @param EE_Base_Class|int $this_obj_or_id
69
-     * @param EE_Base_Class|int $other_obj_or_id
70
-     * @param array             $extra_join_model_fields_n_values
71
-     * @return \EE_Base_Class
72
-     * @throws \EE_Error
73
-     */
74
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
-    {
76
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
78
-
79
-        // handle possible revisions
80
-        $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj);
81
-
82
-        // if is array, then we've already done the add_relation so let's get out
83
-        if (is_array($other_model_obj)) {
84
-            return $other_model_obj[0];
85
-        }
86
-        // find the field on the other model which is a foreign key to this model
87
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
88
-        // set that field on the other model to this model's ID
89
-        $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
90
-        $other_model_obj->save();
91
-        return $other_model_obj;
92
-    }
93
-
94
-
95
-    /**
96
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object
97
-     *
98
-     * @param EE_Base_Class|int $this_obj_or_id
99
-     * @param EE_Base_Class|int $other_obj_or_id
100
-     * @param array             $where_query
101
-     * @return \EE_Base_Class
102
-     * @throws \EE_Error
103
-     */
104
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
105
-    {
106
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id);
107
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
108
-        // handle possible revisions
109
-        $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true);
110
-
111
-
112
-        // if is array, then we've already done the add_relation so let's get out
113
-        if (is_array($other_model_obj)) {
114
-            return $other_model_obj[0];
115
-        }
116
-
117
-        // find the field on the other model which is a foreign key to this model
118
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
119
-
120
-
121
-        // set that field on the other model to this model's ID
122
-        if ($this->_blocking_delete) {
123
-            $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
124
-            $other_model_obj->save();
125
-        } else {
126
-            $other_model_obj->delete();
127
-            $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
128
-            return $other_model_obj;
129
-        }
130
-        return $other_model_obj;
131
-    }
132
-
133
-
134
-    /**
135
-     * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions
136
-     * in here.
137
-     *
138
-     * @param  EE_Base_Class|int $model_object_or_id
139
-     * @param  array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
140
-     * @param  boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
141
-     * @return EE_Base_Class[]
142
-     * @throws \EE_Error
143
-     */
144
-    public function get_all_related(
145
-        $model_object_or_id,
146
-        $query_params = array(),
147
-        $values_already_prepared_by_model_object = false
148
-    ) {
149
-        if ($values_already_prepared_by_model_object !== false) {
150
-            EE_Error::doing_it_wrong(
151
-                'EE_Model_Relation_Base::get_all_related',
152
-                __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
153
-                '4.8.1'
154
-            );
155
-        }
156
-
157
-        // if this is an autosave then we're going to get things differently
158
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
159
-            return $this->_do_autosave_get_all($model_object_or_id, $query_params);
160
-        }
161
-
162
-        return parent::get_all_related($model_object_or_id, $query_params);
163
-    }
164
-
165
-
166
-    /**
167
-     * If we're in the midst of an autosave then we're going to do things a bit differently than the usual
168
-     * get_all_related (commenting within).  For description of params see the get_all_related() comments
169
-     *
170
-     * @access protected
171
-     * @param      $model_object_or_id
172
-     * @param      $query_params
173
-     * @param bool $deprecated
174
-     * @return \EE_Base_Class[]
175
-     * @throws \EE_Error
176
-     */
177
-    protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false)
178
-    {
179
-
180
-        // first we check if the post_id for the incoming query is for an autosave.  If it isn't that's what we want!
181
-        $model_object_id = $this->_get_model_object_id($model_object_or_id);
182
-
183
-        $autosave  = wp_get_post_autosave($model_object_id);
184
-        $id_to_use = $autosave ? $autosave->ID : $model_object_id;
185
-
186
-        $autosave_relations = parent::get_all_related($id_to_use, $query_params);
187
-        $parent_ids         = $parents = array();
188
-        $return_objs        = array();
189
-
190
-        // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191
-        foreach ($autosave_relations as $a_r) {
192
-            $pid = $a_r->parent();
193
-            if (! empty($pid)) {
194
-                $parent_ids[] = $pid;
195
-            } else {
196
-                $return_objs[] = $a_r;
197
-            }
198
-        }
199
-
200
-        // we have to make sure we also include the ORIGINAL values
201
-        $originals = parent::get_all_related($model_object_or_id, $query_params);
202
-
203
-        // merge $originals with $return_objs
204
-        if ($originals) {
205
-            $return_objs = array_merge($originals, $return_objs);
206
-        }
207
-
208
-        // now we setup the query to get all the parents
209
-        if (! empty($parent_ids)) {
210
-            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
-            $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
212
-            $parents                                          = $this->get_other_model()->get_all($query_params);
213
-        }
214
-
215
-        // var_dump($parents);
216
-
217
-
218
-        // now merge parents with our current $return_objs and send back
219
-        return array_merge($parents, $return_objs);
220
-    }
221
-
222
-
223
-    /**
224
-     * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it
225
-     * is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS
226
-     * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is
227
-     * sometime delayed if the object is created/saved first by the autosave)
228
-     *
229
-     * @param  EE_Base_Class $this_obj
230
-     * @param  EE_Base_Class $other_obj
231
-     * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
232
-     * @return EE_Base_Class. ($other_obj);
233
-     * @throws \EE_Error
234
-     */
235
-    protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false)
236
-    {
237
-        $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
238
-        // now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
239
-        if ($this_obj->post_type() === 'revision') {
240
-            // first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
241
-            $parent_evt_id = $this_obj->parent();
242
-            /*var_dump($parent_evt_id);
15
+	/**
16
+	 * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for
17
+	 * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this
18
+	 * value).  The _primary_cpt_field is what is equivalent to the post_id field on a cpt join.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	private $_primary_cpt_field;
23
+
24
+
25
+	/**
26
+	 * This is what field serves as the "parent" column that is linked with whatever the main model's calling this
27
+	 * relation has as a primary key.  In other words EEM_Event has 'Datetime' => new
28
+	 * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent').  That means that in the EEM_Datetime model the
29
+	 * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the
30
+	 * primary key in the other model (EEM_Datetime).
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $_parent_pk_relation_field;
35
+
36
+
37
+	/**
38
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
39
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
40
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
41
+	 * related models across the relation, and add-and-remove the relationships.
42
+	 *
43
+	 * @param string  $primary_cpt_field             See property description for details
44
+	 * @param string  $parent_pk_relation_field      This is the field that is "connected" to the $primary_cpt_field.
45
+	 *                                               See property desc for details.
46
+	 * @param boolean $block_deletes                 For this type of relation, we block by default. If there are
47
+	 *                                               related models across this relation, block (prevent and add an
48
+	 *                                               error) the deletion of this model
49
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
50
+	 *                                               default
51
+	 */
52
+	public function __construct(
53
+		$primary_cpt_field,
54
+		$parent_pk_relation_field,
55
+		$block_deletes = true,
56
+		$blocking_delete_error_message = null
57
+	) {
58
+		$this->_primary_cpt_field        = $primary_cpt_field;
59
+		$this->_parent_pk_relation_field = $parent_pk_relation_field;
60
+		parent::__construct($block_deletes, $blocking_delete_error_message);
61
+	}
62
+
63
+
64
+	/**
65
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
66
+	 * you like.
67
+	 *
68
+	 * @param EE_Base_Class|int $this_obj_or_id
69
+	 * @param EE_Base_Class|int $other_obj_or_id
70
+	 * @param array             $extra_join_model_fields_n_values
71
+	 * @return \EE_Base_Class
72
+	 * @throws \EE_Error
73
+	 */
74
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
+	{
76
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
78
+
79
+		// handle possible revisions
80
+		$other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj);
81
+
82
+		// if is array, then we've already done the add_relation so let's get out
83
+		if (is_array($other_model_obj)) {
84
+			return $other_model_obj[0];
85
+		}
86
+		// find the field on the other model which is a foreign key to this model
87
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
88
+		// set that field on the other model to this model's ID
89
+		$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
90
+		$other_model_obj->save();
91
+		return $other_model_obj;
92
+	}
93
+
94
+
95
+	/**
96
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object
97
+	 *
98
+	 * @param EE_Base_Class|int $this_obj_or_id
99
+	 * @param EE_Base_Class|int $other_obj_or_id
100
+	 * @param array             $where_query
101
+	 * @return \EE_Base_Class
102
+	 * @throws \EE_Error
103
+	 */
104
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
105
+	{
106
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id);
107
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
108
+		// handle possible revisions
109
+		$other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true);
110
+
111
+
112
+		// if is array, then we've already done the add_relation so let's get out
113
+		if (is_array($other_model_obj)) {
114
+			return $other_model_obj[0];
115
+		}
116
+
117
+		// find the field on the other model which is a foreign key to this model
118
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
119
+
120
+
121
+		// set that field on the other model to this model's ID
122
+		if ($this->_blocking_delete) {
123
+			$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
124
+			$other_model_obj->save();
125
+		} else {
126
+			$other_model_obj->delete();
127
+			$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
128
+			return $other_model_obj;
129
+		}
130
+		return $other_model_obj;
131
+	}
132
+
133
+
134
+	/**
135
+	 * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions
136
+	 * in here.
137
+	 *
138
+	 * @param  EE_Base_Class|int $model_object_or_id
139
+	 * @param  array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
140
+	 * @param  boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
141
+	 * @return EE_Base_Class[]
142
+	 * @throws \EE_Error
143
+	 */
144
+	public function get_all_related(
145
+		$model_object_or_id,
146
+		$query_params = array(),
147
+		$values_already_prepared_by_model_object = false
148
+	) {
149
+		if ($values_already_prepared_by_model_object !== false) {
150
+			EE_Error::doing_it_wrong(
151
+				'EE_Model_Relation_Base::get_all_related',
152
+				__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
153
+				'4.8.1'
154
+			);
155
+		}
156
+
157
+		// if this is an autosave then we're going to get things differently
158
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
159
+			return $this->_do_autosave_get_all($model_object_or_id, $query_params);
160
+		}
161
+
162
+		return parent::get_all_related($model_object_or_id, $query_params);
163
+	}
164
+
165
+
166
+	/**
167
+	 * If we're in the midst of an autosave then we're going to do things a bit differently than the usual
168
+	 * get_all_related (commenting within).  For description of params see the get_all_related() comments
169
+	 *
170
+	 * @access protected
171
+	 * @param      $model_object_or_id
172
+	 * @param      $query_params
173
+	 * @param bool $deprecated
174
+	 * @return \EE_Base_Class[]
175
+	 * @throws \EE_Error
176
+	 */
177
+	protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false)
178
+	{
179
+
180
+		// first we check if the post_id for the incoming query is for an autosave.  If it isn't that's what we want!
181
+		$model_object_id = $this->_get_model_object_id($model_object_or_id);
182
+
183
+		$autosave  = wp_get_post_autosave($model_object_id);
184
+		$id_to_use = $autosave ? $autosave->ID : $model_object_id;
185
+
186
+		$autosave_relations = parent::get_all_related($id_to_use, $query_params);
187
+		$parent_ids         = $parents = array();
188
+		$return_objs        = array();
189
+
190
+		// k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191
+		foreach ($autosave_relations as $a_r) {
192
+			$pid = $a_r->parent();
193
+			if (! empty($pid)) {
194
+				$parent_ids[] = $pid;
195
+			} else {
196
+				$return_objs[] = $a_r;
197
+			}
198
+		}
199
+
200
+		// we have to make sure we also include the ORIGINAL values
201
+		$originals = parent::get_all_related($model_object_or_id, $query_params);
202
+
203
+		// merge $originals with $return_objs
204
+		if ($originals) {
205
+			$return_objs = array_merge($originals, $return_objs);
206
+		}
207
+
208
+		// now we setup the query to get all the parents
209
+		if (! empty($parent_ids)) {
210
+			$query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
+			$query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
212
+			$parents                                          = $this->get_other_model()->get_all($query_params);
213
+		}
214
+
215
+		// var_dump($parents);
216
+
217
+
218
+		// now merge parents with our current $return_objs and send back
219
+		return array_merge($parents, $return_objs);
220
+	}
221
+
222
+
223
+	/**
224
+	 * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it
225
+	 * is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS
226
+	 * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is
227
+	 * sometime delayed if the object is created/saved first by the autosave)
228
+	 *
229
+	 * @param  EE_Base_Class $this_obj
230
+	 * @param  EE_Base_Class $other_obj
231
+	 * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
232
+	 * @return EE_Base_Class. ($other_obj);
233
+	 * @throws \EE_Error
234
+	 */
235
+	protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false)
236
+	{
237
+		$pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
238
+		// now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
239
+		if ($this_obj->post_type() === 'revision') {
240
+			// first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
241
+			$parent_evt_id = $this_obj->parent();
242
+			/*var_dump($parent_evt_id);
243 243
             var_dump($this_obj);
244 244
             var_dump($other_obj);/**/
245 245
 
246
-            if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247
-                // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248
-                $has_parent_obj = $this->get_other_model()->get_one(array(
249
-                    array(
250
-                        $this->_parent_pk_relation_field => $other_obj->ID(),
251
-                        $this->_primary_cpt_field        => $this_obj->ID(),
252
-                    ),
253
-                ));
254
-
255
-                if ($has_parent_obj) {
256
-                    // this makes sure the update on the current obj happens to the revision's row NOT the parent row.
257
-
258
-                    $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
259
-                    $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261
-
262
-                    if (! $remove_relation) {
263
-                        $other_obj->save();
264
-                        return array($other_obj);
265
-                    } elseif ($remove_relation && ! $this->_blocking_delete) {
266
-                        $other_obj->delete();
267
-                        $other_obj->set($this->_parent_pk_relation_field, null, true);
268
-                        return array($other_obj);
269
-                    }
270
-                } else {
271
-                    $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
272
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
273
-                    $other_obj->set(
274
-                        $pk_on_related_model,
275
-                        null,
276
-                        true
277
-                    ); // ensure we create a new row for the autosave with parent id the same as the incoming ID.
278
-                    $other_obj->save(); // make sure we insert.
279
-                    return array($other_obj);
280
-                }
281
-            }
282
-
283
-            // var_dump('what makes it here');
284
-            // var_dump($other_obj);
285
-            // the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
286
-
287
-            // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288
-        } else {
289
-            // we only need to do the below IF this is not a remove relation
290
-            if (! $remove_relation) {
291
-                // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292
-                // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293
-                $existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
294
-                $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null;
295
-
296
-                if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
297
-                    // yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
298
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
299
-                    $other_obj->save();
300
-
301
-                    // now create a new other_obj and fill with details from existing object
302
-                    $new_obj = $other_obj;
303
-                    $new_obj->set($this->_primary_cpt_field, $potential_revision_id);
304
-                    $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
305
-                    $new_obj->set($pk_on_related_model, null);
306
-                    $new_obj->save();
307
-                    return array($new_obj);
308
-                }
309
-            }
310
-        }
311
-
312
-        return $other_obj;
313
-    }
246
+			if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247
+				// let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248
+				$has_parent_obj = $this->get_other_model()->get_one(array(
249
+					array(
250
+						$this->_parent_pk_relation_field => $other_obj->ID(),
251
+						$this->_primary_cpt_field        => $this_obj->ID(),
252
+					),
253
+				));
254
+
255
+				if ($has_parent_obj) {
256
+					// this makes sure the update on the current obj happens to the revision's row NOT the parent row.
257
+
258
+					$other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
259
+					$other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261
+
262
+					if (! $remove_relation) {
263
+						$other_obj->save();
264
+						return array($other_obj);
265
+					} elseif ($remove_relation && ! $this->_blocking_delete) {
266
+						$other_obj->delete();
267
+						$other_obj->set($this->_parent_pk_relation_field, null, true);
268
+						return array($other_obj);
269
+					}
270
+				} else {
271
+					$other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
272
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
273
+					$other_obj->set(
274
+						$pk_on_related_model,
275
+						null,
276
+						true
277
+					); // ensure we create a new row for the autosave with parent id the same as the incoming ID.
278
+					$other_obj->save(); // make sure we insert.
279
+					return array($other_obj);
280
+				}
281
+			}
282
+
283
+			// var_dump('what makes it here');
284
+			// var_dump($other_obj);
285
+			// the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
286
+
287
+			// the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288
+		} else {
289
+			// we only need to do the below IF this is not a remove relation
290
+			if (! $remove_relation) {
291
+				// okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292
+				// the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293
+				$existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
294
+				$potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null;
295
+
296
+				if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
297
+					// yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
298
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
299
+					$other_obj->save();
300
+
301
+					// now create a new other_obj and fill with details from existing object
302
+					$new_obj = $other_obj;
303
+					$new_obj->set($this->_primary_cpt_field, $potential_revision_id);
304
+					$new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
305
+					$new_obj->set($pk_on_related_model, null);
306
+					$new_obj->save();
307
+					return array($new_obj);
308
+				}
309
+			}
310
+		}
311
+
312
+		return $other_obj;
313
+	}
314 314
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Any_Relation.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -15,94 +15,94 @@
 block discarded – undo
15 15
 class EE_Has_Many_Any_Relation extends EE_Has_Many_Relation
16 16
 {
17 17
 
18
-    /**
19
-     * Gets the SQL string for performing the join between this model and the other model.
20
-     *
21
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
22
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
23
-     *                other_model_primary_table.fk" etc
24
-     * @throws \EE_Error
25
-     */
26
-    public function get_join_statement($model_relation_chain)
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  = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
32
-        $pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33
-            $model_relation_chain,
34
-            $this->get_this_model()->get_this_model_name()
35
-        ) . $this_table_pk_field->get_table_alias();
36
-        $fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37
-            $model_relation_chain,
38
-            $this->get_other_model()->get_this_model_name()
39
-        ) . $other_table_fk_field->get_table_alias();
40
-        $fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41
-        $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
18
+	/**
19
+	 * Gets the SQL string for performing the join between this model and the other model.
20
+	 *
21
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
22
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
23
+	 *                other_model_primary_table.fk" etc
24
+	 * @throws \EE_Error
25
+	 */
26
+	public function get_join_statement($model_relation_chain)
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  = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
32
+		$pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33
+			$model_relation_chain,
34
+			$this->get_this_model()->get_this_model_name()
35
+		) . $this_table_pk_field->get_table_alias();
36
+		$fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37
+			$model_relation_chain,
38
+			$this->get_other_model()->get_this_model_name()
39
+		) . $other_table_fk_field->get_table_alias();
40
+		$fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41
+		$field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
42 42
 
43
-        return $this->_left_join(
44
-            $fk_table,
45
-            $fk_table_alias,
46
-            $other_table_fk_field->get_table_column(),
47
-            $pk_table_alias,
48
-            $this_table_pk_field->get_table_column(),
49
-            $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
50
-        )
51
-               . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52
-    }
43
+		return $this->_left_join(
44
+			$fk_table,
45
+			$fk_table_alias,
46
+			$other_table_fk_field->get_table_column(),
47
+			$pk_table_alias,
48
+			$this_table_pk_field->get_table_column(),
49
+			$fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
50
+		)
51
+			   . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
57
-     * you like.
58
-     *
59
-     * @param EE_Base_Class|int $this_obj_or_id
60
-     * @param EE_Base_Class|int $other_obj_or_id
61
-     * @param array             $extra_join_model_fields_n_values
62
-     * @return \EE_Base_Class
63
-     * @throws \EE_Error
64
-     */
65
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
66
-    {
67
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
68
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
55
+	/**
56
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
57
+	 * you like.
58
+	 *
59
+	 * @param EE_Base_Class|int $this_obj_or_id
60
+	 * @param EE_Base_Class|int $other_obj_or_id
61
+	 * @param array             $extra_join_model_fields_n_values
62
+	 * @return \EE_Base_Class
63
+	 * @throws \EE_Error
64
+	 */
65
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
66
+	{
67
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
68
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
69 69
 
70
-        // find the field on the other model which is a foreign key to this model
71
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
72
-        // set that field on the other model to this model's ID
73
-        $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
74
-        $other_model_obj->set(
75
-            $this->get_other_model()->get_field_containing_related_model_name()->get_name(),
76
-            $this->get_this_model()->get_this_model_name()
77
-        );
78
-        $other_model_obj->save();
79
-        return $other_model_obj;
80
-    }
70
+		// find the field on the other model which is a foreign key to this model
71
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
72
+		// set that field on the other model to this model's ID
73
+		$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
74
+		$other_model_obj->set(
75
+			$this->get_other_model()->get_field_containing_related_model_name()->get_name(),
76
+			$this->get_this_model()->get_this_model_name()
77
+		);
78
+		$other_model_obj->save();
79
+		return $other_model_obj;
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
85
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
86
-     *
87
-     * @param EE_Base_Class|int $this_obj_or_id
88
-     * @param EE_Base_Class|int $other_obj_or_id
89
-     * @param array             $where_query
90
-     * @return \EE_Base_Class
91
-     * @throws \EE_Error
92
-     */
93
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
-    {
95
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
96
-        // find the field on the other model which is a foreign key to this model
97
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
98
-        // set that field on the other model to this model's ID
99
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
100
-        $other_model_obj->set(
101
-            $this->get_other_model()->get_field_containing_related_model_name()->get_name(),
102
-            null,
103
-            true
104
-        );
105
-        $other_model_obj->save();
106
-        return $other_model_obj;
107
-    }
83
+	/**
84
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
85
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
86
+	 *
87
+	 * @param EE_Base_Class|int $this_obj_or_id
88
+	 * @param EE_Base_Class|int $other_obj_or_id
89
+	 * @param array             $where_query
90
+	 * @return \EE_Base_Class
91
+	 * @throws \EE_Error
92
+	 */
93
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
+	{
95
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
96
+		// find the field on the other model which is a foreign key to this model
97
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
98
+		// set that field on the other model to this model's ID
99
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
100
+		$other_model_obj->set(
101
+			$this->get_other_model()->get_field_containing_related_model_name()->get_name(),
102
+			null,
103
+			true
104
+		);
105
+		$other_model_obj->save();
106
+		return $other_model_obj;
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
         $pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33 33
             $model_relation_chain,
34 34
             $this->get_this_model()->get_this_model_name()
35
-        ) . $this_table_pk_field->get_table_alias();
36
-        $fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
35
+        ).$this_table_pk_field->get_table_alias();
36
+        $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37 37
             $model_relation_chain,
38 38
             $this->get_other_model()->get_this_model_name()
39
-        ) . $other_table_fk_field->get_table_alias();
39
+        ).$other_table_fk_field->get_table_alias();
40 40
         $fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41 41
         $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
42 42
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             $other_table_fk_field->get_table_column(),
47 47
             $pk_table_alias,
48 48
             $this_table_pk_field->get_table_column(),
49
-            $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
49
+            $fk_table_alias.'.'.$field_with_model_name->get_table_column()."='".$this->get_this_model()->get_this_model_name()."'"
50 50
         )
51 51
                . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52 52
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Status.model.php 2 patches
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -11,292 +11,292 @@
 block discarded – undo
11 11
 class EEM_Status extends EEM_Base
12 12
 {
13 13
 
14
-    // private instance of the Attendee object
15
-    protected static $_instance = null;
14
+	// private instance of the Attendee object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18
-    /**
19
-     * @return EEM_Status
20
-     */
21
-    protected function __construct($timezone = null)
22
-    {
23
-        $this->singular_item    = __('Status', 'event_espresso');
24
-        $this->plural_item      = __('Stati', 'event_espresso');
25
-        $this->_tables          = array(
26
-            'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
27
-        );
28
-        $this->_fields          = array(
29
-            'StatusTable' => array(
30
-                'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
31
-                'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
32
-                'STS_type'     => new EE_Enum_Text_Field(
33
-                    'STS_type',
34
-                    __("Type", "event_espresso"),
35
-                    false,
36
-                    'event',
37
-                    array(
38
-                        'event'        => __("Event", "event_espresso"),// deprecated
39
-                        'registration' => __("Registration", "event_espresso"),
40
-                        'transaction'  => __("Transaction", "event_espresso"),
41
-                        'payment'      => __("Payment", "event_espresso"),
42
-                        'email'        => __("Email", "event_espresso"),
43
-                        'message'      => __("Message", "event_espresso"),
44
-                    )
45
-                ),
46
-                'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false, false),
47
-                'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
48
-                'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
49
-            ),
50
-        );
51
-        $this->_model_relations = array(
52
-            'Registration' => new EE_Has_Many_Relation(),
53
-            'Transaction'  => new EE_Has_Many_Relation(),
54
-            'Payment'      => new EE_Has_Many_Relation(),
55
-        );
56
-        // this model is generally available for reading
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
18
+	/**
19
+	 * @return EEM_Status
20
+	 */
21
+	protected function __construct($timezone = null)
22
+	{
23
+		$this->singular_item    = __('Status', 'event_espresso');
24
+		$this->plural_item      = __('Stati', 'event_espresso');
25
+		$this->_tables          = array(
26
+			'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
27
+		);
28
+		$this->_fields          = array(
29
+			'StatusTable' => array(
30
+				'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
31
+				'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
32
+				'STS_type'     => new EE_Enum_Text_Field(
33
+					'STS_type',
34
+					__("Type", "event_espresso"),
35
+					false,
36
+					'event',
37
+					array(
38
+						'event'        => __("Event", "event_espresso"),// deprecated
39
+						'registration' => __("Registration", "event_espresso"),
40
+						'transaction'  => __("Transaction", "event_espresso"),
41
+						'payment'      => __("Payment", "event_espresso"),
42
+						'email'        => __("Email", "event_espresso"),
43
+						'message'      => __("Message", "event_espresso"),
44
+					)
45
+				),
46
+				'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false, false),
47
+				'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
48
+				'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
49
+			),
50
+		);
51
+		$this->_model_relations = array(
52
+			'Registration' => new EE_Has_Many_Relation(),
53
+			'Transaction'  => new EE_Has_Many_Relation(),
54
+			'Payment'      => new EE_Has_Many_Relation(),
55
+		);
56
+		// this model is generally available for reading
57
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
58 58
 
59
-        parent::__construct($timezone);
60
-    }
59
+		parent::__construct($timezone);
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * This method provides the localized singular or plural string for a given status id
65
-     *
66
-     * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
67
-     *                           That way if there isn't a translation in the index we'll return the default code.
68
-     * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
69
-     *                           same as the singular (in English), however, this may NOT be the case with other
70
-     *                           languages
71
-     * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
72
-     *                           the status string returned ( UPPER, lower, Sentence)
73
-     * @throws EE_Error
74
-     * @return array             an array of translated strings for the incoming status id.
75
-     */
76
-    public function localized_status($statuses, $plural = false, $schema = 'upper')
77
-    {
78
-        // note these are all in lower case because ucwords() on upper case will NOT convert.
79
-        $translation_array = array(
80
-            EEM_Registration::status_id_pending_payment => array(
81
-                __('pending payment', 'event_espresso'), // singular
82
-                __('pending payments', 'event_espresso') // plural
83
-            ),
84
-            EEM_Registration::status_id_approved        => array(
85
-                __('approved', 'event_espresso'), // singular
86
-                __('approved', 'event_espresso') // plural
87
-            ),
88
-            EEM_Registration::status_id_not_approved    => array(
89
-                __('not approved', 'event_espresso'),
90
-                __('not approved', 'event_espresso'),
91
-            ),
92
-            EEM_Registration::status_id_cancelled       => array(
93
-                __('cancelled', 'event_espresso'),
94
-                __('cancelled', 'event_espresso'),
95
-            ),
96
-            EEM_Registration::status_id_incomplete      => array(
97
-                __('incomplete', 'event_espresso'),
98
-                __('incomplete', 'event_espresso'),
99
-            ),
100
-            EEM_Registration::status_id_declined        => array(
101
-                __('declined', 'event_espresso'),
102
-                __('declined', 'event_espresso'),
103
-            ),
104
-            EEM_Registration::status_id_wait_list       => array(
105
-                __('wait list', 'event_espresso'),
106
-                __('wait list', 'event_espresso'),
107
-            ),
108
-            EEM_Transaction::overpaid_status_code       => array(
109
-                __('overpaid', 'event_espresso'),
110
-                __('overpaid', 'event_espresso'),
111
-            ),
112
-            EEM_Transaction::complete_status_code       => array(
113
-                __('complete', 'event_espresso'),
114
-                __('complete', 'event_espresso'),
115
-            ),
116
-            EEM_Transaction::incomplete_status_code     => array(
117
-                __('incomplete', 'event_espresso'),
118
-                __('incomplete', 'event_espresso'),
119
-            ),
120
-            EEM_Transaction::failed_status_code         => array(
121
-                __('failed', 'event_espresso'),
122
-                __('failed', 'event_espresso'),
123
-            ),
124
-            EEM_Transaction::abandoned_status_code      => array(
125
-                __('abandoned', 'event_espresso'),
126
-                __('abandoned', 'event_espresso'),
127
-            ),
128
-            EEM_Payment::status_id_approved             => array(
129
-                __('accepted', 'event_espresso'),
130
-                __('accepted', 'event_espresso'),
131
-            ),
132
-            EEM_Payment::status_id_pending              => array(
133
-                __('pending', 'event_espresso'),
134
-                __('pending', 'event_espresso'),
135
-            ),
136
-            EEM_Payment::status_id_cancelled            => array(
137
-                __('cancelled', 'event_espresso'),
138
-                __('cancelled', 'event_espresso'),
139
-            ),
140
-            EEM_Payment::status_id_declined             => array(
141
-                __('declined', 'event_espresso'),
142
-                __('declined', 'event_espresso'),
143
-            ),
144
-            EEM_Payment::status_id_failed               => array(
145
-                __('failed', 'event_espresso'),
146
-                __('failed', 'event_espresso'),
147
-            ),
148
-            // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
149
-            EEM_Event::sold_out                         => array(
150
-                __('sold out', 'event_espresso'),
151
-                __('sold out', 'event_espresso'),
152
-            ),
153
-            EEM_Event::postponed                        => array(
154
-                __('postponed', 'event_espresso'),
155
-                __('Postponed', 'event_espresso'),
156
-            ),
157
-            EEM_Event::cancelled                        => array(
158
-                __('cancelled', 'event_espresso'),
159
-                __('cancelled', 'event_espresso'),
160
-            ),
161
-            EE_Ticket::archived                         => array(
162
-                __('archived', 'event_espresso'),
163
-                __('archived', 'event_espresso'),
164
-            ),
165
-            EE_Ticket::expired                          => array(
166
-                __('expired', 'event_espresso'),
167
-                __('expired', 'event_espresso'),
168
-            ),
169
-            EE_Ticket::sold_out                         => array(
170
-                __('sold out', 'event_espresso'),
171
-                __('sold out', 'event_espresso'),
172
-            ),
173
-            EE_Ticket::pending                          => array(
174
-                __('upcoming', 'event_espresso'),
175
-                __('upcoming', 'event_espresso'),
176
-            ),
177
-            EE_Ticket::onsale                           => array(
178
-                __('on sale', 'event_espresso'),
179
-                __('on sale', 'event_espresso'),
180
-            ),
181
-            EE_Datetime::cancelled                      => array(
182
-                __('cancelled', 'event_espresso'),
183
-                __('cancelled', 'event_espresso'),
184
-            ),
185
-            EE_Datetime::sold_out                       => array(
186
-                __('sold out', 'event_espresso'),
187
-                __('sold out', 'event_espresso'),
188
-            ),
189
-            EE_Datetime::expired                        => array(
190
-                __('expired', 'event_espresso'),
191
-                __('expired', 'event_espresso'),
192
-            ),
193
-            EE_Datetime::inactive                       => array(
194
-                __('inactive', 'event_espresso'),
195
-                __('inactive', 'event_espresso'),
196
-            ),
197
-            EE_Datetime::upcoming                       => array(
198
-                __('upcoming', 'event_espresso'),
199
-                __('upcoming', 'event_espresso'),
200
-            ),
201
-            EE_Datetime::active                         => array(
202
-                __('active', 'event_espresso'),
203
-                __('active', 'event_espresso'),
204
-            ),
205
-            EE_Datetime::postponed                      => array(
206
-                __('postponed', 'event_espresso'),
207
-                __('postponed', 'event_espresso'),
208
-            ),
209
-            // messages related
210
-            EEM_Message::status_sent                    => array(
211
-                __('sent', 'event_espresso'),
212
-                __('sent', 'event_espresso'),
213
-            ),
214
-            EEM_Message::status_idle                    => array(
215
-                __('queued for sending', 'event_espresso'),
216
-                __('queued for sending', 'event_espresso'),
217
-            ),
218
-            EEM_Message::status_failed                  => array(
219
-                __('failed', 'event_espresso'),
220
-                __('failed', 'event_espresso'),
221
-            ),
222
-            EEM_Message::status_debug_only              => array(
223
-                __('debug only', 'event_espresso'),
224
-                __('debug only', 'event_espresso'),
225
-            ),
226
-            EEM_Message::status_messenger_executing     => array(
227
-                __('messenger is executing', 'event_espresso'),
228
-                __('messenger is executing', 'event_espresso'),
229
-            ),
230
-            EEM_Message::status_resend                  => array(
231
-                __('queued for resending', 'event_espresso'),
232
-                __('queued for resending', 'event_espresso'),
233
-            ),
234
-            EEM_Message::status_incomplete              => array(
235
-                __('queued for generating', 'event_espresso'),
236
-                __('queued for generating', 'event_espresso'),
237
-            ),
238
-            EEM_Message::status_retry                   => array(
239
-                __('failed sending, can be retried', 'event_espresso'),
240
-                __('failed sending, can be retried', 'event_espresso'),
241
-            ),
242
-            EEM_CPT_Base::post_status_publish           => array(
243
-                __('published', 'event_espresso'),
244
-                __('published', 'event_espresso'),
245
-            ),
246
-            EEM_CPT_Base::post_status_future            => array(
247
-                __('scheduled', 'event_espresso'),
248
-                __('scheduled', 'event_espresso'),
249
-            ),
250
-            EEM_CPT_Base::post_status_draft             => array(
251
-                __('draft', 'event_espresso'),
252
-                __('draft', 'event_espresso'),
253
-            ),
254
-            EEM_CPT_Base::post_status_pending           => array(
255
-                __('pending', 'event_espresso'),
256
-                __('pending', 'event_espresso'),
257
-            ),
258
-            EEM_CPT_Base::post_status_private           => array(
259
-                __('private', 'event_espresso'),
260
-                __('private', 'event_espresso'),
261
-            ),
262
-            EEM_CPT_Base::post_status_trashed           => array(
263
-                __('trashed', 'event_espresso'),
264
-                __('trashed', 'event_espresso'),
265
-            ),
266
-        );
63
+	/**
64
+	 * This method provides the localized singular or plural string for a given status id
65
+	 *
66
+	 * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
67
+	 *                           That way if there isn't a translation in the index we'll return the default code.
68
+	 * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
69
+	 *                           same as the singular (in English), however, this may NOT be the case with other
70
+	 *                           languages
71
+	 * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
72
+	 *                           the status string returned ( UPPER, lower, Sentence)
73
+	 * @throws EE_Error
74
+	 * @return array             an array of translated strings for the incoming status id.
75
+	 */
76
+	public function localized_status($statuses, $plural = false, $schema = 'upper')
77
+	{
78
+		// note these are all in lower case because ucwords() on upper case will NOT convert.
79
+		$translation_array = array(
80
+			EEM_Registration::status_id_pending_payment => array(
81
+				__('pending payment', 'event_espresso'), // singular
82
+				__('pending payments', 'event_espresso') // plural
83
+			),
84
+			EEM_Registration::status_id_approved        => array(
85
+				__('approved', 'event_espresso'), // singular
86
+				__('approved', 'event_espresso') // plural
87
+			),
88
+			EEM_Registration::status_id_not_approved    => array(
89
+				__('not approved', 'event_espresso'),
90
+				__('not approved', 'event_espresso'),
91
+			),
92
+			EEM_Registration::status_id_cancelled       => array(
93
+				__('cancelled', 'event_espresso'),
94
+				__('cancelled', 'event_espresso'),
95
+			),
96
+			EEM_Registration::status_id_incomplete      => array(
97
+				__('incomplete', 'event_espresso'),
98
+				__('incomplete', 'event_espresso'),
99
+			),
100
+			EEM_Registration::status_id_declined        => array(
101
+				__('declined', 'event_espresso'),
102
+				__('declined', 'event_espresso'),
103
+			),
104
+			EEM_Registration::status_id_wait_list       => array(
105
+				__('wait list', 'event_espresso'),
106
+				__('wait list', 'event_espresso'),
107
+			),
108
+			EEM_Transaction::overpaid_status_code       => array(
109
+				__('overpaid', 'event_espresso'),
110
+				__('overpaid', 'event_espresso'),
111
+			),
112
+			EEM_Transaction::complete_status_code       => array(
113
+				__('complete', 'event_espresso'),
114
+				__('complete', 'event_espresso'),
115
+			),
116
+			EEM_Transaction::incomplete_status_code     => array(
117
+				__('incomplete', 'event_espresso'),
118
+				__('incomplete', 'event_espresso'),
119
+			),
120
+			EEM_Transaction::failed_status_code         => array(
121
+				__('failed', 'event_espresso'),
122
+				__('failed', 'event_espresso'),
123
+			),
124
+			EEM_Transaction::abandoned_status_code      => array(
125
+				__('abandoned', 'event_espresso'),
126
+				__('abandoned', 'event_espresso'),
127
+			),
128
+			EEM_Payment::status_id_approved             => array(
129
+				__('accepted', 'event_espresso'),
130
+				__('accepted', 'event_espresso'),
131
+			),
132
+			EEM_Payment::status_id_pending              => array(
133
+				__('pending', 'event_espresso'),
134
+				__('pending', 'event_espresso'),
135
+			),
136
+			EEM_Payment::status_id_cancelled            => array(
137
+				__('cancelled', 'event_espresso'),
138
+				__('cancelled', 'event_espresso'),
139
+			),
140
+			EEM_Payment::status_id_declined             => array(
141
+				__('declined', 'event_espresso'),
142
+				__('declined', 'event_espresso'),
143
+			),
144
+			EEM_Payment::status_id_failed               => array(
145
+				__('failed', 'event_espresso'),
146
+				__('failed', 'event_espresso'),
147
+			),
148
+			// following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
149
+			EEM_Event::sold_out                         => array(
150
+				__('sold out', 'event_espresso'),
151
+				__('sold out', 'event_espresso'),
152
+			),
153
+			EEM_Event::postponed                        => array(
154
+				__('postponed', 'event_espresso'),
155
+				__('Postponed', 'event_espresso'),
156
+			),
157
+			EEM_Event::cancelled                        => array(
158
+				__('cancelled', 'event_espresso'),
159
+				__('cancelled', 'event_espresso'),
160
+			),
161
+			EE_Ticket::archived                         => array(
162
+				__('archived', 'event_espresso'),
163
+				__('archived', 'event_espresso'),
164
+			),
165
+			EE_Ticket::expired                          => array(
166
+				__('expired', 'event_espresso'),
167
+				__('expired', 'event_espresso'),
168
+			),
169
+			EE_Ticket::sold_out                         => array(
170
+				__('sold out', 'event_espresso'),
171
+				__('sold out', 'event_espresso'),
172
+			),
173
+			EE_Ticket::pending                          => array(
174
+				__('upcoming', 'event_espresso'),
175
+				__('upcoming', 'event_espresso'),
176
+			),
177
+			EE_Ticket::onsale                           => array(
178
+				__('on sale', 'event_espresso'),
179
+				__('on sale', 'event_espresso'),
180
+			),
181
+			EE_Datetime::cancelled                      => array(
182
+				__('cancelled', 'event_espresso'),
183
+				__('cancelled', 'event_espresso'),
184
+			),
185
+			EE_Datetime::sold_out                       => array(
186
+				__('sold out', 'event_espresso'),
187
+				__('sold out', 'event_espresso'),
188
+			),
189
+			EE_Datetime::expired                        => array(
190
+				__('expired', 'event_espresso'),
191
+				__('expired', 'event_espresso'),
192
+			),
193
+			EE_Datetime::inactive                       => array(
194
+				__('inactive', 'event_espresso'),
195
+				__('inactive', 'event_espresso'),
196
+			),
197
+			EE_Datetime::upcoming                       => array(
198
+				__('upcoming', 'event_espresso'),
199
+				__('upcoming', 'event_espresso'),
200
+			),
201
+			EE_Datetime::active                         => array(
202
+				__('active', 'event_espresso'),
203
+				__('active', 'event_espresso'),
204
+			),
205
+			EE_Datetime::postponed                      => array(
206
+				__('postponed', 'event_espresso'),
207
+				__('postponed', 'event_espresso'),
208
+			),
209
+			// messages related
210
+			EEM_Message::status_sent                    => array(
211
+				__('sent', 'event_espresso'),
212
+				__('sent', 'event_espresso'),
213
+			),
214
+			EEM_Message::status_idle                    => array(
215
+				__('queued for sending', 'event_espresso'),
216
+				__('queued for sending', 'event_espresso'),
217
+			),
218
+			EEM_Message::status_failed                  => array(
219
+				__('failed', 'event_espresso'),
220
+				__('failed', 'event_espresso'),
221
+			),
222
+			EEM_Message::status_debug_only              => array(
223
+				__('debug only', 'event_espresso'),
224
+				__('debug only', 'event_espresso'),
225
+			),
226
+			EEM_Message::status_messenger_executing     => array(
227
+				__('messenger is executing', 'event_espresso'),
228
+				__('messenger is executing', 'event_espresso'),
229
+			),
230
+			EEM_Message::status_resend                  => array(
231
+				__('queued for resending', 'event_espresso'),
232
+				__('queued for resending', 'event_espresso'),
233
+			),
234
+			EEM_Message::status_incomplete              => array(
235
+				__('queued for generating', 'event_espresso'),
236
+				__('queued for generating', 'event_espresso'),
237
+			),
238
+			EEM_Message::status_retry                   => array(
239
+				__('failed sending, can be retried', 'event_espresso'),
240
+				__('failed sending, can be retried', 'event_espresso'),
241
+			),
242
+			EEM_CPT_Base::post_status_publish           => array(
243
+				__('published', 'event_espresso'),
244
+				__('published', 'event_espresso'),
245
+			),
246
+			EEM_CPT_Base::post_status_future            => array(
247
+				__('scheduled', 'event_espresso'),
248
+				__('scheduled', 'event_espresso'),
249
+			),
250
+			EEM_CPT_Base::post_status_draft             => array(
251
+				__('draft', 'event_espresso'),
252
+				__('draft', 'event_espresso'),
253
+			),
254
+			EEM_CPT_Base::post_status_pending           => array(
255
+				__('pending', 'event_espresso'),
256
+				__('pending', 'event_espresso'),
257
+			),
258
+			EEM_CPT_Base::post_status_private           => array(
259
+				__('private', 'event_espresso'),
260
+				__('private', 'event_espresso'),
261
+			),
262
+			EEM_CPT_Base::post_status_trashed           => array(
263
+				__('trashed', 'event_espresso'),
264
+				__('trashed', 'event_espresso'),
265
+			),
266
+		);
267 267
 
268
-        $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
268
+		$translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
269 269
 
270
-        if (! is_array($statuses)) {
271
-            throw new EE_Error(__(
272
-                'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273
-                'event_espresso'
274
-            ));
275
-        }
270
+		if (! is_array($statuses)) {
271
+			throw new EE_Error(__(
272
+				'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273
+				'event_espresso'
274
+			));
275
+		}
276 276
 
277
-        $translation = array();
277
+		$translation = array();
278 278
 
279
-        foreach ($statuses as $id => $code) {
280
-            if (isset($translation_array[ $id ])) {
281
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
282
-            } else {
283
-                $translation[ $id ] = $code;
284
-            }
279
+		foreach ($statuses as $id => $code) {
280
+			if (isset($translation_array[ $id ])) {
281
+				$translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
282
+			} else {
283
+				$translation[ $id ] = $code;
284
+			}
285 285
 
286
-            // schema
287
-            switch ($schema) {
288
-                case 'lower':
289
-                    $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
290
-                    break;
291
-                case 'sentence':
292
-                    $translation[ $id ] = ucwords($translation[ $id ]);
293
-                    break;
294
-                case 'upper':
295
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
296
-                    break;
297
-            }
298
-        }
286
+			// schema
287
+			switch ($schema) {
288
+				case 'lower':
289
+					$translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
290
+					break;
291
+				case 'sentence':
292
+					$translation[ $id ] = ucwords($translation[ $id ]);
293
+					break;
294
+				case 'upper':
295
+					$translation[ $id ] = strtoupper($translation[ $id ]);
296
+					break;
297
+			}
298
+		}
299 299
 
300
-        return $translation;
301
-    }
300
+		return $translation;
301
+	}
302 302
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
                     false,
36 36
                     'event',
37 37
                     array(
38
-                        'event'        => __("Event", "event_espresso"),// deprecated
38
+                        'event'        => __("Event", "event_espresso"), // deprecated
39 39
                         'registration' => __("Registration", "event_espresso"),
40 40
                         'transaction'  => __("Transaction", "event_espresso"),
41 41
                         'payment'      => __("Payment", "event_espresso"),
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             'Payment'      => new EE_Has_Many_Relation(),
55 55
         );
56 56
         // this model is generally available for reading
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
57
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
58 58
 
59 59
         parent::__construct($timezone);
60 60
     }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 
268 268
         $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
269 269
 
270
-        if (! is_array($statuses)) {
270
+        if ( ! is_array($statuses)) {
271 271
             throw new EE_Error(__(
272 272
                 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273 273
                 'event_espresso'
@@ -277,22 +277,22 @@  discard block
 block discarded – undo
277 277
         $translation = array();
278 278
 
279 279
         foreach ($statuses as $id => $code) {
280
-            if (isset($translation_array[ $id ])) {
281
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
280
+            if (isset($translation_array[$id])) {
281
+                $translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0];
282 282
             } else {
283
-                $translation[ $id ] = $code;
283
+                $translation[$id] = $code;
284 284
             }
285 285
 
286 286
             // schema
287 287
             switch ($schema) {
288 288
                 case 'lower':
289
-                    $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
289
+                    $translation[$id] = strtolower($translation[$id]); // even though these start in lower case, this will catch any statuses added via filter.
290 290
                     break;
291 291
                 case 'sentence':
292
-                    $translation[ $id ] = ucwords($translation[ $id ]);
292
+                    $translation[$id] = ucwords($translation[$id]);
293 293
                     break;
294 294
                 case 'upper':
295
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
295
+                    $translation[$id] = strtoupper($translation[$id]);
296 296
                     break;
297 297
             }
298 298
         }
Please login to merge, or discard this patch.
core/db_models/EEM_Ticket_Price.model.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -11,43 +11,43 @@
 block discarded – undo
11 11
 class EEM_Ticket_Price extends EEM_Base
12 12
 {
13 13
 
14
-    // private instance of the EEM_Ticket_Price object
15
-    protected static $_instance = null;
14
+	// private instance of the EEM_Ticket_Price object
15
+	protected static $_instance = null;
16 16
 
17
-    /**
18
-     *      private constructor to prevent direct creation
19
-     *      @Constructor
20
-     *      @access protected
21
-     *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
22
-     *      @return void
23
-     */
24
-    protected function __construct($timezone)
25
-    {
26
-        $this->singular_item = __('Ticket Price', 'event_espresso');
27
-        $this->plural_item = __('Ticket Prices', 'event_espresso');
17
+	/**
18
+	 *      private constructor to prevent direct creation
19
+	 *      @Constructor
20
+	 *      @access protected
21
+	 *      @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved).  Note this just sends the timezone info to the date time model field objects.  Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option)
22
+	 *      @return void
23
+	 */
24
+	protected function __construct($timezone)
25
+	{
26
+		$this->singular_item = __('Ticket Price', 'event_espresso');
27
+		$this->plural_item = __('Ticket Prices', 'event_espresso');
28 28
 
29
-        $this->_tables = array(
30
-            'Ticket_Price'=>new EE_Primary_Table('esp_ticket_price', 'TKP_ID')
31
-        );
32
-        $this->_fields = array(
33
-            'Ticket_Price'=> array(
34
-                'TKP_ID'=>new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'),
35
-                'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'),
36
-                'PRC_ID'=>new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'),
37
-            )
38
-        );
39
-        $this->_model_relations = array(
40
-            'Ticket'=>new EE_Belongs_To_Relation(),
41
-            'Price'=>new EE_Belongs_To_Relation()
42
-        );
43
-        $this->_model_chain_to_wp_user = 'Ticket';
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
45
-        // account for default tickets in the caps
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        // follow the caps of the ticket
50
-        $this->_caps_slug = 'tickets';
51
-        parent::__construct($timezone);
52
-    }
29
+		$this->_tables = array(
30
+			'Ticket_Price'=>new EE_Primary_Table('esp_ticket_price', 'TKP_ID')
31
+		);
32
+		$this->_fields = array(
33
+			'Ticket_Price'=> array(
34
+				'TKP_ID'=>new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'),
35
+				'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'),
36
+				'PRC_ID'=>new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'),
37
+			)
38
+		);
39
+		$this->_model_relations = array(
40
+			'Ticket'=>new EE_Belongs_To_Relation(),
41
+			'Price'=>new EE_Belongs_To_Relation()
42
+		);
43
+		$this->_model_chain_to_wp_user = 'Ticket';
44
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
45
+		// account for default tickets in the caps
46
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+		// follow the caps of the ticket
50
+		$this->_caps_slug = 'tickets';
51
+		parent::__construct($timezone);
52
+	}
53 53
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -41,11 +41,11 @@
 block discarded – undo
41 41
             'Price'=>new EE_Belongs_To_Relation()
42 42
         );
43 43
         $this->_model_chain_to_wp_user = 'Ticket';
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
44
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
45 45
         // account for default tickets in the caps
46
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
+        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
47
+        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
48
+        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49 49
         // follow the caps of the ticket
50 50
         $this->_caps_slug = 'tickets';
51 51
         parent::__construct($timezone);
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Index.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -6,45 +6,45 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Index
8 8
 {
9
-    protected $_name;
10
-    protected $_field_names;
11
-    protected $_model_name;
12
-    public function __construct($fields)
13
-    {
14
-        $this->_field_names = $fields;
15
-    }
16
-    public function _construct_finalize($name, $model_name)
17
-    {
18
-        $this->_name = $name;
19
-        $this->_model_name = $model_name;
20
-    }
21
-    public function field_names()
22
-    {
23
-        return $this->_field_names;
24
-    }
25
-    /**
26
-     * Internally used by get_this_model() and get_other_model()
27
-     * @param string $model_name like Event, Question_Group, etc. omit the EEM_
28
-     * @return EEM_Base
29
-     */
30
-    protected function _get_model($model_name)
31
-    {
32
-        $modelInstance=call_user_func("EEM_".$model_name."::instance");
33
-        return $modelInstance;
34
-    }
35
-    /**
36
-     * Gets all the fields for this index
37
-     * @return EE_Model_Field_Base[]
38
-     */
39
-    public function fields()
40
-    {
41
-        $fields = array();
42
-        $model = $this->_get_model($this->_model_name);
43
-        foreach ($model->field_settings() as $field_name => $field_obj) {
44
-            if (in_array($field_name, $this->field_names())) {
45
-                $fields[ $field_name ] = $field_obj;
46
-            }
47
-        }
48
-        return $fields;
49
-    }
9
+	protected $_name;
10
+	protected $_field_names;
11
+	protected $_model_name;
12
+	public function __construct($fields)
13
+	{
14
+		$this->_field_names = $fields;
15
+	}
16
+	public function _construct_finalize($name, $model_name)
17
+	{
18
+		$this->_name = $name;
19
+		$this->_model_name = $model_name;
20
+	}
21
+	public function field_names()
22
+	{
23
+		return $this->_field_names;
24
+	}
25
+	/**
26
+	 * Internally used by get_this_model() and get_other_model()
27
+	 * @param string $model_name like Event, Question_Group, etc. omit the EEM_
28
+	 * @return EEM_Base
29
+	 */
30
+	protected function _get_model($model_name)
31
+	{
32
+		$modelInstance=call_user_func("EEM_".$model_name."::instance");
33
+		return $modelInstance;
34
+	}
35
+	/**
36
+	 * Gets all the fields for this index
37
+	 * @return EE_Model_Field_Base[]
38
+	 */
39
+	public function fields()
40
+	{
41
+		$fields = array();
42
+		$model = $this->_get_model($this->_model_name);
43
+		foreach ($model->field_settings() as $field_name => $field_obj) {
44
+			if (in_array($field_name, $this->field_names())) {
45
+				$fields[ $field_name ] = $field_obj;
46
+			}
47
+		}
48
+		return $fields;
49
+	}
50 50
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
      */
30 30
     protected function _get_model($model_name)
31 31
     {
32
-        $modelInstance=call_user_func("EEM_".$model_name."::instance");
32
+        $modelInstance = call_user_func("EEM_".$model_name."::instance");
33 33
         return $modelInstance;
34 34
     }
35 35
     /**
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $model = $this->_get_model($this->_model_name);
43 43
         foreach ($model->field_settings() as $field_name => $field_obj) {
44 44
             if (in_array($field_name, $this->field_names())) {
45
-                $fields[ $field_name ] = $field_obj;
45
+                $fields[$field_name] = $field_obj;
46 46
             }
47 47
         }
48 48
         return $fields;
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Table_Base.php 2 patches
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -9,164 +9,164 @@
 block discarded – undo
9 9
 abstract class EE_Table_Base
10 10
 {
11 11
 
12
-    /**
13
-     * This holds the table_name without the table prefix.
14
-     *
15
-     * @var string
16
-     */
17
-    public $_table_name;
18
-
19
-
20
-    /**
21
-     * This holds what is used as the alias for the table in queries.
22
-     *
23
-     * @var string
24
-     */
25
-    public $_table_alias;
26
-
27
-
28
-    /**
29
-     * Table's private key column
30
-     *
31
-     * @var string
32
-     */
33
-    protected $_pk_column;
34
-
35
-
36
-    /**
37
-     * Whether this table is a global table (in multisite) or specific to site.
38
-     *
39
-     * @var bool
40
-     */
41
-    protected $_global;
42
-
43
-
44
-
45
-    /**
46
-     * @global wpdb   $wpdb
47
-     * @param string  $table_name with or without wpdb prefix
48
-     * @param string  $pk_column
49
-     * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
-     *                            install, or whether each site on a multisite install has a copy of this table
51
-     */
52
-    public function __construct($table_name, $pk_column, $global = false)
53
-    {
54
-        $this->_global = $global;
55
-        $prefix = $this->get_table_prefix();
56
-        // if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
-        if (strpos($table_name, $prefix) === 0) {
58
-            $table_name = ltrim($table_name, $prefix);
59
-        }
60
-        $this->_table_name = $table_name;
61
-        $this->_pk_column = $pk_column;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * This returns the table prefix for the current model state.
68
-     *
69
-     * @global wpdb $wpdb
70
-     * @return string
71
-     */
72
-    public function get_table_prefix()
73
-    {
74
-        global $wpdb;
75
-        if ($this->_global) {
76
-            $prefix = $wpdb->base_prefix;
77
-        } else {
78
-            $prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
-        }
80
-        return $prefix;
81
-    }
82
-
83
-
84
-
85
-    /**
86
-     * Used to set the table_alias property
87
-     *
88
-     * @param string $table_alias
89
-     */
90
-    public function _construct_finalize_with_alias($table_alias)
91
-    {
92
-        $this->_table_alias = $table_alias;
93
-    }
94
-
95
-
96
-
97
-    /**
98
-     * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
-     *
100
-     * @return string
101
-     */
102
-    public function get_table_name()
103
-    {
104
-        return $this->get_table_prefix() . $this->_table_name;
105
-    }
106
-
107
-
108
-
109
-    /**
110
-     * Provides what is currently set as the alias for the table to be used in queries.
111
-     *
112
-     * @return string
113
-     * @throws EE_Error
114
-     */
115
-    public function get_table_alias()
116
-    {
117
-        if (! $this->_table_alias) {
118
-            throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
-        }
120
-        return $this->_table_alias;
121
-    }
122
-
123
-
124
-
125
-    /**
126
-     * @return string name of column of PK
127
-     */
128
-    public function get_pk_column()
129
-    {
130
-        return $this->_pk_column;
131
-    }
132
-
133
-
134
-
135
-    /**
136
-     * returns a string with the table alias, a period, and the private key's column.
137
-     *
138
-     * @return string
139
-     */
140
-    public function get_fully_qualified_pk_column()
141
-    {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
-        return $sql;
144
-    }
145
-
146
-
147
-
148
-    /**
149
-     * returns the special sql for a inner select with a limit.
150
-     *
151
-     * @return string    SQL select
152
-     */
153
-    public function get_select_join_limit($limit)
154
-    {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
-        return $SQL;
158
-    }
159
-
160
-
161
-
162
-    /**
163
-     * Returns whether or not htis is a global table (ie, on multisite there's
164
-     * only one of these tables, on the main blog)
165
-     *
166
-     * @return boolean
167
-     */
168
-    public function is_global()
169
-    {
170
-        return $this->_global;
171
-    }
12
+	/**
13
+	 * This holds the table_name without the table prefix.
14
+	 *
15
+	 * @var string
16
+	 */
17
+	public $_table_name;
18
+
19
+
20
+	/**
21
+	 * This holds what is used as the alias for the table in queries.
22
+	 *
23
+	 * @var string
24
+	 */
25
+	public $_table_alias;
26
+
27
+
28
+	/**
29
+	 * Table's private key column
30
+	 *
31
+	 * @var string
32
+	 */
33
+	protected $_pk_column;
34
+
35
+
36
+	/**
37
+	 * Whether this table is a global table (in multisite) or specific to site.
38
+	 *
39
+	 * @var bool
40
+	 */
41
+	protected $_global;
42
+
43
+
44
+
45
+	/**
46
+	 * @global wpdb   $wpdb
47
+	 * @param string  $table_name with or without wpdb prefix
48
+	 * @param string  $pk_column
49
+	 * @param boolean $global     whether the table is "global" as in there is only 1 table on an entire multisite
50
+	 *                            install, or whether each site on a multisite install has a copy of this table
51
+	 */
52
+	public function __construct($table_name, $pk_column, $global = false)
53
+	{
54
+		$this->_global = $global;
55
+		$prefix = $this->get_table_prefix();
56
+		// if they added the prefix, let's remove it because we delay adding the prefix until right when its needed.
57
+		if (strpos($table_name, $prefix) === 0) {
58
+			$table_name = ltrim($table_name, $prefix);
59
+		}
60
+		$this->_table_name = $table_name;
61
+		$this->_pk_column = $pk_column;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * This returns the table prefix for the current model state.
68
+	 *
69
+	 * @global wpdb $wpdb
70
+	 * @return string
71
+	 */
72
+	public function get_table_prefix()
73
+	{
74
+		global $wpdb;
75
+		if ($this->_global) {
76
+			$prefix = $wpdb->base_prefix;
77
+		} else {
78
+			$prefix = $wpdb->get_blog_prefix(EEM_Base::get_model_query_blog_id());
79
+		}
80
+		return $prefix;
81
+	}
82
+
83
+
84
+
85
+	/**
86
+	 * Used to set the table_alias property
87
+	 *
88
+	 * @param string $table_alias
89
+	 */
90
+	public function _construct_finalize_with_alias($table_alias)
91
+	{
92
+		$this->_table_alias = $table_alias;
93
+	}
94
+
95
+
96
+
97
+	/**
98
+	 * Returns the fully qualified table name for the database (includes the table prefix current for the blog).
99
+	 *
100
+	 * @return string
101
+	 */
102
+	public function get_table_name()
103
+	{
104
+		return $this->get_table_prefix() . $this->_table_name;
105
+	}
106
+
107
+
108
+
109
+	/**
110
+	 * Provides what is currently set as the alias for the table to be used in queries.
111
+	 *
112
+	 * @return string
113
+	 * @throws EE_Error
114
+	 */
115
+	public function get_table_alias()
116
+	{
117
+		if (! $this->_table_alias) {
118
+			throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119
+		}
120
+		return $this->_table_alias;
121
+	}
122
+
123
+
124
+
125
+	/**
126
+	 * @return string name of column of PK
127
+	 */
128
+	public function get_pk_column()
129
+	{
130
+		return $this->_pk_column;
131
+	}
132
+
133
+
134
+
135
+	/**
136
+	 * returns a string with the table alias, a period, and the private key's column.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	public function get_fully_qualified_pk_column()
141
+	{
142
+		$sql = $this->get_table_alias() . "." . $this->get_pk_column();
143
+		return $sql;
144
+	}
145
+
146
+
147
+
148
+	/**
149
+	 * returns the special sql for a inner select with a limit.
150
+	 *
151
+	 * @return string    SQL select
152
+	 */
153
+	public function get_select_join_limit($limit)
154
+	{
155
+		$limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
156
+		$SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
157
+		return $SQL;
158
+	}
159
+
160
+
161
+
162
+	/**
163
+	 * Returns whether or not htis is a global table (ie, on multisite there's
164
+	 * only one of these tables, on the main blog)
165
+	 *
166
+	 * @return boolean
167
+	 */
168
+	public function is_global()
169
+	{
170
+		return $this->_global;
171
+	}
172 172
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
      */
102 102
     public function get_table_name()
103 103
     {
104
-        return $this->get_table_prefix() . $this->_table_name;
104
+        return $this->get_table_prefix().$this->_table_name;
105 105
     }
106 106
 
107 107
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function get_table_alias()
116 116
     {
117
-        if (! $this->_table_alias) {
117
+        if ( ! $this->_table_alias) {
118 118
             throw new EE_Error("You must call _construct_finalize_with_alias before using the EE_Table_Base. Did you forget to call parent::__construct at the end of your EEMerimental_Base child's __construct?");
119 119
         }
120 120
         return $this->_table_alias;
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function get_fully_qualified_pk_column()
141 141
     {
142
-        $sql = $this->get_table_alias() . "." . $this->get_pk_column();
142
+        $sql = $this->get_table_alias().".".$this->get_pk_column();
143 143
         return $sql;
144 144
     }
145 145
 
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
      */
153 153
     public function get_select_join_limit($limit)
154 154
     {
155
-        $limit = is_array($limit) ? 'LIMIT ' . implode(',', array_map('intval', $limit)) : 'LIMIT ' . (int) $limit;
156
-        $SQL = SP . '(SELECT * FROM ' . $this->_table_name . SP . $limit . ') AS ' . $this->_table_alias;
155
+        $limit = is_array($limit) ? 'LIMIT '.implode(',', array_map('intval', $limit)) : 'LIMIT '.(int) $limit;
156
+        $SQL = SP.'(SELECT * FROM '.$this->_table_name.SP.$limit.') AS '.$this->_table_alias;
157 157
         return $SQL;
158 158
     }
159 159
 
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Unique_Index.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,5 +6,5 @@
 block discarded – undo
6 6
  */
7 7
 class EE_Unique_Index extends EE_Index
8 8
 {
9
-    // yep, actually the same as index right now
9
+	// yep, actually the same as index right now
10 10
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Primary_Table.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -7,24 +7,24 @@
 block discarded – undo
7 7
 class EE_Primary_Table extends EE_Table_Base
8 8
 {
9 9
 
10
-    /**
11
-     *
12
-     * @global type $wpdb
13
-     * @param string $table_name with or without wpdb prefix
14
-     * @param string $pk_column name of primary key column
15
-     * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
16
-     *                  or whether each site on a multisite install has a copy of this table
17
-     */
18
-    public function __construct($table_name, $pk_column = null, $global = false)
19
-    {
20
-        parent::__construct($table_name, $pk_column, $global);
21
-    }
22
-    /**
23
-     * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee "
24
-     * @return string
25
-     */
26
-    public function get_table_sql()
27
-    {
28
-        return " ".$this->get_table_name()." AS ".$this->get_table_alias()." ";
29
-    }
10
+	/**
11
+	 *
12
+	 * @global type $wpdb
13
+	 * @param string $table_name with or without wpdb prefix
14
+	 * @param string $pk_column name of primary key column
15
+	 * @param boolean $global whether the table is "global" as in there is only 1 table on an entire multisite install,
16
+	 *                  or whether each site on a multisite install has a copy of this table
17
+	 */
18
+	public function __construct($table_name, $pk_column = null, $global = false)
19
+	{
20
+		parent::__construct($table_name, $pk_column, $global);
21
+	}
22
+	/**
23
+	 * Gets SQL for this table and assigning it an alias. Eg " wp_esp_attendee AS Attendee "
24
+	 * @return string
25
+	 */
26
+	public function get_table_sql()
27
+	{
28
+		return " ".$this->get_table_name()." AS ".$this->get_table_alias()." ";
29
+	}
30 30
 }
Please login to merge, or discard this patch.