Completed
Branch fix/remove-help-tours-registra... (89b174)
by
unknown
05:04 queued 02:22
created
admin_pages/registration_form/Registration_Form_Admin_Page.core.php 1 patch
Indentation   +764 added lines, -764 removed lines patch added patch discarded remove patch
@@ -16,707 +16,707 @@  discard block
 block discarded – undo
16 16
 class Registration_Form_Admin_Page extends EE_Admin_Page
17 17
 {
18 18
 
19
-    /**
20
-     * holds the specific question object for the question details screen
21
-     *
22
-     * @var EE_Question $_question
23
-     */
24
-    protected $_question;
25
-
26
-    /**
27
-     * holds the specific question group object for the question group details screen
28
-     *
29
-     * @var EE_Question_Group $_question_group
30
-     */
31
-    protected $_question_group;
32
-
33
-    /**
34
-     *_question_model EEM_Question model instance (for queries)
35
-     *
36
-     * @var EEM_Question $_question_model ;
37
-     */
38
-    protected $_question_model;
39
-
40
-    /**
41
-     * _question_group_model EEM_Question_group instance (for queries)
42
-     *
43
-     * @var EEM_Question_Group $_question_group_model
44
-     */
45
-    protected $_question_group_model;
46
-
47
-
48
-    /**
49
-     * @Constructor
50
-     * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
51
-     * @throws EE_Error
52
-     * @throws ReflectionException
53
-     */
54
-    public function __construct($routing = true)
55
-    {
56
-        require_once(EE_MODELS . 'EEM_Question.model.php');
57
-        require_once(EE_MODELS . 'EEM_Question_Group.model.php');
58
-        $this->_question_model       = EEM_Question::instance();
59
-        $this->_question_group_model = EEM_Question_Group::instance();
60
-        parent::__construct($routing);
61
-    }
62
-
63
-
64
-    protected function _init_page_props()
65
-    {
66
-        $this->page_slug        = REGISTRATION_FORM_PG_SLUG;
67
-        $this->page_label       = esc_html__('Registration Form', 'event_espresso');
68
-        $this->_admin_base_url  = REGISTRATION_FORM_ADMIN_URL;
69
-        $this->_admin_base_path = REGISTRATION_FORM_ADMIN;
70
-    }
71
-
72
-
73
-    protected function _ajax_hooks()
74
-    {
75
-    }
76
-
77
-
78
-    protected function _define_page_props()
79
-    {
80
-        $this->_admin_page_title = esc_html__('Registration Form', 'event_espresso');
81
-        $this->_labels           = [
82
-            'buttons' => [
83
-                'edit_question' => esc_html__('Edit Question', 'event_espresso'),
84
-            ],
85
-        ];
86
-    }
87
-
88
-
89
-    /**
90
-     *_set_page_routes
91
-     */
92
-    protected function _set_page_routes()
93
-    {
94
-        $qst_id             =
95
-            ! empty($this->_req_data['QST_ID'])
96
-                ? $this->_req_data['QST_ID']
97
-                : 0;
98
-        $this->_page_routes = [
99
-            'default' => [
100
-                'func'       => '_questions_overview_list_table',
101
-                'capability' => 'ee_read_questions',
102
-            ],
103
-
104
-            'edit_question' => [
105
-                'func'       => '_edit_question',
106
-                'capability' => 'ee_edit_question',
107
-                'obj_id'     => $qst_id,
108
-                'args'       => ['edit'],
109
-            ],
110
-
111
-            'question_groups' => [
112
-                'func'       => '_questions_groups_preview',
113
-                'capability' => 'ee_read_question_groups',
114
-            ],
115
-
116
-            'update_question' => [
117
-                'func'       => '_insert_or_update_question',
118
-                'args'       => ['new_question' => false],
119
-                'capability' => 'ee_edit_question',
120
-                'obj_id'     => $qst_id,
121
-                'noheader'   => true,
122
-            ],
123
-        ];
124
-    }
125
-
126
-
127
-    protected function _set_page_config()
128
-    {
129
-        $this->_page_config = [
130
-            'default' => [
131
-                'nav'           => [
132
-                    'label' => esc_html__('Questions', 'event_espresso'),
133
-                    'order' => 10,
134
-                ],
135
-                'list_table'    => 'Registration_Form_Questions_Admin_List_Table',
136
-                'metaboxes'     => $this->_default_espresso_metaboxes,
137
-                'help_tabs'     => [
138
-                    'registration_form_questions_overview_help_tab'                           => [
139
-                        'title'    => esc_html__('Questions Overview', 'event_espresso'),
140
-                        'filename' => 'registration_form_questions_overview',
141
-                    ],
142
-                    'registration_form_questions_overview_table_column_headings_help_tab'     => [
143
-                        'title'    => esc_html__('Questions Overview Table Column Headings', 'event_espresso'),
144
-                        'filename' => 'registration_form_questions_overview_table_column_headings',
145
-                    ],
146
-                    'registration_form_questions_overview_views_bulk_actions_search_help_tab' => [
147
-                        'title'    => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'),
148
-                        'filename' => 'registration_form_questions_overview_views_bulk_actions_search',
149
-                    ],
150
-                ],
151
-                'require_nonce' => false,
152
-                'qtips'         => [
153
-                    'EE_Registration_Form_Tips',
154
-                ]/**/
155
-            ],
156
-
157
-            'question_groups' => [
158
-                'nav'           => [
159
-                    'label' => esc_html__('Question Groups', 'event_espresso'),
160
-                    'order' => 20,
161
-                ],
162
-                'metaboxes'     => $this->_default_espresso_metaboxes,
163
-                'help_tabs'     => [
164
-                    'registration_form_question_groups_help_tab' => [
165
-                        'title'    => esc_html__('Question Groups', 'event_espresso'),
166
-                        'filename' => 'registration_form_question_groups',
167
-                    ],
168
-                ],
169
-                'require_nonce' => false,
170
-            ],
171
-
172
-            'edit_question' => [
173
-                'nav'           => [
174
-                    'label'      => esc_html__('Edit Question', 'event_espresso'),
175
-                    'order'      => 15,
176
-                    'persistent' => false,
177
-                    'url'        => isset($this->_req_data['question_id'])
178
-                        ? add_query_arg(
179
-                            ['question_id' => $this->_req_data['question_id']],
180
-                            $this->_current_page_view_url
181
-                        )
182
-                        : $this->_admin_base_url,
183
-                ],
184
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
185
-                'help_tabs'     => [
186
-                    'registration_form_edit_question_group_help_tab' => [
187
-                        'title'    => esc_html__('Edit Question', 'event_espresso'),
188
-                        'filename' => 'registration_form_edit_question',
189
-                    ],
190
-                ],
191
-                'require_nonce' => false,
192
-            ],
193
-        ];
194
-    }
195
-
196
-
197
-    protected function _add_screen_options()
198
-    {
199
-        // todo
200
-    }
201
-
202
-
203
-    protected function _add_screen_options_default()
204
-    {
205
-        $page_title              = $this->_admin_page_title;
206
-        $this->_admin_page_title = esc_html__('Questions', 'event_espresso');
207
-        $this->_per_page_screen_option();
208
-        $this->_admin_page_title = $page_title;
209
-    }
210
-
211
-
212
-    protected function _add_screen_options_question_groups()
213
-    {
214
-        $page_title              = $this->_admin_page_title;
215
-        $this->_admin_page_title = esc_html__('Question Groups', 'event_espresso');
216
-        $this->_per_page_screen_option();
217
-        $this->_admin_page_title = $page_title;
218
-    }
219
-
220
-
221
-    // none of the below group are currently used for Event Categories
222
-    protected function _add_feature_pointers()
223
-    {
224
-    }
225
-
226
-
227
-    public function load_scripts_styles()
228
-    {
229
-        wp_register_style(
230
-            'espresso_registration',
231
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css',
232
-            [],
233
-            EVENT_ESPRESSO_VERSION
234
-        );
235
-        wp_enqueue_style('espresso_registration');
236
-    }
237
-
238
-
239
-    public function admin_init()
240
-    {
241
-    }
242
-
243
-
244
-    public function admin_notices()
245
-    {
246
-    }
247
-
248
-
249
-    public function admin_footer_scripts()
250
-    {
251
-    }
252
-
253
-
254
-    public function load_scripts_styles_default()
255
-    {
256
-    }
257
-
258
-
259
-    /**
260
-     * @throws EE_Error
261
-     */
262
-    public function load_scripts_styles_add_question()
263
-    {
264
-        $this->load_scripts_styles_question_details();
265
-    }
266
-
267
-
268
-    /**
269
-     * @throws EE_Error
270
-     */
271
-    public function load_scripts_styles_edit_question()
272
-    {
273
-        $this->load_scripts_styles_question_details();
274
-    }
275
-
276
-
277
-    /**
278
-     * Loads the JS required for adding or editing a question
279
-     *
280
-     * @throws EE_Error
281
-     * @throws EE_Error
282
-     */
283
-    protected function load_scripts_styles_question_details()
284
-    {
285
-        $this->load_scripts_styles_forms();
286
-        wp_register_script(
287
-            'espresso_registration_form_single',
288
-            REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js',
289
-            ['jquery-ui-sortable'],
290
-            EVENT_ESPRESSO_VERSION,
291
-            true
292
-        );
293
-        wp_enqueue_script('espresso_registration_form_single');
294
-        wp_localize_script(
295
-            'espresso_registration_form_single',
296
-            'ee_question_data',
297
-            [
298
-                'question_types_with_max'    => EEM_Question::instance()->questionTypesWithMaxLength(),
299
-                'question_type_with_options' => EEM_Question::instance()->question_types_with_options(),
300
-            ]
301
-        );
302
-    }
303
-
304
-
305
-    public function recaptcha_info_help_tab()
306
-    {
307
-        $template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
308
-        EEH_Template::display_template($template, []);
309
-    }
310
-
311
-
312
-    public function load_scripts_styles_forms()
313
-    {
314
-        // styles
315
-        wp_enqueue_style('espresso-ui-theme');
316
-        // scripts
317
-        wp_enqueue_script('ee_admin_js');
318
-    }
319
-
320
-
321
-    protected function _set_list_table_views_default()
322
-    {
323
-        $this->_views = [
324
-            'all' => [
325
-                'slug'  => 'all',
326
-                'label' => esc_html__('View All Questions', 'event_espresso'),
327
-                'count' => 0,
328
-            ],
329
-        ];
330
-
331
-        if (
332
-            EE_Registry::instance()->CAP->current_user_can(
333
-                'ee_delete_questions',
334
-                'espresso_registration_form_trash_questions'
335
-            )
336
-        ) {
337
-            $this->_views['trash'] = [
338
-                'slug'  => 'trash',
339
-                'label' => esc_html__('Trash', 'event_espresso'),
340
-                'count' => 0,
341
-            ];
342
-        }
343
-    }
344
-
345
-
346
-    /**
347
-     * This just previews the question groups tab that comes in caffeinated.
348
-     *
349
-     * @return void html
350
-     * @throws EE_Error
351
-     */
352
-    protected function _questions_groups_preview()
353
-    {
354
-        $this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
355
-        $this->_template_args['preview_img']  =
356
-            '<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="'
357
-            . esc_attr__(
358
-                'Preview Question Groups Overview List Table screenshot',
359
-                'event_espresso'
360
-            ) . '" />';
361
-        $this->_template_args['preview_text'] = '<strong>'
362
-                                                . esc_html__(
363
-                                                    'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
364
-                                                    'event_espresso'
365
-                                                ) . '</strong>';
366
-        $this->display_admin_caf_preview_page('question_groups_tab');
367
-    }
368
-
369
-
370
-    /**
371
-     * Extracts the question field's values from the POST request to update or insert them
372
-     *
373
-     * @param EEM_Base $model
374
-     * @return array where each key is the name of a model's field/db column, and each value is its value.
375
-     * @throws EE_Error
376
-     */
377
-    protected function _set_column_values_for(EEM_Base $model)
378
-    {
379
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
380
-        $set_column_values = [];
381
-
382
-        // some initial checks for proper values.
383
-        // if QST_admin_only, then no matter what QST_required is we disable.
384
-        if (! empty($this->_req_data['QST_admin_only'])) {
385
-            $this->_req_data['QST_required'] = 0;
386
-        }
387
-        // if the question shouldn't have a max length, don't let them set one
388
-        if (
389
-            ! isset(
390
-                $this->_req_data['QST_type'],
391
-                $this->_req_data['QST_max']
392
-            )
393
-            || ! in_array(
394
-                $this->_req_data['QST_type'],
395
-                EEM_Question::instance()->questionTypesWithMaxLength(),
396
-                true
397
-            )
398
-        ) {
399
-            // they're not allowed to set the max
400
-            $this->_req_data['QST_max'] = null;
401
-        }
402
-        foreach ($model->field_settings() as $fieldName => $settings) {
403
-            // basically if QSG_identifier is empty or not set
404
-            if (
405
-                $fieldName === 'QSG_identifier'
406
-                && (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))
407
-            ) {
408
-                $QSG_name = isset($this->_req_data['QSG_name'])
409
-                    ? $this->_req_data['QSG_name']
410
-                    : '';
411
-                $set_column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true);
412
-            } elseif (
413
-                $fieldName === 'QST_admin_label'
414
-                && (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))
415
-            ) {
416
-                // the admin label is blank, use a slug version of the question text
417
-                $QST_text                        =
418
-                    isset($this->_req_data['QST_display_text'])
419
-                        ? $this->_req_data['QST_display_text']
420
-                        : '';
421
-                $set_column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10));
422
-            } elseif ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
423
-                $set_column_values[ $fieldName ] = 0;
424
-            } elseif ($fieldName === 'QST_max') {
425
-                $qst_system = EEM_Question::instance()->get_var(
426
-                    [
427
-                        [
428
-                            'QST_ID' => isset($this->_req_data['QST_ID'])
429
-                                ? $this->_req_data['QST_ID']
430
-                                : 0,
431
-                        ],
432
-                    ],
433
-                    'QST_system'
434
-                );
435
-                $max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
436
-                if (
437
-                    empty($this->_req_data['QST_max']) || $this->_req_data['QST_max'] > $max_max
438
-                ) {
439
-                    $set_column_values[ $fieldName ] = $max_max;
440
-                }
441
-            }
442
-
443
-
444
-            // only add a property to the array if it's not null (otherwise the model should just use the default value)
445
-            if (
446
-                ! isset($set_column_values[ $fieldName ]) && isset($this->_req_data[ $fieldName ])
447
-            ) {
448
-                $set_column_values[ $fieldName ] = $this->_req_data[ $fieldName ];
449
-            }
450
-        }
451
-        return $set_column_values;// validation fo this data to be performed by the model before insertion.
452
-    }
453
-
454
-
455
-    /**
456
-     *_questions_overview_list_table
457
-     *
458
-     * @throws EE_Error
459
-     */
460
-    protected function _questions_overview_list_table()
461
-    {
462
-        $this->_search_btn_label = esc_html__('Questions', 'event_espresso');
463
-        $this->display_admin_list_table_page_with_sidebar();
464
-    }
465
-
466
-
467
-    /**
468
-     * _edit_question
469
-     *
470
-     * @throws EE_Error
471
-     * @throws ReflectionException
472
-     */
473
-    protected function _edit_question()
474
-    {
475
-        $ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID'])
476
-            ? absint($this->_req_data['QST_ID'])
477
-            : false;
478
-
479
-        switch ($this->_req_action) {
480
-            case 'add_question':
481
-                $this->_admin_page_title = esc_html__('Add Question', 'event_espresso');
482
-                break;
483
-            case 'edit_question':
484
-                $this->_admin_page_title = esc_html__('Edit Question', 'event_espresso');
485
-                break;
486
-            default:
487
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
488
-        }
489
-
490
-        // add PRC_ID to title if editing
491
-        $this->_admin_page_title =
492
-            $ID
493
-                ? $this->_admin_page_title . ' # ' . $ID
494
-                : $this->_admin_page_title;
495
-        if ($ID) {
496
-            $question                 = $this->_question_model->get_one_by_ID($ID);
497
-            $additional_hidden_fields = ['QST_ID' => ['type' => 'hidden', 'value' => $ID]];
498
-            $this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
499
-        } else {
500
-            $question = EE_Question::new_instance();
501
-            $question->set_order_to_latest();
502
-            $this->_set_add_edit_form_tags('insert_question');
503
-        }
504
-        if ($question->system_ID() === EEM_Attendee::system_question_phone) {
505
-            $question_types = array_intersect_key(
506
-                EEM_Question::instance()->allowed_question_types(),
507
-                array_flip(
508
-                    [
509
-                        EEM_Question::QST_type_text,
510
-                        EEM_Question::QST_type_us_phone,
511
-                    ]
512
-                )
513
-            );
514
-        } else {
515
-            $question_types = $question->has_answers()
516
-                ? $this->_question_model->question_types_in_same_category($question->type())
517
-                : $this->_question_model->allowed_question_types();
518
-        }
519
-        $this->_template_args['QST_ID']                     = $ID;
520
-        $this->_template_args['question']                   = $question;
521
-        $this->_template_args['question_types']             = $question_types;
522
-        $this->_template_args['max_max']                    =
523
-            EEM_Question::instance()->absolute_max_for_system_question(
524
-                $question->system_ID()
525
-            );
526
-        $this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
527
-        $this->_set_publish_post_box_vars('id', $ID);
528
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
529
-            REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
530
-            $this->_template_args,
531
-            true
532
-        );
533
-
534
-        // the details template wrapper
535
-        $this->display_admin_page_with_sidebar();
536
-    }
537
-
538
-
539
-    /**
540
-     * @return string
541
-     * @throws EE_Error
542
-     * @throws ReflectionException
543
-     */
544
-    protected function _get_question_type_descriptions()
545
-    {
546
-        EE_Registry::instance()->load_helper('HTML');
547
-        $descriptions               = '';
548
-        $question_type_descriptions = EEM_Question::instance()->question_descriptions();
549
-        foreach ($question_type_descriptions as $type => $question_type_description) {
550
-            if ($type == 'HTML_TEXTAREA') {
551
-                $html                      = new EE_Simple_HTML_Validation_Strategy();
552
-                $question_type_description .= sprintf(
553
-                    esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'),
554
-                    '<br/>',
555
-                    $html->get_list_of_allowed_tags()
556
-                );
557
-            }
558
-            $descriptions .= EEH_HTML::p(
559
-                $question_type_description,
560
-                'question_type_description-' . $type,
561
-                'question_type_description description',
562
-                'display:none;'
563
-            );
564
-        }
565
-        return $descriptions;
566
-    }
567
-
568
-
569
-    /**
570
-     * @param bool|true $new_question
571
-     * @throws EE_Error
572
-     * @throws ReflectionException
573
-     */
574
-    protected function _insert_or_update_question($new_question = true)
575
-    {
576
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
577
-        $set_column_values = $this->_set_column_values_for($this->_question_model);
578
-        if ($new_question) {
579
-            $question    = EE_Question::new_instance($set_column_values);
580
-            $action_desc = 'added';
581
-        } else {
582
-            $question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID']));
583
-            foreach ($set_column_values as $field => $new_value) {
584
-                $question->set($field, $new_value);
585
-            }
586
-            $action_desc = 'updated';
587
-        }
588
-        $success = $question->save();
589
-        $ID      = $question->ID();
590
-        if ($ID && $question->should_have_question_options()) {
591
-            // save the related options
592
-            // trash removed options, save old ones
593
-            // get list of all options
594
-            $options = $question->options();
595
-            if (! empty($options)) {
596
-                foreach ($options as $option_ID => $option) {
597
-                    $option_req_index = $this->_get_option_req_data_index($option_ID);
598
-                    if ($option_req_index !== false) {
599
-                        $option->save($this->_req_data['question_options'][ $option_req_index ]);
600
-                    } else {
601
-                        // not found, remove it
602
-                        $option->delete();
603
-                    }
604
-                }
605
-            }
606
-            // save new related options
607
-            foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
608
-                // skip $index that is from our sample
609
-                if ($index === 'xxcountxx') {
610
-                    continue;
611
-                }
612
-                // note we allow saving blank options.
613
-                if (empty($option_req_data['QSO_ID'])) {
614
-                    // no ID! save it!
615
-                    $new_option = EE_Question_Option::new_instance(
616
-                        [
617
-                            'QSO_value' => $option_req_data['QSO_value'],
618
-                            'QSO_desc'  => $option_req_data['QSO_desc'],
619
-                            'QSO_order' => $option_req_data['QSO_order'],
620
-                            'QST_ID'    => $question->ID(),
621
-                        ]
622
-                    );
623
-                    $new_option->save();
624
-                }
625
-            }
626
-        }
627
-        $query_args = ['action' => 'edit_question', 'QST_ID' => $ID];
628
-        if ($success !== 0) {
629
-            $msg = $new_question
630
-                ? sprintf(
631
-                    esc_html__('The %s has been created', 'event_espresso'),
632
-                    $this->_question_model->item_name()
633
-                )
634
-                : sprintf(
635
-                    esc_html__('The %s has been updated', 'event_espresso'),
636
-                    $this->_question_model->item_name()
637
-                );
638
-            EE_Error::add_success($msg);
639
-        }
640
-
641
-        $this->_redirect_after_action(false, '', $action_desc, $query_args, true);
642
-    }
643
-
644
-
645
-    /**
646
-     * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not
647
-     * by ID
648
-     * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously).
649
-     * So, this function gets the index in that request data array called question_options. Returns FALSE if not found.
650
-     *
651
-     * @param int $ID of the question option to find
652
-     * @return int index in question_options array if successful, FALSE if unsuccessful
653
-     */
654
-    protected function _get_option_req_data_index($ID)
655
-    {
656
-        $req_data_for_question_options = $this->_req_data['question_options'];
657
-        foreach ($req_data_for_question_options as $num => $option_data) {
658
-            if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) {
659
-                return $num;
660
-            }
661
-        }
662
-        return false;
663
-    }
664
-
665
-
666
-
667
-
668
-    /***********/
669
-    /* QUERIES */
670
-    /**
671
-     * For internal use in getting all the query parameters
672
-     * (because it's pretty well the same between question, question groups,
673
-     * and for both when searching for trashed and untrashed ones)
674
-     *
675
-     * @param EEM_Base $model either EEM_Question or EEM_Question_Group
676
-     * @param int      $per_page
677
-     * @param int      $current_page
678
-     * @return array model query params, @see
679
-     *               https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
680
-     */
681
-    protected function get_query_params($model, $per_page = 10, $current_page = 10)
682
-    {
683
-        $query_params             = [];
684
-        $offset                   = ($current_page - 1) * $per_page;
685
-        $query_params['limit']    = [$offset, $per_page];
686
-        $order                    =
687
-            (isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
688
-                ? $this->_req_data['order']
689
-                : 'ASC';
690
-        $orderby_field            =
691
-            $model instanceof EEM_Question
692
-                ? 'QST_ID'
693
-                : 'QSG_order';
694
-        $field_to_order_by        =
695
-            empty($this->_req_data['orderby'])
696
-                ? $orderby_field
697
-                : $this->_req_data['orderby'];
698
-        $query_params['order_by'] = [$field_to_order_by => $order];
699
-        $search_string            =
700
-            array_key_exists('s', $this->_req_data)
701
-                ? $this->_req_data['s']
702
-                : null;
703
-        if (! empty($search_string)) {
704
-            if ($model instanceof EEM_Question_Group) {
705
-                $query_params[0] = [
706
-                    'OR' => [
707
-                        'QSG_name' => ['LIKE', "%$search_string%"],
708
-                        'QSG_desc' => ['LIKE', "%$search_string%"],
709
-                    ],
710
-                ];
711
-            } else {
712
-                $query_params[0] = [
713
-                    'QST_display_text' => ['LIKE', "%$search_string%"],
714
-                ];
715
-            }
716
-        }
717
-
718
-        // capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented)
719
-        /*if ( $model instanceof EEM_Question_Group ) {
19
+	/**
20
+	 * holds the specific question object for the question details screen
21
+	 *
22
+	 * @var EE_Question $_question
23
+	 */
24
+	protected $_question;
25
+
26
+	/**
27
+	 * holds the specific question group object for the question group details screen
28
+	 *
29
+	 * @var EE_Question_Group $_question_group
30
+	 */
31
+	protected $_question_group;
32
+
33
+	/**
34
+	 *_question_model EEM_Question model instance (for queries)
35
+	 *
36
+	 * @var EEM_Question $_question_model ;
37
+	 */
38
+	protected $_question_model;
39
+
40
+	/**
41
+	 * _question_group_model EEM_Question_group instance (for queries)
42
+	 *
43
+	 * @var EEM_Question_Group $_question_group_model
44
+	 */
45
+	protected $_question_group_model;
46
+
47
+
48
+	/**
49
+	 * @Constructor
50
+	 * @param bool $routing indicate whether we want to just load the object and handle routing or just load the object.
51
+	 * @throws EE_Error
52
+	 * @throws ReflectionException
53
+	 */
54
+	public function __construct($routing = true)
55
+	{
56
+		require_once(EE_MODELS . 'EEM_Question.model.php');
57
+		require_once(EE_MODELS . 'EEM_Question_Group.model.php');
58
+		$this->_question_model       = EEM_Question::instance();
59
+		$this->_question_group_model = EEM_Question_Group::instance();
60
+		parent::__construct($routing);
61
+	}
62
+
63
+
64
+	protected function _init_page_props()
65
+	{
66
+		$this->page_slug        = REGISTRATION_FORM_PG_SLUG;
67
+		$this->page_label       = esc_html__('Registration Form', 'event_espresso');
68
+		$this->_admin_base_url  = REGISTRATION_FORM_ADMIN_URL;
69
+		$this->_admin_base_path = REGISTRATION_FORM_ADMIN;
70
+	}
71
+
72
+
73
+	protected function _ajax_hooks()
74
+	{
75
+	}
76
+
77
+
78
+	protected function _define_page_props()
79
+	{
80
+		$this->_admin_page_title = esc_html__('Registration Form', 'event_espresso');
81
+		$this->_labels           = [
82
+			'buttons' => [
83
+				'edit_question' => esc_html__('Edit Question', 'event_espresso'),
84
+			],
85
+		];
86
+	}
87
+
88
+
89
+	/**
90
+	 *_set_page_routes
91
+	 */
92
+	protected function _set_page_routes()
93
+	{
94
+		$qst_id             =
95
+			! empty($this->_req_data['QST_ID'])
96
+				? $this->_req_data['QST_ID']
97
+				: 0;
98
+		$this->_page_routes = [
99
+			'default' => [
100
+				'func'       => '_questions_overview_list_table',
101
+				'capability' => 'ee_read_questions',
102
+			],
103
+
104
+			'edit_question' => [
105
+				'func'       => '_edit_question',
106
+				'capability' => 'ee_edit_question',
107
+				'obj_id'     => $qst_id,
108
+				'args'       => ['edit'],
109
+			],
110
+
111
+			'question_groups' => [
112
+				'func'       => '_questions_groups_preview',
113
+				'capability' => 'ee_read_question_groups',
114
+			],
115
+
116
+			'update_question' => [
117
+				'func'       => '_insert_or_update_question',
118
+				'args'       => ['new_question' => false],
119
+				'capability' => 'ee_edit_question',
120
+				'obj_id'     => $qst_id,
121
+				'noheader'   => true,
122
+			],
123
+		];
124
+	}
125
+
126
+
127
+	protected function _set_page_config()
128
+	{
129
+		$this->_page_config = [
130
+			'default' => [
131
+				'nav'           => [
132
+					'label' => esc_html__('Questions', 'event_espresso'),
133
+					'order' => 10,
134
+				],
135
+				'list_table'    => 'Registration_Form_Questions_Admin_List_Table',
136
+				'metaboxes'     => $this->_default_espresso_metaboxes,
137
+				'help_tabs'     => [
138
+					'registration_form_questions_overview_help_tab'                           => [
139
+						'title'    => esc_html__('Questions Overview', 'event_espresso'),
140
+						'filename' => 'registration_form_questions_overview',
141
+					],
142
+					'registration_form_questions_overview_table_column_headings_help_tab'     => [
143
+						'title'    => esc_html__('Questions Overview Table Column Headings', 'event_espresso'),
144
+						'filename' => 'registration_form_questions_overview_table_column_headings',
145
+					],
146
+					'registration_form_questions_overview_views_bulk_actions_search_help_tab' => [
147
+						'title'    => esc_html__('Question Overview Views & Bulk Actions & Search', 'event_espresso'),
148
+						'filename' => 'registration_form_questions_overview_views_bulk_actions_search',
149
+					],
150
+				],
151
+				'require_nonce' => false,
152
+				'qtips'         => [
153
+					'EE_Registration_Form_Tips',
154
+				]/**/
155
+			],
156
+
157
+			'question_groups' => [
158
+				'nav'           => [
159
+					'label' => esc_html__('Question Groups', 'event_espresso'),
160
+					'order' => 20,
161
+				],
162
+				'metaboxes'     => $this->_default_espresso_metaboxes,
163
+				'help_tabs'     => [
164
+					'registration_form_question_groups_help_tab' => [
165
+						'title'    => esc_html__('Question Groups', 'event_espresso'),
166
+						'filename' => 'registration_form_question_groups',
167
+					],
168
+				],
169
+				'require_nonce' => false,
170
+			],
171
+
172
+			'edit_question' => [
173
+				'nav'           => [
174
+					'label'      => esc_html__('Edit Question', 'event_espresso'),
175
+					'order'      => 15,
176
+					'persistent' => false,
177
+					'url'        => isset($this->_req_data['question_id'])
178
+						? add_query_arg(
179
+							['question_id' => $this->_req_data['question_id']],
180
+							$this->_current_page_view_url
181
+						)
182
+						: $this->_admin_base_url,
183
+				],
184
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, ['_publish_post_box']),
185
+				'help_tabs'     => [
186
+					'registration_form_edit_question_group_help_tab' => [
187
+						'title'    => esc_html__('Edit Question', 'event_espresso'),
188
+						'filename' => 'registration_form_edit_question',
189
+					],
190
+				],
191
+				'require_nonce' => false,
192
+			],
193
+		];
194
+	}
195
+
196
+
197
+	protected function _add_screen_options()
198
+	{
199
+		// todo
200
+	}
201
+
202
+
203
+	protected function _add_screen_options_default()
204
+	{
205
+		$page_title              = $this->_admin_page_title;
206
+		$this->_admin_page_title = esc_html__('Questions', 'event_espresso');
207
+		$this->_per_page_screen_option();
208
+		$this->_admin_page_title = $page_title;
209
+	}
210
+
211
+
212
+	protected function _add_screen_options_question_groups()
213
+	{
214
+		$page_title              = $this->_admin_page_title;
215
+		$this->_admin_page_title = esc_html__('Question Groups', 'event_espresso');
216
+		$this->_per_page_screen_option();
217
+		$this->_admin_page_title = $page_title;
218
+	}
219
+
220
+
221
+	// none of the below group are currently used for Event Categories
222
+	protected function _add_feature_pointers()
223
+	{
224
+	}
225
+
226
+
227
+	public function load_scripts_styles()
228
+	{
229
+		wp_register_style(
230
+			'espresso_registration',
231
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.css',
232
+			[],
233
+			EVENT_ESPRESSO_VERSION
234
+		);
235
+		wp_enqueue_style('espresso_registration');
236
+	}
237
+
238
+
239
+	public function admin_init()
240
+	{
241
+	}
242
+
243
+
244
+	public function admin_notices()
245
+	{
246
+	}
247
+
248
+
249
+	public function admin_footer_scripts()
250
+	{
251
+	}
252
+
253
+
254
+	public function load_scripts_styles_default()
255
+	{
256
+	}
257
+
258
+
259
+	/**
260
+	 * @throws EE_Error
261
+	 */
262
+	public function load_scripts_styles_add_question()
263
+	{
264
+		$this->load_scripts_styles_question_details();
265
+	}
266
+
267
+
268
+	/**
269
+	 * @throws EE_Error
270
+	 */
271
+	public function load_scripts_styles_edit_question()
272
+	{
273
+		$this->load_scripts_styles_question_details();
274
+	}
275
+
276
+
277
+	/**
278
+	 * Loads the JS required for adding or editing a question
279
+	 *
280
+	 * @throws EE_Error
281
+	 * @throws EE_Error
282
+	 */
283
+	protected function load_scripts_styles_question_details()
284
+	{
285
+		$this->load_scripts_styles_forms();
286
+		wp_register_script(
287
+			'espresso_registration_form_single',
288
+			REGISTRATION_FORM_ASSETS_URL . 'espresso_registration_form_admin.js',
289
+			['jquery-ui-sortable'],
290
+			EVENT_ESPRESSO_VERSION,
291
+			true
292
+		);
293
+		wp_enqueue_script('espresso_registration_form_single');
294
+		wp_localize_script(
295
+			'espresso_registration_form_single',
296
+			'ee_question_data',
297
+			[
298
+				'question_types_with_max'    => EEM_Question::instance()->questionTypesWithMaxLength(),
299
+				'question_type_with_options' => EEM_Question::instance()->question_types_with_options(),
300
+			]
301
+		);
302
+	}
303
+
304
+
305
+	public function recaptcha_info_help_tab()
306
+	{
307
+		$template = REGISTRATION_FORM_TEMPLATE_PATH . 'recaptcha_info_help_tab.template.php';
308
+		EEH_Template::display_template($template, []);
309
+	}
310
+
311
+
312
+	public function load_scripts_styles_forms()
313
+	{
314
+		// styles
315
+		wp_enqueue_style('espresso-ui-theme');
316
+		// scripts
317
+		wp_enqueue_script('ee_admin_js');
318
+	}
319
+
320
+
321
+	protected function _set_list_table_views_default()
322
+	{
323
+		$this->_views = [
324
+			'all' => [
325
+				'slug'  => 'all',
326
+				'label' => esc_html__('View All Questions', 'event_espresso'),
327
+				'count' => 0,
328
+			],
329
+		];
330
+
331
+		if (
332
+			EE_Registry::instance()->CAP->current_user_can(
333
+				'ee_delete_questions',
334
+				'espresso_registration_form_trash_questions'
335
+			)
336
+		) {
337
+			$this->_views['trash'] = [
338
+				'slug'  => 'trash',
339
+				'label' => esc_html__('Trash', 'event_espresso'),
340
+				'count' => 0,
341
+			];
342
+		}
343
+	}
344
+
345
+
346
+	/**
347
+	 * This just previews the question groups tab that comes in caffeinated.
348
+	 *
349
+	 * @return void html
350
+	 * @throws EE_Error
351
+	 */
352
+	protected function _questions_groups_preview()
353
+	{
354
+		$this->_admin_page_title              = esc_html__('Question Groups (Preview)', 'event_espresso');
355
+		$this->_template_args['preview_img']  =
356
+			'<img src="' . REGISTRATION_FORM_ASSETS_URL . 'caf_reg_form_preview.jpg" alt="'
357
+			. esc_attr__(
358
+				'Preview Question Groups Overview List Table screenshot',
359
+				'event_espresso'
360
+			) . '" />';
361
+		$this->_template_args['preview_text'] = '<strong>'
362
+												. esc_html__(
363
+													'Question Groups is a feature that is only available in the premium version of Event Espresso 4 which is available with a support license purchase on EventEspresso.com. With the Question Groups feature you are able to create new question groups, edit existing question groups, and create and edit new questions and add them to question groups.',
364
+													'event_espresso'
365
+												) . '</strong>';
366
+		$this->display_admin_caf_preview_page('question_groups_tab');
367
+	}
368
+
369
+
370
+	/**
371
+	 * Extracts the question field's values from the POST request to update or insert them
372
+	 *
373
+	 * @param EEM_Base $model
374
+	 * @return array where each key is the name of a model's field/db column, and each value is its value.
375
+	 * @throws EE_Error
376
+	 */
377
+	protected function _set_column_values_for(EEM_Base $model)
378
+	{
379
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
380
+		$set_column_values = [];
381
+
382
+		// some initial checks for proper values.
383
+		// if QST_admin_only, then no matter what QST_required is we disable.
384
+		if (! empty($this->_req_data['QST_admin_only'])) {
385
+			$this->_req_data['QST_required'] = 0;
386
+		}
387
+		// if the question shouldn't have a max length, don't let them set one
388
+		if (
389
+			! isset(
390
+				$this->_req_data['QST_type'],
391
+				$this->_req_data['QST_max']
392
+			)
393
+			|| ! in_array(
394
+				$this->_req_data['QST_type'],
395
+				EEM_Question::instance()->questionTypesWithMaxLength(),
396
+				true
397
+			)
398
+		) {
399
+			// they're not allowed to set the max
400
+			$this->_req_data['QST_max'] = null;
401
+		}
402
+		foreach ($model->field_settings() as $fieldName => $settings) {
403
+			// basically if QSG_identifier is empty or not set
404
+			if (
405
+				$fieldName === 'QSG_identifier'
406
+				&& (isset($this->_req_data['QSG_identifier']) && empty($this->_req_data['QSG_identifier']))
407
+			) {
408
+				$QSG_name = isset($this->_req_data['QSG_name'])
409
+					? $this->_req_data['QSG_name']
410
+					: '';
411
+				$set_column_values[ $fieldName ] = sanitize_title($QSG_name) . '-' . uniqid('', true);
412
+			} elseif (
413
+				$fieldName === 'QST_admin_label'
414
+				&& (isset($this->_req_data['QST_admin_label']) && empty($this->_req_data['QST_admin_label']))
415
+			) {
416
+				// the admin label is blank, use a slug version of the question text
417
+				$QST_text                        =
418
+					isset($this->_req_data['QST_display_text'])
419
+						? $this->_req_data['QST_display_text']
420
+						: '';
421
+				$set_column_values[ $fieldName ] = sanitize_title(wp_trim_words($QST_text, 10));
422
+			} elseif ($fieldName === 'QST_admin_only' && (! isset($this->_req_data['QST_admin_only']))) {
423
+				$set_column_values[ $fieldName ] = 0;
424
+			} elseif ($fieldName === 'QST_max') {
425
+				$qst_system = EEM_Question::instance()->get_var(
426
+					[
427
+						[
428
+							'QST_ID' => isset($this->_req_data['QST_ID'])
429
+								? $this->_req_data['QST_ID']
430
+								: 0,
431
+						],
432
+					],
433
+					'QST_system'
434
+				);
435
+				$max_max    = EEM_Question::instance()->absolute_max_for_system_question($qst_system);
436
+				if (
437
+					empty($this->_req_data['QST_max']) || $this->_req_data['QST_max'] > $max_max
438
+				) {
439
+					$set_column_values[ $fieldName ] = $max_max;
440
+				}
441
+			}
442
+
443
+
444
+			// only add a property to the array if it's not null (otherwise the model should just use the default value)
445
+			if (
446
+				! isset($set_column_values[ $fieldName ]) && isset($this->_req_data[ $fieldName ])
447
+			) {
448
+				$set_column_values[ $fieldName ] = $this->_req_data[ $fieldName ];
449
+			}
450
+		}
451
+		return $set_column_values;// validation fo this data to be performed by the model before insertion.
452
+	}
453
+
454
+
455
+	/**
456
+	 *_questions_overview_list_table
457
+	 *
458
+	 * @throws EE_Error
459
+	 */
460
+	protected function _questions_overview_list_table()
461
+	{
462
+		$this->_search_btn_label = esc_html__('Questions', 'event_espresso');
463
+		$this->display_admin_list_table_page_with_sidebar();
464
+	}
465
+
466
+
467
+	/**
468
+	 * _edit_question
469
+	 *
470
+	 * @throws EE_Error
471
+	 * @throws ReflectionException
472
+	 */
473
+	protected function _edit_question()
474
+	{
475
+		$ID = isset($this->_req_data['QST_ID']) && ! empty($this->_req_data['QST_ID'])
476
+			? absint($this->_req_data['QST_ID'])
477
+			: false;
478
+
479
+		switch ($this->_req_action) {
480
+			case 'add_question':
481
+				$this->_admin_page_title = esc_html__('Add Question', 'event_espresso');
482
+				break;
483
+			case 'edit_question':
484
+				$this->_admin_page_title = esc_html__('Edit Question', 'event_espresso');
485
+				break;
486
+			default:
487
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
488
+		}
489
+
490
+		// add PRC_ID to title if editing
491
+		$this->_admin_page_title =
492
+			$ID
493
+				? $this->_admin_page_title . ' # ' . $ID
494
+				: $this->_admin_page_title;
495
+		if ($ID) {
496
+			$question                 = $this->_question_model->get_one_by_ID($ID);
497
+			$additional_hidden_fields = ['QST_ID' => ['type' => 'hidden', 'value' => $ID]];
498
+			$this->_set_add_edit_form_tags('update_question', $additional_hidden_fields);
499
+		} else {
500
+			$question = EE_Question::new_instance();
501
+			$question->set_order_to_latest();
502
+			$this->_set_add_edit_form_tags('insert_question');
503
+		}
504
+		if ($question->system_ID() === EEM_Attendee::system_question_phone) {
505
+			$question_types = array_intersect_key(
506
+				EEM_Question::instance()->allowed_question_types(),
507
+				array_flip(
508
+					[
509
+						EEM_Question::QST_type_text,
510
+						EEM_Question::QST_type_us_phone,
511
+					]
512
+				)
513
+			);
514
+		} else {
515
+			$question_types = $question->has_answers()
516
+				? $this->_question_model->question_types_in_same_category($question->type())
517
+				: $this->_question_model->allowed_question_types();
518
+		}
519
+		$this->_template_args['QST_ID']                     = $ID;
520
+		$this->_template_args['question']                   = $question;
521
+		$this->_template_args['question_types']             = $question_types;
522
+		$this->_template_args['max_max']                    =
523
+			EEM_Question::instance()->absolute_max_for_system_question(
524
+				$question->system_ID()
525
+			);
526
+		$this->_template_args['question_type_descriptions'] = $this->_get_question_type_descriptions();
527
+		$this->_set_publish_post_box_vars('id', $ID);
528
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
529
+			REGISTRATION_FORM_TEMPLATE_PATH . 'questions_main_meta_box.template.php',
530
+			$this->_template_args,
531
+			true
532
+		);
533
+
534
+		// the details template wrapper
535
+		$this->display_admin_page_with_sidebar();
536
+	}
537
+
538
+
539
+	/**
540
+	 * @return string
541
+	 * @throws EE_Error
542
+	 * @throws ReflectionException
543
+	 */
544
+	protected function _get_question_type_descriptions()
545
+	{
546
+		EE_Registry::instance()->load_helper('HTML');
547
+		$descriptions               = '';
548
+		$question_type_descriptions = EEM_Question::instance()->question_descriptions();
549
+		foreach ($question_type_descriptions as $type => $question_type_description) {
550
+			if ($type == 'HTML_TEXTAREA') {
551
+				$html                      = new EE_Simple_HTML_Validation_Strategy();
552
+				$question_type_description .= sprintf(
553
+					esc_html__('%1$s(allowed tags: %2$s)', 'event_espresso'),
554
+					'<br/>',
555
+					$html->get_list_of_allowed_tags()
556
+				);
557
+			}
558
+			$descriptions .= EEH_HTML::p(
559
+				$question_type_description,
560
+				'question_type_description-' . $type,
561
+				'question_type_description description',
562
+				'display:none;'
563
+			);
564
+		}
565
+		return $descriptions;
566
+	}
567
+
568
+
569
+	/**
570
+	 * @param bool|true $new_question
571
+	 * @throws EE_Error
572
+	 * @throws ReflectionException
573
+	 */
574
+	protected function _insert_or_update_question($new_question = true)
575
+	{
576
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
577
+		$set_column_values = $this->_set_column_values_for($this->_question_model);
578
+		if ($new_question) {
579
+			$question    = EE_Question::new_instance($set_column_values);
580
+			$action_desc = 'added';
581
+		} else {
582
+			$question = EEM_Question::instance()->get_one_by_ID(absint($this->_req_data['QST_ID']));
583
+			foreach ($set_column_values as $field => $new_value) {
584
+				$question->set($field, $new_value);
585
+			}
586
+			$action_desc = 'updated';
587
+		}
588
+		$success = $question->save();
589
+		$ID      = $question->ID();
590
+		if ($ID && $question->should_have_question_options()) {
591
+			// save the related options
592
+			// trash removed options, save old ones
593
+			// get list of all options
594
+			$options = $question->options();
595
+			if (! empty($options)) {
596
+				foreach ($options as $option_ID => $option) {
597
+					$option_req_index = $this->_get_option_req_data_index($option_ID);
598
+					if ($option_req_index !== false) {
599
+						$option->save($this->_req_data['question_options'][ $option_req_index ]);
600
+					} else {
601
+						// not found, remove it
602
+						$option->delete();
603
+					}
604
+				}
605
+			}
606
+			// save new related options
607
+			foreach ($this->_req_data['question_options'] as $index => $option_req_data) {
608
+				// skip $index that is from our sample
609
+				if ($index === 'xxcountxx') {
610
+					continue;
611
+				}
612
+				// note we allow saving blank options.
613
+				if (empty($option_req_data['QSO_ID'])) {
614
+					// no ID! save it!
615
+					$new_option = EE_Question_Option::new_instance(
616
+						[
617
+							'QSO_value' => $option_req_data['QSO_value'],
618
+							'QSO_desc'  => $option_req_data['QSO_desc'],
619
+							'QSO_order' => $option_req_data['QSO_order'],
620
+							'QST_ID'    => $question->ID(),
621
+						]
622
+					);
623
+					$new_option->save();
624
+				}
625
+			}
626
+		}
627
+		$query_args = ['action' => 'edit_question', 'QST_ID' => $ID];
628
+		if ($success !== 0) {
629
+			$msg = $new_question
630
+				? sprintf(
631
+					esc_html__('The %s has been created', 'event_espresso'),
632
+					$this->_question_model->item_name()
633
+				)
634
+				: sprintf(
635
+					esc_html__('The %s has been updated', 'event_espresso'),
636
+					$this->_question_model->item_name()
637
+				);
638
+			EE_Error::add_success($msg);
639
+		}
640
+
641
+		$this->_redirect_after_action(false, '', $action_desc, $query_args, true);
642
+	}
643
+
644
+
645
+	/**
646
+	 * Upon saving a question, there should be an array of 'question_options'. This array is index numerically, but not
647
+	 * by ID
648
+	 * (this is done because new question options don't have an ID, but we may want to add multiple simultaneously).
649
+	 * So, this function gets the index in that request data array called question_options. Returns FALSE if not found.
650
+	 *
651
+	 * @param int $ID of the question option to find
652
+	 * @return int index in question_options array if successful, FALSE if unsuccessful
653
+	 */
654
+	protected function _get_option_req_data_index($ID)
655
+	{
656
+		$req_data_for_question_options = $this->_req_data['question_options'];
657
+		foreach ($req_data_for_question_options as $num => $option_data) {
658
+			if (array_key_exists('QSO_ID', $option_data) && (int) $option_data['QSO_ID'] === $ID) {
659
+				return $num;
660
+			}
661
+		}
662
+		return false;
663
+	}
664
+
665
+
666
+
667
+
668
+	/***********/
669
+	/* QUERIES */
670
+	/**
671
+	 * For internal use in getting all the query parameters
672
+	 * (because it's pretty well the same between question, question groups,
673
+	 * and for both when searching for trashed and untrashed ones)
674
+	 *
675
+	 * @param EEM_Base $model either EEM_Question or EEM_Question_Group
676
+	 * @param int      $per_page
677
+	 * @param int      $current_page
678
+	 * @return array model query params, @see
679
+	 *               https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
680
+	 */
681
+	protected function get_query_params($model, $per_page = 10, $current_page = 10)
682
+	{
683
+		$query_params             = [];
684
+		$offset                   = ($current_page - 1) * $per_page;
685
+		$query_params['limit']    = [$offset, $per_page];
686
+		$order                    =
687
+			(isset($this->_req_data['order']) && ! empty($this->_req_data['order']))
688
+				? $this->_req_data['order']
689
+				: 'ASC';
690
+		$orderby_field            =
691
+			$model instanceof EEM_Question
692
+				? 'QST_ID'
693
+				: 'QSG_order';
694
+		$field_to_order_by        =
695
+			empty($this->_req_data['orderby'])
696
+				? $orderby_field
697
+				: $this->_req_data['orderby'];
698
+		$query_params['order_by'] = [$field_to_order_by => $order];
699
+		$search_string            =
700
+			array_key_exists('s', $this->_req_data)
701
+				? $this->_req_data['s']
702
+				: null;
703
+		if (! empty($search_string)) {
704
+			if ($model instanceof EEM_Question_Group) {
705
+				$query_params[0] = [
706
+					'OR' => [
707
+						'QSG_name' => ['LIKE', "%$search_string%"],
708
+						'QSG_desc' => ['LIKE', "%$search_string%"],
709
+					],
710
+				];
711
+			} else {
712
+				$query_params[0] = [
713
+					'QST_display_text' => ['LIKE', "%$search_string%"],
714
+				];
715
+			}
716
+		}
717
+
718
+		// capability checks (just leaving this commented out for reference because it illustrates some complicated query params that could be useful when fully implemented)
719
+		/*if ( $model instanceof EEM_Question_Group ) {
720 720
             if ( ! EE_Registry::instance()->CAP->current_user_can( 'edit_others_question_groups', 'espresso_registration_form_edit_question_group' ) ) {
721 721
                 $query_params[0] = array(
722 722
                     'AND' => array(
@@ -746,67 +746,67 @@  discard block
 block discarded – undo
746 746
             }
747 747
         }/**/
748 748
 
749
-        return $query_params;
750
-    }
751
-
752
-
753
-    /**
754
-     * @param int        $per_page
755
-     * @param int        $current_page
756
-     * @param bool|false $count
757
-     * @return EE_Base_Class[]|EE_Question_Group[]|EE_Soft_Delete_Base_Class[]|int
758
-     * @throws EE_Error
759
-     */
760
-    public function get_questions($per_page = 10, $current_page = 1, $count = false)
761
-    {
762
-        $QST          = EEM_Question::instance();
763
-        $query_params = $this->get_query_params($QST, $per_page, $current_page);
764
-        if ($count) {
765
-            $where   =
766
-                isset($query_params[0])
767
-                    ? [$query_params[0]]
768
-                    : [];
769
-            $results = $QST->count($where);
770
-        } else {
771
-            $results = $QST->get_all($query_params);
772
-        }
773
-        return $results;
774
-    }
775
-
776
-
777
-    /**
778
-     * @param            $per_page
779
-     * @param int        $current_page
780
-     * @param bool|false $count
781
-     * @return EE_Soft_Delete_Base_Class[]|int
782
-     * @throws EE_Error
783
-     */
784
-    public function get_trashed_questions($per_page, $current_page = 1, $count = false)
785
-    {
786
-        $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
787
-        $where        =
788
-            isset($query_params[0])
789
-                ? [$query_params[0]]
790
-                : [];
791
-        return $count
792
-            ? EEM_Question::instance()->count_deleted($where)
793
-            : EEM_Question::instance()->get_all_deleted($query_params);
794
-    }
795
-
796
-
797
-    /**
798
-     * @param            $per_page
799
-     * @param int        $current_page
800
-     * @param bool|false $count
801
-     * @return EE_Base_Class[]|EE_Question_Group[]|EE_Soft_Delete_Base_Class[]
802
-     * @throws EE_Error
803
-     */
804
-    public function get_question_groups($per_page, $current_page = 1, $count = false)
805
-    {
806
-        $questionGroupModel = EEM_Question_Group::instance();
807
-        // note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
808
-        return $questionGroupModel->get_all(
809
-            $this->get_query_params($questionGroupModel, $per_page, $current_page)
810
-        );
811
-    }
749
+		return $query_params;
750
+	}
751
+
752
+
753
+	/**
754
+	 * @param int        $per_page
755
+	 * @param int        $current_page
756
+	 * @param bool|false $count
757
+	 * @return EE_Base_Class[]|EE_Question_Group[]|EE_Soft_Delete_Base_Class[]|int
758
+	 * @throws EE_Error
759
+	 */
760
+	public function get_questions($per_page = 10, $current_page = 1, $count = false)
761
+	{
762
+		$QST          = EEM_Question::instance();
763
+		$query_params = $this->get_query_params($QST, $per_page, $current_page);
764
+		if ($count) {
765
+			$where   =
766
+				isset($query_params[0])
767
+					? [$query_params[0]]
768
+					: [];
769
+			$results = $QST->count($where);
770
+		} else {
771
+			$results = $QST->get_all($query_params);
772
+		}
773
+		return $results;
774
+	}
775
+
776
+
777
+	/**
778
+	 * @param            $per_page
779
+	 * @param int        $current_page
780
+	 * @param bool|false $count
781
+	 * @return EE_Soft_Delete_Base_Class[]|int
782
+	 * @throws EE_Error
783
+	 */
784
+	public function get_trashed_questions($per_page, $current_page = 1, $count = false)
785
+	{
786
+		$query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page);
787
+		$where        =
788
+			isset($query_params[0])
789
+				? [$query_params[0]]
790
+				: [];
791
+		return $count
792
+			? EEM_Question::instance()->count_deleted($where)
793
+			: EEM_Question::instance()->get_all_deleted($query_params);
794
+	}
795
+
796
+
797
+	/**
798
+	 * @param            $per_page
799
+	 * @param int        $current_page
800
+	 * @param bool|false $count
801
+	 * @return EE_Base_Class[]|EE_Question_Group[]|EE_Soft_Delete_Base_Class[]
802
+	 * @throws EE_Error
803
+	 */
804
+	public function get_question_groups($per_page, $current_page = 1, $count = false)
805
+	{
806
+		$questionGroupModel = EEM_Question_Group::instance();
807
+		// note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items
808
+		return $questionGroupModel->get_all(
809
+			$this->get_query_params($questionGroupModel, $per_page, $current_page)
810
+		);
811
+	}
812 812
 }
Please login to merge, or discard this patch.
registration_form/help_tabs/registration_form_add_question.help_tab.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -8,34 +8,34 @@  discard block
 block discarded – undo
8 8
 </p>
9 9
 <p>
10 10
     <?php printf(
11
-        esc_html__('This page allows you to add a new question for %s.', 'event_espresso'),
12
-        Domain::brandName()
13
-    ); ?>
11
+		esc_html__('This page allows you to add a new question for %s.', 'event_espresso'),
12
+		Domain::brandName()
13
+	); ?>
14 14
 </p>
15 15
 <ul>
16 16
     <li>
17 17
         <strong><?php esc_html_e('Question Text', 'event_espresso'); ?></strong>
18 18
         <br />
19 19
         <?php esc_html_e(
20
-            'This shows the question as it will be displayed on the registration form. HTML can be used here.',
21
-            'event_espresso'
22
-        ); ?>
20
+			'This shows the question as it will be displayed on the registration form. HTML can be used here.',
21
+			'event_espresso'
22
+		); ?>
23 23
     </li>
24 24
     <li>
25 25
         <strong><?php esc_html_e('Question Label (admin-only)', 'event_espresso'); ?></strong>
26 26
         <br />
27 27
         <?php esc_html_e(
28
-            'This field is only shown to the admin. It is useful for understanding the difference between questions that appear to be similar but are used in various situations. HTML cannot be used.',
29
-            'event_espresso'
30
-        ); ?>
28
+			'This field is only shown to the admin. It is useful for understanding the difference between questions that appear to be similar but are used in various situations. HTML cannot be used.',
29
+			'event_espresso'
30
+		); ?>
31 31
     </li>
32 32
     <li>
33 33
         <strong><?php esc_html_e('Question Order', 'event_espresso'); ?></strong>
34 34
         <br />
35 35
         <?php esc_html_e(
36
-            'Questions can be sorted by using the drag and drop feature on the Questions Overview page. Another way to sort questions is to adjust their order of application by using this field. A smaller order of application will be shown first. For example, a question with an order of application of 1 will appear before one that has an order of application of 5.',
37
-            'event_espresso'
38
-        ); ?>
36
+			'Questions can be sorted by using the drag and drop feature on the Questions Overview page. Another way to sort questions is to adjust their order of application by using this field. A smaller order of application will be shown first. For example, a question with an order of application of 1 will appear before one that has an order of application of 5.',
37
+			'event_espresso'
38
+		); ?>
39 39
     </li>
40 40
     <li>
41 41
         <strong><?php esc_html_e('Admin-Only Question?', 'event_espresso'); ?></strong>
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
         <strong><?php esc_html_e('Question Type', 'event_espresso'); ?></strong>
47 47
         <br />
48 48
         <?php esc_html_e(
49
-            'This shows the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.',
50
-            'event_espresso'
51
-        ); ?>
49
+			'This shows the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, and Date Picker.',
50
+			'event_espresso'
51
+		); ?>
52 52
     </li>
53 53
     <li>
54 54
         <strong><?php esc_html_e('Answer Options (for applicable question types)', 'event_espresso'); ?></strong>
@@ -64,24 +64,24 @@  discard block
 block discarded – undo
64 64
         <strong><?php esc_html_e('Required Text', 'event_espresso'); ?></strong>
65 65
         <br />
66 66
         <?php esc_html_e(
67
-            'This text is displayed when a registrant does not answer a question but is required to do so. The default message will show "this field is required."',
68
-            'event_espresso'
69
-        ); ?>
67
+			'This text is displayed when a registrant does not answer a question but is required to do so. The default message will show "this field is required."',
68
+			'event_espresso'
69
+		); ?>
70 70
     </li>
71 71
 </ul>
72 72
 <p>
73 73
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong>
74 74
     <br />
75 75
     <?php esc_html_e(
76
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
77
-        'event_espresso'
78
-    ); ?>
76
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
77
+		'event_espresso'
78
+	); ?>
79 79
 </p>
80 80
 <p>
81 81
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong>
82 82
     <br />
83 83
     <?php esc_html_e(
84
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
85
-        'event_espresso'
86
-    ); ?>
84
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
85
+		'event_espresso'
86
+	); ?>
87 87
 </p>
88 88
\ No newline at end of file
Please login to merge, or discard this patch.
help_tabs/registration_form_reg_form_settings.help_tab.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@  discard block
 block discarded – undo
3 3
 </p>
4 4
 <p>
5 5
     <?php esc_html_e(
6
-        'This page shows options for Email Validation, the EE "Bot Trap" and reCAPTCHA which can help prevent SPAM registrations on your site.',
7
-        'event_espresso'
8
-    ); ?>
6
+		'This page shows options for Email Validation, the EE "Bot Trap" and reCAPTCHA which can help prevent SPAM registrations on your site.',
7
+		'event_espresso'
8
+	); ?>
9 9
 </p>
10 10
 <div id="email_validation_info">
11 11
     <p>
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
     </p>
14 14
     <p>
15 15
         <?php esc_html_e(
16
-            "Validating an email address is extremely difficult to do correctly. Your server's configuration, as well as your own tolerances and needs, can affect the type of validation needed. We offer different types of validation so that you can control how strict your registration form responds to entered email addresses. If you are receiving too many bogus email addresses, then you can try the WordPress Default validation setting. If you find that the form validation is blocking a valid email address you can try the Basic setting, or if available, the International validation settings.",
17
-            'event_espresso'
18
-        ); ?>
16
+			"Validating an email address is extremely difficult to do correctly. Your server's configuration, as well as your own tolerances and needs, can affect the type of validation needed. We offer different types of validation so that you can control how strict your registration form responds to entered email addresses. If you are receiving too many bogus email addresses, then you can try the WordPress Default validation setting. If you find that the form validation is blocking a valid email address you can try the Basic setting, or if available, the International validation settings.",
17
+			'event_espresso'
18
+		); ?>
19 19
     </p>
20 20
     <p>
21 21
         <strong><?php esc_html_e('Validation Options:', 'event_espresso'); ?></strong>
@@ -23,27 +23,27 @@  discard block
 block discarded – undo
23 23
     <ul>
24 24
         <li>
25 25
             <?php esc_html_e(
26
-                '"Basic" - only checks that an email address follows the most basic structure guidelines ( ie: [email protected] ). Will work with the widest range of email addresses but will also allow the most garbage through.',
27
-                'event_espresso'
28
-            ); ?>
26
+				'"Basic" - only checks that an email address follows the most basic structure guidelines ( ie: [email protected] ). Will work with the widest range of email addresses but will also allow the most garbage through.',
27
+				'event_espresso'
28
+			); ?>
29 29
         </li>
30 30
         <li>
31 31
             <?php esc_html_e(
32
-                '"WordPress Default" - uses built in WordPress email validation, but does not support unicode characters (ie: international characters from non-latin based languages).',
33
-                'event_espresso'
34
-            ); ?>
32
+				'"WordPress Default" - uses built in WordPress email validation, but does not support unicode characters (ie: international characters from non-latin based languages).',
33
+				'event_espresso'
34
+			); ?>
35 35
         </li>
36 36
         <li>
37 37
             <?php esc_html_e(
38
-                '"International" - supports unicode characters but may not be supported by all server configurations. Try this first if you need to international language support, but drop back down to "Basic" if your server configuration conflicts.',
39
-                'event_espresso'
40
-            ); ?>
38
+				'"International" - supports unicode characters but may not be supported by all server configurations. Try this first if you need to international language support, but drop back down to "Basic" if your server configuration conflicts.',
39
+				'event_espresso'
40
+			); ?>
41 41
         </li>
42 42
         <li>
43 43
             <?php esc_html_e(
44
-                '"International + DNS Check" - same as "International" but also performs MX and A record DNS checks to verify that the email address domain exists (ie: the portion of the address after the "@"). Can not verify that the local portion of the email address is valid (ie: the first portion of the address before the "@").',
45
-                'event_espresso'
46
-            ); ?>
44
+				'"International + DNS Check" - same as "International" but also performs MX and A record DNS checks to verify that the email address domain exists (ie: the portion of the address after the "@"). Can not verify that the local portion of the email address is valid (ie: the first portion of the address before the "@").',
45
+				'event_espresso'
46
+			); ?>
47 47
         </li>
48 48
     </ul>
49 49
 </div>
@@ -51,21 +51,21 @@  discard block
 block discarded – undo
51 51
     <p><strong><?php esc_html_e('reCAPTCHA Information', 'event_espresso'); ?></strong></p>
52 52
     <p>
53 53
         <?php printf(
54
-            esc_html__(
55
-                '%s helps prevent automated abuse of your site (such as comment spam or bogus registrations) by using a reCAPTCHA to ensure that only humans perform certain actions.',
56
-                'event_espresso'
57
-            ),
58
-            '<a href="https://www.google.com/recaptcha/intro/index.html" target="_blank" rel="noopener noreferrer">reCAPTCHA</a>'
59
-        ); ?>
54
+			esc_html__(
55
+				'%s helps prevent automated abuse of your site (such as comment spam or bogus registrations) by using a reCAPTCHA to ensure that only humans perform certain actions.',
56
+				'event_espresso'
57
+			),
58
+			'<a href="https://www.google.com/recaptcha/intro/index.html" target="_blank" rel="noopener noreferrer">reCAPTCHA</a>'
59
+		); ?>
60 60
     </p>
61 61
     <p>
62 62
         <?php printf(
63
-            esc_html__(
64
-                'You must sign up for a free %s account to use it with this plugin. If you already have a reCAPTCHA account enter your "Public" and "Private" keys on this page.',
65
-                'event_espresso'
66
-            ),
67
-            '<a href="https://www.google.com/recaptcha/admin#createsite" target="_blank" rel="noopener noreferrer">reCAPTCHA</a>'
68
-        ); ?>
63
+			esc_html__(
64
+				'You must sign up for a free %s account to use it with this plugin. If you already have a reCAPTCHA account enter your "Public" and "Private" keys on this page.',
65
+				'event_espresso'
66
+			),
67
+			'<a href="https://www.google.com/recaptcha/admin#createsite" target="_blank" rel="noopener noreferrer">reCAPTCHA</a>'
68
+		); ?>
69 69
     </p>
70 70
     <p><strong><?php esc_html_e('Helpful Information:', 'event_espresso'); ?></strong></p>
71 71
     <ul>
@@ -82,14 +82,14 @@  discard block
 block discarded – undo
82 82
 <p>
83 83
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong><br />
84 84
     <?php esc_html_e(
85
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
86
-        'event_espresso'
87
-    ); ?>
85
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
86
+		'event_espresso'
87
+	); ?>
88 88
 </p>
89 89
 <p>
90 90
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br />
91 91
     <?php esc_html_e(
92
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
93
-        'event_espresso'
94
-    ); ?>
92
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
93
+		'event_espresso'
94
+	); ?>
95 95
 </p>
Please login to merge, or discard this patch.
help_tabs/registration_form_edit_question_group.help_tab.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,38 +7,38 @@  discard block
 block discarded – undo
7 7
 <p>
8 8
     <strong><?php esc_html_e('Notice', 'event_espresso'); ?></strong><br />
9 9
     <?php esc_html_e(
10
-        'System questions groups may have some options disabled. This is to ensure that your registrations don\'t break from accidental changes.',
11
-        'event_espresso'
12
-    ); ?>
10
+		'System questions groups may have some options disabled. This is to ensure that your registrations don\'t break from accidental changes.',
11
+		'event_espresso'
12
+	); ?>
13 13
 </p>
14 14
 <ul>
15 15
     <li>
16 16
         <strong><?php esc_html_e('Group Name', 'event_espresso'); ?></strong><br />
17 17
         <?php esc_html_e(
18
-            'This is the name (title) of the question group as it will be displayed on the registration form. HTML cannot be used.',
19
-            'event_espresso'
20
-        ); ?>
18
+			'This is the name (title) of the question group as it will be displayed on the registration form. HTML cannot be used.',
19
+			'event_espresso'
20
+		); ?>
21 21
     </li>
22 22
     <li>
23 23
         <strong><?php esc_html_e('Group Identifier', 'event_espresso'); ?></strong><br />
24 24
         <?php esc_html_e(
25
-            'This is a unique name (slug) for this group. It helps you tell the difference between this group and other groups that may appear to be similar. It is not shown to registrants and HTML cannot be used.',
26
-            'event_espresso'
27
-        ); ?>
25
+			'This is a unique name (slug) for this group. It helps you tell the difference between this group and other groups that may appear to be similar. It is not shown to registrants and HTML cannot be used.',
26
+			'event_espresso'
27
+		); ?>
28 28
     </li>
29 29
     <li>
30 30
         <strong><?php esc_html_e('Group Description', 'event_espresso'); ?></strong><br />
31 31
         <?php esc_html_e(
32
-            'This is the description for the question group as it will be shown on the registration form. This can be shown to registrants and HTML is allowed.',
33
-            'event_espresso'
34
-        ); ?>
32
+			'This is the description for the question group as it will be shown on the registration form. This can be shown to registrants and HTML is allowed.',
33
+			'event_espresso'
34
+		); ?>
35 35
     </li>
36 36
     <li>
37 37
         <strong><?php esc_html_e('Question Group Order', 'event_espresso'); ?></strong><br />
38 38
         <?php esc_html_e(
39
-            'Question Groups can be sorted by using the drag and drop feature on the Questions Group page. Another way to sort question groups is to adjust their order of application by using this field. A smaller order of application will be shown first. For example, a question group with an order of application of 1 will appear before one that has an order of application of 5.',
40
-            'event_espresso'
41
-        ); ?>
39
+			'Question Groups can be sorted by using the drag and drop feature on the Questions Group page. Another way to sort question groups is to adjust their order of application by using this field. A smaller order of application will be shown first. For example, a question group with an order of application of 1 will appear before one that has an order of application of 5.',
40
+			'event_espresso'
41
+		); ?>
42 42
     </li>
43 43
     <li>
44 44
         <strong><?php esc_html_e('Show Name', 'event_espresso'); ?></strong><br />
@@ -47,29 +47,29 @@  discard block
 block discarded – undo
47 47
     <li>
48 48
         <strong><?php esc_html_e('Show Description', 'event_espresso'); ?></strong><br />
49 49
         <?php esc_html_e(
50
-            'Whether the description for the question group be will displayed on the registration form.',
51
-            'event_espresso'
52
-        ); ?>
50
+			'Whether the description for the question group be will displayed on the registration form.',
51
+			'event_espresso'
52
+		); ?>
53 53
     </li>
54 54
     <li>
55 55
         <strong><?php esc_html_e('Questions that appear in this group', 'event_espresso'); ?></strong><br />
56 56
         <?php esc_html_e(
57
-            'This shows all available custom questions. If checked, then that question will appear with this question group. Questions that appear here can also be sorted using drag and drop.',
58
-            'event_espresso'
59
-        ); ?>
57
+			'This shows all available custom questions. If checked, then that question will appear with this question group. Questions that appear here can also be sorted using drag and drop.',
58
+			'event_espresso'
59
+		); ?>
60 60
     </li>
61 61
 </ul>
62 62
 <p>
63 63
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong><br />
64 64
     <?php esc_html_e(
65
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
66
-        'event_espresso'
67
-    ); ?>
65
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
66
+		'event_espresso'
67
+	); ?>
68 68
 </p>
69 69
 <p>
70 70
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong><br />
71 71
     <?php esc_html_e(
72
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
73
-        'event_espresso'
74
-    ); ?>
72
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
73
+		'event_espresso'
74
+	); ?>
75 75
 </p>
76 76
\ No newline at end of file
Please login to merge, or discard this patch.
registration_form/help_tabs/registration_form_question_groups.help_tab.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -3,23 +3,23 @@
 block discarded – undo
3 3
 </p>
4 4
 <p>
5 5
     <?php esc_html_e(
6
-        "This page shows all Question Groups that have been created for Event Espresso. Question Groups allow you to create modular registration forms. Each registration form consists of one or more question groups, and these are allocated on a per event basis.",
7
-        'event_espresso'
8
-    ); ?>
6
+		"This page shows all Question Groups that have been created for Event Espresso. Question Groups allow you to create modular registration forms. Each registration form consists of one or more question groups, and these are allocated on a per event basis.",
7
+		'event_espresso'
8
+	); ?>
9 9
 </p>
10 10
 <p>
11 11
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong>
12 12
     <br />
13 13
     <?php esc_html_e(
14
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
15
-        'event_espresso'
16
-    ); ?>
14
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
15
+		'event_espresso'
16
+	); ?>
17 17
 </p>
18 18
 <p>
19 19
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong>
20 20
     <br />
21 21
     <?php esc_html_e(
22
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
23
-        'event_espresso'
24
-    ); ?>
22
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
23
+		'event_espresso'
24
+	); ?>
25 25
 </p>
26 26
\ No newline at end of file
Please login to merge, or discard this patch.
registration_form/help_tabs/registration_form_edit_question.help_tab.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,34 +8,34 @@  discard block
 block discarded – undo
8 8
     <strong><?php esc_html_e('Notice', 'event_espresso'); ?></strong>
9 9
     <br />
10 10
     <?php esc_html_e(
11
-        'System questions may have some options disabled. This is to ensure that your registrations don\'t break from accidental changes.',
12
-        'event_espresso'
13
-    ); ?>
11
+		'System questions may have some options disabled. This is to ensure that your registrations don\'t break from accidental changes.',
12
+		'event_espresso'
13
+	); ?>
14 14
 </p>
15 15
 <ul>
16 16
     <li>
17 17
         <strong><?php esc_html_e('Question Text', 'event_espresso'); ?></strong>
18 18
         <br />
19 19
         <?php esc_html_e(
20
-            'This shows the question as it will be displayed on the registration form. HTML can be used here.',
21
-            'event_espresso'
22
-        ); ?>
20
+			'This shows the question as it will be displayed on the registration form. HTML can be used here.',
21
+			'event_espresso'
22
+		); ?>
23 23
     </li>
24 24
     <li>
25 25
         <strong><?php esc_html_e('Question Label (admin-only)', 'event_espresso'); ?></strong>
26 26
         <br />
27 27
         <?php esc_html_e(
28
-            'This field is only shown to the admin. It is useful for understanding the difference between questions that appear to be similar but are used in various situations. HTML cannot be used.',
29
-            'event_espresso'
30
-        ); ?>
28
+			'This field is only shown to the admin. It is useful for understanding the difference between questions that appear to be similar but are used in various situations. HTML cannot be used.',
29
+			'event_espresso'
30
+		); ?>
31 31
     </li>
32 32
     <li>
33 33
         <strong><?php esc_html_e('Question Order', 'event_espresso'); ?></strong>
34 34
         <br />
35 35
         <?php esc_html_e(
36
-            'Questions are now sorted per question group.  To order the questions edit a question group and you can reorder the questions attached to that group.',
37
-            'event_espresso'
38
-        ); ?>
36
+			'Questions are now sorted per question group.  To order the questions edit a question group and you can reorder the questions attached to that group.',
37
+			'event_espresso'
38
+		); ?>
39 39
     </li>
40 40
     <li>
41 41
         <strong><?php esc_html_e('Admin-Only Question?', 'event_espresso'); ?></strong>
@@ -46,17 +46,17 @@  discard block
 block discarded – undo
46 46
         <strong><?php esc_html_e('Question Type', 'event_espresso'); ?></strong>
47 47
         <br />
48 48
         <?php esc_html_e(
49
-            'This shows the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, Date Picker, and HTML Textarea (allowed tags: a, abbr, acronym, b, br, blockquote ,cite, code, del ,em, i, li, ol, p, q, s, strike, strong, ul).',
50
-            'event_espresso'
51
-        ); ?>
49
+			'This shows the type of question. Available options are Text, Textarea, Checkboxes, Radio Buttons, Dropdown, State/Province Dropdown, Country Dropdown, Date Picker, and HTML Textarea (allowed tags: a, abbr, acronym, b, br, blockquote ,cite, code, del ,em, i, li, ol, p, q, s, strike, strong, ul).',
50
+			'event_espresso'
51
+		); ?>
52 52
     </li>
53 53
     <li>
54 54
         <strong><?php esc_html_e('Answer Options (for applicable question types)', 'event_espresso'); ?></strong>
55 55
         <strong>
56 56
             <?php esc_html_e(
57
-                'Values do not allow any HTML, however, descriptions do allow HTML.',
58
-                'event_espresso'
59
-            ); ?>
57
+				'Values do not allow any HTML, however, descriptions do allow HTML.',
58
+				'event_espresso'
59
+			); ?>
60 60
         </strong>
61 61
     </li>
62 62
     <li>
@@ -68,24 +68,24 @@  discard block
 block discarded – undo
68 68
         <strong><?php esc_html_e('Required Text', 'event_espresso'); ?></strong>
69 69
         <br />
70 70
         <?php esc_html_e(
71
-            'This text is displayed when a registrant does not answer a question but is required to do so. The default message will show "this field is required."',
72
-            'event_espresso'
73
-        ); ?>
71
+			'This text is displayed when a registrant does not answer a question but is required to do so. The default message will show "this field is required."',
72
+			'event_espresso'
73
+		); ?>
74 74
     </li>
75 75
 </ul>
76 76
 <p>
77 77
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong>
78 78
     <br />
79 79
     <?php esc_html_e(
80
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
81
-        'event_espresso'
82
-    ); ?>
80
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
81
+		'event_espresso'
82
+	); ?>
83 83
 </p>
84 84
 <p>
85 85
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong>
86 86
     <br />
87 87
     <?php esc_html_e(
88
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
89
-        'event_espresso'
90
-    ); ?>
88
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
89
+		'event_espresso'
90
+	); ?>
91 91
 </p>
92 92
\ No newline at end of file
Please login to merge, or discard this patch.
help_tabs/registration_form_add_question_group.help_tab.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -8,81 +8,81 @@
 block discarded – undo
8 8
 </p>
9 9
 <p>
10 10
     <?php printf(
11
-        esc_html__('This page allows you to add a new question group for %s.', 'event_espresso'),
12
-        Domain::brandName()
13
-    ); ?>
11
+		esc_html__('This page allows you to add a new question group for %s.', 'event_espresso'),
12
+		Domain::brandName()
13
+	); ?>
14 14
 </p>
15 15
 <ul>
16 16
     <li>
17 17
         <strong><?php esc_html_e('Group Name', 'event_espresso'); ?></strong>
18 18
         <br />
19 19
         <?php esc_html_e(
20
-            'This is the name (title) of the question group as it will be displayed on the registration form. HTML cannot be used.',
21
-            'event_espresso'
22
-        ); ?>
20
+			'This is the name (title) of the question group as it will be displayed on the registration form. HTML cannot be used.',
21
+			'event_espresso'
22
+		); ?>
23 23
     </li>
24 24
     <li>
25 25
         <strong><?php esc_html_e('Group Identifier', 'event_espresso'); ?></strong>
26 26
         <br />
27 27
         <?php esc_html_e(
28
-            'This is a unique name (slug) for this group. It helps you tell the difference between this group and other groups that may appear to be similar. It is not shown to registrants and HTML cannot be used.',
29
-            'event_espresso'
30
-        ); ?>
28
+			'This is a unique name (slug) for this group. It helps you tell the difference between this group and other groups that may appear to be similar. It is not shown to registrants and HTML cannot be used.',
29
+			'event_espresso'
30
+		); ?>
31 31
     </li>
32 32
     <li>
33 33
         <strong><?php esc_html_e('Group Description', 'event_espresso'); ?></strong>
34 34
         <br />
35 35
         <?php esc_html_e(
36
-            'This is the description for the question group as it will be shown on the registration form. This can be shown to registrants and HTML is allowed.',
37
-            'event_espresso'
38
-        ); ?>
36
+			'This is the description for the question group as it will be shown on the registration form. This can be shown to registrants and HTML is allowed.',
37
+			'event_espresso'
38
+		); ?>
39 39
     </li>
40 40
     <li>
41 41
         <strong><?php esc_html_e('Question Group Order', 'event_espresso'); ?></strong>
42 42
         <br />
43 43
         <?php esc_html_e(
44
-            'Question Groups can be sorted by using the drag and drop feature on the Questions Group page. Another way to sort question groups is to adjust their order of application by using this field. A smaller order of application will be shown first. For example, a question group with an order of application of 1 will appear before one that has an order of application of 5.',
45
-            'event_espresso'
46
-        ); ?>
44
+			'Question Groups can be sorted by using the drag and drop feature on the Questions Group page. Another way to sort question groups is to adjust their order of application by using this field. A smaller order of application will be shown first. For example, a question group with an order of application of 1 will appear before one that has an order of application of 5.',
45
+			'event_espresso'
46
+		); ?>
47 47
     </li>
48 48
     <li>
49 49
         <strong><?php esc_html_e('Show Name', 'event_espresso'); ?></strong>
50 50
         <br />
51 51
         <?php esc_html_e(
52
-            'Whether the group name will be displayed on the registration form.',
53
-            'event_espresso'
54
-        ); ?>
52
+			'Whether the group name will be displayed on the registration form.',
53
+			'event_espresso'
54
+		); ?>
55 55
     </li>
56 56
     <li>
57 57
         <strong><?php esc_html_e('Show Description', 'event_espresso'); ?></strong>
58 58
         <br />
59 59
         <?php esc_html_e(
60
-            'Whether the description for the question group be will displayed on the registration form.',
61
-            'event_espresso'
62
-        ); ?>
60
+			'Whether the description for the question group be will displayed on the registration form.',
61
+			'event_espresso'
62
+		); ?>
63 63
     </li>
64 64
     <li>
65 65
         <strong><?php esc_html_e('Questions that appear in this group', 'event_espresso'); ?></strong>
66 66
         <br />
67 67
         <?php esc_html_e(
68
-            'This shows all available custom questions. If checked, then that question will appear with this question group.',
69
-            'event_espresso'
70
-        ); ?>
68
+			'This shows all available custom questions. If checked, then that question will appear with this question group.',
69
+			'event_espresso'
70
+		); ?>
71 71
     </li>
72 72
 </ul>
73 73
 <p>
74 74
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong>
75 75
     <br />
76 76
     <?php esc_html_e(
77
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
78
-        'event_espresso'
79
-    ); ?>
77
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
78
+		'event_espresso'
79
+	); ?>
80 80
 </p>
81 81
 <p>
82 82
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong>
83 83
     <br />
84 84
     <?php esc_html_e(
85
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
86
-        'event_espresso'
87
-    ); ?>
85
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content.',
86
+		'event_espresso'
87
+	); ?>
88 88
 </p>
89 89
\ No newline at end of file
Please login to merge, or discard this patch.
help_tabs/registration_form_questions_overview.help_tab.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,15 +8,15 @@
 block discarded – undo
8 8
     <strong><?php esc_html_e('Recommendations', 'event_espresso'); ?></strong>
9 9
     <br />
10 10
     <?php esc_html_e(
11
-        'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
12
-        'event_espresso'
13
-    ); ?>
11
+		'To learn more about the options on this page, take a look at the different tabs that appear on the left side of the page.',
12
+		'event_espresso'
13
+	); ?>
14 14
 </p>
15 15
 <p>
16 16
     <strong><?php esc_html_e('Screen Options', 'event_espresso'); ?></strong>
17 17
     <br />
18 18
     <?php esc_html_e(
19
-        'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for questions.',
20
-        'event_espresso'
21
-    ); ?>
19
+		'You can customize the information that is shown on this page by toggling the Screen Options tab. Then you can add or remove checkmarks to hide or show certain content and even adjust the pagination for questions.',
20
+		'event_espresso'
21
+	); ?>
22 22
 </p>
23 23
\ No newline at end of file
Please login to merge, or discard this patch.
caffeinated/admin/new/pricing/Pricing_Admin_Page.core.php 1 patch
Indentation   +1415 added lines, -1415 removed lines patch added patch discarded remove patch
@@ -12,1423 +12,1423 @@
 block discarded – undo
12 12
 class Pricing_Admin_Page extends EE_Admin_Page
13 13
 {
14 14
 
15
-    /**
16
-     *    constructor
17
-     *
18
-     * @Constructor
19
-     * @access public
20
-     * @param bool $routing
21
-     * @return Pricing_Admin_Page
22
-     */
23
-    public function __construct($routing = true)
24
-    {
25
-        parent::__construct($routing);
26
-    }
27
-
28
-
29
-    protected function _init_page_props()
30
-    {
31
-        $this->page_slug = PRICING_PG_SLUG;
32
-        $this->page_label = PRICING_LABEL;
33
-        $this->_admin_base_url = PRICING_ADMIN_URL;
34
-        $this->_admin_base_path = PRICING_ADMIN;
35
-    }
36
-
37
-
38
-    protected function _ajax_hooks()
39
-    {
40
-        add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order'));
41
-    }
42
-
43
-
44
-    protected function _define_page_props()
45
-    {
46
-        $this->_admin_page_title = PRICING_LABEL;
47
-        $this->_labels = array(
48
-            'buttons' => array(
49
-                'add'         => esc_html__('Add New Default Price', 'event_espresso'),
50
-                'edit'        => esc_html__('Edit Default Price', 'event_espresso'),
51
-                'delete'      => esc_html__('Delete Default Price', 'event_espresso'),
52
-                'add_type'    => esc_html__('Add New Default Price Type', 'event_espresso'),
53
-                'edit_type'   => esc_html__('Edit Price Type', 'event_espresso'),
54
-                'delete_type' => esc_html__('Delete Price Type', 'event_espresso'),
55
-            ),
56
-        );
57
-    }
58
-
59
-
60
-    /**
61
-     *        an array for storing request actions and their corresponding methods
62
-     *
63
-     * @access private
64
-     * @return void
65
-     */
66
-    protected function _set_page_routes()
67
-    {
68
-        $prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID'])
69
-            ? $this->_req_data['PRC_ID'] : 0;
70
-        $prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID'])
71
-            ? $this->_req_data['PRT_ID'] : 0;
72
-        $this->_page_routes = array(
73
-            'default'                     => array(
74
-                'func'       => '_price_overview_list_table',
75
-                'capability' => 'ee_read_default_prices',
76
-            ),
77
-            'add_new_price'               => array(
78
-                'func'       => '_edit_price_details',
79
-                'args'       => array('new_price' => true),
80
-                'capability' => 'ee_edit_default_prices',
81
-            ),
82
-            'edit_price'                  => array(
83
-                'func'       => '_edit_price_details',
84
-                'args'       => array('new_price' => false),
85
-                'capability' => 'ee_edit_default_price',
86
-                'obj_id'     => $prc_id,
87
-            ),
88
-            'insert_price'                => array(
89
-                'func'       => '_insert_or_update_price',
90
-                'args'       => array('new_price' => true),
91
-                'noheader'   => true,
92
-                'capability' => 'ee_edit_default_prices',
93
-            ),
94
-            'update_price'                => array(
95
-                'func'       => '_insert_or_update_price',
96
-                'args'       => array('new_price' => false),
97
-                'noheader'   => true,
98
-                'capability' => 'ee_edit_default_price',
99
-                'obj_id'     => $prc_id,
100
-            ),
101
-            'trash_price'                 => array(
102
-                'func'       => '_trash_or_restore_price',
103
-                'args'       => array('trash' => true),
104
-                'noheader'   => true,
105
-                'capability' => 'ee_delete_default_price',
106
-                'obj_id'     => $prc_id,
107
-            ),
108
-            'restore_price'               => array(
109
-                'func'       => '_trash_or_restore_price',
110
-                'args'       => array('trash' => false),
111
-                'noheader'   => true,
112
-                'capability' => 'ee_delete_default_price',
113
-                'obj_id'     => $prc_id,
114
-            ),
115
-            'delete_price'                => array(
116
-                'func'       => '_delete_price',
117
-                'noheader'   => true,
118
-                'capability' => 'ee_delete_default_price',
119
-                'obj_id'     => $prc_id,
120
-            ),
121
-            'espresso_update_price_order' => array(
122
-                'func'       => 'update_price_order',
123
-                'noheader'   => true,
124
-                'capability' => 'ee_edit_default_prices',
125
-            ),
126
-            // price types
127
-            'price_types'                 => array(
128
-                'func'       => '_price_types_overview_list_table',
129
-                'capability' => 'ee_read_default_price_types',
130
-            ),
131
-            'add_new_price_type'          => array(
132
-                'func'       => '_edit_price_type_details',
133
-                'capability' => 'ee_edit_default_price_types',
134
-            ),
135
-            'edit_price_type'             => array(
136
-                'func'       => '_edit_price_type_details',
137
-                'capability' => 'ee_edit_default_price_type',
138
-                'obj_id'     => $prt_id,
139
-            ),
140
-            'insert_price_type'           => array(
141
-                'func'       => '_insert_or_update_price_type',
142
-                'args'       => array('new_price_type' => true),
143
-                'noheader'   => true,
144
-                'capability' => 'ee_edit_default_price_types',
145
-            ),
146
-            'update_price_type'           => array(
147
-                'func'       => '_insert_or_update_price_type',
148
-                'args'       => array('new_price_type' => false),
149
-                'noheader'   => true,
150
-                'capability' => 'ee_edit_default_price_type',
151
-                'obj_id'     => $prt_id,
152
-            ),
153
-            'trash_price_type'            => array(
154
-                'func'       => '_trash_or_restore_price_type',
155
-                'args'       => array('trash' => true),
156
-                'noheader'   => true,
157
-                'capability' => 'ee_delete_default_price_type',
158
-                'obj_id'     => $prt_id,
159
-            ),
160
-            'restore_price_type'          => array(
161
-                'func'       => '_trash_or_restore_price_type',
162
-                'args'       => array('trash' => false),
163
-                'noheader'   => true,
164
-                'capability' => 'ee_delete_default_price_type',
165
-                'obj_id'     => $prt_id,
166
-            ),
167
-            'delete_price_type'           => array(
168
-                'func'       => '_delete_price_type',
169
-                'noheader'   => true,
170
-                'capability' => 'ee_delete_default_price_type',
171
-                'obj_id'     => $prt_id,
172
-            ),
173
-            'tax_settings'                => array(
174
-                'func'       => '_tax_settings',
175
-                'capability' => 'manage_options',
176
-            ),
177
-            'update_tax_settings'         => array(
178
-                'func'       => '_update_tax_settings',
179
-                'capability' => 'manage_options',
180
-                'noheader'   => true,
181
-            ),
182
-        );
183
-    }
184
-
185
-
186
-    protected function _set_page_config()
187
-    {
188
-
189
-        $this->_page_config = array(
190
-            'default'            => array(
191
-                'nav'           => array(
192
-                    'label' => esc_html__('Default Pricing', 'event_espresso'),
193
-                    'order' => 10,
194
-                ),
195
-                'list_table'    => 'Prices_List_Table',
196
-                'help_tabs'     => array(
197
-                    'pricing_default_pricing_help_tab'                           => array(
198
-                        'title'    => esc_html__('Default Pricing', 'event_espresso'),
199
-                        'filename' => 'pricing_default_pricing',
200
-                    ),
201
-                    'pricing_default_pricing_table_column_headings_help_tab'     => array(
202
-                        'title'    => esc_html__('Default Pricing Table Column Headings', 'event_espresso'),
203
-                        'filename' => 'pricing_default_pricing_table_column_headings',
204
-                    ),
205
-                    'pricing_default_pricing_views_bulk_actions_search_help_tab' => array(
206
-                        'title'    => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
207
-                        'filename' => 'pricing_default_pricing_views_bulk_actions_search',
208
-                    ),
209
-                ),
210
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
211
-                // 'help_tour'     => array('Pricing_Default_Prices_Help_Tour'),
212
-                'require_nonce' => false,
213
-            ),
214
-            'add_new_price'      => array(
215
-                'nav'           => array(
216
-                    'label'      => esc_html__('Add New Default Price', 'event_espresso'),
217
-                    'order'      => 20,
218
-                    'persistent' => false,
219
-                ),
220
-                'help_tabs'     => array(
221
-                    'add_new_default_price_help_tab' => array(
222
-                        'title'    => esc_html__('Add New Default Price', 'event_espresso'),
223
-                        'filename' => 'pricing_add_new_default_price',
224
-                    ),
225
-                ),
226
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
227
-                // 'help_tour'     => array('Pricing_Add_New_Default_Price_Help_Tour'),
228
-                'metaboxes'     => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'),
229
-                'require_nonce' => false,
230
-            ),
231
-            'edit_price'         => array(
232
-                'nav'           => array(
233
-                    'label'      => esc_html__('Edit Default Price', 'event_espresso'),
234
-                    'order'      => 20,
235
-                    'url'        => isset($this->_req_data['id']) ? add_query_arg(
236
-                        array('id' => $this->_req_data['id']),
237
-                        $this->_current_page_view_url
238
-                    ) : $this->_admin_base_url,
239
-                    'persistent' => false,
240
-                ),
241
-                'metaboxes'     => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'),
242
-                'help_tabs'     => array(
243
-                    'edit_default_price_help_tab' => array(
244
-                        'title'    => esc_html__('Edit Default Price', 'event_espresso'),
245
-                        'filename' => 'pricing_edit_default_price',
246
-                    ),
247
-                ),
248
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
249
-                // 'help_tour'     => array('Pricing_Edit_Default_Price_Help_Tour'),
250
-                'require_nonce' => false,
251
-            ),
252
-            'price_types'        => array(
253
-                'nav'           => array(
254
-                    'label' => esc_html__('Price Types', 'event_espresso'),
255
-                    'order' => 30,
256
-                ),
257
-                'list_table'    => 'Price_Types_List_Table',
258
-                'help_tabs'     => array(
259
-                    'pricing_price_types_help_tab'                           => array(
260
-                        'title'    => esc_html__('Price Types', 'event_espresso'),
261
-                        'filename' => 'pricing_price_types',
262
-                    ),
263
-                    'pricing_price_types_table_column_headings_help_tab'     => array(
264
-                        'title'    => esc_html__('Price Types Table Column Headings', 'event_espresso'),
265
-                        'filename' => 'pricing_price_types_table_column_headings',
266
-                    ),
267
-                    'pricing_price_types_views_bulk_actions_search_help_tab' => array(
268
-                        'title'    => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'),
269
-                        'filename' => 'pricing_price_types_views_bulk_actions_search',
270
-                    ),
271
-                ),
272
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
273
-                // 'help_tour'     => array('Pricing_Price_Types_Default_Help_Tour'),
274
-                'metaboxes'     => array('_espresso_news_post_box', '_espresso_links_post_box'),
275
-                'require_nonce' => false,
276
-            ),
277
-            'add_new_price_type' => array(
278
-                'nav'           => array(
279
-                    'label'      => esc_html__('Add New Price Type', 'event_espresso'),
280
-                    'order'      => 40,
281
-                    'persistent' => false,
282
-                ),
283
-                'help_tabs'     => array(
284
-                    'add_new_price_type_help_tab' => array(
285
-                        'title'    => esc_html__('Add New Price Type', 'event_espresso'),
286
-                        'filename' => 'pricing_add_new_price_type',
287
-                    ),
288
-                ),
289
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
290
-                // 'help_tour'     => array('Pricing_Add_New_Price_Type_Help_Tour'),
291
-                'metaboxes'     => array(
292
-                    '_publish_post_box',
293
-                    '_espresso_news_post_box',
294
-                    '_price_type_details_meta_boxes',
295
-                ),
296
-                'require_nonce' => false,
297
-            ),
298
-            'edit_price_type'    => array(
299
-                'nav'       => array(
300
-                    'label'      => esc_html__('Edit Price Type', 'event_espresso'),
301
-                    'order'      => 40,
302
-                    'persistent' => false,
303
-                ),
304
-                'help_tabs' => array(
305
-                    'edit_price_type_help_tab' => array(
306
-                        'title'    => esc_html__('Edit Price Type', 'event_espresso'),
307
-                        'filename' => 'pricing_edit_price_type',
308
-                    ),
309
-                ),
310
-                // disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
311
-                // 'help_tour' => array('Pricing_Edit_Price_Type_Help_Tour'),
312
-                'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'),
313
-
314
-                'require_nonce' => false,
315
-            ),
316
-            'tax_settings'       => array(
317
-                'nav'           => array(
318
-                    'label' => esc_html__('Tax Settings', 'event_espresso'),
319
-                    'order' => 40,
320
-                ),
321
-                'labels'        => array(
322
-                    'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'),
323
-                ),
324
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
325
-                'require_nonce' => true,
326
-            ),
327
-        );
328
-    }
329
-
330
-
331
-    protected function _add_screen_options()
332
-    {
333
-        // todo
334
-    }
335
-
336
-
337
-    protected function _add_screen_options_default()
338
-    {
339
-        $this->_per_page_screen_option();
340
-    }
341
-
342
-
343
-    protected function _add_screen_options_price_types()
344
-    {
345
-        $page_title = $this->_admin_page_title;
346
-        $this->_admin_page_title = esc_html__('Price Types', 'event_espresso');
347
-        $this->_per_page_screen_option();
348
-        $this->_admin_page_title = $page_title;
349
-    }
350
-
351
-
352
-    protected function _add_feature_pointers()
353
-    {
354
-    }
355
-
356
-
357
-    public function load_scripts_styles()
358
-    {
359
-        // styles
360
-        wp_enqueue_style('espresso-ui-theme');
361
-        wp_register_style(
362
-            'espresso_PRICING',
363
-            PRICING_ASSETS_URL . 'espresso_pricing_admin.css',
364
-            array(),
365
-            EVENT_ESPRESSO_VERSION
366
-        );
367
-        wp_enqueue_style('espresso_PRICING');
368
-
369
-        // scripts
370
-        wp_enqueue_script('ee_admin_js');
371
-        wp_enqueue_script('jquery-ui-position');
372
-        wp_enqueue_script('jquery-ui-widget');
373
-        // wp_enqueue_script('jquery-ui-dialog');
374
-        // wp_enqueue_script('jquery-ui-draggable');
375
-        // wp_enqueue_script('jquery-ui-datepicker');
376
-        wp_register_script(
377
-            'espresso_PRICING',
378
-            PRICING_ASSETS_URL . 'espresso_pricing_admin.js',
379
-            array('jquery'),
380
-            EVENT_ESPRESSO_VERSION,
381
-            true
382
-        );
383
-        wp_enqueue_script('espresso_PRICING');
384
-    }
385
-
386
-
387
-    public function load_scripts_styles_default()
388
-    {
389
-        wp_enqueue_script('espresso_ajax_table_sorting');
390
-    }
391
-
392
-
393
-    public function admin_footer_scripts()
394
-    {
395
-    }
396
-
397
-    public function admin_init()
398
-    {
399
-    }
400
-
401
-    public function admin_notices()
402
-    {
403
-    }
404
-
405
-
406
-    protected function _set_list_table_views_default()
407
-    {
408
-        $this->_views = array(
409
-            'all' => array(
410
-                'slug'        => 'all',
411
-                'label'       => esc_html__('View All Default Pricing', 'event_espresso'),
412
-                'count'       => 0,
413
-                'bulk_action' => array(
414
-                    'trash_price' => esc_html__('Move to Trash', 'event_espresso'),
415
-                ),
416
-            ),
417
-        );
418
-
419
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
420
-            $this->_views['trashed'] = array(
421
-                'slug'        => 'trashed',
422
-                'label'       => esc_html__('Trash', 'event_espresso'),
423
-                'count'       => 0,
424
-                'bulk_action' => array(
425
-                    'restore_price' => esc_html__('Restore from Trash', 'event_espresso'),
426
-                    'delete_price'  => esc_html__('Delete Permanently', 'event_espresso'),
427
-                ),
428
-            );
429
-        }
430
-    }
431
-
432
-
433
-    protected function _set_list_table_views_price_types()
434
-    {
435
-        $this->_views = array(
436
-            'all' => array(
437
-                'slug'        => 'all',
438
-                'label'       => esc_html__('All', 'event_espresso'),
439
-                'count'       => 0,
440
-                'bulk_action' => array(
441
-                    'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'),
442
-                ),
443
-            ),
444
-        );
445
-
446
-        if (
447
-            EE_Registry::instance()->CAP->current_user_can(
448
-                'ee_delete_default_price_types',
449
-                'pricing_trash_price_type'
450
-            )
451
-        ) {
452
-            $this->_views['trashed'] = array(
453
-                'slug'        => 'trashed',
454
-                'label'       => esc_html__('Trash', 'event_espresso'),
455
-                'count'       => 0,
456
-                'bulk_action' => array(
457
-                    'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'),
458
-                    'delete_price_type'  => esc_html__('Delete Permanently', 'event_espresso'),
459
-                ),
460
-            );
461
-        }
462
-    }
463
-
464
-
465
-    /**
466
-     *        generates HTML for main Prices Admin page
467
-     *
468
-     * @access protected
469
-     * @return void
470
-     */
471
-    protected function _price_overview_list_table()
472
-    {
473
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
474
-            'add_new_price',
475
-            'add',
476
-            array(),
477
-            'add-new-h2'
478
-        );
479
-        $this->admin_page_title .= $this->_learn_more_about_pricing_link();
480
-        $this->_search_btn_label = esc_html__('Default Prices', 'event_espresso');
481
-        $this->display_admin_list_table_page_with_no_sidebar();
482
-    }
483
-
484
-
485
-    /**
486
-     *    retrieve data for Prices List table
487
-     *
488
-     * @access public
489
-     * @param  int     $per_page how many prices displayed per page
490
-     * @param  boolean $count    return the count or objects
491
-     * @param  boolean $trashed  whether the current view is of the trash can - eww yuck!
492
-     * @return mixed (int|array)  int = count || array of price objects
493
-     */
494
-    public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false)
495
-    {
496
-
497
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
498
-        // start with an empty array
499
-        $event_pricing = array();
500
-
501
-        require_once(PRICING_ADMIN . 'Prices_List_Table.class.php');
502
-        require_once(EE_MODELS . 'EEM_Price.model.php');
503
-        // $PRC = EEM_Price::instance();
504
-
505
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby'];
506
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
507
-            : 'ASC';
508
-
509
-        switch ($this->_req_data['orderby']) {
510
-            case 'name':
511
-                $orderby = array('PRC_name' => $order);
512
-                break;
513
-            case 'type':
514
-                $orderby = array('Price_Type.PRT_name' => $order);
515
-                break;
516
-            case 'amount':
517
-                $orderby = array('PRC_amount' => $order);
518
-                break;
519
-            default:
520
-                $orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order);
521
-        }
522
-
523
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
524
-            ? $this->_req_data['paged'] : 1;
525
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
526
-            ? $this->_req_data['perpage'] : $per_page;
527
-
528
-        $_where = array(
529
-            'PRC_is_default' => 1,
530
-            'PRC_deleted'    => $trashed,
531
-        );
532
-
533
-        $offset = ($current_page - 1) * $per_page;
534
-        $limit = array($offset, $per_page);
535
-
536
-        if (isset($this->_req_data['s'])) {
537
-            $sstr = '%' . $this->_req_data['s'] . '%';
538
-            $_where['OR'] = array(
539
-                'PRC_name'            => array('LIKE', $sstr),
540
-                'PRC_desc'            => array('LIKE', $sstr),
541
-                'PRC_amount'          => array('LIKE', $sstr),
542
-                'Price_Type.PRT_name' => array('LIKE', $sstr),
543
-            );
544
-        }
545
-
546
-        $query_params = array(
547
-            $_where,
548
-            'order_by' => $orderby,
549
-            'limit'    => $limit,
550
-            'group_by' => 'PRC_ID',
551
-        );
552
-
553
-        if ($count) {
554
-            return $trashed ? EEM_Price::instance()->count(array($_where))
555
-                : EEM_Price::instance()->count_deleted_and_undeleted(array($_where));
556
-        } else {
557
-            return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
558
-        }
559
-    }
560
-
561
-
562
-    /**
563
-     *        _price_details
564
-     *
565
-     * @access protected
566
-     * @return void
567
-     */
568
-    protected function _edit_price_details()
569
-    {
570
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
571
-        // grab price ID
572
-        $PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id'])
573
-            : false;
574
-        // change page title based on request action
575
-        switch ($this->_req_action) {
576
-            case 'add_new_price':
577
-                $this->_admin_page_title = esc_html__('Add New Price', 'event_espresso');
578
-                break;
579
-            case 'edit_price':
580
-                $this->_admin_page_title = esc_html__('Edit Price', 'event_espresso');
581
-                break;
582
-            default:
583
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
584
-        }
585
-        // add PRC_ID to title if editing
586
-        $this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
587
-
588
-        // get prices
589
-        require_once(EE_MODELS . 'EEM_Price.model.php');
590
-        $PRC = EEM_Price::instance();
591
-
592
-        if ($PRC_ID) {
593
-            $price = $PRC->get_one_by_ID($PRC_ID);
594
-            $additional_hidden_fields = array(
595
-                'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID),
596
-            );
597
-            $this->_set_add_edit_form_tags('update_price', $additional_hidden_fields);
598
-        } else {
599
-            $price = $PRC->get_new_price();
600
-            $this->_set_add_edit_form_tags('insert_price');
601
-        }
602
-
603
-        $this->_template_args['PRC_ID'] = $PRC_ID;
604
-        $this->_template_args['price'] = $price;
605
-
606
-        // get price types
607
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
608
-        $PRT = EEM_Price_Type::instance();
609
-        $price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1))));
610
-        $price_type_names = array();
611
-        if (empty($price_types)) {
612
-            $msg = esc_html__(
613
-                'You have no price types defined. Please add a price type before adding a price.',
614
-                'event_espresso'
615
-            );
616
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
617
-            exit();
618
-        } else {
619
-            foreach ($price_types as $type) {
620
-                // if ($type->is_global()) {
621
-                $price_type_names[] = array('id' => $type->ID(), 'text' => $type->name());
622
-            // }
623
-            }
624
-        }
625
-
626
-        $this->_template_args['price_types'] = $price_type_names;
627
-        $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
628
-
629
-        $this->_set_publish_post_box_vars('id', $PRC_ID);
630
-        // the details template wrapper
631
-        $this->display_admin_page_with_sidebar();
632
-    }
633
-
634
-
635
-    /**
636
-     *        declare price details page metaboxes
637
-     *
638
-     * @access protected
639
-     * @return void
640
-     */
641
-    protected function _price_details_meta_boxes()
642
-    {
643
-        add_meta_box(
644
-            'edit-price-details-mbox',
645
-            esc_html__('Default Price Details', 'event_espresso'),
646
-            array($this, '_edit_price_details_meta_box'),
647
-            $this->wp_page_slug,
648
-            'normal',
649
-            'high'
650
-        );
651
-    }
652
-
653
-
654
-    /**
655
-     *        _edit_price_details_meta_box
656
-     *
657
-     * @access public
658
-     * @return void
659
-     */
660
-    public function _edit_price_details_meta_box()
661
-    {
662
-        echo EEH_Template::display_template(
663
-            PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php',
664
-            $this->_template_args,
665
-            true
666
-        );
667
-    }
668
-
669
-
670
-    /**
671
-     *        set_price_column_values
672
-     *
673
-     * @access protected
674
-     * @return array
675
-     */
676
-    protected function set_price_column_values()
677
-    {
678
-
679
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
680
-
681
-        $set_column_values = array(
682
-            'PRT_ID'         => absint($this->_req_data['PRT_ID']),
683
-            'PRC_amount'     => $this->_req_data['PRC_amount'],
684
-            'PRC_name'       => $this->_req_data['PRC_name'],
685
-            'PRC_desc'       => $this->_req_data['PRC_desc'],
686
-            'PRC_is_default' => 1,
687
-            'PRC_overrides'  => null,
688
-            'PRC_order'      => 0,
689
-            'PRC_deleted'    => 0,
690
-            'PRC_parent'     => 0,
691
-        );
692
-        return $set_column_values;
693
-    }
694
-
695
-
696
-    /**
697
-     *        insert_or_update_price
698
-     *
699
-     * @param boolean $insert - whether to insert or update
700
-     * @access protected
701
-     * @return void
702
-     */
703
-    protected function _insert_or_update_price($insert = false)
704
-    {
705
-
706
-        // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
707
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
708
-
709
-        require_once(EE_MODELS . 'EEM_Price.model.php');
710
-        $PRC = EEM_Price::instance();
711
-
712
-        // why be so pessimistic ???  : (
713
-        $success = 0;
714
-
715
-        $set_column_values = $this->set_price_column_values();
716
-        // is this a new Price ?
717
-        if ($insert) {
718
-            // run the insert
719
-            if ($PRC_ID = $PRC->insert($set_column_values)) {
720
-                // make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
721
-                $PR = EEM_price::instance()->get_one_by_ID($PRC_ID);
722
-                if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
723
-                    $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
724
-                    $ticket->_add_relation_to($PR, 'Price');
725
-                    $ticket->save();
726
-                }
727
-                $success = 1;
728
-            } else {
729
-                $PRC_ID = false;
730
-                $success = 0;
731
-            }
732
-            $action_desc = 'created';
733
-        } else {
734
-            $PRC_ID = absint($this->_req_data['PRC_ID']);
735
-            // run the update
736
-            $where_cols_n_values = array('PRC_ID' => $PRC_ID);
737
-            if ($PRC->update($set_column_values, array($where_cols_n_values))) {
738
-                $success = 1;
739
-            }
740
-
741
-            $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
742
-            if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
743
-                // if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated.
744
-                if ($PRC_ID === 1) {
745
-                    $ticket = $PR->get_first_related('Ticket');
746
-                    if ($ticket) {
747
-                        $ticket->set('TKT_price', $PR->get('PRC_amount'));
748
-                        $ticket->set('TKT_name', $PR->get('PRC_name'));
749
-                        $ticket->set('TKT_description', $PR->get('PRC_desc'));
750
-                        $ticket->save();
751
-                    }
752
-                } else {
753
-                    // we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type.
754
-                    $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
755
-                    $ticket->_add_relation_to($PRC_ID, 'Price');
756
-                    $ticket->save();
757
-                }
758
-            }
759
-
760
-            $action_desc = 'updated';
761
-        }
762
-
763
-        $query_args = array('action' => 'edit_price', 'id' => $PRC_ID);
764
-
765
-        $this->_redirect_after_action($success, 'Prices', $action_desc, $query_args);
766
-    }
767
-
768
-
769
-    /**
770
-     *        _trash_or_restore_price
771
-     *
772
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
773
-     * @access protected
774
-     * @return void
775
-     */
776
-    protected function _trash_or_restore_price($trash = true)
777
-    {
778
-
779
-        // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
780
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
781
-
782
-        require_once(EE_MODELS . 'EEM_Price.model.php');
783
-        $PRC = EEM_Price::instance();
784
-
785
-        $success = 1;
786
-        $PRC_deleted = $trash ? true : false;
787
-
788
-        // get base ticket for updating
789
-        $ticket = EEM_Ticket::instance()->get_one_by_ID(1);
790
-        // Checkboxes
791
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
792
-            // if array has more than one element than success message should be plural
793
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
794
-            // cycle thru checkboxes
795
-            while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) {
796
-                if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) {
797
-                    $success = 0;
798
-                } else {
799
-                    $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
800
-                    if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
801
-                        // if trashing then remove relations to base default ticket.  If restoring then add back to base default ticket
802
-                        if ($PRC_deleted) {
803
-                            $ticket->_remove_relation_to($PRC_ID, 'Price');
804
-                        } else {
805
-                            $ticket->_add_relation_to($PRC_ID, 'Price');
806
-                        }
807
-                        $ticket->save();
808
-                    }
809
-                }
810
-            }
811
-        } else {
812
-            // grab single id and delete
813
-            $PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
814
-            if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) {
815
-                $success = 0;
816
-            } else {
817
-                $PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
818
-                if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
819
-                    // if trashing then remove relations to base default ticket.  If restoring then add back to base default ticket
820
-                    if ($PRC_deleted) {
821
-                        $ticket->_remove_relation_to($PRC_ID, 'Price');
822
-                    } else {
823
-                        $ticket->_add_relation_to($PRC_ID, 'Price');
824
-                    }
825
-                    $ticket->save();
826
-                }
827
-            }
828
-        }
829
-        $query_args = array(
830
-            'action' => 'default',
831
-        );
832
-
833
-        if ($success) {
834
-            if ($trash) {
835
-                $msg = $success == 2
836
-                    ? esc_html__('The Prices have been trashed.', 'event_espresso')
837
-                    : esc_html__(
838
-                        'The Price has been trashed.',
839
-                        'event_espresso'
840
-                    );
841
-            } else {
842
-                $msg = $success == 2
843
-                    ? esc_html__('The Prices have been restored.', 'event_espresso')
844
-                    : esc_html__(
845
-                        'The Price has been restored.',
846
-                        'event_espresso'
847
-                    );
848
-            }
849
-
850
-            EE_Error::add_success($msg);
851
-        }
852
-
853
-        $this->_redirect_after_action(false, '', '', $query_args, true);
854
-    }
855
-
856
-
857
-    /**
858
-     *        _delete_price
859
-     *
860
-     * @access protected
861
-     * @return void
862
-     */
863
-    protected function _delete_price()
864
-    {
865
-
866
-        // echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
867
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
868
-
869
-        require_once(EE_MODELS . 'EEM_Price.model.php');
870
-        $PRC = EEM_Price::instance();
871
-
872
-        $success = 1;
873
-        // Checkboxes
874
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
875
-            // if array has more than one element than success message should be plural
876
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
877
-            // cycle thru bulk action checkboxes
878
-            while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) {
879
-                if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) {
880
-                    $success = 0;
881
-                }
882
-            }
883
-        } else {
884
-            // grab single id and delete
885
-            $PRC_ID = absint($this->_req_data['id']);
886
-            if (! $PRC->delete_permanently_by_ID($PRC_ID)) {
887
-                $success = 0;
888
-            }
889
-        }
890
-
891
-        $this->_redirect_after_action($success, 'Prices', 'deleted', array());
892
-    }
893
-
894
-
895
-    public function update_price_order()
896
-    {
897
-        $success = esc_html__('Price order was updated successfully.', 'event_espresso');
898
-
899
-        // grab our row IDs
900
-        $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode(
901
-            ',',
902
-            rtrim(
903
-                $this->_req_data['row_ids'],
904
-                ','
905
-            )
906
-        ) : false;
907
-
908
-        if (is_array($row_ids)) {
909
-            for ($i = 0; $i < count($row_ids); $i++) {
910
-                // Update the prices when re-ordering
911
-                $id = absint($row_ids[ $i ]);
912
-                if (
913
-                    EEM_Price::instance()->update(
914
-                        array('PRC_order' => $i + 1),
915
-                        array(array('PRC_ID' => $id))
916
-                    ) === false
917
-                ) {
918
-                    $success = false;
919
-                }
920
-            }
921
-        } else {
922
-            $success = false;
923
-        }
924
-
925
-        $errors = ! $success ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso') : false;
926
-
927
-        echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors));
928
-        die();
929
-    }
930
-
931
-
932
-
933
-
934
-
935
-
936
-    /**************************************************************************************************************************************************************
15
+	/**
16
+	 *    constructor
17
+	 *
18
+	 * @Constructor
19
+	 * @access public
20
+	 * @param bool $routing
21
+	 * @return Pricing_Admin_Page
22
+	 */
23
+	public function __construct($routing = true)
24
+	{
25
+		parent::__construct($routing);
26
+	}
27
+
28
+
29
+	protected function _init_page_props()
30
+	{
31
+		$this->page_slug = PRICING_PG_SLUG;
32
+		$this->page_label = PRICING_LABEL;
33
+		$this->_admin_base_url = PRICING_ADMIN_URL;
34
+		$this->_admin_base_path = PRICING_ADMIN;
35
+	}
36
+
37
+
38
+	protected function _ajax_hooks()
39
+	{
40
+		add_action('wp_ajax_espresso_update_prices_order', array($this, 'update_price_order'));
41
+	}
42
+
43
+
44
+	protected function _define_page_props()
45
+	{
46
+		$this->_admin_page_title = PRICING_LABEL;
47
+		$this->_labels = array(
48
+			'buttons' => array(
49
+				'add'         => esc_html__('Add New Default Price', 'event_espresso'),
50
+				'edit'        => esc_html__('Edit Default Price', 'event_espresso'),
51
+				'delete'      => esc_html__('Delete Default Price', 'event_espresso'),
52
+				'add_type'    => esc_html__('Add New Default Price Type', 'event_espresso'),
53
+				'edit_type'   => esc_html__('Edit Price Type', 'event_espresso'),
54
+				'delete_type' => esc_html__('Delete Price Type', 'event_espresso'),
55
+			),
56
+		);
57
+	}
58
+
59
+
60
+	/**
61
+	 *        an array for storing request actions and their corresponding methods
62
+	 *
63
+	 * @access private
64
+	 * @return void
65
+	 */
66
+	protected function _set_page_routes()
67
+	{
68
+		$prc_id = ! empty($this->_req_data['PRC_ID']) && ! is_array($this->_req_data['PRC_ID'])
69
+			? $this->_req_data['PRC_ID'] : 0;
70
+		$prt_id = ! empty($this->_req_data['PRT_ID']) && ! is_array($this->_req_data['PRT_ID'])
71
+			? $this->_req_data['PRT_ID'] : 0;
72
+		$this->_page_routes = array(
73
+			'default'                     => array(
74
+				'func'       => '_price_overview_list_table',
75
+				'capability' => 'ee_read_default_prices',
76
+			),
77
+			'add_new_price'               => array(
78
+				'func'       => '_edit_price_details',
79
+				'args'       => array('new_price' => true),
80
+				'capability' => 'ee_edit_default_prices',
81
+			),
82
+			'edit_price'                  => array(
83
+				'func'       => '_edit_price_details',
84
+				'args'       => array('new_price' => false),
85
+				'capability' => 'ee_edit_default_price',
86
+				'obj_id'     => $prc_id,
87
+			),
88
+			'insert_price'                => array(
89
+				'func'       => '_insert_or_update_price',
90
+				'args'       => array('new_price' => true),
91
+				'noheader'   => true,
92
+				'capability' => 'ee_edit_default_prices',
93
+			),
94
+			'update_price'                => array(
95
+				'func'       => '_insert_or_update_price',
96
+				'args'       => array('new_price' => false),
97
+				'noheader'   => true,
98
+				'capability' => 'ee_edit_default_price',
99
+				'obj_id'     => $prc_id,
100
+			),
101
+			'trash_price'                 => array(
102
+				'func'       => '_trash_or_restore_price',
103
+				'args'       => array('trash' => true),
104
+				'noheader'   => true,
105
+				'capability' => 'ee_delete_default_price',
106
+				'obj_id'     => $prc_id,
107
+			),
108
+			'restore_price'               => array(
109
+				'func'       => '_trash_or_restore_price',
110
+				'args'       => array('trash' => false),
111
+				'noheader'   => true,
112
+				'capability' => 'ee_delete_default_price',
113
+				'obj_id'     => $prc_id,
114
+			),
115
+			'delete_price'                => array(
116
+				'func'       => '_delete_price',
117
+				'noheader'   => true,
118
+				'capability' => 'ee_delete_default_price',
119
+				'obj_id'     => $prc_id,
120
+			),
121
+			'espresso_update_price_order' => array(
122
+				'func'       => 'update_price_order',
123
+				'noheader'   => true,
124
+				'capability' => 'ee_edit_default_prices',
125
+			),
126
+			// price types
127
+			'price_types'                 => array(
128
+				'func'       => '_price_types_overview_list_table',
129
+				'capability' => 'ee_read_default_price_types',
130
+			),
131
+			'add_new_price_type'          => array(
132
+				'func'       => '_edit_price_type_details',
133
+				'capability' => 'ee_edit_default_price_types',
134
+			),
135
+			'edit_price_type'             => array(
136
+				'func'       => '_edit_price_type_details',
137
+				'capability' => 'ee_edit_default_price_type',
138
+				'obj_id'     => $prt_id,
139
+			),
140
+			'insert_price_type'           => array(
141
+				'func'       => '_insert_or_update_price_type',
142
+				'args'       => array('new_price_type' => true),
143
+				'noheader'   => true,
144
+				'capability' => 'ee_edit_default_price_types',
145
+			),
146
+			'update_price_type'           => array(
147
+				'func'       => '_insert_or_update_price_type',
148
+				'args'       => array('new_price_type' => false),
149
+				'noheader'   => true,
150
+				'capability' => 'ee_edit_default_price_type',
151
+				'obj_id'     => $prt_id,
152
+			),
153
+			'trash_price_type'            => array(
154
+				'func'       => '_trash_or_restore_price_type',
155
+				'args'       => array('trash' => true),
156
+				'noheader'   => true,
157
+				'capability' => 'ee_delete_default_price_type',
158
+				'obj_id'     => $prt_id,
159
+			),
160
+			'restore_price_type'          => array(
161
+				'func'       => '_trash_or_restore_price_type',
162
+				'args'       => array('trash' => false),
163
+				'noheader'   => true,
164
+				'capability' => 'ee_delete_default_price_type',
165
+				'obj_id'     => $prt_id,
166
+			),
167
+			'delete_price_type'           => array(
168
+				'func'       => '_delete_price_type',
169
+				'noheader'   => true,
170
+				'capability' => 'ee_delete_default_price_type',
171
+				'obj_id'     => $prt_id,
172
+			),
173
+			'tax_settings'                => array(
174
+				'func'       => '_tax_settings',
175
+				'capability' => 'manage_options',
176
+			),
177
+			'update_tax_settings'         => array(
178
+				'func'       => '_update_tax_settings',
179
+				'capability' => 'manage_options',
180
+				'noheader'   => true,
181
+			),
182
+		);
183
+	}
184
+
185
+
186
+	protected function _set_page_config()
187
+	{
188
+
189
+		$this->_page_config = array(
190
+			'default'            => array(
191
+				'nav'           => array(
192
+					'label' => esc_html__('Default Pricing', 'event_espresso'),
193
+					'order' => 10,
194
+				),
195
+				'list_table'    => 'Prices_List_Table',
196
+				'help_tabs'     => array(
197
+					'pricing_default_pricing_help_tab'                           => array(
198
+						'title'    => esc_html__('Default Pricing', 'event_espresso'),
199
+						'filename' => 'pricing_default_pricing',
200
+					),
201
+					'pricing_default_pricing_table_column_headings_help_tab'     => array(
202
+						'title'    => esc_html__('Default Pricing Table Column Headings', 'event_espresso'),
203
+						'filename' => 'pricing_default_pricing_table_column_headings',
204
+					),
205
+					'pricing_default_pricing_views_bulk_actions_search_help_tab' => array(
206
+						'title'    => esc_html__('Default Pricing Views & Bulk Actions & Search', 'event_espresso'),
207
+						'filename' => 'pricing_default_pricing_views_bulk_actions_search',
208
+					),
209
+				),
210
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
211
+				// 'help_tour'     => array('Pricing_Default_Prices_Help_Tour'),
212
+				'require_nonce' => false,
213
+			),
214
+			'add_new_price'      => array(
215
+				'nav'           => array(
216
+					'label'      => esc_html__('Add New Default Price', 'event_espresso'),
217
+					'order'      => 20,
218
+					'persistent' => false,
219
+				),
220
+				'help_tabs'     => array(
221
+					'add_new_default_price_help_tab' => array(
222
+						'title'    => esc_html__('Add New Default Price', 'event_espresso'),
223
+						'filename' => 'pricing_add_new_default_price',
224
+					),
225
+				),
226
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
227
+				// 'help_tour'     => array('Pricing_Add_New_Default_Price_Help_Tour'),
228
+				'metaboxes'     => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'),
229
+				'require_nonce' => false,
230
+			),
231
+			'edit_price'         => array(
232
+				'nav'           => array(
233
+					'label'      => esc_html__('Edit Default Price', 'event_espresso'),
234
+					'order'      => 20,
235
+					'url'        => isset($this->_req_data['id']) ? add_query_arg(
236
+						array('id' => $this->_req_data['id']),
237
+						$this->_current_page_view_url
238
+					) : $this->_admin_base_url,
239
+					'persistent' => false,
240
+				),
241
+				'metaboxes'     => array('_publish_post_box', '_espresso_news_post_box', '_price_details_meta_boxes'),
242
+				'help_tabs'     => array(
243
+					'edit_default_price_help_tab' => array(
244
+						'title'    => esc_html__('Edit Default Price', 'event_espresso'),
245
+						'filename' => 'pricing_edit_default_price',
246
+					),
247
+				),
248
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
249
+				// 'help_tour'     => array('Pricing_Edit_Default_Price_Help_Tour'),
250
+				'require_nonce' => false,
251
+			),
252
+			'price_types'        => array(
253
+				'nav'           => array(
254
+					'label' => esc_html__('Price Types', 'event_espresso'),
255
+					'order' => 30,
256
+				),
257
+				'list_table'    => 'Price_Types_List_Table',
258
+				'help_tabs'     => array(
259
+					'pricing_price_types_help_tab'                           => array(
260
+						'title'    => esc_html__('Price Types', 'event_espresso'),
261
+						'filename' => 'pricing_price_types',
262
+					),
263
+					'pricing_price_types_table_column_headings_help_tab'     => array(
264
+						'title'    => esc_html__('Price Types Table Column Headings', 'event_espresso'),
265
+						'filename' => 'pricing_price_types_table_column_headings',
266
+					),
267
+					'pricing_price_types_views_bulk_actions_search_help_tab' => array(
268
+						'title'    => esc_html__('Price Types Views & Bulk Actions & Search', 'event_espresso'),
269
+						'filename' => 'pricing_price_types_views_bulk_actions_search',
270
+					),
271
+				),
272
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
273
+				// 'help_tour'     => array('Pricing_Price_Types_Default_Help_Tour'),
274
+				'metaboxes'     => array('_espresso_news_post_box', '_espresso_links_post_box'),
275
+				'require_nonce' => false,
276
+			),
277
+			'add_new_price_type' => array(
278
+				'nav'           => array(
279
+					'label'      => esc_html__('Add New Price Type', 'event_espresso'),
280
+					'order'      => 40,
281
+					'persistent' => false,
282
+				),
283
+				'help_tabs'     => array(
284
+					'add_new_price_type_help_tab' => array(
285
+						'title'    => esc_html__('Add New Price Type', 'event_espresso'),
286
+						'filename' => 'pricing_add_new_price_type',
287
+					),
288
+				),
289
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
290
+				// 'help_tour'     => array('Pricing_Add_New_Price_Type_Help_Tour'),
291
+				'metaboxes'     => array(
292
+					'_publish_post_box',
293
+					'_espresso_news_post_box',
294
+					'_price_type_details_meta_boxes',
295
+				),
296
+				'require_nonce' => false,
297
+			),
298
+			'edit_price_type'    => array(
299
+				'nav'       => array(
300
+					'label'      => esc_html__('Edit Price Type', 'event_espresso'),
301
+					'order'      => 40,
302
+					'persistent' => false,
303
+				),
304
+				'help_tabs' => array(
305
+					'edit_price_type_help_tab' => array(
306
+						'title'    => esc_html__('Edit Price Type', 'event_espresso'),
307
+						'filename' => 'pricing_edit_price_type',
308
+					),
309
+				),
310
+				// disabled temporarily. see: https://github.com/eventespresso/eventsmart.com-website/issues/836
311
+				// 'help_tour' => array('Pricing_Edit_Price_Type_Help_Tour'),
312
+				'metaboxes' => array('_publish_post_box', '_espresso_news_post_box', '_price_type_details_meta_boxes'),
313
+
314
+				'require_nonce' => false,
315
+			),
316
+			'tax_settings'       => array(
317
+				'nav'           => array(
318
+					'label' => esc_html__('Tax Settings', 'event_espresso'),
319
+					'order' => 40,
320
+				),
321
+				'labels'        => array(
322
+					'publishbox' => esc_html__('Update Tax Settings', 'event_espresso'),
323
+				),
324
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
325
+				'require_nonce' => true,
326
+			),
327
+		);
328
+	}
329
+
330
+
331
+	protected function _add_screen_options()
332
+	{
333
+		// todo
334
+	}
335
+
336
+
337
+	protected function _add_screen_options_default()
338
+	{
339
+		$this->_per_page_screen_option();
340
+	}
341
+
342
+
343
+	protected function _add_screen_options_price_types()
344
+	{
345
+		$page_title = $this->_admin_page_title;
346
+		$this->_admin_page_title = esc_html__('Price Types', 'event_espresso');
347
+		$this->_per_page_screen_option();
348
+		$this->_admin_page_title = $page_title;
349
+	}
350
+
351
+
352
+	protected function _add_feature_pointers()
353
+	{
354
+	}
355
+
356
+
357
+	public function load_scripts_styles()
358
+	{
359
+		// styles
360
+		wp_enqueue_style('espresso-ui-theme');
361
+		wp_register_style(
362
+			'espresso_PRICING',
363
+			PRICING_ASSETS_URL . 'espresso_pricing_admin.css',
364
+			array(),
365
+			EVENT_ESPRESSO_VERSION
366
+		);
367
+		wp_enqueue_style('espresso_PRICING');
368
+
369
+		// scripts
370
+		wp_enqueue_script('ee_admin_js');
371
+		wp_enqueue_script('jquery-ui-position');
372
+		wp_enqueue_script('jquery-ui-widget');
373
+		// wp_enqueue_script('jquery-ui-dialog');
374
+		// wp_enqueue_script('jquery-ui-draggable');
375
+		// wp_enqueue_script('jquery-ui-datepicker');
376
+		wp_register_script(
377
+			'espresso_PRICING',
378
+			PRICING_ASSETS_URL . 'espresso_pricing_admin.js',
379
+			array('jquery'),
380
+			EVENT_ESPRESSO_VERSION,
381
+			true
382
+		);
383
+		wp_enqueue_script('espresso_PRICING');
384
+	}
385
+
386
+
387
+	public function load_scripts_styles_default()
388
+	{
389
+		wp_enqueue_script('espresso_ajax_table_sorting');
390
+	}
391
+
392
+
393
+	public function admin_footer_scripts()
394
+	{
395
+	}
396
+
397
+	public function admin_init()
398
+	{
399
+	}
400
+
401
+	public function admin_notices()
402
+	{
403
+	}
404
+
405
+
406
+	protected function _set_list_table_views_default()
407
+	{
408
+		$this->_views = array(
409
+			'all' => array(
410
+				'slug'        => 'all',
411
+				'label'       => esc_html__('View All Default Pricing', 'event_espresso'),
412
+				'count'       => 0,
413
+				'bulk_action' => array(
414
+					'trash_price' => esc_html__('Move to Trash', 'event_espresso'),
415
+				),
416
+			),
417
+		);
418
+
419
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) {
420
+			$this->_views['trashed'] = array(
421
+				'slug'        => 'trashed',
422
+				'label'       => esc_html__('Trash', 'event_espresso'),
423
+				'count'       => 0,
424
+				'bulk_action' => array(
425
+					'restore_price' => esc_html__('Restore from Trash', 'event_espresso'),
426
+					'delete_price'  => esc_html__('Delete Permanently', 'event_espresso'),
427
+				),
428
+			);
429
+		}
430
+	}
431
+
432
+
433
+	protected function _set_list_table_views_price_types()
434
+	{
435
+		$this->_views = array(
436
+			'all' => array(
437
+				'slug'        => 'all',
438
+				'label'       => esc_html__('All', 'event_espresso'),
439
+				'count'       => 0,
440
+				'bulk_action' => array(
441
+					'trash_price_type' => esc_html__('Move to Trash', 'event_espresso'),
442
+				),
443
+			),
444
+		);
445
+
446
+		if (
447
+			EE_Registry::instance()->CAP->current_user_can(
448
+				'ee_delete_default_price_types',
449
+				'pricing_trash_price_type'
450
+			)
451
+		) {
452
+			$this->_views['trashed'] = array(
453
+				'slug'        => 'trashed',
454
+				'label'       => esc_html__('Trash', 'event_espresso'),
455
+				'count'       => 0,
456
+				'bulk_action' => array(
457
+					'restore_price_type' => esc_html__('Restore from Trash', 'event_espresso'),
458
+					'delete_price_type'  => esc_html__('Delete Permanently', 'event_espresso'),
459
+				),
460
+			);
461
+		}
462
+	}
463
+
464
+
465
+	/**
466
+	 *        generates HTML for main Prices Admin page
467
+	 *
468
+	 * @access protected
469
+	 * @return void
470
+	 */
471
+	protected function _price_overview_list_table()
472
+	{
473
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
474
+			'add_new_price',
475
+			'add',
476
+			array(),
477
+			'add-new-h2'
478
+		);
479
+		$this->admin_page_title .= $this->_learn_more_about_pricing_link();
480
+		$this->_search_btn_label = esc_html__('Default Prices', 'event_espresso');
481
+		$this->display_admin_list_table_page_with_no_sidebar();
482
+	}
483
+
484
+
485
+	/**
486
+	 *    retrieve data for Prices List table
487
+	 *
488
+	 * @access public
489
+	 * @param  int     $per_page how many prices displayed per page
490
+	 * @param  boolean $count    return the count or objects
491
+	 * @param  boolean $trashed  whether the current view is of the trash can - eww yuck!
492
+	 * @return mixed (int|array)  int = count || array of price objects
493
+	 */
494
+	public function get_prices_overview_data($per_page = 10, $count = false, $trashed = false)
495
+	{
496
+
497
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
498
+		// start with an empty array
499
+		$event_pricing = array();
500
+
501
+		require_once(PRICING_ADMIN . 'Prices_List_Table.class.php');
502
+		require_once(EE_MODELS . 'EEM_Price.model.php');
503
+		// $PRC = EEM_Price::instance();
504
+
505
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby'];
506
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
507
+			: 'ASC';
508
+
509
+		switch ($this->_req_data['orderby']) {
510
+			case 'name':
511
+				$orderby = array('PRC_name' => $order);
512
+				break;
513
+			case 'type':
514
+				$orderby = array('Price_Type.PRT_name' => $order);
515
+				break;
516
+			case 'amount':
517
+				$orderby = array('PRC_amount' => $order);
518
+				break;
519
+			default:
520
+				$orderby = array('PRC_order' => $order, 'Price_Type.PRT_order' => $order, 'PRC_ID' => $order);
521
+		}
522
+
523
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
524
+			? $this->_req_data['paged'] : 1;
525
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
526
+			? $this->_req_data['perpage'] : $per_page;
527
+
528
+		$_where = array(
529
+			'PRC_is_default' => 1,
530
+			'PRC_deleted'    => $trashed,
531
+		);
532
+
533
+		$offset = ($current_page - 1) * $per_page;
534
+		$limit = array($offset, $per_page);
535
+
536
+		if (isset($this->_req_data['s'])) {
537
+			$sstr = '%' . $this->_req_data['s'] . '%';
538
+			$_where['OR'] = array(
539
+				'PRC_name'            => array('LIKE', $sstr),
540
+				'PRC_desc'            => array('LIKE', $sstr),
541
+				'PRC_amount'          => array('LIKE', $sstr),
542
+				'Price_Type.PRT_name' => array('LIKE', $sstr),
543
+			);
544
+		}
545
+
546
+		$query_params = array(
547
+			$_where,
548
+			'order_by' => $orderby,
549
+			'limit'    => $limit,
550
+			'group_by' => 'PRC_ID',
551
+		);
552
+
553
+		if ($count) {
554
+			return $trashed ? EEM_Price::instance()->count(array($_where))
555
+				: EEM_Price::instance()->count_deleted_and_undeleted(array($_where));
556
+		} else {
557
+			return EEM_Price::instance()->get_all_deleted_and_undeleted($query_params);
558
+		}
559
+	}
560
+
561
+
562
+	/**
563
+	 *        _price_details
564
+	 *
565
+	 * @access protected
566
+	 * @return void
567
+	 */
568
+	protected function _edit_price_details()
569
+	{
570
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
571
+		// grab price ID
572
+		$PRC_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id'])
573
+			: false;
574
+		// change page title based on request action
575
+		switch ($this->_req_action) {
576
+			case 'add_new_price':
577
+				$this->_admin_page_title = esc_html__('Add New Price', 'event_espresso');
578
+				break;
579
+			case 'edit_price':
580
+				$this->_admin_page_title = esc_html__('Edit Price', 'event_espresso');
581
+				break;
582
+			default:
583
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
584
+		}
585
+		// add PRC_ID to title if editing
586
+		$this->_admin_page_title = $PRC_ID ? $this->_admin_page_title . ' # ' . $PRC_ID : $this->_admin_page_title;
587
+
588
+		// get prices
589
+		require_once(EE_MODELS . 'EEM_Price.model.php');
590
+		$PRC = EEM_Price::instance();
591
+
592
+		if ($PRC_ID) {
593
+			$price = $PRC->get_one_by_ID($PRC_ID);
594
+			$additional_hidden_fields = array(
595
+				'PRC_ID' => array('type' => 'hidden', 'value' => $PRC_ID),
596
+			);
597
+			$this->_set_add_edit_form_tags('update_price', $additional_hidden_fields);
598
+		} else {
599
+			$price = $PRC->get_new_price();
600
+			$this->_set_add_edit_form_tags('insert_price');
601
+		}
602
+
603
+		$this->_template_args['PRC_ID'] = $PRC_ID;
604
+		$this->_template_args['price'] = $price;
605
+
606
+		// get price types
607
+		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
608
+		$PRT = EEM_Price_Type::instance();
609
+		$price_types = $PRT->get_all(array(array('PBT_ID' => array('!=', 1))));
610
+		$price_type_names = array();
611
+		if (empty($price_types)) {
612
+			$msg = esc_html__(
613
+				'You have no price types defined. Please add a price type before adding a price.',
614
+				'event_espresso'
615
+			);
616
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
617
+			exit();
618
+		} else {
619
+			foreach ($price_types as $type) {
620
+				// if ($type->is_global()) {
621
+				$price_type_names[] = array('id' => $type->ID(), 'text' => $type->name());
622
+			// }
623
+			}
624
+		}
625
+
626
+		$this->_template_args['price_types'] = $price_type_names;
627
+		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
628
+
629
+		$this->_set_publish_post_box_vars('id', $PRC_ID);
630
+		// the details template wrapper
631
+		$this->display_admin_page_with_sidebar();
632
+	}
633
+
634
+
635
+	/**
636
+	 *        declare price details page metaboxes
637
+	 *
638
+	 * @access protected
639
+	 * @return void
640
+	 */
641
+	protected function _price_details_meta_boxes()
642
+	{
643
+		add_meta_box(
644
+			'edit-price-details-mbox',
645
+			esc_html__('Default Price Details', 'event_espresso'),
646
+			array($this, '_edit_price_details_meta_box'),
647
+			$this->wp_page_slug,
648
+			'normal',
649
+			'high'
650
+		);
651
+	}
652
+
653
+
654
+	/**
655
+	 *        _edit_price_details_meta_box
656
+	 *
657
+	 * @access public
658
+	 * @return void
659
+	 */
660
+	public function _edit_price_details_meta_box()
661
+	{
662
+		echo EEH_Template::display_template(
663
+			PRICING_TEMPLATE_PATH . 'pricing_details_main_meta_box.template.php',
664
+			$this->_template_args,
665
+			true
666
+		);
667
+	}
668
+
669
+
670
+	/**
671
+	 *        set_price_column_values
672
+	 *
673
+	 * @access protected
674
+	 * @return array
675
+	 */
676
+	protected function set_price_column_values()
677
+	{
678
+
679
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
680
+
681
+		$set_column_values = array(
682
+			'PRT_ID'         => absint($this->_req_data['PRT_ID']),
683
+			'PRC_amount'     => $this->_req_data['PRC_amount'],
684
+			'PRC_name'       => $this->_req_data['PRC_name'],
685
+			'PRC_desc'       => $this->_req_data['PRC_desc'],
686
+			'PRC_is_default' => 1,
687
+			'PRC_overrides'  => null,
688
+			'PRC_order'      => 0,
689
+			'PRC_deleted'    => 0,
690
+			'PRC_parent'     => 0,
691
+		);
692
+		return $set_column_values;
693
+	}
694
+
695
+
696
+	/**
697
+	 *        insert_or_update_price
698
+	 *
699
+	 * @param boolean $insert - whether to insert or update
700
+	 * @access protected
701
+	 * @return void
702
+	 */
703
+	protected function _insert_or_update_price($insert = false)
704
+	{
705
+
706
+		// echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
707
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
708
+
709
+		require_once(EE_MODELS . 'EEM_Price.model.php');
710
+		$PRC = EEM_Price::instance();
711
+
712
+		// why be so pessimistic ???  : (
713
+		$success = 0;
714
+
715
+		$set_column_values = $this->set_price_column_values();
716
+		// is this a new Price ?
717
+		if ($insert) {
718
+			// run the insert
719
+			if ($PRC_ID = $PRC->insert($set_column_values)) {
720
+				// make sure this new price modifier is attached to the ticket but ONLY if it is not a tax type
721
+				$PR = EEM_price::instance()->get_one_by_ID($PRC_ID);
722
+				if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
723
+					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
724
+					$ticket->_add_relation_to($PR, 'Price');
725
+					$ticket->save();
726
+				}
727
+				$success = 1;
728
+			} else {
729
+				$PRC_ID = false;
730
+				$success = 0;
731
+			}
732
+			$action_desc = 'created';
733
+		} else {
734
+			$PRC_ID = absint($this->_req_data['PRC_ID']);
735
+			// run the update
736
+			$where_cols_n_values = array('PRC_ID' => $PRC_ID);
737
+			if ($PRC->update($set_column_values, array($where_cols_n_values))) {
738
+				$success = 1;
739
+			}
740
+
741
+			$PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
742
+			if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
743
+				// if this is $PRC_ID == 1, then we need to update the default ticket attached to this price so the TKT_price value is updated.
744
+				if ($PRC_ID === 1) {
745
+					$ticket = $PR->get_first_related('Ticket');
746
+					if ($ticket) {
747
+						$ticket->set('TKT_price', $PR->get('PRC_amount'));
748
+						$ticket->set('TKT_name', $PR->get('PRC_name'));
749
+						$ticket->set('TKT_description', $PR->get('PRC_desc'));
750
+						$ticket->save();
751
+					}
752
+				} else {
753
+					// we make sure this price is attached to base ticket. but ONLY if its not a tax ticket type.
754
+					$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
755
+					$ticket->_add_relation_to($PRC_ID, 'Price');
756
+					$ticket->save();
757
+				}
758
+			}
759
+
760
+			$action_desc = 'updated';
761
+		}
762
+
763
+		$query_args = array('action' => 'edit_price', 'id' => $PRC_ID);
764
+
765
+		$this->_redirect_after_action($success, 'Prices', $action_desc, $query_args);
766
+	}
767
+
768
+
769
+	/**
770
+	 *        _trash_or_restore_price
771
+	 *
772
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
773
+	 * @access protected
774
+	 * @return void
775
+	 */
776
+	protected function _trash_or_restore_price($trash = true)
777
+	{
778
+
779
+		// echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
780
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
781
+
782
+		require_once(EE_MODELS . 'EEM_Price.model.php');
783
+		$PRC = EEM_Price::instance();
784
+
785
+		$success = 1;
786
+		$PRC_deleted = $trash ? true : false;
787
+
788
+		// get base ticket for updating
789
+		$ticket = EEM_Ticket::instance()->get_one_by_ID(1);
790
+		// Checkboxes
791
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
792
+			// if array has more than one element than success message should be plural
793
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
794
+			// cycle thru checkboxes
795
+			while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) {
796
+				if (! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), absint($PRC_ID))) {
797
+					$success = 0;
798
+				} else {
799
+					$PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
800
+					if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
801
+						// if trashing then remove relations to base default ticket.  If restoring then add back to base default ticket
802
+						if ($PRC_deleted) {
803
+							$ticket->_remove_relation_to($PRC_ID, 'Price');
804
+						} else {
805
+							$ticket->_add_relation_to($PRC_ID, 'Price');
806
+						}
807
+						$ticket->save();
808
+					}
809
+				}
810
+			}
811
+		} else {
812
+			// grab single id and delete
813
+			$PRC_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
814
+			if (empty($PRC_ID) || ! $PRC->update_by_ID(array('PRC_deleted' => $PRC_deleted), $PRC_ID)) {
815
+				$success = 0;
816
+			} else {
817
+				$PR = EEM_Price::instance()->get_one_by_ID($PRC_ID);
818
+				if ($PR->type_obj()->base_type() !== EEM_Price_Type::base_type_tax) {
819
+					// if trashing then remove relations to base default ticket.  If restoring then add back to base default ticket
820
+					if ($PRC_deleted) {
821
+						$ticket->_remove_relation_to($PRC_ID, 'Price');
822
+					} else {
823
+						$ticket->_add_relation_to($PRC_ID, 'Price');
824
+					}
825
+					$ticket->save();
826
+				}
827
+			}
828
+		}
829
+		$query_args = array(
830
+			'action' => 'default',
831
+		);
832
+
833
+		if ($success) {
834
+			if ($trash) {
835
+				$msg = $success == 2
836
+					? esc_html__('The Prices have been trashed.', 'event_espresso')
837
+					: esc_html__(
838
+						'The Price has been trashed.',
839
+						'event_espresso'
840
+					);
841
+			} else {
842
+				$msg = $success == 2
843
+					? esc_html__('The Prices have been restored.', 'event_espresso')
844
+					: esc_html__(
845
+						'The Price has been restored.',
846
+						'event_espresso'
847
+					);
848
+			}
849
+
850
+			EE_Error::add_success($msg);
851
+		}
852
+
853
+		$this->_redirect_after_action(false, '', '', $query_args, true);
854
+	}
855
+
856
+
857
+	/**
858
+	 *        _delete_price
859
+	 *
860
+	 * @access protected
861
+	 * @return void
862
+	 */
863
+	protected function _delete_price()
864
+	{
865
+
866
+		// echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
867
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
868
+
869
+		require_once(EE_MODELS . 'EEM_Price.model.php');
870
+		$PRC = EEM_Price::instance();
871
+
872
+		$success = 1;
873
+		// Checkboxes
874
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
875
+			// if array has more than one element than success message should be plural
876
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
877
+			// cycle thru bulk action checkboxes
878
+			while (list($PRC_ID, $value) = each($this->_req_data['checkbox'])) {
879
+				if (! $PRC->delete_permanently_by_ID(absint($PRC_ID))) {
880
+					$success = 0;
881
+				}
882
+			}
883
+		} else {
884
+			// grab single id and delete
885
+			$PRC_ID = absint($this->_req_data['id']);
886
+			if (! $PRC->delete_permanently_by_ID($PRC_ID)) {
887
+				$success = 0;
888
+			}
889
+		}
890
+
891
+		$this->_redirect_after_action($success, 'Prices', 'deleted', array());
892
+	}
893
+
894
+
895
+	public function update_price_order()
896
+	{
897
+		$success = esc_html__('Price order was updated successfully.', 'event_espresso');
898
+
899
+		// grab our row IDs
900
+		$row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode(
901
+			',',
902
+			rtrim(
903
+				$this->_req_data['row_ids'],
904
+				','
905
+			)
906
+		) : false;
907
+
908
+		if (is_array($row_ids)) {
909
+			for ($i = 0; $i < count($row_ids); $i++) {
910
+				// Update the prices when re-ordering
911
+				$id = absint($row_ids[ $i ]);
912
+				if (
913
+					EEM_Price::instance()->update(
914
+						array('PRC_order' => $i + 1),
915
+						array(array('PRC_ID' => $id))
916
+					) === false
917
+				) {
918
+					$success = false;
919
+				}
920
+			}
921
+		} else {
922
+			$success = false;
923
+		}
924
+
925
+		$errors = ! $success ? esc_html__('An error occurred. The price order was not updated.', 'event_espresso') : false;
926
+
927
+		echo wp_json_encode(array('return_data' => false, 'success' => $success, 'errors' => $errors));
928
+		die();
929
+	}
930
+
931
+
932
+
933
+
934
+
935
+
936
+	/**************************************************************************************************************************************************************
937 937
      ********************************************************************  TICKET PRICE TYPES  ******************************************************************
938 938
      **************************************************************************************************************************************************************/
939 939
 
940 940
 
941
-    /**
942
-     *        generates HTML for main Prices Admin page
943
-     *
944
-     * @access protected
945
-     * @return void
946
-     */
947
-    protected function _price_types_overview_list_table()
948
-    {
949
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
950
-            'add_new_price_type',
951
-            'add_type',
952
-            array(),
953
-            'add-new-h2'
954
-        );
955
-        $this->admin_page_title .= $this->_learn_more_about_pricing_link();
956
-        $this->_search_btn_label = esc_html__('Price Types', 'event_espresso');
957
-        $this->display_admin_list_table_page_with_no_sidebar();
958
-    }
959
-
960
-
961
-    /**
962
-     *    retrieve data for Price Types List table
963
-     *
964
-     * @access public
965
-     * @param  int     $per_page how many prices displayed per page
966
-     * @param  boolean $count    return the count or objects
967
-     * @param  boolean $trashed  whether the current view is of the trash can - eww yuck!
968
-     * @return mixed (int|array)  int = count || array of price objects
969
-     */
970
-    public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false)
971
-    {
972
-
973
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
974
-        // start with an empty array
975
-
976
-        require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php');
977
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
978
-
979
-        $this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby'];
980
-        $order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
981
-            : 'ASC';
982
-        switch ($this->_req_data['orderby']) {
983
-            case 'name':
984
-                $orderby = array('PRT_name' => $order);
985
-                break;
986
-            default:
987
-                $orderby = array('PRT_order' => $order);
988
-        }
989
-
990
-
991
-        $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
992
-            ? $this->_req_data['paged'] : 1;
993
-        $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
994
-            ? $this->_req_data['perpage'] : $per_page;
995
-
996
-        $offset = ($current_page - 1) * $per_page;
997
-        $limit = array($offset, $per_page);
998
-
999
-        $_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1));
1000
-
1001
-        if (isset($this->_req_data['s'])) {
1002
-            $sstr = '%' . $this->_req_data['s'] . '%';
1003
-            $_where['OR'] = array(
1004
-                'PRT_name' => array('LIKE', $sstr),
1005
-            );
1006
-        }
1007
-        $query_params = array(
1008
-            $_where,
1009
-            'order_by' => $orderby,
1010
-            'limit'    => $limit,
1011
-        );
1012
-        if ($count) {
1013
-            return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params);
1014
-        } else {
1015
-            return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
1016
-        }
1017
-
1018
-        // EEH_Debug_Tools::printr( $price_types, '$price_types  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
1019
-    }
1020
-
1021
-
1022
-    /**
1023
-     *        _edit_price_type_details
1024
-     *
1025
-     * @access protected
1026
-     * @return void
1027
-     */
1028
-    protected function _edit_price_type_details()
1029
-    {
1030
-
1031
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1032
-
1033
-
1034
-        // grab price type ID
1035
-        $PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id'])
1036
-            : false;
1037
-        // change page title based on request action
1038
-        switch ($this->_req_action) {
1039
-            case 'add_new_price_type':
1040
-                $this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso');
1041
-                break;
1042
-            case 'edit_price_type':
1043
-                $this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso');
1044
-                break;
1045
-            default:
1046
-                $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
1047
-        }
1048
-        // add PRT_ID to title if editing
1049
-        $this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
1050
-
1051
-        if ($PRT_ID) {
1052
-            $price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
1053
-            $additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID));
1054
-            $this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields);
1055
-        } else {
1056
-            $price_type = EEM_Price_Type::instance()->get_new_price_type();
1057
-            $this->_set_add_edit_form_tags('insert_price_type');
1058
-        }
1059
-
1060
-        $this->_template_args['PRT_ID'] = $PRT_ID;
1061
-        $this->_template_args['price_type'] = $price_type;
1062
-
1063
-
1064
-        $base_types = EEM_Price_Type::instance()->get_base_types();
1065
-        $select_values = array();
1066
-        foreach ($base_types as $ref => $text) {
1067
-            if ($ref == EEM_Price_Type::base_type_base_price) {
1068
-                // do not allow creation of base_type_base_prices because that's a system only base type.
1069
-                continue;
1070
-            }
1071
-            $values[] = array('id' => $ref, 'text' => $text);
1072
-        }
1073
-
1074
-
1075
-        $this->_template_args['base_type_select'] = EEH_Form_Fields::select_input(
1076
-            'base_type',
1077
-            $values,
1078
-            $price_type->base_type(),
1079
-            'id="price-type-base-type-slct"'
1080
-        );
1081
-        $this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1082
-        $redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url);
1083
-        $this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL);
1084
-        // the details template wrapper
1085
-        $this->display_admin_page_with_sidebar();
1086
-    }
1087
-
1088
-
1089
-    /**
1090
-     *        declare price type details page metaboxes
1091
-     *
1092
-     * @access protected
1093
-     * @return void
1094
-     */
1095
-    protected function _price_type_details_meta_boxes()
1096
-    {
1097
-        add_meta_box(
1098
-            'edit-price-details-mbox',
1099
-            esc_html__('Price Type Details', 'event_espresso'),
1100
-            array($this, '_edit_price_type_details_meta_box'),
1101
-            $this->wp_page_slug,
1102
-            'normal',
1103
-            'high'
1104
-        );
1105
-    }
1106
-
1107
-
1108
-    /**
1109
-     *        _edit_price_type_details_meta_box
1110
-     *
1111
-     * @access public
1112
-     * @return void
1113
-     */
1114
-    public function _edit_price_type_details_meta_box()
1115
-    {
1116
-        echo EEH_Template::display_template(
1117
-            PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php',
1118
-            $this->_template_args,
1119
-            true
1120
-        );
1121
-    }
1122
-
1123
-
1124
-    /**
1125
-     *        set_price_type_column_values
1126
-     *
1127
-     * @access protected
1128
-     * @return void
1129
-     */
1130
-    protected function set_price_type_column_values()
1131
-    {
1132
-
1133
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1134
-
1135
-        $base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type']
1136
-            : EEM_Price_Type::base_type_base_price;
1137
-
1138
-        switch ($base_type) {
1139
-            case EEM_Price_Type::base_type_base_price:
1140
-                $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price;
1141
-                $this->_req_data['PRT_is_percent'] = 0;
1142
-                $this->_req_data['PRT_order'] = 0;
1143
-                break;
1144
-
1145
-            case EEM_Price_Type::base_type_discount:
1146
-                $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount;
1147
-                break;
1148
-
1149
-            case EEM_Price_Type::base_type_surcharge:
1150
-                $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge;
1151
-                break;
1152
-
1153
-            case EEM_Price_Type::base_type_tax:
1154
-                $this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax;
1155
-                $this->_req_data['PRT_is_percent'] = 1;
1156
-                break;
1157
-        }/**/
1158
-
1159
-        $set_column_values = array(
1160
-            'PRT_name'       => $this->_req_data['PRT_name'],
1161
-            'PBT_ID'         => absint($this->_req_data['PBT_ID']),
1162
-            'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']),
1163
-            'PRT_order'      => absint($this->_req_data['PRT_order']),
1164
-            'PRT_deleted'    => 0,
1165
-        );
1166
-
1167
-        return $set_column_values;
1168
-    }
1169
-
1170
-
1171
-    /**
1172
-     *        _insert_or_update_price_type
1173
-     *
1174
-     * @param boolean $new_price_type - whether to insert or update
1175
-     * @access protected
1176
-     * @return void
1177
-     */
1178
-    protected function _insert_or_update_price_type($new_price_type = false)
1179
-    {
1180
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1181
-
1182
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
1183
-        $PRT = EEM_Price_Type::instance();
1184
-
1185
-        // why be so pessimistic ???  : (
1186
-        $success = 0;
1187
-
1188
-        $set_column_values = $this->set_price_type_column_values();
1189
-        // is this a new Price ?
1190
-        if ($new_price_type) {
1191
-            // run the insert
1192
-            if ($PRT_ID = $PRT->insert($set_column_values)) {
1193
-                $success = 1;
1194
-            }
1195
-            $action_desc = 'created';
1196
-        } else {
1197
-            $PRT_ID = absint($this->_req_data['PRT_ID']);
1198
-            // run the update
1199
-            $where_cols_n_values = array('PRT_ID' => $PRT_ID);
1200
-            if ($PRT->update($set_column_values, array($where_cols_n_values))) {
1201
-                $success = 1;
1202
-            }
1203
-            $action_desc = 'updated';
1204
-        }
1205
-
1206
-        $query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID);
1207
-        $this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args);
1208
-    }
1209
-
1210
-
1211
-    /**
1212
-     *        _trash_or_restore_price_type
1213
-     *
1214
-     * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
1215
-     * @access protected
1216
-     * @return void
1217
-     */
1218
-    protected function _trash_or_restore_price_type($trash = true)
1219
-    {
1220
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1221
-
1222
-        require_once(EE_MODELS . 'EEM_Price_Type.model.php');
1223
-        $PRT = EEM_Price_Type::instance();
1224
-
1225
-        $success = 1;
1226
-        $PRT_deleted = $trash ? true : false;
1227
-        // Checkboxes
1228
-        if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1229
-            // if array has more than one element than success message should be plural
1230
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1231
-            $what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type';
1232
-            // cycle thru checkboxes
1233
-            while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) {
1234
-                if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) {
1235
-                    $success = 0;
1236
-                }
1237
-            }
1238
-        } else {
1239
-            // grab single id and delete
1240
-            $PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
1241
-            if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) {
1242
-                $success = 0;
1243
-            }
1244
-            $what = 'Price Type';
1245
-        }
1246
-
1247
-        $query_args = array('action' => 'price_types');
1248
-        if ($success) {
1249
-            if ($trash) {
1250
-                $msg = $success > 1
1251
-                    ? esc_html__('The Price Types have been trashed.', 'event_espresso')
1252
-                    : esc_html__(
1253
-                        'The Price Type has been trashed.',
1254
-                        'event_espresso'
1255
-                    );
1256
-            } else {
1257
-                $msg = $success > 1
1258
-                    ? esc_html__('The Price Types have been restored.', 'event_espresso')
1259
-                    : esc_html__(
1260
-                        'The Price Type has been restored.',
1261
-                        'event_espresso'
1262
-                    );
1263
-            }
1264
-            EE_Error::add_success($msg);
1265
-        }
1266
-
1267
-        $this->_redirect_after_action(false, '', '', $query_args, true);
1268
-    }
1269
-
1270
-
1271
-    /**
1272
-     *        _delete_price_type
1273
-     *
1274
-     * @access protected
1275
-     * @return void
1276
-     */
1277
-    protected function _delete_price_type()
1278
-    {
1279
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1280
-
1281
-        $PRT = EEM_Price_Type::instance();
1282
-
1283
-        $success = 1;
1284
-        // Checkboxes
1285
-        if (! empty($this->_req_data['checkbox'])) {
1286
-            // if array has more than one element than success message should be plural
1287
-            $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1288
-            $what = $PRT->item_name($success);
1289
-            // cycle thru bulk action checkboxes
1290
-            while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) {
1291
-                if (! $PRT->delete_permanently_by_ID($PRT_ID)) {
1292
-                    $success = 0;
1293
-                }
1294
-            }
1295
-        }
1296
-
1297
-
1298
-        $query_args = array('action' => 'price_types');
1299
-        $this->_redirect_after_action($success, $what, 'deleted', $query_args);
1300
-    }
1301
-
1302
-
1303
-    /**
1304
-     *        _learn_more_about_pricing_link
1305
-     *
1306
-     * @access protected
1307
-     * @return string
1308
-     */
1309
-    protected function _learn_more_about_pricing_link()
1310
-    {
1311
-        return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . esc_html__(
1312
-            'learn more about how pricing works',
1313
-            'event_espresso'
1314
-        ) . '</a>';
1315
-    }
1316
-
1317
-
1318
-    protected function _tax_settings()
1319
-    {
1320
-        $this->_set_add_edit_form_tags('update_tax_settings');
1321
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
1322
-        $this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1323
-        $this->display_admin_page_with_sidebar();
1324
-    }
1325
-
1326
-
1327
-    /**
1328
-     * @return \EE_Form_Section_Proper
1329
-     * @throws \EE_Error
1330
-     */
1331
-    protected function tax_settings_form()
1332
-    {
1333
-        return new EE_Form_Section_Proper(
1334
-            array(
1335
-                'name'            => 'tax_settings_form',
1336
-                'html_id'         => 'tax_settings_form',
1337
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
1338
-                'subsections'     => apply_filters(
1339
-                    'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1340
-                    array(
1341
-                        'tax_settings' => new EE_Form_Section_Proper(
1342
-                            array(
1343
-                                'name'            => 'tax_settings_tbl',
1344
-                                'html_id'         => 'tax_settings_tbl',
1345
-                                'html_class'      => 'form-table',
1346
-                                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1347
-                                'subsections'     => array(
1348
-                                    'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1349
-                                        array(
1350
-                                            'html_label_text'         => esc_html__(
1351
-                                                "Show Prices With Taxes Included?",
1352
-                                                'event_espresso'
1353
-                                            ),
1354
-                                            'html_help_text'          => esc_html__(
1355
-                                                'Indicates whether or not to display prices with the taxes included',
1356
-                                                'event_espresso'
1357
-                                            ),
1358
-                                            'default'                 => isset(
1359
-                                                EE_Registry::instance()
1360
-                                                    ->CFG
1361
-                                                    ->tax_settings
1362
-                                                    ->prices_displayed_including_taxes
1363
-                                            )
1364
-                                                ? EE_Registry::instance()
1365
-                                                    ->CFG
1366
-                                                    ->tax_settings
1367
-                                                    ->prices_displayed_including_taxes
1368
-                                                : true,
1369
-                                            'display_html_label_text' => false,
1370
-                                        )
1371
-                                    ),
1372
-                                ),
1373
-                            )
1374
-                        ),
1375
-                    )
1376
-                ),
1377
-            )
1378
-        );
1379
-    }
1380
-
1381
-
1382
-    /**
1383
-     * _update_tax_settings
1384
-     *
1385
-     * @since 4.9.13
1386
-     * @return void
1387
-     */
1388
-    public function _update_tax_settings()
1389
-    {
1390
-        if (! isset(EE_Registry::instance()->CFG->tax_settings)) {
1391
-            EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config();
1392
-        }
1393
-        try {
1394
-            $tax_form = $this->tax_settings_form();
1395
-            // check for form submission
1396
-            if ($tax_form->was_submitted()) {
1397
-                // capture form data
1398
-                $tax_form->receive_form_submission();
1399
-                // validate form data
1400
-                if ($tax_form->is_valid()) {
1401
-                    // grab validated data from form
1402
-                    $valid_data = $tax_form->valid_data();
1403
-                    // set data on config
1404
-                    EE_Registry::instance()
1405
-                        ->CFG
1406
-                        ->tax_settings
1407
-                        ->prices_displayed_including_taxes
1408
-                        = $valid_data['tax_settings']['prices_displayed_including_taxes'];
1409
-                } else {
1410
-                    if ($tax_form->submission_error_message() !== '') {
1411
-                        EE_Error::add_error(
1412
-                            $tax_form->submission_error_message(),
1413
-                            __FILE__,
1414
-                            __FUNCTION__,
1415
-                            __LINE__
1416
-                        );
1417
-                    }
1418
-                }
1419
-            }
1420
-        } catch (EE_Error $e) {
1421
-            EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__);
1422
-        }
1423
-
1424
-        $what = 'Tax Settings';
1425
-        $success = $this->_update_espresso_configuration(
1426
-            $what,
1427
-            EE_Registry::instance()->CFG->tax_settings,
1428
-            __FILE__,
1429
-            __FUNCTION__,
1430
-            __LINE__
1431
-        );
1432
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings'));
1433
-    }
941
+	/**
942
+	 *        generates HTML for main Prices Admin page
943
+	 *
944
+	 * @access protected
945
+	 * @return void
946
+	 */
947
+	protected function _price_types_overview_list_table()
948
+	{
949
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
950
+			'add_new_price_type',
951
+			'add_type',
952
+			array(),
953
+			'add-new-h2'
954
+		);
955
+		$this->admin_page_title .= $this->_learn_more_about_pricing_link();
956
+		$this->_search_btn_label = esc_html__('Price Types', 'event_espresso');
957
+		$this->display_admin_list_table_page_with_no_sidebar();
958
+	}
959
+
960
+
961
+	/**
962
+	 *    retrieve data for Price Types List table
963
+	 *
964
+	 * @access public
965
+	 * @param  int     $per_page how many prices displayed per page
966
+	 * @param  boolean $count    return the count or objects
967
+	 * @param  boolean $trashed  whether the current view is of the trash can - eww yuck!
968
+	 * @return mixed (int|array)  int = count || array of price objects
969
+	 */
970
+	public function get_price_types_overview_data($per_page = 10, $count = false, $trashed = false)
971
+	{
972
+
973
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
974
+		// start with an empty array
975
+
976
+		require_once(PRICING_ADMIN . 'Price_Types_List_Table.class.php');
977
+		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
978
+
979
+		$this->_req_data['orderby'] = empty($this->_req_data['orderby']) ? '' : $this->_req_data['orderby'];
980
+		$order = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order']
981
+			: 'ASC';
982
+		switch ($this->_req_data['orderby']) {
983
+			case 'name':
984
+				$orderby = array('PRT_name' => $order);
985
+				break;
986
+			default:
987
+				$orderby = array('PRT_order' => $order);
988
+		}
989
+
990
+
991
+		$current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged'])
992
+			? $this->_req_data['paged'] : 1;
993
+		$per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage'])
994
+			? $this->_req_data['perpage'] : $per_page;
995
+
996
+		$offset = ($current_page - 1) * $per_page;
997
+		$limit = array($offset, $per_page);
998
+
999
+		$_where = array('PRT_deleted' => $trashed, 'PBT_ID' => array('!=', 1));
1000
+
1001
+		if (isset($this->_req_data['s'])) {
1002
+			$sstr = '%' . $this->_req_data['s'] . '%';
1003
+			$_where['OR'] = array(
1004
+				'PRT_name' => array('LIKE', $sstr),
1005
+			);
1006
+		}
1007
+		$query_params = array(
1008
+			$_where,
1009
+			'order_by' => $orderby,
1010
+			'limit'    => $limit,
1011
+		);
1012
+		if ($count) {
1013
+			return EEM_Price_Type::instance()->count_deleted_and_undeleted($query_params);
1014
+		} else {
1015
+			return EEM_Price_Type::instance()->get_all_deleted_and_undeleted($query_params);
1016
+		}
1017
+
1018
+		// EEH_Debug_Tools::printr( $price_types, '$price_types  <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' );
1019
+	}
1020
+
1021
+
1022
+	/**
1023
+	 *        _edit_price_type_details
1024
+	 *
1025
+	 * @access protected
1026
+	 * @return void
1027
+	 */
1028
+	protected function _edit_price_type_details()
1029
+	{
1030
+
1031
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1032
+
1033
+
1034
+		// grab price type ID
1035
+		$PRT_ID = isset($this->_req_data['id']) && ! empty($this->_req_data['id']) ? absint($this->_req_data['id'])
1036
+			: false;
1037
+		// change page title based on request action
1038
+		switch ($this->_req_action) {
1039
+			case 'add_new_price_type':
1040
+				$this->_admin_page_title = esc_html__('Add New Price Type', 'event_espresso');
1041
+				break;
1042
+			case 'edit_price_type':
1043
+				$this->_admin_page_title = esc_html__('Edit Price Type', 'event_espresso');
1044
+				break;
1045
+			default:
1046
+				$this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action));
1047
+		}
1048
+		// add PRT_ID to title if editing
1049
+		$this->_admin_page_title = $PRT_ID ? $this->_admin_page_title . ' # ' . $PRT_ID : $this->_admin_page_title;
1050
+
1051
+		if ($PRT_ID) {
1052
+			$price_type = EEM_Price_Type::instance()->get_one_by_ID($PRT_ID);
1053
+			$additional_hidden_fields = array('PRT_ID' => array('type' => 'hidden', 'value' => $PRT_ID));
1054
+			$this->_set_add_edit_form_tags('update_price_type', $additional_hidden_fields);
1055
+		} else {
1056
+			$price_type = EEM_Price_Type::instance()->get_new_price_type();
1057
+			$this->_set_add_edit_form_tags('insert_price_type');
1058
+		}
1059
+
1060
+		$this->_template_args['PRT_ID'] = $PRT_ID;
1061
+		$this->_template_args['price_type'] = $price_type;
1062
+
1063
+
1064
+		$base_types = EEM_Price_Type::instance()->get_base_types();
1065
+		$select_values = array();
1066
+		foreach ($base_types as $ref => $text) {
1067
+			if ($ref == EEM_Price_Type::base_type_base_price) {
1068
+				// do not allow creation of base_type_base_prices because that's a system only base type.
1069
+				continue;
1070
+			}
1071
+			$values[] = array('id' => $ref, 'text' => $text);
1072
+		}
1073
+
1074
+
1075
+		$this->_template_args['base_type_select'] = EEH_Form_Fields::select_input(
1076
+			'base_type',
1077
+			$values,
1078
+			$price_type->base_type(),
1079
+			'id="price-type-base-type-slct"'
1080
+		);
1081
+		$this->_template_args['learn_more_about_pricing_link'] = $this->_learn_more_about_pricing_link();
1082
+		$redirect_URL = add_query_arg(array('action' => 'price_types'), $this->_admin_base_url);
1083
+		$this->_set_publish_post_box_vars('id', $PRT_ID, false, $redirect_URL);
1084
+		// the details template wrapper
1085
+		$this->display_admin_page_with_sidebar();
1086
+	}
1087
+
1088
+
1089
+	/**
1090
+	 *        declare price type details page metaboxes
1091
+	 *
1092
+	 * @access protected
1093
+	 * @return void
1094
+	 */
1095
+	protected function _price_type_details_meta_boxes()
1096
+	{
1097
+		add_meta_box(
1098
+			'edit-price-details-mbox',
1099
+			esc_html__('Price Type Details', 'event_espresso'),
1100
+			array($this, '_edit_price_type_details_meta_box'),
1101
+			$this->wp_page_slug,
1102
+			'normal',
1103
+			'high'
1104
+		);
1105
+	}
1106
+
1107
+
1108
+	/**
1109
+	 *        _edit_price_type_details_meta_box
1110
+	 *
1111
+	 * @access public
1112
+	 * @return void
1113
+	 */
1114
+	public function _edit_price_type_details_meta_box()
1115
+	{
1116
+		echo EEH_Template::display_template(
1117
+			PRICING_TEMPLATE_PATH . 'pricing_type_details_main_meta_box.template.php',
1118
+			$this->_template_args,
1119
+			true
1120
+		);
1121
+	}
1122
+
1123
+
1124
+	/**
1125
+	 *        set_price_type_column_values
1126
+	 *
1127
+	 * @access protected
1128
+	 * @return void
1129
+	 */
1130
+	protected function set_price_type_column_values()
1131
+	{
1132
+
1133
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1134
+
1135
+		$base_type = ! empty($this->_req_data['base_type']) ? $this->_req_data['base_type']
1136
+			: EEM_Price_Type::base_type_base_price;
1137
+
1138
+		switch ($base_type) {
1139
+			case EEM_Price_Type::base_type_base_price:
1140
+				$this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_base_price;
1141
+				$this->_req_data['PRT_is_percent'] = 0;
1142
+				$this->_req_data['PRT_order'] = 0;
1143
+				break;
1144
+
1145
+			case EEM_Price_Type::base_type_discount:
1146
+				$this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_discount;
1147
+				break;
1148
+
1149
+			case EEM_Price_Type::base_type_surcharge:
1150
+				$this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_surcharge;
1151
+				break;
1152
+
1153
+			case EEM_Price_Type::base_type_tax:
1154
+				$this->_req_data['PBT_ID'] = EEM_Price_Type::base_type_tax;
1155
+				$this->_req_data['PRT_is_percent'] = 1;
1156
+				break;
1157
+		}/**/
1158
+
1159
+		$set_column_values = array(
1160
+			'PRT_name'       => $this->_req_data['PRT_name'],
1161
+			'PBT_ID'         => absint($this->_req_data['PBT_ID']),
1162
+			'PRT_is_percent' => absint($this->_req_data['PRT_is_percent']),
1163
+			'PRT_order'      => absint($this->_req_data['PRT_order']),
1164
+			'PRT_deleted'    => 0,
1165
+		);
1166
+
1167
+		return $set_column_values;
1168
+	}
1169
+
1170
+
1171
+	/**
1172
+	 *        _insert_or_update_price_type
1173
+	 *
1174
+	 * @param boolean $new_price_type - whether to insert or update
1175
+	 * @access protected
1176
+	 * @return void
1177
+	 */
1178
+	protected function _insert_or_update_price_type($new_price_type = false)
1179
+	{
1180
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1181
+
1182
+		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
1183
+		$PRT = EEM_Price_Type::instance();
1184
+
1185
+		// why be so pessimistic ???  : (
1186
+		$success = 0;
1187
+
1188
+		$set_column_values = $this->set_price_type_column_values();
1189
+		// is this a new Price ?
1190
+		if ($new_price_type) {
1191
+			// run the insert
1192
+			if ($PRT_ID = $PRT->insert($set_column_values)) {
1193
+				$success = 1;
1194
+			}
1195
+			$action_desc = 'created';
1196
+		} else {
1197
+			$PRT_ID = absint($this->_req_data['PRT_ID']);
1198
+			// run the update
1199
+			$where_cols_n_values = array('PRT_ID' => $PRT_ID);
1200
+			if ($PRT->update($set_column_values, array($where_cols_n_values))) {
1201
+				$success = 1;
1202
+			}
1203
+			$action_desc = 'updated';
1204
+		}
1205
+
1206
+		$query_args = array('action' => 'edit_price_type', 'id' => $PRT_ID);
1207
+		$this->_redirect_after_action($success, 'Price Type', $action_desc, $query_args);
1208
+	}
1209
+
1210
+
1211
+	/**
1212
+	 *        _trash_or_restore_price_type
1213
+	 *
1214
+	 * @param boolean $trash - whether to move item to trash (TRUE) or restore it (FALSE)
1215
+	 * @access protected
1216
+	 * @return void
1217
+	 */
1218
+	protected function _trash_or_restore_price_type($trash = true)
1219
+	{
1220
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1221
+
1222
+		require_once(EE_MODELS . 'EEM_Price_Type.model.php');
1223
+		$PRT = EEM_Price_Type::instance();
1224
+
1225
+		$success = 1;
1226
+		$PRT_deleted = $trash ? true : false;
1227
+		// Checkboxes
1228
+		if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) {
1229
+			// if array has more than one element than success message should be plural
1230
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1231
+			$what = count($this->_req_data['checkbox']) > 1 ? 'Price Types' : 'Price Type';
1232
+			// cycle thru checkboxes
1233
+			while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) {
1234
+				if (! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) {
1235
+					$success = 0;
1236
+				}
1237
+			}
1238
+		} else {
1239
+			// grab single id and delete
1240
+			$PRT_ID = isset($this->_req_data['id']) ? absint($this->_req_data['id']) : 0;
1241
+			if (empty($PRT_ID) || ! $PRT->update_by_ID(array('PRT_deleted' => $PRT_deleted), $PRT_ID)) {
1242
+				$success = 0;
1243
+			}
1244
+			$what = 'Price Type';
1245
+		}
1246
+
1247
+		$query_args = array('action' => 'price_types');
1248
+		if ($success) {
1249
+			if ($trash) {
1250
+				$msg = $success > 1
1251
+					? esc_html__('The Price Types have been trashed.', 'event_espresso')
1252
+					: esc_html__(
1253
+						'The Price Type has been trashed.',
1254
+						'event_espresso'
1255
+					);
1256
+			} else {
1257
+				$msg = $success > 1
1258
+					? esc_html__('The Price Types have been restored.', 'event_espresso')
1259
+					: esc_html__(
1260
+						'The Price Type has been restored.',
1261
+						'event_espresso'
1262
+					);
1263
+			}
1264
+			EE_Error::add_success($msg);
1265
+		}
1266
+
1267
+		$this->_redirect_after_action(false, '', '', $query_args, true);
1268
+	}
1269
+
1270
+
1271
+	/**
1272
+	 *        _delete_price_type
1273
+	 *
1274
+	 * @access protected
1275
+	 * @return void
1276
+	 */
1277
+	protected function _delete_price_type()
1278
+	{
1279
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1280
+
1281
+		$PRT = EEM_Price_Type::instance();
1282
+
1283
+		$success = 1;
1284
+		// Checkboxes
1285
+		if (! empty($this->_req_data['checkbox'])) {
1286
+			// if array has more than one element than success message should be plural
1287
+			$success = count($this->_req_data['checkbox']) > 1 ? 2 : 1;
1288
+			$what = $PRT->item_name($success);
1289
+			// cycle thru bulk action checkboxes
1290
+			while (list($PRT_ID, $value) = each($this->_req_data['checkbox'])) {
1291
+				if (! $PRT->delete_permanently_by_ID($PRT_ID)) {
1292
+					$success = 0;
1293
+				}
1294
+			}
1295
+		}
1296
+
1297
+
1298
+		$query_args = array('action' => 'price_types');
1299
+		$this->_redirect_after_action($success, $what, 'deleted', $query_args);
1300
+	}
1301
+
1302
+
1303
+	/**
1304
+	 *        _learn_more_about_pricing_link
1305
+	 *
1306
+	 * @access protected
1307
+	 * @return string
1308
+	 */
1309
+	protected function _learn_more_about_pricing_link()
1310
+	{
1311
+		return '<a class="hidden" style="margin:0 20px; cursor:pointer; font-size:12px;" >' . esc_html__(
1312
+			'learn more about how pricing works',
1313
+			'event_espresso'
1314
+		) . '</a>';
1315
+	}
1316
+
1317
+
1318
+	protected function _tax_settings()
1319
+	{
1320
+		$this->_set_add_edit_form_tags('update_tax_settings');
1321
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
1322
+		$this->_template_args['admin_page_content'] = $this->tax_settings_form()->get_html();
1323
+		$this->display_admin_page_with_sidebar();
1324
+	}
1325
+
1326
+
1327
+	/**
1328
+	 * @return \EE_Form_Section_Proper
1329
+	 * @throws \EE_Error
1330
+	 */
1331
+	protected function tax_settings_form()
1332
+	{
1333
+		return new EE_Form_Section_Proper(
1334
+			array(
1335
+				'name'            => 'tax_settings_form',
1336
+				'html_id'         => 'tax_settings_form',
1337
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
1338
+				'subsections'     => apply_filters(
1339
+					'FHEE__Pricing_Admin_Page__tax_settings_form__form_subsections',
1340
+					array(
1341
+						'tax_settings' => new EE_Form_Section_Proper(
1342
+							array(
1343
+								'name'            => 'tax_settings_tbl',
1344
+								'html_id'         => 'tax_settings_tbl',
1345
+								'html_class'      => 'form-table',
1346
+								'layout_strategy' => new EE_Admin_Two_Column_Layout(),
1347
+								'subsections'     => array(
1348
+									'prices_displayed_including_taxes' => new EE_Yes_No_Input(
1349
+										array(
1350
+											'html_label_text'         => esc_html__(
1351
+												"Show Prices With Taxes Included?",
1352
+												'event_espresso'
1353
+											),
1354
+											'html_help_text'          => esc_html__(
1355
+												'Indicates whether or not to display prices with the taxes included',
1356
+												'event_espresso'
1357
+											),
1358
+											'default'                 => isset(
1359
+												EE_Registry::instance()
1360
+													->CFG
1361
+													->tax_settings
1362
+													->prices_displayed_including_taxes
1363
+											)
1364
+												? EE_Registry::instance()
1365
+													->CFG
1366
+													->tax_settings
1367
+													->prices_displayed_including_taxes
1368
+												: true,
1369
+											'display_html_label_text' => false,
1370
+										)
1371
+									),
1372
+								),
1373
+							)
1374
+						),
1375
+					)
1376
+				),
1377
+			)
1378
+		);
1379
+	}
1380
+
1381
+
1382
+	/**
1383
+	 * _update_tax_settings
1384
+	 *
1385
+	 * @since 4.9.13
1386
+	 * @return void
1387
+	 */
1388
+	public function _update_tax_settings()
1389
+	{
1390
+		if (! isset(EE_Registry::instance()->CFG->tax_settings)) {
1391
+			EE_Registry::instance()->CFG->tax_settings = new EE_Tax_Config();
1392
+		}
1393
+		try {
1394
+			$tax_form = $this->tax_settings_form();
1395
+			// check for form submission
1396
+			if ($tax_form->was_submitted()) {
1397
+				// capture form data
1398
+				$tax_form->receive_form_submission();
1399
+				// validate form data
1400
+				if ($tax_form->is_valid()) {
1401
+					// grab validated data from form
1402
+					$valid_data = $tax_form->valid_data();
1403
+					// set data on config
1404
+					EE_Registry::instance()
1405
+						->CFG
1406
+						->tax_settings
1407
+						->prices_displayed_including_taxes
1408
+						= $valid_data['tax_settings']['prices_displayed_including_taxes'];
1409
+				} else {
1410
+					if ($tax_form->submission_error_message() !== '') {
1411
+						EE_Error::add_error(
1412
+							$tax_form->submission_error_message(),
1413
+							__FILE__,
1414
+							__FUNCTION__,
1415
+							__LINE__
1416
+						);
1417
+					}
1418
+				}
1419
+			}
1420
+		} catch (EE_Error $e) {
1421
+			EE_Error::add_error($e->get_error(), __FILE__, __FUNCTION__, __LINE__);
1422
+		}
1423
+
1424
+		$what = 'Tax Settings';
1425
+		$success = $this->_update_espresso_configuration(
1426
+			$what,
1427
+			EE_Registry::instance()->CFG->tax_settings,
1428
+			__FILE__,
1429
+			__FUNCTION__,
1430
+			__LINE__
1431
+		);
1432
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'tax_settings'));
1433
+	}
1434 1434
 }
Please login to merge, or discard this patch.