Completed
Branch FET-8385-datetime-ticket-selec... (dcae27)
by
unknown
34:01 queued 22:12
created
core/db_models/EEM_Event.model.php 2 patches
Indentation   +636 added lines, -636 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
5 5
 
@@ -16,416 +16,416 @@  discard block
 block discarded – undo
16 16
 class EEM_Event extends EEM_CPT_Base
17 17
 {
18 18
 
19
-    /**
20
-     * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
21
-     * event
22
-     */
23
-    const sold_out = 'sold_out';
24
-
25
-    /**
26
-     * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
27
-     * date)
28
-     */
29
-    const postponed = 'postponed';
30
-
31
-    /**
32
-     * constant used by status(), indicating that the event will no longer occur
33
-     */
34
-    const cancelled = 'cancelled';
35
-
36
-
37
-    /**
38
-     * @var string
39
-     */
40
-    protected static $_default_reg_status = null;
41
-
42
-
43
-    /**
44
-     * private instance of the Event object
45
-     *
46
-     * @var EEM_Event
47
-     */
48
-    protected static $_instance = null;
49
-
50
-
51
-
52
-    /**
53
-     *        This function is a singleton method used to instantiate the EEM_Event object
54
-     *
55
-     * @access public
56
-     * @param string $timezone
57
-     * @return EEM_Event
58
-     */
59
-    public static function instance($timezone = null)
60
-    {
61
-        // check if instance of EEM_Event already exists
62
-        if ( ! self::$_instance instanceof EEM_Event) {
63
-            // instantiate Espresso_model
64
-            self::$_instance = new self($timezone);
65
-        }
66
-        //we might have a timezone set, let set_timezone decide what to do with it
67
-        self::$_instance->set_timezone($timezone);
68
-        // EEM_Event object
69
-        return self::$_instance;
70
-    }
71
-
72
-
73
-
74
-    /**
75
-     * Adds a relationship to Term_Taxonomy for each CPT_Base
76
-     *
77
-     * @param string $timezone
78
-     * @return EEM_Event
79
-     */
80
-    protected function __construct($timezone = null)
81
-    {
82
-        EE_Registry::instance()->load_model('Registration');
83
-        $this->singular_item = __('Event', 'event_espresso');
84
-        $this->plural_item = __('Events', 'event_espresso');
85
-        // to remove Cancelled events from the frontend, copy the following filter to your functions.php file
86
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
87
-        // to remove Postponed events from the frontend, copy the following filter to your functions.php file
88
-        // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
89
-        // to remove Sold Out events from the frontend, copy the following filter to your functions.php file
90
-        //	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
91
-        $this->_custom_stati = apply_filters(
92
-            'AFEE__EEM_Event__construct___custom_stati',
93
-            array(
94
-                EEM_Event::cancelled => array(
95
-                    'label'  => __('Cancelled', 'event_espresso'),
96
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
97
-                ),
98
-                EEM_Event::postponed => array(
99
-                    'label'  => __('Postponed', 'event_espresso'),
100
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
101
-                ),
102
-                EEM_Event::sold_out  => array(
103
-                    'label'  => __('Sold Out', 'event_espresso'),
104
-                    'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
105
-                ),
106
-            )
107
-        );
108
-        self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
109
-            : self::$_default_reg_status;
110
-        $this->_tables = array(
111
-            'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
112
-            'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
113
-        );
114
-        $this->_fields = array(
115
-            'Event_CPT'  => array(
116
-                'EVT_ID'         => new EE_Primary_Key_Int_Field('ID', __('Post ID for Event', 'event_espresso')),
117
-                'EVT_name'       => new EE_Plain_Text_Field('post_title', __('Event Name', 'event_espresso'), false,
118
-                    ''),
119
-                'EVT_desc'       => new EE_Post_Content_Field('post_content', __('Event Description', 'event_espresso'),
120
-                    false, ''),
121
-                'EVT_slug'       => new EE_Slug_Field('post_name', __('Event Slug', 'event_espresso'), false, ''),
122
-                'EVT_created'    => new EE_Datetime_Field('post_date', __('Date/Time Event Created', 'event_espresso'),
123
-                    false, EE_Datetime_Field::now),
124
-                'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
125
-                    __('Event Short Description', 'event_espresso'), false, ''),
126
-                'EVT_modified'   => new EE_Datetime_Field('post_modified',
127
-                    __('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
128
-                'EVT_wp_user'    => new EE_WP_User_Field('post_author', __('Event Creator ID', 'event_espresso'),
129
-                    false),
130
-                'parent'         => new EE_Integer_Field('post_parent', __('Event Parent ID', 'event_espresso'), false,
131
-                    0),
132
-                'EVT_order'      => new EE_Integer_Field('menu_order', __('Event Menu Order', 'event_espresso'), false,
133
-                    1),
134
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
135
-                // EE_Plain_Text_Field( 'post_type', __( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
136
-                'status'         => new EE_WP_Post_Status_Field('post_status', __('Event Status', 'event_espresso'),
137
-                    false, 'draft', $this->_custom_stati),
138
-            ),
139
-            'Event_Meta' => array(
140
-                'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
141
-                    __('Event Meta Row ID', 'event_espresso'), false),
142
-                'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
143
-                    __('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
144
-                'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
145
-                    __('Display Description Flag', 'event_espresso'), false, 1),
146
-                'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
147
-                    __('Display Ticket Selector Flag', 'event_espresso'), false, 1),
148
-                'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
149
-                    __('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
150
-                'EVT_additional_limit'            => new EE_Integer_Field('EVT_additional_limit',
151
-                    __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), true, 10),
152
-                'EVT_default_registration_status' => new EE_Enum_Text_Field(
153
-                    'EVT_default_registration_status',
154
-                    __('Default Registration Status on this Event', 'event_espresso'), false,
155
-                    EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
156
-                ),
157
-                'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
158
-                    __('Member-Only Event Flag', 'event_espresso'), false, false),
159
-                'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
160
-                    __('Event Phone Number', 'event_espresso'), false),
161
-                'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
162
-                    __('Allow Overflow on Event', 'event_espresso'), false, false),
163
-                'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
164
-                    __('Timezone (name) for Event times', 'event_espresso'), false),
165
-                'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
166
-                    __('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
167
-                'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
168
-                    __('Accept Donations?', 'event_espresso'), false, false),
169
-            ),
170
-        );
171
-        $this->_model_relations = array(
172
-            'Registration'           => new EE_Has_Many_Relation(),
173
-            'Datetime'               => new EE_Has_Many_Relation(),
174
-            'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
175
-            'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
176
-            'Term_Relationship'      => new EE_Has_Many_Relation(),
177
-            'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
178
-            'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
179
-            'Attendee'               => new EE_HABTM_Relation('Registration'),
180
-            'WP_User'                => new EE_Belongs_To_Relation(),
181
-        );
182
-        //this model is generally available for reading
183
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
184
-        parent::__construct($timezone);
185
-    }
186
-
187
-
188
-
189
-    /**
190
-     * @param string $default_reg_status
191
-     */
192
-    public static function set_default_reg_status($default_reg_status)
193
-    {
194
-        self::$_default_reg_status = $default_reg_status;
195
-        //if EEM_Event has already been instantiated, then we need to reset the `EVT_default_reg_status` field to use the new default.
196
-        if (self::$_instance instanceof EEM_Event) {
197
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = new EE_Enum_Text_Field(
198
-                'EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'),
199
-                false, $default_reg_status, EEM_Registration::reg_status_array()
200
-            );
201
-            self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize('Event_Meta',
202
-                'EVT_default_registration_status', 'EEM_Event');
203
-        }
204
-    }
205
-
206
-
207
-
208
-    /**
209
-     *        get_question_groups
210
-     *
211
-     * @access        public
212
-     * @return        array
213
-     */
214
-    public function get_all_question_groups()
215
-    {
216
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(array(
217
-            array('QSG_deleted' => false),
218
-            'order_by' => array('QSG_order' => 'ASC'),
219
-        ));
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     *        get_question_groups
226
-     *
227
-     * @access        public
228
-     * @param        int $EVT_ID
229
-     * @return        array
230
-     */
231
-    public function get_all_event_question_groups($EVT_ID = 0)
232
-    {
233
-        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
234
-            EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
235
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
236
-            return false;
237
-        }
238
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array(
239
-            array('EVT_ID' => $EVT_ID),
240
-        ));
241
-    }
242
-
243
-
244
-
245
-    /**
246
-     *        get_question_groups
247
-     *
248
-     * @access        public
249
-     * @param        int     $EVT_ID
250
-     * @param        boolean $for_primary_attendee
251
-     * @return        array
252
-     */
253
-    public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
254
-    {
255
-        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
256
-            EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
257
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
258
-            return false;
259
-        }
260
-        return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array(
261
-            array('EVT_ID' => $EVT_ID, 'EQG_primary' => $for_primary_attendee),
262
-        ));
263
-    }
264
-
265
-
266
-
267
-    /**
268
-     *        get_question_groups
269
-     *
270
-     * @access        public
271
-     * @param        int             $EVT_ID
272
-     * @param        EE_Registration $registration
273
-     * @return        array
274
-     */
275
-    public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
276
-    {
277
-        if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
278
-            EE_Error::add_error(__('An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
279
-                'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
280
-            return false;
281
-        }
282
-        $where_params = array(
283
-            'Event_Question_Group.EVT_ID'      => $EVT_ID,
284
-            'Event_Question_Group.EQG_primary' => $registration->count() == 1 ? true : false,
285
-            'QSG_deleted'                      => false,
286
-        );
287
-        return EE_Registry::instance()->load_model('Question_Group')->get_all(array(
288
-            $where_params,
289
-            'order_by' => array('QSG_order' => 'ASC'),
290
-        ));
291
-    }
292
-
293
-
294
-
295
-    /**
296
-     *        get_question_target_db_column
297
-     *
298
-     * @access        public
299
-     * @param        string $QSG_IDs csv list of $QSG IDs
300
-     * @return        array
301
-     */
302
-    public function get_questions_in_groups($QSG_IDs = '')
303
-    {
304
-        if (empty($QSG_IDs)) {
305
-            EE_Error::add_error(__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
306
-                __FILE__, __FUNCTION__, __LINE__);
307
-            return false;
308
-        }
309
-        return EE_Registry::instance()->load_model('Question')->get_all(array(
310
-            array(
311
-                'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
312
-                'QST_deleted'           => false,
313
-                'QST_admin_only'        => is_admin(),
314
-            ),
315
-            'order_by' => 'QST_order',
316
-        ));
317
-    }
318
-
319
-
320
-
321
-    /**
322
-     *        get_options_for_question
323
-     *
324
-     * @access        public
325
-     * @param        string $QST_IDs csv list of $QST IDs
326
-     * @return        array
327
-     */
328
-    public function get_options_for_question($QST_IDs)
329
-    {
330
-        if (empty($QST_IDs)) {
331
-            EE_Error::add_error(__('An error occurred. No Question IDs were received.', 'event_espresso'), __FILE__,
332
-                __FUNCTION__, __LINE__);
333
-            return false;
334
-        }
335
-        return EE_Registry::instance()->load_model('Question_Option')->get_all(array(
336
-            array(
337
-                'Question.QST_ID' => array('IN', $QST_IDs),
338
-                'QSO_deleted'     => false,
339
-            ),
340
-            'order_by' => 'QSO_ID',
341
-        ));
342
-    }
343
-
344
-
345
-
346
-    /**
347
-     *        _get_question_target_db_column
348
-     *
349
-     * @deprecated as of 4.8.32.rc.001. Instead consider using
350
-     *             EE_Registration_Custom_Questions_Form located in
351
-     *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
352
-     * @access     public
353
-     * @param    EE_Registration $registration (so existing answers for registration are included)
354
-     * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
355
-     *                                         registration).
356
-     * @throws EE_Error
357
-     * @return    array
358
-     */
359
-    public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
360
-    {
361
-        if (empty($EVT_ID)) {
362
-            throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
363
-                'event_espresso'));
364
-        }
365
-        $questions = array();
366
-        // get all question groups for event
367
-        $qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
368
-        if ( ! empty($qgs)) {
369
-            foreach ($qgs as $qg) {
370
-                $qsts = $qg->questions();
371
-                $questions[$qg->ID()] = $qg->model_field_array();
372
-                $questions[$qg->ID()]['QSG_questions'] = array();
373
-                foreach ($qsts as $qst) {
374
-                    if ($qst->is_system_question()) {
375
-                        continue;
376
-                    }
377
-                    $answer = EEM_Answer::instance()->get_one(array(
378
-                        array(
379
-                            'QST_ID' => $qst->ID(),
380
-                            'REG_ID' => $registration->ID(),
381
-                        ),
382
-                    ));
383
-                    $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
384
-                    $qst_name = $qstn_id = $qst->ID();
385
-                    $ans_id = $answer->ID();
386
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
387
-                    $input_name = '';
388
-                    $input_id = sanitize_key($qst->display_text());
389
-                    $input_class = '';
390
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
391
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
392
-                                                                                           . $input_name
393
-                                                                                           . $qst_name;
394
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
395
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
396
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
397
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
398
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
399
-                    //leave responses as-is, don't convert stuff into html entities please!
400
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
401
-                    if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
402
-                        $QSOs = $qst->options(true, $answer->value());
403
-                        if (is_array($QSOs)) {
404
-                            foreach ($QSOs as $QSO_ID => $QSO) {
405
-                                $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
406
-                            }
407
-                        }
408
-                    }
409
-                }
410
-            }
411
-        }
412
-        return $questions;
413
-    }
414
-
415
-
416
-
417
-    /**
418
-     *        _get_question_target_db_column
419
-     *
420
-     * @access        private
421
-     * @param        $QST
422
-     * @return        string        string
423
-     */
424
-    private function _generate_question_input_name($QST)
425
-    {
426
-        if ($QST->QST_system) {
427
-            $qst_name = $QST->QST_system;
428
-            /*			switch( $QST->QST_system ) {
19
+	/**
20
+	 * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the
21
+	 * event
22
+	 */
23
+	const sold_out = 'sold_out';
24
+
25
+	/**
26
+	 * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later
27
+	 * date)
28
+	 */
29
+	const postponed = 'postponed';
30
+
31
+	/**
32
+	 * constant used by status(), indicating that the event will no longer occur
33
+	 */
34
+	const cancelled = 'cancelled';
35
+
36
+
37
+	/**
38
+	 * @var string
39
+	 */
40
+	protected static $_default_reg_status = null;
41
+
42
+
43
+	/**
44
+	 * private instance of the Event object
45
+	 *
46
+	 * @var EEM_Event
47
+	 */
48
+	protected static $_instance = null;
49
+
50
+
51
+
52
+	/**
53
+	 *        This function is a singleton method used to instantiate the EEM_Event object
54
+	 *
55
+	 * @access public
56
+	 * @param string $timezone
57
+	 * @return EEM_Event
58
+	 */
59
+	public static function instance($timezone = null)
60
+	{
61
+		// check if instance of EEM_Event already exists
62
+		if ( ! self::$_instance instanceof EEM_Event) {
63
+			// instantiate Espresso_model
64
+			self::$_instance = new self($timezone);
65
+		}
66
+		//we might have a timezone set, let set_timezone decide what to do with it
67
+		self::$_instance->set_timezone($timezone);
68
+		// EEM_Event object
69
+		return self::$_instance;
70
+	}
71
+
72
+
73
+
74
+	/**
75
+	 * Adds a relationship to Term_Taxonomy for each CPT_Base
76
+	 *
77
+	 * @param string $timezone
78
+	 * @return EEM_Event
79
+	 */
80
+	protected function __construct($timezone = null)
81
+	{
82
+		EE_Registry::instance()->load_model('Registration');
83
+		$this->singular_item = __('Event', 'event_espresso');
84
+		$this->plural_item = __('Events', 'event_espresso');
85
+		// to remove Cancelled events from the frontend, copy the following filter to your functions.php file
86
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' );
87
+		// to remove Postponed events from the frontend, copy the following filter to your functions.php file
88
+		// add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' );
89
+		// to remove Sold Out events from the frontend, copy the following filter to your functions.php file
90
+		//	add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' );
91
+		$this->_custom_stati = apply_filters(
92
+			'AFEE__EEM_Event__construct___custom_stati',
93
+			array(
94
+				EEM_Event::cancelled => array(
95
+					'label'  => __('Cancelled', 'event_espresso'),
96
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true),
97
+				),
98
+				EEM_Event::postponed => array(
99
+					'label'  => __('Postponed', 'event_espresso'),
100
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true),
101
+				),
102
+				EEM_Event::sold_out  => array(
103
+					'label'  => __('Sold Out', 'event_espresso'),
104
+					'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true),
105
+				),
106
+			)
107
+		);
108
+		self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment
109
+			: self::$_default_reg_status;
110
+		$this->_tables = array(
111
+			'Event_CPT'  => new EE_Primary_Table('posts', 'ID'),
112
+			'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'),
113
+		);
114
+		$this->_fields = array(
115
+			'Event_CPT'  => array(
116
+				'EVT_ID'         => new EE_Primary_Key_Int_Field('ID', __('Post ID for Event', 'event_espresso')),
117
+				'EVT_name'       => new EE_Plain_Text_Field('post_title', __('Event Name', 'event_espresso'), false,
118
+					''),
119
+				'EVT_desc'       => new EE_Post_Content_Field('post_content', __('Event Description', 'event_espresso'),
120
+					false, ''),
121
+				'EVT_slug'       => new EE_Slug_Field('post_name', __('Event Slug', 'event_espresso'), false, ''),
122
+				'EVT_created'    => new EE_Datetime_Field('post_date', __('Date/Time Event Created', 'event_espresso'),
123
+					false, EE_Datetime_Field::now),
124
+				'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt',
125
+					__('Event Short Description', 'event_espresso'), false, ''),
126
+				'EVT_modified'   => new EE_Datetime_Field('post_modified',
127
+					__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now),
128
+				'EVT_wp_user'    => new EE_WP_User_Field('post_author', __('Event Creator ID', 'event_espresso'),
129
+					false),
130
+				'parent'         => new EE_Integer_Field('post_parent', __('Event Parent ID', 'event_espresso'), false,
131
+					0),
132
+				'EVT_order'      => new EE_Integer_Field('menu_order', __('Event Menu Order', 'event_espresso'), false,
133
+					1),
134
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_events'),
135
+				// EE_Plain_Text_Field( 'post_type', __( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ),
136
+				'status'         => new EE_WP_Post_Status_Field('post_status', __('Event Status', 'event_espresso'),
137
+					false, 'draft', $this->_custom_stati),
138
+			),
139
+			'Event_Meta' => array(
140
+				'EVTM_ID'                         => new EE_DB_Only_Float_Field('EVTM_ID',
141
+					__('Event Meta Row ID', 'event_espresso'), false),
142
+				'EVT_ID_fk'                       => new EE_DB_Only_Int_Field('EVT_ID',
143
+					__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false),
144
+				'EVT_display_desc'                => new EE_Boolean_Field('EVT_display_desc',
145
+					__('Display Description Flag', 'event_espresso'), false, 1),
146
+				'EVT_display_ticket_selector'     => new EE_Boolean_Field('EVT_display_ticket_selector',
147
+					__('Display Ticket Selector Flag', 'event_espresso'), false, 1),
148
+				'EVT_visible_on'                  => new EE_Datetime_Field('EVT_visible_on',
149
+					__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now),
150
+				'EVT_additional_limit'            => new EE_Integer_Field('EVT_additional_limit',
151
+					__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), true, 10),
152
+				'EVT_default_registration_status' => new EE_Enum_Text_Field(
153
+					'EVT_default_registration_status',
154
+					__('Default Registration Status on this Event', 'event_espresso'), false,
155
+					EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array()
156
+				),
157
+				'EVT_member_only'                 => new EE_Boolean_Field('EVT_member_only',
158
+					__('Member-Only Event Flag', 'event_espresso'), false, false),
159
+				'EVT_phone'                       => new EE_Plain_Text_Field('EVT_phone',
160
+					__('Event Phone Number', 'event_espresso'), false),
161
+				'EVT_allow_overflow'              => new EE_Boolean_Field('EVT_allow_overflow',
162
+					__('Allow Overflow on Event', 'event_espresso'), false, false),
163
+				'EVT_timezone_string'             => new EE_Plain_Text_Field('EVT_timezone_string',
164
+					__('Timezone (name) for Event times', 'event_espresso'), false),
165
+				'EVT_external_URL'                => new EE_Plain_Text_Field('EVT_external_URL',
166
+					__('URL of Event Page if hosted elsewhere', 'event_espresso'), true),
167
+				'EVT_donations'                   => new EE_Boolean_Field('EVT_donations',
168
+					__('Accept Donations?', 'event_espresso'), false, false),
169
+			),
170
+		);
171
+		$this->_model_relations = array(
172
+			'Registration'           => new EE_Has_Many_Relation(),
173
+			'Datetime'               => new EE_Has_Many_Relation(),
174
+			'Question_Group'         => new EE_HABTM_Relation('Event_Question_Group'),
175
+			'Venue'                  => new EE_HABTM_Relation('Event_Venue'),
176
+			'Term_Relationship'      => new EE_Has_Many_Relation(),
177
+			'Term_Taxonomy'          => new EE_HABTM_Relation('Term_Relationship'),
178
+			'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'),
179
+			'Attendee'               => new EE_HABTM_Relation('Registration'),
180
+			'WP_User'                => new EE_Belongs_To_Relation(),
181
+		);
182
+		//this model is generally available for reading
183
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
184
+		parent::__construct($timezone);
185
+	}
186
+
187
+
188
+
189
+	/**
190
+	 * @param string $default_reg_status
191
+	 */
192
+	public static function set_default_reg_status($default_reg_status)
193
+	{
194
+		self::$_default_reg_status = $default_reg_status;
195
+		//if EEM_Event has already been instantiated, then we need to reset the `EVT_default_reg_status` field to use the new default.
196
+		if (self::$_instance instanceof EEM_Event) {
197
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = new EE_Enum_Text_Field(
198
+				'EVT_default_registration_status', __('Default Registration Status on this Event', 'event_espresso'),
199
+				false, $default_reg_status, EEM_Registration::reg_status_array()
200
+			);
201
+			self::$_instance->_fields['Event_Meta']['EVT_default_registration_status']->_construct_finalize('Event_Meta',
202
+				'EVT_default_registration_status', 'EEM_Event');
203
+		}
204
+	}
205
+
206
+
207
+
208
+	/**
209
+	 *        get_question_groups
210
+	 *
211
+	 * @access        public
212
+	 * @return        array
213
+	 */
214
+	public function get_all_question_groups()
215
+	{
216
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(array(
217
+			array('QSG_deleted' => false),
218
+			'order_by' => array('QSG_order' => 'ASC'),
219
+		));
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 *        get_question_groups
226
+	 *
227
+	 * @access        public
228
+	 * @param        int $EVT_ID
229
+	 * @return        array
230
+	 */
231
+	public function get_all_event_question_groups($EVT_ID = 0)
232
+	{
233
+		if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
234
+			EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
235
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
236
+			return false;
237
+		}
238
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array(
239
+			array('EVT_ID' => $EVT_ID),
240
+		));
241
+	}
242
+
243
+
244
+
245
+	/**
246
+	 *        get_question_groups
247
+	 *
248
+	 * @access        public
249
+	 * @param        int     $EVT_ID
250
+	 * @param        boolean $for_primary_attendee
251
+	 * @return        array
252
+	 */
253
+	public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true)
254
+	{
255
+		if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
256
+			EE_Error::add_error(__('An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.',
257
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
258
+			return false;
259
+		}
260
+		return EE_Registry::instance()->load_model('Event_Question_Group')->get_all(array(
261
+			array('EVT_ID' => $EVT_ID, 'EQG_primary' => $for_primary_attendee),
262
+		));
263
+	}
264
+
265
+
266
+
267
+	/**
268
+	 *        get_question_groups
269
+	 *
270
+	 * @access        public
271
+	 * @param        int             $EVT_ID
272
+	 * @param        EE_Registration $registration
273
+	 * @return        array
274
+	 */
275
+	public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration)
276
+	{
277
+		if ( ! isset($EVT_ID) || ! absint($EVT_ID)) {
278
+			EE_Error::add_error(__('An error occurred. No Question Groups could be retrieved because an Event ID was not received.',
279
+				'event_espresso'), __FILE__, __FUNCTION__, __LINE__);
280
+			return false;
281
+		}
282
+		$where_params = array(
283
+			'Event_Question_Group.EVT_ID'      => $EVT_ID,
284
+			'Event_Question_Group.EQG_primary' => $registration->count() == 1 ? true : false,
285
+			'QSG_deleted'                      => false,
286
+		);
287
+		return EE_Registry::instance()->load_model('Question_Group')->get_all(array(
288
+			$where_params,
289
+			'order_by' => array('QSG_order' => 'ASC'),
290
+		));
291
+	}
292
+
293
+
294
+
295
+	/**
296
+	 *        get_question_target_db_column
297
+	 *
298
+	 * @access        public
299
+	 * @param        string $QSG_IDs csv list of $QSG IDs
300
+	 * @return        array
301
+	 */
302
+	public function get_questions_in_groups($QSG_IDs = '')
303
+	{
304
+		if (empty($QSG_IDs)) {
305
+			EE_Error::add_error(__('An error occurred. No Question Group IDs were received.', 'event_espresso'),
306
+				__FILE__, __FUNCTION__, __LINE__);
307
+			return false;
308
+		}
309
+		return EE_Registry::instance()->load_model('Question')->get_all(array(
310
+			array(
311
+				'Question_Group.QSG_ID' => array('IN', $QSG_IDs),
312
+				'QST_deleted'           => false,
313
+				'QST_admin_only'        => is_admin(),
314
+			),
315
+			'order_by' => 'QST_order',
316
+		));
317
+	}
318
+
319
+
320
+
321
+	/**
322
+	 *        get_options_for_question
323
+	 *
324
+	 * @access        public
325
+	 * @param        string $QST_IDs csv list of $QST IDs
326
+	 * @return        array
327
+	 */
328
+	public function get_options_for_question($QST_IDs)
329
+	{
330
+		if (empty($QST_IDs)) {
331
+			EE_Error::add_error(__('An error occurred. No Question IDs were received.', 'event_espresso'), __FILE__,
332
+				__FUNCTION__, __LINE__);
333
+			return false;
334
+		}
335
+		return EE_Registry::instance()->load_model('Question_Option')->get_all(array(
336
+			array(
337
+				'Question.QST_ID' => array('IN', $QST_IDs),
338
+				'QSO_deleted'     => false,
339
+			),
340
+			'order_by' => 'QSO_ID',
341
+		));
342
+	}
343
+
344
+
345
+
346
+	/**
347
+	 *        _get_question_target_db_column
348
+	 *
349
+	 * @deprecated as of 4.8.32.rc.001. Instead consider using
350
+	 *             EE_Registration_Custom_Questions_Form located in
351
+	 *             admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php
352
+	 * @access     public
353
+	 * @param    EE_Registration $registration (so existing answers for registration are included)
354
+	 * @param    int             $EVT_ID       so all question groups are included for event (not just answers from
355
+	 *                                         registration).
356
+	 * @throws EE_Error
357
+	 * @return    array
358
+	 */
359
+	public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0)
360
+	{
361
+		if (empty($EVT_ID)) {
362
+			throw new EE_Error(__('An error occurred. No EVT_ID is included.  Needed to know which question groups to retrieve.',
363
+				'event_espresso'));
364
+		}
365
+		$questions = array();
366
+		// get all question groups for event
367
+		$qgs = $this->get_question_groups_for_event($EVT_ID, $registration);
368
+		if ( ! empty($qgs)) {
369
+			foreach ($qgs as $qg) {
370
+				$qsts = $qg->questions();
371
+				$questions[$qg->ID()] = $qg->model_field_array();
372
+				$questions[$qg->ID()]['QSG_questions'] = array();
373
+				foreach ($qsts as $qst) {
374
+					if ($qst->is_system_question()) {
375
+						continue;
376
+					}
377
+					$answer = EEM_Answer::instance()->get_one(array(
378
+						array(
379
+							'QST_ID' => $qst->ID(),
380
+							'REG_ID' => $registration->ID(),
381
+						),
382
+					));
383
+					$answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
384
+					$qst_name = $qstn_id = $qst->ID();
385
+					$ans_id = $answer->ID();
386
+					$qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
387
+					$input_name = '';
388
+					$input_id = sanitize_key($qst->display_text());
389
+					$input_class = '';
390
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array();
391
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
392
+																						   . $input_name
393
+																						   . $qst_name;
394
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
395
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
396
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
397
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
398
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer;
399
+					//leave responses as-is, don't convert stuff into html entities please!
400
+					$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false;
401
+					if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') {
402
+						$QSOs = $qst->options(true, $answer->value());
403
+						if (is_array($QSOs)) {
404
+							foreach ($QSOs as $QSO_ID => $QSO) {
405
+								$questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array();
406
+							}
407
+						}
408
+					}
409
+				}
410
+			}
411
+		}
412
+		return $questions;
413
+	}
414
+
415
+
416
+
417
+	/**
418
+	 *        _get_question_target_db_column
419
+	 *
420
+	 * @access        private
421
+	 * @param        $QST
422
+	 * @return        string        string
423
+	 */
424
+	private function _generate_question_input_name($QST)
425
+	{
426
+		if ($QST->QST_system) {
427
+			$qst_name = $QST->QST_system;
428
+			/*			switch( $QST->QST_system ) {
429 429
             
430 430
                             case 1 :
431 431
                                     $qst_name = $QST->QST_ID . '-fname';
@@ -468,231 +468,231 @@  discard block
 block discarded – undo
468 468
                                 break;
469 469
             
470 470
                         }*/
471
-        } else {
472
-            //$qst_name = $QST->QST_ID . '-' . str_replace( array( ' ', '-', '.' ), '_', strtolower( $QST->QST_display_text ));
473
-            $qst_name = $QST->QST_ID;
474
-        }
475
-        return $qst_name;
476
-    }
477
-
478
-
479
-
480
-    /**
481
-     * Gets all events that are published and have event start time earlier than now and an event end time later than
482
-     * now
483
-     *
484
-     * @access public
485
-     * @param  array $query_params An array of query params to further filter on (note that status and DTT_EVT_start
486
-     *                             and DTT_EVT_end will be overridden)
487
-     * @param bool   $count        whether to return the count or not (default FALSE)
488
-     * @return array    EE_Event objects
489
-     */
490
-    public function get_active_events($query_params, $count = false)
491
-    {
492
-        if (array_key_exists(0, $query_params)) {
493
-            $where_params = $query_params[0];
494
-            unset($query_params[0]);
495
-        } else {
496
-            $where_params = array();
497
-        }
498
-        //if we have count make sure we don't include group by
499
-        if ($count && isset($query_params['group_by'])) {
500
-            unset($query_params['group_by']);
501
-        }
502
-        //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
503
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
504
-        //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
505
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
506
-            $where_params['Datetime.DTT_EVT_start******'] = array(
507
-                '<',
508
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
509
-            );
510
-        } else {
511
-            $where_params['Datetime.DTT_EVT_start'] = array(
512
-                '<',
513
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
514
-            );
515
-        }
516
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
517
-            $where_params['Datetime.DTT_EVT_end*****'] = array(
518
-                '>',
519
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
520
-            );
521
-        } else {
522
-            $where_params['Datetime.DTT_EVT_end'] = array(
523
-                '>',
524
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
525
-            );
526
-        }
527
-        $query_params[0] = $where_params;
528
-        // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
529
-        return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
530
-    }
531
-
532
-
533
-
534
-    /**
535
-     * get all events that are published and have an event start time later than now
536
-     *
537
-     * @access public
538
-     * @param  array $query_params An array of query params to further filter on (Note that status and DTT_EVT_start
539
-     *                             will be overridden)
540
-     * @param bool   $count        whether to return the count or not (default FALSE)
541
-     * @return array               EE_Event objects
542
-     */
543
-    public function get_upcoming_events($query_params, $count = false)
544
-    {
545
-        if (array_key_exists(0, $query_params)) {
546
-            $where_params = $query_params[0];
547
-            unset($query_params[0]);
548
-        } else {
549
-            $where_params = array();
550
-        }
551
-        //if we have count make sure we don't include group by
552
-        if ($count && isset($query_params['group_by'])) {
553
-            unset($query_params['group_by']);
554
-        }
555
-        //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
556
-        $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
557
-        //if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
558
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
559
-            $where_params['Datetime.DTT_EVT_start*****'] = array(
560
-                '>',
561
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
562
-            );
563
-        } else {
564
-            $where_params['Datetime.DTT_EVT_start'] = array(
565
-                '>',
566
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
567
-            );
568
-        }
569
-        $query_params[0] = $where_params;
570
-        // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
571
-        return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
572
-    }
573
-
574
-
575
-
576
-    /**
577
-     * This only returns events that are expired.  They may still be published but all their datetimes have expired.
578
-     *
579
-     * @access public
580
-     * @param  array $query_params An array of query params to further filter on (note that status and DTT_EVT_end will
581
-     *                             be overridden)
582
-     * @param bool   $count        whether to return the count or not (default FALSE)
583
-     * @return array    EE_Event objects
584
-     */
585
-    public function get_expired_events($query_params, $count = false)
586
-    {
587
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
588
-        //if we have count make sure we don't include group by
589
-        if ($count && isset($query_params['group_by'])) {
590
-            unset($query_params['group_by']);
591
-        }
592
-        //let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
593
-        if (isset($where_params['status'])) {
594
-            unset($where_params['status']);
595
-        }
596
-        $exclude_query = $query_params;
597
-        if (isset($exclude_query[0])) {
598
-            unset($exclude_query[0]);
599
-        }
600
-        $exclude_query[0] = array(
601
-            'Datetime.DTT_EVT_end' => array(
602
-                '>',
603
-                EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
604
-            ),
605
-        );
606
-        //first get all events that have datetimes where its not expired.
607
-        $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
608
-        $event_ids = array_keys($event_ids);
609
-        //if we have any additional query_params, let's add them to the 'AND' condition
610
-        $and_condition = array(
611
-            'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
612
-            'EVT_ID'               => array('NOT IN', $event_ids),
613
-        );
614
-        if (isset($where_params['OR'])) {
615
-            $and_condition['OR'] = $where_params['OR'];
616
-            unset($where_params['OR']);
617
-        }
618
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
619
-            $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
620
-            unset($where_params['Datetime.DTT_EVT_end']);
621
-        }
622
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
623
-            $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
624
-            unset($where_params['Datetime.DTT_EVT_start']);
625
-        }
626
-        //merge remaining $where params with the and conditions.
627
-        $where_params['AND'] = array_merge($and_condition, $where_params);
628
-        $query_params[0] = $where_params;
629
-        // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
630
-        return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
631
-    }
632
-
633
-
634
-
635
-    /**
636
-     * This basically just returns the events that do not have the publish status.
637
-     *
638
-     * @param  array   $query_params An array of query params to further filter on (note that status will be
639
-     *                               overwritten)
640
-     * @param  boolean $count        whether to return the count or not (default FALSE)
641
-     * @return EE_Event[]            array of EE_Event objects
642
-     */
643
-    public function get_inactive_events($query_params, $count = false)
644
-    {
645
-        $where_params = isset($query_params[0]) ? $query_params[0] : array();
646
-        //let's add in specific query_params for inactive events.
647
-        if (isset($where_params['status'])) {
648
-            unset($where_params['status']);
649
-        }
650
-        //if we have count make sure we don't include group by
651
-        if ($count && isset($query_params['group_by'])) {
652
-            unset($query_params['group_by']);
653
-        }
654
-        //if we have any additional query_params, let's add them to the 'AND' condition
655
-        $where_params['AND']['status'] = array('!=', 'publish');
656
-        if (isset($where_params['OR'])) {
657
-            $where_params['AND']['OR'] = $where_params['OR'];
658
-            unset($where_params['OR']);
659
-        }
660
-        if (isset($where_params['Datetime.DTT_EVT_end'])) {
661
-            $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
662
-            unset($where_params['Datetime.DTT_EVT_end']);
663
-        }
664
-        if (isset($where_params['Datetime.DTT_EVT_start'])) {
665
-            $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
666
-            unset($where_params['Datetime.DTT_EVT_start']);
667
-        }
668
-        $query_params[0] = $where_params;
669
-        // don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
670
-        return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
671
-    }
672
-
673
-
674
-
675
-    /**
676
-     * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
677
-     * because we don't want to override any existing global default prices but instead insert NEW prices that get
678
-     * attached to the event. See parent for param descriptions
679
-     */
680
-    public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
681
-    {
682
-        if ($relationName == 'Price') {
683
-            //let's get the PRC object for the given ID to make sure that we aren't dealing with a default
684
-            $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
685
-            //if EVT_ID = 0, then this is a default
686
-            if ($prc_chk->get('EVT_ID') == 0) {
687
-                //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
688
-                $prc_chk->set('PRC_ID', 0);
689
-            }
690
-            //run parent
691
-            return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
692
-        }
693
-        //otherwise carry on as normal
694
-        return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
695
-    }
471
+		} else {
472
+			//$qst_name = $QST->QST_ID . '-' . str_replace( array( ' ', '-', '.' ), '_', strtolower( $QST->QST_display_text ));
473
+			$qst_name = $QST->QST_ID;
474
+		}
475
+		return $qst_name;
476
+	}
477
+
478
+
479
+
480
+	/**
481
+	 * Gets all events that are published and have event start time earlier than now and an event end time later than
482
+	 * now
483
+	 *
484
+	 * @access public
485
+	 * @param  array $query_params An array of query params to further filter on (note that status and DTT_EVT_start
486
+	 *                             and DTT_EVT_end will be overridden)
487
+	 * @param bool   $count        whether to return the count or not (default FALSE)
488
+	 * @return array    EE_Event objects
489
+	 */
490
+	public function get_active_events($query_params, $count = false)
491
+	{
492
+		if (array_key_exists(0, $query_params)) {
493
+			$where_params = $query_params[0];
494
+			unset($query_params[0]);
495
+		} else {
496
+			$where_params = array();
497
+		}
498
+		//if we have count make sure we don't include group by
499
+		if ($count && isset($query_params['group_by'])) {
500
+			unset($query_params['group_by']);
501
+		}
502
+		//let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
503
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
504
+		//if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions
505
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
506
+			$where_params['Datetime.DTT_EVT_start******'] = array(
507
+				'<',
508
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
509
+			);
510
+		} else {
511
+			$where_params['Datetime.DTT_EVT_start'] = array(
512
+				'<',
513
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
514
+			);
515
+		}
516
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
517
+			$where_params['Datetime.DTT_EVT_end*****'] = array(
518
+				'>',
519
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
520
+			);
521
+		} else {
522
+			$where_params['Datetime.DTT_EVT_end'] = array(
523
+				'>',
524
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
525
+			);
526
+		}
527
+		$query_params[0] = $where_params;
528
+		// don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
529
+		return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
530
+	}
531
+
532
+
533
+
534
+	/**
535
+	 * get all events that are published and have an event start time later than now
536
+	 *
537
+	 * @access public
538
+	 * @param  array $query_params An array of query params to further filter on (Note that status and DTT_EVT_start
539
+	 *                             will be overridden)
540
+	 * @param bool   $count        whether to return the count or not (default FALSE)
541
+	 * @return array               EE_Event objects
542
+	 */
543
+	public function get_upcoming_events($query_params, $count = false)
544
+	{
545
+		if (array_key_exists(0, $query_params)) {
546
+			$where_params = $query_params[0];
547
+			unset($query_params[0]);
548
+		} else {
549
+			$where_params = array();
550
+		}
551
+		//if we have count make sure we don't include group by
552
+		if ($count && isset($query_params['group_by'])) {
553
+			unset($query_params['group_by']);
554
+		}
555
+		//let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
556
+		$where_params['status'] = array('IN', array('publish', EEM_Event::sold_out));
557
+		//if there are already query_params matching DTT_EVT_start then we need to modify that to add them.
558
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
559
+			$where_params['Datetime.DTT_EVT_start*****'] = array(
560
+				'>',
561
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
562
+			);
563
+		} else {
564
+			$where_params['Datetime.DTT_EVT_start'] = array(
565
+				'>',
566
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'),
567
+			);
568
+		}
569
+		$query_params[0] = $where_params;
570
+		// don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
571
+		return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
572
+	}
573
+
574
+
575
+
576
+	/**
577
+	 * This only returns events that are expired.  They may still be published but all their datetimes have expired.
578
+	 *
579
+	 * @access public
580
+	 * @param  array $query_params An array of query params to further filter on (note that status and DTT_EVT_end will
581
+	 *                             be overridden)
582
+	 * @param bool   $count        whether to return the count or not (default FALSE)
583
+	 * @return array    EE_Event objects
584
+	 */
585
+	public function get_expired_events($query_params, $count = false)
586
+	{
587
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
588
+		//if we have count make sure we don't include group by
589
+		if ($count && isset($query_params['group_by'])) {
590
+			unset($query_params['group_by']);
591
+		}
592
+		//let's add specific query_params for active_events - keep in mind this will override any sent status in the query AND any date queries.
593
+		if (isset($where_params['status'])) {
594
+			unset($where_params['status']);
595
+		}
596
+		$exclude_query = $query_params;
597
+		if (isset($exclude_query[0])) {
598
+			unset($exclude_query[0]);
599
+		}
600
+		$exclude_query[0] = array(
601
+			'Datetime.DTT_EVT_end' => array(
602
+				'>',
603
+				EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'),
604
+			),
605
+		);
606
+		//first get all events that have datetimes where its not expired.
607
+		$event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID');
608
+		$event_ids = array_keys($event_ids);
609
+		//if we have any additional query_params, let's add them to the 'AND' condition
610
+		$and_condition = array(
611
+			'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')),
612
+			'EVT_ID'               => array('NOT IN', $event_ids),
613
+		);
614
+		if (isset($where_params['OR'])) {
615
+			$and_condition['OR'] = $where_params['OR'];
616
+			unset($where_params['OR']);
617
+		}
618
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
619
+			$and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
620
+			unset($where_params['Datetime.DTT_EVT_end']);
621
+		}
622
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
623
+			$and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
624
+			unset($where_params['Datetime.DTT_EVT_start']);
625
+		}
626
+		//merge remaining $where params with the and conditions.
627
+		$where_params['AND'] = array_merge($and_condition, $where_params);
628
+		$query_params[0] = $where_params;
629
+		// don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
630
+		return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
631
+	}
632
+
633
+
634
+
635
+	/**
636
+	 * This basically just returns the events that do not have the publish status.
637
+	 *
638
+	 * @param  array   $query_params An array of query params to further filter on (note that status will be
639
+	 *                               overwritten)
640
+	 * @param  boolean $count        whether to return the count or not (default FALSE)
641
+	 * @return EE_Event[]            array of EE_Event objects
642
+	 */
643
+	public function get_inactive_events($query_params, $count = false)
644
+	{
645
+		$where_params = isset($query_params[0]) ? $query_params[0] : array();
646
+		//let's add in specific query_params for inactive events.
647
+		if (isset($where_params['status'])) {
648
+			unset($where_params['status']);
649
+		}
650
+		//if we have count make sure we don't include group by
651
+		if ($count && isset($query_params['group_by'])) {
652
+			unset($query_params['group_by']);
653
+		}
654
+		//if we have any additional query_params, let's add them to the 'AND' condition
655
+		$where_params['AND']['status'] = array('!=', 'publish');
656
+		if (isset($where_params['OR'])) {
657
+			$where_params['AND']['OR'] = $where_params['OR'];
658
+			unset($where_params['OR']);
659
+		}
660
+		if (isset($where_params['Datetime.DTT_EVT_end'])) {
661
+			$where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end'];
662
+			unset($where_params['Datetime.DTT_EVT_end']);
663
+		}
664
+		if (isset($where_params['Datetime.DTT_EVT_start'])) {
665
+			$where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start'];
666
+			unset($where_params['Datetime.DTT_EVT_start']);
667
+		}
668
+		$query_params[0] = $where_params;
669
+		// don't use $query_params with count() because we don't want to include additional query clauses like "GROUP BY"
670
+		return $count ? $this->count(array($where_params), 'EVT_ID', true) : $this->get_all($query_params);
671
+	}
672
+
673
+
674
+
675
+	/**
676
+	 * This is just injecting into the parent add_relationship_to so we do special handling on price relationships
677
+	 * because we don't want to override any existing global default prices but instead insert NEW prices that get
678
+	 * attached to the event. See parent for param descriptions
679
+	 */
680
+	public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array())
681
+	{
682
+		if ($relationName == 'Price') {
683
+			//let's get the PRC object for the given ID to make sure that we aren't dealing with a default
684
+			$prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj);
685
+			//if EVT_ID = 0, then this is a default
686
+			if ($prc_chk->get('EVT_ID') == 0) {
687
+				//let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation
688
+				$prc_chk->set('PRC_ID', 0);
689
+			}
690
+			//run parent
691
+			return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query);
692
+		}
693
+		//otherwise carry on as normal
694
+		return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query);
695
+	}
696 696
 
697 697
 
698 698
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4
-require_once(EE_MODELS . 'EEM_CPT_Base.model.php');
4
+require_once(EE_MODELS.'EEM_CPT_Base.model.php');
5 5
 
6 6
 
7 7
 
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
                     $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object();
384 384
                     $qst_name = $qstn_id = $qst->ID();
385 385
                     $ans_id = $answer->ID();
386
-                    $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']';
386
+                    $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']';
387 387
                     $input_name = '';
388 388
                     $input_id = sanitize_key($qst->display_text());
389 389
                     $input_class = '';
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn'
392 392
                                                                                            . $input_name
393 393
                                                                                            . $qst_name;
394
-                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id;
394
+                    $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id;
395 395
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class;
396 396
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array();
397 397
                     $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst;
Please login to merge, or discard this patch.
core/db_models/EEM_Venue.model.php 2 patches
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -25,87 +25,87 @@  discard block
 block discarded – undo
25 25
 class EEM_Venue extends EEM_CPT_Base
26 26
 {
27 27
 
28
-    // private instance of the Attendee object
29
-    protected static $_instance = null;
28
+	// private instance of the Attendee object
29
+	protected static $_instance = null;
30 30
 
31 31
 
32 32
 
33
-    protected function __construct($timezone = null)
34
-    {
35
-        $this->singular_item = __('Venue', 'event_espresso');
36
-        $this->plural_item = __('Venues', 'event_espresso');
37
-        $this->_tables = array(
38
-            'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
39
-            'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
40
-        );
41
-        $this->_fields = array(
42
-            'Venue_CPT'  => array(
43
-                'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
44
-                'VNU_name'       => new EE_Plain_Text_Field('post_title', __("Venue Name", "event_espresso"), false,
45
-                    ''),
46
-                'VNU_desc'       => new EE_Post_Content_Field('post_content', __("Venue Description", "event_espresso"),
47
-                    false, ''),
48
-                'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
49
-                'VNU_created'    => new EE_Datetime_Field('post_date', __("Date Venue Created", "event_espresso"),
50
-                    false, EE_Datetime_Field::now),
51
-                'VNU_short_desc' => new EE_Plain_Text_Field('post_excerpt',
52
-                    __("Short Description of Venue", "event_espresso"), true, ''),
53
-                'VNU_modified'   => new EE_Datetime_Field('post_modified', __("Venue Modified Date", "event_espresso"),
54
-                    false, EE_Datetime_Field::now),
55
-                'VNU_wp_user'    => new EE_WP_User_Field('post_author', __("Venue Creator ID", "event_espresso"),
56
-                    false),
57
-                'parent'         => new EE_Integer_Field('post_parent', __("Venue Parent ID", "event_espresso"), false,
58
-                    0),
59
-                'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
60
-                'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
61
-                // EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'),
62
-            ),
63
-            'Venue_Meta' => array(
64
-                'VNUM_ID'             => new EE_DB_Only_Int_Field('VNUM_ID',
65
-                    __("ID of Venue Meta Row", "event_espresso"), false),
66
-                'VNU_ID_fk'           => new EE_DB_Only_Int_Field('VNU_ID',
67
-                    __("Foreign Key to Venue Post ", "event_espresso"), false),
68
-                'VNU_address'         => new EE_Plain_Text_Field('VNU_address',
69
-                    __("Venue Address line 1", "event_espresso"), true, ''),
70
-                'VNU_address2'        => new EE_Plain_Text_Field('VNU_address2',
71
-                    __("Venue Address line 2", "event_espresso"), true, ''),
72
-                'VNU_city'            => new EE_Plain_Text_Field('VNU_city', __("Venue City", "event_espresso"), true,
73
-                    ''),
74
-                'STA_ID'              => new EE_Foreign_Key_Int_Field('STA_ID', __("State ID", "event_espresso"), true,
75
-                    null, 'State'),
76
-                'CNT_ISO'             => new EE_Foreign_Key_String_Field('CNT_ISO',
77
-                    __("Country Code", "event_espresso"), true, null, 'Country'),
78
-                'VNU_zip'             => new EE_Plain_Text_Field('VNU_zip',
79
-                    __("Venue Zip/Postal Code", "event_espresso"), true),
80
-                'VNU_phone'           => new EE_Plain_Text_Field('VNU_phone', __("Venue Phone", "event_espresso"),
81
-                    true),
82
-                'VNU_capacity'        => new EE_Infinite_Integer_Field('VNU_capacity',
83
-                    __("Venue Capacity", "event_espresso"), true, EE_INF),
84
-                'VNU_url'             => new EE_Plain_Text_Field('VNU_url', __('Venue Website', 'event_espresso'),
85
-                    true),
86
-                'VNU_virtual_phone'   => new EE_Plain_Text_Field('VNU_virtual_phone',
87
-                    __('Call in Number', 'event_espresso'), true),
88
-                'VNU_virtual_url'     => new EE_Plain_Text_Field('VNU_virtual_url', __('Virtual URL', 'event_espresso'),
89
-                    true),
90
-                'VNU_google_map_link' => new EE_Plain_Text_Field('VNU_google_map_link',
91
-                    __('Google Map Link', 'event_espresso'), true),
92
-                'VNU_enable_for_gmap' => new EE_Boolean_Field('VNU_enable_for_gmap',
93
-                    __('Show Google Map?', 'event_espresso'), false, false),
94
-            ),
95
-        );
96
-        $this->_model_relations = array(
97
-            'Event'             => new EE_HABTM_Relation('Event_Venue'),
98
-            'State'             => new EE_Belongs_To_Relation(),
99
-            'Country'           => new EE_Belongs_To_Relation(),
100
-            'Event_Venue'       => new EE_Has_Many_Relation(),
101
-            'WP_User'           => new EE_Belongs_To_Relation(),
102
-            'Term_Relationship' => new EE_Has_Many_Relation(),
103
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
104
-        );
105
-        //this model is generally available for reading
106
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
107
-        parent::__construct($timezone);
108
-    }
33
+	protected function __construct($timezone = null)
34
+	{
35
+		$this->singular_item = __('Venue', 'event_espresso');
36
+		$this->plural_item = __('Venues', 'event_espresso');
37
+		$this->_tables = array(
38
+			'Venue_CPT'  => new EE_Primary_Table('posts', 'ID'),
39
+			'Venue_Meta' => new EE_Secondary_Table('esp_venue_meta', 'VNUM_ID', 'VNU_ID'),
40
+		);
41
+		$this->_fields = array(
42
+			'Venue_CPT'  => array(
43
+				'VNU_ID'         => new EE_Primary_Key_Int_Field('ID', __("Venue ID", "event_espresso")),
44
+				'VNU_name'       => new EE_Plain_Text_Field('post_title', __("Venue Name", "event_espresso"), false,
45
+					''),
46
+				'VNU_desc'       => new EE_Post_Content_Field('post_content', __("Venue Description", "event_espresso"),
47
+					false, ''),
48
+				'VNU_identifier' => new EE_Slug_Field('post_name', __("Venue Identifier", "event_espresso"), false, ''),
49
+				'VNU_created'    => new EE_Datetime_Field('post_date', __("Date Venue Created", "event_espresso"),
50
+					false, EE_Datetime_Field::now),
51
+				'VNU_short_desc' => new EE_Plain_Text_Field('post_excerpt',
52
+					__("Short Description of Venue", "event_espresso"), true, ''),
53
+				'VNU_modified'   => new EE_Datetime_Field('post_modified', __("Venue Modified Date", "event_espresso"),
54
+					false, EE_Datetime_Field::now),
55
+				'VNU_wp_user'    => new EE_WP_User_Field('post_author', __("Venue Creator ID", "event_espresso"),
56
+					false),
57
+				'parent'         => new EE_Integer_Field('post_parent', __("Venue Parent ID", "event_espresso"), false,
58
+					0),
59
+				'VNU_order'      => new EE_Integer_Field('menu_order', __("Venue order", "event_espresso"), false, 1),
60
+				'post_type'      => new EE_WP_Post_Type_Field('espresso_venues'),
61
+				// EE_Plain_Text_Field('post_type', __("Venue post type", "event_espresso"), false, 'espresso_venues'),
62
+			),
63
+			'Venue_Meta' => array(
64
+				'VNUM_ID'             => new EE_DB_Only_Int_Field('VNUM_ID',
65
+					__("ID of Venue Meta Row", "event_espresso"), false),
66
+				'VNU_ID_fk'           => new EE_DB_Only_Int_Field('VNU_ID',
67
+					__("Foreign Key to Venue Post ", "event_espresso"), false),
68
+				'VNU_address'         => new EE_Plain_Text_Field('VNU_address',
69
+					__("Venue Address line 1", "event_espresso"), true, ''),
70
+				'VNU_address2'        => new EE_Plain_Text_Field('VNU_address2',
71
+					__("Venue Address line 2", "event_espresso"), true, ''),
72
+				'VNU_city'            => new EE_Plain_Text_Field('VNU_city', __("Venue City", "event_espresso"), true,
73
+					''),
74
+				'STA_ID'              => new EE_Foreign_Key_Int_Field('STA_ID', __("State ID", "event_espresso"), true,
75
+					null, 'State'),
76
+				'CNT_ISO'             => new EE_Foreign_Key_String_Field('CNT_ISO',
77
+					__("Country Code", "event_espresso"), true, null, 'Country'),
78
+				'VNU_zip'             => new EE_Plain_Text_Field('VNU_zip',
79
+					__("Venue Zip/Postal Code", "event_espresso"), true),
80
+				'VNU_phone'           => new EE_Plain_Text_Field('VNU_phone', __("Venue Phone", "event_espresso"),
81
+					true),
82
+				'VNU_capacity'        => new EE_Infinite_Integer_Field('VNU_capacity',
83
+					__("Venue Capacity", "event_espresso"), true, EE_INF),
84
+				'VNU_url'             => new EE_Plain_Text_Field('VNU_url', __('Venue Website', 'event_espresso'),
85
+					true),
86
+				'VNU_virtual_phone'   => new EE_Plain_Text_Field('VNU_virtual_phone',
87
+					__('Call in Number', 'event_espresso'), true),
88
+				'VNU_virtual_url'     => new EE_Plain_Text_Field('VNU_virtual_url', __('Virtual URL', 'event_espresso'),
89
+					true),
90
+				'VNU_google_map_link' => new EE_Plain_Text_Field('VNU_google_map_link',
91
+					__('Google Map Link', 'event_espresso'), true),
92
+				'VNU_enable_for_gmap' => new EE_Boolean_Field('VNU_enable_for_gmap',
93
+					__('Show Google Map?', 'event_espresso'), false, false),
94
+			),
95
+		);
96
+		$this->_model_relations = array(
97
+			'Event'             => new EE_HABTM_Relation('Event_Venue'),
98
+			'State'             => new EE_Belongs_To_Relation(),
99
+			'Country'           => new EE_Belongs_To_Relation(),
100
+			'Event_Venue'       => new EE_Has_Many_Relation(),
101
+			'WP_User'           => new EE_Belongs_To_Relation(),
102
+			'Term_Relationship' => new EE_Has_Many_Relation(),
103
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
104
+		);
105
+		//this model is generally available for reading
106
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
107
+		parent::__construct($timezone);
108
+	}
109 109
 
110 110
 }
111 111
 // End of file EEM_Venue.model.php
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
  * @author                Michael Nelson
19 19
  *                        ------------------------------------------------------------------------
20 20
  */
21
-require_once(EE_MODELS . 'EEM_Base.model.php');
21
+require_once(EE_MODELS.'EEM_Base.model.php');
22 22
 
23 23
 
24 24
 
Please login to merge, or discard this patch.
core/domain/entities/DbSafeDateTime.php 2 patches
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -32,24 +32,24 @@  discard block
 block discarded – undo
32 32
 	protected $_datetime_string = '';
33 33
 
34 34
 	/**
35
-     * where to write the error log to
36
-     *
37
-     * @type string $_error_log_dir
35
+	 * where to write the error log to
36
+	 *
37
+	 * @type string $_error_log_dir
38 38
 	 */
39 39
 	protected $_error_log_dir = '';
40 40
 
41 41
 
42 42
 
43
-    /**
44
-     * @param string $error_log_dir
45
-     */
46
-    public function setErrorLogDir($error_log_dir)
47
-    {
48
-        // if the folder path is writable, then except the path + filename, else keep empty
49
-        $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
50
-            ?  $error_log_dir
51
-            : '';
52
-    }
43
+	/**
44
+	 * @param string $error_log_dir
45
+	 */
46
+	public function setErrorLogDir($error_log_dir)
47
+	{
48
+		// if the folder path is writable, then except the path + filename, else keep empty
49
+		$this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
50
+			?  $error_log_dir
51
+			: '';
52
+	}
53 53
 
54 54
 
55 55
 
@@ -61,73 +61,73 @@  discard block
 block discarded – undo
61 61
 
62 62
 	public function __sleep() {
63 63
 		$this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format );
64
-        $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
65
-        if ( ! $date instanceof \DateTime) {
66
-            try {
67
-                // we want a stack trace to determine where the malformed date came from, so...
68
-                throw new \DomainException();
69
-            } catch (\DomainException $e) {
70
-                $stack_trace = $e->getTraceAsString();
71
-            }
72
-            $this->writeToErrorLog(
73
-                sprintf(
74
-                    __(
75
-                        'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s',
76
-                        'event_espresso'
77
-                    ),
78
-                    $this->_datetime_string,
79
-                    '<br />',
80
-                    print_r(\DateTime::getLastErrors(), true),
81
-                    PHP_VERSION,
82
-                    $stack_trace
83
-                )
84
-            );
85
-        }
86
-        return array( '_datetime_string' );
64
+		$date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
65
+		if ( ! $date instanceof \DateTime) {
66
+			try {
67
+				// we want a stack trace to determine where the malformed date came from, so...
68
+				throw new \DomainException();
69
+			} catch (\DomainException $e) {
70
+				$stack_trace = $e->getTraceAsString();
71
+			}
72
+			$this->writeToErrorLog(
73
+				sprintf(
74
+					__(
75
+						'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s',
76
+						'event_espresso'
77
+					),
78
+					$this->_datetime_string,
79
+					'<br />',
80
+					print_r(\DateTime::getLastErrors(), true),
81
+					PHP_VERSION,
82
+					$stack_trace
83
+				)
84
+			);
85
+		}
86
+		return array( '_datetime_string' );
87 87
 	}
88 88
 
89 89
 
90 90
 
91 91
 	public function __wakeup() {
92
-	    // if an empty or null value got saved to the db for a datetime,
93
-        // then some servers and/or PHP itself will incorrectly convert that date string
94
-        // resulting in "-0001-11-30" for the year-month-day.
95
-        // We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created,
96
-        // but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
97
-        // so we're no better off, but at least things won't go fatal on us.
98
-        $this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string);
92
+		// if an empty or null value got saved to the db for a datetime,
93
+		// then some servers and/or PHP itself will incorrectly convert that date string
94
+		// resulting in "-0001-11-30" for the year-month-day.
95
+		// We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created,
96
+		// but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
97
+		// so we're no better off, but at least things won't go fatal on us.
98
+		$this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string);
99 99
 		$date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string );
100 100
 		if ( ! $date instanceof \DateTime) {
101
-            $this->writeToErrorLog(
102
-                sprintf(
103
-                    __(
104
-                        'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s',
105
-                        'event_espresso'
106
-                    ),
107
-                    $this->_datetime_string,
108
-                    '<br />',
109
-                    print_r(\DateTime::getLastErrors(), true),
110
-                    PHP_VERSION
111
-                )
112
-            );
113
-        } else {
114
-            $this->__construct(
115
-                $date->format(\EE_Datetime_Field::mysql_timestamp_format),
116
-                new \DateTimeZone($date->format('e'))
117
-            );
118
-        }
101
+			$this->writeToErrorLog(
102
+				sprintf(
103
+					__(
104
+						'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s',
105
+						'event_espresso'
106
+					),
107
+					$this->_datetime_string,
108
+					'<br />',
109
+					print_r(\DateTime::getLastErrors(), true),
110
+					PHP_VERSION
111
+				)
112
+			);
113
+		} else {
114
+			$this->__construct(
115
+				$date->format(\EE_Datetime_Field::mysql_timestamp_format),
116
+				new \DateTimeZone($date->format('e'))
117
+			);
118
+		}
119 119
 	}
120 120
 
121 121
 
122 122
 
123
-    private function writeToErrorLog($message)
124
-    {
125
-        if ( ! empty($this->_error_log_dir)) {
126
-            error_log($message, 3, $this->_error_log_dir);
127
-        } else {
128
-            error_log($message);
129
-        }
130
-    }
123
+	private function writeToErrorLog($message)
124
+	{
125
+		if ( ! empty($this->_error_log_dir)) {
126
+			error_log($message, 3, $this->_error_log_dir);
127
+		} else {
128
+			error_log($message);
129
+		}
130
+	}
131 131
 
132 132
 
133 133
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace EventEspresso\core\domain\entities;
3 3
 
4
-if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
5
-	exit( 'No direct script access allowed' );
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 
@@ -47,20 +47,20 @@  discard block
 block discarded – undo
47 47
     {
48 48
         // if the folder path is writable, then except the path + filename, else keep empty
49 49
         $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir))
50
-            ?  $error_log_dir
50
+            ? $error_log_dir
51 51
             : '';
52 52
     }
53 53
 
54 54
 
55 55
 
56 56
 	public function __toString() {
57
-		return $this->format( DbSafeDateTime::db_safe_timestamp_format );
57
+		return $this->format(DbSafeDateTime::db_safe_timestamp_format);
58 58
 	}
59 59
 
60 60
 
61 61
 
62 62
 	public function __sleep() {
63
-		$this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format );
63
+		$this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format);
64 64
         $date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
65 65
         if ( ! $date instanceof \DateTime) {
66 66
             try {
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
                 )
84 84
             );
85 85
         }
86
-        return array( '_datetime_string' );
86
+        return array('_datetime_string');
87 87
 	}
88 88
 
89 89
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
         // but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000".
97 97
         // so we're no better off, but at least things won't go fatal on us.
98 98
         $this->_datetime_string = str_replace('-0001-11-30', '0000-00-00', $this->_datetime_string);
99
-		$date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string );
99
+		$date = \DateTime::createFromFormat(DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string);
100 100
 		if ( ! $date instanceof \DateTime) {
101 101
             $this->writeToErrorLog(
102 102
                 sprintf(
Please login to merge, or discard this patch.
core/db_classes/EE_Message.class.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -697,7 +697,7 @@
 block discarded – undo
697 697
     /**
698 698
      * Gets any error message.
699 699
      *
700
-     * @return mixed|null
700
+     * @return string
701 701
      */
702 702
     public function error_message()
703 703
     {
Please login to merge, or discard this patch.
Indentation   +838 added lines, -838 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 
5 5
 /**
@@ -12,843 +12,843 @@  discard block
 block discarded – undo
12 12
 class EE_Message extends EE_Base_Class implements EEI_Admin_Links
13 13
 {
14 14
 
15
-    /**
16
-     * @deprecated 4.9.0  Added for backward compat with add-on's
17
-     * @type null
18
-     */
19
-    public $template_pack;
20
-
21
-    /**
22
-     * @deprecated 4.9.0 Added for backward compat with add-on's
23
-     * @type null
24
-     */
25
-    public $template_variation;
26
-
27
-    /**
28
-     * @deprecated 4.9.0 Added for backward compat with add-on's
29
-     * @type string
30
-     */
31
-    public $content = '';
32
-
33
-
34
-    /**
35
-     * @type EE_messenger $_messenger
36
-     */
37
-    protected $_messenger = null;
38
-
39
-    /**
40
-     * @type EE_message_type $_message_type
41
-     */
42
-    protected $_message_type = null;
43
-
44
-
45
-    /**
46
-     * @param array  $props_n_values
47
-     * @param string $timezone
48
-     * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
49
-     *                             format.
50
-     * @return EE_Message
51
-     */
52
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
53
-    {
54
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__);
55
-        //if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
56
-        if ( ! $has_object) {
57
-            EE_Registry::instance()->load_helper('URL');
58
-            $props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
59
-        }
60
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
61
-    }
62
-
63
-
64
-    /**
65
-     * @param array  $props_n_values
66
-     * @param string $timezone
67
-     * @return EE_Message
68
-     */
69
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
70
-    {
71
-        return new self($props_n_values, true, $timezone);
72
-    }
73
-
74
-
75
-    /**
76
-     * Gets MSG_token
77
-     *
78
-     * @return int
79
-     */
80
-    public function MSG_token()
81
-    {
82
-        return $this->get('MSG_token');
83
-    }
84
-
85
-
86
-    /**
87
-     * Sets MSG_token
88
-     *
89
-     * @param int $MSG_token
90
-     */
91
-    public function set_MSG_token($MSG_token)
92
-    {
93
-        $this->set('MSG_token', $MSG_token);
94
-    }
95
-
96
-
97
-    /**
98
-     * Gets GRP_ID
99
-     *
100
-     * @return int
101
-     */
102
-    public function GRP_ID()
103
-    {
104
-        return $this->get('GRP_ID');
105
-    }
106
-
107
-
108
-    /**
109
-     * Sets GRP_ID
110
-     *
111
-     * @param int $GRP_ID
112
-     */
113
-    public function set_GRP_ID($GRP_ID)
114
-    {
115
-        $this->set('GRP_ID', $GRP_ID);
116
-    }
117
-
118
-
119
-    /**
120
-     * Gets TXN_ID
121
-     *
122
-     * @return int
123
-     */
124
-    public function TXN_ID()
125
-    {
126
-        return $this->get('TXN_ID');
127
-    }
128
-
129
-
130
-    /**
131
-     * Sets TXN_ID
132
-     *
133
-     * @param int $TXN_ID
134
-     */
135
-    public function set_TXN_ID($TXN_ID)
136
-    {
137
-        $this->set('TXN_ID', $TXN_ID);
138
-    }
139
-
140
-
141
-    /**
142
-     * Gets messenger
143
-     *
144
-     * @return string
145
-     */
146
-    public function messenger()
147
-    {
148
-        return $this->get('MSG_messenger');
149
-    }
150
-
151
-
152
-    /**
153
-     * Sets messenger
154
-     *
155
-     * @param string $messenger
156
-     */
157
-    public function set_messenger($messenger)
158
-    {
159
-        $this->set('MSG_messenger', $messenger);
160
-    }
161
-
162
-
163
-    /**
164
-     * Returns corresponding messenger object for the set messenger on this message
165
-     *
166
-     * @return EE_messenger | null
167
-     */
168
-    public function messenger_object()
169
-    {
170
-        return $this->_messenger;
171
-    }
172
-
173
-
174
-    /**
175
-     * Sets messenger
176
-     *
177
-     * @param EE_messenger $messenger
178
-     */
179
-    public function set_messenger_object(EE_messenger $messenger)
180
-    {
181
-        $this->_messenger = $messenger;
182
-    }
183
-
184
-
185
-    /**
186
-     * validates messenger
187
-     *
188
-     * @param bool $throw_exceptions
189
-     * @return bool
190
-     * @throws \EE_Error
191
-     */
192
-    public function valid_messenger($throw_exceptions = false)
193
-    {
194
-        if ($this->_messenger instanceof EE_messenger) {
195
-            return true;
196
-        }
197
-        if ($throw_exceptions) {
198
-            throw new EE_Error(
199
-                sprintf(
200
-                    __(
201
-                        'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
202
-                        'event_espresso'
203
-                    ),
204
-                    $this->messenger()
205
-                )
206
-            );
207
-        }
208
-        return false;
209
-    }
210
-
211
-
212
-    /**
213
-     * This returns the set localized label for the messenger on this message.
214
-     * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
215
-     * with this message.
216
-     *
217
-     * @param   bool $plural whether to return the plural label or not.
218
-     * @return string
219
-     */
220
-    public function messenger_label($plural = false)
221
-    {
222
-        $label_type = $plural ? 'plural' : 'singular';
223
-        $messenger  = $this->messenger_object();
224
-        return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger();
225
-    }
226
-
227
-
228
-    /**
229
-     * Gets message_type
230
-     *
231
-     * @return string
232
-     */
233
-    public function message_type()
234
-    {
235
-        return $this->get('MSG_message_type');
236
-    }
237
-
238
-
239
-    /**
240
-     * Sets message_type
241
-     *
242
-     * @param string $message_type
243
-     */
244
-    public function set_message_type($message_type)
245
-    {
246
-        $this->set('MSG_message_type', $message_type);
247
-    }
248
-
249
-
250
-    /**
251
-     * Returns the message type object for the set message type on this message
252
-     *
253
-     * @return EE_message_type | null
254
-     */
255
-    public function message_type_object()
256
-    {
257
-        return $this->_message_type;
258
-    }
259
-
260
-
261
-    /**
262
-     * Sets message_type
263
-     *
264
-     * @param EE_message_type $message_type
265
-     * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
266
-     *                                        the message type or not.
267
-     */
268
-    public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
269
-    {
270
-        $this->_message_type = $message_type;
271
-        if ($set_priority) {
272
-            $this->set_priority($this->_message_type->get_priority());
273
-        }
274
-    }
275
-
276
-
277
-    /**
278
-     * validates message_type
279
-     *
280
-     * @param bool $throw_exceptions
281
-     * @return bool
282
-     * @throws \EE_Error
283
-     */
284
-    public function valid_message_type($throw_exceptions = false)
285
-    {
286
-        if ($this->_message_type instanceof EE_message_type) {
287
-            return true;
288
-        }
289
-        if ($throw_exceptions) {
290
-            throw new EE_Error(
291
-                sprintf(
292
-                    __(
293
-                        'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
294
-                        'event_espresso'
295
-                    ),
296
-                    $this->message_type()
297
-                )
298
-            );
299
-        }
300
-        return false;
301
-    }
302
-
303
-
304
-    /**
305
-     * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
306
-     *
307
-     * @param bool $throw_exceptions
308
-     * @return bool
309
-     * @throws \EE_Error
310
-     */
311
-    public function is_valid($throw_exceptions = false)
312
-    {
313
-        if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
314
-            return true;
315
-        }
316
-        return false;
317
-    }
318
-
319
-
320
-    /**
321
-     * This validates whether the internal messenger and message type objects are valid for sending.
322
-     * Three checks are done:
323
-     * 1. There is a valid messenger object.
324
-     * 2. There is a valid message type object.
325
-     * 3. The message type object is active for the messenger.
326
-     *
327
-     * @throws EE_Error  But only if $throw_exceptions is set to true.
328
-     * @param bool $throw_exceptions
329
-     * @return bool
330
-     */
331
-    public function is_valid_for_sending_or_generation($throw_exceptions = false)
332
-    {
333
-        $valid = false;
334
-        if ($this->is_valid($throw_exceptions)) {
335
-            /** @var EE_Message_Resource_Manager $message_resource_manager */
336
-            $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
337
-            $valid                    = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(),
338
-                $this->message_type());
339
-            if ( ! $valid && $throw_exceptions) {
340
-                throw new EE_Error(
341
-                    sprintf(
342
-                        __('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
-                            'event_espresso'),
344
-                        $this->message_type(),
345
-                        $this->messenger()
346
-                    )
347
-                );
348
-            }
349
-        }
350
-        return $valid;
351
-    }
352
-
353
-
354
-    /**
355
-     * This returns the set localized label for the message type on this message.
356
-     * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
357
-     * with this message.
358
-     *
359
-     * @param   bool $plural whether to return the plural label or not.
360
-     * @return string
361
-     */
362
-    public function message_type_label($plural = false)
363
-    {
364
-        $label_type   = $plural ? 'plural' : 'singular';
365
-        $message_type = $this->message_type_object();
366
-        return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : $this->message_type();
367
-    }
368
-
369
-
370
-    /**
371
-     * Gets context
372
-     *
373
-     * @return string
374
-     */
375
-    public function context()
376
-    {
377
-        return $this->get('MSG_context');
378
-    }
379
-
380
-
381
-    /**
382
-     * This returns the corresponding localized label for the given context slug, if possible from installed message
383
-     * types. Otherwise, this will just return the set context slug on this object.
384
-     *
385
-     * @return string
386
-     */
387
-    public function context_label()
388
-    {
389
-        /** @type EE_Message_Resource_Manager $message_resource_manager */
390
-        $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
-        $contexts                 = $message_resource_manager->get_all_contexts();
392
-        return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context();
393
-    }
394
-
395
-
396
-    /**
397
-     * Sets context
398
-     *
399
-     * @param string $context
400
-     */
401
-    public function set_context($context)
402
-    {
403
-        $this->set('MSG_context', $context);
404
-    }
405
-
406
-
407
-    /**
408
-     * Gets recipient_ID
409
-     *
410
-     * @return int
411
-     */
412
-    public function recipient_ID()
413
-    {
414
-        return $this->get('MSG_recipient_ID');
415
-    }
416
-
417
-
418
-    /**
419
-     * Sets recipient_ID
420
-     *
421
-     * @param string $recipient_ID
422
-     */
423
-    public function set_recipient_ID($recipient_ID)
424
-    {
425
-        $this->set('MSG_recipient_ID', $recipient_ID);
426
-    }
427
-
428
-
429
-    /**
430
-     * Gets recipient_type
431
-     *
432
-     * @return string
433
-     */
434
-    public function recipient_type()
435
-    {
436
-        return $this->get('MSG_recipient_type');
437
-    }
438
-
439
-
440
-    /**
441
-     * Return the related object matching the recipient type and ID.
442
-     *
443
-     * @return EE_Base_Class | null
444
-     */
445
-    public function recipient_object()
446
-    {
447
-        if ( ! $this->recipient_type() || ! $this->recipient_ID()) {
448
-            return null;
449
-        }
450
-
451
-        return $this->get_first_related($this->recipient_type());
452
-    }
453
-
454
-
455
-    /**
456
-     * Sets recipient_type
457
-     *
458
-     * @param string $recipient_type
459
-     */
460
-    public function set_recipient_type($recipient_type)
461
-    {
462
-        $this->set('MSG_recipient_type', $recipient_type);
463
-    }
464
-
465
-
466
-    /**
467
-     * Gets content
468
-     *
469
-     * @return string
470
-     */
471
-    public function content()
472
-    {
473
-        return $this->get('MSG_content');
474
-    }
475
-
476
-
477
-    /**
478
-     * Sets content
479
-     *
480
-     * @param string $content
481
-     */
482
-    public function set_content($content)
483
-    {
484
-        $this->set('MSG_content', $content);
485
-    }
486
-
487
-
488
-    /**
489
-     * Gets subject
490
-     *
491
-     * @return string
492
-     */
493
-    public function subject()
494
-    {
495
-        return $this->get('MSG_subject');
496
-    }
497
-
498
-
499
-    /**
500
-     * Sets subject
501
-     *
502
-     * @param string $subject
503
-     */
504
-    public function set_subject($subject)
505
-    {
506
-        $this->set('MSG_subject', $subject);
507
-    }
508
-
509
-
510
-    /**
511
-     * Gets to
512
-     *
513
-     * @return string
514
-     */
515
-    public function to()
516
-    {
517
-        $to = $this->get('MSG_to');
518
-        return empty($to) ? __('No recipient', 'event_espresso') : $to;
519
-    }
520
-
521
-
522
-    /**
523
-     * Sets to
524
-     *
525
-     * @param string $to
526
-     */
527
-    public function set_to($to)
528
-    {
529
-        $this->set('MSG_to', $to);
530
-    }
531
-
532
-
533
-    /**
534
-     * Gets from
535
-     *
536
-     * @return string
537
-     */
538
-    public function from()
539
-    {
540
-        return $this->get('MSG_from');
541
-    }
542
-
543
-
544
-    /**
545
-     * Sets from
546
-     *
547
-     * @param string $from
548
-     */
549
-    public function set_from($from)
550
-    {
551
-        $this->set('MSG_from', $from);
552
-    }
553
-
554
-
555
-    /**
556
-     * Gets priority
557
-     *
558
-     * @return int
559
-     */
560
-    public function priority()
561
-    {
562
-        return $this->get('MSG_priority');
563
-    }
564
-
565
-
566
-    /**
567
-     * Sets priority
568
-     * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
569
-     * this method calls the send_now method to verify that.
570
-     *
571
-     * @param int $priority
572
-     */
573
-    public function set_priority($priority)
574
-    {
575
-        $priority = $this->send_now() ? EEM_Message::priority_high : $priority;
576
-        parent::set('MSG_priority', $priority);
577
-    }
578
-
579
-
580
-    /**
581
-     * Overrides parent::set method so we can capture any sets for priority.
582
-     *
583
-     * @see parent::set() for phpdocs
584
-     * @param string $field_name
585
-     * @param mixed  $field_value
586
-     * @param bool   $use_default
587
-     * @throws EE_Error
588
-     */
589
-    public function set($field_name, $field_value, $use_default = false)
590
-    {
591
-        if ($field_name === 'MSG_priority') {
592
-            $this->set_priority($field_value);
593
-        }
594
-        parent::set($field_name, $field_value, $use_default);
595
-    }
596
-
597
-
598
-    /**
599
-     * @return bool
600
-     * @throws \EE_Error
601
-     */
602
-    public function send_now()
603
-    {
604
-        $send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority();
605
-        return $send_now === EEM_Message::priority_high ? true : false;
606
-    }
607
-
608
-
609
-    /**
610
-     * Gets STS_ID
611
-     *
612
-     * @return string
613
-     */
614
-    public function STS_ID()
615
-    {
616
-        return $this->get('STS_ID');
617
-    }
618
-
619
-
620
-    /**
621
-     * Sets STS_ID
622
-     *
623
-     * @param string $STS_ID
624
-     */
625
-    public function set_STS_ID($STS_ID)
626
-    {
627
-        $this->set('STS_ID', $STS_ID);
628
-    }
629
-
630
-
631
-    /**
632
-     * Gets created
633
-     *
634
-     * @return string
635
-     */
636
-    public function created()
637
-    {
638
-        return $this->get('MSG_created');
639
-    }
640
-
641
-
642
-    /**
643
-     * Sets created
644
-     *
645
-     * @param string $created
646
-     */
647
-    public function set_created($created)
648
-    {
649
-        $this->set('MSG_created', $created);
650
-    }
651
-
652
-
653
-    /**
654
-     * Gets modified
655
-     *
656
-     * @return string
657
-     */
658
-    public function modified()
659
-    {
660
-        return $this->get('MSG_modified');
661
-    }
662
-
663
-
664
-    /**
665
-     * Sets modified
666
-     *
667
-     * @param string $modified
668
-     */
669
-    public function set_modified($modified)
670
-    {
671
-        $this->set('MSG_modified', $modified);
672
-    }
673
-
674
-
675
-    /**
676
-     * Sets generation data for this message.
677
-     *
678
-     * @param mixed $data
679
-     */
680
-    public function set_generation_data($data)
681
-    {
682
-        $this->set_field_or_extra_meta('MSG_generation_data', $data);
683
-    }
684
-
685
-
686
-    /**
687
-     * Returns any set generation data for this message.
688
-     *
689
-     * @return mixed|null
690
-     */
691
-    public function get_generation_data()
692
-    {
693
-        return $this->get_field_or_extra_meta('MSG_generation_data');
694
-    }
695
-
696
-
697
-    /**
698
-     * Gets any error message.
699
-     *
700
-     * @return mixed|null
701
-     */
702
-    public function error_message()
703
-    {
704
-        return $this->get_field_or_extra_meta('MSG_error');
705
-    }
706
-
707
-
708
-    /**
709
-     * Sets an error message.
710
-     *
711
-     * @param $message
712
-     * @return bool|int
713
-     */
714
-    public function set_error_message($message)
715
-    {
716
-        return $this->set_field_or_extra_meta('MSG_error', $message);
717
-    }
718
-
719
-
720
-    /**
721
-     * This retrieves the associated template pack with this message.
722
-     *
723
-     * @return EE_Messages_Template_Pack | null
724
-     */
725
-    public function get_template_pack()
726
-    {
727
-        /**
728
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
729
-         */
730
-        if ( ! empty($this->template_pack)) {
731
-            return $this->template_pack;
732
-        }
733
-        /** @type EE_Message_Template_Group $grp */
734
-        $grp = $this->get_first_related('Message_Template_Group');
735
-        //if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
736
-        if ( ! $grp instanceof EE_Message_Template_Group) {
737
-            $grp = EEM_Message_Template_Group::instance()->get_one(
738
-                array(
739
-                    array(
740
-                        'MTP_messenger'    => $this->messenger(),
741
-                        'MTP_message_type' => $this->message_type(),
742
-                        'MTP_is_global'    => true,
743
-                    ),
744
-                )
745
-            );
746
-        }
747
-
748
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
749
-    }
750
-
751
-
752
-    /**
753
-     * Retrieves the variation used for generating this message.
754
-     *
755
-     * @return string
756
-     */
757
-    public function get_template_pack_variation()
758
-    {
759
-        /**
760
-         * This is deprecated functionality that will be removed eventually but included here now for backward compat.
761
-         */
762
-        if ( ! empty($this->template_variation)) {
763
-            return $this->template_variation;
764
-        }
765
-
766
-        /** @type EE_Message_Template_Group $grp */
767
-        $grp = $this->get_first_related('Message_Template_Group');
768
-
769
-        //if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
770
-        if ( ! $grp instanceof EE_Message_Template_Group) {
771
-            $grp = EEM_Message_Template_Group::instance()->get_one(
772
-                array(
773
-                    array(
774
-                        'MTP_messenger'    => $this->messenger(),
775
-                        'MTP_message_type' => $this->message_type(),
776
-                        'MTP_is_global'    => true,
777
-                    ),
778
-                )
779
-            );
780
-        }
781
-
782
-        return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
783
-    }
784
-
785
-    /**
786
-     * Return the link to the admin details for the object.
787
-     *
788
-     * @return string
789
-     */
790
-    public function get_admin_details_link()
791
-    {
792
-        EE_Registry::instance()->load_helper('URL');
793
-        EE_Registry::instance()->load_helper('MSG_Template');
794
-        switch ($this->STS_ID()) {
795
-            case EEM_Message::status_failed :
796
-            case EEM_Message::status_debug_only :
797
-                return EEH_MSG_Template::generate_error_display_trigger($this);
798
-                break;
799
-
800
-            case EEM_Message::status_sent :
801
-                return EEH_MSG_Template::generate_browser_trigger($this);
802
-                break;
803
-
804
-            default :
805
-                return '';
806
-        }
807
-    }
808
-
809
-    /**
810
-     * Returns the link to the editor for the object.  Sometimes this is the same as the details.
811
-     *
812
-     * @return string
813
-     */
814
-    public function get_admin_edit_link()
815
-    {
816
-        return $this->get_admin_details_link();
817
-    }
818
-
819
-    /**
820
-     * Returns the link to a settings page for the object.
821
-     *
822
-     * @return string
823
-     */
824
-    public function get_admin_settings_link()
825
-    {
826
-        EE_Registry::instance()->load_helper('URL');
827
-        return EEH_URL::add_query_args_and_nonce(
828
-            array(
829
-                'page'   => 'espresso_messages',
830
-                'action' => 'settings',
831
-            ),
832
-            admin_url('admin.php')
833
-        );
834
-    }
835
-
836
-    /**
837
-     * Returns the link to the "overview" for the object (typically the "list table" view).
838
-     *
839
-     * @return string
840
-     */
841
-    public function get_admin_overview_link()
842
-    {
843
-        EE_Registry::instance()->load_helper('URL');
844
-        return EEH_URL::add_query_args_and_nonce(
845
-            array(
846
-                'page'   => 'espresso_messages',
847
-                'action' => 'default',
848
-            ),
849
-            admin_url('admin.php')
850
-        );
851
-    }
15
+	/**
16
+	 * @deprecated 4.9.0  Added for backward compat with add-on's
17
+	 * @type null
18
+	 */
19
+	public $template_pack;
20
+
21
+	/**
22
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
23
+	 * @type null
24
+	 */
25
+	public $template_variation;
26
+
27
+	/**
28
+	 * @deprecated 4.9.0 Added for backward compat with add-on's
29
+	 * @type string
30
+	 */
31
+	public $content = '';
32
+
33
+
34
+	/**
35
+	 * @type EE_messenger $_messenger
36
+	 */
37
+	protected $_messenger = null;
38
+
39
+	/**
40
+	 * @type EE_message_type $_message_type
41
+	 */
42
+	protected $_message_type = null;
43
+
44
+
45
+	/**
46
+	 * @param array  $props_n_values
47
+	 * @param string $timezone
48
+	 * @param array  $date_formats incoming date formats in an array.  First value is the date_format, second is time
49
+	 *                             format.
50
+	 * @return EE_Message
51
+	 */
52
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
53
+	{
54
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__);
55
+		//if object doesn't exist, let's generate a unique token on instantiation so that its available even before saving to db.
56
+		if ( ! $has_object) {
57
+			EE_Registry::instance()->load_helper('URL');
58
+			$props_n_values['MSG_token'] = EEH_URL::generate_unique_token();
59
+		}
60
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
61
+	}
62
+
63
+
64
+	/**
65
+	 * @param array  $props_n_values
66
+	 * @param string $timezone
67
+	 * @return EE_Message
68
+	 */
69
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
70
+	{
71
+		return new self($props_n_values, true, $timezone);
72
+	}
73
+
74
+
75
+	/**
76
+	 * Gets MSG_token
77
+	 *
78
+	 * @return int
79
+	 */
80
+	public function MSG_token()
81
+	{
82
+		return $this->get('MSG_token');
83
+	}
84
+
85
+
86
+	/**
87
+	 * Sets MSG_token
88
+	 *
89
+	 * @param int $MSG_token
90
+	 */
91
+	public function set_MSG_token($MSG_token)
92
+	{
93
+		$this->set('MSG_token', $MSG_token);
94
+	}
95
+
96
+
97
+	/**
98
+	 * Gets GRP_ID
99
+	 *
100
+	 * @return int
101
+	 */
102
+	public function GRP_ID()
103
+	{
104
+		return $this->get('GRP_ID');
105
+	}
106
+
107
+
108
+	/**
109
+	 * Sets GRP_ID
110
+	 *
111
+	 * @param int $GRP_ID
112
+	 */
113
+	public function set_GRP_ID($GRP_ID)
114
+	{
115
+		$this->set('GRP_ID', $GRP_ID);
116
+	}
117
+
118
+
119
+	/**
120
+	 * Gets TXN_ID
121
+	 *
122
+	 * @return int
123
+	 */
124
+	public function TXN_ID()
125
+	{
126
+		return $this->get('TXN_ID');
127
+	}
128
+
129
+
130
+	/**
131
+	 * Sets TXN_ID
132
+	 *
133
+	 * @param int $TXN_ID
134
+	 */
135
+	public function set_TXN_ID($TXN_ID)
136
+	{
137
+		$this->set('TXN_ID', $TXN_ID);
138
+	}
139
+
140
+
141
+	/**
142
+	 * Gets messenger
143
+	 *
144
+	 * @return string
145
+	 */
146
+	public function messenger()
147
+	{
148
+		return $this->get('MSG_messenger');
149
+	}
150
+
151
+
152
+	/**
153
+	 * Sets messenger
154
+	 *
155
+	 * @param string $messenger
156
+	 */
157
+	public function set_messenger($messenger)
158
+	{
159
+		$this->set('MSG_messenger', $messenger);
160
+	}
161
+
162
+
163
+	/**
164
+	 * Returns corresponding messenger object for the set messenger on this message
165
+	 *
166
+	 * @return EE_messenger | null
167
+	 */
168
+	public function messenger_object()
169
+	{
170
+		return $this->_messenger;
171
+	}
172
+
173
+
174
+	/**
175
+	 * Sets messenger
176
+	 *
177
+	 * @param EE_messenger $messenger
178
+	 */
179
+	public function set_messenger_object(EE_messenger $messenger)
180
+	{
181
+		$this->_messenger = $messenger;
182
+	}
183
+
184
+
185
+	/**
186
+	 * validates messenger
187
+	 *
188
+	 * @param bool $throw_exceptions
189
+	 * @return bool
190
+	 * @throws \EE_Error
191
+	 */
192
+	public function valid_messenger($throw_exceptions = false)
193
+	{
194
+		if ($this->_messenger instanceof EE_messenger) {
195
+			return true;
196
+		}
197
+		if ($throw_exceptions) {
198
+			throw new EE_Error(
199
+				sprintf(
200
+					__(
201
+						'The "%1$s" messenger set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
202
+						'event_espresso'
203
+					),
204
+					$this->messenger()
205
+				)
206
+			);
207
+		}
208
+		return false;
209
+	}
210
+
211
+
212
+	/**
213
+	 * This returns the set localized label for the messenger on this message.
214
+	 * Note, if unable to retrieve the EE_messenger object then will just return the messenger slug saved
215
+	 * with this message.
216
+	 *
217
+	 * @param   bool $plural whether to return the plural label or not.
218
+	 * @return string
219
+	 */
220
+	public function messenger_label($plural = false)
221
+	{
222
+		$label_type = $plural ? 'plural' : 'singular';
223
+		$messenger  = $this->messenger_object();
224
+		return $messenger instanceof EE_messenger ? $messenger->label[$label_type] : $this->messenger();
225
+	}
226
+
227
+
228
+	/**
229
+	 * Gets message_type
230
+	 *
231
+	 * @return string
232
+	 */
233
+	public function message_type()
234
+	{
235
+		return $this->get('MSG_message_type');
236
+	}
237
+
238
+
239
+	/**
240
+	 * Sets message_type
241
+	 *
242
+	 * @param string $message_type
243
+	 */
244
+	public function set_message_type($message_type)
245
+	{
246
+		$this->set('MSG_message_type', $message_type);
247
+	}
248
+
249
+
250
+	/**
251
+	 * Returns the message type object for the set message type on this message
252
+	 *
253
+	 * @return EE_message_type | null
254
+	 */
255
+	public function message_type_object()
256
+	{
257
+		return $this->_message_type;
258
+	}
259
+
260
+
261
+	/**
262
+	 * Sets message_type
263
+	 *
264
+	 * @param EE_message_type $message_type
265
+	 * @param bool            $set_priority   This indicates whether to set the priority to whatever the priority is on
266
+	 *                                        the message type or not.
267
+	 */
268
+	public function set_message_type_object(EE_message_type $message_type, $set_priority = false)
269
+	{
270
+		$this->_message_type = $message_type;
271
+		if ($set_priority) {
272
+			$this->set_priority($this->_message_type->get_priority());
273
+		}
274
+	}
275
+
276
+
277
+	/**
278
+	 * validates message_type
279
+	 *
280
+	 * @param bool $throw_exceptions
281
+	 * @return bool
282
+	 * @throws \EE_Error
283
+	 */
284
+	public function valid_message_type($throw_exceptions = false)
285
+	{
286
+		if ($this->_message_type instanceof EE_message_type) {
287
+			return true;
288
+		}
289
+		if ($throw_exceptions) {
290
+			throw new EE_Error(
291
+				sprintf(
292
+					__(
293
+						'The %1$s message type set for this message is missing or invalid. Please double-check the spelling and verify that the correct files exist.',
294
+						'event_espresso'
295
+					),
296
+					$this->message_type()
297
+				)
298
+			);
299
+		}
300
+		return false;
301
+	}
302
+
303
+
304
+	/**
305
+	 * validates messenger and message_type (that they are valid EE_messenger and EE_message_type objects).
306
+	 *
307
+	 * @param bool $throw_exceptions
308
+	 * @return bool
309
+	 * @throws \EE_Error
310
+	 */
311
+	public function is_valid($throw_exceptions = false)
312
+	{
313
+		if ($this->valid_messenger($throw_exceptions) && $this->valid_message_type($throw_exceptions)) {
314
+			return true;
315
+		}
316
+		return false;
317
+	}
318
+
319
+
320
+	/**
321
+	 * This validates whether the internal messenger and message type objects are valid for sending.
322
+	 * Three checks are done:
323
+	 * 1. There is a valid messenger object.
324
+	 * 2. There is a valid message type object.
325
+	 * 3. The message type object is active for the messenger.
326
+	 *
327
+	 * @throws EE_Error  But only if $throw_exceptions is set to true.
328
+	 * @param bool $throw_exceptions
329
+	 * @return bool
330
+	 */
331
+	public function is_valid_for_sending_or_generation($throw_exceptions = false)
332
+	{
333
+		$valid = false;
334
+		if ($this->is_valid($throw_exceptions)) {
335
+			/** @var EE_Message_Resource_Manager $message_resource_manager */
336
+			$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
337
+			$valid                    = $message_resource_manager->is_message_type_active_for_messenger($this->messenger(),
338
+				$this->message_type());
339
+			if ( ! $valid && $throw_exceptions) {
340
+				throw new EE_Error(
341
+					sprintf(
342
+						__('The %1$s message type is not a valid message type for the %2$s messenger so it will not be sent.',
343
+							'event_espresso'),
344
+						$this->message_type(),
345
+						$this->messenger()
346
+					)
347
+				);
348
+			}
349
+		}
350
+		return $valid;
351
+	}
352
+
353
+
354
+	/**
355
+	 * This returns the set localized label for the message type on this message.
356
+	 * Note, if unable to retrieve the EE_message_type object then will just return the message type slug saved
357
+	 * with this message.
358
+	 *
359
+	 * @param   bool $plural whether to return the plural label or not.
360
+	 * @return string
361
+	 */
362
+	public function message_type_label($plural = false)
363
+	{
364
+		$label_type   = $plural ? 'plural' : 'singular';
365
+		$message_type = $this->message_type_object();
366
+		return $message_type instanceof EE_message_type ? $message_type->label[$label_type] : $this->message_type();
367
+	}
368
+
369
+
370
+	/**
371
+	 * Gets context
372
+	 *
373
+	 * @return string
374
+	 */
375
+	public function context()
376
+	{
377
+		return $this->get('MSG_context');
378
+	}
379
+
380
+
381
+	/**
382
+	 * This returns the corresponding localized label for the given context slug, if possible from installed message
383
+	 * types. Otherwise, this will just return the set context slug on this object.
384
+	 *
385
+	 * @return string
386
+	 */
387
+	public function context_label()
388
+	{
389
+		/** @type EE_Message_Resource_Manager $message_resource_manager */
390
+		$message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager');
391
+		$contexts                 = $message_resource_manager->get_all_contexts();
392
+		return isset($contexts[$this->context()]) ? $contexts[$this->context()] : $this->context();
393
+	}
394
+
395
+
396
+	/**
397
+	 * Sets context
398
+	 *
399
+	 * @param string $context
400
+	 */
401
+	public function set_context($context)
402
+	{
403
+		$this->set('MSG_context', $context);
404
+	}
405
+
406
+
407
+	/**
408
+	 * Gets recipient_ID
409
+	 *
410
+	 * @return int
411
+	 */
412
+	public function recipient_ID()
413
+	{
414
+		return $this->get('MSG_recipient_ID');
415
+	}
416
+
417
+
418
+	/**
419
+	 * Sets recipient_ID
420
+	 *
421
+	 * @param string $recipient_ID
422
+	 */
423
+	public function set_recipient_ID($recipient_ID)
424
+	{
425
+		$this->set('MSG_recipient_ID', $recipient_ID);
426
+	}
427
+
428
+
429
+	/**
430
+	 * Gets recipient_type
431
+	 *
432
+	 * @return string
433
+	 */
434
+	public function recipient_type()
435
+	{
436
+		return $this->get('MSG_recipient_type');
437
+	}
438
+
439
+
440
+	/**
441
+	 * Return the related object matching the recipient type and ID.
442
+	 *
443
+	 * @return EE_Base_Class | null
444
+	 */
445
+	public function recipient_object()
446
+	{
447
+		if ( ! $this->recipient_type() || ! $this->recipient_ID()) {
448
+			return null;
449
+		}
450
+
451
+		return $this->get_first_related($this->recipient_type());
452
+	}
453
+
454
+
455
+	/**
456
+	 * Sets recipient_type
457
+	 *
458
+	 * @param string $recipient_type
459
+	 */
460
+	public function set_recipient_type($recipient_type)
461
+	{
462
+		$this->set('MSG_recipient_type', $recipient_type);
463
+	}
464
+
465
+
466
+	/**
467
+	 * Gets content
468
+	 *
469
+	 * @return string
470
+	 */
471
+	public function content()
472
+	{
473
+		return $this->get('MSG_content');
474
+	}
475
+
476
+
477
+	/**
478
+	 * Sets content
479
+	 *
480
+	 * @param string $content
481
+	 */
482
+	public function set_content($content)
483
+	{
484
+		$this->set('MSG_content', $content);
485
+	}
486
+
487
+
488
+	/**
489
+	 * Gets subject
490
+	 *
491
+	 * @return string
492
+	 */
493
+	public function subject()
494
+	{
495
+		return $this->get('MSG_subject');
496
+	}
497
+
498
+
499
+	/**
500
+	 * Sets subject
501
+	 *
502
+	 * @param string $subject
503
+	 */
504
+	public function set_subject($subject)
505
+	{
506
+		$this->set('MSG_subject', $subject);
507
+	}
508
+
509
+
510
+	/**
511
+	 * Gets to
512
+	 *
513
+	 * @return string
514
+	 */
515
+	public function to()
516
+	{
517
+		$to = $this->get('MSG_to');
518
+		return empty($to) ? __('No recipient', 'event_espresso') : $to;
519
+	}
520
+
521
+
522
+	/**
523
+	 * Sets to
524
+	 *
525
+	 * @param string $to
526
+	 */
527
+	public function set_to($to)
528
+	{
529
+		$this->set('MSG_to', $to);
530
+	}
531
+
532
+
533
+	/**
534
+	 * Gets from
535
+	 *
536
+	 * @return string
537
+	 */
538
+	public function from()
539
+	{
540
+		return $this->get('MSG_from');
541
+	}
542
+
543
+
544
+	/**
545
+	 * Sets from
546
+	 *
547
+	 * @param string $from
548
+	 */
549
+	public function set_from($from)
550
+	{
551
+		$this->set('MSG_from', $from);
552
+	}
553
+
554
+
555
+	/**
556
+	 * Gets priority
557
+	 *
558
+	 * @return int
559
+	 */
560
+	public function priority()
561
+	{
562
+		return $this->get('MSG_priority');
563
+	}
564
+
565
+
566
+	/**
567
+	 * Sets priority
568
+	 * Note.  Send Now Messengers always override any priority that may be set on a Message.  So
569
+	 * this method calls the send_now method to verify that.
570
+	 *
571
+	 * @param int $priority
572
+	 */
573
+	public function set_priority($priority)
574
+	{
575
+		$priority = $this->send_now() ? EEM_Message::priority_high : $priority;
576
+		parent::set('MSG_priority', $priority);
577
+	}
578
+
579
+
580
+	/**
581
+	 * Overrides parent::set method so we can capture any sets for priority.
582
+	 *
583
+	 * @see parent::set() for phpdocs
584
+	 * @param string $field_name
585
+	 * @param mixed  $field_value
586
+	 * @param bool   $use_default
587
+	 * @throws EE_Error
588
+	 */
589
+	public function set($field_name, $field_value, $use_default = false)
590
+	{
591
+		if ($field_name === 'MSG_priority') {
592
+			$this->set_priority($field_value);
593
+		}
594
+		parent::set($field_name, $field_value, $use_default);
595
+	}
596
+
597
+
598
+	/**
599
+	 * @return bool
600
+	 * @throws \EE_Error
601
+	 */
602
+	public function send_now()
603
+	{
604
+		$send_now = $this->valid_messenger() && $this->messenger_object()->send_now() ? EEM_Message::priority_high : $this->priority();
605
+		return $send_now === EEM_Message::priority_high ? true : false;
606
+	}
607
+
608
+
609
+	/**
610
+	 * Gets STS_ID
611
+	 *
612
+	 * @return string
613
+	 */
614
+	public function STS_ID()
615
+	{
616
+		return $this->get('STS_ID');
617
+	}
618
+
619
+
620
+	/**
621
+	 * Sets STS_ID
622
+	 *
623
+	 * @param string $STS_ID
624
+	 */
625
+	public function set_STS_ID($STS_ID)
626
+	{
627
+		$this->set('STS_ID', $STS_ID);
628
+	}
629
+
630
+
631
+	/**
632
+	 * Gets created
633
+	 *
634
+	 * @return string
635
+	 */
636
+	public function created()
637
+	{
638
+		return $this->get('MSG_created');
639
+	}
640
+
641
+
642
+	/**
643
+	 * Sets created
644
+	 *
645
+	 * @param string $created
646
+	 */
647
+	public function set_created($created)
648
+	{
649
+		$this->set('MSG_created', $created);
650
+	}
651
+
652
+
653
+	/**
654
+	 * Gets modified
655
+	 *
656
+	 * @return string
657
+	 */
658
+	public function modified()
659
+	{
660
+		return $this->get('MSG_modified');
661
+	}
662
+
663
+
664
+	/**
665
+	 * Sets modified
666
+	 *
667
+	 * @param string $modified
668
+	 */
669
+	public function set_modified($modified)
670
+	{
671
+		$this->set('MSG_modified', $modified);
672
+	}
673
+
674
+
675
+	/**
676
+	 * Sets generation data for this message.
677
+	 *
678
+	 * @param mixed $data
679
+	 */
680
+	public function set_generation_data($data)
681
+	{
682
+		$this->set_field_or_extra_meta('MSG_generation_data', $data);
683
+	}
684
+
685
+
686
+	/**
687
+	 * Returns any set generation data for this message.
688
+	 *
689
+	 * @return mixed|null
690
+	 */
691
+	public function get_generation_data()
692
+	{
693
+		return $this->get_field_or_extra_meta('MSG_generation_data');
694
+	}
695
+
696
+
697
+	/**
698
+	 * Gets any error message.
699
+	 *
700
+	 * @return mixed|null
701
+	 */
702
+	public function error_message()
703
+	{
704
+		return $this->get_field_or_extra_meta('MSG_error');
705
+	}
706
+
707
+
708
+	/**
709
+	 * Sets an error message.
710
+	 *
711
+	 * @param $message
712
+	 * @return bool|int
713
+	 */
714
+	public function set_error_message($message)
715
+	{
716
+		return $this->set_field_or_extra_meta('MSG_error', $message);
717
+	}
718
+
719
+
720
+	/**
721
+	 * This retrieves the associated template pack with this message.
722
+	 *
723
+	 * @return EE_Messages_Template_Pack | null
724
+	 */
725
+	public function get_template_pack()
726
+	{
727
+		/**
728
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
729
+		 */
730
+		if ( ! empty($this->template_pack)) {
731
+			return $this->template_pack;
732
+		}
733
+		/** @type EE_Message_Template_Group $grp */
734
+		$grp = $this->get_first_related('Message_Template_Group');
735
+		//if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
736
+		if ( ! $grp instanceof EE_Message_Template_Group) {
737
+			$grp = EEM_Message_Template_Group::instance()->get_one(
738
+				array(
739
+					array(
740
+						'MTP_messenger'    => $this->messenger(),
741
+						'MTP_message_type' => $this->message_type(),
742
+						'MTP_is_global'    => true,
743
+					),
744
+				)
745
+			);
746
+		}
747
+
748
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack() : null;
749
+	}
750
+
751
+
752
+	/**
753
+	 * Retrieves the variation used for generating this message.
754
+	 *
755
+	 * @return string
756
+	 */
757
+	public function get_template_pack_variation()
758
+	{
759
+		/**
760
+		 * This is deprecated functionality that will be removed eventually but included here now for backward compat.
761
+		 */
762
+		if ( ! empty($this->template_variation)) {
763
+			return $this->template_variation;
764
+		}
765
+
766
+		/** @type EE_Message_Template_Group $grp */
767
+		$grp = $this->get_first_related('Message_Template_Group');
768
+
769
+		//if no group then let's try to get the first related group by internal messenger and message type (will use global grp).
770
+		if ( ! $grp instanceof EE_Message_Template_Group) {
771
+			$grp = EEM_Message_Template_Group::instance()->get_one(
772
+				array(
773
+					array(
774
+						'MTP_messenger'    => $this->messenger(),
775
+						'MTP_message_type' => $this->message_type(),
776
+						'MTP_is_global'    => true,
777
+					),
778
+				)
779
+			);
780
+		}
781
+
782
+		return $grp instanceof EE_Message_Template_Group ? $grp->get_template_pack_variation() : '';
783
+	}
784
+
785
+	/**
786
+	 * Return the link to the admin details for the object.
787
+	 *
788
+	 * @return string
789
+	 */
790
+	public function get_admin_details_link()
791
+	{
792
+		EE_Registry::instance()->load_helper('URL');
793
+		EE_Registry::instance()->load_helper('MSG_Template');
794
+		switch ($this->STS_ID()) {
795
+			case EEM_Message::status_failed :
796
+			case EEM_Message::status_debug_only :
797
+				return EEH_MSG_Template::generate_error_display_trigger($this);
798
+				break;
799
+
800
+			case EEM_Message::status_sent :
801
+				return EEH_MSG_Template::generate_browser_trigger($this);
802
+				break;
803
+
804
+			default :
805
+				return '';
806
+		}
807
+	}
808
+
809
+	/**
810
+	 * Returns the link to the editor for the object.  Sometimes this is the same as the details.
811
+	 *
812
+	 * @return string
813
+	 */
814
+	public function get_admin_edit_link()
815
+	{
816
+		return $this->get_admin_details_link();
817
+	}
818
+
819
+	/**
820
+	 * Returns the link to a settings page for the object.
821
+	 *
822
+	 * @return string
823
+	 */
824
+	public function get_admin_settings_link()
825
+	{
826
+		EE_Registry::instance()->load_helper('URL');
827
+		return EEH_URL::add_query_args_and_nonce(
828
+			array(
829
+				'page'   => 'espresso_messages',
830
+				'action' => 'settings',
831
+			),
832
+			admin_url('admin.php')
833
+		);
834
+	}
835
+
836
+	/**
837
+	 * Returns the link to the "overview" for the object (typically the "list table" view).
838
+	 *
839
+	 * @return string
840
+	 */
841
+	public function get_admin_overview_link()
842
+	{
843
+		EE_Registry::instance()->load_helper('URL');
844
+		return EEH_URL::add_query_args_and_nonce(
845
+			array(
846
+				'page'   => 'espresso_messages',
847
+				'action' => 'default',
848
+			),
849
+			admin_url('admin.php')
850
+		);
851
+	}
852 852
 
853 853
 
854 854
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 
Please login to merge, or discard this patch.
core/helpers/EEH_Template.helper.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
      * _find_common_base_path
305 305
      * given two paths, this determines if there is a common base path between the two
306 306
      *
307
-     * @param array $paths
307
+     * @param string[] $paths
308 308
      * @return string
309 309
      */
310 310
     protected static function _find_common_base_path($paths)
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
      * @param bool|string $template_path server path to the file to be loaded, including file name and extension
333 333
      * @param  array      $template_args an array of arguments to be extracted for use in the template
334 334
      * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
335
-     * @return mixed string
335
+     * @return string string
336 336
      */
337 337
     public static function display_template($template_path = false, $template_args = array(), $return_string = false)
338 338
     {
Please login to merge, or discard this patch.
Indentation   +907 added lines, -907 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 /**
6 6
  * Event Espresso
@@ -16,35 +16,35 @@  discard block
 block discarded – undo
16 16
 
17 17
 
18 18
 if ( ! function_exists('espresso_get_template_part')) {
19
-    /**
20
-     * espresso_get_template_part
21
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
22
-     * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
23
-     *
24
-     * @param string $slug The slug name for the generic template.
25
-     * @param string $name The name of the specialised template.
26
-     * @return string        the html output for the formatted money value
27
-     */
28
-    function espresso_get_template_part($slug = null, $name = null)
29
-    {
30
-        EEH_Template::get_template_part($slug, $name);
31
-    }
19
+	/**
20
+	 * espresso_get_template_part
21
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files
22
+	 * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name
23
+	 *
24
+	 * @param string $slug The slug name for the generic template.
25
+	 * @param string $name The name of the specialised template.
26
+	 * @return string        the html output for the formatted money value
27
+	 */
28
+	function espresso_get_template_part($slug = null, $name = null)
29
+	{
30
+		EEH_Template::get_template_part($slug, $name);
31
+	}
32 32
 }
33 33
 
34 34
 
35 35
 if ( ! function_exists('espresso_get_object_css_class')) {
36
-    /**
37
-     * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
38
-     *
39
-     * @param EE_Base_Class $object the EE object the css class is being generated for
40
-     * @param  string       $prefix added to the beginning of the generated class
41
-     * @param  string       $suffix added to the end of the generated class
42
-     * @return string
43
-     */
44
-    function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
45
-    {
46
-        return EEH_Template::get_object_css_class($object, $prefix, $suffix);
47
-    }
36
+	/**
37
+	 * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed
38
+	 *
39
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
40
+	 * @param  string       $prefix added to the beginning of the generated class
41
+	 * @param  string       $suffix added to the end of the generated class
42
+	 * @return string
43
+	 */
44
+	function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '')
45
+	{
46
+		return EEH_Template::get_object_css_class($object, $prefix, $suffix);
47
+	}
48 48
 }
49 49
 
50 50
 
@@ -59,627 +59,627 @@  discard block
 block discarded – undo
59 59
 class EEH_Template
60 60
 {
61 61
 
62
-    private static $_espresso_themes = array();
63
-
64
-
65
-    /**
66
-     *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
67
-     *
68
-     * @return boolean
69
-     */
70
-    public static function is_espresso_theme()
71
-    {
72
-        return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
73
-    }
74
-
75
-    /**
76
-     *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
77
-     *    load it's functions.php file ( if not already loaded )
78
-     *
79
-     * @return void
80
-     */
81
-    public static function load_espresso_theme_functions()
82
-    {
83
-        if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
84
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
85
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
86
-            }
87
-        }
88
-    }
89
-
90
-
91
-    /**
92
-     *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
93
-     *
94
-     * @return array
95
-     */
96
-    public static function get_espresso_themes()
97
-    {
98
-        if (empty(EEH_Template::$_espresso_themes)) {
99
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
100
-            if (empty($espresso_themes)) {
101
-                return array();
102
-            }
103
-            if (($key = array_search('global_assets', $espresso_themes)) !== false) {
104
-                unset($espresso_themes[$key]);
105
-            }
106
-            EEH_Template::$_espresso_themes = array();
107
-            foreach ($espresso_themes as $espresso_theme) {
108
-                EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
109
-            }
110
-        }
111
-        return EEH_Template::$_espresso_themes;
112
-    }
113
-
114
-
115
-    /**
116
-     * EEH_Template::get_template_part
117
-     * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
118
-     * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
119
-     * filtering based off of the entire template part name
120
-     *
121
-     * @param string $slug The slug name for the generic template.
122
-     * @param string $name The name of the specialised template.
123
-     * @param array  $template_args
124
-     * @param bool   $return_string
125
-     * @return string        the html output for the formatted money value
126
-     */
127
-    public static function get_template_part(
128
-        $slug = null,
129
-        $name = null,
130
-        $template_args = array(),
131
-        $return_string = false
132
-    ) {
133
-        do_action("get_template_part_{$slug}-{$name}", $slug, $name);
134
-        $templates = array();
135
-        $name      = (string)$name;
136
-        if ($name != '') {
137
-            $templates[] = "{$slug}-{$name}.php";
138
-        }
139
-        // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
140
-        if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
141
-            EEH_Template::locate_template($templates, $template_args, true, $return_string);
142
-        }
143
-    }
144
-
145
-
146
-    /**
147
-     *    locate_template
148
-     *    locate a template file by looking in the following places, in the following order:
149
-     *        <server path up to>/wp-content/themes/<current active WordPress theme>/
150
-     *        <assumed full absolute server path>
151
-     *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
152
-     *        <server path up to>/wp-content/uploads/espresso/templates/
153
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
154
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
155
-     *        <server path up to>/wp-content/plugins/<EE4 folder>/
156
-     *    as soon as the template is found in one of these locations, it will be returned or loaded
157
-     *        Example:
158
-     *          You are using the WordPress Twenty Sixteen theme,
159
-     *        and you want to customize the "some-event.template.php" template,
160
-     *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
161
-     *          Assuming WP is installed on your server in the "/home/public_html/" folder,
162
-     *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
163
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
164
-     *        /relative/path/to/some-event.template.php
165
-     *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
166
-     *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
167
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
168
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
169
-     *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
170
-     *          Had you passed an absolute path to your template that was in some other location,
171
-     *        ie: "/absolute/path/to/some-event.template.php"
172
-     *          then the search would have been :
173
-     *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
174
-     *        /absolute/path/to/some-event.template.php
175
-     *          and stopped there upon finding it in the second location
176
-     *
177
-     * @param array|string $templates       array of template file names including extension (or just a single string)
178
-     * @param  array       $template_args   an array of arguments to be extracted for use in the template
179
-     * @param  boolean     $load            whether to pass the located template path on to the
180
-     *                                      EEH_Template::display_template() method or simply return it
181
-     * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
182
-     *                                      string
183
-     * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
184
-     *                                      generate a custom template or not. Used in places where you don't actually
185
-     *                                      load the template, you just want to know if there's a custom version of it.
186
-     * @return mixed
187
-     */
188
-    public static function locate_template(
189
-        $templates = array(),
190
-        $template_args = array(),
191
-        $load = true,
192
-        $return_string = true,
193
-        $check_if_custom = false
194
-    ) {
195
-        // first use WP locate_template to check for template in the current theme folder
196
-        $template_path = locate_template($templates);
197
-
198
-        if ($check_if_custom && ! empty($template_path)) {
199
-            return true;
200
-        }
201
-
202
-        // not in the theme
203
-        if (empty($template_path)) {
204
-            // not even a template to look for ?
205
-            if (empty($templates)) {
206
-                // get post_type
207
-                $post_type = EE_Registry::instance()->REQ->get('post_type');
208
-                // get array of EE Custom Post Types
209
-                $EE_CPTs = EE_Register_CPTs::get_CPTs();
210
-                // build template name based on request
211
-                if (isset($EE_CPTs[$post_type])) {
212
-                    $archive_or_single = is_archive() ? 'archive' : '';
213
-                    $archive_or_single = is_single() ? 'single' : $archive_or_single;
214
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
215
-                }
216
-            }
217
-            // currently active EE template theme
218
-            $current_theme = EE_Config::get_current_theme();
219
-
220
-            // array of paths to folders that may contain templates
221
-            $template_folder_paths = array(
222
-                // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
223
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
224
-                // then in the root of the /wp-content/uploads/espresso/templates/ folder
225
-                EVENT_ESPRESSO_TEMPLATE_DIR,
226
-            );
227
-
228
-            //add core plugin folders for checking only if we're not $check_if_custom
229
-            if ( ! $check_if_custom) {
230
-                $core_paths            = array(
231
-                    // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
232
-                    EE_PUBLIC . $current_theme,
233
-                    // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
234
-                    EE_TEMPLATES . $current_theme,
235
-                    // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
236
-                    EE_PLUGIN_DIR_PATH,
237
-                );
238
-                $template_folder_paths = array_merge($template_folder_paths, $core_paths);
239
-            }
240
-
241
-            // now filter that array
242
-            $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths',
243
-                $template_folder_paths);
244
-            $templates             = is_array($templates) ? $templates : array($templates);
245
-            $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
246
-            // array to hold all possible template paths
247
-            $full_template_paths = array();
248
-
249
-            // loop through $templates
250
-            foreach ($templates as $template) {
251
-                // normalize directory separators
252
-                $template                      = EEH_File::standardise_directory_separators($template);
253
-                $file_name                     = basename($template);
254
-                $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
255
-                // while looping through all template folder paths
256
-                foreach ($template_folder_paths as $template_folder_path) {
257
-                    // normalize directory separators
258
-                    $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
259
-                    // determine if any common base path exists between the two paths
260
-                    $common_base_path = EEH_Template::_find_common_base_path(
261
-                        array($template_folder_path, $template_path_minus_file_name)
262
-                    );
263
-                    if ($common_base_path !== '') {
264
-                        // both paths have a common base, so just tack the filename onto our search path
265
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
266
-                    } else {
267
-                        // no common base path, so let's just concatenate
268
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
269
-                    }
270
-                    // build up our template locations array by adding our resolved paths
271
-                    $full_template_paths[] = $resolved_path;
272
-                }
273
-                // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
274
-                array_unshift($full_template_paths, $template);
275
-                // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
276
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
277
-            }
278
-            // filter final array of full template paths
279
-            $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths',
280
-                $full_template_paths, $file_name);
281
-            // now loop through our final array of template location paths and check each location
282
-            foreach ((array)$full_template_paths as $full_template_path) {
283
-                if (is_readable($full_template_path)) {
284
-                    $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
285
-                    // hook that can be used to display the full template path that will be used
286
-                    do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
287
-                    break;
288
-                }
289
-            }
290
-        }
291
-        // if we got it and you want to see it...
292
-        if ($template_path && $load && ! $check_if_custom) {
293
-            if ($return_string) {
294
-                return EEH_Template::display_template($template_path, $template_args, true);
295
-            } else {
296
-                EEH_Template::display_template($template_path, $template_args, false);
297
-            }
298
-        }
299
-        return $check_if_custom && ! empty($template_path) ? true : $template_path;
300
-    }
301
-
302
-
303
-    /**
304
-     * _find_common_base_path
305
-     * given two paths, this determines if there is a common base path between the two
306
-     *
307
-     * @param array $paths
308
-     * @return string
309
-     */
310
-    protected static function _find_common_base_path($paths)
311
-    {
312
-        $last_offset      = 0;
313
-        $common_base_path = '';
314
-        while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
315
-            $dir_length = $index - $last_offset + 1;
316
-            $directory  = substr($paths[0], $last_offset, $dir_length);
317
-            foreach ($paths as $path) {
318
-                if (substr($path, $last_offset, $dir_length) != $directory) {
319
-                    return $common_base_path;
320
-                }
321
-            }
322
-            $common_base_path .= $directory;
323
-            $last_offset = $index + 1;
324
-        }
325
-        return substr($common_base_path, 0, -1);
326
-    }
327
-
328
-
329
-    /**
330
-     * load and display a template
331
-     *
332
-     * @param bool|string $template_path server path to the file to be loaded, including file name and extension
333
-     * @param  array      $template_args an array of arguments to be extracted for use in the template
334
-     * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
335
-     * @return mixed string
336
-     */
337
-    public static function display_template($template_path = false, $template_args = array(), $return_string = false)
338
-    {
339
-
340
-        /**
341
-         * These two filters are intended for last minute changes to templates being loaded and/or template arg
342
-         * modifications.  NOTE... modifying these things can cause breakage as most templates running through
343
-         * the display_template method are templates we DON'T want modified (usually because of js
344
-         * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
345
-         * using this.
346
-         *
347
-         * @since 4.6.0
348
-         */
349
-        $template_path = apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
350
-        $template_args = apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
351
-
352
-        // you gimme nuttin - YOU GET NUTTIN !!
353
-        if ( ! $template_path || ! is_readable($template_path)) {
354
-            return '';
355
-        }
356
-        // if $template_args are not in an array, then make it so
357
-        if ( ! is_array($template_args) && ! is_object($template_args)) {
358
-            $template_args = array($template_args);
359
-        }
360
-        extract((array)$template_args);
361
-
362
-        if ($return_string) {
363
-            // because we want to return a string, we are going to capture the output
364
-            ob_start();
365
-            include($template_path);
366
-            return ob_get_clean();
367
-        } else {
368
-            include($template_path);
369
-        }
370
-        return '';
371
-    }
372
-
373
-
374
-    /**
375
-     * get_object_css_class - attempts to generate a css class based on the type of EE object passed
376
-     *
377
-     * @param EE_Base_Class $object the EE object the css class is being generated for
378
-     * @param  string       $prefix added to the beginning of the generated class
379
-     * @param  string       $suffix added to the end of the generated class
380
-     * @return string
381
-     */
382
-    public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
383
-    {
384
-        // in the beginning...
385
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
386
-        // da muddle
387
-        $class = '';
388
-        // the end
389
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
390
-        // is the passed object an EE object ?
391
-        if ($object instanceof EE_Base_Class) {
392
-            // grab the exact type of object
393
-            $obj_class = get_class($object);
394
-            // depending on the type of object...
395
-            switch ($obj_class) {
396
-                // no specifics just yet...
397
-                default :
398
-                    $class = strtolower(str_replace('_', '-', $obj_class));
399
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
400
-
401
-            }
402
-        }
403
-        return $prefix . $class . $suffix;
404
-    }
405
-
406
-
407
-    /**
408
-     * EEH_Template::format_currency
409
-     * This helper takes a raw float value and formats it according to the default config country currency settings, or
410
-     * the country currency settings from the supplied country ISO code
411
-     *
412
-     * @param  float   $amount       raw money value
413
-     * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
414
-     * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
415
-     * @param string   $CNT_ISO      2 letter ISO code for a country
416
-     * @param string   $cur_code_span_class
417
-     * @return string        the html output for the formatted money value
418
-     */
419
-    public static function format_currency(
420
-        $amount = null,
421
-        $return_raw = false,
422
-        $display_code = true,
423
-        $CNT_ISO = '',
424
-        $cur_code_span_class = 'currency-code'
425
-    ) {
426
-        // ensure amount was received
427
-        if (is_null($amount)) {
428
-            $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
429
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
430
-            return '';
431
-        }
432
-        //ensure amount is float
433
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount);
434
-        $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
435
-        // filter raw amount (allows 0.00 to be changed to "free" for example)
436
-        $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
437
-        // still a number or was amount converted to a string like "free" ?
438
-        if (is_float($amount_formatted)) {
439
-            // was a country ISO code passed ? if so generate currency config object for that country
440
-            $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
441
-            // verify results
442
-            if ( ! $mny instanceof EE_Currency_Config) {
443
-                // set default config country currency settings
444
-                $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config ? EE_Registry::instance()->CFG->currency : new EE_Currency_Config();
445
-            }
446
-            // format float
447
-            $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
448
-            // add formatting ?
449
-            if ( ! $return_raw) {
450
-                // add currency sign
451
-                if ($mny->sign_b4) {
452
-                    if ($amount >= 0) {
453
-                        $amount_formatted = $mny->sign . $amount_formatted;
454
-                    } else {
455
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
456
-                    }
457
-
458
-                } else {
459
-                    $amount_formatted = $amount_formatted . $mny->sign;
460
-                }
461
-
462
-                // filter to allow global setting of display_code
463
-                $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
464
-
465
-                // add currency code ?
466
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
467
-            }
468
-            // filter results
469
-            $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted',
470
-                $amount_formatted, $mny, $return_raw);
471
-        }
472
-        // clean up vars
473
-        unset($mny);
474
-        // return formatted currency amount
475
-        return $amount_formatted;
476
-    }
477
-
478
-
479
-    /**
480
-     * This function is used for outputting the localized label for a given status id in the schema requested (and
481
-     * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
482
-     * related status model or model object (i.e. in documentation etc.)
483
-     *
484
-     * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
485
-     *                            match, then 'Unknown' will be returned.
486
-     * @param  boolean $plural    Whether to return plural or not
487
-     * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
488
-     * @return string             The localized label for the status id.
489
-     */
490
-    public static function pretty_status($status_id, $plural = false, $schema = 'upper')
491
-    {
492
-        /** @type EEM_Status $EEM_Status */
493
-        $EEM_Status = EE_Registry::instance()->load_model('Status');
494
-        $status     = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural,
495
-            $schema);
496
-        return $status[$status_id];
497
-    }
498
-
499
-
500
-    /**
501
-     * This helper just returns a button or link for the given parameters
502
-     *
503
-     * @param  string $url   the url for the link
504
-     * @param  string $label What is the label you want displayed for the button
505
-     * @param  string $class what class is used for the button (defaults to 'button-primary')
506
-     * @param string  $icon
507
-     * @param string  $title
508
-     * @return string the html output for the button
509
-     */
510
-    public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
511
-    {
512
-        $icon_html = '';
513
-        if ( ! empty($icon)) {
514
-            $dashicons = preg_split("(ee-icon |dashicons )", $icon);
515
-            $dashicons = array_filter($dashicons);
516
-            $count     = count($dashicons);
517
-            $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
518
-            foreach ($dashicons as $dashicon) {
519
-                $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
520
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
521
-            }
522
-            $icon_html .= $count > 1 ? '</span>' : '';
523
-        }
524
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
525
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
526
-        return $button;
527
-    }
528
-
529
-
530
-    /**
531
-     * This returns a generated link that will load the related help tab on admin pages.
532
-     *
533
-     * @param  string     $help_tab_id the id for the connected help tab
534
-     * @param bool|string $page        The page identifier for the page the help tab is on
535
-     * @param bool|string $action      The action (route) for the admin page the help tab is on.
536
-     * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
537
-     * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
538
-     * @return string              generated link
539
-     */
540
-    public static function get_help_tab_link(
541
-        $help_tab_id,
542
-        $page = false,
543
-        $action = false,
544
-        $icon_style = false,
545
-        $help_text = false
546
-    ) {
547
-
548
-        if ( ! $page) {
549
-            $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
550
-        }
551
-
552
-        if ( ! $action) {
553
-            $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
554
-        }
555
-
556
-        $action = empty($action) ? 'default' : $action;
557
-
558
-
559
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
560
-        $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
561
-        $help_text    = ! $help_text ? '' : $help_text;
562
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
563
-                'event_espresso') . '" > ' . $help_text . ' </a>';
564
-    }
565
-
566
-
567
-    /**
568
-     * This helper generates the html structure for the jquery joyride plugin with the given params.
569
-     *
570
-     * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
571
-     * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
572
-     * @param EE_Help_Tour
573
-     * @return string         html
574
-     */
575
-    public static function help_tour_stops_generator(EE_Help_Tour $tour)
576
-    {
577
-        $id    = $tour->get_slug();
578
-        $stops = $tour->get_stops();
579
-
580
-        $content = '<ol style="display:none" id="' . $id . '">';
581
-
582
-        foreach ($stops as $stop) {
583
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
584
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
585
-
586
-            //if container is set to modal then let's make sure we set the options accordingly
587
-            if (empty($data_id) && empty($data_class)) {
588
-                $stop['options']['modal']  = true;
589
-                $stop['options']['expose'] = true;
590
-            }
591
-
592
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
593
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
594
-            $inner_content = isset($stop['content']) ? $stop['content'] : '';
595
-
596
-            //options
597
-            if (isset($stop['options']) && is_array($stop['options'])) {
598
-                $options = ' data-options="';
599
-                foreach ($stop['options'] as $option => $value) {
600
-                    $options .= $option . ':' . $value . ';';
601
-                }
602
-                $options .= '"';
603
-            } else {
604
-                $options = '';
605
-            }
606
-
607
-            //let's put all together
608
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
609
-        }
610
-
611
-        $content .= '</ol>';
612
-        return $content;
613
-    }
614
-
615
-
616
-    /**
617
-     * This is a helper method to generate a status legend for a given status array.
618
-     * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
619
-     * status_array.
620
-     *
621
-     * @param  array  $status_array  array of statuses that will make up the legend. In format:
622
-     *                               array(
623
-     *                               'status_item' => 'status_name'
624
-     *                               )
625
-     * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
626
-     *                               the legend.
627
-     * @throws EE_Error
628
-     * @return string               html structure for status.
629
-     */
630
-    public static function status_legend($status_array, $active_status = '')
631
-    {
632
-        if ( ! is_array($status_array)) {
633
-            throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
634
-                'event_espresso'));
635
-        }
636
-
637
-        $setup_array = array();
638
-        foreach ($status_array as $item => $status) {
639
-            $setup_array[$item] = array(
640
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
641
-                'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
642
-                'status' => $status,
643
-            );
644
-        }
645
-
646
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
647
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
648
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
649
-        foreach ($setup_array as $item => $details) {
650
-            $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
651
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
652
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
653
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
654
-            $content .= '</dt>' . "\n";
655
-        }
656
-        $content .= '</dl>' . "\n";
657
-        $content .= '</div>' . "\n";
658
-        return $content;
659
-    }
660
-
661
-
662
-    /**
663
-     * Gets HTML for laying out a deeply-nested array (and objects) in a format
664
-     * that's nice for presenting in the wp admin
665
-     *
666
-     * @param mixed $data
667
-     * @return string
668
-     */
669
-    public static function layout_array_as_table($data)
670
-    {
671
-        if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
672
-            $data = (array)$data;
673
-        }
674
-        ob_start();
675
-        if (is_array($data)) {
676
-            if (EEH_Array::is_associative_array($data)) {
677
-                ?>
62
+	private static $_espresso_themes = array();
63
+
64
+
65
+	/**
66
+	 *    is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme
67
+	 *
68
+	 * @return boolean
69
+	 */
70
+	public static function is_espresso_theme()
71
+	{
72
+		return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false;
73
+	}
74
+
75
+	/**
76
+	 *    load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then
77
+	 *    load it's functions.php file ( if not already loaded )
78
+	 *
79
+	 * @return void
80
+	 */
81
+	public static function load_espresso_theme_functions()
82
+	{
83
+		if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
84
+			if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
85
+				require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
86
+			}
87
+		}
88
+	}
89
+
90
+
91
+	/**
92
+	 *    get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory
93
+	 *
94
+	 * @return array
95
+	 */
96
+	public static function get_espresso_themes()
97
+	{
98
+		if (empty(EEH_Template::$_espresso_themes)) {
99
+			$espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
100
+			if (empty($espresso_themes)) {
101
+				return array();
102
+			}
103
+			if (($key = array_search('global_assets', $espresso_themes)) !== false) {
104
+				unset($espresso_themes[$key]);
105
+			}
106
+			EEH_Template::$_espresso_themes = array();
107
+			foreach ($espresso_themes as $espresso_theme) {
108
+				EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme;
109
+			}
110
+		}
111
+		return EEH_Template::$_espresso_themes;
112
+	}
113
+
114
+
115
+	/**
116
+	 * EEH_Template::get_template_part
117
+	 * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead,
118
+	 * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS
119
+	 * filtering based off of the entire template part name
120
+	 *
121
+	 * @param string $slug The slug name for the generic template.
122
+	 * @param string $name The name of the specialised template.
123
+	 * @param array  $template_args
124
+	 * @param bool   $return_string
125
+	 * @return string        the html output for the formatted money value
126
+	 */
127
+	public static function get_template_part(
128
+		$slug = null,
129
+		$name = null,
130
+		$template_args = array(),
131
+		$return_string = false
132
+	) {
133
+		do_action("get_template_part_{$slug}-{$name}", $slug, $name);
134
+		$templates = array();
135
+		$name      = (string)$name;
136
+		if ($name != '') {
137
+			$templates[] = "{$slug}-{$name}.php";
138
+		}
139
+		// allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' );
140
+		if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) {
141
+			EEH_Template::locate_template($templates, $template_args, true, $return_string);
142
+		}
143
+	}
144
+
145
+
146
+	/**
147
+	 *    locate_template
148
+	 *    locate a template file by looking in the following places, in the following order:
149
+	 *        <server path up to>/wp-content/themes/<current active WordPress theme>/
150
+	 *        <assumed full absolute server path>
151
+	 *        <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/
152
+	 *        <server path up to>/wp-content/uploads/espresso/templates/
153
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/
154
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/
155
+	 *        <server path up to>/wp-content/plugins/<EE4 folder>/
156
+	 *    as soon as the template is found in one of these locations, it will be returned or loaded
157
+	 *        Example:
158
+	 *          You are using the WordPress Twenty Sixteen theme,
159
+	 *        and you want to customize the "some-event.template.php" template,
160
+	 *          which is located in the "/relative/path/to/" folder relative to the main EE plugin folder.
161
+	 *          Assuming WP is installed on your server in the "/home/public_html/" folder,
162
+	 *        EEH_Template::locate_template() will look at the following paths in order until the template is found:
163
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
164
+	 *        /relative/path/to/some-event.template.php
165
+	 *        /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
166
+	 *        /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php
167
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php
168
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php
169
+	 *        /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php
170
+	 *          Had you passed an absolute path to your template that was in some other location,
171
+	 *        ie: "/absolute/path/to/some-event.template.php"
172
+	 *          then the search would have been :
173
+	 *        /home/public_html/wp-content/themes/twentysixteen/some-event.template.php
174
+	 *        /absolute/path/to/some-event.template.php
175
+	 *          and stopped there upon finding it in the second location
176
+	 *
177
+	 * @param array|string $templates       array of template file names including extension (or just a single string)
178
+	 * @param  array       $template_args   an array of arguments to be extracted for use in the template
179
+	 * @param  boolean     $load            whether to pass the located template path on to the
180
+	 *                                      EEH_Template::display_template() method or simply return it
181
+	 * @param  boolean     $return_string   whether to send output immediately to screen, or capture and return as a
182
+	 *                                      string
183
+	 * @param boolean      $check_if_custom If TRUE, this flags this method to return boolean for whether this will
184
+	 *                                      generate a custom template or not. Used in places where you don't actually
185
+	 *                                      load the template, you just want to know if there's a custom version of it.
186
+	 * @return mixed
187
+	 */
188
+	public static function locate_template(
189
+		$templates = array(),
190
+		$template_args = array(),
191
+		$load = true,
192
+		$return_string = true,
193
+		$check_if_custom = false
194
+	) {
195
+		// first use WP locate_template to check for template in the current theme folder
196
+		$template_path = locate_template($templates);
197
+
198
+		if ($check_if_custom && ! empty($template_path)) {
199
+			return true;
200
+		}
201
+
202
+		// not in the theme
203
+		if (empty($template_path)) {
204
+			// not even a template to look for ?
205
+			if (empty($templates)) {
206
+				// get post_type
207
+				$post_type = EE_Registry::instance()->REQ->get('post_type');
208
+				// get array of EE Custom Post Types
209
+				$EE_CPTs = EE_Register_CPTs::get_CPTs();
210
+				// build template name based on request
211
+				if (isset($EE_CPTs[$post_type])) {
212
+					$archive_or_single = is_archive() ? 'archive' : '';
213
+					$archive_or_single = is_single() ? 'single' : $archive_or_single;
214
+					$templates         = $archive_or_single . '-' . $post_type . '.php';
215
+				}
216
+			}
217
+			// currently active EE template theme
218
+			$current_theme = EE_Config::get_current_theme();
219
+
220
+			// array of paths to folders that may contain templates
221
+			$template_folder_paths = array(
222
+				// first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
223
+				EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
224
+				// then in the root of the /wp-content/uploads/espresso/templates/ folder
225
+				EVENT_ESPRESSO_TEMPLATE_DIR,
226
+			);
227
+
228
+			//add core plugin folders for checking only if we're not $check_if_custom
229
+			if ( ! $check_if_custom) {
230
+				$core_paths            = array(
231
+					// in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
232
+					EE_PUBLIC . $current_theme,
233
+					// in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
234
+					EE_TEMPLATES . $current_theme,
235
+					// or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
236
+					EE_PLUGIN_DIR_PATH,
237
+				);
238
+				$template_folder_paths = array_merge($template_folder_paths, $core_paths);
239
+			}
240
+
241
+			// now filter that array
242
+			$template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths',
243
+				$template_folder_paths);
244
+			$templates             = is_array($templates) ? $templates : array($templates);
245
+			$template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths);
246
+			// array to hold all possible template paths
247
+			$full_template_paths = array();
248
+
249
+			// loop through $templates
250
+			foreach ($templates as $template) {
251
+				// normalize directory separators
252
+				$template                      = EEH_File::standardise_directory_separators($template);
253
+				$file_name                     = basename($template);
254
+				$template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1));
255
+				// while looping through all template folder paths
256
+				foreach ($template_folder_paths as $template_folder_path) {
257
+					// normalize directory separators
258
+					$template_folder_path = EEH_File::standardise_directory_separators($template_folder_path);
259
+					// determine if any common base path exists between the two paths
260
+					$common_base_path = EEH_Template::_find_common_base_path(
261
+						array($template_folder_path, $template_path_minus_file_name)
262
+					);
263
+					if ($common_base_path !== '') {
264
+						// both paths have a common base, so just tack the filename onto our search path
265
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
266
+					} else {
267
+						// no common base path, so let's just concatenate
268
+						$resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
269
+					}
270
+					// build up our template locations array by adding our resolved paths
271
+					$full_template_paths[] = $resolved_path;
272
+				}
273
+				// if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
274
+				array_unshift($full_template_paths, $template);
275
+				// path to the directory of the current theme: /wp-content/themes/(current WP theme)/
276
+				array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
277
+			}
278
+			// filter final array of full template paths
279
+			$full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths',
280
+				$full_template_paths, $file_name);
281
+			// now loop through our final array of template location paths and check each location
282
+			foreach ((array)$full_template_paths as $full_template_path) {
283
+				if (is_readable($full_template_path)) {
284
+					$template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
285
+					// hook that can be used to display the full template path that will be used
286
+					do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path);
287
+					break;
288
+				}
289
+			}
290
+		}
291
+		// if we got it and you want to see it...
292
+		if ($template_path && $load && ! $check_if_custom) {
293
+			if ($return_string) {
294
+				return EEH_Template::display_template($template_path, $template_args, true);
295
+			} else {
296
+				EEH_Template::display_template($template_path, $template_args, false);
297
+			}
298
+		}
299
+		return $check_if_custom && ! empty($template_path) ? true : $template_path;
300
+	}
301
+
302
+
303
+	/**
304
+	 * _find_common_base_path
305
+	 * given two paths, this determines if there is a common base path between the two
306
+	 *
307
+	 * @param array $paths
308
+	 * @return string
309
+	 */
310
+	protected static function _find_common_base_path($paths)
311
+	{
312
+		$last_offset      = 0;
313
+		$common_base_path = '';
314
+		while (($index = strpos($paths[0], DS, $last_offset)) !== false) {
315
+			$dir_length = $index - $last_offset + 1;
316
+			$directory  = substr($paths[0], $last_offset, $dir_length);
317
+			foreach ($paths as $path) {
318
+				if (substr($path, $last_offset, $dir_length) != $directory) {
319
+					return $common_base_path;
320
+				}
321
+			}
322
+			$common_base_path .= $directory;
323
+			$last_offset = $index + 1;
324
+		}
325
+		return substr($common_base_path, 0, -1);
326
+	}
327
+
328
+
329
+	/**
330
+	 * load and display a template
331
+	 *
332
+	 * @param bool|string $template_path server path to the file to be loaded, including file name and extension
333
+	 * @param  array      $template_args an array of arguments to be extracted for use in the template
334
+	 * @param  boolean    $return_string whether to send output immediately to screen, or capture and return as a string
335
+	 * @return mixed string
336
+	 */
337
+	public static function display_template($template_path = false, $template_args = array(), $return_string = false)
338
+	{
339
+
340
+		/**
341
+		 * These two filters are intended for last minute changes to templates being loaded and/or template arg
342
+		 * modifications.  NOTE... modifying these things can cause breakage as most templates running through
343
+		 * the display_template method are templates we DON'T want modified (usually because of js
344
+		 * dependencies etc).  So unless you know what you are doing, do NOT filter templates or template args
345
+		 * using this.
346
+		 *
347
+		 * @since 4.6.0
348
+		 */
349
+		$template_path = apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path);
350
+		$template_args = apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args);
351
+
352
+		// you gimme nuttin - YOU GET NUTTIN !!
353
+		if ( ! $template_path || ! is_readable($template_path)) {
354
+			return '';
355
+		}
356
+		// if $template_args are not in an array, then make it so
357
+		if ( ! is_array($template_args) && ! is_object($template_args)) {
358
+			$template_args = array($template_args);
359
+		}
360
+		extract((array)$template_args);
361
+
362
+		if ($return_string) {
363
+			// because we want to return a string, we are going to capture the output
364
+			ob_start();
365
+			include($template_path);
366
+			return ob_get_clean();
367
+		} else {
368
+			include($template_path);
369
+		}
370
+		return '';
371
+	}
372
+
373
+
374
+	/**
375
+	 * get_object_css_class - attempts to generate a css class based on the type of EE object passed
376
+	 *
377
+	 * @param EE_Base_Class $object the EE object the css class is being generated for
378
+	 * @param  string       $prefix added to the beginning of the generated class
379
+	 * @param  string       $suffix added to the end of the generated class
380
+	 * @return string
381
+	 */
382
+	public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
383
+	{
384
+		// in the beginning...
385
+		$prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
386
+		// da muddle
387
+		$class = '';
388
+		// the end
389
+		$suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
390
+		// is the passed object an EE object ?
391
+		if ($object instanceof EE_Base_Class) {
392
+			// grab the exact type of object
393
+			$obj_class = get_class($object);
394
+			// depending on the type of object...
395
+			switch ($obj_class) {
396
+				// no specifics just yet...
397
+				default :
398
+					$class = strtolower(str_replace('_', '-', $obj_class));
399
+					$class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
400
+
401
+			}
402
+		}
403
+		return $prefix . $class . $suffix;
404
+	}
405
+
406
+
407
+	/**
408
+	 * EEH_Template::format_currency
409
+	 * This helper takes a raw float value and formats it according to the default config country currency settings, or
410
+	 * the country currency settings from the supplied country ISO code
411
+	 *
412
+	 * @param  float   $amount       raw money value
413
+	 * @param  boolean $return_raw   whether to return the formatted float value only with no currency sign or code
414
+	 * @param  boolean $display_code whether to display the country code (USD). Default = TRUE
415
+	 * @param string   $CNT_ISO      2 letter ISO code for a country
416
+	 * @param string   $cur_code_span_class
417
+	 * @return string        the html output for the formatted money value
418
+	 */
419
+	public static function format_currency(
420
+		$amount = null,
421
+		$return_raw = false,
422
+		$display_code = true,
423
+		$CNT_ISO = '',
424
+		$cur_code_span_class = 'currency-code'
425
+	) {
426
+		// ensure amount was received
427
+		if (is_null($amount)) {
428
+			$msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso');
429
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
430
+			return '';
431
+		}
432
+		//ensure amount is float
433
+		$amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount);
434
+		$CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
435
+		// filter raw amount (allows 0.00 to be changed to "free" for example)
436
+		$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
437
+		// still a number or was amount converted to a string like "free" ?
438
+		if (is_float($amount_formatted)) {
439
+			// was a country ISO code passed ? if so generate currency config object for that country
440
+			$mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null;
441
+			// verify results
442
+			if ( ! $mny instanceof EE_Currency_Config) {
443
+				// set default config country currency settings
444
+				$mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config ? EE_Registry::instance()->CFG->currency : new EE_Currency_Config();
445
+			}
446
+			// format float
447
+			$amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds);
448
+			// add formatting ?
449
+			if ( ! $return_raw) {
450
+				// add currency sign
451
+				if ($mny->sign_b4) {
452
+					if ($amount >= 0) {
453
+						$amount_formatted = $mny->sign . $amount_formatted;
454
+					} else {
455
+						$amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
456
+					}
457
+
458
+				} else {
459
+					$amount_formatted = $amount_formatted . $mny->sign;
460
+				}
461
+
462
+				// filter to allow global setting of display_code
463
+				$display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
464
+
465
+				// add currency code ?
466
+				$amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
467
+			}
468
+			// filter results
469
+			$amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted',
470
+				$amount_formatted, $mny, $return_raw);
471
+		}
472
+		// clean up vars
473
+		unset($mny);
474
+		// return formatted currency amount
475
+		return $amount_formatted;
476
+	}
477
+
478
+
479
+	/**
480
+	 * This function is used for outputting the localized label for a given status id in the schema requested (and
481
+	 * possibly plural).  The intended use of this function is only for cases where wanting a label outside of a
482
+	 * related status model or model object (i.e. in documentation etc.)
483
+	 *
484
+	 * @param  string  $status_id Status ID matching a registered status in the esp_status table.  If there is no
485
+	 *                            match, then 'Unknown' will be returned.
486
+	 * @param  boolean $plural    Whether to return plural or not
487
+	 * @param  string  $schema    'UPPER', 'lower', or 'Sentence'
488
+	 * @return string             The localized label for the status id.
489
+	 */
490
+	public static function pretty_status($status_id, $plural = false, $schema = 'upper')
491
+	{
492
+		/** @type EEM_Status $EEM_Status */
493
+		$EEM_Status = EE_Registry::instance()->load_model('Status');
494
+		$status     = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural,
495
+			$schema);
496
+		return $status[$status_id];
497
+	}
498
+
499
+
500
+	/**
501
+	 * This helper just returns a button or link for the given parameters
502
+	 *
503
+	 * @param  string $url   the url for the link
504
+	 * @param  string $label What is the label you want displayed for the button
505
+	 * @param  string $class what class is used for the button (defaults to 'button-primary')
506
+	 * @param string  $icon
507
+	 * @param string  $title
508
+	 * @return string the html output for the button
509
+	 */
510
+	public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '')
511
+	{
512
+		$icon_html = '';
513
+		if ( ! empty($icon)) {
514
+			$dashicons = preg_split("(ee-icon |dashicons )", $icon);
515
+			$dashicons = array_filter($dashicons);
516
+			$count     = count($dashicons);
517
+			$icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
518
+			foreach ($dashicons as $dashicon) {
519
+				$type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
520
+				$icon_html .= '<span class="' . $type . $dashicon . '"></span>';
521
+			}
522
+			$icon_html .= $count > 1 ? '</span>' : '';
523
+		}
524
+		$label  = ! empty($icon) ? $icon_html . $label : $label;
525
+		$button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
526
+		return $button;
527
+	}
528
+
529
+
530
+	/**
531
+	 * This returns a generated link that will load the related help tab on admin pages.
532
+	 *
533
+	 * @param  string     $help_tab_id the id for the connected help tab
534
+	 * @param bool|string $page        The page identifier for the page the help tab is on
535
+	 * @param bool|string $action      The action (route) for the admin page the help tab is on.
536
+	 * @param bool|string $icon_style  (optional) include css class for the style you want to use for the help icon.
537
+	 * @param bool|string $help_text   (optional) send help text you want to use for the link if default not to be used
538
+	 * @return string              generated link
539
+	 */
540
+	public static function get_help_tab_link(
541
+		$help_tab_id,
542
+		$page = false,
543
+		$action = false,
544
+		$icon_style = false,
545
+		$help_text = false
546
+	) {
547
+
548
+		if ( ! $page) {
549
+			$page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page;
550
+		}
551
+
552
+		if ( ! $action) {
553
+			$action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action;
554
+		}
555
+
556
+		$action = empty($action) ? 'default' : $action;
557
+
558
+
559
+		$help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
560
+		$icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
561
+		$help_text    = ! $help_text ? '' : $help_text;
562
+		return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
563
+				'event_espresso') . '" > ' . $help_text . ' </a>';
564
+	}
565
+
566
+
567
+	/**
568
+	 * This helper generates the html structure for the jquery joyride plugin with the given params.
569
+	 *
570
+	 * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin
571
+	 * @see  EE_Admin_Page->_stop_callback() for the construct expected for the $stops param.
572
+	 * @param EE_Help_Tour
573
+	 * @return string         html
574
+	 */
575
+	public static function help_tour_stops_generator(EE_Help_Tour $tour)
576
+	{
577
+		$id    = $tour->get_slug();
578
+		$stops = $tour->get_stops();
579
+
580
+		$content = '<ol style="display:none" id="' . $id . '">';
581
+
582
+		foreach ($stops as $stop) {
583
+			$data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
584
+			$data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
585
+
586
+			//if container is set to modal then let's make sure we set the options accordingly
587
+			if (empty($data_id) && empty($data_class)) {
588
+				$stop['options']['modal']  = true;
589
+				$stop['options']['expose'] = true;
590
+			}
591
+
592
+			$custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
593
+			$button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
594
+			$inner_content = isset($stop['content']) ? $stop['content'] : '';
595
+
596
+			//options
597
+			if (isset($stop['options']) && is_array($stop['options'])) {
598
+				$options = ' data-options="';
599
+				foreach ($stop['options'] as $option => $value) {
600
+					$options .= $option . ':' . $value . ';';
601
+				}
602
+				$options .= '"';
603
+			} else {
604
+				$options = '';
605
+			}
606
+
607
+			//let's put all together
608
+			$content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
609
+		}
610
+
611
+		$content .= '</ol>';
612
+		return $content;
613
+	}
614
+
615
+
616
+	/**
617
+	 * This is a helper method to generate a status legend for a given status array.
618
+	 * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods
619
+	 * status_array.
620
+	 *
621
+	 * @param  array  $status_array  array of statuses that will make up the legend. In format:
622
+	 *                               array(
623
+	 *                               'status_item' => 'status_name'
624
+	 *                               )
625
+	 * @param  string $active_status This is used to indicate what the active status is IF that is to be highlighted in
626
+	 *                               the legend.
627
+	 * @throws EE_Error
628
+	 * @return string               html structure for status.
629
+	 */
630
+	public static function status_legend($status_array, $active_status = '')
631
+	{
632
+		if ( ! is_array($status_array)) {
633
+			throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!',
634
+				'event_espresso'));
635
+		}
636
+
637
+		$setup_array = array();
638
+		foreach ($status_array as $item => $status) {
639
+			$setup_array[$item] = array(
640
+				'class'  => 'ee-status-legend ee-status-legend-' . $status,
641
+				'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
642
+				'status' => $status,
643
+			);
644
+		}
645
+
646
+		$content = '<div class="ee-list-table-legend-container">' . "\n";
647
+		$content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
648
+		$content .= '<dl class="ee-list-table-legend">' . "\n\t";
649
+		foreach ($setup_array as $item => $details) {
650
+			$active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
651
+			$content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
652
+			$content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
653
+			$content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
654
+			$content .= '</dt>' . "\n";
655
+		}
656
+		$content .= '</dl>' . "\n";
657
+		$content .= '</div>' . "\n";
658
+		return $content;
659
+	}
660
+
661
+
662
+	/**
663
+	 * Gets HTML for laying out a deeply-nested array (and objects) in a format
664
+	 * that's nice for presenting in the wp admin
665
+	 *
666
+	 * @param mixed $data
667
+	 * @return string
668
+	 */
669
+	public static function layout_array_as_table($data)
670
+	{
671
+		if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
672
+			$data = (array)$data;
673
+		}
674
+		ob_start();
675
+		if (is_array($data)) {
676
+			if (EEH_Array::is_associative_array($data)) {
677
+				?>
678 678
                 <table class="widefat">
679 679
                     <tbody>
680 680
                     <?php
681
-                    foreach ($data as $data_key => $data_values) {
682
-                        ?>
681
+					foreach ($data as $data_key => $data_values) {
682
+						?>
683 683
                         <tr>
684 684
                             <td>
685 685
                                 <?php echo $data_key; ?>
@@ -689,247 +689,247 @@  discard block
 block discarded – undo
689 689
                             </td>
690 690
                         </tr>
691 691
                         <?php
692
-                    } ?>
692
+					} ?>
693 693
                     </tbody>
694 694
                 </table>
695 695
                 <?php
696
-            } else {
697
-                ?>
696
+			} else {
697
+				?>
698 698
                 <ul>
699 699
                     <?php
700
-                    foreach ($data as $datum) {
701
-                        echo "<li>";
702
-                        echo self::layout_array_as_table($datum);
703
-                        echo "</li>";
704
-                    } ?>
700
+					foreach ($data as $datum) {
701
+						echo "<li>";
702
+						echo self::layout_array_as_table($datum);
703
+						echo "</li>";
704
+					} ?>
705 705
                 </ul>
706 706
                 <?php
707
-            }
708
-        } else {
709
-            //simple value
710
-            echo esc_html($data);
711
-        }
712
-        return ob_get_clean();
713
-    }
714
-
715
-
716
-    /**
717
-     * wrapper for self::get_paging_html() that simply echos the generated paging html
718
-     *
719
-     * @since 4.4.0
720
-     * @see   self:get_paging_html() for argument docs.
721
-     * @param        $total_items
722
-     * @param        $current
723
-     * @param        $per_page
724
-     * @param        $url
725
-     * @param bool   $show_num_field
726
-     * @param string $paged_arg_name
727
-     * @param array  $items_label
728
-     * @return string
729
-     */
730
-    public static function paging_html(
731
-        $total_items,
732
-        $current,
733
-        $per_page,
734
-        $url,
735
-        $show_num_field = true,
736
-        $paged_arg_name = 'paged',
737
-        $items_label = array()
738
-    ) {
739
-        echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name,
740
-            $items_label);
741
-    }
742
-
743
-
744
-    /**
745
-     * A method for generating paging similar to WP_List_Table
746
-     *
747
-     * @since    4.4.0
748
-     * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
749
-     * @param  integer $total_items     How many total items there are to page.
750
-     * @param  integer $current         What the current page is.
751
-     * @param  integer $per_page        How many items per page.
752
-     * @param  string  $url             What the base url for page links is.
753
-     * @param  boolean $show_num_field  Whether to show the input for changing page number.
754
-     * @param  string  $paged_arg_name  The name of the key for the paged query argument.
755
-     * @param  array   $items_label     An array of singular/plural values for the items label:
756
-     *                                  array(
757
-     *                                  'single' => 'item',
758
-     *                                  'plural' => 'items'
759
-     *                                  )
760
-     * @return  string
761
-     */
762
-    public static function get_paging_html(
763
-        $total_items,
764
-        $current,
765
-        $per_page,
766
-        $url,
767
-        $show_num_field = true,
768
-        $paged_arg_name = 'paged',
769
-        $items_label = array()
770
-    ) {
771
-        $page_links     = array();
772
-        $disable_first  = $disable_last = '';
773
-        $total_items    = (int)$total_items;
774
-        $per_page       = (int)$per_page;
775
-        $current        = (int)$current;
776
-        $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
777
-
778
-        //filter items_label
779
-        $items_label = apply_filters(
780
-            'FHEE__EEH_Template__get_paging_html__items_label',
781
-            $items_label
782
-        );
783
-
784
-        if (empty($items_label)
785
-            || ! is_array($items_label)
786
-            || ! isset($items_label['single'])
787
-            || ! isset($items_label['plural'])
788
-        ) {
789
-            $items_label = array(
790
-                'single' => __('1 item', 'event_espresso'),
791
-                'plural' => __('%s items', 'event_espresso'),
792
-            );
793
-        } else {
794
-            $items_label = array(
795
-                'single' => '1 ' . esc_html($items_label['single']),
796
-                'plural' => '%s ' . esc_html($items_label['plural']),
797
-            );
798
-        }
799
-
800
-        $total_pages = ceil($total_items / $per_page);
801
-
802
-        if ($total_pages <= 1) {
803
-            return '';
804
-        }
805
-
806
-        $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
807
-
808
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
809
-
810
-        if ($current === 1) {
811
-            $disable_first = ' disabled';
812
-        }
813
-        if ($current == $total_pages) {
814
-            $disable_last = ' disabled';
815
-        }
816
-
817
-        $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
818
-            'first-page' . $disable_first,
819
-            esc_attr__('Go to the first page'),
820
-            esc_url(remove_query_arg($paged_arg_name, $url)),
821
-            '&laquo;'
822
-        );
823
-
824
-        $page_links[] = sprintf(
825
-            '<a class="%s" title="%s" href="%s">%s</a>',
826
-            'prev-page' . $disable_first,
827
-            esc_attr__('Go to the previous page'),
828
-            esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
829
-            '&lsaquo;'
830
-        );
831
-
832
-        if ( ! $show_num_field) {
833
-            $html_current_page = $current;
834
-        } else {
835
-            $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
836
-                esc_attr__('Current page'),
837
-                $current,
838
-                strlen($total_pages)
839
-            );
840
-        }
841
-
842
-        $html_total_pages = sprintf(
843
-            '<span class="total-pages">%s</span>',
844
-            number_format_i18n($total_pages)
845
-        );
846
-        $page_links[]     = sprintf(
847
-            _x('%3$s%1$s of %2$s%4$s', 'paging'),
848
-            $html_current_page,
849
-            $html_total_pages,
850
-            '<span class="paging-input">',
851
-            '</span>'
852
-        );
853
-
854
-        $page_links[] = sprintf(
855
-            '<a class="%s" title="%s" href="%s">%s</a>',
856
-            'next-page' . $disable_last,
857
-            esc_attr__('Go to the next page'),
858
-            esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
859
-            '&rsaquo;'
860
-        );
861
-
862
-        $page_links[] = sprintf(
863
-            '<a class="%s" title="%s" href="%s">%s</a>',
864
-            'last-page' . $disable_last,
865
-            esc_attr__('Go to the last page'),
866
-            esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
867
-            '&raquo;'
868
-        );
869
-
870
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
871
-        // set page class
872
-        if ($total_pages) {
873
-            $page_class = $total_pages < 2 ? ' one-page' : '';
874
-        } else {
875
-            $page_class = ' no-pages';
876
-        }
877
-
878
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
879
-    }
880
-
881
-
882
-    /**
883
-     * @param string $wrap_class
884
-     * @param string $wrap_id
885
-     * @return string
886
-     */
887
-    public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
888
-    {
889
-        $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
890
-        if (
891
-            ! $admin &&
892
-            ! apply_filters(
893
-                'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
894
-                EE_Registry::instance()->CFG->admin->show_reg_footer
895
-            )
896
-        ) {
897
-            return '';
898
-        }
899
-        $tag        = $admin ? 'span' : 'div';
900
-        $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
901
-        $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
902
-        $attributes .= ! empty($wrap_class)
903
-            ? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
904
-            : ' class="powered-by-event-espresso-credit"';
905
-        $query_args = array_merge(
906
-            array(
907
-                'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
908
-                'utm_source'   => 'powered_by_event_espresso',
909
-                'utm_medium'   => 'link',
910
-                'utm_campaign' => 'powered_by',
911
-            ),
912
-            $query_args
913
-        );
914
-        $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text',
915
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso');
916
-        $url        = add_query_arg($query_args, 'https://eventespresso.com/');
917
-        $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
918
-        return (string)apply_filters(
919
-            'FHEE__EEH_Template__powered_by_event_espresso__html',
920
-            sprintf(
921
-                esc_html_x(
922
-                    '%1$sOnline event registration and ticketing powered by %2$s',
923
-                    'Online event registration and ticketing powered by [link to eventespresso.com]',
924
-                    'event_espresso'
925
-                ),
926
-                "<{$tag}{$attributes}>",
927
-                "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>"
928
-            ),
929
-            $wrap_class,
930
-            $wrap_id
931
-        );
932
-    }
707
+			}
708
+		} else {
709
+			//simple value
710
+			echo esc_html($data);
711
+		}
712
+		return ob_get_clean();
713
+	}
714
+
715
+
716
+	/**
717
+	 * wrapper for self::get_paging_html() that simply echos the generated paging html
718
+	 *
719
+	 * @since 4.4.0
720
+	 * @see   self:get_paging_html() for argument docs.
721
+	 * @param        $total_items
722
+	 * @param        $current
723
+	 * @param        $per_page
724
+	 * @param        $url
725
+	 * @param bool   $show_num_field
726
+	 * @param string $paged_arg_name
727
+	 * @param array  $items_label
728
+	 * @return string
729
+	 */
730
+	public static function paging_html(
731
+		$total_items,
732
+		$current,
733
+		$per_page,
734
+		$url,
735
+		$show_num_field = true,
736
+		$paged_arg_name = 'paged',
737
+		$items_label = array()
738
+	) {
739
+		echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name,
740
+			$items_label);
741
+	}
742
+
743
+
744
+	/**
745
+	 * A method for generating paging similar to WP_List_Table
746
+	 *
747
+	 * @since    4.4.0
748
+	 * @see      wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination()
749
+	 * @param  integer $total_items     How many total items there are to page.
750
+	 * @param  integer $current         What the current page is.
751
+	 * @param  integer $per_page        How many items per page.
752
+	 * @param  string  $url             What the base url for page links is.
753
+	 * @param  boolean $show_num_field  Whether to show the input for changing page number.
754
+	 * @param  string  $paged_arg_name  The name of the key for the paged query argument.
755
+	 * @param  array   $items_label     An array of singular/plural values for the items label:
756
+	 *                                  array(
757
+	 *                                  'single' => 'item',
758
+	 *                                  'plural' => 'items'
759
+	 *                                  )
760
+	 * @return  string
761
+	 */
762
+	public static function get_paging_html(
763
+		$total_items,
764
+		$current,
765
+		$per_page,
766
+		$url,
767
+		$show_num_field = true,
768
+		$paged_arg_name = 'paged',
769
+		$items_label = array()
770
+	) {
771
+		$page_links     = array();
772
+		$disable_first  = $disable_last = '';
773
+		$total_items    = (int)$total_items;
774
+		$per_page       = (int)$per_page;
775
+		$current        = (int)$current;
776
+		$paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
777
+
778
+		//filter items_label
779
+		$items_label = apply_filters(
780
+			'FHEE__EEH_Template__get_paging_html__items_label',
781
+			$items_label
782
+		);
783
+
784
+		if (empty($items_label)
785
+			|| ! is_array($items_label)
786
+			|| ! isset($items_label['single'])
787
+			|| ! isset($items_label['plural'])
788
+		) {
789
+			$items_label = array(
790
+				'single' => __('1 item', 'event_espresso'),
791
+				'plural' => __('%s items', 'event_espresso'),
792
+			);
793
+		} else {
794
+			$items_label = array(
795
+				'single' => '1 ' . esc_html($items_label['single']),
796
+				'plural' => '%s ' . esc_html($items_label['plural']),
797
+			);
798
+		}
799
+
800
+		$total_pages = ceil($total_items / $per_page);
801
+
802
+		if ($total_pages <= 1) {
803
+			return '';
804
+		}
805
+
806
+		$item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
807
+
808
+		$output = '<span class="displaying-num">' . $item_label . '</span>';
809
+
810
+		if ($current === 1) {
811
+			$disable_first = ' disabled';
812
+		}
813
+		if ($current == $total_pages) {
814
+			$disable_last = ' disabled';
815
+		}
816
+
817
+		$page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
818
+			'first-page' . $disable_first,
819
+			esc_attr__('Go to the first page'),
820
+			esc_url(remove_query_arg($paged_arg_name, $url)),
821
+			'&laquo;'
822
+		);
823
+
824
+		$page_links[] = sprintf(
825
+			'<a class="%s" title="%s" href="%s">%s</a>',
826
+			'prev-page' . $disable_first,
827
+			esc_attr__('Go to the previous page'),
828
+			esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
829
+			'&lsaquo;'
830
+		);
831
+
832
+		if ( ! $show_num_field) {
833
+			$html_current_page = $current;
834
+		} else {
835
+			$html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />",
836
+				esc_attr__('Current page'),
837
+				$current,
838
+				strlen($total_pages)
839
+			);
840
+		}
841
+
842
+		$html_total_pages = sprintf(
843
+			'<span class="total-pages">%s</span>',
844
+			number_format_i18n($total_pages)
845
+		);
846
+		$page_links[]     = sprintf(
847
+			_x('%3$s%1$s of %2$s%4$s', 'paging'),
848
+			$html_current_page,
849
+			$html_total_pages,
850
+			'<span class="paging-input">',
851
+			'</span>'
852
+		);
853
+
854
+		$page_links[] = sprintf(
855
+			'<a class="%s" title="%s" href="%s">%s</a>',
856
+			'next-page' . $disable_last,
857
+			esc_attr__('Go to the next page'),
858
+			esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
859
+			'&rsaquo;'
860
+		);
861
+
862
+		$page_links[] = sprintf(
863
+			'<a class="%s" title="%s" href="%s">%s</a>',
864
+			'last-page' . $disable_last,
865
+			esc_attr__('Go to the last page'),
866
+			esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
867
+			'&raquo;'
868
+		);
869
+
870
+		$output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
871
+		// set page class
872
+		if ($total_pages) {
873
+			$page_class = $total_pages < 2 ? ' one-page' : '';
874
+		} else {
875
+			$page_class = ' no-pages';
876
+		}
877
+
878
+		return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
879
+	}
880
+
881
+
882
+	/**
883
+	 * @param string $wrap_class
884
+	 * @param string $wrap_id
885
+	 * @return string
886
+	 */
887
+	public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array())
888
+	{
889
+		$admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX);
890
+		if (
891
+			! $admin &&
892
+			! apply_filters(
893
+				'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer',
894
+				EE_Registry::instance()->CFG->admin->show_reg_footer
895
+			)
896
+		) {
897
+			return '';
898
+		}
899
+		$tag        = $admin ? 'span' : 'div';
900
+		$attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : '';
901
+		$wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class;
902
+		$attributes .= ! empty($wrap_class)
903
+			? " class=\"{$wrap_class} powered-by-event-espresso-credit\""
904
+			: ' class="powered-by-event-espresso-credit"';
905
+		$query_args = array_merge(
906
+			array(
907
+				'ap_id'        => EE_Registry::instance()->CFG->admin->affiliate_id(),
908
+				'utm_source'   => 'powered_by_event_espresso',
909
+				'utm_medium'   => 'link',
910
+				'utm_campaign' => 'powered_by',
911
+			),
912
+			$query_args
913
+		);
914
+		$powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text',
915
+			$admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso');
916
+		$url        = add_query_arg($query_args, 'https://eventespresso.com/');
917
+		$url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
918
+		return (string)apply_filters(
919
+			'FHEE__EEH_Template__powered_by_event_espresso__html',
920
+			sprintf(
921
+				esc_html_x(
922
+					'%1$sOnline event registration and ticketing powered by %2$s',
923
+					'Online event registration and ticketing powered by [link to eventespresso.com]',
924
+					'event_espresso'
925
+				),
926
+				"<{$tag}{$attributes}>",
927
+				"<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>"
928
+			),
929
+			$wrap_class,
930
+			$wrap_id
931
+		);
932
+	}
933 933
 
934 934
 
935 935
 } //end EEH_Template class
@@ -946,33 +946,33 @@  discard block
 block discarded – undo
946 946
 
947 947
 
948 948
 if ( ! function_exists('espresso_pagination')) {
949
-    /**
950
-     *    espresso_pagination
951
-     *
952
-     * @access    public
953
-     * @return    void
954
-     */
955
-    function espresso_pagination()
956
-    {
957
-        global $wp_query;
958
-        $big        = 999999999; // need an unlikely integer
959
-        $pagination = paginate_links(
960
-            array(
961
-                'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
962
-                'format'       => '?paged=%#%',
963
-                'current'      => max(1, get_query_var('paged')),
964
-                'total'        => $wp_query->max_num_pages,
965
-                'show_all'     => true,
966
-                'end_size'     => 10,
967
-                'mid_size'     => 6,
968
-                'prev_next'    => true,
969
-                'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
970
-                'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
971
-                'type'         => 'plain',
972
-                'add_args'     => false,
973
-                'add_fragment' => '',
974
-            )
975
-        );
976
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
977
-    }
949
+	/**
950
+	 *    espresso_pagination
951
+	 *
952
+	 * @access    public
953
+	 * @return    void
954
+	 */
955
+	function espresso_pagination()
956
+	{
957
+		global $wp_query;
958
+		$big        = 999999999; // need an unlikely integer
959
+		$pagination = paginate_links(
960
+			array(
961
+				'base'         => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
962
+				'format'       => '?paged=%#%',
963
+				'current'      => max(1, get_query_var('paged')),
964
+				'total'        => $wp_query->max_num_pages,
965
+				'show_all'     => true,
966
+				'end_size'     => 10,
967
+				'mid_size'     => 6,
968
+				'prev_next'    => true,
969
+				'prev_text'    => __('&lsaquo; PREV', 'event_espresso'),
970
+				'next_text'    => __('NEXT &rsaquo;', 'event_espresso'),
971
+				'type'         => 'plain',
972
+				'add_args'     => false,
973
+				'add_fragment' => '',
974
+			)
975
+		);
976
+		echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
977
+	}
978 978
 }
979 979
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 /**
@@ -81,8 +81,8 @@  discard block
 block discarded – undo
81 81
     public static function load_espresso_theme_functions()
82 82
     {
83 83
         if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) {
84
-            if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) {
85
-                require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php');
84
+            if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) {
85
+                require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php');
86 86
             }
87 87
         }
88 88
     }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
     public static function get_espresso_themes()
97 97
     {
98 98
         if (empty(EEH_Template::$_espresso_themes)) {
99
-            $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR);
99
+            $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR);
100 100
             if (empty($espresso_themes)) {
101 101
                 return array();
102 102
             }
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     ) {
133 133
         do_action("get_template_part_{$slug}-{$name}", $slug, $name);
134 134
         $templates = array();
135
-        $name      = (string)$name;
135
+        $name      = (string) $name;
136 136
         if ($name != '') {
137 137
             $templates[] = "{$slug}-{$name}.php";
138 138
         }
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
                 if (isset($EE_CPTs[$post_type])) {
212 212
                     $archive_or_single = is_archive() ? 'archive' : '';
213 213
                     $archive_or_single = is_single() ? 'single' : $archive_or_single;
214
-                    $templates         = $archive_or_single . '-' . $post_type . '.php';
214
+                    $templates         = $archive_or_single.'-'.$post_type.'.php';
215 215
                 }
216 216
             }
217 217
             // currently active EE template theme
@@ -220,18 +220,18 @@  discard block
 block discarded – undo
220 220
             // array of paths to folders that may contain templates
221 221
             $template_folder_paths = array(
222 222
                 // first check the /wp-content/uploads/espresso/templates/(current EE theme)/  folder for an EE theme template file
223
-                EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme,
223
+                EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme,
224 224
                 // then in the root of the /wp-content/uploads/espresso/templates/ folder
225 225
                 EVENT_ESPRESSO_TEMPLATE_DIR,
226 226
             );
227 227
 
228 228
             //add core plugin folders for checking only if we're not $check_if_custom
229 229
             if ( ! $check_if_custom) {
230
-                $core_paths            = array(
230
+                $core_paths = array(
231 231
                     // in the  /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin
232
-                    EE_PUBLIC . $current_theme,
232
+                    EE_PUBLIC.$current_theme,
233 233
                     // in the  /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin
234
-                    EE_TEMPLATES . $current_theme,
234
+                    EE_TEMPLATES.$current_theme,
235 235
                     // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/
236 236
                     EE_PLUGIN_DIR_PATH,
237 237
                 );
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
                     );
263 263
                     if ($common_base_path !== '') {
264 264
                         // both paths have a common base, so just tack the filename onto our search path
265
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name;
265
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name;
266 266
                     } else {
267 267
                         // no common base path, so let's just concatenate
268
-                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template;
268
+                        $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template;
269 269
                     }
270 270
                     // build up our template locations array by adding our resolved paths
271 271
                     $full_template_paths[] = $resolved_path;
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
                 // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first
274 274
                 array_unshift($full_template_paths, $template);
275 275
                 // path to the directory of the current theme: /wp-content/themes/(current WP theme)/
276
-                array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name);
276
+                array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name);
277 277
             }
278 278
             // filter final array of full template paths
279 279
             $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths',
280 280
                 $full_template_paths, $file_name);
281 281
             // now loop through our final array of template location paths and check each location
282
-            foreach ((array)$full_template_paths as $full_template_path) {
282
+            foreach ((array) $full_template_paths as $full_template_path) {
283 283
                 if (is_readable($full_template_path)) {
284 284
                     $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path);
285 285
                     // hook that can be used to display the full template path that will be used
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
         if ( ! is_array($template_args) && ! is_object($template_args)) {
358 358
             $template_args = array($template_args);
359 359
         }
360
-        extract((array)$template_args);
360
+        extract((array) $template_args);
361 361
 
362 362
         if ($return_string) {
363 363
             // because we want to return a string, we are going to capture the output
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
     public static function get_object_css_class($object = null, $prefix = '', $suffix = '')
383 383
     {
384 384
         // in the beginning...
385
-        $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : '';
385
+        $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : '';
386 386
         // da muddle
387 387
         $class = '';
388 388
         // the end
389
-        $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : '';
389
+        $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : '';
390 390
         // is the passed object an EE object ?
391 391
         if ($object instanceof EE_Base_Class) {
392 392
             // grab the exact type of object
@@ -396,11 +396,11 @@  discard block
 block discarded – undo
396 396
                 // no specifics just yet...
397 397
                 default :
398 398
                     $class = strtolower(str_replace('_', '-', $obj_class));
399
-                    $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : '';
399
+                    $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : '';
400 400
 
401 401
             }
402 402
         }
403
-        return $prefix . $class . $suffix;
403
+        return $prefix.$class.$suffix;
404 404
     }
405 405
 
406 406
 
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
             return '';
431 431
         }
432 432
         //ensure amount is float
433
-        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount);
433
+        $amount  = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount);
434 434
         $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount);
435 435
         // filter raw amount (allows 0.00 to be changed to "free" for example)
436 436
         $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw);
@@ -450,20 +450,20 @@  discard block
 block discarded – undo
450 450
                 // add currency sign
451 451
                 if ($mny->sign_b4) {
452 452
                     if ($amount >= 0) {
453
-                        $amount_formatted = $mny->sign . $amount_formatted;
453
+                        $amount_formatted = $mny->sign.$amount_formatted;
454 454
                     } else {
455
-                        $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted);
455
+                        $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted);
456 456
                     }
457 457
 
458 458
                 } else {
459
-                    $amount_formatted = $amount_formatted . $mny->sign;
459
+                    $amount_formatted = $amount_formatted.$mny->sign;
460 460
                 }
461 461
 
462 462
                 // filter to allow global setting of display_code
463 463
                 $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code);
464 464
 
465 465
                 // add currency code ?
466
-                $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted;
466
+                $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted;
467 467
             }
468 468
             // filter results
469 469
             $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted',
@@ -517,12 +517,12 @@  discard block
 block discarded – undo
517 517
             $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : '';
518 518
             foreach ($dashicons as $dashicon) {
519 519
                 $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons ';
520
-                $icon_html .= '<span class="' . $type . $dashicon . '"></span>';
520
+                $icon_html .= '<span class="'.$type.$dashicon.'"></span>';
521 521
             }
522 522
             $icon_html .= $count > 1 ? '</span>' : '';
523 523
         }
524
-        $label  = ! empty($icon) ? $icon_html . $label : $label;
525
-        $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>';
524
+        $label  = ! empty($icon) ? $icon_html.$label : $label;
525
+        $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.$url.'" class="'.$class.'" title="'.$title.'">'.$label.'</a>';
526 526
         return $button;
527 527
     }
528 528
 
@@ -556,11 +556,11 @@  discard block
 block discarded – undo
556 556
         $action = empty($action) ? 'default' : $action;
557 557
 
558 558
 
559
-        $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id;
559
+        $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id;
560 560
         $icon         = ! $icon_style ? ' dashicons-editor-help' : $icon_style;
561 561
         $help_text    = ! $help_text ? '' : $help_text;
562
-        return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
563
-                'event_espresso') . '" > ' . $help_text . ' </a>';
562
+        return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__('Click to open the \'Help\' tab for more information about this feature.',
563
+                'event_espresso').'" > '.$help_text.' </a>';
564 564
     }
565 565
 
566 566
 
@@ -577,11 +577,11 @@  discard block
 block discarded – undo
577 577
         $id    = $tour->get_slug();
578 578
         $stops = $tour->get_stops();
579 579
 
580
-        $content = '<ol style="display:none" id="' . $id . '">';
580
+        $content = '<ol style="display:none" id="'.$id.'">';
581 581
 
582 582
         foreach ($stops as $stop) {
583
-            $data_id    = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : '';
584
-            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : '';
583
+            $data_id    = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : '';
584
+            $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : '';
585 585
 
586 586
             //if container is set to modal then let's make sure we set the options accordingly
587 587
             if (empty($data_id) && empty($data_class)) {
@@ -589,15 +589,15 @@  discard block
 block discarded – undo
589 589
                 $stop['options']['expose'] = true;
590 590
             }
591 591
 
592
-            $custom_class  = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : '';
593
-            $button_text   = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : '';
592
+            $custom_class  = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : '';
593
+            $button_text   = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : '';
594 594
             $inner_content = isset($stop['content']) ? $stop['content'] : '';
595 595
 
596 596
             //options
597 597
             if (isset($stop['options']) && is_array($stop['options'])) {
598 598
                 $options = ' data-options="';
599 599
                 foreach ($stop['options'] as $option => $value) {
600
-                    $options .= $option . ':' . $value . ';';
600
+                    $options .= $option.':'.$value.';';
601 601
                 }
602 602
                 $options .= '"';
603 603
             } else {
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
             }
606 606
 
607 607
             //let's put all together
608
-            $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>';
608
+            $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>';
609 609
         }
610 610
 
611 611
         $content .= '</ol>';
@@ -637,24 +637,24 @@  discard block
 block discarded – undo
637 637
         $setup_array = array();
638 638
         foreach ($status_array as $item => $status) {
639 639
             $setup_array[$item] = array(
640
-                'class'  => 'ee-status-legend ee-status-legend-' . $status,
640
+                'class'  => 'ee-status-legend ee-status-legend-'.$status,
641 641
                 'desc'   => EEH_Template::pretty_status($status, false, 'sentence'),
642 642
                 'status' => $status,
643 643
             );
644 644
         }
645 645
 
646
-        $content = '<div class="ee-list-table-legend-container">' . "\n";
647
-        $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n";
648
-        $content .= '<dl class="ee-list-table-legend">' . "\n\t";
646
+        $content = '<div class="ee-list-table-legend-container">'."\n";
647
+        $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n";
648
+        $content .= '<dl class="ee-list-table-legend">'."\n\t";
649 649
         foreach ($setup_array as $item => $details) {
650 650
             $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : '';
651
-            $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t";
652
-            $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t";
653
-            $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t";
654
-            $content .= '</dt>' . "\n";
651
+            $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t";
652
+            $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t";
653
+            $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t";
654
+            $content .= '</dt>'."\n";
655 655
         }
656
-        $content .= '</dl>' . "\n";
657
-        $content .= '</div>' . "\n";
656
+        $content .= '</dl>'."\n";
657
+        $content .= '</div>'."\n";
658 658
         return $content;
659 659
     }
660 660
 
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
     public static function layout_array_as_table($data)
670 670
     {
671 671
         if (is_object($data) || $data instanceof __PHP_Incomplete_Class) {
672
-            $data = (array)$data;
672
+            $data = (array) $data;
673 673
         }
674 674
         ob_start();
675 675
         if (is_array($data)) {
@@ -770,9 +770,9 @@  discard block
 block discarded – undo
770 770
     ) {
771 771
         $page_links     = array();
772 772
         $disable_first  = $disable_last = '';
773
-        $total_items    = (int)$total_items;
774
-        $per_page       = (int)$per_page;
775
-        $current        = (int)$current;
773
+        $total_items    = (int) $total_items;
774
+        $per_page       = (int) $per_page;
775
+        $current        = (int) $current;
776 776
         $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name);
777 777
 
778 778
         //filter items_label
@@ -792,8 +792,8 @@  discard block
 block discarded – undo
792 792
             );
793 793
         } else {
794 794
             $items_label = array(
795
-                'single' => '1 ' . esc_html($items_label['single']),
796
-                'plural' => '%s ' . esc_html($items_label['plural']),
795
+                'single' => '1 '.esc_html($items_label['single']),
796
+                'plural' => '%s '.esc_html($items_label['plural']),
797 797
             );
798 798
         }
799 799
 
@@ -805,7 +805,7 @@  discard block
 block discarded – undo
805 805
 
806 806
         $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single'];
807 807
 
808
-        $output = '<span class="displaying-num">' . $item_label . '</span>';
808
+        $output = '<span class="displaying-num">'.$item_label.'</span>';
809 809
 
810 810
         if ($current === 1) {
811 811
             $disable_first = ' disabled';
@@ -815,7 +815,7 @@  discard block
 block discarded – undo
815 815
         }
816 816
 
817 817
         $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>",
818
-            'first-page' . $disable_first,
818
+            'first-page'.$disable_first,
819 819
             esc_attr__('Go to the first page'),
820 820
             esc_url(remove_query_arg($paged_arg_name, $url)),
821 821
             '&laquo;'
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 
824 824
         $page_links[] = sprintf(
825 825
             '<a class="%s" title="%s" href="%s">%s</a>',
826
-            'prev-page' . $disable_first,
826
+            'prev-page'.$disable_first,
827 827
             esc_attr__('Go to the previous page'),
828 828
             esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)),
829 829
             '&lsaquo;'
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
             '<span class="total-pages">%s</span>',
844 844
             number_format_i18n($total_pages)
845 845
         );
846
-        $page_links[]     = sprintf(
846
+        $page_links[] = sprintf(
847 847
             _x('%3$s%1$s of %2$s%4$s', 'paging'),
848 848
             $html_current_page,
849 849
             $html_total_pages,
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 
854 854
         $page_links[] = sprintf(
855 855
             '<a class="%s" title="%s" href="%s">%s</a>',
856
-            'next-page' . $disable_last,
856
+            'next-page'.$disable_last,
857 857
             esc_attr__('Go to the next page'),
858 858
             esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)),
859 859
             '&rsaquo;'
@@ -861,13 +861,13 @@  discard block
 block discarded – undo
861 861
 
862 862
         $page_links[] = sprintf(
863 863
             '<a class="%s" title="%s" href="%s">%s</a>',
864
-            'last-page' . $disable_last,
864
+            'last-page'.$disable_last,
865 865
             esc_attr__('Go to the last page'),
866 866
             esc_url(add_query_arg($paged_arg_name, $total_pages, $url)),
867 867
             '&raquo;'
868 868
         );
869 869
 
870
-        $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>';
870
+        $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>';
871 871
         // set page class
872 872
         if ($total_pages) {
873 873
             $page_class = $total_pages < 2 ? ' one-page' : '';
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
             $page_class = ' no-pages';
876 876
         }
877 877
 
878
-        return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>';
878
+        return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>';
879 879
     }
880 880
 
881 881
 
@@ -912,10 +912,10 @@  discard block
 block discarded – undo
912 912
             $query_args
913 913
         );
914 914
         $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text',
915
-            $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso');
915
+            $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso');
916 916
         $url        = add_query_arg($query_args, 'https://eventespresso.com/');
917 917
         $url        = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url);
918
-        return (string)apply_filters(
918
+        return (string) apply_filters(
919 919
             'FHEE__EEH_Template__powered_by_event_espresso__html',
920 920
             sprintf(
921 921
                 esc_html_x(
@@ -973,6 +973,6 @@  discard block
 block discarded – undo
973 973
                 'add_fragment' => '',
974 974
             )
975 975
         );
976
-        echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : '';
976
+        echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : '';
977 977
     }
978 978
 }
979 979
\ No newline at end of file
Please login to merge, or discard this patch.
core/libraries/messages/EE_Messages_Queue.lib.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -603,7 +603,7 @@
 block discarded – undo
603 603
      * @param EE_Message      $message
604 604
      * @param EE_messenger    $messenger
605 605
      * @param EE_message_type $message_type
606
-     * @param                 $test_send
606
+     * @param                 boolean $test_send
607 607
      * @return bool   true means all went well, false means, not so much.
608 608
      */
609 609
     protected function _do_preview(
Please login to merge, or discard this patch.
Indentation   +665 added lines, -665 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@  discard block
 block discarded – undo
2 2
 use \EventEspresso\core\exceptions\SendMessageException;
3 3
 
4 4
 if (! defined('EVENT_ESPRESSO_VERSION')) {
5
-    exit('No direct script access allowed');
5
+	exit('No direct script access allowed');
6 6
 }
7 7
 
8 8
 /**
@@ -18,669 +18,669 @@  discard block
 block discarded – undo
18 18
 {
19 19
 
20 20
 
21
-    /**
22
-     * @type    string  reference for sending action
23
-     */
24
-    const action_sending = 'sending';
25
-
26
-    /**
27
-     * @type    string  reference for generation action
28
-     */
29
-    const action_generating = 'generation';
30
-
31
-
32
-    /**
33
-     * @type EE_Message_Repository $_message_repository
34
-     */
35
-    protected $_message_repository;
36
-
37
-    /**
38
-     * Sets the limit of how many messages are generated per process.
39
-     *
40
-     * @type int
41
-     */
42
-    protected $_batch_count;
43
-
44
-    /**
45
-     * Sets the limit of how many messages can be sent per hour.
46
-     *
47
-     * @type int
48
-     */
49
-    protected $_rate_limit;
50
-
51
-    /**
52
-     * This is an array of cached queue items being stored in this object.
53
-     * The array keys will be the ID of the EE_Message in the db if saved.  If the EE_Message
54
-     * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.)
55
-     *
56
-     * @type EE_Message[]
57
-     */
58
-    protected $_cached_queue_items;
59
-
60
-    /**
61
-     * Tracks the number of unsaved queue items.
62
-     *
63
-     * @type int
64
-     */
65
-    protected $_unsaved_count = 0;
66
-
67
-    /**
68
-     * used to record if a do_messenger_hooks has already been called for a message type.  This prevents multiple
69
-     * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls.
70
-     *
71
-     * @type array
72
-     */
73
-    protected $_did_hook = array();
74
-
75
-
76
-    /**
77
-     * Constructor.
78
-     * Setup all the initial properties and load a EE_Message_Repository.
79
-     *
80
-     * @param \EE_Message_Repository $message_repository
81
-     */
82
-    public function __construct(EE_Message_Repository $message_repository)
83
-    {
84
-        $this->_batch_count        = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50);
85
-        $this->_rate_limit         = $this->get_rate_limit();
86
-        $this->_message_repository = $message_repository;
87
-    }
88
-
89
-
90
-    /**
91
-     * Add a EE_Message object to the queue
92
-     *
93
-     * @param EE_Message $message
94
-     * @param array      $data         This will be an array of data to attach to the object in the repository.  If the
95
-     *                                 object is persisted, this data will be saved on an extra_meta object related to
96
-     *                                 EE_Message.
97
-     * @param  bool      $preview      Whether this EE_Message represents a preview or not.
98
-     * @param  bool      $test_send    This indicates whether to do a test send instead of actual send. A test send will
99
-     *                                 use the messenger send method but typically is based on preview data.
100
-     * @return bool          Whether the message was successfully added to the repository or not.
101
-     */
102
-    public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false)
103
-    {
104
-        $data['preview']   = $preview;
105
-        $data['test_send'] = $test_send;
106
-        return $this->_message_repository->add($message, $data);
107
-    }
108
-
109
-
110
-    /**
111
-     * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message
112
-     *
113
-     * @param EE_Message $message The message to detach from the queue
114
-     * @param bool       $persist This flag indicates whether to attempt to delete the object from the db as well.
115
-     * @return bool
116
-     */
117
-    public function remove(EE_Message $message, $persist = false)
118
-    {
119
-        if ($persist && $this->_message_repository->current() !== $message) {
120
-            //get pointer on right message
121
-            if ($this->_message_repository->has($message)) {
122
-                $this->_message_repository->rewind();
123
-                while ($this->_message_repository->valid()) {
124
-                    if ($this->_message_repository->current() === $message) {
125
-                        break;
126
-                    }
127
-                    $this->_message_repository->next();
128
-                }
129
-            } else {
130
-                return false;
131
-            }
132
-        }
133
-        return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message);
134
-    }
135
-
136
-
137
-    /**
138
-     * Persists all queued EE_Message objects to the db.
139
-     *
140
-     * @return array()  @see EE_Messages_Repository::saveAll() for return values.
141
-     */
142
-    public function save()
143
-    {
144
-        return $this->_message_repository->saveAll();
145
-    }
146
-
147
-
148
-    /**
149
-     * @return EE_Message_Repository
150
-     */
151
-    public function get_message_repository()
152
-    {
153
-        return $this->_message_repository;
154
-    }
155
-
156
-
157
-    /**
158
-     * This does the following things:
159
-     * 1. Checks if there is a lock on generation (prevents race conditions).  If there is a lock then exits (return
160
-     * false).
161
-     * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue
162
-     * 3. Returns bool.  True = batch ready.  False = no batch ready (or nothing available for generation).
163
-     * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from
164
-     * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not
165
-     * removed.
166
-     *
167
-     * @return bool  true if successfully retrieved batch, false no batch ready.
168
-     */
169
-    public function get_batch_to_generate()
170
-    {
171
-        if ($this->is_locked(EE_Messages_Queue::action_generating)) {
172
-            return false;
173
-        }
174
-
175
-        //lock batch generation to prevent race conditions.
176
-        $this->lock_queue(EE_Messages_Queue::action_generating);
177
-
178
-        $query_args = array(
179
-            // key 0 = where conditions
180
-            0          => array('STS_ID' => EEM_Message::status_incomplete),
181
-            'order_by' => $this->_get_priority_orderby(),
182
-            'limit'    => $this->_batch_count,
183
-        );
184
-        $messages   = EEM_Message::instance()->get_all($query_args);
185
-
186
-        if ( ! $messages) {
187
-            return false; //nothing to generate
188
-        }
189
-
190
-        foreach ($messages as $message) {
191
-            if ($message instanceof EE_Message) {
192
-                $data = $message->all_extra_meta_array();
193
-                $this->add($message, $data);
194
-            }
195
-        }
196
-        return true;
197
-    }
198
-
199
-
200
-    /**
201
-     * This does the following things:
202
-     * 1. Checks if there is a lock on sending (prevents race conditions).  If there is a lock then exits (return
203
-     * false).
204
-     * 2. Grabs the allowed number of messages to send for the rate_limit.  If cannot send any more messages, then
205
-     * return false.
206
-     * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution.
207
-     * 3. On success or unsuccessful send, sets status appropriately.
208
-     * 4. Saves messages via the queue
209
-     * 5. Releases lock.
210
-     *
211
-     * @return bool  true on success, false if something preventing sending (i.e. lock set).  Note: true does not
212
-     *               necessarily mean that all messages were successfully sent.  It just means that this method
213
-     *               successfully completed. On true, client may want to call $this->count_STS_in_queue(
214
-     *               EEM_Message::status_failed ) to see if any failed EE_Message objects.  Each failed message object
215
-     *               will also have a saved error message on it to assist with notifying user.
216
-     */
217
-    public function get_to_send_batch_and_send()
218
-    {
219
-        if ($this->is_locked(EE_Messages_Queue::action_sending) || $this->_rate_limit < 1) {
220
-            return false;
221
-        }
222
-
223
-        $this->lock_queue(EE_Messages_Queue::action_sending);
224
-
225
-        $batch = $this->_batch_count < $this->_rate_limit ? $this->_batch_count : $this->_rate_limit;
226
-
227
-        $query_args = array(
228
-            // key 0 = where conditions
229
-            0          => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())),
230
-            'order_by' => $this->_get_priority_orderby(),
231
-            'limit'    => $batch,
232
-        );
233
-
234
-        $messages_to_send = EEM_Message::instance()->get_all($query_args);
235
-
236
-
237
-        //any to send?
238
-        if ( ! $messages_to_send) {
239
-            $this->unlock_queue(EE_Messages_Queue::action_sending);
240
-            return false;
241
-        }
242
-
243
-        //add to queue.
244
-        foreach ($messages_to_send as $message) {
245
-            if ($message instanceof EE_Message) {
246
-                $this->add($message);
247
-            }
248
-        }
249
-
250
-        //send messages  (this also updates the rate limit)
251
-        $this->execute();
252
-
253
-        //release lock
254
-        $this->unlock_queue(EE_Messages_Queue::action_sending);
255
-        return true;
256
-    }
257
-
258
-
259
-    /**
260
-     * Locks the queue so that no other queues can call the "batch" methods.
261
-     *
262
-     * @param   string $type The type of queue being locked.
263
-     */
264
-    public function lock_queue($type = EE_Messages_Queue::action_generating)
265
-    {
266
-        set_transient($this->_get_lock_key($type), 1, $this->_get_lock_expiry($type));
267
-    }
268
-
269
-
270
-    /**
271
-     * Unlocks the queue so that batch methods can be used.
272
-     *
273
-     * @param   string $type The type of queue being unlocked.
274
-     */
275
-    public function unlock_queue($type = EE_Messages_Queue::action_generating)
276
-    {
277
-        delete_transient($this->_get_lock_key($type));
278
-    }
279
-
280
-
281
-    /**
282
-     * Retrieve the key used for the lock transient.
283
-     *
284
-     * @param string $type The type of lock.
285
-     * @return string
286
-     */
287
-    protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
288
-    {
289
-        return '_ee_lock_' . $type;
290
-    }
291
-
292
-
293
-    /**
294
-     * Retrieve the expiry time for the lock transient.
295
-     *
296
-     * @param string $type The type of lock
297
-     * @return int   time to expiry in seconds.
298
-     */
299
-    protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
300
-    {
301
-        return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
302
-    }
303
-
304
-
305
-    /**
306
-     * Returns the key used for rate limit transient.
307
-     *
308
-     * @return string
309
-     */
310
-    protected function _get_rate_limit_key()
311
-    {
312
-        return '_ee_rate_limit';
313
-    }
314
-
315
-
316
-    /**
317
-     * Returns the rate limit expiry time.
318
-     *
319
-     * @return int
320
-     */
321
-    protected function _get_rate_limit_expiry()
322
-    {
323
-        return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
324
-    }
325
-
326
-
327
-    /**
328
-     * Returns the default rate limit for sending messages.
329
-     *
330
-     * @return int
331
-     */
332
-    protected function _default_rate_limit()
333
-    {
334
-        return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
335
-    }
336
-
337
-
338
-    /**
339
-     * Return the orderby array for priority.
340
-     *
341
-     * @return array
342
-     */
343
-    protected function _get_priority_orderby()
344
-    {
345
-        return array(
346
-            'MSG_priority' => 'ASC',
347
-            'MSG_modified' => 'DESC',
348
-        );
349
-    }
350
-
351
-
352
-    /**
353
-     * Returns whether batch methods are "locked" or not.
354
-     *
355
-     * @param  string $type The type of lock being checked for.
356
-     * @return bool
357
-     */
358
-    public function is_locked($type = EE_Messages_Queue::action_generating)
359
-    {
360
-        /**
361
-         * This filters the default is_locked behaviour.
362
-         */
363
-        $is_locked = filter_var(
364
-            apply_filters(
365
-                'FHEE__EE_Messages_Queue__is_locked',
366
-                get_transient($this->_get_lock_key($type)),
367
-                $this
368
-            ),
369
-            FILTER_VALIDATE_BOOLEAN
370
-        );
371
-
372
-        /**
373
-         * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method.
374
-         *            Also implemented here because messages processed on the same request should not have any locks applied.
375
-         */
376
-        if (
377
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
378
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
379
-        ) {
380
-            $is_locked = false;
381
-        }
382
-
383
-
384
-        return $is_locked;
385
-    }
386
-
387
-
388
-    /**
389
-     * Retrieves the rate limit that may be cached as a transient.
390
-     * If the rate limit is not set, then this sets the default rate limit and expiry and returns it.
391
-     *
392
-     * @return int
393
-     */
394
-    public function get_rate_limit()
395
-    {
396
-        if ( ! $rate_limit = get_transient($this->_get_rate_limit_key())) {
397
-            $rate_limit = $this->_default_rate_limit();
398
-            set_transient($this->_get_rate_limit_key(), $rate_limit, $this->_get_rate_limit_key());
399
-        }
400
-        return $rate_limit;
401
-    }
402
-
403
-
404
-    /**
405
-     * This updates existing rate limit with the new limit which is the old minus the batch.
406
-     *
407
-     * @param int $batch_completed This sets the new rate limit based on the given batch that was completed.
408
-     */
409
-    public function set_rate_limit($batch_completed)
410
-    {
411
-        //first get the most up to date rate limit (in case its expired and reset)
412
-        $rate_limit = $this->get_rate_limit();
413
-        $new_limit  = $rate_limit - $batch_completed;
414
-        //updating the transient option directly to avoid resetting the expiry.
415
-        update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
416
-    }
417
-
418
-
419
-    /**
420
-     * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in.
421
-     * If that exists, then we immediately initiate a non-blocking request to do the requested action type.
422
-     * Note: Keep in mind that there is the possibility that the request will not execute if there is already another
423
-     * request running on a queue for the given task.
424
-     *
425
-     * @param string $task     This indicates what type of request is going to be initiated.
426
-     * @param int    $priority This indicates the priority that triggers initiating the request.
427
-     */
428
-    public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high)
429
-    {
430
-        //determine what status is matched with the priority as part of the trigger conditions.
431
-        $status = $task == 'generate'
432
-            ? EEM_Message::status_incomplete
433
-            : EEM_Message::instance()->stati_indicating_to_send();
434
-        // always make sure we save because either this will get executed immediately on a separate request
435
-        // or remains in the queue for the regularly scheduled queue batch.
436
-        $this->save();
437
-        /**
438
-         * This filter/option allows users to override processing of messages on separate requests and instead have everything
439
-         * happen on the same request.  If this is utilized remember:
440
-         * - message priorities don't matter
441
-         * - existing unprocessed messages in the queue will not get processed unless manually triggered.
442
-         * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional
443
-         *   processing happening on the same request.
444
-         * - any race condition protection (locks) are removed because they don't apply when things are processed on
445
-         *   the same request.
446
-         */
447
-        if (
448
-            apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
449
-            || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
450
-        ) {
451
-            $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor');
452
-            if ($messages_processor instanceof EE_Messages_Processor) {
453
-                return $messages_processor->process_immediately_from_queue($this);
454
-            }
455
-            //if we get here then that means the messages processor couldn't be loaded so messages will just remain
456
-            //queued for manual triggering by end user.
457
-        }
458
-
459
-        if ($this->_message_repository->count_by_priority_and_status($priority, $status)) {
460
-            EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task);
461
-        }
462
-    }
463
-
464
-
465
-    /**
466
-     *  Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message.
467
-     *
468
-     * @param   bool     $save                    Used to indicate whether to save the message queue after sending
469
-     *                                            (default will save).
470
-     * @param   mixed    $sending_messenger       (optional) When the sending messenger is different than
471
-     *                                            what is on the EE_Message object in the queue.
472
-     *                                            For instance, showing the browser view of an email message,
473
-     *                                            or giving a pdf generated view of an html document.
474
-     *                                            This should be an instance of EE_messenger but if you call this
475
-     *                                            method
476
-     *                                            intending it to be a sending messenger but a valid one could not be
477
-     *                                            retrieved then send in an instance of EE_Error that contains the
478
-     *                                            related error message.
479
-     * @param   bool|int $by_priority             When set, this indicates that only messages
480
-     *                                            matching the given priority should be executed.
481
-     * @return int        Number of messages sent.  Note, 0 does not mean that no messages were processed.
482
-     *                                            Also, if the messenger is an request type messenger (or a preview),
483
-     *                                            its entirely possible that the messenger will exit before
484
-     */
485
-    public function execute($save = true, $sending_messenger = null, $by_priority = false)
486
-    {
487
-        $messages_sent   = 0;
488
-        $this->_did_hook = array();
489
-        $this->_message_repository->rewind();
490
-
491
-        while ($this->_message_repository->valid()) {
492
-            $error_messages = array();
493
-            /** @type EE_Message $message */
494
-            $message = $this->_message_repository->current();
495
-            //only process things that are queued for sending
496
-            if ( ! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
497
-                $this->_message_repository->next();
498
-                continue;
499
-            }
500
-            //if $by_priority is set and does not match then continue;
501
-            if ($by_priority && $by_priority != $message->priority()) {
502
-                $this->_message_repository->next();
503
-                continue;
504
-            }
505
-            //error checking
506
-            if ( ! $message->valid_messenger()) {
507
-                $error_messages[] = sprintf(
508
-                    __('The %s messenger is not active at time of sending.', 'event_espresso'),
509
-                    $message->messenger()
510
-                );
511
-            }
512
-            if ( ! $message->valid_message_type()) {
513
-                $error_messages[] = sprintf(
514
-                    __('The %s message type is not active at the time of sending.', 'event_espresso'),
515
-                    $message->message_type()
516
-                );
517
-            }
518
-            // if there was supposed to be a sending messenger for this message, but it was invalid/inactive,
519
-            // then it will instead be an EE_Error object, so let's check for that
520
-            if ($sending_messenger instanceof EE_Error) {
521
-                $error_messages[] = $sending_messenger->getMessage();
522
-            }
523
-            // if there are no errors, then let's process the message
524
-            if (empty($error_messages) && $this->_process_message($message, $sending_messenger)) {
525
-                $messages_sent++;
526
-            }
527
-            $this->_set_error_message($message, $error_messages);
528
-            //add modified time
529
-            $message->set_modified(time());
530
-            $this->_message_repository->next();
531
-        }
532
-        if ($save) {
533
-            $this->save();
534
-        }
535
-        return $messages_sent;
536
-    }
537
-
538
-
539
-    /**
540
-     * _process_message
541
-     *
542
-     * @param EE_Message $message
543
-     * @param mixed      $sending_messenger (optional)
544
-     * @return bool
545
-     */
546
-    protected function _process_message(EE_Message $message, $sending_messenger = null)
547
-    {
548
-        // these *should* have been validated in the execute() method above
549
-        $messenger    = $message->messenger_object();
550
-        $message_type = $message->message_type_object();
551
-        //do actions for sending messenger if it differs from generating messenger and swap values.
552
-        if (
553
-            $sending_messenger instanceof EE_messenger
554
-            && $messenger instanceof EE_messenger
555
-            && $sending_messenger->name != $messenger->name
556
-        ) {
557
-            $messenger->do_secondary_messenger_hooks($sending_messenger->name);
558
-            $messenger = $sending_messenger;
559
-        }
560
-        // send using messenger, but double check objects
561
-        if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) {
562
-            //set hook for message type (but only if not using another messenger to send).
563
-            if ( ! isset($this->_did_hook[$message_type->name])) {
564
-                $message_type->do_messenger_hooks($messenger);
565
-                $this->_did_hook[$message_type->name] = 1;
566
-            }
567
-            //if preview then use preview method
568
-            return $this->_message_repository->is_preview()
569
-                ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send())
570
-                : $this->_do_send($message, $messenger, $message_type);
571
-        }
572
-        return false;
573
-    }
574
-
575
-
576
-    /**
577
-     * The intention of this method is to count how many EE_Message objects
578
-     * are in the queue with a given status.
579
-     * Example usage:
580
-     * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed
581
-     * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ).
582
-     *
583
-     * @param array $status Stati to check for in queue
584
-     * @return int  Count of EE_Message's matching the given status.
585
-     */
586
-    public function count_STS_in_queue($status)
587
-    {
588
-        $count  = 0;
589
-        $status = is_array($status) ? $status : array($status);
590
-        $this->_message_repository->rewind();
591
-        foreach ($this->_message_repository as $message) {
592
-            if (in_array($message->STS_ID(), $status)) {
593
-                $count++;
594
-            }
595
-        }
596
-        return $count;
597
-    }
598
-
599
-
600
-    /**
601
-     * Executes the get_preview method on the provided messenger.
602
-     *
603
-     * @param EE_Message      $message
604
-     * @param EE_messenger    $messenger
605
-     * @param EE_message_type $message_type
606
-     * @param                 $test_send
607
-     * @return bool   true means all went well, false means, not so much.
608
-     */
609
-    protected function _do_preview(
610
-        EE_Message $message,
611
-        EE_messenger $messenger,
612
-        EE_message_type $message_type,
613
-        $test_send
614
-    ) {
615
-        if ($preview = $messenger->get_preview($message, $message_type, $test_send)) {
616
-            if ( ! $test_send) {
617
-                $message->set_content($preview);
618
-            }
619
-            $message->set_STS_ID(EEM_Message::status_sent);
620
-            return true;
621
-        } else {
622
-            $message->set_STS_ID(EEM_Message::status_failed);
623
-            return false;
624
-        }
625
-    }
626
-
627
-
628
-    /**
629
-     * Executes the send method on the provided messenger
630
-     * EE_Messengers are expected to:
631
-     * - return true if the send was successful.
632
-     * - return false if the send was unsuccessful but can be tried again.
633
-     * - throw an Exception if the send was unsuccessful and cannot be tried again.
634
-     *
635
-     * @param EE_Message      $message
636
-     * @param EE_messenger    $messenger
637
-     * @param EE_message_type $message_type
638
-     * @return bool true means all went well, false means, not so much.
639
-     */
640
-    protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type)
641
-    {
642
-        try {
643
-            if ($messenger->send_message($message, $message_type)) {
644
-                $message->set_STS_ID(EEM_Message::status_sent);
645
-                return true;
646
-            } else {
647
-                $message->set_STS_ID(EEM_Message::status_retry);
648
-                return false;
649
-            }
650
-        } catch (SendMessageException $e) {
651
-            $message->set_STS_ID(EEM_Message::status_failed);
652
-            $message->set_error_message($e->getMessage());
653
-            return false;
654
-        }
655
-    }
656
-
657
-
658
-    /**
659
-     * This sets any necessary error messages on the message object and its status to failed.
660
-     *
661
-     * @param EE_Message $message
662
-     * @param array      $error_messages the response from the messenger.
663
-     */
664
-    protected function _set_error_message(EE_Message $message, $error_messages)
665
-    {
666
-        $error_messages = (array)$error_messages;
667
-        if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
668
-            $notices          = EE_Error::has_notices();
669
-            $error_messages[] = __(
670
-                'Messenger and Message Type were valid and active, but the messenger send method failed.',
671
-                'event_espresso'
672
-            );
673
-            if ($notices === 1) {
674
-                $notices           = EE_Error::get_vanilla_notices();
675
-                $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array();
676
-                $error_messages[]  = implode("\n", $notices['errors']);
677
-            }
678
-        }
679
-        if (count($error_messages) > 0) {
680
-            $msg = __('Message was not executed successfully.', 'event_espresso');
681
-            $msg = $msg . "\n" . implode("\n", $error_messages);
682
-            $message->set_error_message($msg);
683
-        }
684
-    }
21
+	/**
22
+	 * @type    string  reference for sending action
23
+	 */
24
+	const action_sending = 'sending';
25
+
26
+	/**
27
+	 * @type    string  reference for generation action
28
+	 */
29
+	const action_generating = 'generation';
30
+
31
+
32
+	/**
33
+	 * @type EE_Message_Repository $_message_repository
34
+	 */
35
+	protected $_message_repository;
36
+
37
+	/**
38
+	 * Sets the limit of how many messages are generated per process.
39
+	 *
40
+	 * @type int
41
+	 */
42
+	protected $_batch_count;
43
+
44
+	/**
45
+	 * Sets the limit of how many messages can be sent per hour.
46
+	 *
47
+	 * @type int
48
+	 */
49
+	protected $_rate_limit;
50
+
51
+	/**
52
+	 * This is an array of cached queue items being stored in this object.
53
+	 * The array keys will be the ID of the EE_Message in the db if saved.  If the EE_Message
54
+	 * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.)
55
+	 *
56
+	 * @type EE_Message[]
57
+	 */
58
+	protected $_cached_queue_items;
59
+
60
+	/**
61
+	 * Tracks the number of unsaved queue items.
62
+	 *
63
+	 * @type int
64
+	 */
65
+	protected $_unsaved_count = 0;
66
+
67
+	/**
68
+	 * used to record if a do_messenger_hooks has already been called for a message type.  This prevents multiple
69
+	 * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls.
70
+	 *
71
+	 * @type array
72
+	 */
73
+	protected $_did_hook = array();
74
+
75
+
76
+	/**
77
+	 * Constructor.
78
+	 * Setup all the initial properties and load a EE_Message_Repository.
79
+	 *
80
+	 * @param \EE_Message_Repository $message_repository
81
+	 */
82
+	public function __construct(EE_Message_Repository $message_repository)
83
+	{
84
+		$this->_batch_count        = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50);
85
+		$this->_rate_limit         = $this->get_rate_limit();
86
+		$this->_message_repository = $message_repository;
87
+	}
88
+
89
+
90
+	/**
91
+	 * Add a EE_Message object to the queue
92
+	 *
93
+	 * @param EE_Message $message
94
+	 * @param array      $data         This will be an array of data to attach to the object in the repository.  If the
95
+	 *                                 object is persisted, this data will be saved on an extra_meta object related to
96
+	 *                                 EE_Message.
97
+	 * @param  bool      $preview      Whether this EE_Message represents a preview or not.
98
+	 * @param  bool      $test_send    This indicates whether to do a test send instead of actual send. A test send will
99
+	 *                                 use the messenger send method but typically is based on preview data.
100
+	 * @return bool          Whether the message was successfully added to the repository or not.
101
+	 */
102
+	public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false)
103
+	{
104
+		$data['preview']   = $preview;
105
+		$data['test_send'] = $test_send;
106
+		return $this->_message_repository->add($message, $data);
107
+	}
108
+
109
+
110
+	/**
111
+	 * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message
112
+	 *
113
+	 * @param EE_Message $message The message to detach from the queue
114
+	 * @param bool       $persist This flag indicates whether to attempt to delete the object from the db as well.
115
+	 * @return bool
116
+	 */
117
+	public function remove(EE_Message $message, $persist = false)
118
+	{
119
+		if ($persist && $this->_message_repository->current() !== $message) {
120
+			//get pointer on right message
121
+			if ($this->_message_repository->has($message)) {
122
+				$this->_message_repository->rewind();
123
+				while ($this->_message_repository->valid()) {
124
+					if ($this->_message_repository->current() === $message) {
125
+						break;
126
+					}
127
+					$this->_message_repository->next();
128
+				}
129
+			} else {
130
+				return false;
131
+			}
132
+		}
133
+		return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message);
134
+	}
135
+
136
+
137
+	/**
138
+	 * Persists all queued EE_Message objects to the db.
139
+	 *
140
+	 * @return array()  @see EE_Messages_Repository::saveAll() for return values.
141
+	 */
142
+	public function save()
143
+	{
144
+		return $this->_message_repository->saveAll();
145
+	}
146
+
147
+
148
+	/**
149
+	 * @return EE_Message_Repository
150
+	 */
151
+	public function get_message_repository()
152
+	{
153
+		return $this->_message_repository;
154
+	}
155
+
156
+
157
+	/**
158
+	 * This does the following things:
159
+	 * 1. Checks if there is a lock on generation (prevents race conditions).  If there is a lock then exits (return
160
+	 * false).
161
+	 * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue
162
+	 * 3. Returns bool.  True = batch ready.  False = no batch ready (or nothing available for generation).
163
+	 * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from
164
+	 * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not
165
+	 * removed.
166
+	 *
167
+	 * @return bool  true if successfully retrieved batch, false no batch ready.
168
+	 */
169
+	public function get_batch_to_generate()
170
+	{
171
+		if ($this->is_locked(EE_Messages_Queue::action_generating)) {
172
+			return false;
173
+		}
174
+
175
+		//lock batch generation to prevent race conditions.
176
+		$this->lock_queue(EE_Messages_Queue::action_generating);
177
+
178
+		$query_args = array(
179
+			// key 0 = where conditions
180
+			0          => array('STS_ID' => EEM_Message::status_incomplete),
181
+			'order_by' => $this->_get_priority_orderby(),
182
+			'limit'    => $this->_batch_count,
183
+		);
184
+		$messages   = EEM_Message::instance()->get_all($query_args);
185
+
186
+		if ( ! $messages) {
187
+			return false; //nothing to generate
188
+		}
189
+
190
+		foreach ($messages as $message) {
191
+			if ($message instanceof EE_Message) {
192
+				$data = $message->all_extra_meta_array();
193
+				$this->add($message, $data);
194
+			}
195
+		}
196
+		return true;
197
+	}
198
+
199
+
200
+	/**
201
+	 * This does the following things:
202
+	 * 1. Checks if there is a lock on sending (prevents race conditions).  If there is a lock then exits (return
203
+	 * false).
204
+	 * 2. Grabs the allowed number of messages to send for the rate_limit.  If cannot send any more messages, then
205
+	 * return false.
206
+	 * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution.
207
+	 * 3. On success or unsuccessful send, sets status appropriately.
208
+	 * 4. Saves messages via the queue
209
+	 * 5. Releases lock.
210
+	 *
211
+	 * @return bool  true on success, false if something preventing sending (i.e. lock set).  Note: true does not
212
+	 *               necessarily mean that all messages were successfully sent.  It just means that this method
213
+	 *               successfully completed. On true, client may want to call $this->count_STS_in_queue(
214
+	 *               EEM_Message::status_failed ) to see if any failed EE_Message objects.  Each failed message object
215
+	 *               will also have a saved error message on it to assist with notifying user.
216
+	 */
217
+	public function get_to_send_batch_and_send()
218
+	{
219
+		if ($this->is_locked(EE_Messages_Queue::action_sending) || $this->_rate_limit < 1) {
220
+			return false;
221
+		}
222
+
223
+		$this->lock_queue(EE_Messages_Queue::action_sending);
224
+
225
+		$batch = $this->_batch_count < $this->_rate_limit ? $this->_batch_count : $this->_rate_limit;
226
+
227
+		$query_args = array(
228
+			// key 0 = where conditions
229
+			0          => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())),
230
+			'order_by' => $this->_get_priority_orderby(),
231
+			'limit'    => $batch,
232
+		);
233
+
234
+		$messages_to_send = EEM_Message::instance()->get_all($query_args);
235
+
236
+
237
+		//any to send?
238
+		if ( ! $messages_to_send) {
239
+			$this->unlock_queue(EE_Messages_Queue::action_sending);
240
+			return false;
241
+		}
242
+
243
+		//add to queue.
244
+		foreach ($messages_to_send as $message) {
245
+			if ($message instanceof EE_Message) {
246
+				$this->add($message);
247
+			}
248
+		}
249
+
250
+		//send messages  (this also updates the rate limit)
251
+		$this->execute();
252
+
253
+		//release lock
254
+		$this->unlock_queue(EE_Messages_Queue::action_sending);
255
+		return true;
256
+	}
257
+
258
+
259
+	/**
260
+	 * Locks the queue so that no other queues can call the "batch" methods.
261
+	 *
262
+	 * @param   string $type The type of queue being locked.
263
+	 */
264
+	public function lock_queue($type = EE_Messages_Queue::action_generating)
265
+	{
266
+		set_transient($this->_get_lock_key($type), 1, $this->_get_lock_expiry($type));
267
+	}
268
+
269
+
270
+	/**
271
+	 * Unlocks the queue so that batch methods can be used.
272
+	 *
273
+	 * @param   string $type The type of queue being unlocked.
274
+	 */
275
+	public function unlock_queue($type = EE_Messages_Queue::action_generating)
276
+	{
277
+		delete_transient($this->_get_lock_key($type));
278
+	}
279
+
280
+
281
+	/**
282
+	 * Retrieve the key used for the lock transient.
283
+	 *
284
+	 * @param string $type The type of lock.
285
+	 * @return string
286
+	 */
287
+	protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
288
+	{
289
+		return '_ee_lock_' . $type;
290
+	}
291
+
292
+
293
+	/**
294
+	 * Retrieve the expiry time for the lock transient.
295
+	 *
296
+	 * @param string $type The type of lock
297
+	 * @return int   time to expiry in seconds.
298
+	 */
299
+	protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
300
+	{
301
+		return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
302
+	}
303
+
304
+
305
+	/**
306
+	 * Returns the key used for rate limit transient.
307
+	 *
308
+	 * @return string
309
+	 */
310
+	protected function _get_rate_limit_key()
311
+	{
312
+		return '_ee_rate_limit';
313
+	}
314
+
315
+
316
+	/**
317
+	 * Returns the rate limit expiry time.
318
+	 *
319
+	 * @return int
320
+	 */
321
+	protected function _get_rate_limit_expiry()
322
+	{
323
+		return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
324
+	}
325
+
326
+
327
+	/**
328
+	 * Returns the default rate limit for sending messages.
329
+	 *
330
+	 * @return int
331
+	 */
332
+	protected function _default_rate_limit()
333
+	{
334
+		return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
335
+	}
336
+
337
+
338
+	/**
339
+	 * Return the orderby array for priority.
340
+	 *
341
+	 * @return array
342
+	 */
343
+	protected function _get_priority_orderby()
344
+	{
345
+		return array(
346
+			'MSG_priority' => 'ASC',
347
+			'MSG_modified' => 'DESC',
348
+		);
349
+	}
350
+
351
+
352
+	/**
353
+	 * Returns whether batch methods are "locked" or not.
354
+	 *
355
+	 * @param  string $type The type of lock being checked for.
356
+	 * @return bool
357
+	 */
358
+	public function is_locked($type = EE_Messages_Queue::action_generating)
359
+	{
360
+		/**
361
+		 * This filters the default is_locked behaviour.
362
+		 */
363
+		$is_locked = filter_var(
364
+			apply_filters(
365
+				'FHEE__EE_Messages_Queue__is_locked',
366
+				get_transient($this->_get_lock_key($type)),
367
+				$this
368
+			),
369
+			FILTER_VALIDATE_BOOLEAN
370
+		);
371
+
372
+		/**
373
+		 * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method.
374
+		 *            Also implemented here because messages processed on the same request should not have any locks applied.
375
+		 */
376
+		if (
377
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
378
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
379
+		) {
380
+			$is_locked = false;
381
+		}
382
+
383
+
384
+		return $is_locked;
385
+	}
386
+
387
+
388
+	/**
389
+	 * Retrieves the rate limit that may be cached as a transient.
390
+	 * If the rate limit is not set, then this sets the default rate limit and expiry and returns it.
391
+	 *
392
+	 * @return int
393
+	 */
394
+	public function get_rate_limit()
395
+	{
396
+		if ( ! $rate_limit = get_transient($this->_get_rate_limit_key())) {
397
+			$rate_limit = $this->_default_rate_limit();
398
+			set_transient($this->_get_rate_limit_key(), $rate_limit, $this->_get_rate_limit_key());
399
+		}
400
+		return $rate_limit;
401
+	}
402
+
403
+
404
+	/**
405
+	 * This updates existing rate limit with the new limit which is the old minus the batch.
406
+	 *
407
+	 * @param int $batch_completed This sets the new rate limit based on the given batch that was completed.
408
+	 */
409
+	public function set_rate_limit($batch_completed)
410
+	{
411
+		//first get the most up to date rate limit (in case its expired and reset)
412
+		$rate_limit = $this->get_rate_limit();
413
+		$new_limit  = $rate_limit - $batch_completed;
414
+		//updating the transient option directly to avoid resetting the expiry.
415
+		update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
416
+	}
417
+
418
+
419
+	/**
420
+	 * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in.
421
+	 * If that exists, then we immediately initiate a non-blocking request to do the requested action type.
422
+	 * Note: Keep in mind that there is the possibility that the request will not execute if there is already another
423
+	 * request running on a queue for the given task.
424
+	 *
425
+	 * @param string $task     This indicates what type of request is going to be initiated.
426
+	 * @param int    $priority This indicates the priority that triggers initiating the request.
427
+	 */
428
+	public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high)
429
+	{
430
+		//determine what status is matched with the priority as part of the trigger conditions.
431
+		$status = $task == 'generate'
432
+			? EEM_Message::status_incomplete
433
+			: EEM_Message::instance()->stati_indicating_to_send();
434
+		// always make sure we save because either this will get executed immediately on a separate request
435
+		// or remains in the queue for the regularly scheduled queue batch.
436
+		$this->save();
437
+		/**
438
+		 * This filter/option allows users to override processing of messages on separate requests and instead have everything
439
+		 * happen on the same request.  If this is utilized remember:
440
+		 * - message priorities don't matter
441
+		 * - existing unprocessed messages in the queue will not get processed unless manually triggered.
442
+		 * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional
443
+		 *   processing happening on the same request.
444
+		 * - any race condition protection (locks) are removed because they don't apply when things are processed on
445
+		 *   the same request.
446
+		 */
447
+		if (
448
+			apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false)
449
+			|| EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request
450
+		) {
451
+			$messages_processor = EE_Registry::instance()->load_lib('Messages_Processor');
452
+			if ($messages_processor instanceof EE_Messages_Processor) {
453
+				return $messages_processor->process_immediately_from_queue($this);
454
+			}
455
+			//if we get here then that means the messages processor couldn't be loaded so messages will just remain
456
+			//queued for manual triggering by end user.
457
+		}
458
+
459
+		if ($this->_message_repository->count_by_priority_and_status($priority, $status)) {
460
+			EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task);
461
+		}
462
+	}
463
+
464
+
465
+	/**
466
+	 *  Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message.
467
+	 *
468
+	 * @param   bool     $save                    Used to indicate whether to save the message queue after sending
469
+	 *                                            (default will save).
470
+	 * @param   mixed    $sending_messenger       (optional) When the sending messenger is different than
471
+	 *                                            what is on the EE_Message object in the queue.
472
+	 *                                            For instance, showing the browser view of an email message,
473
+	 *                                            or giving a pdf generated view of an html document.
474
+	 *                                            This should be an instance of EE_messenger but if you call this
475
+	 *                                            method
476
+	 *                                            intending it to be a sending messenger but a valid one could not be
477
+	 *                                            retrieved then send in an instance of EE_Error that contains the
478
+	 *                                            related error message.
479
+	 * @param   bool|int $by_priority             When set, this indicates that only messages
480
+	 *                                            matching the given priority should be executed.
481
+	 * @return int        Number of messages sent.  Note, 0 does not mean that no messages were processed.
482
+	 *                                            Also, if the messenger is an request type messenger (or a preview),
483
+	 *                                            its entirely possible that the messenger will exit before
484
+	 */
485
+	public function execute($save = true, $sending_messenger = null, $by_priority = false)
486
+	{
487
+		$messages_sent   = 0;
488
+		$this->_did_hook = array();
489
+		$this->_message_repository->rewind();
490
+
491
+		while ($this->_message_repository->valid()) {
492
+			$error_messages = array();
493
+			/** @type EE_Message $message */
494
+			$message = $this->_message_repository->current();
495
+			//only process things that are queued for sending
496
+			if ( ! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) {
497
+				$this->_message_repository->next();
498
+				continue;
499
+			}
500
+			//if $by_priority is set and does not match then continue;
501
+			if ($by_priority && $by_priority != $message->priority()) {
502
+				$this->_message_repository->next();
503
+				continue;
504
+			}
505
+			//error checking
506
+			if ( ! $message->valid_messenger()) {
507
+				$error_messages[] = sprintf(
508
+					__('The %s messenger is not active at time of sending.', 'event_espresso'),
509
+					$message->messenger()
510
+				);
511
+			}
512
+			if ( ! $message->valid_message_type()) {
513
+				$error_messages[] = sprintf(
514
+					__('The %s message type is not active at the time of sending.', 'event_espresso'),
515
+					$message->message_type()
516
+				);
517
+			}
518
+			// if there was supposed to be a sending messenger for this message, but it was invalid/inactive,
519
+			// then it will instead be an EE_Error object, so let's check for that
520
+			if ($sending_messenger instanceof EE_Error) {
521
+				$error_messages[] = $sending_messenger->getMessage();
522
+			}
523
+			// if there are no errors, then let's process the message
524
+			if (empty($error_messages) && $this->_process_message($message, $sending_messenger)) {
525
+				$messages_sent++;
526
+			}
527
+			$this->_set_error_message($message, $error_messages);
528
+			//add modified time
529
+			$message->set_modified(time());
530
+			$this->_message_repository->next();
531
+		}
532
+		if ($save) {
533
+			$this->save();
534
+		}
535
+		return $messages_sent;
536
+	}
537
+
538
+
539
+	/**
540
+	 * _process_message
541
+	 *
542
+	 * @param EE_Message $message
543
+	 * @param mixed      $sending_messenger (optional)
544
+	 * @return bool
545
+	 */
546
+	protected function _process_message(EE_Message $message, $sending_messenger = null)
547
+	{
548
+		// these *should* have been validated in the execute() method above
549
+		$messenger    = $message->messenger_object();
550
+		$message_type = $message->message_type_object();
551
+		//do actions for sending messenger if it differs from generating messenger and swap values.
552
+		if (
553
+			$sending_messenger instanceof EE_messenger
554
+			&& $messenger instanceof EE_messenger
555
+			&& $sending_messenger->name != $messenger->name
556
+		) {
557
+			$messenger->do_secondary_messenger_hooks($sending_messenger->name);
558
+			$messenger = $sending_messenger;
559
+		}
560
+		// send using messenger, but double check objects
561
+		if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) {
562
+			//set hook for message type (but only if not using another messenger to send).
563
+			if ( ! isset($this->_did_hook[$message_type->name])) {
564
+				$message_type->do_messenger_hooks($messenger);
565
+				$this->_did_hook[$message_type->name] = 1;
566
+			}
567
+			//if preview then use preview method
568
+			return $this->_message_repository->is_preview()
569
+				? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send())
570
+				: $this->_do_send($message, $messenger, $message_type);
571
+		}
572
+		return false;
573
+	}
574
+
575
+
576
+	/**
577
+	 * The intention of this method is to count how many EE_Message objects
578
+	 * are in the queue with a given status.
579
+	 * Example usage:
580
+	 * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed
581
+	 * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ).
582
+	 *
583
+	 * @param array $status Stati to check for in queue
584
+	 * @return int  Count of EE_Message's matching the given status.
585
+	 */
586
+	public function count_STS_in_queue($status)
587
+	{
588
+		$count  = 0;
589
+		$status = is_array($status) ? $status : array($status);
590
+		$this->_message_repository->rewind();
591
+		foreach ($this->_message_repository as $message) {
592
+			if (in_array($message->STS_ID(), $status)) {
593
+				$count++;
594
+			}
595
+		}
596
+		return $count;
597
+	}
598
+
599
+
600
+	/**
601
+	 * Executes the get_preview method on the provided messenger.
602
+	 *
603
+	 * @param EE_Message      $message
604
+	 * @param EE_messenger    $messenger
605
+	 * @param EE_message_type $message_type
606
+	 * @param                 $test_send
607
+	 * @return bool   true means all went well, false means, not so much.
608
+	 */
609
+	protected function _do_preview(
610
+		EE_Message $message,
611
+		EE_messenger $messenger,
612
+		EE_message_type $message_type,
613
+		$test_send
614
+	) {
615
+		if ($preview = $messenger->get_preview($message, $message_type, $test_send)) {
616
+			if ( ! $test_send) {
617
+				$message->set_content($preview);
618
+			}
619
+			$message->set_STS_ID(EEM_Message::status_sent);
620
+			return true;
621
+		} else {
622
+			$message->set_STS_ID(EEM_Message::status_failed);
623
+			return false;
624
+		}
625
+	}
626
+
627
+
628
+	/**
629
+	 * Executes the send method on the provided messenger
630
+	 * EE_Messengers are expected to:
631
+	 * - return true if the send was successful.
632
+	 * - return false if the send was unsuccessful but can be tried again.
633
+	 * - throw an Exception if the send was unsuccessful and cannot be tried again.
634
+	 *
635
+	 * @param EE_Message      $message
636
+	 * @param EE_messenger    $messenger
637
+	 * @param EE_message_type $message_type
638
+	 * @return bool true means all went well, false means, not so much.
639
+	 */
640
+	protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type)
641
+	{
642
+		try {
643
+			if ($messenger->send_message($message, $message_type)) {
644
+				$message->set_STS_ID(EEM_Message::status_sent);
645
+				return true;
646
+			} else {
647
+				$message->set_STS_ID(EEM_Message::status_retry);
648
+				return false;
649
+			}
650
+		} catch (SendMessageException $e) {
651
+			$message->set_STS_ID(EEM_Message::status_failed);
652
+			$message->set_error_message($e->getMessage());
653
+			return false;
654
+		}
655
+	}
656
+
657
+
658
+	/**
659
+	 * This sets any necessary error messages on the message object and its status to failed.
660
+	 *
661
+	 * @param EE_Message $message
662
+	 * @param array      $error_messages the response from the messenger.
663
+	 */
664
+	protected function _set_error_message(EE_Message $message, $error_messages)
665
+	{
666
+		$error_messages = (array)$error_messages;
667
+		if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
668
+			$notices          = EE_Error::has_notices();
669
+			$error_messages[] = __(
670
+				'Messenger and Message Type were valid and active, but the messenger send method failed.',
671
+				'event_espresso'
672
+			);
673
+			if ($notices === 1) {
674
+				$notices           = EE_Error::get_vanilla_notices();
675
+				$notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array();
676
+				$error_messages[]  = implode("\n", $notices['errors']);
677
+			}
678
+		}
679
+		if (count($error_messages) > 0) {
680
+			$msg = __('Message was not executed successfully.', 'event_espresso');
681
+			$msg = $msg . "\n" . implode("\n", $error_messages);
682
+			$message->set_error_message($msg);
683
+		}
684
+	}
685 685
 
686 686
 } //end EE_Messages_Queue class
687 687
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 use \EventEspresso\core\exceptions\SendMessageException;
3 3
 
4
-if (! defined('EVENT_ESPRESSO_VERSION')) {
4
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
5 5
     exit('No direct script access allowed');
6 6
 }
7 7
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             'order_by' => $this->_get_priority_orderby(),
182 182
             'limit'    => $this->_batch_count,
183 183
         );
184
-        $messages   = EEM_Message::instance()->get_all($query_args);
184
+        $messages = EEM_Message::instance()->get_all($query_args);
185 185
 
186 186
         if ( ! $messages) {
187 187
             return false; //nothing to generate
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
      */
287 287
     protected function _get_lock_key($type = EE_Messages_Queue::action_generating)
288 288
     {
289
-        return '_ee_lock_' . $type;
289
+        return '_ee_lock_'.$type;
290 290
     }
291 291
 
292 292
 
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      */
299 299
     protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating)
300 300
     {
301
-        return (int)apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
301
+        return (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type);
302 302
     }
303 303
 
304 304
 
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
      */
321 321
     protected function _get_rate_limit_expiry()
322 322
     {
323
-        return (int)apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
323
+        return (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS);
324 324
     }
325 325
 
326 326
 
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
      */
332 332
     protected function _default_rate_limit()
333 333
     {
334
-        return (int)apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
334
+        return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200);
335 335
     }
336 336
 
337 337
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
         $rate_limit = $this->get_rate_limit();
413 413
         $new_limit  = $rate_limit - $batch_completed;
414 414
         //updating the transient option directly to avoid resetting the expiry.
415
-        update_option('_transient_' . $this->_get_rate_limit_key(), $new_limit);
415
+        update_option('_transient_'.$this->_get_rate_limit_key(), $new_limit);
416 416
     }
417 417
 
418 418
 
@@ -663,7 +663,7 @@  discard block
 block discarded – undo
663 663
      */
664 664
     protected function _set_error_message(EE_Message $message, $error_messages)
665 665
     {
666
-        $error_messages = (array)$error_messages;
666
+        $error_messages = (array) $error_messages;
667 667
         if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) {
668 668
             $notices          = EE_Error::has_notices();
669 669
             $error_messages[] = __(
@@ -678,7 +678,7 @@  discard block
 block discarded – undo
678 678
         }
679 679
         if (count($error_messages) > 0) {
680 680
             $msg = __('Message was not executed successfully.', 'event_espresso');
681
-            $msg = $msg . "\n" . implode("\n", $error_messages);
681
+            $msg = $msg."\n".implode("\n", $error_messages);
682 682
             $message->set_error_message($msg);
683 683
         }
684 684
     }
Please login to merge, or discard this patch.
admin_pages/messages/EE_Message_List_Table.class.php 2 patches
Indentation   +423 added lines, -423 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 /**
@@ -15,426 +15,426 @@  discard block
 block discarded – undo
15 15
 {
16 16
 
17 17
 
18
-    /**
19
-     * @return Messages_Admin_Page
20
-     */
21
-    public function get_admin_page()
22
-    {
23
-        return $this->_admin_page;
24
-    }
25
-
26
-
27
-    protected function _setup_data()
28
-    {
29
-        $this->_data           = $this->_get_messages($this->_per_page, $this->_view);
30
-        $this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true);
31
-    }
32
-
33
-
34
-    protected function _set_properties()
35
-    {
36
-        $this->_wp_list_args = array(
37
-            'singular' => __('Message', 'event_espresso'),
38
-            'plural'   => __('Messages', 'event_espresso'),
39
-            'ajax'     => true,
40
-            'screen'   => $this->get_admin_page()->get_current_screen()->id,
41
-        );
42
-
43
-        $this->_columns = array(
44
-            'cb'           => '<input type="checkbox" />',
45
-            'to'           => __('To', 'event_espresso'),
46
-            'from'         => __('From', 'event_espresso'),
47
-            'messenger'    => __('Messenger', 'event_espresso'),
48
-            'message_type' => __('Message Type', 'event_espresso'),
49
-            'context'      => __('Context', 'event_espresso'),
50
-            'modified'     => __('Modified', 'event_espresso'),
51
-            'action'       => __('Actions', 'event_espresso'),
52
-            'msg_id'       => __('ID', 'event_espresso'),
53
-        );
54
-
55
-        $this->_sortable_columns = array(
56
-            'modified'     => array('MSG_modified' => true),
57
-            'message_type' => array('MSG_message_type' => false),
58
-            'messenger'    => array('MSG_messenger' => false),
59
-            'to'           => array('MSG_to' => false),
60
-            'from'         => array('MSG_from' => false),
61
-            'context'      => array('MSG_context' => false),
62
-            'msg_id'       => array('MSG_ID', false),
63
-        );
64
-
65
-        $this->_primary_column = 'to';
66
-
67
-        $this->_hidden_columns = array(
68
-            'msg_id',
69
-        );
70
-    }
71
-
72
-
73
-    /**
74
-     * This simply sets up the row class for the table rows.
75
-     * Allows for easier overriding of child methods for setting up sorting.
76
-     *
77
-     * @param  object $item the current item
78
-     * @return string
79
-     */
80
-    protected function _get_row_class($item)
81
-    {
82
-        $class = parent::_get_row_class($item);
83
-        //add status class
84
-        $class .= ' ee-status-strip msg-status-' . $item->STS_ID();
85
-        if ($this->_has_checkbox_column) {
86
-            $class .= ' has-checkbox-column';
87
-        }
88
-        return $class;
89
-    }
90
-
91
-
92
-    /**
93
-     * _get_table_filters
94
-     * We use this to assemble and return any filters that are associated with this table that help further refine what
95
-     * get's shown in the table.
96
-     *
97
-     * @abstract
98
-     * @access protected
99
-     * @return string
100
-     * @throws \EE_Error
101
-     */
102
-    protected function _get_table_filters()
103
-    {
104
-        $filters = array();
105
-
106
-        //get select_inputs
107
-        $select_inputs = array(
108
-            $this->_get_messengers_dropdown_filter(),
109
-            $this->_get_message_types_dropdown_filter(),
110
-            $this->_get_contexts_for_message_types_dropdown_filter(),
111
-        );
112
-
113
-        //set filters to select inputs if they aren't empty
114
-        foreach ($select_inputs as $select_input) {
115
-            if ($select_input) {
116
-                $filters[] = $select_input;
117
-            }
118
-        }
119
-        return $filters;
120
-    }
121
-
122
-
123
-    protected function _add_view_counts()
124
-    {
125
-        foreach ($this->_views as $view => $args) {
126
-            $this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true);
127
-        }
128
-    }
129
-
130
-
131
-    /**
132
-     * @param EE_Message $message
133
-     * @return string   checkbox
134
-     * @throws \EE_Error
135
-     */
136
-    public function column_cb($message)
137
-    {
138
-        return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID());
139
-    }
140
-
141
-
142
-    /**
143
-     * @param EE_Message $message
144
-     * @return string
145
-     * @throws \EE_Error
146
-     */
147
-    public function column_msg_id(EE_Message $message)
148
-    {
149
-        return $message->ID();
150
-    }
151
-
152
-
153
-    /**
154
-     * @param EE_Message $message
155
-     * @return string    The recipient of the message
156
-     * @throws \EE_Error
157
-     */
158
-    public function column_to(EE_Message $message)
159
-    {
160
-        EE_Registry::instance()->load_helper('URL');
161
-        $actions           = array();
162
-        $actions['delete'] = '<a href="'
163
-                             . EEH_URL::add_query_args_and_nonce(
164
-                array(
165
-                    'page'   => 'espresso_messages',
166
-                    'action' => 'delete_ee_message',
167
-                    'MSG_ID' => $message->ID(),
168
-                ),
169
-                admin_url('admin.php')
170
-            )
171
-                             . '">' . __('Delete', 'event_espresso') . '</a>';
172
-        return esc_html($message->to()) . $this->row_actions($actions);
173
-    }
174
-
175
-
176
-    /**
177
-     * @param EE_Message $message
178
-     * @return string   The sender of the message
179
-     */
180
-    public function column_from(EE_Message $message)
181
-    {
182
-        return esc_html($message->from());
183
-    }
184
-
185
-
186
-    /**
187
-     * @param EE_Message $message
188
-     * @return string  The messenger used to send the message.
189
-     */
190
-    public function column_messenger(EE_Message $message)
191
-    {
192
-        return ucwords($message->messenger_label());
193
-    }
194
-
195
-
196
-    /**
197
-     * @param EE_Message $message
198
-     * @return string  The message type used to generate the message.
199
-     */
200
-    public function column_message_type(EE_Message $message)
201
-    {
202
-        return ucwords($message->message_type_label());
203
-    }
204
-
205
-
206
-    /**
207
-     * @param EE_Message $message
208
-     * @return string  The context the message was generated for.
209
-     */
210
-    public function column_context(EE_Message $message)
211
-    {
212
-        return $message->context_label();
213
-    }
214
-
215
-
216
-    /**
217
-     * @param EE_Message $message
218
-     * @return string    The timestamp when this message was last modified.
219
-     */
220
-    public function column_modified(EE_Message $message)
221
-    {
222
-        return $message->modified();
223
-    }
224
-
225
-
226
-    /**
227
-     * @param EE_Message $message
228
-     * @return string   Actions that can be done on the current message.
229
-     */
230
-    public function column_action(EE_Message $message)
231
-    {
232
-        EE_Registry::instance()->load_helper('MSG_Template');
233
-        $action_links = array(
234
-            'view'                => EEH_MSG_Template::get_message_action_link('view', $message),
235
-            'error'               => EEH_MSG_Template::get_message_action_link('error', $message),
236
-            'generate_now'        => EEH_MSG_Template::get_message_action_link('generate_now', $message),
237
-            'send_now'            => EEH_MSG_Template::get_message_action_link('send_now', $message),
238
-            'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message),
239
-            'view_transaction'    => EEH_MSG_Template::get_message_action_link('view_transaction', $message),
240
-        );
241
-        $content      = '';
242
-        switch ($message->STS_ID()) {
243
-            case EEM_Message::status_sent :
244
-                $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
245
-                break;
246
-            case EEM_Message::status_resend :
247
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
248
-                break;
249
-            case EEM_Message::status_retry :
250
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
251
-                break;
252
-            case EEM_Message::status_failed :
253
-            case EEM_Message::status_debug_only :
254
-                $content = $action_links['error'] . $action_links['view_transaction'];
255
-                break;
256
-            case EEM_Message::status_idle :
257
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
258
-                break;
259
-            case EEM_Message::status_incomplete;
260
-                $content = $action_links['generate_now'] . $action_links['view_transaction'];
261
-                break;
262
-        }
263
-        return $content;
264
-    }
265
-
266
-
267
-    /**
268
-     * Retrieve the EE_Message objects for the list table.
269
-     *
270
-     * @param int    $perpage The number of items per page
271
-     * @param string $view    The view items are being retrieved for
272
-     * @param bool   $count   Whether to just return a count or not.
273
-     * @param bool   $all     Disregard any paging info (no limit on data returned).
274
-     * @return int | EE_Message[]
275
-     * @throws \EE_Error
276
-     */
277
-    protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false)
278
-    {
279
-
280
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
281
-            ? $this->_req_data['paged']
282
-            : 1;
283
-
284
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
285
-            ? $this->_req_data['perpage']
286
-            : $perpage;
287
-
288
-        $offset       = ($current_page - 1) * $per_page;
289
-        $limit        = $all || $count ? null : array($offset, $per_page);
290
-        $query_params = array(
291
-            'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'],
292
-            'order'    => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'],
293
-            'limit'    => $limit,
294
-        );
295
-
296
-        /**
297
-         * Any filters coming in from other routes?
298
-         */
299
-        if (isset($this->_req_data['filterby'])) {
300
-            $query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params());
301
-            if ( ! $count) {
302
-                $query_params['group_by'] = 'MSG_ID';
303
-            }
304
-        }
305
-
306
-        //view conditionals
307
-        if ($view !== 'all' && $count && $all) {
308
-            $query_params[0]['AND*view_conditional'] = array(
309
-                'STS_ID' => strtoupper($view),
310
-            );
311
-        }
312
-
313
-        if ( ! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
314
-            $query_params[0]['AND*view_conditional'] = array(
315
-                'STS_ID' => strtoupper($this->_req_data['status']),
316
-            );
317
-        }
318
-
319
-        if ( ! $all && ! empty($this->_req_data['s'])) {
320
-            $search_string         = '%' . $this->_req_data['s'] . '%';
321
-            $query_params[0]['OR'] = array(
322
-                'MSG_to'      => array('LIKE', $search_string),
323
-                'MSG_from'    => array('LIKE', $search_string),
324
-                'MSG_subject' => array('LIKE', $search_string),
325
-                'MSG_content' => array('LIKE', $search_string),
326
-            );
327
-        }
328
-
329
-        //account for debug only status.  We don't show Messages with the EEM_Message::status_debug_only to clients when
330
-        //the messages system is in debug mode.
331
-        //Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only
332
-        //messages in the database.
333
-        if ( ! EEM_Message::debug()) {
334
-            $query_params[0]['AND*debug_only_conditional'] = array(
335
-                'STS_ID' => array('!=', EEM_Message::status_debug_only),
336
-            );
337
-        }
338
-
339
-        //account for filters
340
-        if (
341
-            ! $all
342
-            && isset($this->_req_data['ee_messenger_filter_by'])
343
-            && $this->_req_data['ee_messenger_filter_by'] !== 'none_selected'
344
-        ) {
345
-            $query_params[0]['AND*messenger_filter'] = array(
346
-                'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'],
347
-            );
348
-        }
349
-        if (
350
-            ! $all
351
-            && ! empty($this->_req_data['ee_message_type_filter_by'])
352
-            && $this->_req_data['ee_message_type_filter_by'] !== 'none_selected'
353
-        ) {
354
-            $query_params[0]['AND*message_type_filter'] = array(
355
-                'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'],
356
-            );
357
-        }
358
-
359
-        if (
360
-            ! $all
361
-            && ! empty($this->_req_data['ee_context_filter_by'])
362
-            && $this->_req_data['ee_context_filter_by'] !== 'none_selected'
363
-        ) {
364
-            $query_params[0]['AND*context_filter'] = array(
365
-                'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])),
366
-            );
367
-        }
368
-
369
-        return $count
370
-            ? EEM_Message::instance()->count($query_params, null, true)
371
-            : EEM_Message::instance()->get_all($query_params);
372
-    }
373
-
374
-
375
-    /**
376
-     * Generate dropdown filter select input for messengers.
377
-     *
378
-     * @return string
379
-     */
380
-    protected function _get_messengers_dropdown_filter()
381
-    {
382
-        $messenger_options                    = array();
383
-        $active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
384
-
385
-        //setup array of messenger options
386
-        foreach ($active_messages_grouped_by_messenger as $active_message) {
387
-            if ($active_message instanceof EE_Message) {
388
-                $messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label());
389
-            }
390
-        }
391
-        return $this->get_admin_page()->get_messengers_select_input($messenger_options);
392
-    }
393
-
394
-
395
-    /**
396
-     * Generate dropdown filter select input for message types
397
-     *
398
-     * @return string
399
-     */
400
-    protected function _get_message_types_dropdown_filter()
401
-    {
402
-        $message_type_options                    = array();
403
-        $active_messages_grouped_by_message_type = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
404
-
405
-        //setup array of message type options
406
-        foreach ($active_messages_grouped_by_message_type as $active_message) {
407
-            if ($active_message instanceof EE_Message) {
408
-                $message_type_options[$active_message->message_type()] = ucwords($active_message->message_type_label());
409
-            }
410
-        }
411
-        return $this->get_admin_page()->get_message_types_select_input($message_type_options);
412
-    }
413
-
414
-
415
-    /**
416
-     * Generate dropdown filter select input for message type contexts
417
-     *
418
-     * @return string
419
-     */
420
-    protected function _get_contexts_for_message_types_dropdown_filter()
421
-    {
422
-        $context_options                    = array();
423
-        $active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
424
-
425
-        //setup array of context options
426
-        foreach ($active_messages_grouped_by_context as $active_message) {
427
-            if ($active_message instanceof EE_Message) {
428
-                $message_type = $active_message->message_type_object();
429
-                if ($message_type instanceof EE_message_type) {
430
-                    foreach ($message_type->get_contexts() as $context => $context_details) {
431
-                        if (isset($context_details['label'])) {
432
-                            $context_options[$context] = $context_details['label'];
433
-                        }
434
-                    }
435
-                }
436
-            }
437
-        }
438
-        return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options);
439
-    }
18
+	/**
19
+	 * @return Messages_Admin_Page
20
+	 */
21
+	public function get_admin_page()
22
+	{
23
+		return $this->_admin_page;
24
+	}
25
+
26
+
27
+	protected function _setup_data()
28
+	{
29
+		$this->_data           = $this->_get_messages($this->_per_page, $this->_view);
30
+		$this->_all_data_count = $this->_get_messages($this->_per_page, $this->_view, true);
31
+	}
32
+
33
+
34
+	protected function _set_properties()
35
+	{
36
+		$this->_wp_list_args = array(
37
+			'singular' => __('Message', 'event_espresso'),
38
+			'plural'   => __('Messages', 'event_espresso'),
39
+			'ajax'     => true,
40
+			'screen'   => $this->get_admin_page()->get_current_screen()->id,
41
+		);
42
+
43
+		$this->_columns = array(
44
+			'cb'           => '<input type="checkbox" />',
45
+			'to'           => __('To', 'event_espresso'),
46
+			'from'         => __('From', 'event_espresso'),
47
+			'messenger'    => __('Messenger', 'event_espresso'),
48
+			'message_type' => __('Message Type', 'event_espresso'),
49
+			'context'      => __('Context', 'event_espresso'),
50
+			'modified'     => __('Modified', 'event_espresso'),
51
+			'action'       => __('Actions', 'event_espresso'),
52
+			'msg_id'       => __('ID', 'event_espresso'),
53
+		);
54
+
55
+		$this->_sortable_columns = array(
56
+			'modified'     => array('MSG_modified' => true),
57
+			'message_type' => array('MSG_message_type' => false),
58
+			'messenger'    => array('MSG_messenger' => false),
59
+			'to'           => array('MSG_to' => false),
60
+			'from'         => array('MSG_from' => false),
61
+			'context'      => array('MSG_context' => false),
62
+			'msg_id'       => array('MSG_ID', false),
63
+		);
64
+
65
+		$this->_primary_column = 'to';
66
+
67
+		$this->_hidden_columns = array(
68
+			'msg_id',
69
+		);
70
+	}
71
+
72
+
73
+	/**
74
+	 * This simply sets up the row class for the table rows.
75
+	 * Allows for easier overriding of child methods for setting up sorting.
76
+	 *
77
+	 * @param  object $item the current item
78
+	 * @return string
79
+	 */
80
+	protected function _get_row_class($item)
81
+	{
82
+		$class = parent::_get_row_class($item);
83
+		//add status class
84
+		$class .= ' ee-status-strip msg-status-' . $item->STS_ID();
85
+		if ($this->_has_checkbox_column) {
86
+			$class .= ' has-checkbox-column';
87
+		}
88
+		return $class;
89
+	}
90
+
91
+
92
+	/**
93
+	 * _get_table_filters
94
+	 * We use this to assemble and return any filters that are associated with this table that help further refine what
95
+	 * get's shown in the table.
96
+	 *
97
+	 * @abstract
98
+	 * @access protected
99
+	 * @return string
100
+	 * @throws \EE_Error
101
+	 */
102
+	protected function _get_table_filters()
103
+	{
104
+		$filters = array();
105
+
106
+		//get select_inputs
107
+		$select_inputs = array(
108
+			$this->_get_messengers_dropdown_filter(),
109
+			$this->_get_message_types_dropdown_filter(),
110
+			$this->_get_contexts_for_message_types_dropdown_filter(),
111
+		);
112
+
113
+		//set filters to select inputs if they aren't empty
114
+		foreach ($select_inputs as $select_input) {
115
+			if ($select_input) {
116
+				$filters[] = $select_input;
117
+			}
118
+		}
119
+		return $filters;
120
+	}
121
+
122
+
123
+	protected function _add_view_counts()
124
+	{
125
+		foreach ($this->_views as $view => $args) {
126
+			$this->_views[$view]['count'] = $this->_get_messages($this->_per_page, $view, true, true);
127
+		}
128
+	}
129
+
130
+
131
+	/**
132
+	 * @param EE_Message $message
133
+	 * @return string   checkbox
134
+	 * @throws \EE_Error
135
+	 */
136
+	public function column_cb($message)
137
+	{
138
+		return sprintf('<input type="checkbox" name="MSG_ID[%s]" value="1" />', $message->ID());
139
+	}
140
+
141
+
142
+	/**
143
+	 * @param EE_Message $message
144
+	 * @return string
145
+	 * @throws \EE_Error
146
+	 */
147
+	public function column_msg_id(EE_Message $message)
148
+	{
149
+		return $message->ID();
150
+	}
151
+
152
+
153
+	/**
154
+	 * @param EE_Message $message
155
+	 * @return string    The recipient of the message
156
+	 * @throws \EE_Error
157
+	 */
158
+	public function column_to(EE_Message $message)
159
+	{
160
+		EE_Registry::instance()->load_helper('URL');
161
+		$actions           = array();
162
+		$actions['delete'] = '<a href="'
163
+							 . EEH_URL::add_query_args_and_nonce(
164
+				array(
165
+					'page'   => 'espresso_messages',
166
+					'action' => 'delete_ee_message',
167
+					'MSG_ID' => $message->ID(),
168
+				),
169
+				admin_url('admin.php')
170
+			)
171
+							 . '">' . __('Delete', 'event_espresso') . '</a>';
172
+		return esc_html($message->to()) . $this->row_actions($actions);
173
+	}
174
+
175
+
176
+	/**
177
+	 * @param EE_Message $message
178
+	 * @return string   The sender of the message
179
+	 */
180
+	public function column_from(EE_Message $message)
181
+	{
182
+		return esc_html($message->from());
183
+	}
184
+
185
+
186
+	/**
187
+	 * @param EE_Message $message
188
+	 * @return string  The messenger used to send the message.
189
+	 */
190
+	public function column_messenger(EE_Message $message)
191
+	{
192
+		return ucwords($message->messenger_label());
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param EE_Message $message
198
+	 * @return string  The message type used to generate the message.
199
+	 */
200
+	public function column_message_type(EE_Message $message)
201
+	{
202
+		return ucwords($message->message_type_label());
203
+	}
204
+
205
+
206
+	/**
207
+	 * @param EE_Message $message
208
+	 * @return string  The context the message was generated for.
209
+	 */
210
+	public function column_context(EE_Message $message)
211
+	{
212
+		return $message->context_label();
213
+	}
214
+
215
+
216
+	/**
217
+	 * @param EE_Message $message
218
+	 * @return string    The timestamp when this message was last modified.
219
+	 */
220
+	public function column_modified(EE_Message $message)
221
+	{
222
+		return $message->modified();
223
+	}
224
+
225
+
226
+	/**
227
+	 * @param EE_Message $message
228
+	 * @return string   Actions that can be done on the current message.
229
+	 */
230
+	public function column_action(EE_Message $message)
231
+	{
232
+		EE_Registry::instance()->load_helper('MSG_Template');
233
+		$action_links = array(
234
+			'view'                => EEH_MSG_Template::get_message_action_link('view', $message),
235
+			'error'               => EEH_MSG_Template::get_message_action_link('error', $message),
236
+			'generate_now'        => EEH_MSG_Template::get_message_action_link('generate_now', $message),
237
+			'send_now'            => EEH_MSG_Template::get_message_action_link('send_now', $message),
238
+			'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message),
239
+			'view_transaction'    => EEH_MSG_Template::get_message_action_link('view_transaction', $message),
240
+		);
241
+		$content      = '';
242
+		switch ($message->STS_ID()) {
243
+			case EEM_Message::status_sent :
244
+				$content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
245
+				break;
246
+			case EEM_Message::status_resend :
247
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
248
+				break;
249
+			case EEM_Message::status_retry :
250
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
251
+				break;
252
+			case EEM_Message::status_failed :
253
+			case EEM_Message::status_debug_only :
254
+				$content = $action_links['error'] . $action_links['view_transaction'];
255
+				break;
256
+			case EEM_Message::status_idle :
257
+				$content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
258
+				break;
259
+			case EEM_Message::status_incomplete;
260
+				$content = $action_links['generate_now'] . $action_links['view_transaction'];
261
+				break;
262
+		}
263
+		return $content;
264
+	}
265
+
266
+
267
+	/**
268
+	 * Retrieve the EE_Message objects for the list table.
269
+	 *
270
+	 * @param int    $perpage The number of items per page
271
+	 * @param string $view    The view items are being retrieved for
272
+	 * @param bool   $count   Whether to just return a count or not.
273
+	 * @param bool   $all     Disregard any paging info (no limit on data returned).
274
+	 * @return int | EE_Message[]
275
+	 * @throws \EE_Error
276
+	 */
277
+	protected function _get_messages($perpage = 10, $view = 'all', $count = false, $all = false)
278
+	{
279
+
280
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
281
+			? $this->_req_data['paged']
282
+			: 1;
283
+
284
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
285
+			? $this->_req_data['perpage']
286
+			: $perpage;
287
+
288
+		$offset       = ($current_page - 1) * $per_page;
289
+		$limit        = $all || $count ? null : array($offset, $per_page);
290
+		$query_params = array(
291
+			'order_by' => empty($this->_req_data['orderby']) ? 'MSG_modified' : $this->_req_data['orderby'],
292
+			'order'    => empty($this->_req_data['order']) ? 'DESC' : $this->_req_data['order'],
293
+			'limit'    => $limit,
294
+		);
295
+
296
+		/**
297
+		 * Any filters coming in from other routes?
298
+		 */
299
+		if (isset($this->_req_data['filterby'])) {
300
+			$query_params = array_merge($query_params, EEM_Message::instance()->filter_by_query_params());
301
+			if ( ! $count) {
302
+				$query_params['group_by'] = 'MSG_ID';
303
+			}
304
+		}
305
+
306
+		//view conditionals
307
+		if ($view !== 'all' && $count && $all) {
308
+			$query_params[0]['AND*view_conditional'] = array(
309
+				'STS_ID' => strtoupper($view),
310
+			);
311
+		}
312
+
313
+		if ( ! $all && ! empty($this->_req_data['status']) && $this->_req_data['status'] !== 'all') {
314
+			$query_params[0]['AND*view_conditional'] = array(
315
+				'STS_ID' => strtoupper($this->_req_data['status']),
316
+			);
317
+		}
318
+
319
+		if ( ! $all && ! empty($this->_req_data['s'])) {
320
+			$search_string         = '%' . $this->_req_data['s'] . '%';
321
+			$query_params[0]['OR'] = array(
322
+				'MSG_to'      => array('LIKE', $search_string),
323
+				'MSG_from'    => array('LIKE', $search_string),
324
+				'MSG_subject' => array('LIKE', $search_string),
325
+				'MSG_content' => array('LIKE', $search_string),
326
+			);
327
+		}
328
+
329
+		//account for debug only status.  We don't show Messages with the EEM_Message::status_debug_only to clients when
330
+		//the messages system is in debug mode.
331
+		//Note: for backward compat with previous iterations, this is necessary because there may be EEM_Message::status_debug_only
332
+		//messages in the database.
333
+		if ( ! EEM_Message::debug()) {
334
+			$query_params[0]['AND*debug_only_conditional'] = array(
335
+				'STS_ID' => array('!=', EEM_Message::status_debug_only),
336
+			);
337
+		}
338
+
339
+		//account for filters
340
+		if (
341
+			! $all
342
+			&& isset($this->_req_data['ee_messenger_filter_by'])
343
+			&& $this->_req_data['ee_messenger_filter_by'] !== 'none_selected'
344
+		) {
345
+			$query_params[0]['AND*messenger_filter'] = array(
346
+				'MSG_messenger' => $this->_req_data['ee_messenger_filter_by'],
347
+			);
348
+		}
349
+		if (
350
+			! $all
351
+			&& ! empty($this->_req_data['ee_message_type_filter_by'])
352
+			&& $this->_req_data['ee_message_type_filter_by'] !== 'none_selected'
353
+		) {
354
+			$query_params[0]['AND*message_type_filter'] = array(
355
+				'MSG_message_type' => $this->_req_data['ee_message_type_filter_by'],
356
+			);
357
+		}
358
+
359
+		if (
360
+			! $all
361
+			&& ! empty($this->_req_data['ee_context_filter_by'])
362
+			&& $this->_req_data['ee_context_filter_by'] !== 'none_selected'
363
+		) {
364
+			$query_params[0]['AND*context_filter'] = array(
365
+				'MSG_context' => array('IN', explode(',', $this->_req_data['ee_context_filter_by'])),
366
+			);
367
+		}
368
+
369
+		return $count
370
+			? EEM_Message::instance()->count($query_params, null, true)
371
+			: EEM_Message::instance()->get_all($query_params);
372
+	}
373
+
374
+
375
+	/**
376
+	 * Generate dropdown filter select input for messengers.
377
+	 *
378
+	 * @return string
379
+	 */
380
+	protected function _get_messengers_dropdown_filter()
381
+	{
382
+		$messenger_options                    = array();
383
+		$active_messages_grouped_by_messenger = EEM_Message::instance()->get_all(array('group_by' => 'MSG_messenger'));
384
+
385
+		//setup array of messenger options
386
+		foreach ($active_messages_grouped_by_messenger as $active_message) {
387
+			if ($active_message instanceof EE_Message) {
388
+				$messenger_options[$active_message->messenger()] = ucwords($active_message->messenger_label());
389
+			}
390
+		}
391
+		return $this->get_admin_page()->get_messengers_select_input($messenger_options);
392
+	}
393
+
394
+
395
+	/**
396
+	 * Generate dropdown filter select input for message types
397
+	 *
398
+	 * @return string
399
+	 */
400
+	protected function _get_message_types_dropdown_filter()
401
+	{
402
+		$message_type_options                    = array();
403
+		$active_messages_grouped_by_message_type = EEM_Message::instance()->get_all(array('group_by' => 'MSG_message_type'));
404
+
405
+		//setup array of message type options
406
+		foreach ($active_messages_grouped_by_message_type as $active_message) {
407
+			if ($active_message instanceof EE_Message) {
408
+				$message_type_options[$active_message->message_type()] = ucwords($active_message->message_type_label());
409
+			}
410
+		}
411
+		return $this->get_admin_page()->get_message_types_select_input($message_type_options);
412
+	}
413
+
414
+
415
+	/**
416
+	 * Generate dropdown filter select input for message type contexts
417
+	 *
418
+	 * @return string
419
+	 */
420
+	protected function _get_contexts_for_message_types_dropdown_filter()
421
+	{
422
+		$context_options                    = array();
423
+		$active_messages_grouped_by_context = EEM_Message::instance()->get_all(array('group_by' => 'MSG_context'));
424
+
425
+		//setup array of context options
426
+		foreach ($active_messages_grouped_by_context as $active_message) {
427
+			if ($active_message instanceof EE_Message) {
428
+				$message_type = $active_message->message_type_object();
429
+				if ($message_type instanceof EE_message_type) {
430
+					foreach ($message_type->get_contexts() as $context => $context_details) {
431
+						if (isset($context_details['label'])) {
432
+							$context_options[$context] = $context_details['label'];
433
+						}
434
+					}
435
+				}
436
+			}
437
+		}
438
+		return $this->get_admin_page()->get_contexts_for_message_types_select_input($context_options);
439
+	}
440 440
 } //end EE_Message_List_Table class
441 441
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('NO direct script access allowed');
4 4
 }
5 5
 
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
     {
82 82
         $class = parent::_get_row_class($item);
83 83
         //add status class
84
-        $class .= ' ee-status-strip msg-status-' . $item->STS_ID();
84
+        $class .= ' ee-status-strip msg-status-'.$item->STS_ID();
85 85
         if ($this->_has_checkbox_column) {
86 86
             $class .= ' has-checkbox-column';
87 87
         }
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
                 ),
169 169
                 admin_url('admin.php')
170 170
             )
171
-                             . '">' . __('Delete', 'event_espresso') . '</a>';
172
-        return esc_html($message->to()) . $this->row_actions($actions);
171
+                             . '">'.__('Delete', 'event_espresso').'</a>';
172
+        return esc_html($message->to()).$this->row_actions($actions);
173 173
     }
174 174
 
175 175
 
@@ -238,26 +238,26 @@  discard block
 block discarded – undo
238 238
             'queue_for_resending' => EEH_MSG_Template::get_message_action_link('queue_for_resending', $message),
239 239
             'view_transaction'    => EEH_MSG_Template::get_message_action_link('view_transaction', $message),
240 240
         );
241
-        $content      = '';
241
+        $content = '';
242 242
         switch ($message->STS_ID()) {
243 243
             case EEM_Message::status_sent :
244
-                $content = $action_links['view'] . $action_links['queue_for_resending'] . $action_links['view_transaction'];
244
+                $content = $action_links['view'].$action_links['queue_for_resending'].$action_links['view_transaction'];
245 245
                 break;
246 246
             case EEM_Message::status_resend :
247
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
247
+                $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction'];
248 248
                 break;
249 249
             case EEM_Message::status_retry :
250
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['error'] . $action_links['view_transaction'];
250
+                $content = $action_links['view'].$action_links['send_now'].$action_links['error'].$action_links['view_transaction'];
251 251
                 break;
252 252
             case EEM_Message::status_failed :
253 253
             case EEM_Message::status_debug_only :
254
-                $content = $action_links['error'] . $action_links['view_transaction'];
254
+                $content = $action_links['error'].$action_links['view_transaction'];
255 255
                 break;
256 256
             case EEM_Message::status_idle :
257
-                $content = $action_links['view'] . $action_links['send_now'] . $action_links['view_transaction'];
257
+                $content = $action_links['view'].$action_links['send_now'].$action_links['view_transaction'];
258 258
                 break;
259 259
             case EEM_Message::status_incomplete;
260
-                $content = $action_links['generate_now'] . $action_links['view_transaction'];
260
+                $content = $action_links['generate_now'].$action_links['view_transaction'];
261 261
                 break;
262 262
         }
263 263
         return $content;
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
         }
318 318
 
319 319
         if ( ! $all && ! empty($this->_req_data['s'])) {
320
-            $search_string         = '%' . $this->_req_data['s'] . '%';
320
+            $search_string         = '%'.$this->_req_data['s'].'%';
321 321
             $query_params[0]['OR'] = array(
322 322
                 'MSG_to'      => array('LIKE', $search_string),
323 323
                 'MSG_from'    => array('LIKE', $search_string),
Please login to merge, or discard this patch.
core/libraries/messages/EE_Message_Repository.lib.php 2 patches
Indentation   +249 added lines, -249 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -16,254 +16,254 @@  discard block
 block discarded – undo
16 16
 {
17 17
 
18 18
 
19
-    /**
20
-     *    EE_Message_Repository constructor
21
-     */
22
-    public function __construct()
23
-    {
24
-        $this->interface = 'EE_Message';
25
-        parent::__construct();
26
-    }
27
-
28
-
29
-    /**
30
-     * Add the EE_Message to the repository.
31
-     * This also ensures that the MSG_token is saves as a part of the info for retrieval.
32
-     *
33
-     * @param EE_Message $message
34
-     * @param mixed      $info Any included data is saved in the attached object info array indexed by 'data'
35
-     * @return bool
36
-     */
37
-    public function add($message, $info = null)
38
-    {
39
-        $attached = parent::add($message);
40
-        //ensure $info is an array if not already
41
-        $info = $info === null ? $info = array() : (array)$info;
42
-        $data = $this->_init_data($info, $attached, $message);
43
-        if ($attached) {
44
-            $this->set_info($message, $data);
45
-        }
46
-        return $attached;
47
-    }
48
-
49
-
50
-    /**
51
-     * Initializes the data from the incoming info.
52
-     *
53
-     * @param array      $info     incoming data.
54
-     * @param bool       $attached Indicates whether the object was attached successfully.
55
-     * @param EE_Message $message
56
-     * @return array
57
-     */
58
-    protected function _init_data($info, $attached, $message)
59
-    {
60
-        $data = array(
61
-            'test_send'               => false,
62
-            'preview'                 => false,
63
-            'data_handler_class_name' => '',
64
-            'data'                    => array(
65
-                'MSG_generation_data' => array(),
66
-            ),
67
-        );
68
-        if (isset($info['preview'])) {
69
-            $data['preview'] = $info['preview'];
70
-            unset($info['preview']);
71
-        }
72
-        if (isset($info['test_send'])) {
73
-            $data['test_send'] = $info['test_send'];
74
-            unset($info['test_send']);
75
-        }
76
-        if (isset($info['data_handler_class_name'])) {
77
-            $data['data_handler_class_name'] = $info['data_handler_class_name'];
78
-            unset($info['data_handler_class_name']);
79
-        }
80
-        if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) {
81
-            $generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array();
82
-            //if data isn't in $info...let's see if its available via the message object
83
-            $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data;
84
-            //still empty then let's just use info
85
-            $generation_data                     = ! $generation_data ? $info : $generation_data;
86
-            $data['data']['MSG_generation_data'] = $generation_data;
87
-        }
88
-        return $data;
89
-    }
90
-
91
-
92
-    /**
93
-     * Save all EE_Message objects to the db.
94
-     *
95
-     * @return array  array(
96
-     *                  'updated' => 0, //count of how many messages updated
97
-     *                  'notupdated' => 0, //count of how many messages not updated.
98
-     *                  'errors' => array( $token ), //array of message object tokens that had errors in saving
99
-     *                )
100
-     */
101
-    public function saveAll()
102
-    {
103
-        $this->rewind();
104
-        $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array());
105
-
106
-        //exit early if there is nothing to save.
107
-        if ( ! $this->count() > 0) {
108
-            return $save_tracking;
109
-        }
110
-
111
-        while ($this->valid()) {
112
-
113
-            $saved = $this->current()->save();
114
-            if ($saved === false) {
115
-                $save_tracking['errors'][] = $this->current()->MSG_token();
116
-            } elseif ($saved) {
117
-                $save_tracking['updated']++;
118
-            } else {
119
-                $save_tracking['notupdated']++;
120
-            }
121
-            //maybe persist generation data if this is an incomplete EE_Message.
122
-            $this->_maybe_persist_attached_data();
123
-
124
-            $this->next();
125
-        }
126
-        do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this);
127
-        return $save_tracking;
128
-    }
129
-
130
-
131
-    /**
132
-     * Retrieves a EE_Message from the repository that matches the given token.
133
-     *
134
-     * @param string $token Token.
135
-     * @return EE_Message | null
136
-     */
137
-    public function getMessageByToken($token)
138
-    {
139
-        $this->rewind();
140
-        while ($this->valid()) {
141
-            if ($this->current()->MSG_token() === $token) {
142
-                $message = $this->current();
143
-                $this->rewind();
144
-                return $message;
145
-            }
146
-            $this->next();
147
-        }
148
-        return null;
149
-    }
150
-
151
-
152
-    /**
153
-     * This retrieves any data required for generation that may be saved with the current EE_Message in storage.
154
-     *
155
-     * @return array();
156
-     */
157
-    public function get_generation_data()
158
-    {
159
-        //first verify we're at a valid iterator point.
160
-        if ( ! $this->valid()) {
161
-            return array();
162
-        }
163
-        $info = $this->getInfo();
164
-        return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array();
165
-    }
166
-
167
-
168
-    /**
169
-     * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator.
170
-     *
171
-     * @return string
172
-     */
173
-    public function get_data_handler()
174
-    {
175
-        if ( ! $this->valid()) {
176
-            return '';
177
-        }
178
-        $info = $this->getInfo();
179
-        return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : '';
180
-    }
181
-
182
-
183
-    /**
184
-     * Returns whether this EE_Message is for a preview or not.
185
-     *
186
-     * @return bool
187
-     */
188
-    public function is_preview()
189
-    {
190
-        if ( ! $this->valid()) {
191
-            return false;
192
-        }
193
-        $info = $this->getInfo();
194
-        return $info['preview'];
195
-    }
196
-
197
-
198
-    /**
199
-     * Returns whether the current message pointed to is for a test send.
200
-     *
201
-     * @return bool
202
-     */
203
-    public function is_test_send()
204
-    {
205
-        if ( ! $this->valid()) {
206
-            return false;
207
-        }
208
-        $info = $this->getInfo();
209
-        return $info['test_send'];
210
-    }
211
-
212
-
213
-    /**
214
-     *  This checks if the current EE_Message in the iterator is incomplete. If it is, then
215
-     *  data is attached for later retrieval (batch generation).
216
-     */
217
-    protected function _maybe_persist_attached_data()
218
-    {
219
-        if ( ! $this->valid()) {
220
-            return;
221
-        }
222
-
223
-        $info                    = $this->getInfo();
224
-        $data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : '';
225
-        $data                    = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array();
226
-        if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) {
227
-            $this->current()->set_generation_data($data);
228
-            $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name);
229
-        }
230
-    }
231
-
232
-
233
-    /**
234
-     * This method returns a count of messages in the repository that have a given priority.
235
-     *
236
-     * @param int   $priority the priority that is being filtered for the count.
237
-     * @param array $status   the optional status(es) that will also be filtered by when priority matches.
238
-     * @return int  count of messages in the queue matching the conditions.
239
-     */
240
-    public function count_by_priority_and_status($priority, $status = array())
241
-    {
242
-        if ( ! empty($status)) {
243
-            $status = is_array($status) ? $status : array($status);
244
-        }
245
-
246
-        $count = 0;
247
-        $this->rewind();
248
-        while ($this->valid()) {
249
-            if ($this->current()->priority() === $priority && (($status && in_array($this->current()->STS_ID(),
250
-                            $status)) || ! $status)
251
-            ) {
252
-                $count++;
253
-            }
254
-            $this->next();
255
-        }
256
-        return $count;
257
-    }
258
-
259
-
260
-    /**
261
-     * @return EE_Message
262
-     */
263
-    public function current()
264
-    {
265
-        return parent::current();
266
-    }
19
+	/**
20
+	 *    EE_Message_Repository constructor
21
+	 */
22
+	public function __construct()
23
+	{
24
+		$this->interface = 'EE_Message';
25
+		parent::__construct();
26
+	}
27
+
28
+
29
+	/**
30
+	 * Add the EE_Message to the repository.
31
+	 * This also ensures that the MSG_token is saves as a part of the info for retrieval.
32
+	 *
33
+	 * @param EE_Message $message
34
+	 * @param mixed      $info Any included data is saved in the attached object info array indexed by 'data'
35
+	 * @return bool
36
+	 */
37
+	public function add($message, $info = null)
38
+	{
39
+		$attached = parent::add($message);
40
+		//ensure $info is an array if not already
41
+		$info = $info === null ? $info = array() : (array)$info;
42
+		$data = $this->_init_data($info, $attached, $message);
43
+		if ($attached) {
44
+			$this->set_info($message, $data);
45
+		}
46
+		return $attached;
47
+	}
48
+
49
+
50
+	/**
51
+	 * Initializes the data from the incoming info.
52
+	 *
53
+	 * @param array      $info     incoming data.
54
+	 * @param bool       $attached Indicates whether the object was attached successfully.
55
+	 * @param EE_Message $message
56
+	 * @return array
57
+	 */
58
+	protected function _init_data($info, $attached, $message)
59
+	{
60
+		$data = array(
61
+			'test_send'               => false,
62
+			'preview'                 => false,
63
+			'data_handler_class_name' => '',
64
+			'data'                    => array(
65
+				'MSG_generation_data' => array(),
66
+			),
67
+		);
68
+		if (isset($info['preview'])) {
69
+			$data['preview'] = $info['preview'];
70
+			unset($info['preview']);
71
+		}
72
+		if (isset($info['test_send'])) {
73
+			$data['test_send'] = $info['test_send'];
74
+			unset($info['test_send']);
75
+		}
76
+		if (isset($info['data_handler_class_name'])) {
77
+			$data['data_handler_class_name'] = $info['data_handler_class_name'];
78
+			unset($info['data_handler_class_name']);
79
+		}
80
+		if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) {
81
+			$generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array();
82
+			//if data isn't in $info...let's see if its available via the message object
83
+			$generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data;
84
+			//still empty then let's just use info
85
+			$generation_data                     = ! $generation_data ? $info : $generation_data;
86
+			$data['data']['MSG_generation_data'] = $generation_data;
87
+		}
88
+		return $data;
89
+	}
90
+
91
+
92
+	/**
93
+	 * Save all EE_Message objects to the db.
94
+	 *
95
+	 * @return array  array(
96
+	 *                  'updated' => 0, //count of how many messages updated
97
+	 *                  'notupdated' => 0, //count of how many messages not updated.
98
+	 *                  'errors' => array( $token ), //array of message object tokens that had errors in saving
99
+	 *                )
100
+	 */
101
+	public function saveAll()
102
+	{
103
+		$this->rewind();
104
+		$save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array());
105
+
106
+		//exit early if there is nothing to save.
107
+		if ( ! $this->count() > 0) {
108
+			return $save_tracking;
109
+		}
110
+
111
+		while ($this->valid()) {
112
+
113
+			$saved = $this->current()->save();
114
+			if ($saved === false) {
115
+				$save_tracking['errors'][] = $this->current()->MSG_token();
116
+			} elseif ($saved) {
117
+				$save_tracking['updated']++;
118
+			} else {
119
+				$save_tracking['notupdated']++;
120
+			}
121
+			//maybe persist generation data if this is an incomplete EE_Message.
122
+			$this->_maybe_persist_attached_data();
123
+
124
+			$this->next();
125
+		}
126
+		do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this);
127
+		return $save_tracking;
128
+	}
129
+
130
+
131
+	/**
132
+	 * Retrieves a EE_Message from the repository that matches the given token.
133
+	 *
134
+	 * @param string $token Token.
135
+	 * @return EE_Message | null
136
+	 */
137
+	public function getMessageByToken($token)
138
+	{
139
+		$this->rewind();
140
+		while ($this->valid()) {
141
+			if ($this->current()->MSG_token() === $token) {
142
+				$message = $this->current();
143
+				$this->rewind();
144
+				return $message;
145
+			}
146
+			$this->next();
147
+		}
148
+		return null;
149
+	}
150
+
151
+
152
+	/**
153
+	 * This retrieves any data required for generation that may be saved with the current EE_Message in storage.
154
+	 *
155
+	 * @return array();
156
+	 */
157
+	public function get_generation_data()
158
+	{
159
+		//first verify we're at a valid iterator point.
160
+		if ( ! $this->valid()) {
161
+			return array();
162
+		}
163
+		$info = $this->getInfo();
164
+		return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array();
165
+	}
166
+
167
+
168
+	/**
169
+	 * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator.
170
+	 *
171
+	 * @return string
172
+	 */
173
+	public function get_data_handler()
174
+	{
175
+		if ( ! $this->valid()) {
176
+			return '';
177
+		}
178
+		$info = $this->getInfo();
179
+		return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : '';
180
+	}
181
+
182
+
183
+	/**
184
+	 * Returns whether this EE_Message is for a preview or not.
185
+	 *
186
+	 * @return bool
187
+	 */
188
+	public function is_preview()
189
+	{
190
+		if ( ! $this->valid()) {
191
+			return false;
192
+		}
193
+		$info = $this->getInfo();
194
+		return $info['preview'];
195
+	}
196
+
197
+
198
+	/**
199
+	 * Returns whether the current message pointed to is for a test send.
200
+	 *
201
+	 * @return bool
202
+	 */
203
+	public function is_test_send()
204
+	{
205
+		if ( ! $this->valid()) {
206
+			return false;
207
+		}
208
+		$info = $this->getInfo();
209
+		return $info['test_send'];
210
+	}
211
+
212
+
213
+	/**
214
+	 *  This checks if the current EE_Message in the iterator is incomplete. If it is, then
215
+	 *  data is attached for later retrieval (batch generation).
216
+	 */
217
+	protected function _maybe_persist_attached_data()
218
+	{
219
+		if ( ! $this->valid()) {
220
+			return;
221
+		}
222
+
223
+		$info                    = $this->getInfo();
224
+		$data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : '';
225
+		$data                    = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array();
226
+		if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) {
227
+			$this->current()->set_generation_data($data);
228
+			$this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name);
229
+		}
230
+	}
231
+
232
+
233
+	/**
234
+	 * This method returns a count of messages in the repository that have a given priority.
235
+	 *
236
+	 * @param int   $priority the priority that is being filtered for the count.
237
+	 * @param array $status   the optional status(es) that will also be filtered by when priority matches.
238
+	 * @return int  count of messages in the queue matching the conditions.
239
+	 */
240
+	public function count_by_priority_and_status($priority, $status = array())
241
+	{
242
+		if ( ! empty($status)) {
243
+			$status = is_array($status) ? $status : array($status);
244
+		}
245
+
246
+		$count = 0;
247
+		$this->rewind();
248
+		while ($this->valid()) {
249
+			if ($this->current()->priority() === $priority && (($status && in_array($this->current()->STS_ID(),
250
+							$status)) || ! $status)
251
+			) {
252
+				$count++;
253
+			}
254
+			$this->next();
255
+		}
256
+		return $count;
257
+	}
258
+
259
+
260
+	/**
261
+	 * @return EE_Message
262
+	 */
263
+	public function current()
264
+	{
265
+		return parent::current();
266
+	}
267 267
 
268 268
 
269 269
 }
270 270
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     {
39 39
         $attached = parent::add($message);
40 40
         //ensure $info is an array if not already
41
-        $info = $info === null ? $info = array() : (array)$info;
41
+        $info = $info === null ? $info = array() : (array) $info;
42 42
         $data = $this->_init_data($info, $attached, $message);
43 43
         if ($attached) {
44 44
             $this->set_info($message, $data);
Please login to merge, or discard this patch.
core/db_models/EEM_Status.model.php 2 patches
Indentation   +271 added lines, -271 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php if (! defined('EVENT_ESPRESSO_VERSION')) {
2
-    exit('No direct script access allowed');
2
+	exit('No direct script access allowed');
3 3
 }
4 4
 /**
5 5
  * Event Espresso
@@ -25,287 +25,287 @@  discard block
 block discarded – undo
25 25
 class EEM_Status extends EEM_Base
26 26
 {
27 27
 
28
-    // private instance of the Attendee object
29
-    protected static $_instance = null;
28
+	// private instance of the Attendee object
29
+	protected static $_instance = null;
30 30
 
31 31
 
32
-    /**
33
-     * @return EEM_Status
34
-     */
35
-    protected function __construct($timezone = null)
36
-    {
37
-        $this->singular_item    = __('Status', 'event_espresso');
38
-        $this->plural_item      = __('Stati', 'event_espresso');
39
-        $this->_tables          = array(
40
-            'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
41
-        );
42
-        $this->_fields          = array(
43
-            'StatusTable' => array(
44
-                'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
45
-                'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
46
-                'STS_type'     => new EE_Enum_Text_Field(
47
-                    'STS_type',
48
-                    __("Type", "event_espresso"),
49
-                    false,
50
-                    'event',
51
-                    array(
52
-                        'event'        => __("Event", "event_espresso"),//deprecated
53
-                        'registration' => __("Registration", "event_espresso"),
54
-                        'transaction'  => __("Transaction", "event_espresso"),
55
-                        'payment'      => __("Payment", "event_espresso"),
56
-                        'email'        => __("Email", "event_espresso"),
57
-                        'message'      => __("Message", "event_espresso"),
58
-                    )),
59
-                'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false),
60
-                'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
61
-                'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
62
-            ),
63
-        );
64
-        $this->_model_relations = array(
65
-            'Registration' => new EE_Has_Many_Relation(),
66
-            'Transaction'  => new EE_Has_Many_Relation(),
67
-            'Payment'      => new EE_Has_Many_Relation(),
68
-        );
69
-        //this model is generally available for reading
70
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
32
+	/**
33
+	 * @return EEM_Status
34
+	 */
35
+	protected function __construct($timezone = null)
36
+	{
37
+		$this->singular_item    = __('Status', 'event_espresso');
38
+		$this->plural_item      = __('Stati', 'event_espresso');
39
+		$this->_tables          = array(
40
+			'StatusTable' => new EE_Primary_Table('esp_status', 'STS_ID'),
41
+		);
42
+		$this->_fields          = array(
43
+			'StatusTable' => array(
44
+				'STS_ID'       => new EE_Primary_Key_String_Field('STS_ID', __('Status ID', 'event_espresso')),
45
+				'STS_code'     => new EE_Plain_Text_Field('STS_code', __('Status Code', 'event_espresso'), false, ''),
46
+				'STS_type'     => new EE_Enum_Text_Field(
47
+					'STS_type',
48
+					__("Type", "event_espresso"),
49
+					false,
50
+					'event',
51
+					array(
52
+						'event'        => __("Event", "event_espresso"),//deprecated
53
+						'registration' => __("Registration", "event_espresso"),
54
+						'transaction'  => __("Transaction", "event_espresso"),
55
+						'payment'      => __("Payment", "event_espresso"),
56
+						'email'        => __("Email", "event_espresso"),
57
+						'message'      => __("Message", "event_espresso"),
58
+					)),
59
+				'STS_can_edit' => new EE_Boolean_Field('STS_can_edit', __('Editable?', 'event_espresso'), false),
60
+				'STS_desc'     => new EE_Simple_HTML_Field('STS_desc', __("Description", "event_espresso"), false, ''),
61
+				'STS_open'     => new EE_Boolean_Field('STS_open', __("Open?", "event_espresso"), false, false),
62
+			),
63
+		);
64
+		$this->_model_relations = array(
65
+			'Registration' => new EE_Has_Many_Relation(),
66
+			'Transaction'  => new EE_Has_Many_Relation(),
67
+			'Payment'      => new EE_Has_Many_Relation(),
68
+		);
69
+		//this model is generally available for reading
70
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
71 71
 
72
-        parent::__construct($timezone);
73
-    }
72
+		parent::__construct($timezone);
73
+	}
74 74
 
75 75
 
76
-    /**
77
-     * This method provides the localized singular or plural string for a given status id
78
-     *
79
-     * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
80
-     *                           That way if there isn't a translation in the index we'll return the default code.
81
-     * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
82
-     *                           same as the singular (in English), however, this may NOT be the case with other
83
-     *                           languages
84
-     * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
85
-     *                           the status string returned ( UPPER, lower, Sentence)
86
-     * @throws EE_Error
87
-     * @return array             an array of translated strings for the incoming status id.
88
-     */
89
-    public function localized_status($statuses, $plural = false, $schema = 'upper')
90
-    {
91
-        //note these are all in lower case because ucwords() on upper case will NOT convert.
92
-        $translation_array = array(
93
-            EEM_Registration::status_id_pending_payment => array(
94
-                __('pending payment', 'event_espresso'), //singular
95
-                __('pending payments', 'event_espresso') //plural
96
-            ),
97
-            EEM_Registration::status_id_approved        => array(
98
-                __('approved', 'event_espresso'), //singular
99
-                __('approved', 'event_espresso') //plural
100
-            ),
101
-            EEM_Registration::status_id_not_approved    => array(
102
-                __('not approved', 'event_espresso'),
103
-                __('not approved', 'event_espresso'),
104
-            ),
105
-            EEM_Registration::status_id_cancelled       => array(
106
-                __('cancelled', 'event_espresso'),
107
-                __('cancelled', 'event_espresso'),
108
-            ),
109
-            EEM_Registration::status_id_incomplete      => array(
110
-                __('incomplete', 'event_espresso'),
111
-                __('incomplete', 'event_espresso'),
112
-            ),
113
-            EEM_Registration::status_id_declined        => array(
114
-                __('declined', 'event_espresso'),
115
-                __('declined', 'event_espresso'),
116
-            ),
117
-            EEM_Registration::status_id_wait_list       => array(
118
-                __('wait list', 'event_espresso'),
119
-                __('wait list', 'event_espresso'),
120
-            ),
121
-            EEM_Transaction::overpaid_status_code       => array(
122
-                __('overpaid', 'event_espresso'),
123
-                __('overpaid', 'event_espresso'),
124
-            ),
125
-            EEM_Transaction::complete_status_code       => array(
126
-                __('complete', 'event_espresso'),
127
-                __('complete', 'event_espresso'),
128
-            ),
129
-            EEM_Transaction::incomplete_status_code     => array(
130
-                __('incomplete', 'event_espresso'),
131
-                __('incomplete', 'event_espresso'),
132
-            ),
133
-            EEM_Transaction::failed_status_code         => array(
134
-                __('failed', 'event_espresso'),
135
-                __('failed', 'event_espresso'),
136
-            ),
137
-            EEM_Transaction::abandoned_status_code      => array(
138
-                __('abandoned', 'event_espresso'),
139
-                __('abandoned', 'event_espresso'),
140
-            ),
141
-            EEM_Payment::status_id_approved             => array(
142
-                __('accepted', 'event_espresso'),
143
-                __('accepted', 'event_espresso'),
144
-            ),
145
-            EEM_Payment::status_id_pending              => array(
146
-                __('pending', 'event_espresso'),
147
-                __('pending', 'event_espresso'),
148
-            ),
149
-            EEM_Payment::status_id_cancelled            => array(
150
-                __('cancelled', 'event_espresso'),
151
-                __('cancelled', 'event_espresso'),
152
-            ),
153
-            EEM_Payment::status_id_declined             => array(
154
-                __('declined', 'event_espresso'),
155
-                __('declined', 'event_espresso'),
156
-            ),
157
-            EEM_Payment::status_id_failed               => array(
158
-                __('failed', 'event_espresso'),
159
-                __('failed', 'event_espresso'),
160
-            ),
161
-            //following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
162
-            EEM_Event::sold_out                         => array(
163
-                __('sold out', 'event_espresso'),
164
-                __('sold out', 'event_espresso'),
165
-            ),
166
-            EEM_Event::postponed                        => array(
167
-                __('postponed', 'event_espresso'),
168
-                __('Postponed', 'event_espresso'),
169
-            ),
170
-            EEM_Event::cancelled                        => array(
171
-                __('cancelled', 'event_espresso'),
172
-                __('cancelled', 'event_espresso'),
173
-            ),
174
-            EE_Ticket::archived                         => array(
175
-                __('archived', 'event_espresso'),
176
-                __('archived', 'event_espresso'),
177
-            ),
178
-            EE_Ticket::expired                          => array(
179
-                __('expired', 'event_espresso'),
180
-                __('expired', 'event_espresso'),
181
-            ),
182
-            EE_Ticket::sold_out                         => array(
183
-                __('sold out', 'event_espresso'),
184
-                __('sold out', 'event_espresso'),
185
-            ),
186
-            EE_Ticket::pending                          => array(
187
-                __('upcoming', 'event_espresso'),
188
-                __('upcoming', 'event_espresso'),
189
-            ),
190
-            EE_Ticket::onsale                           => array(
191
-                __('on sale', 'event_espresso'),
192
-                __('on sale', 'event_espresso'),
193
-            ),
194
-            EE_Datetime::cancelled                      => array(
195
-                __('cancelled', 'event_espresso'),
196
-                __('cancelled', 'event_espresso'),
197
-            ),
198
-            EE_Datetime::sold_out                       => array(
199
-                __('sold out', 'event_espresso'),
200
-                __('sold out', 'event_espresso'),
201
-            ),
202
-            EE_Datetime::expired                        => array(
203
-                __('expired', 'event_espresso'),
204
-                __('expired', 'event_espresso'),
205
-            ),
206
-            EE_Datetime::inactive                       => array(
207
-                __('inactive', 'event_espresso'),
208
-                __('inactive', 'event_espresso'),
209
-            ),
210
-            EE_Datetime::upcoming                       => array(
211
-                __('upcoming', 'event_espresso'),
212
-                __('upcoming', 'event_espresso'),
213
-            ),
214
-            EE_Datetime::active                         => array(
215
-                __('active', 'event_espresso'),
216
-                __('active', 'event_espresso'),
217
-            ),
218
-            EE_Datetime::postponed                      => array(
219
-                __('postponed', 'event_espresso'),
220
-                __('postponed', 'event_espresso'),
221
-            ),
222
-            //messages related
223
-            EEM_Message::status_sent                    => array(
224
-                __('sent', 'event_espresso'),
225
-                __('sent', 'event_espresso'),
226
-            ),
227
-            EEM_Message::status_idle                    => array(
228
-                __('queued for sending', 'event_espresso'),
229
-                __('queued for sending', 'event_espresso'),
230
-            ),
231
-            EEM_Message::status_failed                  => array(
232
-                __('failed', 'event_espresso'),
233
-                __('failed', 'event_espresso'),
234
-            ),
235
-            EEM_Message::status_debug_only              => array(
236
-                __('debug only', 'event_espresso'),
237
-                __('debug only', 'event_espresso'),
238
-            ),
239
-            EEM_Message::status_resend                  => array(
240
-                __('queued for resending', 'event_espresso'),
241
-                __('queued for resending', 'event_espresso'),
242
-            ),
243
-            EEM_Message::status_incomplete              => array(
244
-                __('queued for generating', 'event_espresso'),
245
-                __('queued for generating', 'event_espresso'),
246
-            ),
247
-            EEM_Message::status_retry                   => array(
248
-                __('failed sending, can be retried', 'event_espresso'),
249
-                __('failed sending, can be retried', 'event_espresso'),
250
-            ),
251
-            EEM_CPT_Base::post_status_publish           => array(
252
-                __('published', 'event_espresso'),
253
-                __('published', 'event_espresso'),
254
-            ),
255
-            EEM_CPT_Base::post_status_future            => array(
256
-                __('scheduled', 'event_espresso'),
257
-                __('scheduled', 'event_espresso'),
258
-            ),
259
-            EEM_CPT_Base::post_status_draft             => array(
260
-                __('draft', 'event_espresso'),
261
-                __('draft', 'event_espresso'),
262
-            ),
263
-            EEM_CPT_Base::post_status_pending           => array(
264
-                __('pending', 'event_espresso'),
265
-                __('pending', 'event_espresso'),
266
-            ),
267
-            EEM_CPT_Base::post_status_private           => array(
268
-                __('private', 'event_espresso'),
269
-                __('private', 'event_espresso'),
270
-            ),
271
-            EEM_CPT_Base::post_status_trashed           => array(
272
-                __('trashed', 'event_espresso'),
273
-                __('trashed', 'event_espresso'),
274
-            ),
275
-        );
76
+	/**
77
+	 * This method provides the localized singular or plural string for a given status id
78
+	 *
79
+	 * @param  array   $statuses This should be an array of statuses in the format array( $status_id, $status_code ).
80
+	 *                           That way if there isn't a translation in the index we'll return the default code.
81
+	 * @param  boolean $plural   Whether to return plural string or not. Note, nearly all of the plural strings are the
82
+	 *                           same as the singular (in English), however, this may NOT be the case with other
83
+	 *                           languages
84
+	 * @param  string  $schema   This can be either 'upper', 'lower', or 'sentence'.  Basically indicates how we want
85
+	 *                           the status string returned ( UPPER, lower, Sentence)
86
+	 * @throws EE_Error
87
+	 * @return array             an array of translated strings for the incoming status id.
88
+	 */
89
+	public function localized_status($statuses, $plural = false, $schema = 'upper')
90
+	{
91
+		//note these are all in lower case because ucwords() on upper case will NOT convert.
92
+		$translation_array = array(
93
+			EEM_Registration::status_id_pending_payment => array(
94
+				__('pending payment', 'event_espresso'), //singular
95
+				__('pending payments', 'event_espresso') //plural
96
+			),
97
+			EEM_Registration::status_id_approved        => array(
98
+				__('approved', 'event_espresso'), //singular
99
+				__('approved', 'event_espresso') //plural
100
+			),
101
+			EEM_Registration::status_id_not_approved    => array(
102
+				__('not approved', 'event_espresso'),
103
+				__('not approved', 'event_espresso'),
104
+			),
105
+			EEM_Registration::status_id_cancelled       => array(
106
+				__('cancelled', 'event_espresso'),
107
+				__('cancelled', 'event_espresso'),
108
+			),
109
+			EEM_Registration::status_id_incomplete      => array(
110
+				__('incomplete', 'event_espresso'),
111
+				__('incomplete', 'event_espresso'),
112
+			),
113
+			EEM_Registration::status_id_declined        => array(
114
+				__('declined', 'event_espresso'),
115
+				__('declined', 'event_espresso'),
116
+			),
117
+			EEM_Registration::status_id_wait_list       => array(
118
+				__('wait list', 'event_espresso'),
119
+				__('wait list', 'event_espresso'),
120
+			),
121
+			EEM_Transaction::overpaid_status_code       => array(
122
+				__('overpaid', 'event_espresso'),
123
+				__('overpaid', 'event_espresso'),
124
+			),
125
+			EEM_Transaction::complete_status_code       => array(
126
+				__('complete', 'event_espresso'),
127
+				__('complete', 'event_espresso'),
128
+			),
129
+			EEM_Transaction::incomplete_status_code     => array(
130
+				__('incomplete', 'event_espresso'),
131
+				__('incomplete', 'event_espresso'),
132
+			),
133
+			EEM_Transaction::failed_status_code         => array(
134
+				__('failed', 'event_espresso'),
135
+				__('failed', 'event_espresso'),
136
+			),
137
+			EEM_Transaction::abandoned_status_code      => array(
138
+				__('abandoned', 'event_espresso'),
139
+				__('abandoned', 'event_espresso'),
140
+			),
141
+			EEM_Payment::status_id_approved             => array(
142
+				__('accepted', 'event_espresso'),
143
+				__('accepted', 'event_espresso'),
144
+			),
145
+			EEM_Payment::status_id_pending              => array(
146
+				__('pending', 'event_espresso'),
147
+				__('pending', 'event_espresso'),
148
+			),
149
+			EEM_Payment::status_id_cancelled            => array(
150
+				__('cancelled', 'event_espresso'),
151
+				__('cancelled', 'event_espresso'),
152
+			),
153
+			EEM_Payment::status_id_declined             => array(
154
+				__('declined', 'event_espresso'),
155
+				__('declined', 'event_espresso'),
156
+			),
157
+			EEM_Payment::status_id_failed               => array(
158
+				__('failed', 'event_espresso'),
159
+				__('failed', 'event_espresso'),
160
+			),
161
+			//following statuses are NOT part of the EEM_Status but to keep things centralized we include in here.
162
+			EEM_Event::sold_out                         => array(
163
+				__('sold out', 'event_espresso'),
164
+				__('sold out', 'event_espresso'),
165
+			),
166
+			EEM_Event::postponed                        => array(
167
+				__('postponed', 'event_espresso'),
168
+				__('Postponed', 'event_espresso'),
169
+			),
170
+			EEM_Event::cancelled                        => array(
171
+				__('cancelled', 'event_espresso'),
172
+				__('cancelled', 'event_espresso'),
173
+			),
174
+			EE_Ticket::archived                         => array(
175
+				__('archived', 'event_espresso'),
176
+				__('archived', 'event_espresso'),
177
+			),
178
+			EE_Ticket::expired                          => array(
179
+				__('expired', 'event_espresso'),
180
+				__('expired', 'event_espresso'),
181
+			),
182
+			EE_Ticket::sold_out                         => array(
183
+				__('sold out', 'event_espresso'),
184
+				__('sold out', 'event_espresso'),
185
+			),
186
+			EE_Ticket::pending                          => array(
187
+				__('upcoming', 'event_espresso'),
188
+				__('upcoming', 'event_espresso'),
189
+			),
190
+			EE_Ticket::onsale                           => array(
191
+				__('on sale', 'event_espresso'),
192
+				__('on sale', 'event_espresso'),
193
+			),
194
+			EE_Datetime::cancelled                      => array(
195
+				__('cancelled', 'event_espresso'),
196
+				__('cancelled', 'event_espresso'),
197
+			),
198
+			EE_Datetime::sold_out                       => array(
199
+				__('sold out', 'event_espresso'),
200
+				__('sold out', 'event_espresso'),
201
+			),
202
+			EE_Datetime::expired                        => array(
203
+				__('expired', 'event_espresso'),
204
+				__('expired', 'event_espresso'),
205
+			),
206
+			EE_Datetime::inactive                       => array(
207
+				__('inactive', 'event_espresso'),
208
+				__('inactive', 'event_espresso'),
209
+			),
210
+			EE_Datetime::upcoming                       => array(
211
+				__('upcoming', 'event_espresso'),
212
+				__('upcoming', 'event_espresso'),
213
+			),
214
+			EE_Datetime::active                         => array(
215
+				__('active', 'event_espresso'),
216
+				__('active', 'event_espresso'),
217
+			),
218
+			EE_Datetime::postponed                      => array(
219
+				__('postponed', 'event_espresso'),
220
+				__('postponed', 'event_espresso'),
221
+			),
222
+			//messages related
223
+			EEM_Message::status_sent                    => array(
224
+				__('sent', 'event_espresso'),
225
+				__('sent', 'event_espresso'),
226
+			),
227
+			EEM_Message::status_idle                    => array(
228
+				__('queued for sending', 'event_espresso'),
229
+				__('queued for sending', 'event_espresso'),
230
+			),
231
+			EEM_Message::status_failed                  => array(
232
+				__('failed', 'event_espresso'),
233
+				__('failed', 'event_espresso'),
234
+			),
235
+			EEM_Message::status_debug_only              => array(
236
+				__('debug only', 'event_espresso'),
237
+				__('debug only', 'event_espresso'),
238
+			),
239
+			EEM_Message::status_resend                  => array(
240
+				__('queued for resending', 'event_espresso'),
241
+				__('queued for resending', 'event_espresso'),
242
+			),
243
+			EEM_Message::status_incomplete              => array(
244
+				__('queued for generating', 'event_espresso'),
245
+				__('queued for generating', 'event_espresso'),
246
+			),
247
+			EEM_Message::status_retry                   => array(
248
+				__('failed sending, can be retried', 'event_espresso'),
249
+				__('failed sending, can be retried', 'event_espresso'),
250
+			),
251
+			EEM_CPT_Base::post_status_publish           => array(
252
+				__('published', 'event_espresso'),
253
+				__('published', 'event_espresso'),
254
+			),
255
+			EEM_CPT_Base::post_status_future            => array(
256
+				__('scheduled', 'event_espresso'),
257
+				__('scheduled', 'event_espresso'),
258
+			),
259
+			EEM_CPT_Base::post_status_draft             => array(
260
+				__('draft', 'event_espresso'),
261
+				__('draft', 'event_espresso'),
262
+			),
263
+			EEM_CPT_Base::post_status_pending           => array(
264
+				__('pending', 'event_espresso'),
265
+				__('pending', 'event_espresso'),
266
+			),
267
+			EEM_CPT_Base::post_status_private           => array(
268
+				__('private', 'event_espresso'),
269
+				__('private', 'event_espresso'),
270
+			),
271
+			EEM_CPT_Base::post_status_trashed           => array(
272
+				__('trashed', 'event_espresso'),
273
+				__('trashed', 'event_espresso'),
274
+			),
275
+		);
276 276
 
277
-        $translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
277
+		$translation_array = apply_filters('FHEE__EEM_Status__localized_status__translation_array', $translation_array);
278 278
 
279
-        if ( ! is_array($statuses)) {
280
-            throw new EE_Error(__('The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
281
-                'event_espresso'));
282
-        }
279
+		if ( ! is_array($statuses)) {
280
+			throw new EE_Error(__('The incoming statuses argument must be an array with keys as the $status_id and values as the $status_code',
281
+				'event_espresso'));
282
+		}
283 283
 
284
-        $translation = array();
284
+		$translation = array();
285 285
 
286
-        foreach ($statuses as $id => $code) {
287
-            if (isset($translation_array[$id])) {
288
-                $translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0];
289
-            } else {
290
-                $translation[$id] = $code;
291
-            }
286
+		foreach ($statuses as $id => $code) {
287
+			if (isset($translation_array[$id])) {
288
+				$translation[$id] = $plural ? $translation_array[$id][1] : $translation_array[$id][0];
289
+			} else {
290
+				$translation[$id] = $code;
291
+			}
292 292
 
293
-            //schema
294
-            switch ($schema) {
295
-                case 'lower' :
296
-                    $translation[$id] = strtolower($translation[$id]); //even though these start in lower case, this will catch any statuses added via filter.
297
-                    break;
298
-                case 'sentence' :
299
-                    $translation[$id] = ucwords($translation[$id]);
300
-                    break;
301
-                case 'upper' :
302
-                    $translation[$id] = strtoupper($translation[$id]);
303
-                    break;
304
-            }
305
-        }
293
+			//schema
294
+			switch ($schema) {
295
+				case 'lower' :
296
+					$translation[$id] = strtolower($translation[$id]); //even though these start in lower case, this will catch any statuses added via filter.
297
+					break;
298
+				case 'sentence' :
299
+					$translation[$id] = ucwords($translation[$id]);
300
+					break;
301
+				case 'upper' :
302
+					$translation[$id] = strtoupper($translation[$id]);
303
+					break;
304
+			}
305
+		}
306 306
 
307
-        return $translation;
308
-    }
307
+		return $translation;
308
+	}
309 309
 
310 310
 
311 311
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@  discard block
 block discarded – undo
1
-<?php if (! defined('EVENT_ESPRESSO_VERSION')) {
1
+<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) {
2 2
     exit('No direct script access allowed');
3 3
 }
4 4
 /**
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @ version            4.0
13 13
  * ------------------------------------------------------------------------
14 14
  */
15
-require_once(EE_MODELS . 'EEM_Base.model.php');
15
+require_once(EE_MODELS.'EEM_Base.model.php');
16 16
 
17 17
 /**
18 18
  * Class EEM_Status
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
                     false,
50 50
                     'event',
51 51
                     array(
52
-                        'event'        => __("Event", "event_espresso"),//deprecated
52
+                        'event'        => __("Event", "event_espresso"), //deprecated
53 53
                         'registration' => __("Registration", "event_espresso"),
54 54
                         'transaction'  => __("Transaction", "event_espresso"),
55 55
                         'payment'      => __("Payment", "event_espresso"),
Please login to merge, or discard this patch.