Completed
Branch sideload-all-language-files (829736)
by
unknown
08:41
created
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.
core/db_models/helpers/EE_Model_Parser.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -8,153 +8,153 @@
 block discarded – undo
8 8
  */
9 9
 class EE_Model_Parser
10 10
 {
11
-    const table_alias_model_relation_chain_separator = '__';
12
-    const table_alias_model_relation_chain_prefix_end = '___';
13
-    /**
14
-     * Adds a period onto the front and end of the string. This often helps in searching.
15
-     * For example, if we want to find the model name "Event", it can be tricky when the following are possible
16
-     * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in
17
-     * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT
18
-     * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally
19
-     * has it as a substring
20
-     * @param string $string_to_pad
21
-     * @return string
22
-     */
23
-    public static function pad_with_periods($string_to_pad)
24
-    {
25
-        return ".".$string_to_pad.".";
26
-    }
27
-    /**
28
-     * Basically undoes _pad_with_periods
29
-     * @param string $string_to_trim
30
-     * @return string
31
-     */
32
-    public static function trim_periods($string_to_trim)
33
-    {
34
-        return trim($string_to_trim, '.');
35
-    }
11
+	const table_alias_model_relation_chain_separator = '__';
12
+	const table_alias_model_relation_chain_prefix_end = '___';
13
+	/**
14
+	 * Adds a period onto the front and end of the string. This often helps in searching.
15
+	 * For example, if we want to find the model name "Event", it can be tricky when the following are possible
16
+	 * "","Event.EVT_ID","Event","Event_Venue.Venue.VNU_ID",etc. It's easier to look for ".Event." in
17
+	 * "..",".Event.EVT_ID.", ".Event.", and ".Event_Venue.Venue.VNU_ID", especially when the last example should NOT
18
+	 * be found because the "Event" model isn't mentioned- it's just a string that has a model name that coincidentally
19
+	 * has it as a substring
20
+	 * @param string $string_to_pad
21
+	 * @return string
22
+	 */
23
+	public static function pad_with_periods($string_to_pad)
24
+	{
25
+		return ".".$string_to_pad.".";
26
+	}
27
+	/**
28
+	 * Basically undoes _pad_with_periods
29
+	 * @param string $string_to_trim
30
+	 * @return string
31
+	 */
32
+	public static function trim_periods($string_to_trim)
33
+	{
34
+		return trim($string_to_trim, '.');
35
+	}
36 36
 
37 37
 
38 38
 
39
-    /**
40
-     * Gets the calculated table's alias
41
-     * @param string $model_relation_chain or query param
42
-     * @param        $this_model_name
43
-     * @return string which can be added onto table aliases to make them unique
44
-     */
45
-    public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name)
46
-    {
47
-        // eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event'
48
-        $model_relation_chain = self::pad_with_periods($model_relation_chain);
49
-        $this_model_name = self::pad_with_periods($this_model_name);
50
-        // eg '.Venue.Event_Venue.Event.Registration." and '.Event.'
51
-        // remove this model name and everything afterwards
52
-        $pos_of_model_name = strpos($model_relation_chain, $this_model_name);
53
-        $model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name);
54
-        // eg '.Venue.Event_Venue.'
55
-        // trim periods
56
-        $model_relation_chain = self::trim_periods($model_relation_chain);
57
-        // eg 'Venue.Event_Venue'
58
-        // replace periods with double-underscores
59
-        $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain);
60
-        // eg 'Venue__Event_Venue'
61
-        if ($model_relation_chain !='') {
62
-            $model_relation_chain = $model_relation_chain.self::table_alias_model_relation_chain_prefix_end;
63
-        }
64
-        // eg 'Venue_Event_Venue___'
65
-        return $model_relation_chain;
66
-    }
67
-    /**
68
-     * Gets the table's alias (without prefix or anything)
69
-     * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not)
70
-     * @return string
71
-     */
72
-    public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix)
73
-    {
74
-        // does this actually have a table alias model relation chain prefix?
75
-        $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end);
76
-        if ($pos !== false) {
77
-            // yes
78
-            // find that triple underscore and remove it and everything before it
79
-            $table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end));
80
-        } else {
81
-            $table_alias = $table_alias_with_model_relation_chain_prefix;
82
-        }
83
-        return $table_alias;
84
-    }
85
-    /**
86
-     * Gets the table alias model relation chain prefix from the table alias already containing it
87
-     * @param string $table_alias_with_model_relation_chain_prefix
88
-     * @return string
89
-     */
90
-    public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix)
91
-    {
92
-        // does this actually have a table alias model relation chain prefix?
93
-        $pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end);
94
-        if ($pos !== false) {
95
-            // yes
96
-            // find that triple underscore and remove it and everything before it
97
-            $prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end));
98
-        } else {
99
-            $prefix = '';
100
-        }
101
-        return $prefix;
102
-    }
39
+	/**
40
+	 * Gets the calculated table's alias
41
+	 * @param string $model_relation_chain or query param
42
+	 * @param        $this_model_name
43
+	 * @return string which can be added onto table aliases to make them unique
44
+	 */
45
+	public static function extract_table_alias_model_relation_chain_prefix($model_relation_chain, $this_model_name)
46
+	{
47
+		// eg $model_relation_chain = 'Venue.Event_Venue.Event.Registration", and $this_model_name = 'Event'
48
+		$model_relation_chain = self::pad_with_periods($model_relation_chain);
49
+		$this_model_name = self::pad_with_periods($this_model_name);
50
+		// eg '.Venue.Event_Venue.Event.Registration." and '.Event.'
51
+		// remove this model name and everything afterwards
52
+		$pos_of_model_name = strpos($model_relation_chain, $this_model_name);
53
+		$model_relation_chain = substr($model_relation_chain, 0, $pos_of_model_name);
54
+		// eg '.Venue.Event_Venue.'
55
+		// trim periods
56
+		$model_relation_chain = self::trim_periods($model_relation_chain);
57
+		// eg 'Venue.Event_Venue'
58
+		// replace periods with double-underscores
59
+		$model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain);
60
+		// eg 'Venue__Event_Venue'
61
+		if ($model_relation_chain !='') {
62
+			$model_relation_chain = $model_relation_chain.self::table_alias_model_relation_chain_prefix_end;
63
+		}
64
+		// eg 'Venue_Event_Venue___'
65
+		return $model_relation_chain;
66
+	}
67
+	/**
68
+	 * Gets the table's alias (without prefix or anything)
69
+	 * @param string $table_alias_with_model_relation_chain_prefix which CAN have a table alias model relation chain prefix (or not)
70
+	 * @return string
71
+	 */
72
+	public static function remove_table_alias_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix)
73
+	{
74
+		// does this actually have a table alias model relation chain prefix?
75
+		$pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end);
76
+		if ($pos !== false) {
77
+			// yes
78
+			// find that triple underscore and remove it and everything before it
79
+			$table_alias = substr($table_alias_with_model_relation_chain_prefix, $pos + strlen(self::table_alias_model_relation_chain_prefix_end));
80
+		} else {
81
+			$table_alias = $table_alias_with_model_relation_chain_prefix;
82
+		}
83
+		return $table_alias;
84
+	}
85
+	/**
86
+	 * Gets the table alias model relation chain prefix from the table alias already containing it
87
+	 * @param string $table_alias_with_model_relation_chain_prefix
88
+	 * @return string
89
+	 */
90
+	public static function get_prefix_from_table_alias_with_model_relation_chain_prefix($table_alias_with_model_relation_chain_prefix)
91
+	{
92
+		// does this actually have a table alias model relation chain prefix?
93
+		$pos = strpos($table_alias_with_model_relation_chain_prefix, self::table_alias_model_relation_chain_prefix_end);
94
+		if ($pos !== false) {
95
+			// yes
96
+			// find that triple underscore and remove it and everything before it
97
+			$prefix = substr($table_alias_with_model_relation_chain_prefix, 0, $pos + strlen(self::table_alias_model_relation_chain_prefix_end));
98
+		} else {
99
+			$prefix = '';
100
+		}
101
+		return $prefix;
102
+	}
103 103
 
104
-    /**
105
-     * Gets the table alias model relation chain prefix (ie, what can be prepended onto
106
-     * EE_Model_Field::get_qualified_column() to get the proper column name for that field
107
-     * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID').
108
-     *
109
-     * @param string $model_name of the model on which the related query param was found to be belong
110
-     * @param string $original_query_param
111
-     * @return string
112
-     */
113
-    public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param)
114
-    {
115
-        $relation_chain = self::extract_model_relation_chain($model_name, $original_query_param);
116
-        $table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name);
117
-        return $table_alias_with_model_relation_chain_prefix;
118
-    }
119
-    /**
120
-     * Gets the model relation chain to $model_name from the $original_query_param.
121
-     * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID',
122
-     * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment'
123
-     * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment'
124
-     * @param string $model_name
125
-     * @param string $original_query_param
126
-     * @return string
127
-     */
128
-    public static function extract_model_relation_chain($model_name, $original_query_param)
129
-    {
130
-        // prefix and postfix both with a period, as this facilitates searching
131
-        $model_name = EE_Model_Parser::pad_with_periods($model_name);
132
-        $original_query_param = EE_Model_Parser::pad_with_periods($original_query_param);
133
-        $pos_of_model_string = strpos($original_query_param, $model_name);
134
-        // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like
135
-        // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string
136
-        // "Registration.Transaction.Payment"
137
-        $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string+strlen($model_name));
138
-        return EE_Model_Parser::trim_periods($model_relation_chain);
139
-    }
104
+	/**
105
+	 * Gets the table alias model relation chain prefix (ie, what can be prepended onto
106
+	 * EE_Model_Field::get_qualified_column() to get the proper column name for that field
107
+	 * in a specific query) from teh query param (eg 'Registration.Event.EVT_ID').
108
+	 *
109
+	 * @param string $model_name of the model on which the related query param was found to be belong
110
+	 * @param string $original_query_param
111
+	 * @return string
112
+	 */
113
+	public static function extract_table_alias_model_relation_chain_from_query_param($model_name, $original_query_param)
114
+	{
115
+		$relation_chain = self::extract_model_relation_chain($model_name, $original_query_param);
116
+		$table_alias_with_model_relation_chain_prefix = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix($relation_chain, $model_name);
117
+		return $table_alias_with_model_relation_chain_prefix;
118
+	}
119
+	/**
120
+	 * Gets the model relation chain to $model_name from the $original_query_param.
121
+	 * Eg, if $model_name were 'Payment', and $original_query_param were 'Registration.Transaction.Payment.PAY_ID',
122
+	 * this would return 'Registration.Transaction.Payment'. Also if the query param were 'Registration.Transaction.Payment'
123
+	 * and $model_name were 'Payment', it should return 'Registration.Transaction.Payment'
124
+	 * @param string $model_name
125
+	 * @param string $original_query_param
126
+	 * @return string
127
+	 */
128
+	public static function extract_model_relation_chain($model_name, $original_query_param)
129
+	{
130
+		// prefix and postfix both with a period, as this facilitates searching
131
+		$model_name = EE_Model_Parser::pad_with_periods($model_name);
132
+		$original_query_param = EE_Model_Parser::pad_with_periods($original_query_param);
133
+		$pos_of_model_string = strpos($original_query_param, $model_name);
134
+		// eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like
135
+		// "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string
136
+		// "Registration.Transaction.Payment"
137
+		$model_relation_chain = substr($original_query_param, 0, $pos_of_model_string+strlen($model_name));
138
+		return EE_Model_Parser::trim_periods($model_relation_chain);
139
+	}
140 140
 
141
-    /**
142
-     * Replaces the specified model in teh model relation chain with teh join model.
143
-     * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain(
144
-     * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return
145
-     * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix
146
-     * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix
147
-     * @param string $model_name
148
-     * @param string $join_model_name
149
-     * @param string $model_relation_chain
150
-     * @return string
151
-     */
152
-    public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain)
153
-    {
154
-        $model_name = EE_Model_Parser::pad_with_periods($model_name);
155
-        $join_model_name = EE_Model_Parser::pad_with_periods($join_model_name);
156
-        $model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain);
157
-        $replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain);
158
-        return EE_Model_Parser::trim_periods($replaced_with_periods);
159
-    }
141
+	/**
142
+	 * Replaces the specified model in teh model relation chain with teh join model.
143
+	 * Eg EE_Model_Parser::replace_model_name_with_join_model_name_in_model_relation_chain(
144
+	 * "Ticket", "Datetime_Ticket", "Datetime.Ticket" ) will return
145
+	 * "Datetime.Datetime_Ticket" which can be used to find the table alias model relation chain prefix
146
+	 * using EE_Model_Parser::extract_table_alias_model_relation_chain_prefix
147
+	 * @param string $model_name
148
+	 * @param string $join_model_name
149
+	 * @param string $model_relation_chain
150
+	 * @return string
151
+	 */
152
+	public static function replace_model_name_with_join_model_name_in_model_relation_chain($model_name, $join_model_name, $model_relation_chain)
153
+	{
154
+		$model_name = EE_Model_Parser::pad_with_periods($model_name);
155
+		$join_model_name = EE_Model_Parser::pad_with_periods($join_model_name);
156
+		$model_relation_chain = EE_Model_Parser::pad_with_periods($model_relation_chain);
157
+		$replaced_with_periods = str_replace($model_name, $join_model_name, $model_relation_chain);
158
+		return EE_Model_Parser::trim_periods($replaced_with_periods);
159
+	}
160 160
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@  discard block
 block discarded – undo
58 58
         // replace periods with double-underscores
59 59
         $model_relation_chain = str_replace(".", self::table_alias_model_relation_chain_separator, $model_relation_chain);
60 60
         // eg 'Venue__Event_Venue'
61
-        if ($model_relation_chain !='') {
61
+        if ($model_relation_chain != '') {
62 62
             $model_relation_chain = $model_relation_chain.self::table_alias_model_relation_chain_prefix_end;
63 63
         }
64 64
         // eg 'Venue_Event_Venue___'
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
         // eg, if we're looking for the model relation chain from Event to Payment, the original query param is probably something like
135 135
         // "Registration.Transaction.Payment.PAY_ID", $pos_of_model_string points to the 'P' or Payment. We want the string
136 136
         // "Registration.Transaction.Payment"
137
-        $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string+strlen($model_name));
137
+        $model_relation_chain = substr($original_query_param, 0, $pos_of_model_string + strlen($model_name));
138 138
         return EE_Model_Parser::trim_periods($model_relation_chain);
139 139
     }
140 140
 
Please login to merge, or discard this patch.