Completed
Branch update-venue-ui (4b9c7e)
by
unknown
02:27
created
core/db_models/relations/EE_Model_Relation_Base.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         $this_table_join_column,
157 157
         $extra_join_sql = ''
158 158
     ) {
159
-        return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : '');
159
+        return " LEFT JOIN ".$other_table." AS ".$other_table_alias." ON ".$other_table_alias.".".$other_table_column."=".$this_table_alias.".".$this_table_join_column.($extra_join_sql ? " AND $extra_join_sql" : '');
160 160
     }
161 161
 
162 162
 
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
                                                              . "."
191 191
                                                              . $this->get_this_model()->get_primary_key_field()->get_name();
192 192
         $model_object_id                                   = $this->_get_model_object_id($model_object_or_id);
193
-        $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
193
+        $query_params[0][$query_param_where_this_model_pk] = $model_object_id;
194 194
         return $this->get_other_model()->get_all($query_params);
195 195
     }
196 196
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
      */
204 204
     protected function _disable_default_where_conditions_on_query_param($query_params)
205 205
     {
206
-        if (! isset($query_params['default_where_conditions'])) {
206
+        if ( ! isset($query_params['default_where_conditions'])) {
207 207
             $query_params['default_where_conditions'] = 'none';
208 208
         }
209 209
         return $query_params;
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
                 $model_object_or_id
234 234
             );
235 235
             /* @var $model_object_or_id EE_Base_Class */
236
-            if (! $delete_is_blocked) {
236
+            if ( ! $delete_is_blocked) {
237 237
                 $this->remove_relation_to($model_object_or_id, $related_model_object);
238 238
                 $related_model_object->delete();
239 239
                 $deleted_count++;
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
             if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
270 270
                 $this->remove_relation_to($model_object_or_id, $related_model_object);
271 271
                 $deleted_count++;
272
-                if (! $delete_is_blocked) {
272
+                if ( ! $delete_is_blocked) {
273 273
                     $related_model_object->delete_permanently();
274 274
                 } else {
275 275
                     // delete is blocked
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
                 }
279 279
             } else {
280 280
                 // its not a soft-deletable thing anyways. do the normal logic.
281
-                if (! $delete_is_blocked) {
281
+                if ( ! $delete_is_blocked) {
282 282
                     $this->remove_relation_to($model_object_or_id, $related_model_object);
283 283
                     $related_model_object->delete();
284 284
                     $deleted_count++;
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
         if ($model_object_or_id instanceof EE_Base_Class) {
303 303
             $model_object_id = $model_object_or_id->ID();
304 304
         }
305
-        if (! $model_object_id) {
305
+        if ( ! $model_object_id) {
306 306
             throw new EE_Error(sprintf(
307 307
                 __(
308 308
                     "Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects",
Please login to merge, or discard this patch.
Indentation   +497 added lines, -497 removed lines patch added patch discarded remove patch
@@ -15,502 +15,502 @@
 block discarded – undo
15 15
  */
16 16
 abstract class EE_Model_Relation_Base implements HasSchemaInterface
17 17
 {
18
-    /**
19
-     * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base)
20
-     *
21
-     * @var string eg Event, Question_Group, Registration
22
-     */
23
-    private $_this_model_name;
24
-    /**
25
-     * The model name pointed to by this relation (ie, the model we want to establish a relationship to)
26
-     *
27
-     * @var string eg Event, Question_Group, Registration
28
-     */
29
-    private $_other_model_name;
30
-
31
-    /**
32
-     * this is typically used when calling the relation models to make sure they inherit any set timezone from the
33
-     * initiating model.
34
-     *
35
-     * @var string
36
-     */
37
-    protected $_timezone;
38
-
39
-    /**
40
-     * If you try to delete "this_model", and there are related "other_models",
41
-     * and this isn't null, then abandon the deletion and add this warning.
42
-     * This effectively makes it impossible to delete "this_model" while there are
43
-     * related "other_models" along this relation.
44
-     *
45
-     * @var string (internationalized)
46
-     */
47
-    protected $_blocking_delete_error_message;
48
-
49
-    protected $_blocking_delete = false;
50
-
51
-    /**
52
-     * Object representing the relationship between two models. This knows how to join the models,
53
-     * get related models across the relation, and add-and-remove the relationships.
54
-     *
55
-     * @param boolean $block_deletes                 if there are related models across this relation, block (prevent
56
-     *                                               and add an error) the deletion of this model
57
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
58
-     *                                               default
59
-     */
60
-    public function __construct($block_deletes, $blocking_delete_error_message)
61
-    {
62
-        $this->_blocking_delete               = $block_deletes;
63
-        $this->_blocking_delete_error_message = $blocking_delete_error_message;
64
-    }
65
-
66
-
67
-    /**
68
-     * @param $this_model_name
69
-     * @param $other_model_name
70
-     * @throws EE_Error
71
-     */
72
-    public function _construct_finalize_set_models($this_model_name, $other_model_name)
73
-    {
74
-        $this->_this_model_name  = $this_model_name;
75
-        $this->_other_model_name = $other_model_name;
76
-        if (is_string($this->_blocking_delete)) {
77
-            throw new EE_Error(sprintf(
78
-                __(
79
-                    "When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)",
80
-                    "event_espresso"
81
-                ),
82
-                get_class($this),
83
-                $this_model_name,
84
-                $other_model_name,
85
-                $this->_blocking_delete
86
-            ));
87
-        }
88
-    }
89
-
90
-
91
-    /**
92
-     * Gets the model where this relation is defined.
93
-     *
94
-     * @return EEM_Base
95
-     */
96
-    public function get_this_model()
97
-    {
98
-        return $this->_get_model($this->_this_model_name);
99
-    }
100
-
101
-
102
-    /**
103
-     * Gets the model which this relation establishes the relation TO (ie,
104
-     * this relation object was defined on get_this_model(), get_other_model() is the other one)
105
-     *
106
-     * @return EEM_Base
107
-     */
108
-    public function get_other_model()
109
-    {
110
-        return $this->_get_model($this->_other_model_name);
111
-    }
112
-
113
-
114
-    /**
115
-     * Internally used by get_this_model() and get_other_model()
116
-     *
117
-     * @param string $model_name like Event, Question_Group, etc. omit the EEM_
118
-     * @return EEM_Base
119
-     */
120
-    protected function _get_model($model_name)
121
-    {
122
-        $modelInstance = EE_Registry::instance()->load_model($model_name);
123
-        $modelInstance->set_timezone($this->_timezone);
124
-        return $modelInstance;
125
-    }
126
-
127
-
128
-    /**
129
-     * entirely possible that relations may be called from a model and we need to make sure those relations have their
130
-     * timezone set correctly.
131
-     *
132
-     * @param string $timezone timezone to set.
133
-     */
134
-    public function set_timezone($timezone)
135
-    {
136
-        if ($timezone !== null) {
137
-            $this->_timezone = $timezone;
138
-        }
139
-    }
140
-
141
-
142
-    /**
143
-     * @param        $other_table
144
-     * @param        $other_table_alias
145
-     * @param        $other_table_column
146
-     * @param        $this_table_alias
147
-     * @param        $this_table_join_column
148
-     * @param string $extra_join_sql
149
-     * @return string
150
-     */
151
-    protected function _left_join(
152
-        $other_table,
153
-        $other_table_alias,
154
-        $other_table_column,
155
-        $this_table_alias,
156
-        $this_table_join_column,
157
-        $extra_join_sql = ''
158
-    ) {
159
-        return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : '');
160
-    }
161
-
162
-
163
-    /**
164
-     * Gets all the model objects of type of other model related to $model_object,
165
-     * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation.
166
-     * For both of those child classes, $model_object must be saved so that it has an ID before querying,
167
-     * otherwise an error will be thrown. Note: by default we disable default_where_conditions
168
-     * EE_Belongs_To_Relation doesn't need to be saved before querying.
169
-     *
170
-     * @param EE_Base_Class|int $model_object_or_id                      or the primary key of this model
171
-     * @param array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
172
-     * @param boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
173
-     * @return EE_Base_Class[]
174
-     * @throws \EE_Error
175
-     */
176
-    public function get_all_related(
177
-        $model_object_or_id,
178
-        $query_params = array(),
179
-        $values_already_prepared_by_model_object = false
180
-    ) {
181
-        if ($values_already_prepared_by_model_object !== false) {
182
-            EE_Error::doing_it_wrong(
183
-                'EE_Model_Relation_Base::get_all_related',
184
-                __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
185
-                '4.8.1'
186
-            );
187
-        }
188
-        $query_params                                      = $this->_disable_default_where_conditions_on_query_param($query_params);
189
-        $query_param_where_this_model_pk                   = $this->get_this_model()->get_this_model_name()
190
-                                                             . "."
191
-                                                             . $this->get_this_model()->get_primary_key_field()->get_name();
192
-        $model_object_id                                   = $this->_get_model_object_id($model_object_or_id);
193
-        $query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
194
-        return $this->get_other_model()->get_all($query_params);
195
-    }
196
-
197
-
198
-    /**
199
-     * Alters the $query_params to disable default where conditions, unless otherwise specified
200
-     *
201
-     * @param string $query_params
202
-     * @return array
203
-     */
204
-    protected function _disable_default_where_conditions_on_query_param($query_params)
205
-    {
206
-        if (! isset($query_params['default_where_conditions'])) {
207
-            $query_params['default_where_conditions'] = 'none';
208
-        }
209
-        return $query_params;
210
-    }
211
-
212
-
213
-    /**
214
-     * Deletes the related model objects which meet the query parameters. If no
215
-     * parameters are specified, then all related model objects will be deleted.
216
-     * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
217
-     * model objects will only be soft-deleted.
218
-     *
219
-     * @param EE_Base_Class|int|string $model_object_or_id
220
-     * @param array                    $query_params
221
-     * @return int of how many related models got deleted
222
-     * @throws \EE_Error
223
-     */
224
-    public function delete_all_related($model_object_or_id, $query_params = array())
225
-    {
226
-        // for each thing we would delete,
227
-        $related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
228
-        // determine if it's blocked by anything else before it can be deleted
229
-        $deleted_count = 0;
230
-        foreach ($related_model_objects as $related_model_object) {
231
-            $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
232
-                $related_model_object,
233
-                $model_object_or_id
234
-            );
235
-            /* @var $model_object_or_id EE_Base_Class */
236
-            if (! $delete_is_blocked) {
237
-                $this->remove_relation_to($model_object_or_id, $related_model_object);
238
-                $related_model_object->delete();
239
-                $deleted_count++;
240
-            }
241
-        }
242
-        return $deleted_count;
243
-    }
244
-
245
-
246
-    /**
247
-     * Deletes the related model objects which meet the query parameters. If no
248
-     * parameters are specified, then all related model objects will be deleted.
249
-     * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
250
-     * model objects will only be soft-deleted.
251
-     *
252
-     * @param EE_Base_Class|int|string $model_object_or_id
253
-     * @param array                    $query_params
254
-     * @return int of how many related models got deleted
255
-     * @throws \EE_Error
256
-     */
257
-    public function delete_related_permanently($model_object_or_id, $query_params = array())
258
-    {
259
-        // for each thing we would delete,
260
-        $related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
261
-        // determine if it's blocked by anything else before it can be deleted
262
-        $deleted_count = 0;
263
-        foreach ($related_model_objects as $related_model_object) {
264
-            $delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
265
-                $related_model_object,
266
-                $model_object_or_id
267
-            );
268
-            /* @var $model_object_or_id EE_Base_Class */
269
-            if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
270
-                $this->remove_relation_to($model_object_or_id, $related_model_object);
271
-                $deleted_count++;
272
-                if (! $delete_is_blocked) {
273
-                    $related_model_object->delete_permanently();
274
-                } else {
275
-                    // delete is blocked
276
-                    // brent and darren, in this case, wanted to just soft delete it then
277
-                    $related_model_object->delete();
278
-                }
279
-            } else {
280
-                // its not a soft-deletable thing anyways. do the normal logic.
281
-                if (! $delete_is_blocked) {
282
-                    $this->remove_relation_to($model_object_or_id, $related_model_object);
283
-                    $related_model_object->delete();
284
-                    $deleted_count++;
285
-                }
286
-            }
287
-        }
288
-        return $deleted_count;
289
-    }
290
-
291
-
292
-    /**
293
-     * this just returns a model_object_id for incoming item that could be an object or id.
294
-     *
295
-     * @param  EE_Base_Class|int $model_object_or_id model object or the primary key of this model
296
-     * @throws EE_Error
297
-     * @return int
298
-     */
299
-    protected function _get_model_object_id($model_object_or_id)
300
-    {
301
-        $model_object_id = $model_object_or_id;
302
-        if ($model_object_or_id instanceof EE_Base_Class) {
303
-            $model_object_id = $model_object_or_id->ID();
304
-        }
305
-        if (! $model_object_id) {
306
-            throw new EE_Error(sprintf(
307
-                __(
308
-                    "Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects",
309
-                    "event_espresso"
310
-                ),
311
-                $this->get_other_model()->get_this_model_name(),
312
-                $this->get_this_model()->get_this_model_name()
313
-            ));
314
-        }
315
-        return $model_object_id;
316
-    }
317
-
318
-
319
-    /**
320
-     * Gets the SQL string for performing the join between this model and the other model.
321
-     *
322
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
323
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
324
-     *                other_model_primary_table.fk" etc
325
-     */
326
-    abstract public function get_join_statement($model_relation_chain);
327
-
328
-
329
-    /**
330
-     * Adds a relationships between the two model objects provided. Each type of relationship handles this differently
331
-     * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this
332
-     * relationship only allows this model to be related to a single other model of this type)
333
-     *
334
-     * @param       $this_obj_or_id
335
-     * @param       $other_obj_or_id
336
-     * @param array $extra_join_model_fields_n_values
337
-     * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for
338
-     *                        $other_obj_or_id)
339
-     */
340
-    abstract public function add_relation_to(
341
-        $this_obj_or_id,
342
-        $other_obj_or_id,
343
-        $extra_join_model_fields_n_values = array()
344
-    );
345
-
346
-
347
-    /**
348
-     * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two
349
-     * model objects
350
-     *
351
-     * @param       $this_obj_or_id
352
-     * @param       $other_obj_or_id
353
-     * @param array $where_query
354
-     * @return bool
355
-     */
356
-    abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array());
357
-
358
-
359
-    /**
360
-     * Removes ALL relation instances for this relation obj
361
-     *
362
-     * @param EE_Base_Class|int $this_obj_or_id
363
-     * @param array             $where_query_param @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
364
-     * @return EE_Base_Class[]
365
-     * @throws \EE_Error
366
-     */
367
-    public function remove_relations($this_obj_or_id, $where_query_param = array())
368
-    {
369
-        $related_things = $this->get_all_related($this_obj_or_id, array($where_query_param));
370
-        $objs_removed   = array();
371
-        foreach ($related_things as $related_thing) {
372
-            $objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing);
373
-        }
374
-        return $objs_removed;
375
-    }
376
-
377
-
378
-    /**
379
-     * If you aren't allowed to delete this model when there are related models across this
380
-     * relation object, return true. Otherwise, if you can delete this model even though
381
-     * related objects exist, returns false.
382
-     *
383
-     * @return boolean
384
-     */
385
-    public function block_delete_if_related_models_exist()
386
-    {
387
-        return $this->_blocking_delete;
388
-    }
389
-
390
-
391
-    /**
392
-     * Gets the error message to show
393
-     *
394
-     * @return string
395
-     */
396
-    public function get_deletion_error_message()
397
-    {
398
-        if ($this->_blocking_delete_error_message) {
399
-            return $this->_blocking_delete_error_message;
400
-        } else {
18
+	/**
19
+	 * The model name of which this relation is a component (ie, the model that called new EE_Model_Relation_Base)
20
+	 *
21
+	 * @var string eg Event, Question_Group, Registration
22
+	 */
23
+	private $_this_model_name;
24
+	/**
25
+	 * The model name pointed to by this relation (ie, the model we want to establish a relationship to)
26
+	 *
27
+	 * @var string eg Event, Question_Group, Registration
28
+	 */
29
+	private $_other_model_name;
30
+
31
+	/**
32
+	 * this is typically used when calling the relation models to make sure they inherit any set timezone from the
33
+	 * initiating model.
34
+	 *
35
+	 * @var string
36
+	 */
37
+	protected $_timezone;
38
+
39
+	/**
40
+	 * If you try to delete "this_model", and there are related "other_models",
41
+	 * and this isn't null, then abandon the deletion and add this warning.
42
+	 * This effectively makes it impossible to delete "this_model" while there are
43
+	 * related "other_models" along this relation.
44
+	 *
45
+	 * @var string (internationalized)
46
+	 */
47
+	protected $_blocking_delete_error_message;
48
+
49
+	protected $_blocking_delete = false;
50
+
51
+	/**
52
+	 * Object representing the relationship between two models. This knows how to join the models,
53
+	 * get related models across the relation, and add-and-remove the relationships.
54
+	 *
55
+	 * @param boolean $block_deletes                 if there are related models across this relation, block (prevent
56
+	 *                                               and add an error) the deletion of this model
57
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
58
+	 *                                               default
59
+	 */
60
+	public function __construct($block_deletes, $blocking_delete_error_message)
61
+	{
62
+		$this->_blocking_delete               = $block_deletes;
63
+		$this->_blocking_delete_error_message = $blocking_delete_error_message;
64
+	}
65
+
66
+
67
+	/**
68
+	 * @param $this_model_name
69
+	 * @param $other_model_name
70
+	 * @throws EE_Error
71
+	 */
72
+	public function _construct_finalize_set_models($this_model_name, $other_model_name)
73
+	{
74
+		$this->_this_model_name  = $this_model_name;
75
+		$this->_other_model_name = $other_model_name;
76
+		if (is_string($this->_blocking_delete)) {
77
+			throw new EE_Error(sprintf(
78
+				__(
79
+					"When instantiating the relation of type %s from %s to %s, the \$block_deletes argument should be a boolean, not a string (%s)",
80
+					"event_espresso"
81
+				),
82
+				get_class($this),
83
+				$this_model_name,
84
+				$other_model_name,
85
+				$this->_blocking_delete
86
+			));
87
+		}
88
+	}
89
+
90
+
91
+	/**
92
+	 * Gets the model where this relation is defined.
93
+	 *
94
+	 * @return EEM_Base
95
+	 */
96
+	public function get_this_model()
97
+	{
98
+		return $this->_get_model($this->_this_model_name);
99
+	}
100
+
101
+
102
+	/**
103
+	 * Gets the model which this relation establishes the relation TO (ie,
104
+	 * this relation object was defined on get_this_model(), get_other_model() is the other one)
105
+	 *
106
+	 * @return EEM_Base
107
+	 */
108
+	public function get_other_model()
109
+	{
110
+		return $this->_get_model($this->_other_model_name);
111
+	}
112
+
113
+
114
+	/**
115
+	 * Internally used by get_this_model() and get_other_model()
116
+	 *
117
+	 * @param string $model_name like Event, Question_Group, etc. omit the EEM_
118
+	 * @return EEM_Base
119
+	 */
120
+	protected function _get_model($model_name)
121
+	{
122
+		$modelInstance = EE_Registry::instance()->load_model($model_name);
123
+		$modelInstance->set_timezone($this->_timezone);
124
+		return $modelInstance;
125
+	}
126
+
127
+
128
+	/**
129
+	 * entirely possible that relations may be called from a model and we need to make sure those relations have their
130
+	 * timezone set correctly.
131
+	 *
132
+	 * @param string $timezone timezone to set.
133
+	 */
134
+	public function set_timezone($timezone)
135
+	{
136
+		if ($timezone !== null) {
137
+			$this->_timezone = $timezone;
138
+		}
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param        $other_table
144
+	 * @param        $other_table_alias
145
+	 * @param        $other_table_column
146
+	 * @param        $this_table_alias
147
+	 * @param        $this_table_join_column
148
+	 * @param string $extra_join_sql
149
+	 * @return string
150
+	 */
151
+	protected function _left_join(
152
+		$other_table,
153
+		$other_table_alias,
154
+		$other_table_column,
155
+		$this_table_alias,
156
+		$this_table_join_column,
157
+		$extra_join_sql = ''
158
+	) {
159
+		return " LEFT JOIN " . $other_table . " AS " . $other_table_alias . " ON " . $other_table_alias . "." . $other_table_column . "=" . $this_table_alias . "." . $this_table_join_column . ($extra_join_sql ? " AND $extra_join_sql" : '');
160
+	}
161
+
162
+
163
+	/**
164
+	 * Gets all the model objects of type of other model related to $model_object,
165
+	 * according to this relation. This is the same code for EE_HABTM_Relation and EE_Has_Many_Relation.
166
+	 * For both of those child classes, $model_object must be saved so that it has an ID before querying,
167
+	 * otherwise an error will be thrown. Note: by default we disable default_where_conditions
168
+	 * EE_Belongs_To_Relation doesn't need to be saved before querying.
169
+	 *
170
+	 * @param EE_Base_Class|int $model_object_or_id                      or the primary key of this model
171
+	 * @param array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
172
+	 * @param boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
173
+	 * @return EE_Base_Class[]
174
+	 * @throws \EE_Error
175
+	 */
176
+	public function get_all_related(
177
+		$model_object_or_id,
178
+		$query_params = array(),
179
+		$values_already_prepared_by_model_object = false
180
+	) {
181
+		if ($values_already_prepared_by_model_object !== false) {
182
+			EE_Error::doing_it_wrong(
183
+				'EE_Model_Relation_Base::get_all_related',
184
+				__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
185
+				'4.8.1'
186
+			);
187
+		}
188
+		$query_params                                      = $this->_disable_default_where_conditions_on_query_param($query_params);
189
+		$query_param_where_this_model_pk                   = $this->get_this_model()->get_this_model_name()
190
+															 . "."
191
+															 . $this->get_this_model()->get_primary_key_field()->get_name();
192
+		$model_object_id                                   = $this->_get_model_object_id($model_object_or_id);
193
+		$query_params[0][ $query_param_where_this_model_pk ] = $model_object_id;
194
+		return $this->get_other_model()->get_all($query_params);
195
+	}
196
+
197
+
198
+	/**
199
+	 * Alters the $query_params to disable default where conditions, unless otherwise specified
200
+	 *
201
+	 * @param string $query_params
202
+	 * @return array
203
+	 */
204
+	protected function _disable_default_where_conditions_on_query_param($query_params)
205
+	{
206
+		if (! isset($query_params['default_where_conditions'])) {
207
+			$query_params['default_where_conditions'] = 'none';
208
+		}
209
+		return $query_params;
210
+	}
211
+
212
+
213
+	/**
214
+	 * Deletes the related model objects which meet the query parameters. If no
215
+	 * parameters are specified, then all related model objects will be deleted.
216
+	 * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
217
+	 * model objects will only be soft-deleted.
218
+	 *
219
+	 * @param EE_Base_Class|int|string $model_object_or_id
220
+	 * @param array                    $query_params
221
+	 * @return int of how many related models got deleted
222
+	 * @throws \EE_Error
223
+	 */
224
+	public function delete_all_related($model_object_or_id, $query_params = array())
225
+	{
226
+		// for each thing we would delete,
227
+		$related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
228
+		// determine if it's blocked by anything else before it can be deleted
229
+		$deleted_count = 0;
230
+		foreach ($related_model_objects as $related_model_object) {
231
+			$delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
232
+				$related_model_object,
233
+				$model_object_or_id
234
+			);
235
+			/* @var $model_object_or_id EE_Base_Class */
236
+			if (! $delete_is_blocked) {
237
+				$this->remove_relation_to($model_object_or_id, $related_model_object);
238
+				$related_model_object->delete();
239
+				$deleted_count++;
240
+			}
241
+		}
242
+		return $deleted_count;
243
+	}
244
+
245
+
246
+	/**
247
+	 * Deletes the related model objects which meet the query parameters. If no
248
+	 * parameters are specified, then all related model objects will be deleted.
249
+	 * Note: If the related model is extends EEM_Soft_Delete_Base, then the related
250
+	 * model objects will only be soft-deleted.
251
+	 *
252
+	 * @param EE_Base_Class|int|string $model_object_or_id
253
+	 * @param array                    $query_params
254
+	 * @return int of how many related models got deleted
255
+	 * @throws \EE_Error
256
+	 */
257
+	public function delete_related_permanently($model_object_or_id, $query_params = array())
258
+	{
259
+		// for each thing we would delete,
260
+		$related_model_objects = $this->get_all_related($model_object_or_id, $query_params);
261
+		// determine if it's blocked by anything else before it can be deleted
262
+		$deleted_count = 0;
263
+		foreach ($related_model_objects as $related_model_object) {
264
+			$delete_is_blocked = $this->get_other_model()->delete_is_blocked_by_related_models(
265
+				$related_model_object,
266
+				$model_object_or_id
267
+			);
268
+			/* @var $model_object_or_id EE_Base_Class */
269
+			if ($related_model_object instanceof EE_Soft_Delete_Base_Class) {
270
+				$this->remove_relation_to($model_object_or_id, $related_model_object);
271
+				$deleted_count++;
272
+				if (! $delete_is_blocked) {
273
+					$related_model_object->delete_permanently();
274
+				} else {
275
+					// delete is blocked
276
+					// brent and darren, in this case, wanted to just soft delete it then
277
+					$related_model_object->delete();
278
+				}
279
+			} else {
280
+				// its not a soft-deletable thing anyways. do the normal logic.
281
+				if (! $delete_is_blocked) {
282
+					$this->remove_relation_to($model_object_or_id, $related_model_object);
283
+					$related_model_object->delete();
284
+					$deleted_count++;
285
+				}
286
+			}
287
+		}
288
+		return $deleted_count;
289
+	}
290
+
291
+
292
+	/**
293
+	 * this just returns a model_object_id for incoming item that could be an object or id.
294
+	 *
295
+	 * @param  EE_Base_Class|int $model_object_or_id model object or the primary key of this model
296
+	 * @throws EE_Error
297
+	 * @return int
298
+	 */
299
+	protected function _get_model_object_id($model_object_or_id)
300
+	{
301
+		$model_object_id = $model_object_or_id;
302
+		if ($model_object_or_id instanceof EE_Base_Class) {
303
+			$model_object_id = $model_object_or_id->ID();
304
+		}
305
+		if (! $model_object_id) {
306
+			throw new EE_Error(sprintf(
307
+				__(
308
+					"Sorry, we cant get the related %s model objects to %s model object before it has an ID. You can solve that by just saving it before trying to get its related model objects",
309
+					"event_espresso"
310
+				),
311
+				$this->get_other_model()->get_this_model_name(),
312
+				$this->get_this_model()->get_this_model_name()
313
+			));
314
+		}
315
+		return $model_object_id;
316
+	}
317
+
318
+
319
+	/**
320
+	 * Gets the SQL string for performing the join between this model and the other model.
321
+	 *
322
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
323
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
324
+	 *                other_model_primary_table.fk" etc
325
+	 */
326
+	abstract public function get_join_statement($model_relation_chain);
327
+
328
+
329
+	/**
330
+	 * Adds a relationships between the two model objects provided. Each type of relationship handles this differently
331
+	 * (EE_Belongs_To is a slight exception, it should more accurately be called set_relation_to(...), as this
332
+	 * relationship only allows this model to be related to a single other model of this type)
333
+	 *
334
+	 * @param       $this_obj_or_id
335
+	 * @param       $other_obj_or_id
336
+	 * @param array $extra_join_model_fields_n_values
337
+	 * @return \EE_Base_Class the EE_Base_Class which was added as a relation. (Convenient if you only pass an ID for
338
+	 *                        $other_obj_or_id)
339
+	 */
340
+	abstract public function add_relation_to(
341
+		$this_obj_or_id,
342
+		$other_obj_or_id,
343
+		$extra_join_model_fields_n_values = array()
344
+	);
345
+
346
+
347
+	/**
348
+	 * Similar to 'add_relation_to(...)', performs the opposite action of removing the relationship between the two
349
+	 * model objects
350
+	 *
351
+	 * @param       $this_obj_or_id
352
+	 * @param       $other_obj_or_id
353
+	 * @param array $where_query
354
+	 * @return bool
355
+	 */
356
+	abstract public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array());
357
+
358
+
359
+	/**
360
+	 * Removes ALL relation instances for this relation obj
361
+	 *
362
+	 * @param EE_Base_Class|int $this_obj_or_id
363
+	 * @param array             $where_query_param @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md#0-where-conditions
364
+	 * @return EE_Base_Class[]
365
+	 * @throws \EE_Error
366
+	 */
367
+	public function remove_relations($this_obj_or_id, $where_query_param = array())
368
+	{
369
+		$related_things = $this->get_all_related($this_obj_or_id, array($where_query_param));
370
+		$objs_removed   = array();
371
+		foreach ($related_things as $related_thing) {
372
+			$objs_removed[] = $this->remove_relation_to($this_obj_or_id, $related_thing);
373
+		}
374
+		return $objs_removed;
375
+	}
376
+
377
+
378
+	/**
379
+	 * If you aren't allowed to delete this model when there are related models across this
380
+	 * relation object, return true. Otherwise, if you can delete this model even though
381
+	 * related objects exist, returns false.
382
+	 *
383
+	 * @return boolean
384
+	 */
385
+	public function block_delete_if_related_models_exist()
386
+	{
387
+		return $this->_blocking_delete;
388
+	}
389
+
390
+
391
+	/**
392
+	 * Gets the error message to show
393
+	 *
394
+	 * @return string
395
+	 */
396
+	public function get_deletion_error_message()
397
+	{
398
+		if ($this->_blocking_delete_error_message) {
399
+			return $this->_blocking_delete_error_message;
400
+		} else {
401 401
 //          return sprintf(__('Cannot delete %1$s when there are related %2$s', "event_espresso"),$this->get_this_model()->item_name(2),$this->get_other_model()->item_name(2));
402
-            return sprintf(
403
-                __(
404
-                    'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.',
405
-                    "event_espresso"
406
-                ),
407
-                $this->get_this_model()->item_name(1),
408
-                $this->get_other_model()->item_name(1),
409
-                $this->get_other_model()->item_name(2)
410
-            );
411
-        }
412
-    }
413
-
414
-    /**
415
-     * Returns whatever is set as the nicename for the object.
416
-     *
417
-     * @return string
418
-     */
419
-    public function getSchemaDescription()
420
-    {
421
-        $description = $this instanceof EE_Belongs_To_Relation
422
-            ? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso')
423
-            : esc_html__('The related %1$s entities to the %2$s.', 'event_espresso');
424
-        return sprintf(
425
-            $description,
426
-            $this->get_other_model()->get_this_model_name(),
427
-            $this->get_this_model()->get_this_model_name()
428
-        );
429
-    }
430
-
431
-    /**
432
-     * Returns whatever is set as the $_schema_type property for the object.
433
-     * Note: this will automatically add 'null' to the schema if the object is_nullable()
434
-     *
435
-     * @return string|array
436
-     */
437
-    public function getSchemaType()
438
-    {
439
-        return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array';
440
-    }
441
-
442
-    /**
443
-     * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
444
-     * this method and return the properties for the schema.
445
-     * The reason this is not a property on the class is because there may be filters set on the values for the property
446
-     * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
447
-     *
448
-     * @return array
449
-     */
450
-    public function getSchemaProperties()
451
-    {
452
-        return array();
453
-    }
454
-
455
-    /**
456
-     * If a child class has enum values, they should override this method and provide a simple array
457
-     * of the enum values.
458
-     * The reason this is not a property on the class is because there may be filterable enum values that
459
-     * are set on the instantiated object that could be filtered after construct.
460
-     *
461
-     * @return array
462
-     */
463
-    public function getSchemaEnum()
464
-    {
465
-        return array();
466
-    }
467
-
468
-    /**
469
-     * This returns the value of the $_schema_format property on the object.
470
-     *
471
-     * @return string
472
-     */
473
-    public function getSchemaFormat()
474
-    {
475
-        return array();
476
-    }
477
-
478
-    /**
479
-     * This returns the value of the $_schema_readonly property on the object.
480
-     *
481
-     * @return bool
482
-     */
483
-    public function getSchemaReadonly()
484
-    {
485
-        return true;
486
-    }
487
-
488
-    /**
489
-     * This returns elements used to represent this field in the json schema.
490
-     *
491
-     * @link http://json-schema.org/
492
-     * @return array
493
-     */
494
-    public function getSchema()
495
-    {
496
-        $schema = array(
497
-            'description' => $this->getSchemaDescription(),
498
-            'type' => $this->getSchemaType(),
499
-            'relation' => true,
500
-            'relation_type' => get_class($this),
501
-            'readonly' => $this->getSchemaReadonly()
502
-        );
503
-
504
-        if ($this instanceof EE_HABTM_Relation) {
505
-            $schema['joining_model_name'] = $this->get_join_model()->get_this_model_name();
506
-        }
507
-
508
-        if ($this->getSchemaType() === 'array') {
509
-            $schema['items'] = array(
510
-                'type' => 'object'
511
-            );
512
-        }
513
-
514
-        return $schema;
515
-    }
402
+			return sprintf(
403
+				__(
404
+					'This %1$s is currently linked to one or more %2$s records. If this %1$s is incorrect, then please remove it from all %3$s before attempting to delete it.',
405
+					"event_espresso"
406
+				),
407
+				$this->get_this_model()->item_name(1),
408
+				$this->get_other_model()->item_name(1),
409
+				$this->get_other_model()->item_name(2)
410
+			);
411
+		}
412
+	}
413
+
414
+	/**
415
+	 * Returns whatever is set as the nicename for the object.
416
+	 *
417
+	 * @return string
418
+	 */
419
+	public function getSchemaDescription()
420
+	{
421
+		$description = $this instanceof EE_Belongs_To_Relation
422
+			? esc_html__('The related %1$s entity to the %2$s.', 'event_espresso')
423
+			: esc_html__('The related %1$s entities to the %2$s.', 'event_espresso');
424
+		return sprintf(
425
+			$description,
426
+			$this->get_other_model()->get_this_model_name(),
427
+			$this->get_this_model()->get_this_model_name()
428
+		);
429
+	}
430
+
431
+	/**
432
+	 * Returns whatever is set as the $_schema_type property for the object.
433
+	 * Note: this will automatically add 'null' to the schema if the object is_nullable()
434
+	 *
435
+	 * @return string|array
436
+	 */
437
+	public function getSchemaType()
438
+	{
439
+		return $this instanceof EE_Belongs_To_Relation ? 'object' : 'array';
440
+	}
441
+
442
+	/**
443
+	 * This is usually present when the $_schema_type property is 'object'.  Any child classes will need to override
444
+	 * this method and return the properties for the schema.
445
+	 * The reason this is not a property on the class is because there may be filters set on the values for the property
446
+	 * that won't be exposed on construct.  For example enum type schemas may have the enum values filtered.
447
+	 *
448
+	 * @return array
449
+	 */
450
+	public function getSchemaProperties()
451
+	{
452
+		return array();
453
+	}
454
+
455
+	/**
456
+	 * If a child class has enum values, they should override this method and provide a simple array
457
+	 * of the enum values.
458
+	 * The reason this is not a property on the class is because there may be filterable enum values that
459
+	 * are set on the instantiated object that could be filtered after construct.
460
+	 *
461
+	 * @return array
462
+	 */
463
+	public function getSchemaEnum()
464
+	{
465
+		return array();
466
+	}
467
+
468
+	/**
469
+	 * This returns the value of the $_schema_format property on the object.
470
+	 *
471
+	 * @return string
472
+	 */
473
+	public function getSchemaFormat()
474
+	{
475
+		return array();
476
+	}
477
+
478
+	/**
479
+	 * This returns the value of the $_schema_readonly property on the object.
480
+	 *
481
+	 * @return bool
482
+	 */
483
+	public function getSchemaReadonly()
484
+	{
485
+		return true;
486
+	}
487
+
488
+	/**
489
+	 * This returns elements used to represent this field in the json schema.
490
+	 *
491
+	 * @link http://json-schema.org/
492
+	 * @return array
493
+	 */
494
+	public function getSchema()
495
+	{
496
+		$schema = array(
497
+			'description' => $this->getSchemaDescription(),
498
+			'type' => $this->getSchemaType(),
499
+			'relation' => true,
500
+			'relation_type' => get_class($this),
501
+			'readonly' => $this->getSchemaReadonly()
502
+		);
503
+
504
+		if ($this instanceof EE_HABTM_Relation) {
505
+			$schema['joining_model_name'] = $this->get_join_model()->get_this_model_name();
506
+		}
507
+
508
+		if ($this->getSchemaType() === 'array') {
509
+			$schema['items'] = array(
510
+				'type' => 'object'
511
+			);
512
+		}
513
+
514
+		return $schema;
515
+	}
516 516
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Revision_Relation.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
         // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191 191
         foreach ($autosave_relations as $a_r) {
192 192
             $pid = $a_r->parent();
193
-            if (! empty($pid)) {
193
+            if ( ! empty($pid)) {
194 194
                 $parent_ids[] = $pid;
195 195
             } else {
196 196
                 $return_objs[] = $a_r;
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
         }
207 207
 
208 208
         // now we setup the query to get all the parents
209
-        if (! empty($parent_ids)) {
210
-            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
-            $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
209
+        if ( ! empty($parent_ids)) {
210
+            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name().".".$this->get_this_model()->get_primary_key_field()->get_name();
211
+            $query_param[0][$query_param_where_this_model_pk] = array('IN', $parent_ids);
212 212
             $parents                                          = $this->get_other_model()->get_all($query_params);
213 213
         }
214 214
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
             var_dump($this_obj);
244 244
             var_dump($other_obj);/**/
245 245
 
246
-            if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
246
+            if ( ! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247 247
                 // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248 248
                 $has_parent_obj = $this->get_other_model()->get_one(array(
249 249
                     array(
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
                     $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260 260
                     $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261 261
 
262
-                    if (! $remove_relation) {
262
+                    if ( ! $remove_relation) {
263 263
                         $other_obj->save();
264 264
                         return array($other_obj);
265 265
                     } elseif ($remove_relation && ! $this->_blocking_delete) {
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
             // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288 288
         } else {
289 289
             // we only need to do the below IF this is not a remove relation
290
-            if (! $remove_relation) {
290
+            if ( ! $remove_relation) {
291 291
                 // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292 292
                 // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293 293
                 $existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
Please login to merge, or discard this patch.
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -12,303 +12,303 @@
 block discarded – undo
12 12
 {
13 13
 
14 14
 
15
-    /**
16
-     * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for
17
-     * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this
18
-     * value).  The _primary_cpt_field is what is equivalent to the post_id field on a cpt join.
19
-     *
20
-     * @var string
21
-     */
22
-    private $_primary_cpt_field;
23
-
24
-
25
-    /**
26
-     * This is what field serves as the "parent" column that is linked with whatever the main model's calling this
27
-     * relation has as a primary key.  In other words EEM_Event has 'Datetime' => new
28
-     * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent').  That means that in the EEM_Datetime model the
29
-     * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the
30
-     * primary key in the other model (EEM_Datetime).
31
-     *
32
-     * @var string
33
-     */
34
-    private $_parent_pk_relation_field;
35
-
36
-
37
-    /**
38
-     * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
39
-     * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
40
-     * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
41
-     * related models across the relation, and add-and-remove the relationships.
42
-     *
43
-     * @param string  $primary_cpt_field             See property description for details
44
-     * @param string  $parent_pk_relation_field      This is the field that is "connected" to the $primary_cpt_field.
45
-     *                                               See property desc for details.
46
-     * @param boolean $block_deletes                 For this type of relation, we block by default. If there are
47
-     *                                               related models across this relation, block (prevent and add an
48
-     *                                               error) the deletion of this model
49
-     * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
50
-     *                                               default
51
-     */
52
-    public function __construct(
53
-        $primary_cpt_field,
54
-        $parent_pk_relation_field,
55
-        $block_deletes = true,
56
-        $blocking_delete_error_message = null
57
-    ) {
58
-        $this->_primary_cpt_field        = $primary_cpt_field;
59
-        $this->_parent_pk_relation_field = $parent_pk_relation_field;
60
-        parent::__construct($block_deletes, $blocking_delete_error_message);
61
-    }
62
-
63
-
64
-    /**
65
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
66
-     * you like.
67
-     *
68
-     * @param EE_Base_Class|int $this_obj_or_id
69
-     * @param EE_Base_Class|int $other_obj_or_id
70
-     * @param array             $extra_join_model_fields_n_values
71
-     * @return \EE_Base_Class
72
-     * @throws \EE_Error
73
-     */
74
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
-    {
76
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
78
-
79
-        // handle possible revisions
80
-        $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj);
81
-
82
-        // if is array, then we've already done the add_relation so let's get out
83
-        if (is_array($other_model_obj)) {
84
-            return $other_model_obj[0];
85
-        }
86
-        // find the field on the other model which is a foreign key to this model
87
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
88
-        // set that field on the other model to this model's ID
89
-        $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
90
-        $other_model_obj->save();
91
-        return $other_model_obj;
92
-    }
93
-
94
-
95
-    /**
96
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object
97
-     *
98
-     * @param EE_Base_Class|int $this_obj_or_id
99
-     * @param EE_Base_Class|int $other_obj_or_id
100
-     * @param array             $where_query
101
-     * @return \EE_Base_Class
102
-     * @throws \EE_Error
103
-     */
104
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
105
-    {
106
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id);
107
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
108
-        // handle possible revisions
109
-        $other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true);
110
-
111
-
112
-        // if is array, then we've already done the add_relation so let's get out
113
-        if (is_array($other_model_obj)) {
114
-            return $other_model_obj[0];
115
-        }
116
-
117
-        // find the field on the other model which is a foreign key to this model
118
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
119
-
120
-
121
-        // set that field on the other model to this model's ID
122
-        if ($this->_blocking_delete) {
123
-            $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
124
-            $other_model_obj->save();
125
-        } else {
126
-            $other_model_obj->delete();
127
-            $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
128
-            return $other_model_obj;
129
-        }
130
-        return $other_model_obj;
131
-    }
132
-
133
-
134
-    /**
135
-     * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions
136
-     * in here.
137
-     *
138
-     * @param  EE_Base_Class|int $model_object_or_id
139
-     * @param  array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
140
-     * @param  boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
141
-     * @return EE_Base_Class[]
142
-     * @throws \EE_Error
143
-     */
144
-    public function get_all_related(
145
-        $model_object_or_id,
146
-        $query_params = array(),
147
-        $values_already_prepared_by_model_object = false
148
-    ) {
149
-        if ($values_already_prepared_by_model_object !== false) {
150
-            EE_Error::doing_it_wrong(
151
-                'EE_Model_Relation_Base::get_all_related',
152
-                __('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
153
-                '4.8.1'
154
-            );
155
-        }
156
-
157
-        // if this is an autosave then we're going to get things differently
158
-        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
159
-            return $this->_do_autosave_get_all($model_object_or_id, $query_params);
160
-        }
161
-
162
-        return parent::get_all_related($model_object_or_id, $query_params);
163
-    }
164
-
165
-
166
-    /**
167
-     * If we're in the midst of an autosave then we're going to do things a bit differently than the usual
168
-     * get_all_related (commenting within).  For description of params see the get_all_related() comments
169
-     *
170
-     * @access protected
171
-     * @param      $model_object_or_id
172
-     * @param      $query_params
173
-     * @param bool $deprecated
174
-     * @return \EE_Base_Class[]
175
-     * @throws \EE_Error
176
-     */
177
-    protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false)
178
-    {
179
-
180
-        // first we check if the post_id for the incoming query is for an autosave.  If it isn't that's what we want!
181
-        $model_object_id = $this->_get_model_object_id($model_object_or_id);
182
-
183
-        $autosave  = wp_get_post_autosave($model_object_id);
184
-        $id_to_use = $autosave ? $autosave->ID : $model_object_id;
185
-
186
-        $autosave_relations = parent::get_all_related($id_to_use, $query_params);
187
-        $parent_ids         = $parents = array();
188
-        $return_objs        = array();
189
-
190
-        // k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191
-        foreach ($autosave_relations as $a_r) {
192
-            $pid = $a_r->parent();
193
-            if (! empty($pid)) {
194
-                $parent_ids[] = $pid;
195
-            } else {
196
-                $return_objs[] = $a_r;
197
-            }
198
-        }
199
-
200
-        // we have to make sure we also include the ORIGINAL values
201
-        $originals = parent::get_all_related($model_object_or_id, $query_params);
202
-
203
-        // merge $originals with $return_objs
204
-        if ($originals) {
205
-            $return_objs = array_merge($originals, $return_objs);
206
-        }
207
-
208
-        // now we setup the query to get all the parents
209
-        if (! empty($parent_ids)) {
210
-            $query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
-            $query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
212
-            $parents                                          = $this->get_other_model()->get_all($query_params);
213
-        }
214
-
215
-        // var_dump($parents);
216
-
217
-
218
-        // now merge parents with our current $return_objs and send back
219
-        return array_merge($parents, $return_objs);
220
-    }
221
-
222
-
223
-    /**
224
-     * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it
225
-     * is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS
226
-     * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is
227
-     * sometime delayed if the object is created/saved first by the autosave)
228
-     *
229
-     * @param  EE_Base_Class $this_obj
230
-     * @param  EE_Base_Class $other_obj
231
-     * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
232
-     * @return EE_Base_Class. ($other_obj);
233
-     * @throws \EE_Error
234
-     */
235
-    protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false)
236
-    {
237
-        $pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
238
-        // now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
239
-        if ($this_obj->post_type() === 'revision') {
240
-            // first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
241
-            $parent_evt_id = $this_obj->parent();
242
-            /*var_dump($parent_evt_id);
15
+	/**
16
+	 * The Foreign key on the model that acts as the PRIMARY KEY used in special autosave handling where we query for
17
+	 * autosaves (or the Foreign key on other models in relations pointing to this models primary key which is this
18
+	 * value).  The _primary_cpt_field is what is equivalent to the post_id field on a cpt join.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	private $_primary_cpt_field;
23
+
24
+
25
+	/**
26
+	 * This is what field serves as the "parent" column that is linked with whatever the main model's calling this
27
+	 * relation has as a primary key.  In other words EEM_Event has 'Datetime' => new
28
+	 * EE_Has_Many_Revision_Relation('EVT_ID', 'DTT_parent').  That means that in the EEM_Datetime model the
29
+	 * 'DTT_Parent' field is related to the 'DTT_ID' primary key field (in the same model) because 'DTT_ID' is the
30
+	 * primary key in the other model (EEM_Datetime).
31
+	 *
32
+	 * @var string
33
+	 */
34
+	private $_parent_pk_relation_field;
35
+
36
+
37
+	/**
38
+	 * Object representing the relationship between two models. Has_Many_Relations are where the OTHER model has the
39
+	 * foreign key this model. IE, there can be many other model objects related to one of this model's objects (but
40
+	 * NOT through a JOIN table, which is the case for EE_HABTM_Relations). This knows how to join the models, get
41
+	 * related models across the relation, and add-and-remove the relationships.
42
+	 *
43
+	 * @param string  $primary_cpt_field             See property description for details
44
+	 * @param string  $parent_pk_relation_field      This is the field that is "connected" to the $primary_cpt_field.
45
+	 *                                               See property desc for details.
46
+	 * @param boolean $block_deletes                 For this type of relation, we block by default. If there are
47
+	 *                                               related models across this relation, block (prevent and add an
48
+	 *                                               error) the deletion of this model
49
+	 * @param string  $blocking_delete_error_message a customized error message on blocking deletes instead of the
50
+	 *                                               default
51
+	 */
52
+	public function __construct(
53
+		$primary_cpt_field,
54
+		$parent_pk_relation_field,
55
+		$block_deletes = true,
56
+		$blocking_delete_error_message = null
57
+	) {
58
+		$this->_primary_cpt_field        = $primary_cpt_field;
59
+		$this->_parent_pk_relation_field = $parent_pk_relation_field;
60
+		parent::__construct($block_deletes, $blocking_delete_error_message);
61
+	}
62
+
63
+
64
+	/**
65
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
66
+	 * you like.
67
+	 *
68
+	 * @param EE_Base_Class|int $this_obj_or_id
69
+	 * @param EE_Base_Class|int $other_obj_or_id
70
+	 * @param array             $extra_join_model_fields_n_values
71
+	 * @return \EE_Base_Class
72
+	 * @throws \EE_Error
73
+	 */
74
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
75
+	{
76
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
77
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
78
+
79
+		// handle possible revisions
80
+		$other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj);
81
+
82
+		// if is array, then we've already done the add_relation so let's get out
83
+		if (is_array($other_model_obj)) {
84
+			return $other_model_obj[0];
85
+		}
86
+		// find the field on the other model which is a foreign key to this model
87
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
88
+		// set that field on the other model to this model's ID
89
+		$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
90
+		$other_model_obj->save();
91
+		return $other_model_obj;
92
+	}
93
+
94
+
95
+	/**
96
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object
97
+	 *
98
+	 * @param EE_Base_Class|int $this_obj_or_id
99
+	 * @param EE_Base_Class|int $other_obj_or_id
100
+	 * @param array             $where_query
101
+	 * @return \EE_Base_Class
102
+	 * @throws \EE_Error
103
+	 */
104
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
105
+	{
106
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id);
107
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id);
108
+		// handle possible revisions
109
+		$other_model_obj = $this->_check_for_revision($this_model_obj, $other_model_obj, true);
110
+
111
+
112
+		// if is array, then we've already done the add_relation so let's get out
113
+		if (is_array($other_model_obj)) {
114
+			return $other_model_obj[0];
115
+		}
116
+
117
+		// find the field on the other model which is a foreign key to this model
118
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
119
+
120
+
121
+		// set that field on the other model to this model's ID
122
+		if ($this->_blocking_delete) {
123
+			$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
124
+			$other_model_obj->save();
125
+		} else {
126
+			$other_model_obj->delete();
127
+			$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
128
+			return $other_model_obj;
129
+		}
130
+		return $other_model_obj;
131
+	}
132
+
133
+
134
+	/**
135
+	 * This is identical to EE_Model_Relation->get_all_related() except we're going handle special autosave conditions
136
+	 * in here.
137
+	 *
138
+	 * @param  EE_Base_Class|int $model_object_or_id
139
+	 * @param  array             $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
140
+	 * @param  boolean           $values_already_prepared_by_model_object @deprecated since 4.8.1
141
+	 * @return EE_Base_Class[]
142
+	 * @throws \EE_Error
143
+	 */
144
+	public function get_all_related(
145
+		$model_object_or_id,
146
+		$query_params = array(),
147
+		$values_already_prepared_by_model_object = false
148
+	) {
149
+		if ($values_already_prepared_by_model_object !== false) {
150
+			EE_Error::doing_it_wrong(
151
+				'EE_Model_Relation_Base::get_all_related',
152
+				__('The argument $values_already_prepared_by_model_object is no longer used.', 'event_espresso'),
153
+				'4.8.1'
154
+			);
155
+		}
156
+
157
+		// if this is an autosave then we're going to get things differently
158
+		if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
159
+			return $this->_do_autosave_get_all($model_object_or_id, $query_params);
160
+		}
161
+
162
+		return parent::get_all_related($model_object_or_id, $query_params);
163
+	}
164
+
165
+
166
+	/**
167
+	 * If we're in the midst of an autosave then we're going to do things a bit differently than the usual
168
+	 * get_all_related (commenting within).  For description of params see the get_all_related() comments
169
+	 *
170
+	 * @access protected
171
+	 * @param      $model_object_or_id
172
+	 * @param      $query_params
173
+	 * @param bool $deprecated
174
+	 * @return \EE_Base_Class[]
175
+	 * @throws \EE_Error
176
+	 */
177
+	protected function _do_autosave_get_all($model_object_or_id, $query_params, $deprecated = false)
178
+	{
179
+
180
+		// first we check if the post_id for the incoming query is for an autosave.  If it isn't that's what we want!
181
+		$model_object_id = $this->_get_model_object_id($model_object_or_id);
182
+
183
+		$autosave  = wp_get_post_autosave($model_object_id);
184
+		$id_to_use = $autosave ? $autosave->ID : $model_object_id;
185
+
186
+		$autosave_relations = parent::get_all_related($id_to_use, $query_params);
187
+		$parent_ids         = $parents = array();
188
+		$return_objs        = array();
189
+
190
+		// k this is where things differ because NOW what we're going to do is get the PARENTS for the get all related (and we'll also start setting up the return_objs array containing related that DON'T have parent ids, for those that DON'T have parents to merge with our returned objects);
191
+		foreach ($autosave_relations as $a_r) {
192
+			$pid = $a_r->parent();
193
+			if (! empty($pid)) {
194
+				$parent_ids[] = $pid;
195
+			} else {
196
+				$return_objs[] = $a_r;
197
+			}
198
+		}
199
+
200
+		// we have to make sure we also include the ORIGINAL values
201
+		$originals = parent::get_all_related($model_object_or_id, $query_params);
202
+
203
+		// merge $originals with $return_objs
204
+		if ($originals) {
205
+			$return_objs = array_merge($originals, $return_objs);
206
+		}
207
+
208
+		// now we setup the query to get all the parents
209
+		if (! empty($parent_ids)) {
210
+			$query_param_where_this_model_pk                  = $this->get_this_model()->get_this_model_name() . "." . $this->get_this_model()->get_primary_key_field()->get_name();
211
+			$query_param[0][ $query_param_where_this_model_pk ] = array('IN', $parent_ids);
212
+			$parents                                          = $this->get_other_model()->get_all($query_params);
213
+		}
214
+
215
+		// var_dump($parents);
216
+
217
+
218
+		// now merge parents with our current $return_objs and send back
219
+		return array_merge($parents, $return_objs);
220
+	}
221
+
222
+
223
+	/**
224
+	 * Basically this method gets called to verify if the incoming object needs to be manipulated somewhat because it
225
+	 * is a revision save.  If so, then we change things before sending back.  We also do verifications when this IS
226
+	 * NOT an revision because we always need to make sure that the autosave/revision has parent recorded (which is
227
+	 * sometime delayed if the object is created/saved first by the autosave)
228
+	 *
229
+	 * @param  EE_Base_Class $this_obj
230
+	 * @param  EE_Base_Class $other_obj
231
+	 * @param  boolean       $remove_relation Indicates whether we're doing a remove_relation or add_relation.
232
+	 * @return EE_Base_Class. ($other_obj);
233
+	 * @throws \EE_Error
234
+	 */
235
+	protected function _check_for_revision($this_obj, $other_obj, $remove_relation = false)
236
+	{
237
+		$pk_on_related_model = $this->get_other_model()->get_primary_key_field()->get_name();
238
+		// now we need to determine if we're in a WP revision save cause if we are we need to do some special handling
239
+		if ($this_obj->post_type() === 'revision') {
240
+			// first if $other_obj fk = this_obj pk then we know that this is a pk object, let's make sure there is a matching set for the autosave if there is then we save over it, if there isn't then we need to create a new one.
241
+			$parent_evt_id = $this_obj->parent();
242
+			/*var_dump($parent_evt_id);
243 243
             var_dump($this_obj);
244 244
             var_dump($other_obj);/**/
245 245
 
246
-            if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247
-                // let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248
-                $has_parent_obj = $this->get_other_model()->get_one(array(
249
-                    array(
250
-                        $this->_parent_pk_relation_field => $other_obj->ID(),
251
-                        $this->_primary_cpt_field        => $this_obj->ID(),
252
-                    ),
253
-                ));
254
-
255
-                if ($has_parent_obj) {
256
-                    // this makes sure the update on the current obj happens to the revision's row NOT the parent row.
257
-
258
-                    $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
259
-                    $other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261
-
262
-                    if (! $remove_relation) {
263
-                        $other_obj->save();
264
-                        return array($other_obj);
265
-                    } elseif ($remove_relation && ! $this->_blocking_delete) {
266
-                        $other_obj->delete();
267
-                        $other_obj->set($this->_parent_pk_relation_field, null, true);
268
-                        return array($other_obj);
269
-                    }
270
-                } else {
271
-                    $other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
272
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
273
-                    $other_obj->set(
274
-                        $pk_on_related_model,
275
-                        null,
276
-                        true
277
-                    ); // ensure we create a new row for the autosave with parent id the same as the incoming ID.
278
-                    $other_obj->save(); // make sure we insert.
279
-                    return array($other_obj);
280
-                }
281
-            }
282
-
283
-            // var_dump('what makes it here');
284
-            // var_dump($other_obj);
285
-            // the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
286
-
287
-            // the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288
-        } else {
289
-            // we only need to do the below IF this is not a remove relation
290
-            if (! $remove_relation) {
291
-                // okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292
-                // the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293
-                $existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
294
-                $potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null;
295
-
296
-                if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
297
-                    // yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
298
-                    $other_obj->set($this->_primary_cpt_field, $this_obj->ID());
299
-                    $other_obj->save();
300
-
301
-                    // now create a new other_obj and fill with details from existing object
302
-                    $new_obj = $other_obj;
303
-                    $new_obj->set($this->_primary_cpt_field, $potential_revision_id);
304
-                    $new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
305
-                    $new_obj->set($pk_on_related_model, null);
306
-                    $new_obj->save();
307
-                    return array($new_obj);
308
-                }
309
-            }
310
-        }
311
-
312
-        return $other_obj;
313
-    }
246
+			if (! empty($parent_evt_id) && $parent_evt_id == $other_obj->get($this->_primary_cpt_field)) {
247
+				// let's do query on this objects model to see if the incoming pk value on the obj matches any parents in this objects table.
248
+				$has_parent_obj = $this->get_other_model()->get_one(array(
249
+					array(
250
+						$this->_parent_pk_relation_field => $other_obj->ID(),
251
+						$this->_primary_cpt_field        => $this_obj->ID(),
252
+					),
253
+				));
254
+
255
+				if ($has_parent_obj) {
256
+					// this makes sure the update on the current obj happens to the revision's row NOT the parent row.
257
+
258
+					$other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
259
+					$other_obj->set($pk_on_related_model, $has_parent_obj->ID());
260
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
261
+
262
+					if (! $remove_relation) {
263
+						$other_obj->save();
264
+						return array($other_obj);
265
+					} elseif ($remove_relation && ! $this->_blocking_delete) {
266
+						$other_obj->delete();
267
+						$other_obj->set($this->_parent_pk_relation_field, null, true);
268
+						return array($other_obj);
269
+					}
270
+				} else {
271
+					$other_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
272
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
273
+					$other_obj->set(
274
+						$pk_on_related_model,
275
+						null,
276
+						true
277
+					); // ensure we create a new row for the autosave with parent id the same as the incoming ID.
278
+					$other_obj->save(); // make sure we insert.
279
+					return array($other_obj);
280
+				}
281
+			}
282
+
283
+			// var_dump('what makes it here');
284
+			// var_dump($other_obj);
285
+			// the next possible condition is that the incoming other_model obj has a NULL pk which means it just gets saved (which in turn creates it)
286
+
287
+			// the last possible condition on a revision is that the incoming other_model object has a fk that == $this_obj pk which means we just return the $other obj and let it save as normal so we see the return at the bottom of this method.
288
+		} else {
289
+			// we only need to do the below IF this is not a remove relation
290
+			if (! $remove_relation) {
291
+				// okay this is is a normal update/save/remove so, let's make sure the other object is not a revision of the current object.
292
+				// the other object will likely NOT have the correct fk on it (which is the primary_cpt_field_mame) so we must retrieve from the db to get that first.
293
+				$existing_other_obj    = $this->get_other_model()->get_one_by_ID($other_obj->ID());
294
+				$potential_revision_id = is_object($existing_other_obj) ? $existing_other_obj->get($this->_primary_cpt_field) : null;
295
+
296
+				if ($parent_this_obj_id = wp_is_post_revision($potential_revision_id)) {
297
+					// yes the OTHER object is linked to the revision of the parent, not the parent itself. That means we need to make the other_object an attachment of this_obj and then duplicate other_obj for the revision.
298
+					$other_obj->set($this->_primary_cpt_field, $this_obj->ID());
299
+					$other_obj->save();
300
+
301
+					// now create a new other_obj and fill with details from existing object
302
+					$new_obj = $other_obj;
303
+					$new_obj->set($this->_primary_cpt_field, $potential_revision_id);
304
+					$new_obj->set($this->_parent_pk_relation_field, $other_obj->ID());
305
+					$new_obj->set($pk_on_related_model, null);
306
+					$new_obj->save();
307
+					return array($new_obj);
308
+				}
309
+			}
310
+		}
311
+
312
+		return $other_obj;
313
+	}
314 314
 }
Please login to merge, or discard this patch.
core/db_models/relations/EE_Has_Many_Any_Relation.php 2 patches
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -15,94 +15,94 @@
 block discarded – undo
15 15
 class EE_Has_Many_Any_Relation extends EE_Has_Many_Relation
16 16
 {
17 17
 
18
-    /**
19
-     * Gets the SQL string for performing the join between this model and the other model.
20
-     *
21
-     * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
22
-     * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
23
-     *                other_model_primary_table.fk" etc
24
-     * @throws \EE_Error
25
-     */
26
-    public function get_join_statement($model_relation_chain)
27
-    {
28
-        // create the sql string like
29
-        // LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
30
-        $this_table_pk_field   = $this->get_this_model()->get_primary_key_field();
31
-        $other_table_fk_field  = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
32
-        $pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33
-            $model_relation_chain,
34
-            $this->get_this_model()->get_this_model_name()
35
-        ) . $this_table_pk_field->get_table_alias();
36
-        $fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37
-            $model_relation_chain,
38
-            $this->get_other_model()->get_this_model_name()
39
-        ) . $other_table_fk_field->get_table_alias();
40
-        $fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41
-        $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
18
+	/**
19
+	 * Gets the SQL string for performing the join between this model and the other model.
20
+	 *
21
+	 * @param string $model_relation_chain like 'Event.Event_Venue.Venue'
22
+	 * @return string of SQL, eg "LEFT JOIN table_name AS table_alias ON this_model_primary_table.pk =
23
+	 *                other_model_primary_table.fk" etc
24
+	 * @throws \EE_Error
25
+	 */
26
+	public function get_join_statement($model_relation_chain)
27
+	{
28
+		// create the sql string like
29
+		// LEFT JOIN other_table AS table_alias ON this_table_alias.pk = other_table_alias.fk extra_join_conditions
30
+		$this_table_pk_field   = $this->get_this_model()->get_primary_key_field();
31
+		$other_table_fk_field  = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
32
+		$pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33
+			$model_relation_chain,
34
+			$this->get_this_model()->get_this_model_name()
35
+		) . $this_table_pk_field->get_table_alias();
36
+		$fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37
+			$model_relation_chain,
38
+			$this->get_other_model()->get_this_model_name()
39
+		) . $other_table_fk_field->get_table_alias();
40
+		$fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41
+		$field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
42 42
 
43
-        return $this->_left_join(
44
-            $fk_table,
45
-            $fk_table_alias,
46
-            $other_table_fk_field->get_table_column(),
47
-            $pk_table_alias,
48
-            $this_table_pk_field->get_table_column(),
49
-            $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
50
-        )
51
-               . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52
-    }
43
+		return $this->_left_join(
44
+			$fk_table,
45
+			$fk_table_alias,
46
+			$other_table_fk_field->get_table_column(),
47
+			$pk_table_alias,
48
+			$this_table_pk_field->get_table_column(),
49
+			$fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
50
+		)
51
+			   . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
57
-     * you like.
58
-     *
59
-     * @param EE_Base_Class|int $this_obj_or_id
60
-     * @param EE_Base_Class|int $other_obj_or_id
61
-     * @param array             $extra_join_model_fields_n_values
62
-     * @return \EE_Base_Class
63
-     * @throws \EE_Error
64
-     */
65
-    public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
66
-    {
67
-        $this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
68
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
55
+	/**
56
+	 * Sets the other model object's foreign key to this model object's primary key. Feel free to do this manually if
57
+	 * you like.
58
+	 *
59
+	 * @param EE_Base_Class|int $this_obj_or_id
60
+	 * @param EE_Base_Class|int $other_obj_or_id
61
+	 * @param array             $extra_join_model_fields_n_values
62
+	 * @return \EE_Base_Class
63
+	 * @throws \EE_Error
64
+	 */
65
+	public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array())
66
+	{
67
+		$this_model_obj  = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true);
68
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
69 69
 
70
-        // find the field on the other model which is a foreign key to this model
71
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
72
-        // set that field on the other model to this model's ID
73
-        $other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
74
-        $other_model_obj->set(
75
-            $this->get_other_model()->get_field_containing_related_model_name()->get_name(),
76
-            $this->get_this_model()->get_this_model_name()
77
-        );
78
-        $other_model_obj->save();
79
-        return $other_model_obj;
80
-    }
70
+		// find the field on the other model which is a foreign key to this model
71
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
72
+		// set that field on the other model to this model's ID
73
+		$other_model_obj->set($fk_field_on_other_model->get_name(), $this_model_obj->ID());
74
+		$other_model_obj->set(
75
+			$this->get_other_model()->get_field_containing_related_model_name()->get_name(),
76
+			$this->get_this_model()->get_this_model_name()
77
+		);
78
+		$other_model_obj->save();
79
+		return $other_model_obj;
80
+	}
81 81
 
82 82
 
83
-    /**
84
-     * Sets the other model object's foreign key to its default, instead of pointing to this model object.
85
-     * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
86
-     *
87
-     * @param EE_Base_Class|int $this_obj_or_id
88
-     * @param EE_Base_Class|int $other_obj_or_id
89
-     * @param array             $where_query
90
-     * @return \EE_Base_Class
91
-     * @throws \EE_Error
92
-     */
93
-    public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
-    {
95
-        $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
96
-        // find the field on the other model which is a foreign key to this model
97
-        $fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
98
-        // set that field on the other model to this model's ID
99
-        $other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
100
-        $other_model_obj->set(
101
-            $this->get_other_model()->get_field_containing_related_model_name()->get_name(),
102
-            null,
103
-            true
104
-        );
105
-        $other_model_obj->save();
106
-        return $other_model_obj;
107
-    }
83
+	/**
84
+	 * Sets the other model object's foreign key to its default, instead of pointing to this model object.
85
+	 * If $other_obj_or_id doesn't have any other relations, this function is essentially orphaning it
86
+	 *
87
+	 * @param EE_Base_Class|int $this_obj_or_id
88
+	 * @param EE_Base_Class|int $other_obj_or_id
89
+	 * @param array             $where_query
90
+	 * @return \EE_Base_Class
91
+	 * @throws \EE_Error
92
+	 */
93
+	public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array())
94
+	{
95
+		$other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true);
96
+		// find the field on the other model which is a foreign key to this model
97
+		$fk_field_on_other_model = $this->get_other_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name());
98
+		// set that field on the other model to this model's ID
99
+		$other_model_obj->set($fk_field_on_other_model->get_name(), null, true);
100
+		$other_model_obj->set(
101
+			$this->get_other_model()->get_field_containing_related_model_name()->get_name(),
102
+			null,
103
+			true
104
+		);
105
+		$other_model_obj->save();
106
+		return $other_model_obj;
107
+	}
108 108
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,11 +32,11 @@  discard block
 block discarded – undo
32 32
         $pk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
33 33
             $model_relation_chain,
34 34
             $this->get_this_model()->get_this_model_name()
35
-        ) . $this_table_pk_field->get_table_alias();
36
-        $fk_table_alias        = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
35
+        ).$this_table_pk_field->get_table_alias();
36
+        $fk_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix(
37 37
             $model_relation_chain,
38 38
             $this->get_other_model()->get_this_model_name()
39
-        ) . $other_table_fk_field->get_table_alias();
39
+        ).$other_table_fk_field->get_table_alias();
40 40
         $fk_table              = $this->get_other_model()->get_table_for_alias($fk_table_alias);
41 41
         $field_with_model_name = $this->get_other_model()->get_field_containing_related_model_name();
42 42
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             $other_table_fk_field->get_table_column(),
47 47
             $pk_table_alias,
48 48
             $this_table_pk_field->get_table_column(),
49
-            $fk_table_alias . '.' . $field_with_model_name->get_table_column() . "='" . $this->get_this_model()->get_this_model_name() . "'"
49
+            $fk_table_alias.'.'.$field_with_model_name->get_table_column()."='".$this->get_this_model()->get_this_model_name()."'"
50 50
         )
51 51
                . $this->get_other_model()->_construct_internal_join_to_table_with_alias($fk_table_alias);
52 52
     }
Please login to merge, or discard this patch.
core/db_models/EEM_Status.model.php 2 patches
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -11,292 +11,292 @@
 block discarded – undo
11 11
 class EEM_Status extends EEM_Base
12 12
 {
13 13
 
14
-    // private instance of the Attendee object
15
-    protected static $_instance = null;
14
+	// private instance of the Attendee object
15
+	protected static $_instance = null;
16 16
 
17 17
 
18
-    /**
19
-     * @return EEM_Status
20
-     */
21
-    protected function __construct($timezone = null)
22
-    {
23
-        $this->singular_item    = __('Status', 'event_espresso');
24
-        $this->plural_item      = __('Stati', 'event_espresso');
25
-        $this->_tables          = array(
26
-            'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
27
-        );
28
-        $this->_fields          = array(
29
-            'StatusTable' => array(
30
-                'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
31
-                'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
32
-                'STS_type'     => new EE_Enum_Text_Field(
33
-                    'STS_type',
34
-                    __("Type", "event_espresso"),
35
-                    false,
36
-                    'event',
37
-                    array(
38
-                        'event'        => __("Event", "event_espresso"),// deprecated
39
-                        'registration' => __("Registration", "event_espresso"),
40
-                        'transaction'  => __("Transaction", "event_espresso"),
41
-                        'payment'      => __("Payment", "event_espresso"),
42
-                        'email'        => __("Email", "event_espresso"),
43
-                        'message'      => __("Message", "event_espresso"),
44
-                    )
45
-                ),
46
-                'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false, false),
47
-                'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
48
-                'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
49
-            ),
50
-        );
51
-        $this->_model_relations = array(
52
-            'Registration' => new EE_Has_Many_Relation(),
53
-            'Transaction'  => new EE_Has_Many_Relation(),
54
-            'Payment'      => new EE_Has_Many_Relation(),
55
-        );
56
-        // this model is generally available for reading
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
18
+	/**
19
+	 * @return EEM_Status
20
+	 */
21
+	protected function __construct($timezone = null)
22
+	{
23
+		$this->singular_item    = __('Status', 'event_espresso');
24
+		$this->plural_item      = __('Stati', 'event_espresso');
25
+		$this->_tables          = array(
26
+			'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
27
+		);
28
+		$this->_fields          = array(
29
+			'StatusTable' => array(
30
+				'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
31
+				'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
32
+				'STS_type'     => new EE_Enum_Text_Field(
33
+					'STS_type',
34
+					__("Type", "event_espresso"),
35
+					false,
36
+					'event',
37
+					array(
38
+						'event'        => __("Event", "event_espresso"),// deprecated
39
+						'registration' => __("Registration", "event_espresso"),
40
+						'transaction'  => __("Transaction", "event_espresso"),
41
+						'payment'      => __("Payment", "event_espresso"),
42
+						'email'        => __("Email", "event_espresso"),
43
+						'message'      => __("Message", "event_espresso"),
44
+					)
45
+				),
46
+				'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false, false),
47
+				'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
48
+				'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
49
+			),
50
+		);
51
+		$this->_model_relations = array(
52
+			'Registration' => new EE_Has_Many_Relation(),
53
+			'Transaction'  => new EE_Has_Many_Relation(),
54
+			'Payment'      => new EE_Has_Many_Relation(),
55
+		);
56
+		// this model is generally available for reading
57
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
58 58
 
59
-        parent::__construct($timezone);
60
-    }
59
+		parent::__construct($timezone);
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * This method provides the localized singular or plural string for a given status id
65
-     *
66
-     * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
67
-     *                           That way if there isn't a translation in the index we'll return the default code.
68
-     * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
69
-     *                           same as the singular (in English), however, this may NOT be the case with other
70
-     *                           languages
71
-     * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
72
-     *                           the status string returned ( UPPER, lower, Sentence)
73
-     * @throws EE_Error
74
-     * @return array             an array of translated strings for the incoming status id.
75
-     */
76
-    public function localized_status($statuses, $plural = false, $schema = 'upper')
77
-    {
78
-        // note these are all in lower case because ucwords() on upper case will NOT convert.
79
-        $translation_array = array(
80
-            EEM_Registration::status_id_pending_payment => array(
81
-                __('pending payment', 'event_espresso'), // singular
82
-                __('pending payments', 'event_espresso') // plural
83
-            ),
84
-            EEM_Registration::status_id_approved        => array(
85
-                __('approved', 'event_espresso'), // singular
86
-                __('approved', 'event_espresso') // plural
87
-            ),
88
-            EEM_Registration::status_id_not_approved    => array(
89
-                __('not approved', 'event_espresso'),
90
-                __('not approved', 'event_espresso'),
91
-            ),
92
-            EEM_Registration::status_id_cancelled       => array(
93
-                __('cancelled', 'event_espresso'),
94
-                __('cancelled', 'event_espresso'),
95
-            ),
96
-            EEM_Registration::status_id_incomplete      => array(
97
-                __('incomplete', 'event_espresso'),
98
-                __('incomplete', 'event_espresso'),
99
-            ),
100
-            EEM_Registration::status_id_declined        => array(
101
-                __('declined', 'event_espresso'),
102
-                __('declined', 'event_espresso'),
103
-            ),
104
-            EEM_Registration::status_id_wait_list       => array(
105
-                __('wait list', 'event_espresso'),
106
-                __('wait list', 'event_espresso'),
107
-            ),
108
-            EEM_Transaction::overpaid_status_code       => array(
109
-                __('overpaid', 'event_espresso'),
110
-                __('overpaid', 'event_espresso'),
111
-            ),
112
-            EEM_Transaction::complete_status_code       => array(
113
-                __('complete', 'event_espresso'),
114
-                __('complete', 'event_espresso'),
115
-            ),
116
-            EEM_Transaction::incomplete_status_code     => array(
117
-                __('incomplete', 'event_espresso'),
118
-                __('incomplete', 'event_espresso'),
119
-            ),
120
-            EEM_Transaction::failed_status_code         => array(
121
-                __('failed', 'event_espresso'),
122
-                __('failed', 'event_espresso'),
123
-            ),
124
-            EEM_Transaction::abandoned_status_code      => array(
125
-                __('abandoned', 'event_espresso'),
126
-                __('abandoned', 'event_espresso'),
127
-            ),
128
-            EEM_Payment::status_id_approved             => array(
129
-                __('accepted', 'event_espresso'),
130
-                __('accepted', 'event_espresso'),
131
-            ),
132
-            EEM_Payment::status_id_pending              => array(
133
-                __('pending', 'event_espresso'),
134
-                __('pending', 'event_espresso'),
135
-            ),
136
-            EEM_Payment::status_id_cancelled            => array(
137
-                __('cancelled', 'event_espresso'),
138
-                __('cancelled', 'event_espresso'),
139
-            ),
140
-            EEM_Payment::status_id_declined             => array(
141
-                __('declined', 'event_espresso'),
142
-                __('declined', 'event_espresso'),
143
-            ),
144
-            EEM_Payment::status_id_failed               => array(
145
-                __('failed', 'event_espresso'),
146
-                __('failed', 'event_espresso'),
147
-            ),
148
-            // following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
149
-            EEM_Event::sold_out                         => array(
150
-                __('sold out', 'event_espresso'),
151
-                __('sold out', 'event_espresso'),
152
-            ),
153
-            EEM_Event::postponed                        => array(
154
-                __('postponed', 'event_espresso'),
155
-                __('Postponed', 'event_espresso'),
156
-            ),
157
-            EEM_Event::cancelled                        => array(
158
-                __('cancelled', 'event_espresso'),
159
-                __('cancelled', 'event_espresso'),
160
-            ),
161
-            EE_Ticket::archived                         => array(
162
-                __('archived', 'event_espresso'),
163
-                __('archived', 'event_espresso'),
164
-            ),
165
-            EE_Ticket::expired                          => array(
166
-                __('expired', 'event_espresso'),
167
-                __('expired', 'event_espresso'),
168
-            ),
169
-            EE_Ticket::sold_out                         => array(
170
-                __('sold out', 'event_espresso'),
171
-                __('sold out', 'event_espresso'),
172
-            ),
173
-            EE_Ticket::pending                          => array(
174
-                __('upcoming', 'event_espresso'),
175
-                __('upcoming', 'event_espresso'),
176
-            ),
177
-            EE_Ticket::onsale                           => array(
178
-                __('on sale', 'event_espresso'),
179
-                __('on sale', 'event_espresso'),
180
-            ),
181
-            EE_Datetime::cancelled                      => array(
182
-                __('cancelled', 'event_espresso'),
183
-                __('cancelled', 'event_espresso'),
184
-            ),
185
-            EE_Datetime::sold_out                       => array(
186
-                __('sold out', 'event_espresso'),
187
-                __('sold out', 'event_espresso'),
188
-            ),
189
-            EE_Datetime::expired                        => array(
190
-                __('expired', 'event_espresso'),
191
-                __('expired', 'event_espresso'),
192
-            ),
193
-            EE_Datetime::inactive                       => array(
194
-                __('inactive', 'event_espresso'),
195
-                __('inactive', 'event_espresso'),
196
-            ),
197
-            EE_Datetime::upcoming                       => array(
198
-                __('upcoming', 'event_espresso'),
199
-                __('upcoming', 'event_espresso'),
200
-            ),
201
-            EE_Datetime::active                         => array(
202
-                __('active', 'event_espresso'),
203
-                __('active', 'event_espresso'),
204
-            ),
205
-            EE_Datetime::postponed                      => array(
206
-                __('postponed', 'event_espresso'),
207
-                __('postponed', 'event_espresso'),
208
-            ),
209
-            // messages related
210
-            EEM_Message::status_sent                    => array(
211
-                __('sent', 'event_espresso'),
212
-                __('sent', 'event_espresso'),
213
-            ),
214
-            EEM_Message::status_idle                    => array(
215
-                __('queued for sending', 'event_espresso'),
216
-                __('queued for sending', 'event_espresso'),
217
-            ),
218
-            EEM_Message::status_failed                  => array(
219
-                __('failed', 'event_espresso'),
220
-                __('failed', 'event_espresso'),
221
-            ),
222
-            EEM_Message::status_debug_only              => array(
223
-                __('debug only', 'event_espresso'),
224
-                __('debug only', 'event_espresso'),
225
-            ),
226
-            EEM_Message::status_messenger_executing     => array(
227
-                __('messenger is executing', 'event_espresso'),
228
-                __('messenger is executing', 'event_espresso'),
229
-            ),
230
-            EEM_Message::status_resend                  => array(
231
-                __('queued for resending', 'event_espresso'),
232
-                __('queued for resending', 'event_espresso'),
233
-            ),
234
-            EEM_Message::status_incomplete              => array(
235
-                __('queued for generating', 'event_espresso'),
236
-                __('queued for generating', 'event_espresso'),
237
-            ),
238
-            EEM_Message::status_retry                   => array(
239
-                __('failed sending, can be retried', 'event_espresso'),
240
-                __('failed sending, can be retried', 'event_espresso'),
241
-            ),
242
-            EEM_CPT_Base::post_status_publish           => array(
243
-                __('published', 'event_espresso'),
244
-                __('published', 'event_espresso'),
245
-            ),
246
-            EEM_CPT_Base::post_status_future            => array(
247
-                __('scheduled', 'event_espresso'),
248
-                __('scheduled', 'event_espresso'),
249
-            ),
250
-            EEM_CPT_Base::post_status_draft             => array(
251
-                __('draft', 'event_espresso'),
252
-                __('draft', 'event_espresso'),
253
-            ),
254
-            EEM_CPT_Base::post_status_pending           => array(
255
-                __('pending', 'event_espresso'),
256
-                __('pending', 'event_espresso'),
257
-            ),
258
-            EEM_CPT_Base::post_status_private           => array(
259
-                __('private', 'event_espresso'),
260
-                __('private', 'event_espresso'),
261
-            ),
262
-            EEM_CPT_Base::post_status_trashed           => array(
263
-                __('trashed', 'event_espresso'),
264
-                __('trashed', 'event_espresso'),
265
-            ),
266
-        );
63
+	/**
64
+	 * This method provides the localized singular or plural string for a given status id
65
+	 *
66
+	 * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
67
+	 *                           That way if there isn't a translation in the index we'll return the default code.
68
+	 * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
69
+	 *                           same as the singular (in English), however, this may NOT be the case with other
70
+	 *                           languages
71
+	 * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
72
+	 *                           the status string returned ( UPPER, lower, Sentence)
73
+	 * @throws EE_Error
74
+	 * @return array             an array of translated strings for the incoming status id.
75
+	 */
76
+	public function localized_status($statuses, $plural = false, $schema = 'upper')
77
+	{
78
+		// note these are all in lower case because ucwords() on upper case will NOT convert.
79
+		$translation_array = array(
80
+			EEM_Registration::status_id_pending_payment => array(
81
+				__('pending payment', 'event_espresso'), // singular
82
+				__('pending payments', 'event_espresso') // plural
83
+			),
84
+			EEM_Registration::status_id_approved        => array(
85
+				__('approved', 'event_espresso'), // singular
86
+				__('approved', 'event_espresso') // plural
87
+			),
88
+			EEM_Registration::status_id_not_approved    => array(
89
+				__('not approved', 'event_espresso'),
90
+				__('not approved', 'event_espresso'),
91
+			),
92
+			EEM_Registration::status_id_cancelled       => array(
93
+				__('cancelled', 'event_espresso'),
94
+				__('cancelled', 'event_espresso'),
95
+			),
96
+			EEM_Registration::status_id_incomplete      => array(
97
+				__('incomplete', 'event_espresso'),
98
+				__('incomplete', 'event_espresso'),
99
+			),
100
+			EEM_Registration::status_id_declined        => array(
101
+				__('declined', 'event_espresso'),
102
+				__('declined', 'event_espresso'),
103
+			),
104
+			EEM_Registration::status_id_wait_list       => array(
105
+				__('wait list', 'event_espresso'),
106
+				__('wait list', 'event_espresso'),
107
+			),
108
+			EEM_Transaction::overpaid_status_code       => array(
109
+				__('overpaid', 'event_espresso'),
110
+				__('overpaid', 'event_espresso'),
111
+			),
112
+			EEM_Transaction::complete_status_code       => array(
113
+				__('complete', 'event_espresso'),
114
+				__('complete', 'event_espresso'),
115
+			),
116
+			EEM_Transaction::incomplete_status_code     => array(
117
+				__('incomplete', 'event_espresso'),
118
+				__('incomplete', 'event_espresso'),
119
+			),
120
+			EEM_Transaction::failed_status_code         => array(
121
+				__('failed', 'event_espresso'),
122
+				__('failed', 'event_espresso'),
123
+			),
124
+			EEM_Transaction::abandoned_status_code      => array(
125
+				__('abandoned', 'event_espresso'),
126
+				__('abandoned', 'event_espresso'),
127
+			),
128
+			EEM_Payment::status_id_approved             => array(
129
+				__('accepted', 'event_espresso'),
130
+				__('accepted', 'event_espresso'),
131
+			),
132
+			EEM_Payment::status_id_pending              => array(
133
+				__('pending', 'event_espresso'),
134
+				__('pending', 'event_espresso'),
135
+			),
136
+			EEM_Payment::status_id_cancelled            => array(
137
+				__('cancelled', 'event_espresso'),
138
+				__('cancelled', 'event_espresso'),
139
+			),
140
+			EEM_Payment::status_id_declined             => array(
141
+				__('declined', 'event_espresso'),
142
+				__('declined', 'event_espresso'),
143
+			),
144
+			EEM_Payment::status_id_failed               => array(
145
+				__('failed', 'event_espresso'),
146
+				__('failed', 'event_espresso'),
147
+			),
148
+			// following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
149
+			EEM_Event::sold_out                         => array(
150
+				__('sold out', 'event_espresso'),
151
+				__('sold out', 'event_espresso'),
152
+			),
153
+			EEM_Event::postponed                        => array(
154
+				__('postponed', 'event_espresso'),
155
+				__('Postponed', 'event_espresso'),
156
+			),
157
+			EEM_Event::cancelled                        => array(
158
+				__('cancelled', 'event_espresso'),
159
+				__('cancelled', 'event_espresso'),
160
+			),
161
+			EE_Ticket::archived                         => array(
162
+				__('archived', 'event_espresso'),
163
+				__('archived', 'event_espresso'),
164
+			),
165
+			EE_Ticket::expired                          => array(
166
+				__('expired', 'event_espresso'),
167
+				__('expired', 'event_espresso'),
168
+			),
169
+			EE_Ticket::sold_out                         => array(
170
+				__('sold out', 'event_espresso'),
171
+				__('sold out', 'event_espresso'),
172
+			),
173
+			EE_Ticket::pending                          => array(
174
+				__('upcoming', 'event_espresso'),
175
+				__('upcoming', 'event_espresso'),
176
+			),
177
+			EE_Ticket::onsale                           => array(
178
+				__('on sale', 'event_espresso'),
179
+				__('on sale', 'event_espresso'),
180
+			),
181
+			EE_Datetime::cancelled                      => array(
182
+				__('cancelled', 'event_espresso'),
183
+				__('cancelled', 'event_espresso'),
184
+			),
185
+			EE_Datetime::sold_out                       => array(
186
+				__('sold out', 'event_espresso'),
187
+				__('sold out', 'event_espresso'),
188
+			),
189
+			EE_Datetime::expired                        => array(
190
+				__('expired', 'event_espresso'),
191
+				__('expired', 'event_espresso'),
192
+			),
193
+			EE_Datetime::inactive                       => array(
194
+				__('inactive', 'event_espresso'),
195
+				__('inactive', 'event_espresso'),
196
+			),
197
+			EE_Datetime::upcoming                       => array(
198
+				__('upcoming', 'event_espresso'),
199
+				__('upcoming', 'event_espresso'),
200
+			),
201
+			EE_Datetime::active                         => array(
202
+				__('active', 'event_espresso'),
203
+				__('active', 'event_espresso'),
204
+			),
205
+			EE_Datetime::postponed                      => array(
206
+				__('postponed', 'event_espresso'),
207
+				__('postponed', 'event_espresso'),
208
+			),
209
+			// messages related
210
+			EEM_Message::status_sent                    => array(
211
+				__('sent', 'event_espresso'),
212
+				__('sent', 'event_espresso'),
213
+			),
214
+			EEM_Message::status_idle                    => array(
215
+				__('queued for sending', 'event_espresso'),
216
+				__('queued for sending', 'event_espresso'),
217
+			),
218
+			EEM_Message::status_failed                  => array(
219
+				__('failed', 'event_espresso'),
220
+				__('failed', 'event_espresso'),
221
+			),
222
+			EEM_Message::status_debug_only              => array(
223
+				__('debug only', 'event_espresso'),
224
+				__('debug only', 'event_espresso'),
225
+			),
226
+			EEM_Message::status_messenger_executing     => array(
227
+				__('messenger is executing', 'event_espresso'),
228
+				__('messenger is executing', 'event_espresso'),
229
+			),
230
+			EEM_Message::status_resend                  => array(
231
+				__('queued for resending', 'event_espresso'),
232
+				__('queued for resending', 'event_espresso'),
233
+			),
234
+			EEM_Message::status_incomplete              => array(
235
+				__('queued for generating', 'event_espresso'),
236
+				__('queued for generating', 'event_espresso'),
237
+			),
238
+			EEM_Message::status_retry                   => array(
239
+				__('failed sending, can be retried', 'event_espresso'),
240
+				__('failed sending, can be retried', 'event_espresso'),
241
+			),
242
+			EEM_CPT_Base::post_status_publish           => array(
243
+				__('published', 'event_espresso'),
244
+				__('published', 'event_espresso'),
245
+			),
246
+			EEM_CPT_Base::post_status_future            => array(
247
+				__('scheduled', 'event_espresso'),
248
+				__('scheduled', 'event_espresso'),
249
+			),
250
+			EEM_CPT_Base::post_status_draft             => array(
251
+				__('draft', 'event_espresso'),
252
+				__('draft', 'event_espresso'),
253
+			),
254
+			EEM_CPT_Base::post_status_pending           => array(
255
+				__('pending', 'event_espresso'),
256
+				__('pending', 'event_espresso'),
257
+			),
258
+			EEM_CPT_Base::post_status_private           => array(
259
+				__('private', 'event_espresso'),
260
+				__('private', 'event_espresso'),
261
+			),
262
+			EEM_CPT_Base::post_status_trashed           => array(
263
+				__('trashed', 'event_espresso'),
264
+				__('trashed', 'event_espresso'),
265
+			),
266
+		);
267 267
 
268
-        $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
268
+		$translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
269 269
 
270
-        if (! is_array($statuses)) {
271
-            throw new EE_Error(__(
272
-                'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273
-                'event_espresso'
274
-            ));
275
-        }
270
+		if (! is_array($statuses)) {
271
+			throw new EE_Error(__(
272
+				'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273
+				'event_espresso'
274
+			));
275
+		}
276 276
 
277
-        $translation = array();
277
+		$translation = array();
278 278
 
279
-        foreach ($statuses as $id => $code) {
280
-            if (isset($translation_array[ $id ])) {
281
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
282
-            } else {
283
-                $translation[ $id ] = $code;
284
-            }
279
+		foreach ($statuses as $id => $code) {
280
+			if (isset($translation_array[ $id ])) {
281
+				$translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
282
+			} else {
283
+				$translation[ $id ] = $code;
284
+			}
285 285
 
286
-            // schema
287
-            switch ($schema) {
288
-                case 'lower':
289
-                    $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
290
-                    break;
291
-                case 'sentence':
292
-                    $translation[ $id ] = ucwords($translation[ $id ]);
293
-                    break;
294
-                case 'upper':
295
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
296
-                    break;
297
-            }
298
-        }
286
+			// schema
287
+			switch ($schema) {
288
+				case 'lower':
289
+					$translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
290
+					break;
291
+				case 'sentence':
292
+					$translation[ $id ] = ucwords($translation[ $id ]);
293
+					break;
294
+				case 'upper':
295
+					$translation[ $id ] = strtoupper($translation[ $id ]);
296
+					break;
297
+			}
298
+		}
299 299
 
300
-        return $translation;
301
-    }
300
+		return $translation;
301
+	}
302 302
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
                     false,
36 36
                     'event',
37 37
                     array(
38
-                        'event'        => __("Event", "event_espresso"),// deprecated
38
+                        'event'        => __("Event", "event_espresso"), // deprecated
39 39
                         'registration' => __("Registration", "event_espresso"),
40 40
                         'transaction'  => __("Transaction", "event_espresso"),
41 41
                         'payment'      => __("Payment", "event_espresso"),
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             'Payment'      => new EE_Has_Many_Relation(),
55 55
         );
56 56
         // this model is generally available for reading
57
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
57
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
58 58
 
59 59
         parent::__construct($timezone);
60 60
     }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 
268 268
         $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
269 269
 
270
-        if (! is_array($statuses)) {
270
+        if ( ! is_array($statuses)) {
271 271
             throw new EE_Error(__(
272 272
                 'The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
273 273
                 'event_espresso'
@@ -277,22 +277,22 @@  discard block
 block discarded – undo
277 277
         $translation = array();
278 278
 
279 279
         foreach ($statuses as $id => $code) {
280
-            if (isset($translation_array[ $id ])) {
281
-                $translation[ $id ] = $plural ? $translation_array[ $id ][1] : $translation_array[ $id ][0];
280
+            if (isset($translation_array[$id])) {
281
+                $translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0];
282 282
             } else {
283
-                $translation[ $id ] = $code;
283
+                $translation[$id] = $code;
284 284
             }
285 285
 
286 286
             // schema
287 287
             switch ($schema) {
288 288
                 case 'lower':
289
-                    $translation[ $id ] = strtolower($translation[ $id ]); // even though these start in lower case, this will catch any statuses added via filter.
289
+                    $translation[$id] = strtolower($translation[$id]); // even though these start in lower case, this will catch any statuses added via filter.
290 290
                     break;
291 291
                 case 'sentence':
292
-                    $translation[ $id ] = ucwords($translation[ $id ]);
292
+                    $translation[$id] = ucwords($translation[$id]);
293 293
                     break;
294 294
                 case 'upper':
295
-                    $translation[ $id ] = strtoupper($translation[ $id ]);
295
+                    $translation[$id] = strtoupper($translation[$id]);
296 296
                     break;
297 297
             }
298 298
         }
Please login to merge, or discard this patch.
core/db_models/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_Key_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_Primary_Key_Index extends EE_Unique_Index
8 8
 {
9
-    // yep, actually the same as unique index right now
9
+	// yep, actually the same as unique index right now
10 10
 }
Please login to merge, or discard this patch.
core/db_models/helpers/EE_Model_Query_Info_Carrier.php 2 patches
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -14,141 +14,141 @@  discard block
 block discarded – undo
14 14
    /**
15 15
     * @var string SQL for performing joins (Eg, "INNER JOIN blah ON blah=blah INNER JOIN FOO ON foo=foo...")
16 16
     */
17
-    private $_join_sql;
17
+	private $_join_sql;
18 18
    /**
19 19
     *
20 20
     * @var array stating all the models that have been included thus far,so we don't get duplicates.
21 21
     * Keys are the model relation chains to them from the queried model
22 22
     * (eg, "Registration.Transaction.Payment"), and valuesare model names (eg "Payment")
23 23
     */
24
-    private $_models_included;
24
+	private $_models_included;
25 25
    
26 26
    /**
27 27
     * After we've acquired all the data types, we can create this sql.
28 28
     * @var string
29 29
     */
30
-    private $_where_sql;
30
+	private $_where_sql;
31 31
    /**
32 32
     * Full join sql. Eg, in a select query, that's everything after the "FROM", and before the "WHERE", so it includes
33 33
     * the declaration of the main model's tables, and then appends all the joining sql to other models
34 34
     * @var string
35 35
     */
36
-    private $_main_join_sql;
36
+	private $_main_join_sql;
37 37
    
38 38
    
39
-    private $_limit_sql;
39
+	private $_limit_sql;
40 40
    
41
-    private $_order_by_sql;
41
+	private $_order_by_sql;
42 42
    
43
-    private $_having_sql;
43
+	private $_having_sql;
44 44
    
45
-    private $_group_by_sql;
45
+	private $_group_by_sql;
46 46
    
47
-    public function set_limit_sql($limit_sql)
48
-    {
49
-        $this->_limit_sql = $limit_sql;
50
-    }
47
+	public function set_limit_sql($limit_sql)
48
+	{
49
+		$this->_limit_sql = $limit_sql;
50
+	}
51 51
     
52
-    public function set_order_by_sql($order_by_sql)
53
-    {
54
-        $this->_order_by_sql = $order_by_sql;
55
-    }
56
-    public function set_group_by_sql($group_by_sql)
57
-    {
58
-        $this->_group_by_sql = $group_by_sql;
59
-    }
60
-    public function set_having_sql($having_sql)
61
-    {
62
-        $this->_having_sql = $having_sql;
63
-    }
64
-    public function get_limit_sql()
65
-    {
66
-        return $this->_limit_sql;
67
-    }
68
-    public function get_order_by_sql()
69
-    {
70
-        return $this->_order_by_sql;
71
-    }
72
-    public function get_group_by_sql()
73
-    {
74
-        return $this->_group_by_sql;
75
-    }
76
-    public function get_having_sql()
77
-    {
78
-        return $this->_having_sql;
79
-    }
52
+	public function set_order_by_sql($order_by_sql)
53
+	{
54
+		$this->_order_by_sql = $order_by_sql;
55
+	}
56
+	public function set_group_by_sql($group_by_sql)
57
+	{
58
+		$this->_group_by_sql = $group_by_sql;
59
+	}
60
+	public function set_having_sql($having_sql)
61
+	{
62
+		$this->_having_sql = $having_sql;
63
+	}
64
+	public function get_limit_sql()
65
+	{
66
+		return $this->_limit_sql;
67
+	}
68
+	public function get_order_by_sql()
69
+	{
70
+		return $this->_order_by_sql;
71
+	}
72
+	public function get_group_by_sql()
73
+	{
74
+		return $this->_group_by_sql;
75
+	}
76
+	public function get_having_sql()
77
+	{
78
+		return $this->_having_sql;
79
+	}
80 80
    /**
81 81
     *
82 82
     * @param type $model_included_name
83 83
     * @param type $join_sql
84 84
     * @param type $data_types
85 85
     */
86
-    public function __construct($model_included_name = array(), $join_sql = '')
87
-    {
88
-        $this->_models_included = $model_included_name;
89
-        $this->_join_sql = $join_sql;
90
-    }
86
+	public function __construct($model_included_name = array(), $join_sql = '')
87
+	{
88
+		$this->_models_included = $model_included_name;
89
+		$this->_join_sql = $join_sql;
90
+	}
91 91
    
92 92
    /**
93 93
     * Merges info from the other EEM_Related_Model_Info_Carrier into this one.
94 94
     * @param EE_Model_Query_Info_Carrier $other_model_query_info_carrier
95 95
     */
96
-    public function merge($other_model_query_info_carrier)
97
-    {
98
-        if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
-            $model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
100
-            $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101
-            $this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102
-        }
103
-        // otherwise don't merge our data.
104
-        // yes, this means that we must immediately merge any model data into our grand list
105
-        // as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier
106
-        // which is carrying info from two models WHERE one is already included but the other is NOT
107
-    }
96
+	public function merge($other_model_query_info_carrier)
97
+	{
98
+		if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
+			$model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
100
+			$this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101
+			$this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102
+		}
103
+		// otherwise don't merge our data.
104
+		// yes, this means that we must immediately merge any model data into our grand list
105
+		// as soon as we get some from ONE model, or else we could reject a EEM_Related_Model_Info_Carrier
106
+		// which is carrying info from two models WHERE one is already included but the other is NOT
107
+	}
108 108
    /**
109 109
     * Checks whether or not we have already included all the models mentione din $model_names on the query info varrier
110 110
     * @param array $model_names just like EE_MOdel_QUery_Info_Carrier::_models_included: keys are model chain paths, values are the model names only
111 111
     * @return boolean
112 112
     */
113
-    protected function _have_already_included_one_of_these_models($model_names)
114
-    {
115
-        foreach ($this->_models_included as $model_relation_path => $model_included) {
116
-            if (array_key_exists($model_relation_path, $model_names)) {
117
-                return true;
118
-            }
119
-        }
120
-        return false;
121
-    }
113
+	protected function _have_already_included_one_of_these_models($model_names)
114
+	{
115
+		foreach ($this->_models_included as $model_relation_path => $model_included) {
116
+			if (array_key_exists($model_relation_path, $model_names)) {
117
+				return true;
118
+			}
119
+		}
120
+		return false;
121
+	}
122 122
    /**
123 123
     * Array keys are model names, values are "model relation paths". See EE_Model_Query_Info_Carrier::_models_included for details
124 124
     * @return array like EE_Model_Query_Info_Carrier::_models_included
125 125
     */
126
-    public function get_model_names_included()
127
-    {
128
-        return $this->_models_included;
129
-    }
126
+	public function get_model_names_included()
127
+	{
128
+		return $this->_models_included;
129
+	}
130 130
    /**
131 131
     * sets the $where_sql for later use from client code
132 132
     * @param string $where_sql
133 133
     */
134
-    public function set_where_sql($where_sql)
135
-    {
136
-        $this->_where_sql = $where_sql;
137
-    }
138
-    public function get_where_sql()
139
-    {
140
-        return $this->_where_sql;
141
-    }
134
+	public function set_where_sql($where_sql)
135
+	{
136
+		$this->_where_sql = $where_sql;
137
+	}
138
+	public function get_where_sql()
139
+	{
140
+		return $this->_where_sql;
141
+	}
142 142
 
143 143
    /**
144 144
     * Gets the SQL for joining the main model to other models involves in the query, which was set earlier on
145 145
     * the EE_Model_Query_info_Carrier by calling set_main_model_join_sql()
146 146
     * @return string
147 147
     */
148
-    public function get_main_model_join_sql()
149
-    {
150
-        return $this->_main_join_sql;
151
-    }
148
+	public function get_main_model_join_sql()
149
+	{
150
+		return $this->_main_join_sql;
151
+	}
152 152
 
153 153
 
154 154
    /**
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
     * after the FROM and before the WHERE.)
159 159
     * @param string $join_sql
160 160
     */
161
-    public function set_main_model_join_sql($join_sql)
162
-    {
163
-        $this->_main_join_sql = $join_sql;
164
-    }
165
-    public function get_full_join_sql()
166
-    {
167
-        return $this->_main_join_sql . $this->_join_sql;
168
-    }
161
+	public function set_main_model_join_sql($join_sql)
162
+	{
163
+		$this->_main_join_sql = $join_sql;
164
+	}
165
+	public function get_full_join_sql()
166
+	{
167
+		return $this->_main_join_sql . $this->_join_sql;
168
+	}
169 169
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     public function merge($other_model_query_info_carrier)
97 97
     {
98 98
         if ($other_model_query_info_carrier && ! $this->_have_already_included_one_of_these_models($other_model_query_info_carrier->get_model_names_included())) {
99
-            $model_included_on_other_join_sql_and_data_types_carrier =  $other_model_query_info_carrier->get_model_names_included();
99
+            $model_included_on_other_join_sql_and_data_types_carrier = $other_model_query_info_carrier->get_model_names_included();
100 100
             $this->_models_included = array_merge($this->_models_included, $model_included_on_other_join_sql_and_data_types_carrier);
101 101
             $this->_join_sql .= $other_model_query_info_carrier->_join_sql;
102 102
         }
@@ -164,6 +164,6 @@  discard block
 block discarded – undo
164 164
     }
165 165
     public function get_full_join_sql()
166 166
     {
167
-        return $this->_main_join_sql . $this->_join_sql;
167
+        return $this->_main_join_sql.$this->_join_sql;
168 168
     }
169 169
 }
Please login to merge, or discard this patch.
core/EE_Cart.core.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
             self::$_instance = new self($grand_total, $session);
66 66
         }
67 67
         // or maybe retrieve an existing one ?
68
-        if (! self::$_instance instanceof EE_Cart) {
68
+        if ( ! self::$_instance instanceof EE_Cart) {
69 69
             // try getting the cart out of the session
70 70
             $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71 71
             self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72 72
             unset($saved_cart);
73 73
         }
74 74
         // verify that cart is ok and grand total line item exists
75
-        if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
75
+        if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76 76
             self::$_instance = new self($grand_total, $session);
77 77
         }
78 78
         self::$_instance->get_grand_total();
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     public function session()
126 126
     {
127
-        if (! $this->_session instanceof EE_Session) {
127
+        if ( ! $this->_session instanceof EE_Session) {
128 128
             $this->set_session();
129 129
         }
130 130
         return $this->_session;
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
 
393 393
     public function __wakeup()
394 394
     {
395
-        if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
395
+        if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
396 396
             // $this->_grand_total is actually just an ID, so use it to get the object from the db
397 397
             $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
398 398
         }
Please login to merge, or discard this patch.
Indentation   +393 added lines, -393 removed lines patch added patch discarded remove patch
@@ -17,397 +17,397 @@
 block discarded – undo
17 17
 class EE_Cart implements ResettableInterface
18 18
 {
19 19
 
20
-    /**
21
-     * instance of the EE_Cart object
22
-     *
23
-     * @access    private
24
-     * @var EE_Cart $_instance
25
-     */
26
-    private static $_instance;
27
-
28
-    /**
29
-     * instance of the EE_Session object
30
-     *
31
-     * @access    protected
32
-     * @var EE_Session $_session
33
-     */
34
-    protected $_session;
35
-
36
-    /**
37
-     * The total Line item which comprises all the children line-item subtotals,
38
-     * which in turn each have their line items.
39
-     * Typically, the line item structure will look like:
40
-     * grand total
41
-     * -tickets-sub-total
42
-     * --ticket1
43
-     * --ticket2
44
-     * --...
45
-     * -taxes-sub-total
46
-     * --tax1
47
-     * --tax2
48
-     *
49
-     * @var EE_Line_Item
50
-     */
51
-    private $_grand_total;
52
-
53
-
54
-    /**
55
-     * @singleton method used to instantiate class object
56
-     * @access    public
57
-     * @param EE_Line_Item $grand_total
58
-     * @param EE_Session   $session
59
-     * @return \EE_Cart
60
-     * @throws \EE_Error
61
-     */
62
-    public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
63
-    {
64
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
65
-            self::$_instance = new self($grand_total, $session);
66
-        }
67
-        // or maybe retrieve an existing one ?
68
-        if (! self::$_instance instanceof EE_Cart) {
69
-            // try getting the cart out of the session
70
-            $saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71
-            self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72
-            unset($saved_cart);
73
-        }
74
-        // verify that cart is ok and grand total line item exists
75
-        if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76
-            self::$_instance = new self($grand_total, $session);
77
-        }
78
-        self::$_instance->get_grand_total();
79
-        // once everything is all said and done, save the cart to the EE_Session
80
-        add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
81
-        return self::$_instance;
82
-    }
83
-
84
-
85
-    /**
86
-     * private constructor to prevent direct creation
87
-     *
88
-     * @Constructor
89
-     * @access private
90
-     * @param EE_Line_Item $grand_total
91
-     * @param EE_Session   $session
92
-     */
93
-    private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
94
-    {
95
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
96
-        $this->set_session($session);
97
-        if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
98
-            $this->set_grand_total_line_item($grand_total);
99
-        }
100
-    }
101
-
102
-
103
-    /**
104
-     * Resets the cart completely (whereas empty_cart
105
-     *
106
-     * @param EE_Line_Item $grand_total
107
-     * @param EE_Session   $session
108
-     * @return EE_Cart
109
-     * @throws \EE_Error
110
-     */
111
-    public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
112
-    {
113
-        remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
114
-        if ($session instanceof EE_Session) {
115
-            $session->reset_cart();
116
-        }
117
-        self::$_instance = null;
118
-        return self::instance($grand_total, $session);
119
-    }
120
-
121
-
122
-    /**
123
-     * @return \EE_Session
124
-     */
125
-    public function session()
126
-    {
127
-        if (! $this->_session instanceof EE_Session) {
128
-            $this->set_session();
129
-        }
130
-        return $this->_session;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param EE_Session $session
136
-     */
137
-    public function set_session(EE_Session $session = null)
138
-    {
139
-        $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
140
-    }
141
-
142
-
143
-    /**
144
-     * Sets the cart to match the line item. Especially handy for loading an old cart where you
145
-     *  know the grand total line item on it
146
-     *
147
-     * @param EE_Line_Item $line_item
148
-     */
149
-    public function set_grand_total_line_item(EE_Line_Item $line_item)
150
-    {
151
-        $this->_grand_total = $line_item;
152
-    }
153
-
154
-
155
-    /**
156
-     * get_cart_from_reg_url_link
157
-     *
158
-     * @access public
159
-     * @param EE_Transaction $transaction
160
-     * @param EE_Session     $session
161
-     * @return \EE_Cart
162
-     * @throws \EE_Error
163
-     */
164
-    public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
165
-    {
166
-        $grand_total = $transaction->total_line_item();
167
-        $grand_total->get_items();
168
-        $grand_total->tax_descendants();
169
-        return EE_Cart::instance($grand_total, $session);
170
-    }
171
-
172
-
173
-    /**
174
-     * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
175
-     *
176
-     * @return EE_Line_Item
177
-     * @throws \EE_Error
178
-     */
179
-    private function _create_grand_total()
180
-    {
181
-        $this->_grand_total = EEH_Line_Item::create_total_line_item();
182
-        return $this->_grand_total;
183
-    }
184
-
185
-
186
-    /**
187
-     * Gets all the line items of object type Ticket
188
-     *
189
-     * @access public
190
-     * @return \EE_Line_Item[]
191
-     */
192
-    public function get_tickets()
193
-    {
194
-        if ($this->_grand_total === null) {
195
-            return array();
196
-        }
197
-        return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
198
-    }
199
-
200
-
201
-    /**
202
-     * returns the total quantity of tickets in the cart
203
-     *
204
-     * @access public
205
-     * @return int
206
-     * @throws \EE_Error
207
-     */
208
-    public function all_ticket_quantity_count()
209
-    {
210
-        $tickets = $this->get_tickets();
211
-        if (empty($tickets)) {
212
-            return 0;
213
-        }
214
-        $count = 0;
215
-        foreach ($tickets as $ticket) {
216
-            $count += $ticket->get('LIN_quantity');
217
-        }
218
-        return $count;
219
-    }
220
-
221
-
222
-    /**
223
-     * Gets all the tax line items
224
-     *
225
-     * @return \EE_Line_Item[]
226
-     * @throws \EE_Error
227
-     */
228
-    public function get_taxes()
229
-    {
230
-        return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
231
-    }
232
-
233
-
234
-    /**
235
-     * Gets the total line item (which is a parent of all other line items) on this cart
236
-     *
237
-     * @return EE_Line_Item
238
-     * @throws \EE_Error
239
-     */
240
-    public function get_grand_total()
241
-    {
242
-        return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
243
-    }
244
-
245
-
246
-    /**
247
-     * @process items for adding to cart
248
-     * @access  public
249
-     * @param EE_Ticket $ticket
250
-     * @param int       $qty
251
-     * @return TRUE on success, FALSE on fail
252
-     * @throws \EE_Error
253
-     */
254
-    public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
255
-    {
256
-        EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
257
-        return $this->save_cart() ? true : false;
258
-    }
259
-
260
-
261
-    /**
262
-     * get_cart_total_before_tax
263
-     *
264
-     * @access public
265
-     * @return float
266
-     * @throws \EE_Error
267
-     */
268
-    public function get_cart_total_before_tax()
269
-    {
270
-        return $this->get_grand_total()->recalculate_pre_tax_total();
271
-    }
272
-
273
-
274
-    /**
275
-     * gets the total amount of tax paid for items in this cart
276
-     *
277
-     * @access public
278
-     * @return float
279
-     * @throws \EE_Error
280
-     */
281
-    public function get_applied_taxes()
282
-    {
283
-        return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
284
-    }
285
-
286
-
287
-    /**
288
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
289
-     *
290
-     * @access public
291
-     * @return float
292
-     * @throws \EE_Error
293
-     */
294
-    public function get_cart_grand_total()
295
-    {
296
-        EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
297
-        return $this->get_grand_total()->total();
298
-    }
299
-
300
-
301
-    /**
302
-     * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
303
-     *
304
-     * @access public
305
-     * @return float
306
-     * @throws \EE_Error
307
-     */
308
-    public function recalculate_all_cart_totals()
309
-    {
310
-        $pre_tax_total = $this->get_cart_total_before_tax();
311
-        $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
312
-        $this->_grand_total->set_total($pre_tax_total + $taxes_total);
313
-        $this->_grand_total->save_this_and_descendants_to_txn();
314
-        return $this->get_grand_total()->total();
315
-    }
316
-
317
-
318
-    /**
319
-     * deletes an item from the cart
320
-     *
321
-     * @access public
322
-     * @param array|bool|string $line_item_codes
323
-     * @return int on success, FALSE on fail
324
-     * @throws \EE_Error
325
-     */
326
-    public function delete_items($line_item_codes = false)
327
-    {
328
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
329
-        return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
330
-    }
331
-
332
-
333
-    /**
334
-     * @remove ALL items from cart and zero ALL totals
335
-     * @access public
336
-     * @return bool
337
-     * @throws \EE_Error
338
-     */
339
-    public function empty_cart()
340
-    {
341
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
342
-        $this->_grand_total = $this->_create_grand_total();
343
-        return $this->save_cart(true);
344
-    }
345
-
346
-
347
-    /**
348
-     * @remove ALL items from cart and delete total as well
349
-     * @access public
350
-     * @return bool
351
-     * @throws \EE_Error
352
-     */
353
-    public function delete_cart()
354
-    {
355
-        if ($this->_grand_total instanceof EE_Line_Item) {
356
-            $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
357
-            if ($deleted) {
358
-                $deleted += $this->_grand_total->delete();
359
-                $this->_grand_total = null;
360
-                return true;
361
-            }
362
-        }
363
-        return false;
364
-    }
365
-
366
-
367
-    /**
368
-     * @save   cart to session
369
-     * @access public
370
-     * @param bool $apply_taxes
371
-     * @return TRUE on success, FALSE on fail
372
-     * @throws \EE_Error
373
-     */
374
-    public function save_cart($apply_taxes = true)
375
-    {
376
-        if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
377
-            EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
378
-            // make sure we don't cache the transaction because it can get stale
379
-            if (
380
-                $this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
381
-                && $this->_grand_total->get_one_from_cache('Transaction')->ID()
382
-            ) {
383
-                $this->_grand_total->clear_cache('Transaction', null, true);
384
-            }
385
-        }
386
-        if ($this->session() instanceof EE_Session) {
387
-            return $this->session()->set_cart($this);
388
-        } else {
389
-            return false;
390
-        }
391
-    }
392
-
393
-
394
-    public function __wakeup()
395
-    {
396
-        if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
397
-            // $this->_grand_total is actually just an ID, so use it to get the object from the db
398
-            $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
399
-        }
400
-    }
401
-
402
-
403
-    /**
404
-     * @return array
405
-     */
406
-    public function __sleep()
407
-    {
408
-        if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
409
-            $this->_grand_total = $this->_grand_total->ID();
410
-        }
411
-        return array('_grand_total');
412
-    }
20
+	/**
21
+	 * instance of the EE_Cart object
22
+	 *
23
+	 * @access    private
24
+	 * @var EE_Cart $_instance
25
+	 */
26
+	private static $_instance;
27
+
28
+	/**
29
+	 * instance of the EE_Session object
30
+	 *
31
+	 * @access    protected
32
+	 * @var EE_Session $_session
33
+	 */
34
+	protected $_session;
35
+
36
+	/**
37
+	 * The total Line item which comprises all the children line-item subtotals,
38
+	 * which in turn each have their line items.
39
+	 * Typically, the line item structure will look like:
40
+	 * grand total
41
+	 * -tickets-sub-total
42
+	 * --ticket1
43
+	 * --ticket2
44
+	 * --...
45
+	 * -taxes-sub-total
46
+	 * --tax1
47
+	 * --tax2
48
+	 *
49
+	 * @var EE_Line_Item
50
+	 */
51
+	private $_grand_total;
52
+
53
+
54
+	/**
55
+	 * @singleton method used to instantiate class object
56
+	 * @access    public
57
+	 * @param EE_Line_Item $grand_total
58
+	 * @param EE_Session   $session
59
+	 * @return \EE_Cart
60
+	 * @throws \EE_Error
61
+	 */
62
+	public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null)
63
+	{
64
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
65
+			self::$_instance = new self($grand_total, $session);
66
+		}
67
+		// or maybe retrieve an existing one ?
68
+		if (! self::$_instance instanceof EE_Cart) {
69
+			// try getting the cart out of the session
70
+			$saved_cart = $session instanceof EE_Session ? $session->cart() : null;
71
+			self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session);
72
+			unset($saved_cart);
73
+		}
74
+		// verify that cart is ok and grand total line item exists
75
+		if (! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) {
76
+			self::$_instance = new self($grand_total, $session);
77
+		}
78
+		self::$_instance->get_grand_total();
79
+		// once everything is all said and done, save the cart to the EE_Session
80
+		add_action('shutdown', array(self::$_instance, 'save_cart'), 90);
81
+		return self::$_instance;
82
+	}
83
+
84
+
85
+	/**
86
+	 * private constructor to prevent direct creation
87
+	 *
88
+	 * @Constructor
89
+	 * @access private
90
+	 * @param EE_Line_Item $grand_total
91
+	 * @param EE_Session   $session
92
+	 */
93
+	private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null)
94
+	{
95
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
96
+		$this->set_session($session);
97
+		if ($grand_total instanceof EE_Line_Item && $grand_total->is_total()) {
98
+			$this->set_grand_total_line_item($grand_total);
99
+		}
100
+	}
101
+
102
+
103
+	/**
104
+	 * Resets the cart completely (whereas empty_cart
105
+	 *
106
+	 * @param EE_Line_Item $grand_total
107
+	 * @param EE_Session   $session
108
+	 * @return EE_Cart
109
+	 * @throws \EE_Error
110
+	 */
111
+	public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null)
112
+	{
113
+		remove_action('shutdown', array(self::$_instance, 'save_cart'), 90);
114
+		if ($session instanceof EE_Session) {
115
+			$session->reset_cart();
116
+		}
117
+		self::$_instance = null;
118
+		return self::instance($grand_total, $session);
119
+	}
120
+
121
+
122
+	/**
123
+	 * @return \EE_Session
124
+	 */
125
+	public function session()
126
+	{
127
+		if (! $this->_session instanceof EE_Session) {
128
+			$this->set_session();
129
+		}
130
+		return $this->_session;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param EE_Session $session
136
+	 */
137
+	public function set_session(EE_Session $session = null)
138
+	{
139
+		$this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session');
140
+	}
141
+
142
+
143
+	/**
144
+	 * Sets the cart to match the line item. Especially handy for loading an old cart where you
145
+	 *  know the grand total line item on it
146
+	 *
147
+	 * @param EE_Line_Item $line_item
148
+	 */
149
+	public function set_grand_total_line_item(EE_Line_Item $line_item)
150
+	{
151
+		$this->_grand_total = $line_item;
152
+	}
153
+
154
+
155
+	/**
156
+	 * get_cart_from_reg_url_link
157
+	 *
158
+	 * @access public
159
+	 * @param EE_Transaction $transaction
160
+	 * @param EE_Session     $session
161
+	 * @return \EE_Cart
162
+	 * @throws \EE_Error
163
+	 */
164
+	public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null)
165
+	{
166
+		$grand_total = $transaction->total_line_item();
167
+		$grand_total->get_items();
168
+		$grand_total->tax_descendants();
169
+		return EE_Cart::instance($grand_total, $session);
170
+	}
171
+
172
+
173
+	/**
174
+	 * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items
175
+	 *
176
+	 * @return EE_Line_Item
177
+	 * @throws \EE_Error
178
+	 */
179
+	private function _create_grand_total()
180
+	{
181
+		$this->_grand_total = EEH_Line_Item::create_total_line_item();
182
+		return $this->_grand_total;
183
+	}
184
+
185
+
186
+	/**
187
+	 * Gets all the line items of object type Ticket
188
+	 *
189
+	 * @access public
190
+	 * @return \EE_Line_Item[]
191
+	 */
192
+	public function get_tickets()
193
+	{
194
+		if ($this->_grand_total === null) {
195
+			return array();
196
+		}
197
+		return EEH_Line_Item::get_ticket_line_items($this->_grand_total);
198
+	}
199
+
200
+
201
+	/**
202
+	 * returns the total quantity of tickets in the cart
203
+	 *
204
+	 * @access public
205
+	 * @return int
206
+	 * @throws \EE_Error
207
+	 */
208
+	public function all_ticket_quantity_count()
209
+	{
210
+		$tickets = $this->get_tickets();
211
+		if (empty($tickets)) {
212
+			return 0;
213
+		}
214
+		$count = 0;
215
+		foreach ($tickets as $ticket) {
216
+			$count += $ticket->get('LIN_quantity');
217
+		}
218
+		return $count;
219
+	}
220
+
221
+
222
+	/**
223
+	 * Gets all the tax line items
224
+	 *
225
+	 * @return \EE_Line_Item[]
226
+	 * @throws \EE_Error
227
+	 */
228
+	public function get_taxes()
229
+	{
230
+		return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children();
231
+	}
232
+
233
+
234
+	/**
235
+	 * Gets the total line item (which is a parent of all other line items) on this cart
236
+	 *
237
+	 * @return EE_Line_Item
238
+	 * @throws \EE_Error
239
+	 */
240
+	public function get_grand_total()
241
+	{
242
+		return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total();
243
+	}
244
+
245
+
246
+	/**
247
+	 * @process items for adding to cart
248
+	 * @access  public
249
+	 * @param EE_Ticket $ticket
250
+	 * @param int       $qty
251
+	 * @return TRUE on success, FALSE on fail
252
+	 * @throws \EE_Error
253
+	 */
254
+	public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1)
255
+	{
256
+		EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty);
257
+		return $this->save_cart() ? true : false;
258
+	}
259
+
260
+
261
+	/**
262
+	 * get_cart_total_before_tax
263
+	 *
264
+	 * @access public
265
+	 * @return float
266
+	 * @throws \EE_Error
267
+	 */
268
+	public function get_cart_total_before_tax()
269
+	{
270
+		return $this->get_grand_total()->recalculate_pre_tax_total();
271
+	}
272
+
273
+
274
+	/**
275
+	 * gets the total amount of tax paid for items in this cart
276
+	 *
277
+	 * @access public
278
+	 * @return float
279
+	 * @throws \EE_Error
280
+	 */
281
+	public function get_applied_taxes()
282
+	{
283
+		return EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
284
+	}
285
+
286
+
287
+	/**
288
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
289
+	 *
290
+	 * @access public
291
+	 * @return float
292
+	 * @throws \EE_Error
293
+	 */
294
+	public function get_cart_grand_total()
295
+	{
296
+		EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
297
+		return $this->get_grand_total()->total();
298
+	}
299
+
300
+
301
+	/**
302
+	 * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers
303
+	 *
304
+	 * @access public
305
+	 * @return float
306
+	 * @throws \EE_Error
307
+	 */
308
+	public function recalculate_all_cart_totals()
309
+	{
310
+		$pre_tax_total = $this->get_cart_total_before_tax();
311
+		$taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
312
+		$this->_grand_total->set_total($pre_tax_total + $taxes_total);
313
+		$this->_grand_total->save_this_and_descendants_to_txn();
314
+		return $this->get_grand_total()->total();
315
+	}
316
+
317
+
318
+	/**
319
+	 * deletes an item from the cart
320
+	 *
321
+	 * @access public
322
+	 * @param array|bool|string $line_item_codes
323
+	 * @return int on success, FALSE on fail
324
+	 * @throws \EE_Error
325
+	 */
326
+	public function delete_items($line_item_codes = false)
327
+	{
328
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
329
+		return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes);
330
+	}
331
+
332
+
333
+	/**
334
+	 * @remove ALL items from cart and zero ALL totals
335
+	 * @access public
336
+	 * @return bool
337
+	 * @throws \EE_Error
338
+	 */
339
+	public function empty_cart()
340
+	{
341
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
342
+		$this->_grand_total = $this->_create_grand_total();
343
+		return $this->save_cart(true);
344
+	}
345
+
346
+
347
+	/**
348
+	 * @remove ALL items from cart and delete total as well
349
+	 * @access public
350
+	 * @return bool
351
+	 * @throws \EE_Error
352
+	 */
353
+	public function delete_cart()
354
+	{
355
+		if ($this->_grand_total instanceof EE_Line_Item) {
356
+			$deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total);
357
+			if ($deleted) {
358
+				$deleted += $this->_grand_total->delete();
359
+				$this->_grand_total = null;
360
+				return true;
361
+			}
362
+		}
363
+		return false;
364
+	}
365
+
366
+
367
+	/**
368
+	 * @save   cart to session
369
+	 * @access public
370
+	 * @param bool $apply_taxes
371
+	 * @return TRUE on success, FALSE on fail
372
+	 * @throws \EE_Error
373
+	 */
374
+	public function save_cart($apply_taxes = true)
375
+	{
376
+		if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) {
377
+			EEH_Line_Item::ensure_taxes_applied($this->_grand_total);
378
+			// make sure we don't cache the transaction because it can get stale
379
+			if (
380
+				$this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction
381
+				&& $this->_grand_total->get_one_from_cache('Transaction')->ID()
382
+			) {
383
+				$this->_grand_total->clear_cache('Transaction', null, true);
384
+			}
385
+		}
386
+		if ($this->session() instanceof EE_Session) {
387
+			return $this->session()->set_cart($this);
388
+		} else {
389
+			return false;
390
+		}
391
+	}
392
+
393
+
394
+	public function __wakeup()
395
+	{
396
+		if (! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) {
397
+			// $this->_grand_total is actually just an ID, so use it to get the object from the db
398
+			$this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total);
399
+		}
400
+	}
401
+
402
+
403
+	/**
404
+	 * @return array
405
+	 */
406
+	public function __sleep()
407
+	{
408
+		if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) {
409
+			$this->_grand_total = $this->_grand_total->ID();
410
+		}
411
+		return array('_grand_total');
412
+	}
413 413
 }
Please login to merge, or discard this patch.
core/middleware/EE_Detect_Login.core.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -13,27 +13,27 @@
 block discarded – undo
13 13
 {
14 14
 
15 15
 
16
-    /**
17
-     * @deprecated
18
-     * @param    EE_Request  $request
19
-     * @param    EE_Response $response
20
-     * @return    EE_Response
21
-     */
22
-    public function handle_request(EE_Request $request, EE_Response $response)
23
-    {
24
-        EE_Error::doing_it_wrong(
25
-            __METHOD__,
26
-            sprintf(
27
-                esc_html__(
28
-                    'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
29
-                    'event_espresso'
30
-                ),
31
-                'EventEspresso\core\services\request\middleware\DetectLogin',
32
-                '\core\services\request',
33
-                'EventEspresso\core\services\request'
34
-            ),
35
-            '4.9.52'
36
-        );
37
-        return $response;
38
-    }
16
+	/**
17
+	 * @deprecated
18
+	 * @param    EE_Request  $request
19
+	 * @param    EE_Response $response
20
+	 * @return    EE_Response
21
+	 */
22
+	public function handle_request(EE_Request $request, EE_Response $response)
23
+	{
24
+		EE_Error::doing_it_wrong(
25
+			__METHOD__,
26
+			sprintf(
27
+				esc_html__(
28
+					'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace',
29
+					'event_espresso'
30
+				),
31
+				'EventEspresso\core\services\request\middleware\DetectLogin',
32
+				'\core\services\request',
33
+				'EventEspresso\core\services\request'
34
+			),
35
+			'4.9.52'
36
+		);
37
+		return $response;
38
+	}
39 39
 }
Please login to merge, or discard this patch.