Completed
Branch BUG/required-message-fields (8f9492)
by
unknown
10:53 queued 20s
created
core/db_models/EEM_Soft_Delete_Base.model.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     protected function __construct($timezone = null)
34 34
     {
35
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
35
+        if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
36 36
             $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
37 37
         }
38 38
         parent::__construct($timezone);
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
     protected function _alter_query_params_so_only_trashed_items_included($query_params)
134 134
     {
135 135
         $deletedFlagFieldName = $this->deleted_field_name();
136
-        $query_params[0][ $deletedFlagFieldName ] = true;
136
+        $query_params[0][$deletedFlagFieldName] = true;
137 137
         return $query_params;
138 138
     }
139 139
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
      */
174 174
     protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
175 175
     {
176
-        if (! isset($query_params['default_where_conditions'])) {
176
+        if ( ! isset($query_params['default_where_conditions'])) {
177 177
             $query_params['default_where_conditions'] = 'minimum';
178 178
         }
179 179
         return $query_params;
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      */
302 302
     public function delete_or_restore_by_ID($delete = true, $ID = false)
303 303
     {
304
-        if (! $ID) {
304
+        if ( ! $ID) {
305 305
             return false;
306 306
         }
307 307
         if (
Please login to merge, or discard this patch.
Indentation   +361 added lines, -361 removed lines patch added patch discarded remove patch
@@ -26,365 +26,365 @@
 block discarded – undo
26 26
  */
27 27
 abstract class EEM_Soft_Delete_Base extends EEM_Base
28 28
 {
29
-    /**
30
-     * @param null $timezone
31
-     */
32
-    protected function __construct($timezone = null)
33
-    {
34
-        if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
35
-            $this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
36
-        }
37
-        parent::__construct($timezone);
38
-    }
39
-
40
-
41
-
42
-    /**
43
-     * Searches for field on this model of type 'deleted_flag'. if it is found,
44
-     * returns it's name.
45
-     *
46
-     * @return string
47
-     * @throws EE_Error
48
-     */
49
-    public function deleted_field_name()
50
-    {
51
-        $field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
52
-        if ($field) {
53
-            return $field->get_name();
54
-        } else {
55
-            throw new EE_Error(sprintf(esc_html__(
56
-                'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
57
-                'event_espresso'
58
-            ), get_class($this), get_class($this)));
59
-        }
60
-    }
61
-
62
-
63
-
64
-    /**
65
-     * Gets one item that's been deleted, according to $query_params
66
-     *
67
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
68
-     * @return EE_Soft_Delete_Base_Class
69
-     */
70
-    public function get_one_deleted($query_params = array())
71
-    {
72
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
73
-        return parent::get_one($query_params);
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     * Gets one item from the DB, regardless of whether it's been soft-deleted or not
80
-     *
81
-     * @param array $query_params like EEM_base::get_all's $query_params
82
-     * @return EE_Soft_Delete_Base_Class
83
-     */
84
-    public function get_one_deleted_or_undeleted($query_params = array())
85
-    {
86
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
87
-        return parent::get_one($query_params);
88
-    }
89
-
90
-
91
-
92
-    /**
93
-     * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
94
-     *
95
-     * @param int|string $id
96
-     * @return EE_Soft_Delete_Base_Class
97
-     */
98
-    public function get_one_by_ID_but_ignore_deleted($id)
99
-    {
100
-        return $this->get_one(
101
-            $this->alter_query_params_to_restrict_by_ID(
102
-                $id,
103
-                array('default_where_conditions' => 'default')
104
-            )
105
-        );
106
-    }
107
-
108
-
109
-
110
-    /**
111
-     * Counts all the deleted/trashed items
112
-     *
113
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
114
-     * @param string $field_to_count
115
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
116
-     * @return int
117
-     */
118
-    public function count_deleted($query_params = null, $field_to_count = null, $distinct = false)
119
-    {
120
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
121
-        return parent::count($query_params, $field_to_count, $distinct);
122
-    }
123
-
124
-
125
-
126
-    /**
127
-     * Alters the query params so that only trashed/soft-deleted items are considered
128
-     *
129
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
130
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
131
-     */
132
-    protected function _alter_query_params_so_only_trashed_items_included($query_params)
133
-    {
134
-        $deletedFlagFieldName = $this->deleted_field_name();
135
-        $query_params[0][ $deletedFlagFieldName ] = true;
136
-        return $query_params;
137
-    }
138
-
139
-
140
-
141
-    /**
142
-     * Alters the query params so that only trashed/soft-deleted items are considered
143
-     *
144
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
145
-     * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
146
-     */
147
-    public function alter_query_params_so_only_trashed_items_included($query_params)
148
-    {
149
-        return $this->_alter_query_params_so_only_trashed_items_included($query_params);
150
-    }
151
-
152
-
153
-
154
-    /**
155
-     * Alters the query params so each item's deleted status is ignored.
156
-     *
157
-     * @param array $query_params
158
-     * @return array
159
-     */
160
-    public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array())
161
-    {
162
-        return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * Alters the query params so each item's deleted status is ignored.
169
-     *
170
-     * @param array $query_params
171
-     * @return array
172
-     */
173
-    protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
174
-    {
175
-        if (! isset($query_params['default_where_conditions'])) {
176
-            $query_params['default_where_conditions'] = 'minimum';
177
-        }
178
-        return $query_params;
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     * Counts all deleted and undeleted items
185
-     *
186
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
187
-     * @param string $field_to_count
188
-     * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
189
-     * @return int
190
-     */
191
-    public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false)
192
-    {
193
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
194
-        return parent::count($query_params, $field_to_count, $distinct);
195
-    }
196
-
197
-
198
-
199
-    /**
200
-     * Sum all the deleted items.
201
-     *
202
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
203
-     * @param string $field_to_sum
204
-     * @return int
205
-     */
206
-    public function sum_deleted($query_params = null, $field_to_sum = null)
207
-    {
208
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
209
-        return parent::sum($query_params, $field_to_sum);
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * Sums all the deleted and undeleted items.
216
-     *
217
-     * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
218
-     * @param string $field_to_sum
219
-     * @return int
220
-     */
221
-    public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null)
222
-    {
223
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
224
-        parent::sum($query_params, $field_to_sum);
225
-    }
226
-
227
-
228
-
229
-    /**
230
-     * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
231
-     * whether they've been soft-deleted or not
232
-     *
233
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
234
-     * @return EE_Soft_Delete_Base_Class[]
235
-     */
236
-    public function get_all_deleted_and_undeleted($query_params = array())
237
-    {
238
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
239
-        return parent::get_all($query_params);
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
246
-     *
247
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
248
-     * @return EE_Soft_Delete_Base_Class[]
249
-     */
250
-    public function get_all_deleted($query_params = array())
251
-    {
252
-        $query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
253
-        return parent::get_all($query_params);
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * Permanently deletes the selected rows. When selecting rows for deletion, ignores
260
-     * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
261
-     * before you can permanently delete them).
262
-     * Because this will cause a real deletion, related models may block this deletion (ie, add an error
263
-     * and abort the delete)
264
-     *
265
-     * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
266
-     * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
267
-     *                                that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
268
-     *                                which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
269
-     * @return int                    number of rows deleted
270
-     * @throws EE_Error
271
-     */
272
-    public function delete_permanently($query_params, $allow_blocking = true)
273
-    {
274
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
275
-        return parent::delete_permanently($query_params, $allow_blocking);
276
-    }
277
-
278
-
279
-
280
-    /**
281
-     * Restores a particular item by its ID (primary key). Ignores the fact whether the item
282
-     * has been soft-deleted or not.
283
-     *
284
-     * @param mixed $ID int if primary key is an int, string otherwise
285
-     * @return boolean success
286
-     */
287
-    public function restore_by_ID($ID = false)
288
-    {
289
-        return $this->delete_or_restore_by_ID(false, $ID);
290
-    }
291
-
292
-
293
-
294
-    /**
295
-     * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
296
-     * this function will ignore whether the items have been soft-deleted or not.
297
-     *
298
-     * @param boolean $delete true for delete, false for restore
299
-     * @param mixed   $ID     int if primary key is an int, string otherwise
300
-     * @return boolean
301
-     */
302
-    public function delete_or_restore_by_ID($delete = true, $ID = false)
303
-    {
304
-        if (! $ID) {
305
-            return false;
306
-        }
307
-        if (
308
-            $this->delete_or_restore(
309
-                $delete,
310
-                $this->alter_query_params_to_restrict_by_ID($ID)
311
-            )
312
-        ) {
313
-            return true;
314
-        } else {
315
-            return false;
316
-        }
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     * Overrides parent's 'delete' method to instead do a soft delete on all rows that
323
-     * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not.
324
-     * Note: because this item will be soft-deleted only,
325
-     * doesn't block because of model dependencies
326
-     *
327
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
328
-     * @param bool  $block_deletes
329
-     * @return boolean
330
-     */
331
-    public function delete($query_params = array(), $block_deletes = false)
332
-    {
333
-        // no matter what, we WON'T block soft deletes.
334
-        return $this->delete_or_restore(true, $query_params);
335
-    }
336
-
337
-
338
-
339
-    /**
340
-     * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted
341
-     * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not.
342
-     *
343
-     * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
344
-     * @return boolean
345
-     */
346
-    public function restore($query_params = array())
347
-    {
348
-        return $this->delete_or_restore(false, $query_params);
349
-    }
350
-
351
-
352
-
353
-    /**
354
-     * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
355
-     *
356
-     * @param boolean $delete       true to indicate deletion, false to indicate restoration
357
-     * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
358
-     * @return boolean
359
-     */
360
-    public function delete_or_restore($delete = true, $query_params = array())
361
-    {
362
-        $deletedFlagFieldName = $this->deleted_field_name();
363
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
364
-        if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) {
365
-            return true;
366
-        } else {
367
-            return false;
368
-        }
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * Updates all the items of this model which match the $query params, regardless of whether
375
-     * they've been soft-deleted or not
376
-     *
377
-     * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
378
-     * @param array   $query_params            like EEM_base::get_all's $query_params
379
-     * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
380
-     *                                         in this model's entity map according to $fields_n_values that match $query_params. This
381
-     *                                         obviously has some overhead, so you can disable it by setting this to FALSE, but
382
-     *                                         be aware that model objects being used could get out-of-sync with the database
383
-     * @return int number of items updated
384
-     */
385
-    public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
386
-    {
387
-        $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
388
-        return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
389
-    }
29
+	/**
30
+	 * @param null $timezone
31
+	 */
32
+	protected function __construct($timezone = null)
33
+	{
34
+		if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) {
35
+			$this->_default_where_conditions_strategy = new EE_Soft_Delete_Where_Conditions();
36
+		}
37
+		parent::__construct($timezone);
38
+	}
39
+
40
+
41
+
42
+	/**
43
+	 * Searches for field on this model of type 'deleted_flag'. if it is found,
44
+	 * returns it's name.
45
+	 *
46
+	 * @return string
47
+	 * @throws EE_Error
48
+	 */
49
+	public function deleted_field_name()
50
+	{
51
+		$field = $this->get_a_field_of_type('EE_Trashed_Flag_Field');
52
+		if ($field) {
53
+			return $field->get_name();
54
+		} else {
55
+			throw new EE_Error(sprintf(esc_html__(
56
+				'We are trying to find the deleted flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?',
57
+				'event_espresso'
58
+			), get_class($this), get_class($this)));
59
+		}
60
+	}
61
+
62
+
63
+
64
+	/**
65
+	 * Gets one item that's been deleted, according to $query_params
66
+	 *
67
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
68
+	 * @return EE_Soft_Delete_Base_Class
69
+	 */
70
+	public function get_one_deleted($query_params = array())
71
+	{
72
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
73
+		return parent::get_one($query_params);
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 * Gets one item from the DB, regardless of whether it's been soft-deleted or not
80
+	 *
81
+	 * @param array $query_params like EEM_base::get_all's $query_params
82
+	 * @return EE_Soft_Delete_Base_Class
83
+	 */
84
+	public function get_one_deleted_or_undeleted($query_params = array())
85
+	{
86
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
87
+		return parent::get_one($query_params);
88
+	}
89
+
90
+
91
+
92
+	/**
93
+	 * Gets the item indicated by its ID. But if it's soft-deleted, pretends it doesn't exist.
94
+	 *
95
+	 * @param int|string $id
96
+	 * @return EE_Soft_Delete_Base_Class
97
+	 */
98
+	public function get_one_by_ID_but_ignore_deleted($id)
99
+	{
100
+		return $this->get_one(
101
+			$this->alter_query_params_to_restrict_by_ID(
102
+				$id,
103
+				array('default_where_conditions' => 'default')
104
+			)
105
+		);
106
+	}
107
+
108
+
109
+
110
+	/**
111
+	 * Counts all the deleted/trashed items
112
+	 *
113
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
114
+	 * @param string $field_to_count
115
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
116
+	 * @return int
117
+	 */
118
+	public function count_deleted($query_params = null, $field_to_count = null, $distinct = false)
119
+	{
120
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
121
+		return parent::count($query_params, $field_to_count, $distinct);
122
+	}
123
+
124
+
125
+
126
+	/**
127
+	 * Alters the query params so that only trashed/soft-deleted items are considered
128
+	 *
129
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
130
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
131
+	 */
132
+	protected function _alter_query_params_so_only_trashed_items_included($query_params)
133
+	{
134
+		$deletedFlagFieldName = $this->deleted_field_name();
135
+		$query_params[0][ $deletedFlagFieldName ] = true;
136
+		return $query_params;
137
+	}
138
+
139
+
140
+
141
+	/**
142
+	 * Alters the query params so that only trashed/soft-deleted items are considered
143
+	 *
144
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
145
+	 * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
146
+	 */
147
+	public function alter_query_params_so_only_trashed_items_included($query_params)
148
+	{
149
+		return $this->_alter_query_params_so_only_trashed_items_included($query_params);
150
+	}
151
+
152
+
153
+
154
+	/**
155
+	 * Alters the query params so each item's deleted status is ignored.
156
+	 *
157
+	 * @param array $query_params
158
+	 * @return array
159
+	 */
160
+	public function alter_query_params_so_deleted_and_undeleted_items_included($query_params = array())
161
+	{
162
+		return $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * Alters the query params so each item's deleted status is ignored.
169
+	 *
170
+	 * @param array $query_params
171
+	 * @return array
172
+	 */
173
+	protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params)
174
+	{
175
+		if (! isset($query_params['default_where_conditions'])) {
176
+			$query_params['default_where_conditions'] = 'minimum';
177
+		}
178
+		return $query_params;
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 * Counts all deleted and undeleted items
185
+	 *
186
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
187
+	 * @param string $field_to_count
188
+	 * @param bool   $distinct     if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE;
189
+	 * @return int
190
+	 */
191
+	public function count_deleted_and_undeleted($query_params = null, $field_to_count = null, $distinct = false)
192
+	{
193
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
194
+		return parent::count($query_params, $field_to_count, $distinct);
195
+	}
196
+
197
+
198
+
199
+	/**
200
+	 * Sum all the deleted items.
201
+	 *
202
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
203
+	 * @param string $field_to_sum
204
+	 * @return int
205
+	 */
206
+	public function sum_deleted($query_params = null, $field_to_sum = null)
207
+	{
208
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
209
+		return parent::sum($query_params, $field_to_sum);
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * Sums all the deleted and undeleted items.
216
+	 *
217
+	 * @param array  $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
218
+	 * @param string $field_to_sum
219
+	 * @return int
220
+	 */
221
+	public function sum_deleted_and_undeleted($query_params = null, $field_to_sum = null)
222
+	{
223
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
224
+		parent::sum($query_params, $field_to_sum);
225
+	}
226
+
227
+
228
+
229
+	/**
230
+	 * Gets all deleted and undeleted mode objects from the db that meet the criteria, regardless of
231
+	 * whether they've been soft-deleted or not
232
+	 *
233
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
234
+	 * @return EE_Soft_Delete_Base_Class[]
235
+	 */
236
+	public function get_all_deleted_and_undeleted($query_params = array())
237
+	{
238
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
239
+		return parent::get_all($query_params);
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * For 'soft deletable' models, gets all which ARE deleted, according to conditions specified in $query_params.
246
+	 *
247
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
248
+	 * @return EE_Soft_Delete_Base_Class[]
249
+	 */
250
+	public function get_all_deleted($query_params = array())
251
+	{
252
+		$query_params = $this->_alter_query_params_so_only_trashed_items_included($query_params);
253
+		return parent::get_all($query_params);
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * Permanently deletes the selected rows. When selecting rows for deletion, ignores
260
+	 * whether they've been soft-deleted or not. (ie, you don't have to soft-delete objects
261
+	 * before you can permanently delete them).
262
+	 * Because this will cause a real deletion, related models may block this deletion (ie, add an error
263
+	 * and abort the delete)
264
+	 *
265
+	 * @param array   $query_params   @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
266
+	 * @param boolean $allow_blocking if TRUE, matched objects will only be deleted if there is no related model info
267
+	 *                                that blocks it (ie, there' sno other data that depends on this data); if false, deletes regardless of other objects
268
+	 *                                which may depend on it. Its generally advisable to always leave this as TRUE, otherwise you could easily corrupt your DB
269
+	 * @return int                    number of rows deleted
270
+	 * @throws EE_Error
271
+	 */
272
+	public function delete_permanently($query_params, $allow_blocking = true)
273
+	{
274
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
275
+		return parent::delete_permanently($query_params, $allow_blocking);
276
+	}
277
+
278
+
279
+
280
+	/**
281
+	 * Restores a particular item by its ID (primary key). Ignores the fact whether the item
282
+	 * has been soft-deleted or not.
283
+	 *
284
+	 * @param mixed $ID int if primary key is an int, string otherwise
285
+	 * @return boolean success
286
+	 */
287
+	public function restore_by_ID($ID = false)
288
+	{
289
+		return $this->delete_or_restore_by_ID(false, $ID);
290
+	}
291
+
292
+
293
+
294
+	/**
295
+	 * For deleting or restoring a particular item. Note that this model is a SOFT-DELETABLE model! However,
296
+	 * this function will ignore whether the items have been soft-deleted or not.
297
+	 *
298
+	 * @param boolean $delete true for delete, false for restore
299
+	 * @param mixed   $ID     int if primary key is an int, string otherwise
300
+	 * @return boolean
301
+	 */
302
+	public function delete_or_restore_by_ID($delete = true, $ID = false)
303
+	{
304
+		if (! $ID) {
305
+			return false;
306
+		}
307
+		if (
308
+			$this->delete_or_restore(
309
+				$delete,
310
+				$this->alter_query_params_to_restrict_by_ID($ID)
311
+			)
312
+		) {
313
+			return true;
314
+		} else {
315
+			return false;
316
+		}
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 * Overrides parent's 'delete' method to instead do a soft delete on all rows that
323
+	 * meet the criteria in $where_col_n_values. This particular function ignores whether the items have been soft-deleted or not.
324
+	 * Note: because this item will be soft-deleted only,
325
+	 * doesn't block because of model dependencies
326
+	 *
327
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
328
+	 * @param bool  $block_deletes
329
+	 * @return boolean
330
+	 */
331
+	public function delete($query_params = array(), $block_deletes = false)
332
+	{
333
+		// no matter what, we WON'T block soft deletes.
334
+		return $this->delete_or_restore(true, $query_params);
335
+	}
336
+
337
+
338
+
339
+	/**
340
+	 * 'Un-deletes' the chosen items. Note that this model is a SOFT-DELETABLE model! That means that, by default, trashed/soft-deleted
341
+	 * items are ignored in queries. However, this particular function ignores whether the items have been soft-deleted or not.
342
+	 *
343
+	 * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
344
+	 * @return boolean
345
+	 */
346
+	public function restore($query_params = array())
347
+	{
348
+		return $this->delete_or_restore(false, $query_params);
349
+	}
350
+
351
+
352
+
353
+	/**
354
+	 * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered.
355
+	 *
356
+	 * @param boolean $delete       true to indicate deletion, false to indicate restoration
357
+	 * @param array   $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
358
+	 * @return boolean
359
+	 */
360
+	public function delete_or_restore($delete = true, $query_params = array())
361
+	{
362
+		$deletedFlagFieldName = $this->deleted_field_name();
363
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
364
+		if ($this->update(array($deletedFlagFieldName => $delete), $query_params)) {
365
+			return true;
366
+		} else {
367
+			return false;
368
+		}
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * Updates all the items of this model which match the $query params, regardless of whether
375
+	 * they've been soft-deleted or not
376
+	 *
377
+	 * @param array   $fields_n_values         like EEM_Base::update's $fields_n_value
378
+	 * @param array   $query_params            like EEM_base::get_all's $query_params
379
+	 * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects
380
+	 *                                         in this model's entity map according to $fields_n_values that match $query_params. This
381
+	 *                                         obviously has some overhead, so you can disable it by setting this to FALSE, but
382
+	 *                                         be aware that model objects being used could get out-of-sync with the database
383
+	 * @return int number of items updated
384
+	 */
385
+	public function update_deleted_and_undeleted($fields_n_values, $query_params, $keep_model_objs_in_sync = true)
386
+	{
387
+		$query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params);
388
+		return $this->update($fields_n_values, $query_params, $keep_model_objs_in_sync);
389
+	}
390 390
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Class_Tools.helper.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
         } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
31 31
             return $backtrace[3]['class'];
32 32
         } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
33
-            if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
33
+            if (self::$file_line == $backtrace[2]['file'].$backtrace[2]['line']) {
34 34
                 self::$i++;
35 35
             } else {
36 36
                 self::$i = 0;
37
-                self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
37
+                self::$file_line = $backtrace[2]['file'].$backtrace[2]['line'];
38 38
             }
39 39
             // was  class method called via call_user_func ?
40 40
             if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
@@ -45,15 +45,15 @@  discard block
 block discarded – undo
45 45
                         $prefix_chars = strpos($called_class, '_') + 1;
46 46
                         $prefix = substr($called_class, 0, $prefix_chars);
47 47
                         $classname = substr($called_class, $prefix_chars, strlen($called_class));
48
-                        $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48
+                        $classname = $prefix.str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
49 49
                         return $classname;
50 50
                     }
51 51
                 }
52 52
             } else {
53 53
                 $lines = file($backtrace[2]['file']);
54
-                preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line'] - 1 ], $matches);
55
-                if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
56
-                    return $matches[1][ self::$i ];
54
+                preg_match_all('/([a-zA-Z0-9\_]+)::'.$backtrace[2]['function'].'/', $lines[$backtrace[2]['line'] - 1], $matches);
55
+                if (isset($matches[1]) && isset($matches[1][self::$i])) {
56
+                    return $matches[1][self::$i];
57 57
                 }
58 58
             }
59 59
         }
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
         global $wp_filter;
76 76
         $class_names = array();
77 77
         // are any callbacks registered for this hook ?
78
-        if (isset($wp_filter[ $hook ])) {
78
+        if (isset($wp_filter[$hook])) {
79 79
             // loop thru all of the callbacks attached to the deprecated hookpoint
80
-            foreach ($wp_filter[ $hook ] as $priority) {
80
+            foreach ($wp_filter[$hook] as $priority) {
81 81
                 foreach ($priority as $callback) {
82 82
                     // is the callback a non-static class method ?
83 83
                     if (isset($callback['function']) && is_array($callback['function'])) {
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 }
132 132
 
133 133
 // if PHP version < 5.3
134
-if (! function_exists('get_called_class')) {
134
+if ( ! function_exists('get_called_class')) {
135 135
     /**
136 136
      * @return string
137 137
      */
Please login to merge, or discard this patch.
Indentation   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -11,131 +11,131 @@
 block discarded – undo
11 11
  */
12 12
 class EEH_Class_Tools
13 13
 {
14
-    public static $i = 0;
15
-    public static $file_line = null;
14
+	public static $i = 0;
15
+	public static $file_line = null;
16 16
 
17
-    /**
18
-     *  get_called_class - for PHP versions < 5.3
19
-     *
20
-     *  @access     public
21
-     *  @author origins:  http://stackoverflow.com/a/1542045
22
-     *  return string
23
-     */
24
-    public static function get_called_class()
25
-    {
26
-        $backtrace = debug_backtrace();
27
-        if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) {
28
-            return $backtrace[2]['class'];
29
-        } elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
30
-            return $backtrace[3]['class'];
31
-        } elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
32
-            if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
33
-                self::$i++;
34
-            } else {
35
-                self::$i = 0;
36
-                self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
37
-            }
38
-            // was  class method called via call_user_func ?
39
-            if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
40
-                if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) {
41
-                    $called_class = $backtrace[2]['args'][0][0];
42
-                    // is it an EE function ?
43
-                    if (strpos($called_class, 'EE') === 0) {
44
-                        $prefix_chars = strpos($called_class, '_') + 1;
45
-                        $prefix = substr($called_class, 0, $prefix_chars);
46
-                        $classname = substr($called_class, $prefix_chars, strlen($called_class));
47
-                        $classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48
-                        return $classname;
49
-                    }
50
-                }
51
-            } else {
52
-                $lines = file($backtrace[2]['file']);
53
-                preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line'] - 1 ], $matches);
54
-                if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
55
-                    return $matches[1][ self::$i ];
56
-                }
57
-            }
58
-        }
59
-        return false;
60
-    }
17
+	/**
18
+	 *  get_called_class - for PHP versions < 5.3
19
+	 *
20
+	 *  @access     public
21
+	 *  @author origins:  http://stackoverflow.com/a/1542045
22
+	 *  return string
23
+	 */
24
+	public static function get_called_class()
25
+	{
26
+		$backtrace = debug_backtrace();
27
+		if (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['class']) && ! isset($backtrace[2]['file'])) {
28
+			return $backtrace[2]['class'];
29
+		} elseif (isset($backtrace[3]) && is_array($backtrace[3]) && isset($backtrace[3]['class']) && ! isset($backtrace[3]['file'])) {
30
+			return $backtrace[3]['class'];
31
+		} elseif (isset($backtrace[2]) && is_array($backtrace[2]) && isset($backtrace[2]['file']) && isset($backtrace[2]['line'])) {
32
+			if (self::$file_line == $backtrace[2]['file'] . $backtrace[2]['line']) {
33
+				self::$i++;
34
+			} else {
35
+				self::$i = 0;
36
+				self::$file_line = $backtrace[2]['file'] . $backtrace[2]['line'];
37
+			}
38
+			// was  class method called via call_user_func ?
39
+			if ($backtrace[2]['function'] == 'call_user_func' && isset($backtrace[2]['args']) && is_array($backtrace[2]['args'])) {
40
+				if (isset($backtrace[2]['args'][0]) && isset($backtrace[2]['args'][0][0])) {
41
+					$called_class = $backtrace[2]['args'][0][0];
42
+					// is it an EE function ?
43
+					if (strpos($called_class, 'EE') === 0) {
44
+						$prefix_chars = strpos($called_class, '_') + 1;
45
+						$prefix = substr($called_class, 0, $prefix_chars);
46
+						$classname = substr($called_class, $prefix_chars, strlen($called_class));
47
+						$classname = $prefix . str_replace(' ', '_', ucwords(strtolower(str_replace('_', ' ', $classname))));
48
+						return $classname;
49
+					}
50
+				}
51
+			} else {
52
+				$lines = file($backtrace[2]['file']);
53
+				preg_match_all('/([a-zA-Z0-9\_]+)::' . $backtrace[2]['function'] . '/', $lines[ $backtrace[2]['line'] - 1 ], $matches);
54
+				if (isset($matches[1]) && isset($matches[1][ self::$i ])) {
55
+					return $matches[1][ self::$i ];
56
+				}
57
+			}
58
+		}
59
+		return false;
60
+	}
61 61
 
62 62
 
63 63
 
64 64
 
65
-    /**
66
-     *  get_class_names_for_all_callbacks_on_hook
67
-     * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook
68
-     *  @access     public
69
-     *  @param  string  $hook
70
-     *  @return     array
71
-     */
72
-    public static function get_class_names_for_all_callbacks_on_hook($hook = null)
73
-    {
74
-        global $wp_filter;
75
-        $class_names = array();
76
-        // are any callbacks registered for this hook ?
77
-        if (isset($wp_filter[ $hook ])) {
78
-            // loop thru all of the callbacks attached to the deprecated hookpoint
79
-            foreach ($wp_filter[ $hook ] as $priority) {
80
-                foreach ($priority as $callback) {
81
-                    // is the callback a non-static class method ?
82
-                    if (isset($callback['function']) && is_array($callback['function'])) {
83
-                        if (isset($callback['function'][0]) && is_object($callback['function'][0])) {
84
-                            $class_names[] = get_class($callback['function'][0]);
85
-                        }
86
-                    // test for static method
87
-                    } elseif (strpos($callback['function'], '::') !== false) {
88
-                        $class = explode('::', $callback['function']);
89
-                        $class_names[] = $class[0];
90
-                    } else {
91
-                        // just a function
92
-                    }
93
-                }
94
-            }
95
-        }
96
-        return $class_names;
97
-    }
65
+	/**
66
+	 *  get_class_names_for_all_callbacks_on_hook
67
+	 * returns an array of names for all classes that have methods registered as callbacks for the given action or filter hook
68
+	 *  @access     public
69
+	 *  @param  string  $hook
70
+	 *  @return     array
71
+	 */
72
+	public static function get_class_names_for_all_callbacks_on_hook($hook = null)
73
+	{
74
+		global $wp_filter;
75
+		$class_names = array();
76
+		// are any callbacks registered for this hook ?
77
+		if (isset($wp_filter[ $hook ])) {
78
+			// loop thru all of the callbacks attached to the deprecated hookpoint
79
+			foreach ($wp_filter[ $hook ] as $priority) {
80
+				foreach ($priority as $callback) {
81
+					// is the callback a non-static class method ?
82
+					if (isset($callback['function']) && is_array($callback['function'])) {
83
+						if (isset($callback['function'][0]) && is_object($callback['function'][0])) {
84
+							$class_names[] = get_class($callback['function'][0]);
85
+						}
86
+					// test for static method
87
+					} elseif (strpos($callback['function'], '::') !== false) {
88
+						$class = explode('::', $callback['function']);
89
+						$class_names[] = $class[0];
90
+					} else {
91
+						// just a function
92
+					}
93
+				}
94
+			}
95
+		}
96
+		return $class_names;
97
+	}
98 98
 
99 99
 
100 100
 
101 101
 
102
-    /**
103
-     *  property_exists() with fallback for PHP versions < 5.3
104
-     *  @access     public
105
-     *  @param      mixed object | string   $class
106
-     *  @param      string  $property
107
-     *  @return         boolean
108
-     */
109
-    public static function has_property($class = null, $property = null)
110
-    {
111
-        // if $class or $property don't exist, then get out, cuz that would be like... fatal dude
112
-        if (empty($class) || empty($property)) {
113
-            return false;
114
-        }
115
-        // if your hosting company doesn't cut the mustard
116
-        if (version_compare(PHP_VERSION, '5.3.0') < 0) {
117
-            // just in case $class is an actual instantiated object
118
-            if (is_object($class)) {
119
-                return isset($class->{$property}) ? true : false;
120
-            } else {
121
-                // use reflection for < PHP 5.3 to get details using just the class name
122
-                $reflector = new ReflectionClass($class);
123
-                return $reflector->hasProperty($property);
124
-            }
125
-        } else {
126
-            // or try regular property exists method which works as expected in PHP 5.3+
127
-            return property_exists($class, $property);
128
-        }
129
-    }
102
+	/**
103
+	 *  property_exists() with fallback for PHP versions < 5.3
104
+	 *  @access     public
105
+	 *  @param      mixed object | string   $class
106
+	 *  @param      string  $property
107
+	 *  @return         boolean
108
+	 */
109
+	public static function has_property($class = null, $property = null)
110
+	{
111
+		// if $class or $property don't exist, then get out, cuz that would be like... fatal dude
112
+		if (empty($class) || empty($property)) {
113
+			return false;
114
+		}
115
+		// if your hosting company doesn't cut the mustard
116
+		if (version_compare(PHP_VERSION, '5.3.0') < 0) {
117
+			// just in case $class is an actual instantiated object
118
+			if (is_object($class)) {
119
+				return isset($class->{$property}) ? true : false;
120
+			} else {
121
+				// use reflection for < PHP 5.3 to get details using just the class name
122
+				$reflector = new ReflectionClass($class);
123
+				return $reflector->hasProperty($property);
124
+			}
125
+		} else {
126
+			// or try regular property exists method which works as expected in PHP 5.3+
127
+			return property_exists($class, $property);
128
+		}
129
+	}
130 130
 }
131 131
 
132 132
 // if PHP version < 5.3
133 133
 if (! function_exists('get_called_class')) {
134
-    /**
135
-     * @return string
136
-     */
137
-    function get_called_class()
138
-    {
139
-        return EEH_Class_Tools::get_called_class();
140
-    }
134
+	/**
135
+	 * @return string
136
+	 */
137
+	function get_called_class()
138
+	{
139
+		return EEH_Class_Tools::get_called_class();
140
+	}
141 141
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Inflector.helper.php 2 patches
Indentation   +380 added lines, -380 removed lines patch added patch discarded remove patch
@@ -33,384 +33,384 @@
 block discarded – undo
33 33
  */
34 34
 class EEH_Inflector
35 35
 {
36
-    // ------ CLASS METHODS ------ //
37
-    // ---- Public methods ---- //
38
-    // {{{ pluralize()
39
-
40
-    /**
41
-     * Just calls self::pluralize and strtolower on $word and returns it
42
-     * @param string $word
43
-     * @return string
44
-     */
45
-    public static function pluralize_and_lower($word)
46
-    {
47
-        return strtolower(self::pluralize($word));
48
-    }
49
-
50
-
51
-
52
-    /**
53
-     * @param string $word
54
-     * @return mixed
55
-     */
56
-    public static function singularize_and_upper($word)
57
-    {
58
-        return str_replace(' ', '_', self::humanize(self::singularize($word), 'all'));
59
-    }
60
-
61
-
62
-
63
-    /**
64
-     * Pluralizes English nouns.
65
-     *
66
-     * @access public
67
-     * @static
68
-     * @param    string    $word    English noun to pluralize
69
-     * @return string Plural noun
70
-     */
71
-    public static function pluralize($word)
72
-    {
73
-        $plural = array(
74
-            '/(quiz)$/i'               => '\1zes',
75
-            '/^(ox)$/i'                => '\1en',
76
-            '/([m|l])ouse$/i'          => '\1ice',
77
-            '/(matr|vert|ind)ix|ex$/i' => '\1ices',
78
-            '/(x|ch|ss|sh)$/i'         => '\1es',
79
-            '/([^aeiouy]|qu)ies$/i'    => '\1y',
80
-            '/([^aeiouy]|qu)y$/i'      => '\1ies',
81
-            '/(hive)$/i'               => '\1s',
82
-            '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
83
-            '/sis$/i'                  => 'ses',
84
-            '/([ti])um$/i'             => '\1a',
85
-            '/(buffal|tomat)o$/i'      => '\1oes',
86
-            '/(bu)s$/i'                => '\1ses',
87
-            '/(alias|status)/i'        => '\1es',
88
-            '/(octop|vir)us$/i'        => '\1i',
89
-            '/(ax|test)is$/i'          => '\1es',
90
-            '/s$/i'                    => 's',
91
-            '/$/'                      => 's');
92
-
93
-        $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
94
-
95
-        $irregular = array(
96
-            'person' => 'people',
97
-            'man'    => 'men',
98
-            'child'  => 'children',
99
-            'sex'    => 'sexes',
100
-            'move'   => 'moves');
101
-
102
-        $lowercased_word = strtolower($word);
103
-
104
-        foreach ($uncountable as $_uncountable) {
105
-            if (
106
-                substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
107
-                    ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ])
108
-            ) {
109
-                return $word;
110
-            }
111
-        }
112
-
113
-        foreach ($irregular as $_plural => $_singular) {
114
-            if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
115
-                return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
116
-            }
117
-        }
118
-
119
-        foreach ($plural as $rule => $replacement) {
120
-            if (preg_match($rule, $word)) {
121
-                return preg_replace($rule, $replacement, $word);
122
-            }
123
-        }
124
-        return false;
125
-    }
126
-
127
-    // }}}
128
-    // {{{ singularize()
129
-
130
-    /**
131
-     * Singularizes English nouns.
132
-     *
133
-     * @access public
134
-     * @static
135
-     * @param    string    $word    English noun to singularize
136
-     * @return string Singular noun.
137
-     */
138
-    public static function singularize($word)
139
-    {
140
-        $singular = array(
141
-            '/(quiz)zes$/i'                                                    => '\1',
142
-            '/(matr)ices$/i'                                                   => '\1ix',
143
-            '/(vert|ind)ices$/i'                                               => '\1ex',
144
-            '/^(ox)en/i'                                                       => '\1',
145
-            '/(alias|status)es$/i'                                             => '\1',
146
-            '/([octop|vir])i$/i'                                               => '\1us',
147
-            '/(cris|ax|test)es$/i'                                             => '\1is',
148
-            '/(shoe)s$/i'                                                      => '\1',
149
-            '/(o)es$/i'                                                        => '\1',
150
-            '/(bus)es$/i'                                                      => '\1',
151
-            '/([m|l])ice$/i'                                                   => '\1ouse',
152
-            '/(x|ch|ss|sh)es$/i'                                               => '\1',
153
-            '/(m)ovies$/i'                                                     => '\1ovie',
154
-            '/(s)eries$/i'                                                     => '\1eries',
155
-            '/([^aeiouy]|qu)ies$/i'                                            => '\1y',
156
-            '/([lr])ves$/i'                                                    => '\1f',
157
-            '/(tive)s$/i'                                                      => '\1',
158
-            '/(hive)s$/i'                                                      => '\1',
159
-            '/([^f])ves$/i'                                                    => '\1fe',
160
-            '/(^analy)ses$/i'                                                  => '\1sis',
161
-            '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
162
-            '/([ti])a$/i'                                                      => '\1um',
163
-            '/(n)ews$/i'                                                       => '\1ews',
164
-            '/s$/i'                                                            => '',
165
-        );
166
-
167
-        $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
168
-
169
-        $irregular = array(
170
-            'person' => 'people',
171
-            'man'    => 'men',
172
-            'child'  => 'children',
173
-            'sex'    => 'sexes',
174
-            'move'   => 'moves');
175
-
176
-        $lowercased_word = strtolower($word);
177
-        foreach ($uncountable as $_uncountable) {
178
-            if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
179
-                return $word;
180
-            }
181
-        }
182
-
183
-        foreach ($irregular as $_plural => $_singular) {
184
-            if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
185
-                return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
186
-            }
187
-        }
188
-
189
-        foreach ($singular as $rule => $replacement) {
190
-            if (preg_match($rule, $word)) {
191
-                return preg_replace($rule, $replacement, $word);
192
-            }
193
-        }
194
-
195
-        return $word;
196
-    }
197
-
198
-    // }}}
199
-    // {{{ titleize()
200
-
201
-    /**
202
-     * Converts an underscored or CamelCase word into a English
203
-     * sentence.
204
-     *
205
-     * The titleize static function converts text like "WelcomePage",
206
-     * "welcome_page" or  "welcome page" to this "Welcome
207
-     * Page".
208
-     * If second parameter is set to 'first' it will only
209
-     * capitalize the first character of the title.
210
-     *
211
-     * @access public
212
-     * @static
213
-     * @param    string    $word    Word to format as tile
214
-     * @param    string    $uppercase    If set to 'first' it will only uppercase the
215
-     * first character. Otherwise it will uppercase all
216
-     * the words in the title.
217
-     * @return string Text formatted as title
218
-     */
219
-    public static function titleize($word, $uppercase = '')
220
-    {
221
-        $uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords';
222
-        return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word)));
223
-    }
224
-
225
-    // }}}
226
-    // {{{ camelize()
227
-
228
-    /**
229
-     * Returns given word as CamelCased
230
-     *
231
-     * Converts a word like "send_email" to "SendEmail". It
232
-     * will remove non alphanumeric character from the word, so
233
-     * "who's online" will be converted to "WhoSOnline"
234
-     *
235
-     * @access public
236
-     * @static
237
-     * @see variablize
238
-     * @param    string    $word    Word to convert to camel case
239
-     * @return string UpperCamelCasedWord
240
-     */
241
-    public static function camelize($word)
242
-    {
243
-        return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word)));
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention
250
-     * with the new PSR-based naming conventions
251
-     * @param $word
252
-     * @return string
253
-     */
254
-    public static function camelize_all_but_first($word)
255
-    {
256
-        return lcfirst(EEH_Inflector::camelize($word));
257
-    }
258
-    // }}}
259
-    // {{{ underscore()
260
-
261
-    /**
262
-     * Converts a word "into_it_s_underscored_version"
263
-     *
264
-     * Convert any "CamelCased" or "ordinary Word" into an
265
-     * "underscored_word".
266
-     *
267
-     * This can be really useful for creating friendly URLs.
268
-     *
269
-     * @access public
270
-     * @static
271
-     * @param    string    $word    Word to underscore
272
-     * @return string Underscored word
273
-     */
274
-    public static function underscore($word)
275
-    {
276
-        return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word))));
277
-    }
278
-
279
-    // }}}
280
-    // {{{ humanize()
281
-
282
-    /**
283
-     * Returns a human-readable string from $word
284
-     *
285
-     * Returns a human-readable string from $word, by replacing
286
-     * underscores with a space, and by upper-casing the initial
287
-     * character by default.
288
-     *
289
-     * If you need to uppercase all the words you just have to
290
-     * pass 'all' as a second parameter.
291
-     *
292
-     * @access public
293
-     * @static
294
-     * @param    string    $word    String to "humanize"
295
-     * @param    string    $uppercase    If set to 'all' it will uppercase all the words
296
-     * instead of just the first one.
297
-     * @return string Human-readable word
298
-     */
299
-    public static function humanize($word, $uppercase = '')
300
-    {
301
-        // make special exceptions for acronyms
302
-        $word = str_replace('wp_', 'WP_', $word);
303
-        $uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst';
304
-        return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word)));
305
-    }
306
-
307
-    // }}}
308
-    // {{{ variablize()
309
-
310
-    /**
311
-     * Same as camelize but first char is underscored
312
-     *
313
-     * Converts a word like "send_email" to "sendEmail". It
314
-     * will remove non alphanumeric character from the word, so
315
-     * "who's online" will be converted to "whoSOnline"
316
-     *
317
-     * @access public
318
-     * @static
319
-     * @see camelize
320
-     * @param    string    $word    Word to lowerCamelCase
321
-     * @return string Returns a lowerCamelCasedWord
322
-     */
323
-    public static function variablize($word)
324
-    {
325
-        $word = EEH_Inflector::camelize($word);
326
-        return strtolower($word[0]) . substr($word, 1);
327
-    }
328
-
329
-    // }}}
330
-    // {{{ tableize()
331
-
332
-    /**
333
-     * Converts a class name to its table name according to rails
334
-     * naming conventions.
335
-     *
336
-     * Converts "Person" to "people"
337
-     *
338
-     * @access public
339
-     * @static
340
-     * @see classify
341
-     * @param    string    $class_name    Class name for getting related table_name.
342
-     * @return string plural_table_name
343
-     */
344
-    public static function tableize($class_name)
345
-    {
346
-        return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name));
347
-    }
348
-
349
-    // }}}
350
-    // {{{ classify()
351
-
352
-    /**
353
-     * Converts a table name to its class name according to rails
354
-     * naming conventions.
355
-     *
356
-     * Converts "people" to "Person"
357
-     *
358
-     * @access public
359
-     * @static
360
-     * @see tableize
361
-     * @param    string    $table_name    Table name for getting related ClassName.
362
-     * @return string SingularClassName
363
-     */
364
-    public static function classify($table_name)
365
-    {
366
-        return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name));
367
-    }
368
-
369
-    // }}}
370
-    // {{{ ordinalize()
371
-
372
-    /**
373
-     * Converts number to its ordinal English form.
374
-     *
375
-     * This method converts 13 to 13th, 2 to 2nd ...
376
-     *
377
-     * @access public
378
-     * @static
379
-     * @param    integer    $number    Number to get its ordinal value
380
-     * @return string Ordinal representation of given string.
381
-     */
382
-    public static function ordinalize($number)
383
-    {
384
-        if (in_array(($number % 100), range(11, 13))) {
385
-            return $number . 'th';
386
-        } else {
387
-            switch (($number % 10)) {
388
-                case 1:
389
-                    return $number . 'st';
390
-                    break;
391
-                case 2:
392
-                    return $number . 'nd';
393
-                    break;
394
-                case 3:
395
-                    return $number . 'rd';
396
-                default:
397
-                    return $number . 'th';
398
-                    break;
399
-            }
400
-        }
401
-    }
402
-
403
-
404
-
405
-    /**
406
-     * @param $string
407
-     * @return string
408
-     */
409
-    public static function add_indefinite_article($string)
410
-    {
411
-        if (strtolower($string) === 'null') {
412
-            return $string;
413
-        }
414
-        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
415
-    }
36
+	// ------ CLASS METHODS ------ //
37
+	// ---- Public methods ---- //
38
+	// {{{ pluralize()
39
+
40
+	/**
41
+	 * Just calls self::pluralize and strtolower on $word and returns it
42
+	 * @param string $word
43
+	 * @return string
44
+	 */
45
+	public static function pluralize_and_lower($word)
46
+	{
47
+		return strtolower(self::pluralize($word));
48
+	}
49
+
50
+
51
+
52
+	/**
53
+	 * @param string $word
54
+	 * @return mixed
55
+	 */
56
+	public static function singularize_and_upper($word)
57
+	{
58
+		return str_replace(' ', '_', self::humanize(self::singularize($word), 'all'));
59
+	}
60
+
61
+
62
+
63
+	/**
64
+	 * Pluralizes English nouns.
65
+	 *
66
+	 * @access public
67
+	 * @static
68
+	 * @param    string    $word    English noun to pluralize
69
+	 * @return string Plural noun
70
+	 */
71
+	public static function pluralize($word)
72
+	{
73
+		$plural = array(
74
+			'/(quiz)$/i'               => '\1zes',
75
+			'/^(ox)$/i'                => '\1en',
76
+			'/([m|l])ouse$/i'          => '\1ice',
77
+			'/(matr|vert|ind)ix|ex$/i' => '\1ices',
78
+			'/(x|ch|ss|sh)$/i'         => '\1es',
79
+			'/([^aeiouy]|qu)ies$/i'    => '\1y',
80
+			'/([^aeiouy]|qu)y$/i'      => '\1ies',
81
+			'/(hive)$/i'               => '\1s',
82
+			'/(?:([^f])fe|([lr])f)$/i' => '\1\2ves',
83
+			'/sis$/i'                  => 'ses',
84
+			'/([ti])um$/i'             => '\1a',
85
+			'/(buffal|tomat)o$/i'      => '\1oes',
86
+			'/(bu)s$/i'                => '\1ses',
87
+			'/(alias|status)/i'        => '\1es',
88
+			'/(octop|vir)us$/i'        => '\1i',
89
+			'/(ax|test)is$/i'          => '\1es',
90
+			'/s$/i'                    => 's',
91
+			'/$/'                      => 's');
92
+
93
+		$uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
94
+
95
+		$irregular = array(
96
+			'person' => 'people',
97
+			'man'    => 'men',
98
+			'child'  => 'children',
99
+			'sex'    => 'sexes',
100
+			'move'   => 'moves');
101
+
102
+		$lowercased_word = strtolower($word);
103
+
104
+		foreach ($uncountable as $_uncountable) {
105
+			if (
106
+				substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
107
+					! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ])
108
+			) {
109
+				return $word;
110
+			}
111
+		}
112
+
113
+		foreach ($irregular as $_plural => $_singular) {
114
+			if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
115
+				return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
116
+			}
117
+		}
118
+
119
+		foreach ($plural as $rule => $replacement) {
120
+			if (preg_match($rule, $word)) {
121
+				return preg_replace($rule, $replacement, $word);
122
+			}
123
+		}
124
+		return false;
125
+	}
126
+
127
+	// }}}
128
+	// {{{ singularize()
129
+
130
+	/**
131
+	 * Singularizes English nouns.
132
+	 *
133
+	 * @access public
134
+	 * @static
135
+	 * @param    string    $word    English noun to singularize
136
+	 * @return string Singular noun.
137
+	 */
138
+	public static function singularize($word)
139
+	{
140
+		$singular = array(
141
+			'/(quiz)zes$/i'                                                    => '\1',
142
+			'/(matr)ices$/i'                                                   => '\1ix',
143
+			'/(vert|ind)ices$/i'                                               => '\1ex',
144
+			'/^(ox)en/i'                                                       => '\1',
145
+			'/(alias|status)es$/i'                                             => '\1',
146
+			'/([octop|vir])i$/i'                                               => '\1us',
147
+			'/(cris|ax|test)es$/i'                                             => '\1is',
148
+			'/(shoe)s$/i'                                                      => '\1',
149
+			'/(o)es$/i'                                                        => '\1',
150
+			'/(bus)es$/i'                                                      => '\1',
151
+			'/([m|l])ice$/i'                                                   => '\1ouse',
152
+			'/(x|ch|ss|sh)es$/i'                                               => '\1',
153
+			'/(m)ovies$/i'                                                     => '\1ovie',
154
+			'/(s)eries$/i'                                                     => '\1eries',
155
+			'/([^aeiouy]|qu)ies$/i'                                            => '\1y',
156
+			'/([lr])ves$/i'                                                    => '\1f',
157
+			'/(tive)s$/i'                                                      => '\1',
158
+			'/(hive)s$/i'                                                      => '\1',
159
+			'/([^f])ves$/i'                                                    => '\1fe',
160
+			'/(^analy)ses$/i'                                                  => '\1sis',
161
+			'/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis',
162
+			'/([ti])a$/i'                                                      => '\1um',
163
+			'/(n)ews$/i'                                                       => '\1ews',
164
+			'/s$/i'                                                            => '',
165
+		);
166
+
167
+		$uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep');
168
+
169
+		$irregular = array(
170
+			'person' => 'people',
171
+			'man'    => 'men',
172
+			'child'  => 'children',
173
+			'sex'    => 'sexes',
174
+			'move'   => 'moves');
175
+
176
+		$lowercased_word = strtolower($word);
177
+		foreach ($uncountable as $_uncountable) {
178
+			if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) {
179
+				return $word;
180
+			}
181
+		}
182
+
183
+		foreach ($irregular as $_plural => $_singular) {
184
+			if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
185
+				return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
186
+			}
187
+		}
188
+
189
+		foreach ($singular as $rule => $replacement) {
190
+			if (preg_match($rule, $word)) {
191
+				return preg_replace($rule, $replacement, $word);
192
+			}
193
+		}
194
+
195
+		return $word;
196
+	}
197
+
198
+	// }}}
199
+	// {{{ titleize()
200
+
201
+	/**
202
+	 * Converts an underscored or CamelCase word into a English
203
+	 * sentence.
204
+	 *
205
+	 * The titleize static function converts text like "WelcomePage",
206
+	 * "welcome_page" or  "welcome page" to this "Welcome
207
+	 * Page".
208
+	 * If second parameter is set to 'first' it will only
209
+	 * capitalize the first character of the title.
210
+	 *
211
+	 * @access public
212
+	 * @static
213
+	 * @param    string    $word    Word to format as tile
214
+	 * @param    string    $uppercase    If set to 'first' it will only uppercase the
215
+	 * first character. Otherwise it will uppercase all
216
+	 * the words in the title.
217
+	 * @return string Text formatted as title
218
+	 */
219
+	public static function titleize($word, $uppercase = '')
220
+	{
221
+		$uppercase = $uppercase === 'first' ? 'ucfirst' : 'ucwords';
222
+		return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word)));
223
+	}
224
+
225
+	// }}}
226
+	// {{{ camelize()
227
+
228
+	/**
229
+	 * Returns given word as CamelCased
230
+	 *
231
+	 * Converts a word like "send_email" to "SendEmail". It
232
+	 * will remove non alphanumeric character from the word, so
233
+	 * "who's online" will be converted to "WhoSOnline"
234
+	 *
235
+	 * @access public
236
+	 * @static
237
+	 * @see variablize
238
+	 * @param    string    $word    Word to convert to camel case
239
+	 * @return string UpperCamelCasedWord
240
+	 */
241
+	public static function camelize($word)
242
+	{
243
+		return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word)));
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * Camelizes all but the first word. This is handy converting a method which followed EE4 legacy naming convention
250
+	 * with the new PSR-based naming conventions
251
+	 * @param $word
252
+	 * @return string
253
+	 */
254
+	public static function camelize_all_but_first($word)
255
+	{
256
+		return lcfirst(EEH_Inflector::camelize($word));
257
+	}
258
+	// }}}
259
+	// {{{ underscore()
260
+
261
+	/**
262
+	 * Converts a word "into_it_s_underscored_version"
263
+	 *
264
+	 * Convert any "CamelCased" or "ordinary Word" into an
265
+	 * "underscored_word".
266
+	 *
267
+	 * This can be really useful for creating friendly URLs.
268
+	 *
269
+	 * @access public
270
+	 * @static
271
+	 * @param    string    $word    Word to underscore
272
+	 * @return string Underscored word
273
+	 */
274
+	public static function underscore($word)
275
+	{
276
+		return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word))));
277
+	}
278
+
279
+	// }}}
280
+	// {{{ humanize()
281
+
282
+	/**
283
+	 * Returns a human-readable string from $word
284
+	 *
285
+	 * Returns a human-readable string from $word, by replacing
286
+	 * underscores with a space, and by upper-casing the initial
287
+	 * character by default.
288
+	 *
289
+	 * If you need to uppercase all the words you just have to
290
+	 * pass 'all' as a second parameter.
291
+	 *
292
+	 * @access public
293
+	 * @static
294
+	 * @param    string    $word    String to "humanize"
295
+	 * @param    string    $uppercase    If set to 'all' it will uppercase all the words
296
+	 * instead of just the first one.
297
+	 * @return string Human-readable word
298
+	 */
299
+	public static function humanize($word, $uppercase = '')
300
+	{
301
+		// make special exceptions for acronyms
302
+		$word = str_replace('wp_', 'WP_', $word);
303
+		$uppercase = $uppercase === 'all' ? 'ucwords' : 'ucfirst';
304
+		return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word)));
305
+	}
306
+
307
+	// }}}
308
+	// {{{ variablize()
309
+
310
+	/**
311
+	 * Same as camelize but first char is underscored
312
+	 *
313
+	 * Converts a word like "send_email" to "sendEmail". It
314
+	 * will remove non alphanumeric character from the word, so
315
+	 * "who's online" will be converted to "whoSOnline"
316
+	 *
317
+	 * @access public
318
+	 * @static
319
+	 * @see camelize
320
+	 * @param    string    $word    Word to lowerCamelCase
321
+	 * @return string Returns a lowerCamelCasedWord
322
+	 */
323
+	public static function variablize($word)
324
+	{
325
+		$word = EEH_Inflector::camelize($word);
326
+		return strtolower($word[0]) . substr($word, 1);
327
+	}
328
+
329
+	// }}}
330
+	// {{{ tableize()
331
+
332
+	/**
333
+	 * Converts a class name to its table name according to rails
334
+	 * naming conventions.
335
+	 *
336
+	 * Converts "Person" to "people"
337
+	 *
338
+	 * @access public
339
+	 * @static
340
+	 * @see classify
341
+	 * @param    string    $class_name    Class name for getting related table_name.
342
+	 * @return string plural_table_name
343
+	 */
344
+	public static function tableize($class_name)
345
+	{
346
+		return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name));
347
+	}
348
+
349
+	// }}}
350
+	// {{{ classify()
351
+
352
+	/**
353
+	 * Converts a table name to its class name according to rails
354
+	 * naming conventions.
355
+	 *
356
+	 * Converts "people" to "Person"
357
+	 *
358
+	 * @access public
359
+	 * @static
360
+	 * @see tableize
361
+	 * @param    string    $table_name    Table name for getting related ClassName.
362
+	 * @return string SingularClassName
363
+	 */
364
+	public static function classify($table_name)
365
+	{
366
+		return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name));
367
+	}
368
+
369
+	// }}}
370
+	// {{{ ordinalize()
371
+
372
+	/**
373
+	 * Converts number to its ordinal English form.
374
+	 *
375
+	 * This method converts 13 to 13th, 2 to 2nd ...
376
+	 *
377
+	 * @access public
378
+	 * @static
379
+	 * @param    integer    $number    Number to get its ordinal value
380
+	 * @return string Ordinal representation of given string.
381
+	 */
382
+	public static function ordinalize($number)
383
+	{
384
+		if (in_array(($number % 100), range(11, 13))) {
385
+			return $number . 'th';
386
+		} else {
387
+			switch (($number % 10)) {
388
+				case 1:
389
+					return $number . 'st';
390
+					break;
391
+				case 2:
392
+					return $number . 'nd';
393
+					break;
394
+				case 3:
395
+					return $number . 'rd';
396
+				default:
397
+					return $number . 'th';
398
+					break;
399
+			}
400
+		}
401
+	}
402
+
403
+
404
+
405
+	/**
406
+	 * @param $string
407
+	 * @return string
408
+	 */
409
+	public static function add_indefinite_article($string)
410
+	{
411
+		if (strtolower($string) === 'null') {
412
+			return $string;
413
+		}
414
+		return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
415
+	}
416 416
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -104,15 +104,15 @@  discard block
 block discarded – undo
104 104
         foreach ($uncountable as $_uncountable) {
105 105
             if (
106 106
                 substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && // even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter
107
-                    ! ctype_alpha($lowercased_word[ strlen($lowercased_word) - strlen($_uncountable) ])
107
+                    ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)])
108 108
             ) {
109 109
                 return $word;
110 110
             }
111 111
         }
112 112
 
113 113
         foreach ($irregular as $_plural => $_singular) {
114
-            if (preg_match('/(' . $_plural . ')$/i', $word, $arr)) {
115
-                return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word);
114
+            if (preg_match('/('.$_plural.')$/i', $word, $arr)) {
115
+                return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word);
116 116
             }
117 117
         }
118 118
 
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
         }
182 182
 
183 183
         foreach ($irregular as $_plural => $_singular) {
184
-            if (preg_match('/(' . $_singular . ')$/i', $word, $arr)) {
185
-                return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word);
184
+            if (preg_match('/('.$_singular.')$/i', $word, $arr)) {
185
+                return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word);
186 186
             }
187 187
         }
188 188
 
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
     public static function variablize($word)
324 324
     {
325 325
         $word = EEH_Inflector::camelize($word);
326
-        return strtolower($word[0]) . substr($word, 1);
326
+        return strtolower($word[0]).substr($word, 1);
327 327
     }
328 328
 
329 329
     // }}}
@@ -382,19 +382,19 @@  discard block
 block discarded – undo
382 382
     public static function ordinalize($number)
383 383
     {
384 384
         if (in_array(($number % 100), range(11, 13))) {
385
-            return $number . 'th';
385
+            return $number.'th';
386 386
         } else {
387 387
             switch (($number % 10)) {
388 388
                 case 1:
389
-                    return $number . 'st';
389
+                    return $number.'st';
390 390
                     break;
391 391
                 case 2:
392
-                    return $number . 'nd';
392
+                    return $number.'nd';
393 393
                     break;
394 394
                 case 3:
395
-                    return $number . 'rd';
395
+                    return $number.'rd';
396 396
                 default:
397
-                    return $number . 'th';
397
+                    return $number.'th';
398 398
                     break;
399 399
             }
400 400
         }
@@ -411,6 +411,6 @@  discard block
 block discarded – undo
411 411
         if (strtolower($string) === 'null') {
412 412
             return $string;
413 413
         }
414
-        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ') . $string;
414
+        return (stripos('aeiou', $string[0]) !== false ? 'an ' : 'a ').$string;
415 415
     }
416 416
 }
Please login to merge, or discard this patch.
core/helpers/EEH_Parse_Shortcodes.helper.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
                 if ($sc_obj instanceof EE_Shortcodes) {
209 209
                     // we need to setup any dynamic shortcodes so that they work with the array_key_exists
210 210
                     preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
211
-                    $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
211
+                    $sc_to_verify = ! empty($matches[0]) ? $matches[0][0].']' : $shortcode;
212 212
 
213
-                    if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) {
213
+                    if ( ! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) {
214 214
                         continue; // the given shortcode isn't in this object
215 215
                     }
216 216
 
217 217
                     // if this isn't  a "list" type shortcode then we'll send along the data vanilla instead of in an array.
218
-                    if (! in_array($sc_to_verify, $list_type_shortcodes)) {
218
+                    if ( ! in_array($sc_to_verify, $list_type_shortcodes)) {
219 219
                         $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data;
220 220
                     } else {
221 221
                         $data_send = $this->_data;
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         foreach ($valid_shortcodes as $shortcode_ref) {
272 272
             $ref       = ucwords(str_replace('_', ' ', $shortcode_ref));
273 273
             $ref       = str_replace(' ', '_', $ref);
274
-            $classname = 'EE_' . $ref . '_Shortcodes';
274
+            $classname = 'EE_'.$ref.'_Shortcodes';
275 275
             if (class_exists($classname)) {
276 276
                 $this->_shortcode_objs[] = new $classname();
277 277
             }
Please login to merge, or discard this patch.
Indentation   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -11,268 +11,268 @@
 block discarded – undo
11 11
  */
12 12
 class EEH_Parse_Shortcodes
13 13
 {
14
-    /**
15
-     * holds the template
16
-     *
17
-     * @access private
18
-     * @var mixed (string|array)
19
-     */
20
-    private $_template;
21
-
22
-
23
-    /**
24
-     * holds the incoming data object
25
-     *
26
-     * @access private
27
-     * @var object
28
-     */
29
-    private $_data;
30
-
31
-
32
-    /**
33
-     * will hold an array of EE_Shortcodes library objects.
34
-     *
35
-     * @access private
36
-     * @var EE_Shortcodes[]
37
-     */
38
-    private $_shortcode_objs = array();
39
-
40
-
41
-    public function __construct()
42
-    {
43
-    }
44
-
45
-
46
-    /**
47
-     * This kicks off the parsing of shortcodes in message templates
48
-     *
49
-     * @param  string                $template         This is the incoming string to be parsed
50
-     * @param  EE_Messages_Addressee $data             This is the incoming data object
51
-     * @param  array                 $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries
52
-     * @param EE_message_type        $message_type     The message type that called the parser
53
-     * @param EE_messenger           $messenger        The active messenger for this parsing session.
54
-     * @param EE_Message             $message
55
-     * @return string                   The parsed template string
56
-     */
57
-    public function parse_message_template(
58
-        $template,
59
-        EE_Messages_Addressee $data,
60
-        $valid_shortcodes,
61
-        EE_message_type $message_type,
62
-        EE_messenger $messenger,
63
-        EE_Message $message
64
-    ) {
65
-        $extra_data = array(
66
-            'messenger'    => $messenger,
67
-            'message_type' => $message_type,
68
-            'message'      => $message,
69
-        );
70
-        $this->_init_data($template, $data, $valid_shortcodes, $extra_data);
71
-        $this->_template = is_array($template) ? $template['main'] : $template;
72
-        return $this->_parse_message_template();
73
-    }
74
-
75
-
76
-    public function parse_attendee_list_template(
77
-        $template,
78
-        EE_Registration $registration,
79
-        $valid_shortcodes,
80
-        $extra_data = array()
81
-    ) {
82
-        $this->_init_data($template, $registration, $valid_shortcodes, $extra_data);
83
-        $this->_template = is_array($template) ? $template['attendee_list'] : $template;
84
-        return $this->_parse_message_template();
85
-    }
86
-
87
-    public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array())
88
-    {
89
-        $this->_init_data($template, $event, $valid_shortcodes, $extra_data);
90
-        $this->_template = is_array($template) ? $template['event_list'] : $template;
91
-        return $this->_parse_message_template();
92
-    }
93
-
94
-
95
-    public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array())
96
-    {
97
-        $this->_init_data($template, $ticket, $valid_shortcodes, $extra_data);
98
-        $this->_template = is_array($template) ? $template['ticket_list'] : $template;
99
-        return $this->_parse_message_template();
100
-    }
101
-
102
-
103
-    public function parse_line_item_list_template(
104
-        $template,
105
-        EE_Line_Item $line_item,
106
-        $valid_shortcodes,
107
-        $extra_data = array()
108
-    ) {
109
-        $this->_init_data($template, $line_item, $valid_shortcodes, $extra_data);
110
-        $this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template;
111
-        return $this->_parse_message_template();
112
-    }
113
-
114
-
115
-    public function parse_payment_list_template(
116
-        $template,
117
-        EE_Payment $payment_item,
118
-        $valid_shortcodes,
119
-        $extra_data = array()
120
-    ) {
121
-        $this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data);
122
-        $this->_template = is_array($template) ? $template['payment_list'] : $template;
123
-        return $this->_parse_message_template();
124
-    }
125
-
126
-
127
-    public function parse_datetime_list_template(
128
-        $template,
129
-        EE_Datetime $datetime,
130
-        $valid_shortcodes,
131
-        $extra_data = array()
132
-    ) {
133
-        $this->_init_data($template, $datetime, $valid_shortcodes, $extra_data);
134
-        $this->_template = is_array($template) ? $template['datetime_list'] : $template;
135
-        return $this->_parse_message_template();
136
-    }
137
-
138
-
139
-    public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array())
140
-    {
141
-        $this->_init_data($template, $answer, $valid_shortcodes, $extra_data);
142
-        $this->_template = is_array($template) ? $template['question_list'] : $template;
143
-        return $this->_parse_message_template();
144
-    }
145
-
146
-
147
-    private function _init_data($template, $data, $valid_shortcodes, $extra_data = array())
148
-    {
149
-        $this->_reset_props();
150
-        $this->_data['template']   = $template;
151
-        $this->_data['data']       = $data;
152
-        $this->_data['extra_data'] = $extra_data;
153
-        $this->_set_shortcodes($valid_shortcodes);
154
-    }
155
-
156
-
157
-    private function _reset_props()
158
-    {
159
-        $this->_template       = $this->_data = null;
160
-        $this->_shortcode_objs = array();
161
-    }
162
-
163
-
164
-    /**
165
-     * takes the given template and parses it with the $_shortcodes property
166
-     *
167
-     * @access private
168
-     * @return string
169
-     */
170
-    private function _parse_message_template()
171
-    {
172
-        // now let's get a list of shortcodes that are found in the given template
173
-        preg_match_all('/(\[.+?\])/', $this->_template, $matches);
174
-        $shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string.
175
-
176
-        $matched_code = array();
177
-        $sc_values    = array();
178
-
179
-        $list_type_shortcodes = array(
180
-            '[ATTENDEE_LIST]',
181
-            '[EVENT_LIST]',
182
-            '[TICKET_LIST]',
183
-            '[DATETIME_LIST]',
184
-            '[QUESTION_LIST]',
185
-            '[RECIPIENT_QUESTION_LIST]',
186
-            '[PRIMARY_REGISTRANT_QUESTION_LIST]',
187
-            '[RECIPIENT_TICKET_LIST]',
188
-            '[PRIMARY_REGISTRANT_TICKET_LIST]',
189
-            '[RECIPIENT_DATETIME_LIST]',
190
-            '[PRIMARY_REGISTRANT_DATETIME_LIST]',
191
-            '[TICKET_LINE_ITEM_LIST]',
192
-            '[TAX_LINE_ITEM_LIST]',
193
-            '[ADDITIONAL_LINE_ITEM_LIST]',
194
-            '[PRICE_MODIFIER_LINE_ITEM_LIST]',
195
-            '[PAYMENT_LIST_*]',
196
-        );
197
-
198
-        $list_type_shortcodes = apply_filters(
199
-            'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes',
200
-            $list_type_shortcodes
201
-        );
202
-
203
-        // now lets go ahead and loop through our parsers for each shortcode and setup the values
204
-        foreach ($shortcodes as $shortcode) {
205
-            foreach ($this->_shortcode_objs as $sc_obj) {
206
-                if ($sc_obj instanceof EE_Shortcodes) {
207
-                    // we need to setup any dynamic shortcodes so that they work with the array_key_exists
208
-                    preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
209
-                    $sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
210
-
211
-                    if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) {
212
-                        continue; // the given shortcode isn't in this object
213
-                    }
214
-
215
-                    // if this isn't  a "list" type shortcode then we'll send along the data vanilla instead of in an array.
216
-                    if (! in_array($sc_to_verify, $list_type_shortcodes)) {
217
-                        $data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data;
218
-                    } else {
219
-                        $data_send = $this->_data;
220
-                    }
221
-
222
-                    // is this a conditional type shortcode?  If it is then we actually parse the template here.
223
-                    if ($this->_is_conditional_shortcode($shortcode)) {
224
-                        // most shortcode parsers are not going to have a match for this shortcode and will return an
225
-                        // empty string so we need to make sure that we're only replacing the template when there is a non empty string.
226
-                        $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']);
227
-                        if ($parsed) {
228
-                            $this->_template = $parsed;
229
-                        }
230
-                    }
231
-
232
-                    $parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']);
233
-
234
-                    $matched_code[] = $shortcode;
235
-                    $sc_values[]    = $parsed;
236
-                }
237
-            }
238
-        }
239
-
240
-        // now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out.
241
-        $parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template);
242
-        return $parsed;
243
-    }
244
-
245
-
246
-    /**
247
-     * Simply returns whether the given shortcode matches the structure for a conditional shortcode.
248
-     *
249
-     * Does it match this format: `[IF_`
250
-     *
251
-     * @param $shortcode
252
-     */
253
-    protected function _is_conditional_shortcode($shortcode)
254
-    {
255
-        return strpos($shortcode, '[IF_') === 0;
256
-    }
257
-
258
-
259
-    /**
260
-     * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of
261
-     * various EE_Shortcode library objects
262
-     *
263
-     * @access private
264
-     * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects
265
-     * @return void
266
-     */
267
-    private function _set_shortcodes($valid_shortcodes)
268
-    {
269
-        foreach ($valid_shortcodes as $shortcode_ref) {
270
-            $ref       = ucwords(str_replace('_', ' ', $shortcode_ref));
271
-            $ref       = str_replace(' ', '_', $ref);
272
-            $classname = 'EE_' . $ref . '_Shortcodes';
273
-            if (class_exists($classname)) {
274
-                $this->_shortcode_objs[] = new $classname();
275
-            }
276
-        }
277
-    }
14
+	/**
15
+	 * holds the template
16
+	 *
17
+	 * @access private
18
+	 * @var mixed (string|array)
19
+	 */
20
+	private $_template;
21
+
22
+
23
+	/**
24
+	 * holds the incoming data object
25
+	 *
26
+	 * @access private
27
+	 * @var object
28
+	 */
29
+	private $_data;
30
+
31
+
32
+	/**
33
+	 * will hold an array of EE_Shortcodes library objects.
34
+	 *
35
+	 * @access private
36
+	 * @var EE_Shortcodes[]
37
+	 */
38
+	private $_shortcode_objs = array();
39
+
40
+
41
+	public function __construct()
42
+	{
43
+	}
44
+
45
+
46
+	/**
47
+	 * This kicks off the parsing of shortcodes in message templates
48
+	 *
49
+	 * @param  string                $template         This is the incoming string to be parsed
50
+	 * @param  EE_Messages_Addressee $data             This is the incoming data object
51
+	 * @param  array                 $valid_shortcodes An array of strings that correspond to EE_Shortcode libraries
52
+	 * @param EE_message_type        $message_type     The message type that called the parser
53
+	 * @param EE_messenger           $messenger        The active messenger for this parsing session.
54
+	 * @param EE_Message             $message
55
+	 * @return string                   The parsed template string
56
+	 */
57
+	public function parse_message_template(
58
+		$template,
59
+		EE_Messages_Addressee $data,
60
+		$valid_shortcodes,
61
+		EE_message_type $message_type,
62
+		EE_messenger $messenger,
63
+		EE_Message $message
64
+	) {
65
+		$extra_data = array(
66
+			'messenger'    => $messenger,
67
+			'message_type' => $message_type,
68
+			'message'      => $message,
69
+		);
70
+		$this->_init_data($template, $data, $valid_shortcodes, $extra_data);
71
+		$this->_template = is_array($template) ? $template['main'] : $template;
72
+		return $this->_parse_message_template();
73
+	}
74
+
75
+
76
+	public function parse_attendee_list_template(
77
+		$template,
78
+		EE_Registration $registration,
79
+		$valid_shortcodes,
80
+		$extra_data = array()
81
+	) {
82
+		$this->_init_data($template, $registration, $valid_shortcodes, $extra_data);
83
+		$this->_template = is_array($template) ? $template['attendee_list'] : $template;
84
+		return $this->_parse_message_template();
85
+	}
86
+
87
+	public function parse_event_list_template($template, EE_Event $event, $valid_shortcodes, $extra_data = array())
88
+	{
89
+		$this->_init_data($template, $event, $valid_shortcodes, $extra_data);
90
+		$this->_template = is_array($template) ? $template['event_list'] : $template;
91
+		return $this->_parse_message_template();
92
+	}
93
+
94
+
95
+	public function parse_ticket_list_template($template, EE_Ticket $ticket, $valid_shortcodes, $extra_data = array())
96
+	{
97
+		$this->_init_data($template, $ticket, $valid_shortcodes, $extra_data);
98
+		$this->_template = is_array($template) ? $template['ticket_list'] : $template;
99
+		return $this->_parse_message_template();
100
+	}
101
+
102
+
103
+	public function parse_line_item_list_template(
104
+		$template,
105
+		EE_Line_Item $line_item,
106
+		$valid_shortcodes,
107
+		$extra_data = array()
108
+	) {
109
+		$this->_init_data($template, $line_item, $valid_shortcodes, $extra_data);
110
+		$this->_template = is_array($template) ? $template['ticket_line_item_no_pms'] : $template;
111
+		return $this->_parse_message_template();
112
+	}
113
+
114
+
115
+	public function parse_payment_list_template(
116
+		$template,
117
+		EE_Payment $payment_item,
118
+		$valid_shortcodes,
119
+		$extra_data = array()
120
+	) {
121
+		$this->_init_data($template, $payment_item, $valid_shortcodes, $extra_data);
122
+		$this->_template = is_array($template) ? $template['payment_list'] : $template;
123
+		return $this->_parse_message_template();
124
+	}
125
+
126
+
127
+	public function parse_datetime_list_template(
128
+		$template,
129
+		EE_Datetime $datetime,
130
+		$valid_shortcodes,
131
+		$extra_data = array()
132
+	) {
133
+		$this->_init_data($template, $datetime, $valid_shortcodes, $extra_data);
134
+		$this->_template = is_array($template) ? $template['datetime_list'] : $template;
135
+		return $this->_parse_message_template();
136
+	}
137
+
138
+
139
+	public function parse_question_list_template($template, EE_Answer $answer, $valid_shortcodes, $extra_data = array())
140
+	{
141
+		$this->_init_data($template, $answer, $valid_shortcodes, $extra_data);
142
+		$this->_template = is_array($template) ? $template['question_list'] : $template;
143
+		return $this->_parse_message_template();
144
+	}
145
+
146
+
147
+	private function _init_data($template, $data, $valid_shortcodes, $extra_data = array())
148
+	{
149
+		$this->_reset_props();
150
+		$this->_data['template']   = $template;
151
+		$this->_data['data']       = $data;
152
+		$this->_data['extra_data'] = $extra_data;
153
+		$this->_set_shortcodes($valid_shortcodes);
154
+	}
155
+
156
+
157
+	private function _reset_props()
158
+	{
159
+		$this->_template       = $this->_data = null;
160
+		$this->_shortcode_objs = array();
161
+	}
162
+
163
+
164
+	/**
165
+	 * takes the given template and parses it with the $_shortcodes property
166
+	 *
167
+	 * @access private
168
+	 * @return string
169
+	 */
170
+	private function _parse_message_template()
171
+	{
172
+		// now let's get a list of shortcodes that are found in the given template
173
+		preg_match_all('/(\[.+?\])/', $this->_template, $matches);
174
+		$shortcodes = (array) $matches[0]; // this should be an array of shortcodes in the template string.
175
+
176
+		$matched_code = array();
177
+		$sc_values    = array();
178
+
179
+		$list_type_shortcodes = array(
180
+			'[ATTENDEE_LIST]',
181
+			'[EVENT_LIST]',
182
+			'[TICKET_LIST]',
183
+			'[DATETIME_LIST]',
184
+			'[QUESTION_LIST]',
185
+			'[RECIPIENT_QUESTION_LIST]',
186
+			'[PRIMARY_REGISTRANT_QUESTION_LIST]',
187
+			'[RECIPIENT_TICKET_LIST]',
188
+			'[PRIMARY_REGISTRANT_TICKET_LIST]',
189
+			'[RECIPIENT_DATETIME_LIST]',
190
+			'[PRIMARY_REGISTRANT_DATETIME_LIST]',
191
+			'[TICKET_LINE_ITEM_LIST]',
192
+			'[TAX_LINE_ITEM_LIST]',
193
+			'[ADDITIONAL_LINE_ITEM_LIST]',
194
+			'[PRICE_MODIFIER_LINE_ITEM_LIST]',
195
+			'[PAYMENT_LIST_*]',
196
+		);
197
+
198
+		$list_type_shortcodes = apply_filters(
199
+			'FHEE__EEH_Parse_Shortcodes___parse_message_template__list_type_shortcodes',
200
+			$list_type_shortcodes
201
+		);
202
+
203
+		// now lets go ahead and loop through our parsers for each shortcode and setup the values
204
+		foreach ($shortcodes as $shortcode) {
205
+			foreach ($this->_shortcode_objs as $sc_obj) {
206
+				if ($sc_obj instanceof EE_Shortcodes) {
207
+					// we need to setup any dynamic shortcodes so that they work with the array_key_exists
208
+					preg_match_all('/(\[[A-Za-z0-9\_]+_\*)/', $shortcode, $matches);
209
+					$sc_to_verify = ! empty($matches[0]) ? $matches[0][0] . ']' : $shortcode;
210
+
211
+					if (! array_key_exists($sc_to_verify, $sc_obj->get_shortcodes())) {
212
+						continue; // the given shortcode isn't in this object
213
+					}
214
+
215
+					// if this isn't  a "list" type shortcode then we'll send along the data vanilla instead of in an array.
216
+					if (! in_array($sc_to_verify, $list_type_shortcodes)) {
217
+						$data_send = ! is_object($this->_data) && isset($this->_data['data']) ? $this->_data['data'] : $this->_data;
218
+					} else {
219
+						$data_send = $this->_data;
220
+					}
221
+
222
+					// is this a conditional type shortcode?  If it is then we actually parse the template here.
223
+					if ($this->_is_conditional_shortcode($shortcode)) {
224
+						// most shortcode parsers are not going to have a match for this shortcode and will return an
225
+						// empty string so we need to make sure that we're only replacing the template when there is a non empty string.
226
+						$parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']);
227
+						if ($parsed) {
228
+							$this->_template = $parsed;
229
+						}
230
+					}
231
+
232
+					$parsed = $sc_obj->parser($shortcode, $data_send, $this->_data['extra_data']);
233
+
234
+					$matched_code[] = $shortcode;
235
+					$sc_values[]    = $parsed;
236
+				}
237
+			}
238
+		}
239
+
240
+		// now we've got parsed values for all the shortcodes in the template so we can go ahead and swap the shortcodes out.
241
+		$parsed = str_replace(array_values($matched_code), array_values($sc_values), $this->_template);
242
+		return $parsed;
243
+	}
244
+
245
+
246
+	/**
247
+	 * Simply returns whether the given shortcode matches the structure for a conditional shortcode.
248
+	 *
249
+	 * Does it match this format: `[IF_`
250
+	 *
251
+	 * @param $shortcode
252
+	 */
253
+	protected function _is_conditional_shortcode($shortcode)
254
+	{
255
+		return strpos($shortcode, '[IF_') === 0;
256
+	}
257
+
258
+
259
+	/**
260
+	 * This sets the shortcodes property from the incoming array of valid shortcodes that corresponds to names of
261
+	 * various EE_Shortcode library objects
262
+	 *
263
+	 * @access private
264
+	 * @param array $valid_shortcodes an array of strings corresponding to EE_Shortcode Library objects
265
+	 * @return void
266
+	 */
267
+	private function _set_shortcodes($valid_shortcodes)
268
+	{
269
+		foreach ($valid_shortcodes as $shortcode_ref) {
270
+			$ref       = ucwords(str_replace('_', ' ', $shortcode_ref));
271
+			$ref       = str_replace(' ', '_', $ref);
272
+			$classname = 'EE_' . $ref . '_Shortcodes';
273
+			if (class_exists($classname)) {
274
+				$this->_shortcode_objs[] = new $classname();
275
+			}
276
+		}
277
+	}
278 278
 }
Please login to merge, or discard this patch.
core/domain/values/model/CustomSelects.php 2 patches
Indentation   +336 added lines, -336 removed lines patch added patch discarded remove patch
@@ -17,340 +17,340 @@
 block discarded – undo
17 17
  */
18 18
 class CustomSelects
19 19
 {
20
-    const TYPE_SIMPLE = 'simple';
21
-    const TYPE_COMPLEX = 'complex';
22
-    const TYPE_STRUCTURED = 'structured';
23
-
24
-    private $valid_operators = array('COUNT', 'SUM');
25
-
26
-
27
-    /**
28
-     * Original incoming select array
29
-     *
30
-     * @var array
31
-     */
32
-    private $original_selects;
33
-
34
-    /**
35
-     * Select string that can be added to the query
36
-     *
37
-     * @var string
38
-     */
39
-    private $columns_to_select_expression;
40
-
41
-
42
-    /**
43
-     * An array of aliases for the columns included in the incoming select array.
44
-     *
45
-     * @var array
46
-     */
47
-    private $column_aliases_in_select;
48
-
49
-
50
-    /**
51
-     * Enum representation of the "type" of array coming into this value object.
52
-     *
53
-     * @var string
54
-     */
55
-    private $type = '';
56
-
57
-
58
-    /**
59
-     * CustomSelects constructor.
60
-     * Incoming selects can be in one of the following formats:
61
-     * ---- self::TYPE_SIMPLE array ----
62
-     * This is considered the "simple" type. In this case the array is an numerically indexed array with single or
63
-     * multiple columns to select as the values.
64
-     * eg. array( 'ATT_ID', 'REG_ID' )
65
-     * eg. array( '*' )
66
-     * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or
67
-     * "structured" method.
68
-     * ---- self::TYPE_COMPLEX array ----
69
-     * This is considered the "complex" type.  In this case the array is indexed by arbitrary strings that serve as
70
-     * column alias, and the value is an numerically indexed array where there are two values.  The first value (0) is
71
-     * the selection and the second value (1) is the data type.  Data types must be one of the types defined in
72
-     * EEM_Base::$_valid_wpdb_data_types.
73
-     * eg. array( 'count' => array('count(REG_ID)', '%d') )
74
-     * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses.
75
-     * ---- self::TYPE_STRUCTURED array ---
76
-     * This is considered the "structured" type. This type is similar to the complex type except that the array attached
77
-     * to the column alias contains three values.  The first value is the qualified column name (which can include
78
-     * join syntax for models).  The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc).,
79
-     * the third value is the data type.  Note, if the select does not have an operator, you can use an empty string for
80
-     * the second value.
81
-     * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total))
82
-     * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') );
83
-     * NOTE: mixing array types in the incoming $select will cause errors.
84
-     *
85
-     * @param array $selects
86
-     * @throws InvalidArgumentException
87
-     */
88
-    public function __construct(array $selects)
89
-    {
90
-        $this->original_selects = $selects;
91
-        $this->deriveType($selects);
92
-        $this->deriveParts($selects);
93
-    }
94
-
95
-
96
-    /**
97
-     * Derives what type of custom select has been sent in.
98
-     *
99
-     * @param array $selects
100
-     * @throws InvalidArgumentException
101
-     */
102
-    private function deriveType(array $selects)
103
-    {
104
-        // first if the first key for this array is an integer then its coming in as a simple format, so we'll also
105
-        // ensure all elements of the array are simple.
106
-        if (is_int(key($selects))) {
107
-            // let's ensure all keys are ints
108
-            $invalid_keys = array_filter(
109
-                array_keys($selects),
110
-                function ($value) {
111
-                    return ! is_int($value);
112
-                }
113
-            );
114
-            if (! empty($invalid_keys)) {
115
-                throw new InvalidArgumentException(
116
-                    sprintf(
117
-                        esc_html__(
118
-                            'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically',
119
-                            'event_espresso'
120
-                        ),
121
-                        self::TYPE_SIMPLE
122
-                    )
123
-                );
124
-            }
125
-            $this->type = self::TYPE_SIMPLE;
126
-            return;
127
-        }
128
-        // made it here so that means we've got either complex or structured selects.  Let's find out which by popping
129
-        // the first array element off.
130
-        $first_element = reset($selects);
131
-
132
-        if (! is_array($first_element)) {
133
-            throw new InvalidArgumentException(
134
-                sprintf(
135
-                    esc_html__(
136
-                        'Incoming array looks like its formatted as a "%1$s" or "%2$s" type.  However, the values in the array must be arrays themselves and they are not.',
137
-                        'event_espresso'
138
-                    ),
139
-                    self::TYPE_COMPLEX,
140
-                    self::TYPE_STRUCTURED
141
-                )
142
-            );
143
-        }
144
-        $this->type = count($first_element) === 2
145
-            ? self::TYPE_COMPLEX
146
-            : self::TYPE_STRUCTURED;
147
-    }
148
-
149
-
150
-    /**
151
-     * Sets up the various properties for the vo depending on type.
152
-     *
153
-     * @param array $selects
154
-     * @throws InvalidArgumentException
155
-     */
156
-    private function deriveParts(array $selects)
157
-    {
158
-        $column_parts = array();
159
-        switch ($this->type) {
160
-            case self::TYPE_SIMPLE:
161
-                $column_parts = $selects;
162
-                $this->column_aliases_in_select = $selects;
163
-                break;
164
-            case self::TYPE_COMPLEX:
165
-                foreach ($selects as $alias => $parts) {
166
-                    $this->validateSelectValueForType($parts, $alias);
167
-                    $column_parts[] = "{$parts[0]} AS {$alias}";
168
-                    $this->column_aliases_in_select[] = $alias;
169
-                }
170
-                break;
171
-            case self::TYPE_STRUCTURED:
172
-                foreach ($selects as $alias => $parts) {
173
-                    $this->validateSelectValueForType($parts, $alias);
174
-                    $column_parts[] = $parts[1] !== ''
175
-                        ? $this->assembleSelectStringWithOperator($parts, $alias)
176
-                        : "{$parts[0]} AS {$alias}";
177
-                    $this->column_aliases_in_select[] = $alias;
178
-                }
179
-                break;
180
-        }
181
-        $this->columns_to_select_expression = implode(', ', $column_parts);
182
-    }
183
-
184
-
185
-    /**
186
-     * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts.
187
-     *
188
-     * @param array  $select_parts
189
-     * @param string $alias
190
-     * @throws InvalidArgumentException
191
-     */
192
-    private function validateSelectValueForType(array $select_parts, $alias)
193
-    {
194
-        $valid_data_types = array('%d', '%s', '%f');
195
-        if (count($select_parts) !== $this->expectedSelectPartCountForType()) {
196
-            throw new InvalidArgumentException(
197
-                sprintf(
198
-                    esc_html__(
199
-                        'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s.  However the count was %4$d.',
200
-                        'event_espresso'
201
-                    ),
202
-                    $alias,
203
-                    $this->expectedSelectPartCountForType(),
204
-                    $this->type,
205
-                    count($select_parts)
206
-                )
207
-            );
208
-        }
209
-        // validate data type.
210
-        $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : '';
211
-        $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type;
212
-
213
-        if (! in_array($data_type, $valid_data_types, true)) {
214
-            throw new InvalidArgumentException(
215
-                sprintf(
216
-                    esc_html__(
217
-                        'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)',
218
-                        'event_espresso'
219
-                    ),
220
-                    $data_type,
221
-                    $select_parts[0],
222
-                    $alias,
223
-                    implode(', ', $valid_data_types)
224
-                )
225
-            );
226
-        }
227
-    }
228
-
229
-
230
-    /**
231
-     * Each type will have an expected count of array elements, this returns what that expected count is.
232
-     *
233
-     * @param string $type
234
-     * @return int
235
-     */
236
-    private function expectedSelectPartCountForType($type = '')
237
-    {
238
-        $type = $type === '' ? $this->type : $type;
239
-        $types_count_map = array(
240
-            self::TYPE_COMPLEX    => 2,
241
-            self::TYPE_STRUCTURED => 3,
242
-        );
243
-        return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0;
244
-    }
245
-
246
-
247
-    /**
248
-     * Prepares the select statement part for for structured type selects.
249
-     *
250
-     * @param array  $select_parts
251
-     * @param string $alias
252
-     * @return string
253
-     * @throws InvalidArgumentException
254
-     */
255
-    private function assembleSelectStringWithOperator(array $select_parts, $alias)
256
-    {
257
-        $operator = strtoupper($select_parts[1]);
258
-        // validate operator
259
-        if (! in_array($operator, $this->valid_operators, true)) {
260
-            throw new InvalidArgumentException(
261
-                sprintf(
262
-                    esc_html__(
263
-                        'An invalid operator has been provided (%1$s) for the column %2$s.  Valid operators must be one of the following: %3$s.',
264
-                        'event_espresso'
265
-                    ),
266
-                    $operator,
267
-                    $alias,
268
-                    implode(', ', $this->valid_operators)
269
-                )
270
-            );
271
-        }
272
-        return $operator . '(' . $select_parts[0] . ') AS ' . $alias;
273
-    }
274
-
275
-
276
-    /**
277
-     * Return the datatype from the given select part.
278
-     * Remember the select_part has already been validated on object instantiation.
279
-     *
280
-     * @param array $select_part
281
-     * @return string
282
-     */
283
-    private function getDataTypeForSelectType(array $select_part)
284
-    {
285
-        switch ($this->type) {
286
-            case self::TYPE_COMPLEX:
287
-                return $select_part[1];
288
-            case self::TYPE_STRUCTURED:
289
-                return $select_part[2];
290
-            default:
291
-                return '';
292
-        }
293
-    }
294
-
295
-
296
-    /**
297
-     * Returns the original select array sent into the VO.
298
-     *
299
-     * @return array
300
-     */
301
-    public function originalSelects()
302
-    {
303
-        return $this->original_selects;
304
-    }
305
-
306
-
307
-    /**
308
-     * Returns the final assembled select expression derived from the incoming select array.
309
-     *
310
-     * @return string
311
-     */
312
-    public function columnsToSelectExpression()
313
-    {
314
-        return $this->columns_to_select_expression;
315
-    }
316
-
317
-
318
-    /**
319
-     * Returns all the column aliases derived from the incoming select array.
320
-     *
321
-     * @return array
322
-     */
323
-    public function columnAliases()
324
-    {
325
-        return $this->column_aliases_in_select;
326
-    }
327
-
328
-
329
-    /**
330
-     * Returns the enum type for the incoming select array.
331
-     *
332
-     * @return string
333
-     */
334
-    public function type()
335
-    {
336
-        return $this->type;
337
-    }
338
-
339
-
340
-    /**
341
-     * Return the datatype for the given column_alias
342
-     *
343
-     * @param string $column_alias
344
-     * @return string  (if there's no data type we return string as the default).
345
-     */
346
-    public function getDataTypeForAlias($column_alias)
347
-    {
348
-        if (
349
-            isset($this->original_selects[ $column_alias ])
350
-            && in_array($column_alias, $this->columnAliases(), true)
351
-        ) {
352
-            return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]);
353
-        }
354
-        return '%s';
355
-    }
20
+	const TYPE_SIMPLE = 'simple';
21
+	const TYPE_COMPLEX = 'complex';
22
+	const TYPE_STRUCTURED = 'structured';
23
+
24
+	private $valid_operators = array('COUNT', 'SUM');
25
+
26
+
27
+	/**
28
+	 * Original incoming select array
29
+	 *
30
+	 * @var array
31
+	 */
32
+	private $original_selects;
33
+
34
+	/**
35
+	 * Select string that can be added to the query
36
+	 *
37
+	 * @var string
38
+	 */
39
+	private $columns_to_select_expression;
40
+
41
+
42
+	/**
43
+	 * An array of aliases for the columns included in the incoming select array.
44
+	 *
45
+	 * @var array
46
+	 */
47
+	private $column_aliases_in_select;
48
+
49
+
50
+	/**
51
+	 * Enum representation of the "type" of array coming into this value object.
52
+	 *
53
+	 * @var string
54
+	 */
55
+	private $type = '';
56
+
57
+
58
+	/**
59
+	 * CustomSelects constructor.
60
+	 * Incoming selects can be in one of the following formats:
61
+	 * ---- self::TYPE_SIMPLE array ----
62
+	 * This is considered the "simple" type. In this case the array is an numerically indexed array with single or
63
+	 * multiple columns to select as the values.
64
+	 * eg. array( 'ATT_ID', 'REG_ID' )
65
+	 * eg. array( '*' )
66
+	 * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or
67
+	 * "structured" method.
68
+	 * ---- self::TYPE_COMPLEX array ----
69
+	 * This is considered the "complex" type.  In this case the array is indexed by arbitrary strings that serve as
70
+	 * column alias, and the value is an numerically indexed array where there are two values.  The first value (0) is
71
+	 * the selection and the second value (1) is the data type.  Data types must be one of the types defined in
72
+	 * EEM_Base::$_valid_wpdb_data_types.
73
+	 * eg. array( 'count' => array('count(REG_ID)', '%d') )
74
+	 * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses.
75
+	 * ---- self::TYPE_STRUCTURED array ---
76
+	 * This is considered the "structured" type. This type is similar to the complex type except that the array attached
77
+	 * to the column alias contains three values.  The first value is the qualified column name (which can include
78
+	 * join syntax for models).  The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc).,
79
+	 * the third value is the data type.  Note, if the select does not have an operator, you can use an empty string for
80
+	 * the second value.
81
+	 * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total))
82
+	 * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') );
83
+	 * NOTE: mixing array types in the incoming $select will cause errors.
84
+	 *
85
+	 * @param array $selects
86
+	 * @throws InvalidArgumentException
87
+	 */
88
+	public function __construct(array $selects)
89
+	{
90
+		$this->original_selects = $selects;
91
+		$this->deriveType($selects);
92
+		$this->deriveParts($selects);
93
+	}
94
+
95
+
96
+	/**
97
+	 * Derives what type of custom select has been sent in.
98
+	 *
99
+	 * @param array $selects
100
+	 * @throws InvalidArgumentException
101
+	 */
102
+	private function deriveType(array $selects)
103
+	{
104
+		// first if the first key for this array is an integer then its coming in as a simple format, so we'll also
105
+		// ensure all elements of the array are simple.
106
+		if (is_int(key($selects))) {
107
+			// let's ensure all keys are ints
108
+			$invalid_keys = array_filter(
109
+				array_keys($selects),
110
+				function ($value) {
111
+					return ! is_int($value);
112
+				}
113
+			);
114
+			if (! empty($invalid_keys)) {
115
+				throw new InvalidArgumentException(
116
+					sprintf(
117
+						esc_html__(
118
+							'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically',
119
+							'event_espresso'
120
+						),
121
+						self::TYPE_SIMPLE
122
+					)
123
+				);
124
+			}
125
+			$this->type = self::TYPE_SIMPLE;
126
+			return;
127
+		}
128
+		// made it here so that means we've got either complex or structured selects.  Let's find out which by popping
129
+		// the first array element off.
130
+		$first_element = reset($selects);
131
+
132
+		if (! is_array($first_element)) {
133
+			throw new InvalidArgumentException(
134
+				sprintf(
135
+					esc_html__(
136
+						'Incoming array looks like its formatted as a "%1$s" or "%2$s" type.  However, the values in the array must be arrays themselves and they are not.',
137
+						'event_espresso'
138
+					),
139
+					self::TYPE_COMPLEX,
140
+					self::TYPE_STRUCTURED
141
+				)
142
+			);
143
+		}
144
+		$this->type = count($first_element) === 2
145
+			? self::TYPE_COMPLEX
146
+			: self::TYPE_STRUCTURED;
147
+	}
148
+
149
+
150
+	/**
151
+	 * Sets up the various properties for the vo depending on type.
152
+	 *
153
+	 * @param array $selects
154
+	 * @throws InvalidArgumentException
155
+	 */
156
+	private function deriveParts(array $selects)
157
+	{
158
+		$column_parts = array();
159
+		switch ($this->type) {
160
+			case self::TYPE_SIMPLE:
161
+				$column_parts = $selects;
162
+				$this->column_aliases_in_select = $selects;
163
+				break;
164
+			case self::TYPE_COMPLEX:
165
+				foreach ($selects as $alias => $parts) {
166
+					$this->validateSelectValueForType($parts, $alias);
167
+					$column_parts[] = "{$parts[0]} AS {$alias}";
168
+					$this->column_aliases_in_select[] = $alias;
169
+				}
170
+				break;
171
+			case self::TYPE_STRUCTURED:
172
+				foreach ($selects as $alias => $parts) {
173
+					$this->validateSelectValueForType($parts, $alias);
174
+					$column_parts[] = $parts[1] !== ''
175
+						? $this->assembleSelectStringWithOperator($parts, $alias)
176
+						: "{$parts[0]} AS {$alias}";
177
+					$this->column_aliases_in_select[] = $alias;
178
+				}
179
+				break;
180
+		}
181
+		$this->columns_to_select_expression = implode(', ', $column_parts);
182
+	}
183
+
184
+
185
+	/**
186
+	 * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts.
187
+	 *
188
+	 * @param array  $select_parts
189
+	 * @param string $alias
190
+	 * @throws InvalidArgumentException
191
+	 */
192
+	private function validateSelectValueForType(array $select_parts, $alias)
193
+	{
194
+		$valid_data_types = array('%d', '%s', '%f');
195
+		if (count($select_parts) !== $this->expectedSelectPartCountForType()) {
196
+			throw new InvalidArgumentException(
197
+				sprintf(
198
+					esc_html__(
199
+						'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s.  However the count was %4$d.',
200
+						'event_espresso'
201
+					),
202
+					$alias,
203
+					$this->expectedSelectPartCountForType(),
204
+					$this->type,
205
+					count($select_parts)
206
+				)
207
+			);
208
+		}
209
+		// validate data type.
210
+		$data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : '';
211
+		$data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type;
212
+
213
+		if (! in_array($data_type, $valid_data_types, true)) {
214
+			throw new InvalidArgumentException(
215
+				sprintf(
216
+					esc_html__(
217
+						'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)',
218
+						'event_espresso'
219
+					),
220
+					$data_type,
221
+					$select_parts[0],
222
+					$alias,
223
+					implode(', ', $valid_data_types)
224
+				)
225
+			);
226
+		}
227
+	}
228
+
229
+
230
+	/**
231
+	 * Each type will have an expected count of array elements, this returns what that expected count is.
232
+	 *
233
+	 * @param string $type
234
+	 * @return int
235
+	 */
236
+	private function expectedSelectPartCountForType($type = '')
237
+	{
238
+		$type = $type === '' ? $this->type : $type;
239
+		$types_count_map = array(
240
+			self::TYPE_COMPLEX    => 2,
241
+			self::TYPE_STRUCTURED => 3,
242
+		);
243
+		return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0;
244
+	}
245
+
246
+
247
+	/**
248
+	 * Prepares the select statement part for for structured type selects.
249
+	 *
250
+	 * @param array  $select_parts
251
+	 * @param string $alias
252
+	 * @return string
253
+	 * @throws InvalidArgumentException
254
+	 */
255
+	private function assembleSelectStringWithOperator(array $select_parts, $alias)
256
+	{
257
+		$operator = strtoupper($select_parts[1]);
258
+		// validate operator
259
+		if (! in_array($operator, $this->valid_operators, true)) {
260
+			throw new InvalidArgumentException(
261
+				sprintf(
262
+					esc_html__(
263
+						'An invalid operator has been provided (%1$s) for the column %2$s.  Valid operators must be one of the following: %3$s.',
264
+						'event_espresso'
265
+					),
266
+					$operator,
267
+					$alias,
268
+					implode(', ', $this->valid_operators)
269
+				)
270
+			);
271
+		}
272
+		return $operator . '(' . $select_parts[0] . ') AS ' . $alias;
273
+	}
274
+
275
+
276
+	/**
277
+	 * Return the datatype from the given select part.
278
+	 * Remember the select_part has already been validated on object instantiation.
279
+	 *
280
+	 * @param array $select_part
281
+	 * @return string
282
+	 */
283
+	private function getDataTypeForSelectType(array $select_part)
284
+	{
285
+		switch ($this->type) {
286
+			case self::TYPE_COMPLEX:
287
+				return $select_part[1];
288
+			case self::TYPE_STRUCTURED:
289
+				return $select_part[2];
290
+			default:
291
+				return '';
292
+		}
293
+	}
294
+
295
+
296
+	/**
297
+	 * Returns the original select array sent into the VO.
298
+	 *
299
+	 * @return array
300
+	 */
301
+	public function originalSelects()
302
+	{
303
+		return $this->original_selects;
304
+	}
305
+
306
+
307
+	/**
308
+	 * Returns the final assembled select expression derived from the incoming select array.
309
+	 *
310
+	 * @return string
311
+	 */
312
+	public function columnsToSelectExpression()
313
+	{
314
+		return $this->columns_to_select_expression;
315
+	}
316
+
317
+
318
+	/**
319
+	 * Returns all the column aliases derived from the incoming select array.
320
+	 *
321
+	 * @return array
322
+	 */
323
+	public function columnAliases()
324
+	{
325
+		return $this->column_aliases_in_select;
326
+	}
327
+
328
+
329
+	/**
330
+	 * Returns the enum type for the incoming select array.
331
+	 *
332
+	 * @return string
333
+	 */
334
+	public function type()
335
+	{
336
+		return $this->type;
337
+	}
338
+
339
+
340
+	/**
341
+	 * Return the datatype for the given column_alias
342
+	 *
343
+	 * @param string $column_alias
344
+	 * @return string  (if there's no data type we return string as the default).
345
+	 */
346
+	public function getDataTypeForAlias($column_alias)
347
+	{
348
+		if (
349
+			isset($this->original_selects[ $column_alias ])
350
+			&& in_array($column_alias, $this->columnAliases(), true)
351
+		) {
352
+			return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]);
353
+		}
354
+		return '%s';
355
+	}
356 356
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
             // let's ensure all keys are ints
108 108
             $invalid_keys = array_filter(
109 109
                 array_keys($selects),
110
-                function ($value) {
110
+                function($value) {
111 111
                     return ! is_int($value);
112 112
                 }
113 113
             );
114
-            if (! empty($invalid_keys)) {
114
+            if ( ! empty($invalid_keys)) {
115 115
                 throw new InvalidArgumentException(
116 116
                     sprintf(
117 117
                         esc_html__(
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
         // the first array element off.
130 130
         $first_element = reset($selects);
131 131
 
132
-        if (! is_array($first_element)) {
132
+        if ( ! is_array($first_element)) {
133 133
             throw new InvalidArgumentException(
134 134
                 sprintf(
135 135
                     esc_html__(
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
         $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : '';
211 211
         $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type;
212 212
 
213
-        if (! in_array($data_type, $valid_data_types, true)) {
213
+        if ( ! in_array($data_type, $valid_data_types, true)) {
214 214
             throw new InvalidArgumentException(
215 215
                 sprintf(
216 216
                     esc_html__(
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
             self::TYPE_COMPLEX    => 2,
241 241
             self::TYPE_STRUCTURED => 3,
242 242
         );
243
-        return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0;
243
+        return isset($types_count_map[$type]) ? $types_count_map[$type] : 0;
244 244
     }
245 245
 
246 246
 
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
     {
257 257
         $operator = strtoupper($select_parts[1]);
258 258
         // validate operator
259
-        if (! in_array($operator, $this->valid_operators, true)) {
259
+        if ( ! in_array($operator, $this->valid_operators, true)) {
260 260
             throw new InvalidArgumentException(
261 261
                 sprintf(
262 262
                     esc_html__(
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
                 )
270 270
             );
271 271
         }
272
-        return $operator . '(' . $select_parts[0] . ') AS ' . $alias;
272
+        return $operator.'('.$select_parts[0].') AS '.$alias;
273 273
     }
274 274
 
275 275
 
@@ -346,10 +346,10 @@  discard block
 block discarded – undo
346 346
     public function getDataTypeForAlias($column_alias)
347 347
     {
348 348
         if (
349
-            isset($this->original_selects[ $column_alias ])
349
+            isset($this->original_selects[$column_alias])
350 350
             && in_array($column_alias, $this->columnAliases(), true)
351 351
         ) {
352
-            return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]);
352
+            return $this->getDataTypeForSelectType($this->original_selects[$column_alias]);
353 353
         }
354 354
         return '%s';
355 355
     }
Please login to merge, or discard this patch.
core/domain/entities/editor/blocks/EventAttendees.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -156,19 +156,19 @@  discard block
 block discarded – undo
156 156
         $sanitized_attributes = array();
157 157
         foreach ($attributes as $attribute => $value) {
158 158
             $convert = $this->getAttributesMap();
159
-            if (isset($convert[ $attribute ])) {
160
-                $sanitize = $convert[ $attribute ];
159
+            if (isset($convert[$attribute])) {
160
+                $sanitize = $convert[$attribute];
161 161
                 if ($sanitize === 'bool') {
162
-                    $sanitized_attributes[ $attribute ] = filter_var(
162
+                    $sanitized_attributes[$attribute] = filter_var(
163 163
                         $value,
164 164
                         FILTER_VALIDATE_BOOLEAN
165 165
                     );
166 166
                 } else {
167
-                    $sanitized_attributes[ $attribute ] = $sanitize($value);
167
+                    $sanitized_attributes[$attribute] = $sanitize($value);
168 168
                 }
169 169
                 // don't pass along attributes with a 0 value
170
-                if ($sanitized_attributes[ $attribute ] === 0) {
171
-                    unset($sanitized_attributes[ $attribute ]);
170
+                if ($sanitized_attributes[$attribute] === 0) {
171
+                    unset($sanitized_attributes[$attribute]);
172 172
                 }
173 173
             }
174 174
         }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     public function renderBlock(array $attributes = array())
188 188
     {
189 189
         $attributes = $this->sanitizeAttributes($attributes);
190
-        if (! (bool) $attributes['displayOnArchives'] && (is_archive() || is_front_page() || is_home())) {
190
+        if ( ! (bool) $attributes['displayOnArchives'] && (is_archive() || is_front_page() || is_home())) {
191 191
             return '';
192 192
         }
193 193
         $this->loadGraphQLRelayAutoloader();
Please login to merge, or discard this patch.
Indentation   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -20,176 +20,176 @@
 block discarded – undo
20 20
  */
21 21
 class EventAttendees extends Block
22 22
 {
23
-    const BLOCK_TYPE = 'event-attendees';
23
+	const BLOCK_TYPE = 'event-attendees';
24 24
 
25
-    /**
26
-     * @var EventAttendeesBlockRenderer $renderer
27
-     */
28
-    protected $renderer;
25
+	/**
26
+	 * @var EventAttendeesBlockRenderer $renderer
27
+	 */
28
+	protected $renderer;
29 29
 
30 30
 
31
-    /**
32
-     * EventAttendees constructor.
33
-     *
34
-     * @param CoreBlocksAssetManager      $block_asset_manager
35
-     * @param RequestInterface            $request
36
-     * @param EventAttendeesBlockRenderer $renderer
37
-     */
38
-    public function __construct(
39
-        CoreBlocksAssetManager $block_asset_manager,
40
-        RequestInterface $request,
41
-        EventAttendeesBlockRenderer $renderer
42
-    ) {
43
-        parent::__construct($block_asset_manager, $request);
44
-        $this->renderer = $renderer;
45
-    }
31
+	/**
32
+	 * EventAttendees constructor.
33
+	 *
34
+	 * @param CoreBlocksAssetManager      $block_asset_manager
35
+	 * @param RequestInterface            $request
36
+	 * @param EventAttendeesBlockRenderer $renderer
37
+	 */
38
+	public function __construct(
39
+		CoreBlocksAssetManager $block_asset_manager,
40
+		RequestInterface $request,
41
+		EventAttendeesBlockRenderer $renderer
42
+	) {
43
+		parent::__construct($block_asset_manager, $request);
44
+		$this->renderer = $renderer;
45
+	}
46 46
 
47 47
 
48
-    /**
49
-     * Perform any early setup required by the block
50
-     * including setting the block type and supported post types
51
-     *
52
-     * @return void
53
-     */
54
-    public function initialize()
55
-    {
56
-        $this->setBlockType(EventAttendees::BLOCK_TYPE);
57
-        $this->setSupportedRoutes(
58
-            array(
59
-                'EventEspresso\core\domain\entities\routing\specifications\admin\WordPressPostTypeEditor',
60
-                'EventEspresso\core\domain\entities\routing\specifications\frontend\EspressoBlockRenderer',
61
-                'EventEspresso\core\domain\entities\routing\specifications\frontend\AnyFrontendRequest'
62
-            )
63
-        );
64
-        $EVT_ID = $this->request->getRequestParam('page') === 'espresso_events'
65
-            ? $this->request->getRequestParam('post', 0, 'int')
66
-            : 0;
67
-        $this->setAttributes(
68
-            array(
69
-                'eventId'           => array(
70
-                    'type'    => 'number',
71
-                    'default' => $EVT_ID,
72
-                ),
73
-                'datetimeId'        => array(
74
-                    'type'    => 'number',
75
-                    'default' => 0,
76
-                ),
77
-                'ticketId'          => array(
78
-                    'type'    => 'number',
79
-                    'default' => 0,
80
-                ),
81
-                'status'            => array(
82
-                    'type'    => 'string',
83
-                    'default' => EEM_Registration::status_id_approved,
84
-                ),
85
-                'limit'             => array(
86
-                    'type'    => 'number',
87
-                    'default' => 100,
88
-                ),
89
-                'order' => array(
90
-                    'type' => 'string',
91
-                    'default' => 'ASC'
92
-                ),
93
-                'orderBy' => array(
94
-                    'type' => 'string',
95
-                    'default' => 'lastThenFirstName',
96
-                ),
97
-                'showGravatar'      => array(
98
-                    'type'    => 'boolean',
99
-                    'default' => false,
100
-                ),
101
-                'avatarClass' => array(
102
-                    'type' => 'string',
103
-                    'default' => 'contact',
104
-                ),
105
-                'avatarSize' => array(
106
-                    'type' => 'number',
107
-                    'default' => 24,
108
-                ),
109
-                'displayOnArchives' => array(
110
-                    'type'    => 'boolean',
111
-                    'default' => false,
112
-                ),
113
-            )
114
-        );
115
-        $this->setDynamic();
116
-    }
48
+	/**
49
+	 * Perform any early setup required by the block
50
+	 * including setting the block type and supported post types
51
+	 *
52
+	 * @return void
53
+	 */
54
+	public function initialize()
55
+	{
56
+		$this->setBlockType(EventAttendees::BLOCK_TYPE);
57
+		$this->setSupportedRoutes(
58
+			array(
59
+				'EventEspresso\core\domain\entities\routing\specifications\admin\WordPressPostTypeEditor',
60
+				'EventEspresso\core\domain\entities\routing\specifications\frontend\EspressoBlockRenderer',
61
+				'EventEspresso\core\domain\entities\routing\specifications\frontend\AnyFrontendRequest'
62
+			)
63
+		);
64
+		$EVT_ID = $this->request->getRequestParam('page') === 'espresso_events'
65
+			? $this->request->getRequestParam('post', 0, 'int')
66
+			: 0;
67
+		$this->setAttributes(
68
+			array(
69
+				'eventId'           => array(
70
+					'type'    => 'number',
71
+					'default' => $EVT_ID,
72
+				),
73
+				'datetimeId'        => array(
74
+					'type'    => 'number',
75
+					'default' => 0,
76
+				),
77
+				'ticketId'          => array(
78
+					'type'    => 'number',
79
+					'default' => 0,
80
+				),
81
+				'status'            => array(
82
+					'type'    => 'string',
83
+					'default' => EEM_Registration::status_id_approved,
84
+				),
85
+				'limit'             => array(
86
+					'type'    => 'number',
87
+					'default' => 100,
88
+				),
89
+				'order' => array(
90
+					'type' => 'string',
91
+					'default' => 'ASC'
92
+				),
93
+				'orderBy' => array(
94
+					'type' => 'string',
95
+					'default' => 'lastThenFirstName',
96
+				),
97
+				'showGravatar'      => array(
98
+					'type'    => 'boolean',
99
+					'default' => false,
100
+				),
101
+				'avatarClass' => array(
102
+					'type' => 'string',
103
+					'default' => 'contact',
104
+				),
105
+				'avatarSize' => array(
106
+					'type' => 'number',
107
+					'default' => 24,
108
+				),
109
+				'displayOnArchives' => array(
110
+					'type'    => 'boolean',
111
+					'default' => false,
112
+				),
113
+			)
114
+		);
115
+		$this->setDynamic();
116
+	}
117 117
 
118 118
 
119
-    /**
120
-     * Returns an array where the key corresponds to the incoming attribute name from the WP block
121
-     * and the value corresponds to the attribute name for the existing EspressoEventAttendees shortcode
122
-     *
123
-     * @since 4.9.71.p
124
-     * @return array
125
-     */
126
-    private function getAttributesMap()
127
-    {
128
-        return array(
129
-            'event'             => 'sanitize_text_field',
130
-            'datetime'          => 'sanitize_text_field',
131
-            'ticket'            => 'sanitize_text_field',
132
-            'eventId'           => 'absint',
133
-            'datetimeId'        => 'absint',
134
-            'ticketId'          => 'absint',
135
-            'status'            => 'sanitize_text_field',
136
-            'limit'             => 'intval',
137
-            'showGravatar'      => 'bool',
138
-            'avatarClass'       => 'sanitize_text_field',
139
-            'avatarSize'        => 'absint',
140
-            'displayOnArchives' => 'bool',
141
-            'order' => 'sanitize_text_field',
142
-            'orderBy' => 'sanitize_text_field',
143
-        );
144
-    }
119
+	/**
120
+	 * Returns an array where the key corresponds to the incoming attribute name from the WP block
121
+	 * and the value corresponds to the attribute name for the existing EspressoEventAttendees shortcode
122
+	 *
123
+	 * @since 4.9.71.p
124
+	 * @return array
125
+	 */
126
+	private function getAttributesMap()
127
+	{
128
+		return array(
129
+			'event'             => 'sanitize_text_field',
130
+			'datetime'          => 'sanitize_text_field',
131
+			'ticket'            => 'sanitize_text_field',
132
+			'eventId'           => 'absint',
133
+			'datetimeId'        => 'absint',
134
+			'ticketId'          => 'absint',
135
+			'status'            => 'sanitize_text_field',
136
+			'limit'             => 'intval',
137
+			'showGravatar'      => 'bool',
138
+			'avatarClass'       => 'sanitize_text_field',
139
+			'avatarSize'        => 'absint',
140
+			'displayOnArchives' => 'bool',
141
+			'order' => 'sanitize_text_field',
142
+			'orderBy' => 'sanitize_text_field',
143
+		);
144
+	}
145 145
 
146 146
 
147
-    /**
148
-     * Sanitizes attributes.
149
-     *
150
-     * @param array $attributes
151
-     * @return array
152
-     */
153
-    private function sanitizeAttributes(array $attributes)
154
-    {
155
-        $sanitized_attributes = array();
156
-        foreach ($attributes as $attribute => $value) {
157
-            $convert = $this->getAttributesMap();
158
-            if (isset($convert[ $attribute ])) {
159
-                $sanitize = $convert[ $attribute ];
160
-                if ($sanitize === 'bool') {
161
-                    $sanitized_attributes[ $attribute ] = filter_var(
162
-                        $value,
163
-                        FILTER_VALIDATE_BOOLEAN
164
-                    );
165
-                } else {
166
-                    $sanitized_attributes[ $attribute ] = $sanitize($value);
167
-                }
168
-                // don't pass along attributes with a 0 value
169
-                if ($sanitized_attributes[ $attribute ] === 0) {
170
-                    unset($sanitized_attributes[ $attribute ]);
171
-                }
172
-            }
173
-        }
174
-        return $attributes;
175
-    }
147
+	/**
148
+	 * Sanitizes attributes.
149
+	 *
150
+	 * @param array $attributes
151
+	 * @return array
152
+	 */
153
+	private function sanitizeAttributes(array $attributes)
154
+	{
155
+		$sanitized_attributes = array();
156
+		foreach ($attributes as $attribute => $value) {
157
+			$convert = $this->getAttributesMap();
158
+			if (isset($convert[ $attribute ])) {
159
+				$sanitize = $convert[ $attribute ];
160
+				if ($sanitize === 'bool') {
161
+					$sanitized_attributes[ $attribute ] = filter_var(
162
+						$value,
163
+						FILTER_VALIDATE_BOOLEAN
164
+					);
165
+				} else {
166
+					$sanitized_attributes[ $attribute ] = $sanitize($value);
167
+				}
168
+				// don't pass along attributes with a 0 value
169
+				if ($sanitized_attributes[ $attribute ] === 0) {
170
+					unset($sanitized_attributes[ $attribute ]);
171
+				}
172
+			}
173
+		}
174
+		return $attributes;
175
+	}
176 176
 
177 177
 
178
-    /**
179
-     * Returns the rendered HTML for the block
180
-     *
181
-     * @param array $attributes
182
-     * @return string
183
-     * @throws DomainException
184
-     * @throws EE_Error
185
-     */
186
-    public function renderBlock(array $attributes = array())
187
-    {
188
-        $attributes = $this->sanitizeAttributes($attributes);
189
-        if (! (bool) $attributes['displayOnArchives'] && (is_archive() || is_front_page() || is_home())) {
190
-            return '';
191
-        }
192
-        $this->loadGraphQLRelayAutoloader();
193
-        return $this->renderer->render($attributes);
194
-    }
178
+	/**
179
+	 * Returns the rendered HTML for the block
180
+	 *
181
+	 * @param array $attributes
182
+	 * @return string
183
+	 * @throws DomainException
184
+	 * @throws EE_Error
185
+	 */
186
+	public function renderBlock(array $attributes = array())
187
+	{
188
+		$attributes = $this->sanitizeAttributes($attributes);
189
+		if (! (bool) $attributes['displayOnArchives'] && (is_archive() || is_front_page() || is_home())) {
190
+			return '';
191
+		}
192
+		$this->loadGraphQLRelayAutoloader();
193
+		return $this->renderer->render($attributes);
194
+	}
195 195
 }
Please login to merge, or discard this patch.
core/domain/entities/shortcodes/EspressoEventAttendees.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $attributes['limit'] = (int) $attributes['limit'];
117 117
         $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
118 118
         // don't display on archives unless 'display_on_archives' is true
119
-        if ($attributes['limit'] === 0 || (! $display_on_archives && is_archive())) {
119
+        if ($attributes['limit'] === 0 || ( ! $display_on_archives && is_archive())) {
120 120
             return '';
121 121
         }
122 122
         try {
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
      */
318 318
     private function getDatetime(array $attributes)
319 319
     {
320
-        if (! empty($attributes['datetime_id'])) {
320
+        if ( ! empty($attributes['datetime_id'])) {
321 321
             $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
322 322
             if ($datetime instanceof EE_Datetime) {
323 323
                 return $datetime;
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
      */
338 338
     private function getTicket(array $attributes)
339 339
     {
340
-        if (! empty($attributes['ticket_id'])) {
340
+        if ( ! empty($attributes['ticket_id'])) {
341 341
             $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
342 342
             if ($ticket instanceof EE_Ticket) {
343 343
                 return $ticket;
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
     private function setAdditionalQueryParams(array $attributes)
355 355
     {
356 356
         $reg_status_array = EEM_Registration::reg_status_array();
357
-        if (isset($reg_status_array[ $attributes['status'] ])) {
357
+        if (isset($reg_status_array[$attributes['status']])) {
358 358
             $this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
359 359
         }
360 360
         if (absint($attributes['limit'])) {
Please login to merge, or discard this patch.
Indentation   +310 added lines, -310 removed lines patch added patch discarded remove patch
@@ -30,339 +30,339 @@
 block discarded – undo
30 30
  */
31 31
 class EspressoEventAttendees extends EspressoShortcode
32 32
 {
33
-    private $query_params = array(
34
-        0 => array(),
35
-    );
33
+	private $query_params = array(
34
+		0 => array(),
35
+	);
36 36
 
37
-    private $template_args = array(
38
-        'contacts' => array(),
39
-        'event'    => null,
40
-        'datetime' => null,
41
-        'ticket'   => null,
42
-    );
37
+	private $template_args = array(
38
+		'contacts' => array(),
39
+		'event'    => null,
40
+		'datetime' => null,
41
+		'ticket'   => null,
42
+	);
43 43
 
44
-    /**
45
-     * the actual shortcode tag that gets registered with WordPress
46
-     *
47
-     * @return string
48
-     */
49
-    public function getTag()
50
-    {
51
-        return 'ESPRESSO_EVENT_ATTENDEES';
52
-    }
44
+	/**
45
+	 * the actual shortcode tag that gets registered with WordPress
46
+	 *
47
+	 * @return string
48
+	 */
49
+	public function getTag()
50
+	{
51
+		return 'ESPRESSO_EVENT_ATTENDEES';
52
+	}
53 53
 
54 54
 
55
-    /**
56
-     * the time in seconds to cache the results of the processShortcode() method
57
-     * 0 means the processShortcode() results will NOT be cached at all
58
-     *
59
-     * @return int
60
-     */
61
-    public function cacheExpiration()
62
-    {
63
-        return 0;
64
-    }
55
+	/**
56
+	 * the time in seconds to cache the results of the processShortcode() method
57
+	 * 0 means the processShortcode() results will NOT be cached at all
58
+	 *
59
+	 * @return int
60
+	 */
61
+	public function cacheExpiration()
62
+	{
63
+		return 0;
64
+	}
65 65
 
66 66
 
67
-    /**
68
-     * a place for adding any initialization code that needs to run prior to wp_header().
69
-     * this may be required for shortcodes that utilize a corresponding module,
70
-     * and need to enqueue assets for that module
71
-     *
72
-     * @return void
73
-     */
74
-    public function initializeShortcode()
75
-    {
76
-        $this->shortcodeHasBeenInitialized();
77
-    }
67
+	/**
68
+	 * a place for adding any initialization code that needs to run prior to wp_header().
69
+	 * this may be required for shortcodes that utilize a corresponding module,
70
+	 * and need to enqueue assets for that module
71
+	 *
72
+	 * @return void
73
+	 */
74
+	public function initializeShortcode()
75
+	{
76
+		$this->shortcodeHasBeenInitialized();
77
+	}
78 78
 
79 79
 
80
-    /**
81
-     * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
82
-     *  [ESPRESSO_EVENT_ATTENDEES]
83
-     *  - defaults to attendees for earliest active event, or earliest upcoming event.
84
-     *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
85
-     *  - attendees for specific event.
86
-     *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
87
-     *  - attendees for a specific datetime.
88
-     *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
89
-     *  - attendees for a specific ticket.
90
-     *  [ESPRESSO_EVENT_ATTENDEES status=all]
91
-     *  - specific registration status (use status id) or all for all attendees regardless of status.
92
-     *  Note default is to only return approved attendees
93
-     *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
94
-     *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
95
-     *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
96
-     *  - default is to not display attendees list on archive pages.
97
-     * Note: because of the relationship between event_id, ticket_id, and datetime_id:
98
-     * If more than one of those params is included, then preference is given to the following:
99
-     *  - event_id is used whenever its present and any others are ignored.
100
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
101
-     *  - otherwise ticket_id is used if present.
102
-     *
103
-     * @param array $attributes
104
-     * @return string
105
-     * @throws EE_Error
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidInterfaceException
108
-     * @throws InvalidArgumentException
109
-     * @throws DomainException
110
-     */
111
-    public function processShortcode($attributes = array())
112
-    {
113
-        // grab attributes and merge with defaults
114
-        $attributes = $this->getAttributes((array) $attributes);
115
-        $attributes['limit'] = (int) $attributes['limit'];
116
-        $display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
117
-        // don't display on archives unless 'display_on_archives' is true
118
-        if ($attributes['limit'] === 0 || (! $display_on_archives && is_archive())) {
119
-            return '';
120
-        }
121
-        try {
122
-            $this->setBaseTemplateArguments($attributes);
123
-            $this->validateEntities($attributes);
124
-            $this->setBaseQueryParams();
125
-        } catch (EntityNotFoundException $e) {
126
-            if (WP_DEBUG) {
127
-                return '<div class="important-notice ee-error">'
128
-                       . $e->getMessage()
129
-                       . '</div>';
130
-            }
131
-            return '';
132
-        }
133
-        $this->setAdditionalQueryParams($attributes);
134
-        // get contacts!
135
-        $this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
136
-        // all set let's load up the template and return.
137
-        return EEH_Template::locate_template(
138
-            'loop-espresso_event_attendees.php',
139
-            $this->template_args
140
-        );
141
-    }
80
+	/**
81
+	 * process_shortcode - ESPRESSO_EVENT_ATTENDEES - Returns a list of attendees to an event.
82
+	 *  [ESPRESSO_EVENT_ATTENDEES]
83
+	 *  - defaults to attendees for earliest active event, or earliest upcoming event.
84
+	 *  [ESPRESSO_EVENT_ATTENDEES event_id=123]
85
+	 *  - attendees for specific event.
86
+	 *  [ESPRESSO_EVENT_ATTENDEES datetime_id=245]
87
+	 *  - attendees for a specific datetime.
88
+	 *  [ESPRESSO_EVENT_ATTENDEES ticket_id=123]
89
+	 *  - attendees for a specific ticket.
90
+	 *  [ESPRESSO_EVENT_ATTENDEES status=all]
91
+	 *  - specific registration status (use status id) or all for all attendees regardless of status.
92
+	 *  Note default is to only return approved attendees
93
+	 *  [ESPRESSO_EVENT_ATTENDEES show_gravatar=true]
94
+	 *  - default is to not return gravatar.  Otherwise if this is set then return gravatar for email address given.
95
+	 *  [ESPRESSO_EVENT_ATTENDEES display_on_archives=true]
96
+	 *  - default is to not display attendees list on archive pages.
97
+	 * Note: because of the relationship between event_id, ticket_id, and datetime_id:
98
+	 * If more than one of those params is included, then preference is given to the following:
99
+	 *  - event_id is used whenever its present and any others are ignored.
100
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
101
+	 *  - otherwise ticket_id is used if present.
102
+	 *
103
+	 * @param array $attributes
104
+	 * @return string
105
+	 * @throws EE_Error
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidInterfaceException
108
+	 * @throws InvalidArgumentException
109
+	 * @throws DomainException
110
+	 */
111
+	public function processShortcode($attributes = array())
112
+	{
113
+		// grab attributes and merge with defaults
114
+		$attributes = $this->getAttributes((array) $attributes);
115
+		$attributes['limit'] = (int) $attributes['limit'];
116
+		$display_on_archives = filter_var($attributes['display_on_archives'], FILTER_VALIDATE_BOOLEAN);
117
+		// don't display on archives unless 'display_on_archives' is true
118
+		if ($attributes['limit'] === 0 || (! $display_on_archives && is_archive())) {
119
+			return '';
120
+		}
121
+		try {
122
+			$this->setBaseTemplateArguments($attributes);
123
+			$this->validateEntities($attributes);
124
+			$this->setBaseQueryParams();
125
+		} catch (EntityNotFoundException $e) {
126
+			if (WP_DEBUG) {
127
+				return '<div class="important-notice ee-error">'
128
+					   . $e->getMessage()
129
+					   . '</div>';
130
+			}
131
+			return '';
132
+		}
133
+		$this->setAdditionalQueryParams($attributes);
134
+		// get contacts!
135
+		$this->template_args['contacts'] = EEM_Attendee::instance()->get_all($this->query_params);
136
+		// all set let's load up the template and return.
137
+		return EEH_Template::locate_template(
138
+			'loop-espresso_event_attendees.php',
139
+			$this->template_args
140
+		);
141
+	}
142 142
 
143 143
 
144
-    /**
145
-     * merge incoming attributes with filtered defaults
146
-     *
147
-     * @param array $attributes
148
-     * @return array
149
-     */
150
-    private function getAttributes(array $attributes)
151
-    {
152
-        return (array) apply_filters(
153
-            'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
154
-            $attributes + array(
155
-                'event_id'            => null,
156
-                'datetime_id'         => null,
157
-                'ticket_id'           => null,
158
-                'status'              => EEM_Registration::status_id_approved,
159
-                'show_gravatar'       => false,
160
-                'display_on_archives' => false,
161
-                'limit'               => 999,
162
-            )
163
-        );
164
-    }
144
+	/**
145
+	 * merge incoming attributes with filtered defaults
146
+	 *
147
+	 * @param array $attributes
148
+	 * @return array
149
+	 */
150
+	private function getAttributes(array $attributes)
151
+	{
152
+		return (array) apply_filters(
153
+			'EES_Espresso_Event_Attendees__process_shortcode__default_shortcode_atts',
154
+			$attributes + array(
155
+				'event_id'            => null,
156
+				'datetime_id'         => null,
157
+				'ticket_id'           => null,
158
+				'status'              => EEM_Registration::status_id_approved,
159
+				'show_gravatar'       => false,
160
+				'display_on_archives' => false,
161
+				'limit'               => 999,
162
+			)
163
+		);
164
+	}
165 165
 
166 166
 
167
-    /**
168
-     * Set all the base template arguments from the incoming attributes.
169
-     * * Note: because of the relationship between event_id, ticket_id, and datetime_id:
170
-     * If more than one of those params is included, then preference is given to the following:
171
-     *  - event_id is used whenever its present and any others are ignored.
172
-     *  - if no event_id then datetime is used whenever its present and any others are ignored.
173
-     *  - otherwise ticket_id is used if present.
174
-     *
175
-     * @param array $attributes
176
-     * @throws EE_Error
177
-     * @throws InvalidDataTypeException
178
-     * @throws InvalidInterfaceException
179
-     * @throws InvalidArgumentException
180
-     */
181
-    private function setBaseTemplateArguments(array $attributes)
182
-    {
183
-        $this->template_args['show_gravatar'] = $attributes['show_gravatar'];
184
-        $this->template_args['event'] = $this->getEvent($attributes);
185
-        $this->template_args['datetime'] = empty($attributes['event_id'])
186
-            ? $this->getDatetime($attributes)
187
-            : null;
188
-        $this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id'])
189
-            ? $this->getTicket($attributes)
190
-            : null;
191
-    }
167
+	/**
168
+	 * Set all the base template arguments from the incoming attributes.
169
+	 * * Note: because of the relationship between event_id, ticket_id, and datetime_id:
170
+	 * If more than one of those params is included, then preference is given to the following:
171
+	 *  - event_id is used whenever its present and any others are ignored.
172
+	 *  - if no event_id then datetime is used whenever its present and any others are ignored.
173
+	 *  - otherwise ticket_id is used if present.
174
+	 *
175
+	 * @param array $attributes
176
+	 * @throws EE_Error
177
+	 * @throws InvalidDataTypeException
178
+	 * @throws InvalidInterfaceException
179
+	 * @throws InvalidArgumentException
180
+	 */
181
+	private function setBaseTemplateArguments(array $attributes)
182
+	{
183
+		$this->template_args['show_gravatar'] = $attributes['show_gravatar'];
184
+		$this->template_args['event'] = $this->getEvent($attributes);
185
+		$this->template_args['datetime'] = empty($attributes['event_id'])
186
+			? $this->getDatetime($attributes)
187
+			: null;
188
+		$this->template_args['ticket'] = empty($attributes['datetime_id']) && empty($attributes['event_id'])
189
+			? $this->getTicket($attributes)
190
+			: null;
191
+	}
192 192
 
193 193
 
194
-    /**
195
-     * Validates the presence of entities for the given attribute values.
196
-     *
197
-     * @param array $attributes
198
-     * @throws EntityNotFoundException
199
-     */
200
-    private function validateEntities(array $attributes)
201
-    {
202
-        if (
203
-            ! $this->template_args['event'] instanceof EE_Event
204
-            || (
205
-                empty($attributes['event_id'])
206
-                && $attributes['datetime_id']
207
-                && ! $this->template_args['datetime'] instanceof EE_Datetime
208
-            )
209
-            || (
210
-                empty($attributes['event_id'])
211
-                && empty($attributes['datetime_id'])
212
-                && $attributes['ticket_id']
213
-                && ! $this->template_args['ticket'] instanceof EE_Ticket
214
-            )
215
-        ) {
216
-            throw new EntityNotFoundException(
217
-                '',
218
-                '',
219
-                esc_html__(
220
-                    'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
221
-                    'event_espresso'
222
-                )
223
-            );
224
-        }
225
-    }
194
+	/**
195
+	 * Validates the presence of entities for the given attribute values.
196
+	 *
197
+	 * @param array $attributes
198
+	 * @throws EntityNotFoundException
199
+	 */
200
+	private function validateEntities(array $attributes)
201
+	{
202
+		if (
203
+			! $this->template_args['event'] instanceof EE_Event
204
+			|| (
205
+				empty($attributes['event_id'])
206
+				&& $attributes['datetime_id']
207
+				&& ! $this->template_args['datetime'] instanceof EE_Datetime
208
+			)
209
+			|| (
210
+				empty($attributes['event_id'])
211
+				&& empty($attributes['datetime_id'])
212
+				&& $attributes['ticket_id']
213
+				&& ! $this->template_args['ticket'] instanceof EE_Ticket
214
+			)
215
+		) {
216
+			throw new EntityNotFoundException(
217
+				'',
218
+				'',
219
+				esc_html__(
220
+					'The [ESPRESSO_EVENT_ATTENDEES] shortcode has been used incorrectly.  Please double check the arguments you used for any typos.  In the case of ID type arguments, its possible the given ID does not correspond to existing data in the database.',
221
+					'event_espresso'
222
+				)
223
+			);
224
+		}
225
+	}
226 226
 
227 227
 
228
-    /**
229
-     * Sets the query params for the base query elements.
230
-     */
231
-    private function setBaseQueryParams()
232
-    {
233
-        switch (true) {
234
-            case $this->template_args['datetime'] instanceof EE_Datetime:
235
-                $this->query_params = array(
236
-                    0                          => array(
237
-                        'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID(),
238
-                    ),
239
-                    'default_where_conditions' => 'this_model_only',
240
-                );
241
-                break;
242
-            case $this->template_args['ticket'] instanceof EE_Ticket:
243
-                $this->query_params[0] = array(
244
-                    'Registration.TKT_ID' => $this->template_args['ticket']->ID(),
245
-                );
246
-                break;
247
-            case $this->template_args['event'] instanceof EE_Event:
248
-                $this->query_params[0] = array(
249
-                    'Registration.EVT_ID' => $this->template_args['event']->ID(),
250
-                );
251
-                break;
252
-        }
253
-    }
228
+	/**
229
+	 * Sets the query params for the base query elements.
230
+	 */
231
+	private function setBaseQueryParams()
232
+	{
233
+		switch (true) {
234
+			case $this->template_args['datetime'] instanceof EE_Datetime:
235
+				$this->query_params = array(
236
+					0                          => array(
237
+						'Registration.Ticket.Datetime.DTT_ID' => $this->template_args['datetime']->ID(),
238
+					),
239
+					'default_where_conditions' => 'this_model_only',
240
+				);
241
+				break;
242
+			case $this->template_args['ticket'] instanceof EE_Ticket:
243
+				$this->query_params[0] = array(
244
+					'Registration.TKT_ID' => $this->template_args['ticket']->ID(),
245
+				);
246
+				break;
247
+			case $this->template_args['event'] instanceof EE_Event:
248
+				$this->query_params[0] = array(
249
+					'Registration.EVT_ID' => $this->template_args['event']->ID(),
250
+				);
251
+				break;
252
+		}
253
+	}
254 254
 
255 255
 
256
-    /**
257
-     * @param array $attributes
258
-     * @return EE_Event|null
259
-     * @throws EE_Error
260
-     * @throws InvalidDataTypeException
261
-     * @throws InvalidInterfaceException
262
-     * @throws InvalidArgumentException
263
-     */
264
-    private function getEvent(array $attributes)
265
-    {
266
-        switch (true) {
267
-            case ! empty($attributes['event_id']):
268
-                $event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
269
-                break;
270
-            case ! empty($attributes['datetime_id']):
271
-                $event = EEM_Event::instance()->get_one(array(
272
-                    array(
273
-                        'Datetime.DTT_ID' => $attributes['datetime_id'],
274
-                    ),
275
-                ));
276
-                break;
277
-            case ! empty($attributes['ticket_id']):
278
-                $event = EEM_Event::instance()->get_one(array(
279
-                    array(
280
-                        'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'],
281
-                    ),
282
-                    'default_where_conditions' => 'none'
283
-                ));
284
-                break;
285
-            case is_espresso_event():
286
-                $event = EEH_Event_View::get_event();
287
-                break;
288
-            default:
289
-                // one last shot...
290
-                // try getting the earliest active event
291
-                $events = EEM_Event::instance()->get_active_events(array(
292
-                    'limit'    => 1,
293
-                    'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
294
-                ));
295
-                //  if none then get the next upcoming
296
-                $events = empty($events)
297
-                    ? EEM_Event::instance()->get_upcoming_events(array(
298
-                        'limit'    => 1,
299
-                        'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
300
-                    ))
301
-                    : $events;
302
-                $event = reset($events);
303
-        }
256
+	/**
257
+	 * @param array $attributes
258
+	 * @return EE_Event|null
259
+	 * @throws EE_Error
260
+	 * @throws InvalidDataTypeException
261
+	 * @throws InvalidInterfaceException
262
+	 * @throws InvalidArgumentException
263
+	 */
264
+	private function getEvent(array $attributes)
265
+	{
266
+		switch (true) {
267
+			case ! empty($attributes['event_id']):
268
+				$event = EEM_Event::instance()->get_one_by_ID($attributes['event_id']);
269
+				break;
270
+			case ! empty($attributes['datetime_id']):
271
+				$event = EEM_Event::instance()->get_one(array(
272
+					array(
273
+						'Datetime.DTT_ID' => $attributes['datetime_id'],
274
+					),
275
+				));
276
+				break;
277
+			case ! empty($attributes['ticket_id']):
278
+				$event = EEM_Event::instance()->get_one(array(
279
+					array(
280
+						'Datetime.Ticket.TKT_ID' => $attributes['ticket_id'],
281
+					),
282
+					'default_where_conditions' => 'none'
283
+				));
284
+				break;
285
+			case is_espresso_event():
286
+				$event = EEH_Event_View::get_event();
287
+				break;
288
+			default:
289
+				// one last shot...
290
+				// try getting the earliest active event
291
+				$events = EEM_Event::instance()->get_active_events(array(
292
+					'limit'    => 1,
293
+					'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
294
+				));
295
+				//  if none then get the next upcoming
296
+				$events = empty($events)
297
+					? EEM_Event::instance()->get_upcoming_events(array(
298
+						'limit'    => 1,
299
+						'order_by' => array('Datetime.DTT_EVT_start' => 'ASC'),
300
+					))
301
+					: $events;
302
+				$event = reset($events);
303
+		}
304 304
 
305
-        return $event instanceof EE_Event ? $event : null;
306
-    }
305
+		return $event instanceof EE_Event ? $event : null;
306
+	}
307 307
 
308 308
 
309
-    /**
310
-     * @param array $attributes
311
-     * @return EE_Datetime|null
312
-     * @throws EE_Error
313
-     * @throws InvalidDataTypeException
314
-     * @throws InvalidInterfaceException
315
-     * @throws InvalidArgumentException
316
-     */
317
-    private function getDatetime(array $attributes)
318
-    {
319
-        if (! empty($attributes['datetime_id'])) {
320
-            $datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
321
-            if ($datetime instanceof EE_Datetime) {
322
-                return $datetime;
323
-            }
324
-        }
325
-        return null;
326
-    }
309
+	/**
310
+	 * @param array $attributes
311
+	 * @return EE_Datetime|null
312
+	 * @throws EE_Error
313
+	 * @throws InvalidDataTypeException
314
+	 * @throws InvalidInterfaceException
315
+	 * @throws InvalidArgumentException
316
+	 */
317
+	private function getDatetime(array $attributes)
318
+	{
319
+		if (! empty($attributes['datetime_id'])) {
320
+			$datetime = EEM_Datetime::instance()->get_one_by_ID($attributes['datetime_id']);
321
+			if ($datetime instanceof EE_Datetime) {
322
+				return $datetime;
323
+			}
324
+		}
325
+		return null;
326
+	}
327 327
 
328 328
 
329
-    /**
330
-     * @param array $attributes
331
-     * @return \EE_Base_Class|EE_Ticket|null
332
-     * @throws EE_Error
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     * @throws InvalidArgumentException
336
-     */
337
-    private function getTicket(array $attributes)
338
-    {
339
-        if (! empty($attributes['ticket_id'])) {
340
-            $ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
341
-            if ($ticket instanceof EE_Ticket) {
342
-                return $ticket;
343
-            }
344
-        }
345
-        return null;
346
-    }
329
+	/**
330
+	 * @param array $attributes
331
+	 * @return \EE_Base_Class|EE_Ticket|null
332
+	 * @throws EE_Error
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 * @throws InvalidArgumentException
336
+	 */
337
+	private function getTicket(array $attributes)
338
+	{
339
+		if (! empty($attributes['ticket_id'])) {
340
+			$ticket = EEM_Ticket::instance()->get_one_by_ID($attributes['ticket_id']);
341
+			if ($ticket instanceof EE_Ticket) {
342
+				return $ticket;
343
+			}
344
+		}
345
+		return null;
346
+	}
347 347
 
348 348
 
349
-    /**
350
-     * @param array $attributes
351
-     * @throws EE_Error
352
-     */
353
-    private function setAdditionalQueryParams(array $attributes)
354
-    {
355
-        $reg_status_array = EEM_Registration::reg_status_array();
356
-        if (isset($reg_status_array[ $attributes['status'] ])) {
357
-            $this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
358
-        }
359
-        if (absint($attributes['limit'])) {
360
-            $this->query_params['limit'] = $attributes['limit'];
361
-        }
362
-        $this->query_params['group_by'] = array('ATT_ID');
363
-        $this->query_params['order_by'] = (array) apply_filters(
364
-            'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
365
-            array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
366
-        );
367
-    }
349
+	/**
350
+	 * @param array $attributes
351
+	 * @throws EE_Error
352
+	 */
353
+	private function setAdditionalQueryParams(array $attributes)
354
+	{
355
+		$reg_status_array = EEM_Registration::reg_status_array();
356
+		if (isset($reg_status_array[ $attributes['status'] ])) {
357
+			$this->query_params[0]['Registration.STS_ID'] = $attributes['status'];
358
+		}
359
+		if (absint($attributes['limit'])) {
360
+			$this->query_params['limit'] = $attributes['limit'];
361
+		}
362
+		$this->query_params['group_by'] = array('ATT_ID');
363
+		$this->query_params['order_by'] = (array) apply_filters(
364
+			'FHEE__EES_Espresso_Event_Attendees__process_shortcode__order_by',
365
+			array('ATT_lname' => 'ASC', 'ATT_fname' => 'ASC')
366
+		);
367
+	}
368 368
 }
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Strategy.core.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
         if (is_array($this->_CPTs)) {
129 129
             foreach ($this->_CPTs as $CPT_type => $CPT) {
130 130
                 if (isset($CPT['plural_slug'])) {
131
-                    $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
131
+                    $_CPT_endpoints [(string) $CPT['plural_slug']] = $CPT_type;
132 132
                 }
133 133
             }
134 134
         }
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
     public function pre_get_posts($WP_Query)
152 152
     {
153 153
         // check that post-type is set
154
-        if (! $WP_Query instanceof WP_Query) {
154
+        if ( ! $WP_Query instanceof WP_Query) {
155 155
             return;
156 156
         }
157 157
         // add our conditionals
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
             $terms = EEM_Term::instance()->get_all_CPT_post_tags();
196 196
             foreach ($terms as $term) {
197 197
                 if ($term instanceof EE_Term) {
198
-                    $this->_CPT_terms[ $term->slug() ] = $term;
198
+                    $this->_CPT_terms[$term->slug()] = $term;
199 199
                 }
200 200
             }
201 201
         }
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
             // loop thru our taxonomies
261 261
             foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
262 262
                 // check if one of our taxonomies is set as a query var
263
-                if (isset($WP_Query->query[ $CPT_taxonomy ])) {
263
+                if (isset($WP_Query->query[$CPT_taxonomy])) {
264 264
                     // but which CPT does that correspond to??? hmmm... guess we gotta go looping
265 265
                     foreach ($this->_CPTs as $post_type => $CPT) {
266 266
                         // verify our CPT has args, is public and has taxonomies set
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
                                     break;
285 285
                                 default:
286 286
                                     do_action(
287
-                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
287
+                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_'.$post_type.'_post_type',
288 288
                                         $WP_Query,
289 289
                                         $this
290 290
                                     );
@@ -309,11 +309,11 @@  discard block
 block discarded – undo
309 309
             // loop thru post_types as array
310 310
             foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
311 311
                 // is current query for an EE CPT ?
312
-                if (isset($this->_CPTs[ $post_type ])) {
312
+                if (isset($this->_CPTs[$post_type])) {
313 313
                     // is EE on or off ?
314 314
                     if (EE_Maintenance_Mode::instance()->level()) {
315 315
                         // reroute CPT template view to maintenance_mode.template.php
316
-                        if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
316
+                        if ( ! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
317 317
                             add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
318 318
                         }
319 319
                         if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
             'EventEspresso\core\CPTs\CptQueryModifier',
342 342
             array(
343 343
                 $post_type,
344
-                $this->_CPTs[ $post_type ],
344
+                $this->_CPTs[$post_type],
345 345
                 $WP_Query,
346 346
             )
347 347
         );
Please login to merge, or discard this patch.
Indentation   +445 added lines, -445 removed lines patch added patch discarded remove patch
@@ -15,449 +15,449 @@
 block discarded – undo
15 15
  */
16 16
 class EE_CPT_Strategy extends EE_Base
17 17
 {
18
-    /**
19
-     * @var EE_CPT_Strategy $_instance
20
-     */
21
-    private static $_instance;
22
-
23
-    /**
24
-     * the current page, if it utilizes CPTs
25
-     *
26
-     * @var array $CPT
27
-     */
28
-    protected $CPT;
29
-
30
-    /**
31
-     * return value from CustomPostTypeDefinitions::getDefinitions()
32
-     *
33
-     * @var array $_CPTs
34
-     */
35
-    protected $_CPTs = array();
36
-
37
-    /**
38
-     * @var array $_CPT_taxonomies
39
-     */
40
-    protected $_CPT_taxonomies = array();
41
-
42
-    /**
43
-     * @var array $_CPT_terms
44
-     */
45
-    protected $_CPT_terms = array();
46
-
47
-    /**
48
-     * @var array $_CPT_endpoints
49
-     */
50
-    protected $_CPT_endpoints = array();
51
-
52
-    /**
53
-     * @var EEM_Base $CPT_model
54
-     */
55
-    protected $CPT_model;
56
-
57
-    /**
58
-     * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier
59
-     */
60
-    protected $query_modifier;
61
-
62
-
63
-    /**
64
-     * @singleton method used to instantiate class object
65
-     * @param CustomPostTypeDefinitions|null $custom_post_types
66
-     * @param CustomTaxonomyDefinitions|null $taxonomies
67
-     * @return EE_CPT_Strategy
68
-     */
69
-    public static function instance(
70
-        CustomPostTypeDefinitions $custom_post_types = null,
71
-        CustomTaxonomyDefinitions $taxonomies = null
72
-    ) {
73
-        // check if class object is instantiated
74
-        if (
75
-            ! self::$_instance instanceof EE_CPT_Strategy
76
-            && $custom_post_types instanceof CustomPostTypeDefinitions
77
-            && $taxonomies instanceof CustomTaxonomyDefinitions
78
-        ) {
79
-            self::$_instance = new self($custom_post_types, $taxonomies);
80
-        }
81
-        return self::$_instance;
82
-    }
83
-
84
-
85
-    /**
86
-     * @param CustomPostTypeDefinitions $custom_post_types
87
-     * @param CustomTaxonomyDefinitions $taxonomies
88
-     */
89
-    protected function __construct(
90
-        CustomPostTypeDefinitions $custom_post_types,
91
-        CustomTaxonomyDefinitions $taxonomies
92
-    ) {
93
-        // get CPT data
94
-        $this->_CPTs = $custom_post_types->getDefinitions();
95
-        $this->_CPT_endpoints = $this->_set_CPT_endpoints();
96
-        $this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions();
97
-        add_action('pre_get_posts', array($this, 'pre_get_posts'), 5);
98
-    }
99
-
100
-
101
-    /**
102
-     * @return array
103
-     */
104
-    public function get_CPT_endpoints()
105
-    {
106
-        return $this->_CPT_endpoints;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return array
112
-     */
113
-    public function get_CPT_taxonomies()
114
-    {
115
-        return $this->_CPT_taxonomies;
116
-    }
117
-
118
-
119
-    /**
120
-     * add CPT "slugs" to array of default espresso "pages"
121
-     *
122
-     * @return array
123
-     */
124
-    private function _set_CPT_endpoints()
125
-    {
126
-        $_CPT_endpoints = array();
127
-        if (is_array($this->_CPTs)) {
128
-            foreach ($this->_CPTs as $CPT_type => $CPT) {
129
-                if (isset($CPT['plural_slug'])) {
130
-                    $_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
131
-                }
132
-            }
133
-        }
134
-        return $_CPT_endpoints;
135
-    }
136
-
137
-
138
-    /**
139
-     * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to
140
-     * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and
141
-     * adding EE objects to the post to facilitate further querying of related data etc)
142
-     *
143
-     * @param WP_Query $WP_Query
144
-     * @return void
145
-     * @throws \EE_Error
146
-     * @throws \InvalidArgumentException
147
-     * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
148
-     * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
149
-     */
150
-    public function pre_get_posts($WP_Query)
151
-    {
152
-        // check that post-type is set
153
-        if (! $WP_Query instanceof WP_Query) {
154
-            return;
155
-        }
156
-        // add our conditionals
157
-        $this->_set_EE_tags_on_WP_Query($WP_Query);
158
-        // check for terms
159
-        $this->_set_post_type_for_terms($WP_Query);
160
-        // make sure paging is always set
161
-        $this->_set_paging($WP_Query);
162
-        // is a taxonomy set ?
163
-        $this->_set_CPT_taxonomies_on_WP_Query($WP_Query);
164
-        // loop thru post_types if set
165
-        $this->_process_WP_Query_post_types($WP_Query);
166
-    }
167
-
168
-
169
-    /**
170
-     * @param WP_Query $WP_Query
171
-     * @return void
172
-     */
173
-    private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query)
174
-    {
175
-        $WP_Query->is_espresso_event_single = false;
176
-        $WP_Query->is_espresso_event_archive = false;
177
-        $WP_Query->is_espresso_event_taxonomy = false;
178
-        $WP_Query->is_espresso_venue_single = false;
179
-        $WP_Query->is_espresso_venue_archive = false;
180
-        $WP_Query->is_espresso_venue_taxonomy = false;
181
-    }
182
-
183
-
184
-    /**
185
-     * @return void
186
-     * @throws EE_Error
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidInterfaceException
190
-     */
191
-    private function _set_CPT_terms()
192
-    {
193
-        if (empty($this->_CPT_terms)) {
194
-            $terms = EEM_Term::instance()->get_all_CPT_post_tags();
195
-            foreach ($terms as $term) {
196
-                if ($term instanceof EE_Term) {
197
-                    $this->_CPT_terms[ $term->slug() ] = $term;
198
-                }
199
-            }
200
-        }
201
-    }
202
-
203
-
204
-    /**
205
-     * @param WP_Query $WP_Query
206
-     * @return void
207
-     * @throws EE_Error
208
-     * @throws InvalidArgumentException
209
-     * @throws InvalidDataTypeException
210
-     * @throws InvalidInterfaceException
211
-     */
212
-    private function _set_post_type_for_terms(WP_Query $WP_Query)
213
-    {
214
-        // is a tag set ?
215
-        if (isset($WP_Query->query['tag'])) {
216
-            // get term for tag
217
-            $term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']);
218
-            // verify the term
219
-            if ($term instanceof EE_Term) {
220
-                $term->post_type = array_merge(array('post', 'page'), (array) $term->post_type);
221
-                $term->post_type = apply_filters(
222
-                    'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type',
223
-                    $term->post_type,
224
-                    $term
225
-                );
226
-                // if a post type is already set
227
-                if (isset($WP_Query->query_vars['post_type'])) {
228
-                    // add to existing array
229
-                    $term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type);
230
-                }
231
-                // just set post_type to our CPT
232
-                $WP_Query->set('post_type', array_unique($term->post_type));
233
-            }
234
-        }
235
-    }
236
-
237
-
238
-    /**
239
-     * @param WP_Query $WP_Query
240
-     * @return void
241
-     */
242
-    public function _set_paging($WP_Query)
243
-    {
244
-        if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) {
245
-            $page = get_query_var('page') ? get_query_var('page') : null;
246
-            $paged = get_query_var('paged') ? get_query_var('paged') : $page;
247
-            $WP_Query->set('paged', $paged);
248
-        }
249
-    }
250
-
251
-
252
-    /**
253
-     * @param \WP_Query $WP_Query
254
-     */
255
-    protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query)
256
-    {
257
-        // is a taxonomy set ?
258
-        if ($WP_Query->is_tax) {
259
-            // loop thru our taxonomies
260
-            foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
261
-                // check if one of our taxonomies is set as a query var
262
-                if (isset($WP_Query->query[ $CPT_taxonomy ])) {
263
-                    // but which CPT does that correspond to??? hmmm... guess we gotta go looping
264
-                    foreach ($this->_CPTs as $post_type => $CPT) {
265
-                        // verify our CPT has args, is public and has taxonomies set
266
-                        if (
267
-                            isset($CPT['args']['public'])
268
-                            && $CPT['args']['public']
269
-                            && ! empty($CPT['args']['taxonomies'])
270
-                            && in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true)
271
-                        ) {
272
-                            // if so, then add this CPT post_type to the current query's array of post_types'
273
-                            $WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type'])
274
-                                ? (array) $WP_Query->query_vars['post_type']
275
-                                : array();
276
-                            $WP_Query->query_vars['post_type'][] = $post_type;
277
-                            switch ($post_type) {
278
-                                case 'espresso_events':
279
-                                    $WP_Query->is_espresso_event_taxonomy = true;
280
-                                    break;
281
-                                case 'espresso_venues':
282
-                                    $WP_Query->is_espresso_venue_taxonomy = true;
283
-                                    break;
284
-                                default:
285
-                                    do_action(
286
-                                        'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
287
-                                        $WP_Query,
288
-                                        $this
289
-                                    );
290
-                            }
291
-                        }
292
-                    }
293
-                }
294
-            }
295
-        }
296
-    }
297
-
298
-
299
-    /**
300
-     * @param \WP_Query $WP_Query
301
-     * @throws InvalidArgumentException
302
-     * @throws InvalidDataTypeException
303
-     * @throws InvalidInterfaceException
304
-     */
305
-    protected function _process_WP_Query_post_types(WP_Query $WP_Query)
306
-    {
307
-        if (isset($WP_Query->query_vars['post_type'])) {
308
-            // loop thru post_types as array
309
-            foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
310
-                // is current query for an EE CPT ?
311
-                if (isset($this->_CPTs[ $post_type ])) {
312
-                    // is EE on or off ?
313
-                    if (EE_Maintenance_Mode::instance()->level()) {
314
-                        // reroute CPT template view to maintenance_mode.template.php
315
-                        if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
316
-                            add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
317
-                        }
318
-                        if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
319
-                            add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1);
320
-                        }
321
-                        return;
322
-                    }
323
-                    $this->_generate_CptQueryModifier($WP_Query, $post_type);
324
-                }
325
-            }
326
-        }
327
-    }
328
-
329
-
330
-    /**
331
-     * @param \WP_Query $WP_Query
332
-     * @param string    $post_type
333
-     * @throws InvalidArgumentException
334
-     * @throws InvalidDataTypeException
335
-     * @throws InvalidInterfaceException
336
-     */
337
-    protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type)
338
-    {
339
-        $this->query_modifier = LoaderFactory::getLoader()->getShared(
340
-            'EventEspresso\core\CPTs\CptQueryModifier',
341
-            array(
342
-                $post_type,
343
-                $this->_CPTs[ $post_type ],
344
-                $WP_Query,
345
-            )
346
-        );
347
-        $this->_CPT_taxonomies = $this->query_modifier->taxonomies();
348
-    }
349
-
350
-
351
-    /**
352
-     * inject_EE_shortcode_placeholder
353
-     * in order to display the M-Mode notice on our CPT routes,
354
-     * we need to first inject what looks like one of our shortcodes,
355
-     * so that it can be replaced with the actual M-Mode notice
356
-     *
357
-     * @return string
358
-     */
359
-    public function inject_EE_shortcode_placeholder()
360
-    {
361
-        return '[ESPRESSO_';
362
-    }
363
-
364
-
365
-    /**
366
-     * @deprecated
367
-     * @since  4.8.41
368
-     * @return void
369
-     */
370
-    public function _possibly_set_ee_request_var()
371
-    {
372
-        $this->query_modifier->setRequestVarsIfCpt();
373
-    }
374
-
375
-
376
-    /**
377
-     * @deprecated
378
-     * @since  4.8.41
379
-     * @param  $SQL
380
-     * @return string
381
-     */
382
-    public function posts_fields($SQL)
383
-    {
384
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
385
-            return $this->query_modifier->postsFields($SQL);
386
-        }
387
-        return $SQL;
388
-    }
389
-
390
-
391
-    /**
392
-     * @deprecated
393
-     * @since  4.8.41
394
-     * @param  $SQL
395
-     * @return string
396
-     */
397
-    public function posts_join($SQL)
398
-    {
399
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
400
-            return $this->query_modifier->postsJoin($SQL);
401
-        }
402
-        return $SQL;
403
-    }
404
-
405
-
406
-    /**
407
-     * @deprecated
408
-     * @since  4.8.41
409
-     * @param  \WP_Post[] $posts
410
-     * @return \WP_Post[]
411
-     */
412
-    public function the_posts($posts)
413
-    {
414
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
415
-            $this->query_modifier->thePosts($posts);
416
-        }
417
-        return $posts;
418
-    }
419
-
420
-
421
-    /**
422
-     * @deprecated
423
-     * @since  4.8.41
424
-     * @param $url
425
-     * @param $ID
426
-     * @return string
427
-     */
428
-    public function get_edit_post_link($url, $ID)
429
-    {
430
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
431
-            return $this->query_modifier->getEditPostLink($url, $ID);
432
-        }
433
-        return '';
434
-    }
435
-
436
-
437
-    /**
438
-     * @deprecated
439
-     * @since  4.8.41
440
-     * @param null $WP_Query
441
-     */
442
-    protected function _do_template_filters($WP_Query = null)
443
-    {
444
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
445
-            $this->query_modifier->addTemplateFilters();
446
-        }
447
-    }
448
-
449
-
450
-    /**
451
-     * @deprecated
452
-     * @since  4.8.41
453
-     * @param string $current_template Existing default template path derived for this page call.
454
-     * @return string the path to the full template file.
455
-     */
456
-    public function single_cpt_template($current_template)
457
-    {
458
-        if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
459
-            return $this->query_modifier->singleCptTemplate($current_template);
460
-        }
461
-        return $current_template;
462
-    }
18
+	/**
19
+	 * @var EE_CPT_Strategy $_instance
20
+	 */
21
+	private static $_instance;
22
+
23
+	/**
24
+	 * the current page, if it utilizes CPTs
25
+	 *
26
+	 * @var array $CPT
27
+	 */
28
+	protected $CPT;
29
+
30
+	/**
31
+	 * return value from CustomPostTypeDefinitions::getDefinitions()
32
+	 *
33
+	 * @var array $_CPTs
34
+	 */
35
+	protected $_CPTs = array();
36
+
37
+	/**
38
+	 * @var array $_CPT_taxonomies
39
+	 */
40
+	protected $_CPT_taxonomies = array();
41
+
42
+	/**
43
+	 * @var array $_CPT_terms
44
+	 */
45
+	protected $_CPT_terms = array();
46
+
47
+	/**
48
+	 * @var array $_CPT_endpoints
49
+	 */
50
+	protected $_CPT_endpoints = array();
51
+
52
+	/**
53
+	 * @var EEM_Base $CPT_model
54
+	 */
55
+	protected $CPT_model;
56
+
57
+	/**
58
+	 * @var EventEspresso\Core\CPTs\CptQueryModifier $query_modifier
59
+	 */
60
+	protected $query_modifier;
61
+
62
+
63
+	/**
64
+	 * @singleton method used to instantiate class object
65
+	 * @param CustomPostTypeDefinitions|null $custom_post_types
66
+	 * @param CustomTaxonomyDefinitions|null $taxonomies
67
+	 * @return EE_CPT_Strategy
68
+	 */
69
+	public static function instance(
70
+		CustomPostTypeDefinitions $custom_post_types = null,
71
+		CustomTaxonomyDefinitions $taxonomies = null
72
+	) {
73
+		// check if class object is instantiated
74
+		if (
75
+			! self::$_instance instanceof EE_CPT_Strategy
76
+			&& $custom_post_types instanceof CustomPostTypeDefinitions
77
+			&& $taxonomies instanceof CustomTaxonomyDefinitions
78
+		) {
79
+			self::$_instance = new self($custom_post_types, $taxonomies);
80
+		}
81
+		return self::$_instance;
82
+	}
83
+
84
+
85
+	/**
86
+	 * @param CustomPostTypeDefinitions $custom_post_types
87
+	 * @param CustomTaxonomyDefinitions $taxonomies
88
+	 */
89
+	protected function __construct(
90
+		CustomPostTypeDefinitions $custom_post_types,
91
+		CustomTaxonomyDefinitions $taxonomies
92
+	) {
93
+		// get CPT data
94
+		$this->_CPTs = $custom_post_types->getDefinitions();
95
+		$this->_CPT_endpoints = $this->_set_CPT_endpoints();
96
+		$this->_CPT_taxonomies = $taxonomies->getCustomTaxonomyDefinitions();
97
+		add_action('pre_get_posts', array($this, 'pre_get_posts'), 5);
98
+	}
99
+
100
+
101
+	/**
102
+	 * @return array
103
+	 */
104
+	public function get_CPT_endpoints()
105
+	{
106
+		return $this->_CPT_endpoints;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return array
112
+	 */
113
+	public function get_CPT_taxonomies()
114
+	{
115
+		return $this->_CPT_taxonomies;
116
+	}
117
+
118
+
119
+	/**
120
+	 * add CPT "slugs" to array of default espresso "pages"
121
+	 *
122
+	 * @return array
123
+	 */
124
+	private function _set_CPT_endpoints()
125
+	{
126
+		$_CPT_endpoints = array();
127
+		if (is_array($this->_CPTs)) {
128
+			foreach ($this->_CPTs as $CPT_type => $CPT) {
129
+				if (isset($CPT['plural_slug'])) {
130
+					$_CPT_endpoints [ (string) $CPT['plural_slug'] ] = $CPT_type;
131
+				}
132
+			}
133
+		}
134
+		return $_CPT_endpoints;
135
+	}
136
+
137
+
138
+	/**
139
+	 * If this query (not just "main" queries (ie, for WP's infamous "loop")) is for an EE CPT, then we want to
140
+	 * supercharge the get_posts query to add our EE stuff (like joining to our tables, selecting extra columns, and
141
+	 * adding EE objects to the post to facilitate further querying of related data etc)
142
+	 *
143
+	 * @param WP_Query $WP_Query
144
+	 * @return void
145
+	 * @throws \EE_Error
146
+	 * @throws \InvalidArgumentException
147
+	 * @throws \EventEspresso\core\exceptions\InvalidInterfaceException
148
+	 * @throws \EventEspresso\core\exceptions\InvalidDataTypeException
149
+	 */
150
+	public function pre_get_posts($WP_Query)
151
+	{
152
+		// check that post-type is set
153
+		if (! $WP_Query instanceof WP_Query) {
154
+			return;
155
+		}
156
+		// add our conditionals
157
+		$this->_set_EE_tags_on_WP_Query($WP_Query);
158
+		// check for terms
159
+		$this->_set_post_type_for_terms($WP_Query);
160
+		// make sure paging is always set
161
+		$this->_set_paging($WP_Query);
162
+		// is a taxonomy set ?
163
+		$this->_set_CPT_taxonomies_on_WP_Query($WP_Query);
164
+		// loop thru post_types if set
165
+		$this->_process_WP_Query_post_types($WP_Query);
166
+	}
167
+
168
+
169
+	/**
170
+	 * @param WP_Query $WP_Query
171
+	 * @return void
172
+	 */
173
+	private function _set_EE_tags_on_WP_Query(WP_Query $WP_Query)
174
+	{
175
+		$WP_Query->is_espresso_event_single = false;
176
+		$WP_Query->is_espresso_event_archive = false;
177
+		$WP_Query->is_espresso_event_taxonomy = false;
178
+		$WP_Query->is_espresso_venue_single = false;
179
+		$WP_Query->is_espresso_venue_archive = false;
180
+		$WP_Query->is_espresso_venue_taxonomy = false;
181
+	}
182
+
183
+
184
+	/**
185
+	 * @return void
186
+	 * @throws EE_Error
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidInterfaceException
190
+	 */
191
+	private function _set_CPT_terms()
192
+	{
193
+		if (empty($this->_CPT_terms)) {
194
+			$terms = EEM_Term::instance()->get_all_CPT_post_tags();
195
+			foreach ($terms as $term) {
196
+				if ($term instanceof EE_Term) {
197
+					$this->_CPT_terms[ $term->slug() ] = $term;
198
+				}
199
+			}
200
+		}
201
+	}
202
+
203
+
204
+	/**
205
+	 * @param WP_Query $WP_Query
206
+	 * @return void
207
+	 * @throws EE_Error
208
+	 * @throws InvalidArgumentException
209
+	 * @throws InvalidDataTypeException
210
+	 * @throws InvalidInterfaceException
211
+	 */
212
+	private function _set_post_type_for_terms(WP_Query $WP_Query)
213
+	{
214
+		// is a tag set ?
215
+		if (isset($WP_Query->query['tag'])) {
216
+			// get term for tag
217
+			$term = EEM_Term::instance()->get_post_tag_for_event_or_venue($WP_Query->query['tag']);
218
+			// verify the term
219
+			if ($term instanceof EE_Term) {
220
+				$term->post_type = array_merge(array('post', 'page'), (array) $term->post_type);
221
+				$term->post_type = apply_filters(
222
+					'FHEE__EE_CPT_Strategy___set_post_type_for_terms__term_post_type',
223
+					$term->post_type,
224
+					$term
225
+				);
226
+				// if a post type is already set
227
+				if (isset($WP_Query->query_vars['post_type'])) {
228
+					// add to existing array
229
+					$term->post_type = array_merge((array) $WP_Query->query_vars['post_type'], $term->post_type);
230
+				}
231
+				// just set post_type to our CPT
232
+				$WP_Query->set('post_type', array_unique($term->post_type));
233
+			}
234
+		}
235
+	}
236
+
237
+
238
+	/**
239
+	 * @param WP_Query $WP_Query
240
+	 * @return void
241
+	 */
242
+	public function _set_paging($WP_Query)
243
+	{
244
+		if ($WP_Query->is_main_query() && apply_filters('FHEE__EE_CPT_Strategy___set_paging', true)) {
245
+			$page = get_query_var('page') ? get_query_var('page') : null;
246
+			$paged = get_query_var('paged') ? get_query_var('paged') : $page;
247
+			$WP_Query->set('paged', $paged);
248
+		}
249
+	}
250
+
251
+
252
+	/**
253
+	 * @param \WP_Query $WP_Query
254
+	 */
255
+	protected function _set_CPT_taxonomies_on_WP_Query(WP_Query $WP_Query)
256
+	{
257
+		// is a taxonomy set ?
258
+		if ($WP_Query->is_tax) {
259
+			// loop thru our taxonomies
260
+			foreach ($this->_CPT_taxonomies as $CPT_taxonomy => $CPT_taxonomy_details) {
261
+				// check if one of our taxonomies is set as a query var
262
+				if (isset($WP_Query->query[ $CPT_taxonomy ])) {
263
+					// but which CPT does that correspond to??? hmmm... guess we gotta go looping
264
+					foreach ($this->_CPTs as $post_type => $CPT) {
265
+						// verify our CPT has args, is public and has taxonomies set
266
+						if (
267
+							isset($CPT['args']['public'])
268
+							&& $CPT['args']['public']
269
+							&& ! empty($CPT['args']['taxonomies'])
270
+							&& in_array($CPT_taxonomy, $CPT['args']['taxonomies'], true)
271
+						) {
272
+							// if so, then add this CPT post_type to the current query's array of post_types'
273
+							$WP_Query->query_vars['post_type'] = isset($WP_Query->query_vars['post_type'])
274
+								? (array) $WP_Query->query_vars['post_type']
275
+								: array();
276
+							$WP_Query->query_vars['post_type'][] = $post_type;
277
+							switch ($post_type) {
278
+								case 'espresso_events':
279
+									$WP_Query->is_espresso_event_taxonomy = true;
280
+									break;
281
+								case 'espresso_venues':
282
+									$WP_Query->is_espresso_venue_taxonomy = true;
283
+									break;
284
+								default:
285
+									do_action(
286
+										'AHEE__EE_CPT_Strategy___set_CPT_taxonomies_on_WP_Query__for_' . $post_type . '_post_type',
287
+										$WP_Query,
288
+										$this
289
+									);
290
+							}
291
+						}
292
+					}
293
+				}
294
+			}
295
+		}
296
+	}
297
+
298
+
299
+	/**
300
+	 * @param \WP_Query $WP_Query
301
+	 * @throws InvalidArgumentException
302
+	 * @throws InvalidDataTypeException
303
+	 * @throws InvalidInterfaceException
304
+	 */
305
+	protected function _process_WP_Query_post_types(WP_Query $WP_Query)
306
+	{
307
+		if (isset($WP_Query->query_vars['post_type'])) {
308
+			// loop thru post_types as array
309
+			foreach ((array) $WP_Query->query_vars['post_type'] as $post_type) {
310
+				// is current query for an EE CPT ?
311
+				if (isset($this->_CPTs[ $post_type ])) {
312
+					// is EE on or off ?
313
+					if (EE_Maintenance_Mode::instance()->level()) {
314
+						// reroute CPT template view to maintenance_mode.template.php
315
+						if (! has_filter('template_include', array('EE_Maintenance_Mode', 'template_include'))) {
316
+							add_filter('template_include', array('EE_Maintenance_Mode', 'template_include'), 99999);
317
+						}
318
+						if (has_filter('the_content', array(EE_Maintenance_Mode::instance(), 'the_content'))) {
319
+							add_filter('the_content', array($this, 'inject_EE_shortcode_placeholder'), 1);
320
+						}
321
+						return;
322
+					}
323
+					$this->_generate_CptQueryModifier($WP_Query, $post_type);
324
+				}
325
+			}
326
+		}
327
+	}
328
+
329
+
330
+	/**
331
+	 * @param \WP_Query $WP_Query
332
+	 * @param string    $post_type
333
+	 * @throws InvalidArgumentException
334
+	 * @throws InvalidDataTypeException
335
+	 * @throws InvalidInterfaceException
336
+	 */
337
+	protected function _generate_CptQueryModifier(WP_Query $WP_Query, $post_type)
338
+	{
339
+		$this->query_modifier = LoaderFactory::getLoader()->getShared(
340
+			'EventEspresso\core\CPTs\CptQueryModifier',
341
+			array(
342
+				$post_type,
343
+				$this->_CPTs[ $post_type ],
344
+				$WP_Query,
345
+			)
346
+		);
347
+		$this->_CPT_taxonomies = $this->query_modifier->taxonomies();
348
+	}
349
+
350
+
351
+	/**
352
+	 * inject_EE_shortcode_placeholder
353
+	 * in order to display the M-Mode notice on our CPT routes,
354
+	 * we need to first inject what looks like one of our shortcodes,
355
+	 * so that it can be replaced with the actual M-Mode notice
356
+	 *
357
+	 * @return string
358
+	 */
359
+	public function inject_EE_shortcode_placeholder()
360
+	{
361
+		return '[ESPRESSO_';
362
+	}
363
+
364
+
365
+	/**
366
+	 * @deprecated
367
+	 * @since  4.8.41
368
+	 * @return void
369
+	 */
370
+	public function _possibly_set_ee_request_var()
371
+	{
372
+		$this->query_modifier->setRequestVarsIfCpt();
373
+	}
374
+
375
+
376
+	/**
377
+	 * @deprecated
378
+	 * @since  4.8.41
379
+	 * @param  $SQL
380
+	 * @return string
381
+	 */
382
+	public function posts_fields($SQL)
383
+	{
384
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
385
+			return $this->query_modifier->postsFields($SQL);
386
+		}
387
+		return $SQL;
388
+	}
389
+
390
+
391
+	/**
392
+	 * @deprecated
393
+	 * @since  4.8.41
394
+	 * @param  $SQL
395
+	 * @return string
396
+	 */
397
+	public function posts_join($SQL)
398
+	{
399
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
400
+			return $this->query_modifier->postsJoin($SQL);
401
+		}
402
+		return $SQL;
403
+	}
404
+
405
+
406
+	/**
407
+	 * @deprecated
408
+	 * @since  4.8.41
409
+	 * @param  \WP_Post[] $posts
410
+	 * @return \WP_Post[]
411
+	 */
412
+	public function the_posts($posts)
413
+	{
414
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
415
+			$this->query_modifier->thePosts($posts);
416
+		}
417
+		return $posts;
418
+	}
419
+
420
+
421
+	/**
422
+	 * @deprecated
423
+	 * @since  4.8.41
424
+	 * @param $url
425
+	 * @param $ID
426
+	 * @return string
427
+	 */
428
+	public function get_edit_post_link($url, $ID)
429
+	{
430
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
431
+			return $this->query_modifier->getEditPostLink($url, $ID);
432
+		}
433
+		return '';
434
+	}
435
+
436
+
437
+	/**
438
+	 * @deprecated
439
+	 * @since  4.8.41
440
+	 * @param null $WP_Query
441
+	 */
442
+	protected function _do_template_filters($WP_Query = null)
443
+	{
444
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
445
+			$this->query_modifier->addTemplateFilters();
446
+		}
447
+	}
448
+
449
+
450
+	/**
451
+	 * @deprecated
452
+	 * @since  4.8.41
453
+	 * @param string $current_template Existing default template path derived for this page call.
454
+	 * @return string the path to the full template file.
455
+	 */
456
+	public function single_cpt_template($current_template)
457
+	{
458
+		if ($this->query_modifier instanceof EventEspresso\Core\CPTs\CptQueryModifier) {
459
+			return $this->query_modifier->singleCptTemplate($current_template);
460
+		}
461
+		return $current_template;
462
+	}
463 463
 }
Please login to merge, or discard this patch.
core/CPTs/EE_CPT_Event_Strategy.core.php 2 patches
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -122,13 +122,13 @@  discard block
 block discarded – undo
122 122
             )
123 123
         ) {
124 124
             // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
125
-            $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
125
+            $SQL .= ', '.EEM_Datetime::instance()->table().'.* ';
126 126
             if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
127 127
                 // because we only want to retrieve the next upcoming datetime for each event:
128 128
                 // add something like:
129 129
                 // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
130 130
                 // to WP Query SELECT statement
131
-                $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
131
+                $SQL .= ', MIN( '.EEM_Datetime::instance()->table().'.DTT_EVT_start ) as event_start_date ';
132 132
             }
133 133
         }
134 134
         return $SQL;
@@ -158,9 +158,9 @@  discard block
 block discarded – undo
158 158
             // adds something like:
159 159
             // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
160 160
             // to WP Query JOIN statement
161
-            $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
162
-                    . '.ID = ' . EEM_Datetime::instance()->table() . '.'
163
-                    . EEM_Event::instance()->primary_key_name() . ' ) ';
161
+            $SQL .= ' INNER JOIN '.EEM_Datetime::instance()->table().' ON ( '.EEM_Event::instance()->table()
162
+                    . '.ID = '.EEM_Datetime::instance()->table().'.'
163
+                    . EEM_Event::instance()->primary_key_name().' ) ';
164 164
         }
165 165
         return $SQL;
166 166
     }
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
                 || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
191 191
                 || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
192 192
             ) {
193
-                $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
194
-                        . current_time('mysql', true) . "' ";
193
+                $SQL .= ' AND '.EEM_Datetime::instance()->table().".DTT_EVT_end > '"
194
+                        . current_time('mysql', true)."' ";
195 195
             }
196 196
         }
197 197
         return $SQL;
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
             // but we want to only show each event only once
240 240
             // (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
241 241
             global $wpdb;
242
-            $SQL = $wpdb->posts . '.ID ';
242
+            $SQL = $wpdb->posts.'.ID ';
243 243
         }
244 244
         return $SQL;
245 245
     }
Please login to merge, or discard this patch.
Indentation   +243 added lines, -243 removed lines patch added patch discarded remove patch
@@ -9,247 +9,247 @@
 block discarded – undo
9 9
  */
10 10
 class EE_CPT_Event_Strategy
11 11
 {
12
-    /**
13
-     * the current page, if it utilizes CPTs
14
-     *
15
-     * @var object $CPT
16
-     */
17
-    protected $CPT;
18
-
19
-
20
-    /**
21
-     * @param array|WP_Query $wp_query
22
-     * @param array          $CPT
23
-     */
24
-    public function __construct($wp_query, array $CPT = [])
25
-    {
26
-        if ($wp_query instanceof WP_Query) {
27
-            $WP_Query  = $wp_query;
28
-            $this->CPT = $CPT;
29
-        } else {
30
-            $WP_Query  = $wp_query['WP_Query'] ?? null;
31
-            $this->CPT = $wp_query['CPT'] ?? null;
32
-        }
33
-        // !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
34
-        // here's the list of available filters in the WP_Query object
35
-        // 'posts_where'
36
-        // 'posts_where_paged'
37
-        // 'posts_groupby'
38
-        // 'posts_join_paged'
39
-        // 'posts_orderby'
40
-        // 'posts_distinct'
41
-        // 'post_limits'
42
-        // 'posts_fields'
43
-        // 'posts_join'
44
-        $this->_add_filters();
45
-        if ($WP_Query instanceof WP_Query) {
46
-            $WP_Query->is_espresso_event_single   = is_singular()
47
-                                                    && isset($WP_Query->query->post_type)
48
-                                                    && $WP_Query->query->post_type === 'espresso_events';
49
-            $WP_Query->is_espresso_event_archive  = is_post_type_archive('espresso_events');
50
-            $WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories');
51
-        }
52
-    }
53
-
54
-
55
-    /**
56
-     * When an instance of this class is created, we add our filters
57
-     * (which will get removed in case the next call to get_posts ISN'T
58
-     * for event CPTs)
59
-     */
60
-    protected function _add_filters()
61
-    {
62
-        add_filter('posts_fields', [$this, 'posts_fields'], 1, 2);
63
-        add_filter('posts_join', [$this, 'posts_join'], 1, 2);
64
-        add_filter('posts_where', [$this, 'posts_where'], 10, 2);
65
-        // add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 );
66
-        add_filter('posts_orderby', [$this, 'posts_orderby'], 1, 2);
67
-        add_filter('posts_groupby', [$this, 'posts_groupby'], 1, 2);
68
-        add_action('posts_selection', [$this, 'remove_filters']);
69
-    }
70
-
71
-
72
-    /**
73
-     * public access to _remove_filters()
74
-     *
75
-     * @since 4.9.63.p
76
-     */
77
-    public function remove_filters()
78
-    {
79
-        $this->_remove_filters();
80
-    }
81
-
82
-
83
-    /**
84
-     * Should eb called when the last filter or hook is fired for this CPT strategy.
85
-     * This is to avoid applying this CPT strategy for other posts or CPTs (eg,
86
-     * we don't want to join to the datetime table when querying for venues, do we!?)
87
-     */
88
-    protected function _remove_filters()
89
-    {
90
-        remove_filter('posts_fields', [$this, 'posts_fields'], 1);
91
-        remove_filter('posts_join', [$this, 'posts_join'], 1);
92
-        remove_filter('posts_where', [$this, 'posts_where']);
93
-        // remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 );
94
-        remove_filter('posts_orderby', [$this, 'posts_orderby'], 1);
95
-        remove_filter('posts_groupby', [$this, 'posts_groupby'], 1);
96
-        remove_action('posts_selection', [$this, 'remove_filters']);
97
-    }
98
-
99
-
100
-    /**
101
-     * @param string        $SQL
102
-     * @param WP_Query|null $wp_query
103
-     * @return    string
104
-     * @throws EE_Error
105
-     * @throws ReflectionException
106
-     */
107
-    public function posts_fields(string $SQL, ?WP_Query $wp_query): string
108
-    {
109
-        if (
110
-            $wp_query instanceof WP_Query
111
-            && (
112
-                $wp_query->is_espresso_event_single
113
-                || $wp_query->is_espresso_event_archive
114
-                || $wp_query->is_espresso_event_taxonomy
115
-            )
116
-        ) {
117
-            // adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
118
-            $SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
119
-            if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
120
-                // because we only want to retrieve the next upcoming datetime for each event:
121
-                // add something like:
122
-                // ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
123
-                // to WP Query SELECT statement
124
-                $SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
125
-            }
126
-        }
127
-        return $SQL;
128
-    }
129
-
130
-
131
-    /**
132
-     * @param string        $SQL
133
-     * @param WP_Query|null $wp_query
134
-     * @return string
135
-     * @throws EE_Error
136
-     * @throws ReflectionException
137
-     */
138
-    public function posts_join(string $SQL, ?WP_Query $wp_query): string
139
-    {
140
-        if (
141
-            $wp_query instanceof WP_Query
142
-            && (
143
-                $wp_query->is_espresso_event_single
144
-                || $wp_query->is_espresso_event_archive
145
-                || $wp_query->is_espresso_event_taxonomy
146
-            )
147
-        ) {
148
-            // adds something like:
149
-            // " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
150
-            // to WP Query JOIN statement
151
-            $SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
152
-                    . '.ID = ' . EEM_Datetime::instance()->table() . '.'
153
-                    . EEM_Event::instance()->primary_key_name() . ' ) ';
154
-        }
155
-        return $SQL;
156
-    }
157
-
158
-
159
-    /**
160
-     * @param string        $SQL
161
-     * @param WP_Query|null $wp_query
162
-     * @return string
163
-     * @throws EE_Error
164
-     * @throws ReflectionException
165
-     */
166
-    public function posts_where(string $SQL, ?WP_Query $wp_query): string
167
-    {
168
-        if (
169
-            $wp_query instanceof WP_Query
170
-            && (
171
-                $wp_query->is_espresso_event_archive
172
-                || $wp_query->is_espresso_event_taxonomy
173
-            )
174
-        ) {
175
-            if (
176
-                ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
177
-                || ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
178
-                || ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
179
-            ) {
180
-                $SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
181
-                        . current_time('mysql', true) . "' ";
182
-            }
183
-        }
184
-        return $SQL;
185
-    }
186
-
187
-
188
-    /**
189
-     * @param string        $SQL
190
-     * @param WP_Query|null $wp_query
191
-     * @return string
192
-     */
193
-    public function posts_orderby(string $SQL, ?WP_Query $wp_query): string
194
-    {
195
-        if (
196
-            $wp_query instanceof WP_Query
197
-            && (
198
-                $wp_query->is_espresso_event_archive
199
-                || $wp_query->is_espresso_event_taxonomy
200
-            )
201
-        ) {
202
-            $SQL = ' event_start_date ASC ';
203
-        }
204
-        return $SQL;
205
-    }
206
-
207
-
208
-    /**
209
-     * @param string        $SQL
210
-     * @param WP_Query|null $wp_query
211
-     * @return string
212
-     */
213
-    public function posts_groupby(string $SQL, ?WP_Query $wp_query): string
214
-    {
215
-        if (
216
-            $wp_query instanceof WP_Query
217
-            && (
218
-                $wp_query->is_espresso_event_archive
219
-                || $wp_query->is_espresso_event_taxonomy
220
-            )
221
-        ) {
222
-            // TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default)
223
-            // we're joining to the datetimes table, where there can be MANY datetimes for a single event,
224
-            // but we want to only show each event only once
225
-            // (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
226
-            global $wpdb;
227
-            $SQL = $wpdb->posts . '.ID ';
228
-        }
229
-        return $SQL;
230
-    }
231
-
232
-
233
-    /**
234
-     * @param array         $posts
235
-     * @param WP_Query|null $wp_query
236
-     * @return array
237
-     */
238
-    public function the_posts(array $posts, WP_Query $wp_query): array
239
-    {
240
-        return $posts;
241
-    }
242
-
243
-
244
-    /**
245
-     * @param mixed $meta_value
246
-     * @param       $post_id
247
-     * @param       $meta_key
248
-     * @param       $single
249
-     * @return mixed
250
-     */
251
-    public function get_EE_post_type_metadata($meta_value, $post_id, $meta_key, $single)
252
-    {
253
-        return $meta_value;
254
-    }
12
+	/**
13
+	 * the current page, if it utilizes CPTs
14
+	 *
15
+	 * @var object $CPT
16
+	 */
17
+	protected $CPT;
18
+
19
+
20
+	/**
21
+	 * @param array|WP_Query $wp_query
22
+	 * @param array          $CPT
23
+	 */
24
+	public function __construct($wp_query, array $CPT = [])
25
+	{
26
+		if ($wp_query instanceof WP_Query) {
27
+			$WP_Query  = $wp_query;
28
+			$this->CPT = $CPT;
29
+		} else {
30
+			$WP_Query  = $wp_query['WP_Query'] ?? null;
31
+			$this->CPT = $wp_query['CPT'] ?? null;
32
+		}
33
+		// !!!!!!!!!!  IMPORTANT !!!!!!!!!!!!
34
+		// here's the list of available filters in the WP_Query object
35
+		// 'posts_where'
36
+		// 'posts_where_paged'
37
+		// 'posts_groupby'
38
+		// 'posts_join_paged'
39
+		// 'posts_orderby'
40
+		// 'posts_distinct'
41
+		// 'post_limits'
42
+		// 'posts_fields'
43
+		// 'posts_join'
44
+		$this->_add_filters();
45
+		if ($WP_Query instanceof WP_Query) {
46
+			$WP_Query->is_espresso_event_single   = is_singular()
47
+													&& isset($WP_Query->query->post_type)
48
+													&& $WP_Query->query->post_type === 'espresso_events';
49
+			$WP_Query->is_espresso_event_archive  = is_post_type_archive('espresso_events');
50
+			$WP_Query->is_espresso_event_taxonomy = is_tax('espresso_event_categories');
51
+		}
52
+	}
53
+
54
+
55
+	/**
56
+	 * When an instance of this class is created, we add our filters
57
+	 * (which will get removed in case the next call to get_posts ISN'T
58
+	 * for event CPTs)
59
+	 */
60
+	protected function _add_filters()
61
+	{
62
+		add_filter('posts_fields', [$this, 'posts_fields'], 1, 2);
63
+		add_filter('posts_join', [$this, 'posts_join'], 1, 2);
64
+		add_filter('posts_where', [$this, 'posts_where'], 10, 2);
65
+		// add_filter( 'the_posts', array( $this, 'the_posts' ), 1, 2 );
66
+		add_filter('posts_orderby', [$this, 'posts_orderby'], 1, 2);
67
+		add_filter('posts_groupby', [$this, 'posts_groupby'], 1, 2);
68
+		add_action('posts_selection', [$this, 'remove_filters']);
69
+	}
70
+
71
+
72
+	/**
73
+	 * public access to _remove_filters()
74
+	 *
75
+	 * @since 4.9.63.p
76
+	 */
77
+	public function remove_filters()
78
+	{
79
+		$this->_remove_filters();
80
+	}
81
+
82
+
83
+	/**
84
+	 * Should eb called when the last filter or hook is fired for this CPT strategy.
85
+	 * This is to avoid applying this CPT strategy for other posts or CPTs (eg,
86
+	 * we don't want to join to the datetime table when querying for venues, do we!?)
87
+	 */
88
+	protected function _remove_filters()
89
+	{
90
+		remove_filter('posts_fields', [$this, 'posts_fields'], 1);
91
+		remove_filter('posts_join', [$this, 'posts_join'], 1);
92
+		remove_filter('posts_where', [$this, 'posts_where']);
93
+		// remove_filter( 'the_posts', array( $this, 'the_posts' ), 1 );
94
+		remove_filter('posts_orderby', [$this, 'posts_orderby'], 1);
95
+		remove_filter('posts_groupby', [$this, 'posts_groupby'], 1);
96
+		remove_action('posts_selection', [$this, 'remove_filters']);
97
+	}
98
+
99
+
100
+	/**
101
+	 * @param string        $SQL
102
+	 * @param WP_Query|null $wp_query
103
+	 * @return    string
104
+	 * @throws EE_Error
105
+	 * @throws ReflectionException
106
+	 */
107
+	public function posts_fields(string $SQL, ?WP_Query $wp_query): string
108
+	{
109
+		if (
110
+			$wp_query instanceof WP_Query
111
+			&& (
112
+				$wp_query->is_espresso_event_single
113
+				|| $wp_query->is_espresso_event_archive
114
+				|| $wp_query->is_espresso_event_taxonomy
115
+			)
116
+		) {
117
+			// adds something like ", wp_esp_datetime.* " to WP Query SELECT statement
118
+			$SQL .= ', ' . EEM_Datetime::instance()->table() . '.* ';
119
+			if ($wp_query->is_espresso_event_archive || $wp_query->is_espresso_event_taxonomy) {
120
+				// because we only want to retrieve the next upcoming datetime for each event:
121
+				// add something like:
122
+				// ", MIN( wp_esp_datetime.DTT_EVT_start ) as event_start_date "
123
+				// to WP Query SELECT statement
124
+				$SQL .= ', MIN( ' . EEM_Datetime::instance()->table() . '.DTT_EVT_start ) as event_start_date ';
125
+			}
126
+		}
127
+		return $SQL;
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param string        $SQL
133
+	 * @param WP_Query|null $wp_query
134
+	 * @return string
135
+	 * @throws EE_Error
136
+	 * @throws ReflectionException
137
+	 */
138
+	public function posts_join(string $SQL, ?WP_Query $wp_query): string
139
+	{
140
+		if (
141
+			$wp_query instanceof WP_Query
142
+			&& (
143
+				$wp_query->is_espresso_event_single
144
+				|| $wp_query->is_espresso_event_archive
145
+				|| $wp_query->is_espresso_event_taxonomy
146
+			)
147
+		) {
148
+			// adds something like:
149
+			// " LEFT JOIN wp_esp_datetime ON ( wp_esp_datetime.EVT_ID = wp_posts.ID ) "
150
+			// to WP Query JOIN statement
151
+			$SQL .= ' INNER JOIN ' . EEM_Datetime::instance()->table() . ' ON ( ' . EEM_Event::instance()->table()
152
+					. '.ID = ' . EEM_Datetime::instance()->table() . '.'
153
+					. EEM_Event::instance()->primary_key_name() . ' ) ';
154
+		}
155
+		return $SQL;
156
+	}
157
+
158
+
159
+	/**
160
+	 * @param string        $SQL
161
+	 * @param WP_Query|null $wp_query
162
+	 * @return string
163
+	 * @throws EE_Error
164
+	 * @throws ReflectionException
165
+	 */
166
+	public function posts_where(string $SQL, ?WP_Query $wp_query): string
167
+	{
168
+		if (
169
+			$wp_query instanceof WP_Query
170
+			&& (
171
+				$wp_query->is_espresso_event_archive
172
+				|| $wp_query->is_espresso_event_taxonomy
173
+			)
174
+		) {
175
+			if (
176
+				! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive)
177
+				|| ! isset(EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events)
178
+				|| ! EE_Registry::instance()->CFG->template_settings->EED_Events_Archive->display_expired_events
179
+			) {
180
+				$SQL .= ' AND ' . EEM_Datetime::instance()->table() . ".DTT_EVT_end > '"
181
+						. current_time('mysql', true) . "' ";
182
+			}
183
+		}
184
+		return $SQL;
185
+	}
186
+
187
+
188
+	/**
189
+	 * @param string        $SQL
190
+	 * @param WP_Query|null $wp_query
191
+	 * @return string
192
+	 */
193
+	public function posts_orderby(string $SQL, ?WP_Query $wp_query): string
194
+	{
195
+		if (
196
+			$wp_query instanceof WP_Query
197
+			&& (
198
+				$wp_query->is_espresso_event_archive
199
+				|| $wp_query->is_espresso_event_taxonomy
200
+			)
201
+		) {
202
+			$SQL = ' event_start_date ASC ';
203
+		}
204
+		return $SQL;
205
+	}
206
+
207
+
208
+	/**
209
+	 * @param string        $SQL
210
+	 * @param WP_Query|null $wp_query
211
+	 * @return string
212
+	 */
213
+	public function posts_groupby(string $SQL, ?WP_Query $wp_query): string
214
+	{
215
+		if (
216
+			$wp_query instanceof WP_Query
217
+			&& (
218
+				$wp_query->is_espresso_event_archive
219
+				|| $wp_query->is_espresso_event_taxonomy
220
+			)
221
+		) {
222
+			// TODO: add event list option for displaying ALL datetimes in event list or only primary datetime (default)
223
+			// we're joining to the datetimes table, where there can be MANY datetimes for a single event,
224
+			// but we want to only show each event only once
225
+			// (whereas if we didn't group them by the post's ID, then we would end up with many repeats)
226
+			global $wpdb;
227
+			$SQL = $wpdb->posts . '.ID ';
228
+		}
229
+		return $SQL;
230
+	}
231
+
232
+
233
+	/**
234
+	 * @param array         $posts
235
+	 * @param WP_Query|null $wp_query
236
+	 * @return array
237
+	 */
238
+	public function the_posts(array $posts, WP_Query $wp_query): array
239
+	{
240
+		return $posts;
241
+	}
242
+
243
+
244
+	/**
245
+	 * @param mixed $meta_value
246
+	 * @param       $post_id
247
+	 * @param       $meta_key
248
+	 * @param       $single
249
+	 * @return mixed
250
+	 */
251
+	public function get_EE_post_type_metadata($meta_value, $post_id, $meta_key, $single)
252
+	{
253
+		return $meta_value;
254
+	}
255 255
 }
Please login to merge, or discard this patch.