Completed
Branch FET-8385-datetime-ticket-selec... (dbda12)
by
unknown
194:55 queued 183:27
created
public/Espresso_Arabica_2014/content-espresso_events-header.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@
 block discarded – undo
5 5
 ?>
6 6
 <header class="event-header">
7 7
 	<?php echo "<{$tag}  id=\"event-details-{$tag}-{$post->ID}\" class=\"entry-title\">"; ?>
8
-		<a class="ee-event-header-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target();?>>
8
+		<a class="ee-event-header-lnk" href="<?php the_permalink(); ?>"<?php echo \EED_Events_Archive::link_target(); ?>>
9 9
             <?php the_title(); ?>
10 10
         </a>
11 11
 	<?php echo "</{$tag}"; ?>
12
-	<?php if ( ! is_archive() && has_excerpt( $post->ID )): the_excerpt(); endif;?>
12
+	<?php if ( ! is_archive() && has_excerpt($post->ID)): the_excerpt(); endif; ?>
13 13
 </header>
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorIframe.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\libraries\iframe_display\Iframe;
5 5
 
6 6
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
-    exit( 'No direct script access allowed' );
7
+	exit( 'No direct script access allowed' );
8 8
 }
9 9
 
10 10
 
@@ -21,61 +21,61 @@  discard block
 block discarded – undo
21 21
 class TicketSelectorIframe extends Iframe
22 22
 {
23 23
 
24
-    /**
25
-     * TicketSelectorIframe constructor.
26
-     *
27
-     * @throws \DomainException
28
-     * @throws \EE_Error
29
-     */
30
-    public function __construct()
31
-    {
32
-        \EE_Registry::instance()->REQ->set_espresso_page( true );
33
-        /** @type \EEM_Event $EEM_Event */
34
-        $EEM_Event = \EE_Registry::instance()->load_model( 'Event' );
35
-        $event = $EEM_Event->get_one_by_ID(
36
-            \EE_Registry::instance()->REQ->get( 'event', 0 )
37
-        );
38
-        $ticket_selector = new DisplayTicketSelector();
39
-        $ticket_selector->setIframe( true );
40
-        parent::__construct(
41
-            esc_html__( 'Ticket Selector', 'event_espresso' ),
42
-            $ticket_selector->display( $event )
43
-        );
44
-        $this->addStylesheets(
45
-            apply_filters(
46
-                'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
47
-                array(
48
-                    'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL
49
-                                               . 'ticket_selector_embed.css?ver='
50
-                                               . EVENT_ESPRESSO_VERSION,
51
-                    'ticket_selector'       => TICKET_SELECTOR_ASSETS_URL
52
-                                               . 'ticket_selector.css?ver='
53
-                                               . EVENT_ESPRESSO_VERSION,
54
-                ),
55
-                $this
56
-            )
57
-        );
58
-        $this->addScripts(
59
-            apply_filters(
60
-                'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
61
-                array(
62
-                    'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL
63
-                                                      . 'ticket_selector_iframe_embed.js?ver='
64
-                                                      . EVENT_ESPRESSO_VERSION,
65
-                ),
66
-                $this
67
-            )
68
-        );
69
-        $this->addLocalizedVars(
70
-            array(
71
-                'ticket_selector_iframe' => true,
72
-                'EEDTicketSelectorMsg'   => __(
73
-                    'Please choose at least one ticket before continuing.',
74
-                    'event_espresso'
75
-                ),
76
-            )
77
-        );
78
-    }
24
+	/**
25
+	 * TicketSelectorIframe constructor.
26
+	 *
27
+	 * @throws \DomainException
28
+	 * @throws \EE_Error
29
+	 */
30
+	public function __construct()
31
+	{
32
+		\EE_Registry::instance()->REQ->set_espresso_page( true );
33
+		/** @type \EEM_Event $EEM_Event */
34
+		$EEM_Event = \EE_Registry::instance()->load_model( 'Event' );
35
+		$event = $EEM_Event->get_one_by_ID(
36
+			\EE_Registry::instance()->REQ->get( 'event', 0 )
37
+		);
38
+		$ticket_selector = new DisplayTicketSelector();
39
+		$ticket_selector->setIframe( true );
40
+		parent::__construct(
41
+			esc_html__( 'Ticket Selector', 'event_espresso' ),
42
+			$ticket_selector->display( $event )
43
+		);
44
+		$this->addStylesheets(
45
+			apply_filters(
46
+				'FHEE__EED_Ticket_Selector__ticket_selector_iframe__css',
47
+				array(
48
+					'ticket_selector_embed' => TICKET_SELECTOR_ASSETS_URL
49
+											   . 'ticket_selector_embed.css?ver='
50
+											   . EVENT_ESPRESSO_VERSION,
51
+					'ticket_selector'       => TICKET_SELECTOR_ASSETS_URL
52
+											   . 'ticket_selector.css?ver='
53
+											   . EVENT_ESPRESSO_VERSION,
54
+				),
55
+				$this
56
+			)
57
+		);
58
+		$this->addScripts(
59
+			apply_filters(
60
+				'FHEE__EED_Ticket_Selector__ticket_selector_iframe__js',
61
+				array(
62
+					'ticket_selector_iframe_embed' => TICKET_SELECTOR_ASSETS_URL
63
+													  . 'ticket_selector_iframe_embed.js?ver='
64
+													  . EVENT_ESPRESSO_VERSION,
65
+				),
66
+				$this
67
+			)
68
+		);
69
+		$this->addLocalizedVars(
70
+			array(
71
+				'ticket_selector_iframe' => true,
72
+				'EEDTicketSelectorMsg'   => __(
73
+					'Please choose at least one ticket before continuing.',
74
+					'event_espresso'
75
+				),
76
+			)
77
+		);
78
+	}
79 79
 
80 80
 }
81 81
 // End of file TicketSelectorIframe.php
Please login to merge, or discard this patch.
modules/events_archive/EED_Events_Archive.module.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	protected static $using_get_the_excerpt = false;
39 39
 
40
-    /**
41
-     * Used to flag when the event list is being called from an external iframe.
42
-     *
43
-     * @var bool $iframe
44
-     */
45
-    protected static $iframe = false;
46
-
47
-    /**
40
+	/**
41
+	 * Used to flag when the event list is being called from an external iframe.
42
+	 *
43
+	 * @var bool $iframe
44
+	 */
45
+	protected static $iframe = false;
46
+
47
+	/**
48 48
 	 * @var \EventEspresso\core\libraries\iframe_display\EventListIframeEmbedButton $_iframe_embed_button
49 49
 	 */
50 50
 	private static $_iframe_embed_button;
51 51
 
52
-    /**
52
+	/**
53 53
 	 * @type EE_Template_Part_Manager $template_parts
54 54
 	 */
55 55
 	protected $template_parts;
@@ -233,26 +233,26 @@  discard block
 block discarded – undo
233 233
 
234 234
 
235 235
 
236
-    /**
237
-     * @access    public
238
-     * @return    void
239
-     * @throws \EE_Error
240
-     * @throws \DomainException
241
-     */
236
+	/**
237
+	 * @access    public
238
+	 * @return    void
239
+	 * @throws \EE_Error
240
+	 * @throws \DomainException
241
+	 */
242 242
 	public function event_list_iframe() {
243
-        \EED_Events_Archive::$iframe = true;
243
+		\EED_Events_Archive::$iframe = true;
244 244
 		$event_list_iframe = new EventsArchiveIframe( $this );
245 245
 		$event_list_iframe->display();
246 246
 	}
247 247
 
248 248
 
249 249
 
250
-    /**
251
-     * @access public
252
-     * @return string
253
-     */
250
+	/**
251
+	 * @access public
252
+	 * @return string
253
+	 */
254 254
 	public static function link_target() {
255
-        return \EED_Events_Archive::$iframe ? ' target="_blank"' : '';
255
+		return \EED_Events_Archive::$iframe ? ' target="_blank"' : '';
256 256
 	}
257 257
 
258 258
 
Please login to merge, or discard this patch.
modules/events_archive/EventsArchiveIframe.php 1 patch
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 use EventEspresso\core\libraries\iframe_display\Iframe;
5 5
 
6 6
 if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) {
7
-    exit( 'No direct script access allowed' );
7
+	exit( 'No direct script access allowed' );
8 8
 }
9 9
 
10 10
 
@@ -21,59 +21,59 @@  discard block
 block discarded – undo
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * EventsArchiveIframe constructor.
26
-     *
27
-     * @param \EED_Events_Archive $EED_Events_Archive
28
-     * @throws \DomainException
29
-     */
30
-    public function __construct( $EED_Events_Archive )
31
-    {
32
-        \EE_Registry::instance()->REQ->set_espresso_page( true );
33
-        add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true');
34
-        $EED_Events_Archive->event_list();
35
-        $event_list = new \EES_Espresso_Events();
36
-        parent::__construct(
37
-            esc_html__( 'Event List', 'event_espresso' ),
38
-            $event_list->process_shortcode()
39
-        );
40
-        $this->addStylesheets(
41
-            apply_filters(
42
-                'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
43
-                array(
44
-                    'espresso_default'           => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' )
45
-                        ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION
46
-                        : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
47
-                    $EED_Events_Archive->theme() => get_stylesheet_directory_uri()
48
-                                                    . $EED_Events_Archive->theme() . DS
49
-                                                    . 'style.css?ver=' . EVENT_ESPRESSO_VERSION,
50
-                ),
51
-                $this
52
-            )
53
-        );
54
-        $this->addScripts(
55
-            apply_filters(
56
-                'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
57
-                array(
58
-                    'gmap_api' => sprintf(
59
-                        'https://maps.googleapis.com/maps/api/js?key=%s',
60
-                        apply_filters(
61
-                            'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
62
-                            \EE_Registry::instance()->CFG->map_settings->google_map_api_key
63
-                        )
64
-                    ),
65
-                    'ee_gmap'  => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0',
66
-                ),
67
-                $this
68
-            )
69
-        );
70
-        $this->addLocalizedVars(
71
-            array(
72
-                'ee_gmap' => \EEH_Maps::$gmap_vars,
73
-            ),
74
-            'ee_gmap_vars'
75
-        );
76
-    }
24
+	/**
25
+	 * EventsArchiveIframe constructor.
26
+	 *
27
+	 * @param \EED_Events_Archive $EED_Events_Archive
28
+	 * @throws \DomainException
29
+	 */
30
+	public function __construct( $EED_Events_Archive )
31
+	{
32
+		\EE_Registry::instance()->REQ->set_espresso_page( true );
33
+		add_filter('FHEE__EED_Events_Archive__event_list_iframe', '__return_true');
34
+		$EED_Events_Archive->event_list();
35
+		$event_list = new \EES_Espresso_Events();
36
+		parent::__construct(
37
+			esc_html__( 'Event List', 'event_espresso' ),
38
+			$event_list->process_shortcode()
39
+		);
40
+		$this->addStylesheets(
41
+			apply_filters(
42
+				'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__css',
43
+				array(
44
+					'espresso_default'           => is_readable( EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css' )
45
+						? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION
46
+						: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION,
47
+					$EED_Events_Archive->theme() => get_stylesheet_directory_uri()
48
+													. $EED_Events_Archive->theme() . DS
49
+													. 'style.css?ver=' . EVENT_ESPRESSO_VERSION,
50
+				),
51
+				$this
52
+			)
53
+		);
54
+		$this->addScripts(
55
+			apply_filters(
56
+				'FHEE__EventEspresso_modules_events_archive_EventsArchiveIframe__display__js',
57
+				array(
58
+					'gmap_api' => sprintf(
59
+						'https://maps.googleapis.com/maps/api/js?key=%s',
60
+						apply_filters(
61
+							'FHEE__EEH_Maps__espresso_google_maps_js__api_key',
62
+							\EE_Registry::instance()->CFG->map_settings->google_map_api_key
63
+						)
64
+					),
65
+					'ee_gmap'  => EE_HELPERS_ASSETS . 'ee_gmap.js?ver=1.0',
66
+				),
67
+				$this
68
+			)
69
+		);
70
+		$this->addLocalizedVars(
71
+			array(
72
+				'ee_gmap' => \EEH_Maps::$gmap_vars,
73
+			),
74
+			'ee_gmap_vars'
75
+		);
76
+	}
77 77
 
78 78
 
79 79
 
Please login to merge, or discard this patch.
core/EE_Config.core.php 1 patch
Indentation   +127 added lines, -127 removed lines patch added patch discarded remove patch
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	public static function reset( $hard_reset = false, $reinstantiate = true ) {
157 157
 		if ( self::$_instance instanceof EE_Config ) {
158
-            if ($hard_reset) {
159
-                self::$_instance->_addon_option_names = array();
160
-                self::$_instance->_initialize_config();
161
-                self::$_instance->update_espresso_config();
162
-            }
163
-            self::$_instance->update_addon_option_names();
158
+			if ($hard_reset) {
159
+				self::$_instance->_addon_option_names = array();
160
+				self::$_instance->_initialize_config();
161
+				self::$_instance->update_espresso_config();
162
+			}
163
+			self::$_instance->update_addon_option_names();
164 164
 		}
165 165
 		self::$_instance = null;
166 166
 		//we don't need to reset the static properties imo because those should
@@ -2211,7 +2211,7 @@  discard block
 block discarded – undo
2211 2211
 		$table_analysis = EE_Registry::instance()->create( 'TableAnalysis', array(), true );
2212 2212
 		// get country code from organization settings or use default
2213 2213
 		$ORG_CNT = isset( EE_Registry::instance()->CFG->organization )
2214
-		           && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2214
+				   && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config
2215 2215
 			? EE_Registry::instance()->CFG->organization->CNT_ISO
2216 2216
 			: '';
2217 2217
 		// but override if requested
@@ -2521,12 +2521,12 @@  discard block
 block discarded – undo
2521 2521
 	public $help_tour_activation;
2522 2522
 
2523 2523
 	/**
2524
-     * adds extra layer of encoding to session data to prevent serialization errors
2525
-     * but is incompatible with some server configuration errors
2526
-     * if you get "500 internal server errors" during registration, try turning this on
2527
-     * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2528
-     *
2529
-     * @var boolean $encode_session_data
2524
+	 * adds extra layer of encoding to session data to prevent serialization errors
2525
+	 * but is incompatible with some server configuration errors
2526
+	 * if you get "500 internal server errors" during registration, try turning this on
2527
+	 * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off
2528
+	 *
2529
+	 * @var boolean $encode_session_data
2530 2530
 	 */
2531 2531
 	private $encode_session_data = false;
2532 2532
 
@@ -2591,21 +2591,21 @@  discard block
 block discarded – undo
2591 2591
 
2592 2592
 
2593 2593
 
2594
-    /**
2595
-     * @return boolean
2596
-     */
2597
-    public function encode_session_data() {
2598
-        return filter_var( $this->encode_session_data, FILTER_VALIDATE_BOOLEAN );
2599
-    }
2594
+	/**
2595
+	 * @return boolean
2596
+	 */
2597
+	public function encode_session_data() {
2598
+		return filter_var( $this->encode_session_data, FILTER_VALIDATE_BOOLEAN );
2599
+	}
2600 2600
 
2601 2601
 
2602 2602
 
2603
-    /**
2604
-     * @param boolean $encode_session_data
2605
-     */
2606
-    public function set_encode_session_data( $encode_session_data ) {
2607
-        $this->encode_session_data = filter_var( $encode_session_data, FILTER_VALIDATE_BOOLEAN );
2608
-    }
2603
+	/**
2604
+	 * @param boolean $encode_session_data
2605
+	 */
2606
+	public function set_encode_session_data( $encode_session_data ) {
2607
+		$this->encode_session_data = filter_var( $encode_session_data, FILTER_VALIDATE_BOOLEAN );
2608
+	}
2609 2609
 
2610 2610
 
2611 2611
 
@@ -2649,13 +2649,13 @@  discard block
 block discarded – undo
2649 2649
 	public $current_espresso_theme;
2650 2650
 
2651 2651
 	/**
2652
-	* @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2653
-	*/
2652
+	 * @var EE_Ticket_Selector_Config $EED_Ticket_Selector
2653
+	 */
2654 2654
 	public $EED_Ticket_Selector;
2655 2655
 
2656 2656
 	/**
2657
-	* @var EE_Event_Single_Config $EED_Event_Single
2658
-	*/
2657
+	 * @var EE_Event_Single_Config $EED_Event_Single
2658
+	 */
2659 2659
 	public $EED_Event_Single;
2660 2660
 
2661 2661
 	/**
@@ -2896,16 +2896,16 @@  discard block
 block discarded – undo
2896 2896
  */
2897 2897
 class EE_Ticket_Selector_Config extends EE_Config_Base {
2898 2898
 
2899
-    /**
2900
-     * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2901
-     */
2902
-    const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2899
+	/**
2900
+	 * constant to indicate that a datetime selector should NEVER be shown for ticket selectors
2901
+	 */
2902
+	const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector';
2903 2903
 
2904
-    /**
2905
-     * constant to indicate that a datetime selector should only be shown for ticket selectors
2906
-     * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2907
-     */
2908
-    const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2904
+	/**
2905
+	 * constant to indicate that a datetime selector should only be shown for ticket selectors
2906
+	 * when the number of datetimes for the event matches the value set for $datetime_selector_threshold
2907
+	 */
2908
+	const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector';
2909 2909
 
2910 2910
 	/**
2911 2911
 	 * @var boolean $show_ticket_sale_columns
@@ -2944,7 +2944,7 @@  discard block
 block discarded – undo
2944 2944
 	 *    class constructor
2945 2945
 	 */
2946 2946
 	public function __construct() {
2947
-        $this->show_ticket_sale_columns = true;
2947
+		$this->show_ticket_sale_columns = true;
2948 2948
 		$this->show_ticket_details = true;
2949 2949
 		$this->show_expired_tickets = true;
2950 2950
 		$this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
@@ -2953,92 +2953,92 @@  discard block
 block discarded – undo
2953 2953
 
2954 2954
 
2955 2955
 
2956
-    /**
2957
-     * returns true if a datetime selector should be displayed
2958
-     *
2959
-     * @param array $datetimes
2960
-     * @return bool
2961
-     */
2962
-    public function showDatetimeSelector(array $datetimes)
2963
-    {
2964
-        // if the settings are NOT: don't show OR below threshold, THEN active = true
2965
-        return ! (
2966
-            $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2967
-           || (
2968
-               $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2969
-               && count($datetimes) < $this->getDatetimeSelectorThreshold()
2970
-           )
2971
-        );
2972
-    }
2973
-
2974
-
2975
-    /**
2976
-     * @return string
2977
-     */
2978
-    public function getShowDatetimeSelector()
2979
-    {
2980
-        return $this->show_datetime_selector;
2981
-    }
2956
+	/**
2957
+	 * returns true if a datetime selector should be displayed
2958
+	 *
2959
+	 * @param array $datetimes
2960
+	 * @return bool
2961
+	 */
2962
+	public function showDatetimeSelector(array $datetimes)
2963
+	{
2964
+		// if the settings are NOT: don't show OR below threshold, THEN active = true
2965
+		return ! (
2966
+			$this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR
2967
+		   || (
2968
+			   $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR
2969
+			   && count($datetimes) < $this->getDatetimeSelectorThreshold()
2970
+		   )
2971
+		);
2972
+	}
2982 2973
 
2983 2974
 
2975
+	/**
2976
+	 * @return string
2977
+	 */
2978
+	public function getShowDatetimeSelector()
2979
+	{
2980
+		return $this->show_datetime_selector;
2981
+	}
2984 2982
 
2985
-    /**
2986
-     * @param bool $keys_only
2987
-     * @return array
2988
-     */
2989
-    public function getShowDatetimeSelectorOptions($keys_only = true)
2990
-    {
2991
-        return $keys_only
2992
-            ? array(
2993
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
2994
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
2995
-            )
2996
-            : array(
2997
-                \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
2998
-                    'Do not show date & time filter', 'event_espresso'
2999
-                ),
3000
-                \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__(
3001
-                    'Maybe show date & time filter', 'event_espresso'
3002
-                ),
3003
-            );
3004
-    }
3005
-
3006
-
3007
-
3008
-    /**
3009
-     * @param string $show_datetime_selector
3010
-     */
3011
-    public function setShowDatetimeSelector($show_datetime_selector)
3012
-    {
3013
-        $this->show_datetime_selector = in_array(
3014
-            $show_datetime_selector,
3015
-            $this->getShowDatetimeSelectorOptions(),
3016
-            true
3017
-        )
3018
-            ? $show_datetime_selector
3019
-            : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3020
-    }
3021 2983
 
3022 2984
 
2985
+	/**
2986
+	 * @param bool $keys_only
2987
+	 * @return array
2988
+	 */
2989
+	public function getShowDatetimeSelectorOptions($keys_only = true)
2990
+	{
2991
+		return $keys_only
2992
+			? array(
2993
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
2994
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR,
2995
+			)
2996
+			: array(
2997
+				\EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__(
2998
+					'Do not show date & time filter', 'event_espresso'
2999
+				),
3000
+				\EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__(
3001
+					'Maybe show date & time filter', 'event_espresso'
3002
+				),
3003
+			);
3004
+	}
3023 3005
 
3024
-    /**
3025
-     * @return int
3026
-     */
3027
-    public function getDatetimeSelectorThreshold()
3028
-    {
3029
-        return $this->datetime_selector_threshold;
3030
-    }
3031 3006
 
3032 3007
 
3008
+	/**
3009
+	 * @param string $show_datetime_selector
3010
+	 */
3011
+	public function setShowDatetimeSelector($show_datetime_selector)
3012
+	{
3013
+		$this->show_datetime_selector = in_array(
3014
+			$show_datetime_selector,
3015
+			$this->getShowDatetimeSelectorOptions(),
3016
+			true
3017
+		)
3018
+			? $show_datetime_selector
3019
+			: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR;
3020
+	}
3033 3021
 
3034
-    /**
3035
-     * @param int $datetime_selector_threshold
3036
-     */
3037
-    public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3038
-    {
3039
-        $datetime_selector_threshold = absint($datetime_selector_threshold);
3040
-        $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3041
-    }
3022
+
3023
+
3024
+	/**
3025
+	 * @return int
3026
+	 */
3027
+	public function getDatetimeSelectorThreshold()
3028
+	{
3029
+		return $this->datetime_selector_threshold;
3030
+	}
3031
+
3032
+
3033
+
3034
+	/**
3035
+	 * @param int $datetime_selector_threshold
3036
+	 */
3037
+	public function setDatetimeSelectorThreshold($datetime_selector_threshold)
3038
+	{
3039
+		$datetime_selector_threshold = absint($datetime_selector_threshold);
3040
+		$this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3;
3041
+	}
3042 3042
 
3043 3043
 
3044 3044
 }
@@ -3101,8 +3101,8 @@  discard block
 block discarded – undo
3101 3101
 	 */
3102 3102
 	public function max_input_vars_limit_check( $input_count = 0 ) {
3103 3103
 		if ( ! empty( $this->php->max_input_vars )
3104
-		     && ( $input_count >= $this->php->max_input_vars )
3105
-		     && ( PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9 )
3104
+			 && ( $input_count >= $this->php->max_input_vars )
3105
+			 && ( PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9 )
3106 3106
 		) {
3107 3107
 			return sprintf(
3108 3108
 				__(
@@ -3146,22 +3146,22 @@  discard block
 block discarded – undo
3146 3146
 class EE_Tax_Config extends EE_Config_Base
3147 3147
 {
3148 3148
 
3149
-    /*
3149
+	/*
3150 3150
      * flag to indicate whether or not to display ticket prices with the taxes included
3151 3151
      *
3152 3152
      * @var boolean $prices_displayed_including_taxes
3153 3153
      */
3154
-    public $prices_displayed_including_taxes;
3154
+	public $prices_displayed_including_taxes;
3155 3155
 
3156 3156
 
3157 3157
 
3158
-    /**
3159
-     *    class constructor
3160
-     */
3161
-    public function __construct()
3162
-    {
3163
-        $this->prices_displayed_including_taxes = true;
3164
-    }
3158
+	/**
3159
+	 *    class constructor
3160
+	 */
3161
+	public function __construct()
3162
+	{
3163
+		$this->prices_displayed_including_taxes = true;
3164
+	}
3165 3165
 }
3166 3166
 
3167 3167
 
Please login to merge, or discard this patch.
modules/ticket_selector_caff/EED_Ticket_Selector_Caff.module.php 2 patches
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -47,14 +47,14 @@  discard block
 block discarded – undo
47 47
 	 * @param \WP $WP
48 48
 	 */
49 49
 	public function run( $WP ) {
50
-        $this->set_config();
50
+		$this->set_config();
51 51
 	}
52 52
 
53 53
 
54 54
 
55 55
 
56 56
 	protected function set_config(){
57
-        $this->set_config_section( 'template_settings' );
57
+		$this->set_config_section( 'template_settings' );
58 58
 		$this->set_config_class( 'EE_Ticket_Selector_Config' );
59 59
 		$this->set_config_name( 'EED_Ticket_Selector' );
60 60
 	}
@@ -103,27 +103,27 @@  discard block
 block discarded – undo
103 103
 
104 104
 
105 105
 
106
-    /**
107
-     * @return \EE_Form_Section_Proper
108
-     * @throws \EE_Error
109
-     */
110
-    public static function _ticket_selector_appearance_settings() {
111
-        if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
112
-            \EED_Ticket_Selector::instance()->set_config();
113
-            \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
114
-        }
115
-        // get option for whether to show datetime selector in TS
116
-	    $show_datetime_selector = \EE_Registry::instance()
117
-		    ->CFG
118
-		    ->template_settings
119
-		    ->EED_Ticket_Selector
120
-		    ->getShowDatetimeSelector();
121
-	    // and option for how may datetimes must exist if display is conditional
122
-	    $datetime_selector_threshold = \EE_Registry::instance()
123
-		    ->CFG
124
-		    ->template_settings
125
-		    ->EED_Ticket_Selector
126
-		    ->getDatetimeSelectorThreshold();
106
+	/**
107
+	 * @return \EE_Form_Section_Proper
108
+	 * @throws \EE_Error
109
+	 */
110
+	public static function _ticket_selector_appearance_settings() {
111
+		if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
112
+			\EED_Ticket_Selector::instance()->set_config();
113
+			\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
114
+		}
115
+		// get option for whether to show datetime selector in TS
116
+		$show_datetime_selector = \EE_Registry::instance()
117
+			->CFG
118
+			->template_settings
119
+			->EED_Ticket_Selector
120
+			->getShowDatetimeSelector();
121
+		// and option for how may datetimes must exist if display is conditional
122
+		$datetime_selector_threshold = \EE_Registry::instance()
123
+			->CFG
124
+			->template_settings
125
+			->EED_Ticket_Selector
126
+			->getDatetimeSelectorThreshold();
127 127
 
128 128
 		return new EE_Form_Section_Proper(
129 129
 			array(
@@ -165,19 +165,19 @@  discard block
 block discarded – undo
165 165
 								)
166 166
 							),
167 167
 							'show_datetime_selector' => new EE_Select_Input(
168
-                                \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->getShowDatetimeSelectorOptions(false),
168
+								\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->getShowDatetimeSelectorOptions(false),
169 169
 								array(
170 170
 									'html_label_text' => esc_html__( 'Show Date & Time Filter?', 'event_espresso' ),
171 171
 									'html_help_text' => sprintf(
172
-									    esc_html__(
173
-									        'Indicates whether or not to display a dropdown select box above each ticket selector that displays dates and times for the available tickets. Ticket options can be unselected, which removes (hides) them from the list of tickets being displayed.%1$sOptions include:%1$s &bull; %2$sdo not show date & time filter%3$s%1$s &nbsp; this option will NEVER display a date filter, regardless of how many dates exist.%1$s &bull; %2$smaybe show date & time filter%3$s%1$s &nbsp; this option will conditionally display the date filter when the number of dates for the event matches the value set for "Date Filter Threshold".',
174
-                                            'event_espresso'
175
-                                        ),
176
-                                        '<br>',
177
-                                        '<strong>',
178
-                                        '</strong>'
179
-
180
-                                    ),
172
+										esc_html__(
173
+											'Indicates whether or not to display a dropdown select box above each ticket selector that displays dates and times for the available tickets. Ticket options can be unselected, which removes (hides) them from the list of tickets being displayed.%1$sOptions include:%1$s &bull; %2$sdo not show date & time filter%3$s%1$s &nbsp; this option will NEVER display a date filter, regardless of how many dates exist.%1$s &bull; %2$smaybe show date & time filter%3$s%1$s &nbsp; this option will conditionally display the date filter when the number of dates for the event matches the value set for "Date Filter Threshold".',
174
+											'event_espresso'
175
+										),
176
+										'<br>',
177
+										'<strong>',
178
+										'</strong>'
179
+
180
+									),
181 181
 									'default' => ! empty( $show_datetime_selector )
182 182
 										? $show_datetime_selector
183 183
 										: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
@@ -185,13 +185,13 @@  discard block
 block discarded – undo
185 185
 								)
186 186
 							),
187 187
 							'datetime_selector_threshold' => new EE_Select_Input(
188
-                                array_combine($r = range(1, 10), $r),
188
+								array_combine($r = range(1, 10), $r),
189 189
 								array(
190 190
 									'html_label_text' => esc_html__( 'Date & Time Filter Threshold', 'event_espresso' ),
191 191
 									'html_help_text' => esc_html__(
192
-                                        'The number of unique dates an event has to have before conditionally displaying a date & time filter',
193
-                                        'event_espresso'
194
-                                    ),
192
+										'The number of unique dates an event has to have before conditionally displaying a date & time filter',
193
+										'event_espresso'
194
+									),
195 195
 									'default' => ! empty( $datetime_selector_threshold )
196 196
 										? $datetime_selector_threshold
197 197
 										: 3,
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 	 */
218 218
 	public static function update_template_settings( EE_Template_Config $CFG, $REQ ) {
219 219
 		if ( ! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
220
-            \EED_Ticket_Selector::instance()->set_config();
221
-            $CFG->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
220
+			\EED_Ticket_Selector::instance()->set_config();
221
+			$CFG->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
222 222
 		}
223 223
 		try {
224 224
 			$ticket_selector_form = EED_Ticket_Selector_Caff::_ticket_selector_settings_form();
@@ -240,11 +240,11 @@  discard block
 block discarded – undo
240 240
 					$CFG->EED_Ticket_Selector->show_ticket_details = $valid_data['appearance_settings']['show_ticket_details'];
241 241
 					$CFG->EED_Ticket_Selector->show_expired_tickets = $valid_data['appearance_settings']['show_expired_tickets'];
242 242
 					$CFG->EED_Ticket_Selector->setShowDatetimeSelector(
243
-					    $valid_data['appearance_settings']['show_datetime_selector']
244
-                    );
243
+						$valid_data['appearance_settings']['show_datetime_selector']
244
+					);
245 245
 					$CFG->EED_Ticket_Selector->setDatetimeSelectorThreshold(
246
-					    $valid_data['appearance_settings']['datetime_selector_threshold']
247
-                    );
246
+						$valid_data['appearance_settings']['datetime_selector_threshold']
247
+					);
248 248
 				} else {
249 249
 					if ( $ticket_selector_form->submission_error_message() !== '' ) {
250 250
 						EE_Error::add_error( $ticket_selector_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__ );
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 	 * @return EED_Ticket_Selector_Caff
17 17
 	 */
18 18
 	public static function instance() {
19
-		return parent::get_instance( __CLASS__ );
19
+		return parent::get_instance(__CLASS__);
20 20
 	}
21 21
 
22 22
 
@@ -37,26 +37,26 @@  discard block
 block discarded – undo
37 37
 	 *  @return 	void
38 38
 	 */
39 39
 	public static function set_hooks_admin() {
40
-		define( 'TICKET_SELECTOR_CAFF_TEMPLATES_PATH', str_replace( '\\', DS, plugin_dir_path( __FILE__ )) . 'templates' . DS );
41
-		add_action( 'AHEE__template_settings__template__before_settings_form', array( 'EED_Ticket_Selector_Caff', 'template_settings_form' ), 10 );
42
-		add_filter( 'FHEE__General_Settings_Admin_Page__update_template_settings__data', array( 'EED_Ticket_Selector_Caff', 'update_template_settings' ), 10, 2 );
40
+		define('TICKET_SELECTOR_CAFF_TEMPLATES_PATH', str_replace('\\', DS, plugin_dir_path(__FILE__)).'templates'.DS);
41
+		add_action('AHEE__template_settings__template__before_settings_form', array('EED_Ticket_Selector_Caff', 'template_settings_form'), 10);
42
+		add_filter('FHEE__General_Settings_Admin_Page__update_template_settings__data', array('EED_Ticket_Selector_Caff', 'update_template_settings'), 10, 2);
43 43
 	}
44 44
 
45 45
 
46 46
 	/**
47 47
 	 * @param \WP $WP
48 48
 	 */
49
-	public function run( $WP ) {
49
+	public function run($WP) {
50 50
         $this->set_config();
51 51
 	}
52 52
 
53 53
 
54 54
 
55 55
 
56
-	protected function set_config(){
57
-        $this->set_config_section( 'template_settings' );
58
-		$this->set_config_class( 'EE_Ticket_Selector_Config' );
59
-		$this->set_config_name( 'EED_Ticket_Selector' );
56
+	protected function set_config() {
57
+        $this->set_config_section('template_settings');
58
+		$this->set_config_class('EE_Ticket_Selector_Config');
59
+		$this->set_config_name('EED_Ticket_Selector');
60 60
 	}
61 61
 
62 62
 
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 					'FHEE__EED_Ticket_Selector_Caff___ticket_selector_settings_form__form_subsections',
92 92
 					array(
93 93
 						'appearance_settings_hdr' 	=> new EE_Form_Section_HTML(
94
-							EEH_HTML::br(2) .
95
-							EEH_HTML::h2( esc_html__( 'Ticket Selector Template Settings', 'event_espresso' ))
94
+							EEH_HTML::br(2).
95
+							EEH_HTML::h2(esc_html__('Ticket Selector Template Settings', 'event_espresso'))
96 96
 						),
97 97
 						'appearance_settings' 			=> EED_Ticket_Selector_Caff::_ticket_selector_appearance_settings()
98 98
 					)
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
      * @throws \EE_Error
109 109
      */
110 110
     public static function _ticket_selector_appearance_settings() {
111
-        if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
111
+        if ( ! \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
112 112
             \EED_Ticket_Selector::instance()->set_config();
113 113
             \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
114 114
         }
@@ -136,9 +136,9 @@  discard block
 block discarded – undo
136 136
 						array(
137 137
 							'show_ticket_details' => new EE_Yes_No_Input(
138 138
 								array(
139
-									'html_label_text' => esc_html__('Show Ticket Details?', 'event_espresso' ),
140
-									'html_help_text' => esc_html__( 'This lets you choose whether the extra ticket details section is displayed with the ticket selector.', 'event_espresso'),
141
-									'default' => isset( EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_details )
139
+									'html_label_text' => esc_html__('Show Ticket Details?', 'event_espresso'),
140
+									'html_help_text' => esc_html__('This lets you choose whether the extra ticket details section is displayed with the ticket selector.', 'event_espresso'),
141
+									'default' => isset(EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_details)
142 142
 										? EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_details
143 143
 										: true,
144 144
 									'display_html_label_text' => false
@@ -146,9 +146,9 @@  discard block
 block discarded – undo
146 146
 							),
147 147
 							'show_ticket_sale_columns' => new EE_Yes_No_Input(
148 148
 								array(
149
-									'html_label_text' => esc_html__('Show Ticket Sale Info?', 'event_espresso' ),
150
-									'html_help_text' => esc_html__( 'This lets you indicate whether information about ticket sales is shown with ticket details in the ticket selector.', 'event_espresso'),
151
-									'default' => isset( EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_sale_columns )
149
+									'html_label_text' => esc_html__('Show Ticket Sale Info?', 'event_espresso'),
150
+									'html_help_text' => esc_html__('This lets you indicate whether information about ticket sales is shown with ticket details in the ticket selector.', 'event_espresso'),
151
+									'default' => isset(EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_sale_columns)
152 152
 										? EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_ticket_sale_columns
153 153
 										: true,
154 154
 									'display_html_label_text' => false
@@ -156,9 +156,9 @@  discard block
 block discarded – undo
156 156
 							),
157 157
 							'show_expired_tickets' => new EE_Yes_No_Input(
158 158
 								array(
159
-									'html_label_text' => esc_html__( 'Show Expired Tickets?', 'event_espresso' ),
160
-									'html_help_text' => esc_html__( 'Indicate whether to show expired tickets in the ticket selector', 'event_espresso' ),
161
-									'default' => isset( EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets )
159
+									'html_label_text' => esc_html__('Show Expired Tickets?', 'event_espresso'),
160
+									'html_help_text' => esc_html__('Indicate whether to show expired tickets in the ticket selector', 'event_espresso'),
161
+									'default' => isset(EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets)
162 162
 										? EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets
163 163
 										: true,
164 164
 									'display_html_label_text' => false
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 							'show_datetime_selector' => new EE_Select_Input(
168 168
                                 \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->getShowDatetimeSelectorOptions(false),
169 169
 								array(
170
-									'html_label_text' => esc_html__( 'Show Date & Time Filter?', 'event_espresso' ),
170
+									'html_label_text' => esc_html__('Show Date & Time Filter?', 'event_espresso'),
171 171
 									'html_help_text' => sprintf(
172 172
 									    esc_html__(
173 173
 									        'Indicates whether or not to display a dropdown select box above each ticket selector that displays dates and times for the available tickets. Ticket options can be unselected, which removes (hides) them from the list of tickets being displayed.%1$sOptions include:%1$s &bull; %2$sdo not show date & time filter%3$s%1$s &nbsp; this option will NEVER display a date filter, regardless of how many dates exist.%1$s &bull; %2$smaybe show date & time filter%3$s%1$s &nbsp; this option will conditionally display the date filter when the number of dates for the event matches the value set for "Date Filter Threshold".',
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
                                         '</strong>'
179 179
 
180 180
                                     ),
181
-									'default' => ! empty( $show_datetime_selector )
181
+									'default' => ! empty($show_datetime_selector)
182 182
 										? $show_datetime_selector
183 183
 										: \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
184 184
 									'display_html_label_text' => false
@@ -187,12 +187,12 @@  discard block
 block discarded – undo
187 187
 							'datetime_selector_threshold' => new EE_Select_Input(
188 188
                                 array_combine($r = range(1, 10), $r),
189 189
 								array(
190
-									'html_label_text' => esc_html__( 'Date & Time Filter Threshold', 'event_espresso' ),
190
+									'html_label_text' => esc_html__('Date & Time Filter Threshold', 'event_espresso'),
191 191
 									'html_help_text' => esc_html__(
192 192
                                         'The number of unique dates an event has to have before conditionally displaying a date & time filter',
193 193
                                         'event_espresso'
194 194
                                     ),
195
-									'default' => ! empty( $datetime_selector_threshold )
195
+									'default' => ! empty($datetime_selector_threshold)
196 196
 										? $datetime_selector_threshold
197 197
 										: 3,
198 198
 									'display_html_label_text' => false
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param array              $REQ incoming request
216 216
 	 * @return EE_Template_Config
217 217
 	 */
218
-	public static function update_template_settings( EE_Template_Config $CFG, $REQ ) {
219
-		if ( ! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config ) {
218
+	public static function update_template_settings(EE_Template_Config $CFG, $REQ) {
219
+		if ( ! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
220 220
             \EED_Ticket_Selector::instance()->set_config();
221 221
             $CFG->EED_Ticket_Selector = \EED_Ticket_Selector::instance()->config();
222 222
 		}
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 			$ticket_selector_form = EED_Ticket_Selector_Caff::_ticket_selector_settings_form();
225 225
 
226 226
 			//check for form submission
227
-			if ( $ticket_selector_form->was_submitted() ) {
227
+			if ($ticket_selector_form->was_submitted()) {
228 228
 
229 229
 				//capture form data
230 230
 				$ticket_selector_form->receive_form_submission();
231 231
 
232 232
 				//validate form data
233
-				if ( $ticket_selector_form->is_valid() ) {
233
+				if ($ticket_selector_form->is_valid()) {
234 234
 
235 235
 					//grab validated data from form
236 236
 					$valid_data = $ticket_selector_form->valid_data();
@@ -246,13 +246,13 @@  discard block
 block discarded – undo
246 246
 					    $valid_data['appearance_settings']['datetime_selector_threshold']
247 247
                     );
248 248
 				} else {
249
-					if ( $ticket_selector_form->submission_error_message() !== '' ) {
250
-						EE_Error::add_error( $ticket_selector_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__ );
249
+					if ($ticket_selector_form->submission_error_message() !== '') {
250
+						EE_Error::add_error($ticket_selector_form->submission_error_message(), __FILE__, __FUNCTION__, __LINE__);
251 251
 					}
252 252
 				}
253 253
 
254 254
 			}
255
-		} catch( EE_Error $e ) {
255
+		} catch (EE_Error $e) {
256 256
 			$e->get_error();
257 257
 		}
258 258
 
Please login to merge, or discard this patch.
admin_pages/events/Events_Admin_Page.core.php 1 patch
Indentation   +2567 added lines, -2567 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('NO direct script access allowed');
3
+	exit('NO direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -17,2573 +17,2573 @@  discard block
 block discarded – undo
17 17
 class Events_Admin_Page extends EE_Admin_Page_CPT
18 18
 {
19 19
 
20
-    /**
21
-     * This will hold the event object for event_details screen.
22
-     *
23
-     * @access protected
24
-     * @var EE_Event $_event
25
-     */
26
-    protected $_event;
27
-
28
-
29
-    /**
30
-     * This will hold the category object for category_details screen.
31
-     *
32
-     * @var stdClass $_category
33
-     */
34
-    protected $_category;
35
-
36
-
37
-    /**
38
-     * This will hold the event model instance
39
-     *
40
-     * @var EEM_Event $_event_model
41
-     */
42
-    protected $_event_model;
43
-
44
-
45
-
46
-    /**
47
-     * @var EE_Event
48
-     */
49
-    protected $_cpt_model_obj = false;
50
-
51
-
52
-
53
-    protected function _init_page_props()
54
-    {
55
-        $this->page_slug = EVENTS_PG_SLUG;
56
-        $this->page_label = EVENTS_LABEL;
57
-        $this->_admin_base_url = EVENTS_ADMIN_URL;
58
-        $this->_admin_base_path = EVENTS_ADMIN;
59
-        $this->_cpt_model_names = array(
60
-            'create_new' => 'EEM_Event',
61
-            'edit'       => 'EEM_Event',
62
-        );
63
-        $this->_cpt_edit_routes = array(
64
-            'espresso_events' => 'edit',
65
-        );
66
-        add_action(
67
-            'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
-            array($this, 'verify_event_edit')
69
-        );
70
-    }
71
-
72
-
73
-
74
-    protected function _ajax_hooks()
75
-    {
76
-        //todo: all hooks for events ajax goes in here.
77
-    }
78
-
79
-
80
-
81
-    protected function _define_page_props()
82
-    {
83
-        $this->_admin_page_title = EVENTS_LABEL;
84
-        $this->_labels = array(
85
-            'buttons'      => array(
86
-                'add'             => esc_html__('Add New Event', 'event_espresso'),
87
-                'edit'            => esc_html__('Edit Event', 'event_espresso'),
88
-                'delete'          => esc_html__('Delete Event', 'event_espresso'),
89
-                'add_category'    => esc_html__('Add New Category', 'event_espresso'),
90
-                'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
91
-                'delete_category' => esc_html__('Delete Category', 'event_espresso'),
92
-            ),
93
-            'editor_title' => array(
94
-                'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
95
-            ),
96
-            'publishbox'   => array(
97
-                'create_new'        => esc_html__('Save New Event', 'event_espresso'),
98
-                'edit'              => esc_html__('Update Event', 'event_espresso'),
99
-                'add_category'      => esc_html__('Save New Category', 'event_espresso'),
100
-                'edit_category'     => esc_html__('Update Category', 'event_espresso'),
101
-                'template_settings' => esc_html__('Update Settings', 'event_espresso'),
102
-            ),
103
-        );
104
-    }
105
-
106
-
107
-
108
-    protected function _set_page_routes()
109
-    {
110
-        //load formatter helper
111
-        //load field generator helper
112
-        //is there a evt_id in the request?
113
-        $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
114
-            ? $this->_req_data['EVT_ID'] : 0;
115
-        $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
116
-        $this->_page_routes = array(
117
-            'default'                       => array(
118
-                'func'       => '_events_overview_list_table',
119
-                'capability' => 'ee_read_events',
120
-            ),
121
-            'create_new'                    => array(
122
-                'func'       => '_create_new_cpt_item',
123
-                'capability' => 'ee_edit_events',
124
-            ),
125
-            'edit'                          => array(
126
-                'func'       => '_edit_cpt_item',
127
-                'capability' => 'ee_edit_event',
128
-                'obj_id'     => $evt_id,
129
-            ),
130
-            'copy_event'                    => array(
131
-                'func'       => '_copy_events',
132
-                'capability' => 'ee_edit_event',
133
-                'obj_id'     => $evt_id,
134
-                'noheader'   => true,
135
-            ),
136
-            'trash_event'                   => array(
137
-                'func'       => '_trash_or_restore_event',
138
-                'args'       => array('event_status' => 'trash'),
139
-                'capability' => 'ee_delete_event',
140
-                'obj_id'     => $evt_id,
141
-                'noheader'   => true,
142
-            ),
143
-            'trash_events'                  => array(
144
-                'func'       => '_trash_or_restore_events',
145
-                'args'       => array('event_status' => 'trash'),
146
-                'capability' => 'ee_delete_events',
147
-                'noheader'   => true,
148
-            ),
149
-            'restore_event'                 => array(
150
-                'func'       => '_trash_or_restore_event',
151
-                'args'       => array('event_status' => 'draft'),
152
-                'capability' => 'ee_delete_event',
153
-                'obj_id'     => $evt_id,
154
-                'noheader'   => true,
155
-            ),
156
-            'restore_events'                => array(
157
-                'func'       => '_trash_or_restore_events',
158
-                'args'       => array('event_status' => 'draft'),
159
-                'capability' => 'ee_delete_events',
160
-                'noheader'   => true,
161
-            ),
162
-            'delete_event'                  => array(
163
-                'func'       => '_delete_event',
164
-                'capability' => 'ee_delete_event',
165
-                'obj_id'     => $evt_id,
166
-                'noheader'   => true,
167
-            ),
168
-            'delete_events'                 => array(
169
-                'func'       => '_delete_events',
170
-                'capability' => 'ee_delete_events',
171
-                'noheader'   => true,
172
-            ),
173
-            'view_report'                   => array(
174
-                'func'      => '_view_report',
175
-                'capablity' => 'ee_edit_events',
176
-            ),
177
-            'default_event_settings'        => array(
178
-                'func'       => '_default_event_settings',
179
-                'capability' => 'manage_options',
180
-            ),
181
-            'update_default_event_settings' => array(
182
-                'func'       => '_update_default_event_settings',
183
-                'capability' => 'manage_options',
184
-                'noheader'   => true,
185
-            ),
186
-            'template_settings'             => array(
187
-                'func'       => '_template_settings',
188
-                'capability' => 'manage_options',
189
-            ),
190
-            //event category tab related
191
-            'add_category'                  => array(
192
-                'func'       => '_category_details',
193
-                'capability' => 'ee_edit_event_category',
194
-                'args'       => array('add'),
195
-            ),
196
-            'edit_category'                 => array(
197
-                'func'       => '_category_details',
198
-                'capability' => 'ee_edit_event_category',
199
-                'args'       => array('edit'),
200
-            ),
201
-            'delete_categories'             => array(
202
-                'func'       => '_delete_categories',
203
-                'capability' => 'ee_delete_event_category',
204
-                'noheader'   => true,
205
-            ),
206
-            'delete_category'               => array(
207
-                'func'       => '_delete_categories',
208
-                'capability' => 'ee_delete_event_category',
209
-                'noheader'   => true,
210
-            ),
211
-            'insert_category'               => array(
212
-                'func'       => '_insert_or_update_category',
213
-                'args'       => array('new_category' => true),
214
-                'capability' => 'ee_edit_event_category',
215
-                'noheader'   => true,
216
-            ),
217
-            'update_category'               => array(
218
-                'func'       => '_insert_or_update_category',
219
-                'args'       => array('new_category' => false),
220
-                'capability' => 'ee_edit_event_category',
221
-                'noheader'   => true,
222
-            ),
223
-            'category_list'                 => array(
224
-                'func'       => '_category_list_table',
225
-                'capability' => 'ee_manage_event_categories',
226
-            ),
227
-        );
228
-    }
229
-
230
-
231
-
232
-    protected function _set_page_config()
233
-    {
234
-        $this->_page_config = array(
235
-            'default'                => array(
236
-                'nav'           => array(
237
-                    'label' => esc_html__('Overview', 'event_espresso'),
238
-                    'order' => 10,
239
-                ),
240
-                'list_table'    => 'Events_Admin_List_Table',
241
-                'help_tabs'     => array(
242
-                    'events_overview_help_tab'                       => array(
243
-                        'title'    => esc_html__('Events Overview', 'event_espresso'),
244
-                        'filename' => 'events_overview',
245
-                    ),
246
-                    'events_overview_table_column_headings_help_tab' => array(
247
-                        'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
248
-                        'filename' => 'events_overview_table_column_headings',
249
-                    ),
250
-                    'events_overview_filters_help_tab'               => array(
251
-                        'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
252
-                        'filename' => 'events_overview_filters',
253
-                    ),
254
-                    'events_overview_view_help_tab'                  => array(
255
-                        'title'    => esc_html__('Events Overview Views', 'event_espresso'),
256
-                        'filename' => 'events_overview_views',
257
-                    ),
258
-                    'events_overview_other_help_tab'                 => array(
259
-                        'title'    => esc_html__('Events Overview Other', 'event_espresso'),
260
-                        'filename' => 'events_overview_other',
261
-                    ),
262
-                ),
263
-                'help_tour'     => array(
264
-                    'Event_Overview_Help_Tour',
265
-                    //'New_Features_Test_Help_Tour' for testing multiple help tour
266
-                ),
267
-                'qtips'         => array(
268
-                    'EE_Event_List_Table_Tips',
269
-                ),
270
-                'require_nonce' => false,
271
-            ),
272
-            'create_new'             => array(
273
-                'nav'           => array(
274
-                    'label'      => esc_html__('Add Event', 'event_espresso'),
275
-                    'order'      => 5,
276
-                    'persistent' => false,
277
-                ),
278
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
279
-                'help_tabs'     => array(
280
-                    'event_editor_help_tab'                            => array(
281
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
282
-                        'filename' => 'event_editor',
283
-                    ),
284
-                    'event_editor_title_richtexteditor_help_tab'       => array(
285
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
286
-                        'filename' => 'event_editor_title_richtexteditor',
287
-                    ),
288
-                    'event_editor_venue_details_help_tab'              => array(
289
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
290
-                        'filename' => 'event_editor_venue_details',
291
-                    ),
292
-                    'event_editor_event_datetimes_help_tab'            => array(
293
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
294
-                        'filename' => 'event_editor_event_datetimes',
295
-                    ),
296
-                    'event_editor_event_tickets_help_tab'              => array(
297
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
298
-                        'filename' => 'event_editor_event_tickets',
299
-                    ),
300
-                    'event_editor_event_registration_options_help_tab' => array(
301
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
302
-                        'filename' => 'event_editor_event_registration_options',
303
-                    ),
304
-                    'event_editor_tags_categories_help_tab'            => array(
305
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
306
-                        'filename' => 'event_editor_tags_categories',
307
-                    ),
308
-                    'event_editor_questions_registrants_help_tab'      => array(
309
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
310
-                        'filename' => 'event_editor_questions_registrants',
311
-                    ),
312
-                    'event_editor_save_new_event_help_tab'             => array(
313
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
314
-                        'filename' => 'event_editor_save_new_event',
315
-                    ),
316
-                    'event_editor_other_help_tab'                      => array(
317
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
318
-                        'filename' => 'event_editor_other',
319
-                    ),
320
-                ),
321
-                'help_tour'     => array(
322
-                    'Event_Editor_Help_Tour',
323
-                ),
324
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
325
-                'require_nonce' => false,
326
-            ),
327
-            'edit'                   => array(
328
-                'nav'           => array(
329
-                    'label'      => esc_html__('Edit Event', 'event_espresso'),
330
-                    'order'      => 5,
331
-                    'persistent' => false,
332
-                    'url'        => isset($this->_req_data['post'])
333
-                        ? EE_Admin_Page::add_query_args_and_nonce(
334
-                            array('post' => $this->_req_data['post'], 'action' => 'edit'),
335
-                            $this->_current_page_view_url
336
-                        )
337
-                        : $this->_admin_base_url,
338
-                ),
339
-                'metaboxes'     => array('_register_event_editor_meta_boxes'),
340
-                'help_tabs'     => array(
341
-                    'event_editor_help_tab'                            => array(
342
-                        'title'    => esc_html__('Event Editor', 'event_espresso'),
343
-                        'filename' => 'event_editor',
344
-                    ),
345
-                    'event_editor_title_richtexteditor_help_tab'       => array(
346
-                        'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
347
-                        'filename' => 'event_editor_title_richtexteditor',
348
-                    ),
349
-                    'event_editor_venue_details_help_tab'              => array(
350
-                        'title'    => esc_html__('Event Venue Details', 'event_espresso'),
351
-                        'filename' => 'event_editor_venue_details',
352
-                    ),
353
-                    'event_editor_event_datetimes_help_tab'            => array(
354
-                        'title'    => esc_html__('Event Datetimes', 'event_espresso'),
355
-                        'filename' => 'event_editor_event_datetimes',
356
-                    ),
357
-                    'event_editor_event_tickets_help_tab'              => array(
358
-                        'title'    => esc_html__('Event Tickets', 'event_espresso'),
359
-                        'filename' => 'event_editor_event_tickets',
360
-                    ),
361
-                    'event_editor_event_registration_options_help_tab' => array(
362
-                        'title'    => esc_html__('Event Registration Options', 'event_espresso'),
363
-                        'filename' => 'event_editor_event_registration_options',
364
-                    ),
365
-                    'event_editor_tags_categories_help_tab'            => array(
366
-                        'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
367
-                        'filename' => 'event_editor_tags_categories',
368
-                    ),
369
-                    'event_editor_questions_registrants_help_tab'      => array(
370
-                        'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
371
-                        'filename' => 'event_editor_questions_registrants',
372
-                    ),
373
-                    'event_editor_save_new_event_help_tab'             => array(
374
-                        'title'    => esc_html__('Save New Event', 'event_espresso'),
375
-                        'filename' => 'event_editor_save_new_event',
376
-                    ),
377
-                    'event_editor_other_help_tab'                      => array(
378
-                        'title'    => esc_html__('Event Other', 'event_espresso'),
379
-                        'filename' => 'event_editor_other',
380
-                    ),
381
-                ),
382
-                /*'help_tour' => array(
20
+	/**
21
+	 * This will hold the event object for event_details screen.
22
+	 *
23
+	 * @access protected
24
+	 * @var EE_Event $_event
25
+	 */
26
+	protected $_event;
27
+
28
+
29
+	/**
30
+	 * This will hold the category object for category_details screen.
31
+	 *
32
+	 * @var stdClass $_category
33
+	 */
34
+	protected $_category;
35
+
36
+
37
+	/**
38
+	 * This will hold the event model instance
39
+	 *
40
+	 * @var EEM_Event $_event_model
41
+	 */
42
+	protected $_event_model;
43
+
44
+
45
+
46
+	/**
47
+	 * @var EE_Event
48
+	 */
49
+	protected $_cpt_model_obj = false;
50
+
51
+
52
+
53
+	protected function _init_page_props()
54
+	{
55
+		$this->page_slug = EVENTS_PG_SLUG;
56
+		$this->page_label = EVENTS_LABEL;
57
+		$this->_admin_base_url = EVENTS_ADMIN_URL;
58
+		$this->_admin_base_path = EVENTS_ADMIN;
59
+		$this->_cpt_model_names = array(
60
+			'create_new' => 'EEM_Event',
61
+			'edit'       => 'EEM_Event',
62
+		);
63
+		$this->_cpt_edit_routes = array(
64
+			'espresso_events' => 'edit',
65
+		);
66
+		add_action(
67
+			'AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object',
68
+			array($this, 'verify_event_edit')
69
+		);
70
+	}
71
+
72
+
73
+
74
+	protected function _ajax_hooks()
75
+	{
76
+		//todo: all hooks for events ajax goes in here.
77
+	}
78
+
79
+
80
+
81
+	protected function _define_page_props()
82
+	{
83
+		$this->_admin_page_title = EVENTS_LABEL;
84
+		$this->_labels = array(
85
+			'buttons'      => array(
86
+				'add'             => esc_html__('Add New Event', 'event_espresso'),
87
+				'edit'            => esc_html__('Edit Event', 'event_espresso'),
88
+				'delete'          => esc_html__('Delete Event', 'event_espresso'),
89
+				'add_category'    => esc_html__('Add New Category', 'event_espresso'),
90
+				'edit_category'   => esc_html__('Edit Category', 'event_espresso'),
91
+				'delete_category' => esc_html__('Delete Category', 'event_espresso'),
92
+			),
93
+			'editor_title' => array(
94
+				'espresso_events' => esc_html__('Enter event title here', 'event_espresso'),
95
+			),
96
+			'publishbox'   => array(
97
+				'create_new'        => esc_html__('Save New Event', 'event_espresso'),
98
+				'edit'              => esc_html__('Update Event', 'event_espresso'),
99
+				'add_category'      => esc_html__('Save New Category', 'event_espresso'),
100
+				'edit_category'     => esc_html__('Update Category', 'event_espresso'),
101
+				'template_settings' => esc_html__('Update Settings', 'event_espresso'),
102
+			),
103
+		);
104
+	}
105
+
106
+
107
+
108
+	protected function _set_page_routes()
109
+	{
110
+		//load formatter helper
111
+		//load field generator helper
112
+		//is there a evt_id in the request?
113
+		$evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID'])
114
+			? $this->_req_data['EVT_ID'] : 0;
115
+		$evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id;
116
+		$this->_page_routes = array(
117
+			'default'                       => array(
118
+				'func'       => '_events_overview_list_table',
119
+				'capability' => 'ee_read_events',
120
+			),
121
+			'create_new'                    => array(
122
+				'func'       => '_create_new_cpt_item',
123
+				'capability' => 'ee_edit_events',
124
+			),
125
+			'edit'                          => array(
126
+				'func'       => '_edit_cpt_item',
127
+				'capability' => 'ee_edit_event',
128
+				'obj_id'     => $evt_id,
129
+			),
130
+			'copy_event'                    => array(
131
+				'func'       => '_copy_events',
132
+				'capability' => 'ee_edit_event',
133
+				'obj_id'     => $evt_id,
134
+				'noheader'   => true,
135
+			),
136
+			'trash_event'                   => array(
137
+				'func'       => '_trash_or_restore_event',
138
+				'args'       => array('event_status' => 'trash'),
139
+				'capability' => 'ee_delete_event',
140
+				'obj_id'     => $evt_id,
141
+				'noheader'   => true,
142
+			),
143
+			'trash_events'                  => array(
144
+				'func'       => '_trash_or_restore_events',
145
+				'args'       => array('event_status' => 'trash'),
146
+				'capability' => 'ee_delete_events',
147
+				'noheader'   => true,
148
+			),
149
+			'restore_event'                 => array(
150
+				'func'       => '_trash_or_restore_event',
151
+				'args'       => array('event_status' => 'draft'),
152
+				'capability' => 'ee_delete_event',
153
+				'obj_id'     => $evt_id,
154
+				'noheader'   => true,
155
+			),
156
+			'restore_events'                => array(
157
+				'func'       => '_trash_or_restore_events',
158
+				'args'       => array('event_status' => 'draft'),
159
+				'capability' => 'ee_delete_events',
160
+				'noheader'   => true,
161
+			),
162
+			'delete_event'                  => array(
163
+				'func'       => '_delete_event',
164
+				'capability' => 'ee_delete_event',
165
+				'obj_id'     => $evt_id,
166
+				'noheader'   => true,
167
+			),
168
+			'delete_events'                 => array(
169
+				'func'       => '_delete_events',
170
+				'capability' => 'ee_delete_events',
171
+				'noheader'   => true,
172
+			),
173
+			'view_report'                   => array(
174
+				'func'      => '_view_report',
175
+				'capablity' => 'ee_edit_events',
176
+			),
177
+			'default_event_settings'        => array(
178
+				'func'       => '_default_event_settings',
179
+				'capability' => 'manage_options',
180
+			),
181
+			'update_default_event_settings' => array(
182
+				'func'       => '_update_default_event_settings',
183
+				'capability' => 'manage_options',
184
+				'noheader'   => true,
185
+			),
186
+			'template_settings'             => array(
187
+				'func'       => '_template_settings',
188
+				'capability' => 'manage_options',
189
+			),
190
+			//event category tab related
191
+			'add_category'                  => array(
192
+				'func'       => '_category_details',
193
+				'capability' => 'ee_edit_event_category',
194
+				'args'       => array('add'),
195
+			),
196
+			'edit_category'                 => array(
197
+				'func'       => '_category_details',
198
+				'capability' => 'ee_edit_event_category',
199
+				'args'       => array('edit'),
200
+			),
201
+			'delete_categories'             => array(
202
+				'func'       => '_delete_categories',
203
+				'capability' => 'ee_delete_event_category',
204
+				'noheader'   => true,
205
+			),
206
+			'delete_category'               => array(
207
+				'func'       => '_delete_categories',
208
+				'capability' => 'ee_delete_event_category',
209
+				'noheader'   => true,
210
+			),
211
+			'insert_category'               => array(
212
+				'func'       => '_insert_or_update_category',
213
+				'args'       => array('new_category' => true),
214
+				'capability' => 'ee_edit_event_category',
215
+				'noheader'   => true,
216
+			),
217
+			'update_category'               => array(
218
+				'func'       => '_insert_or_update_category',
219
+				'args'       => array('new_category' => false),
220
+				'capability' => 'ee_edit_event_category',
221
+				'noheader'   => true,
222
+			),
223
+			'category_list'                 => array(
224
+				'func'       => '_category_list_table',
225
+				'capability' => 'ee_manage_event_categories',
226
+			),
227
+		);
228
+	}
229
+
230
+
231
+
232
+	protected function _set_page_config()
233
+	{
234
+		$this->_page_config = array(
235
+			'default'                => array(
236
+				'nav'           => array(
237
+					'label' => esc_html__('Overview', 'event_espresso'),
238
+					'order' => 10,
239
+				),
240
+				'list_table'    => 'Events_Admin_List_Table',
241
+				'help_tabs'     => array(
242
+					'events_overview_help_tab'                       => array(
243
+						'title'    => esc_html__('Events Overview', 'event_espresso'),
244
+						'filename' => 'events_overview',
245
+					),
246
+					'events_overview_table_column_headings_help_tab' => array(
247
+						'title'    => esc_html__('Events Overview Table Column Headings', 'event_espresso'),
248
+						'filename' => 'events_overview_table_column_headings',
249
+					),
250
+					'events_overview_filters_help_tab'               => array(
251
+						'title'    => esc_html__('Events Overview Filters', 'event_espresso'),
252
+						'filename' => 'events_overview_filters',
253
+					),
254
+					'events_overview_view_help_tab'                  => array(
255
+						'title'    => esc_html__('Events Overview Views', 'event_espresso'),
256
+						'filename' => 'events_overview_views',
257
+					),
258
+					'events_overview_other_help_tab'                 => array(
259
+						'title'    => esc_html__('Events Overview Other', 'event_espresso'),
260
+						'filename' => 'events_overview_other',
261
+					),
262
+				),
263
+				'help_tour'     => array(
264
+					'Event_Overview_Help_Tour',
265
+					//'New_Features_Test_Help_Tour' for testing multiple help tour
266
+				),
267
+				'qtips'         => array(
268
+					'EE_Event_List_Table_Tips',
269
+				),
270
+				'require_nonce' => false,
271
+			),
272
+			'create_new'             => array(
273
+				'nav'           => array(
274
+					'label'      => esc_html__('Add Event', 'event_espresso'),
275
+					'order'      => 5,
276
+					'persistent' => false,
277
+				),
278
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
279
+				'help_tabs'     => array(
280
+					'event_editor_help_tab'                            => array(
281
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
282
+						'filename' => 'event_editor',
283
+					),
284
+					'event_editor_title_richtexteditor_help_tab'       => array(
285
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
286
+						'filename' => 'event_editor_title_richtexteditor',
287
+					),
288
+					'event_editor_venue_details_help_tab'              => array(
289
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
290
+						'filename' => 'event_editor_venue_details',
291
+					),
292
+					'event_editor_event_datetimes_help_tab'            => array(
293
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
294
+						'filename' => 'event_editor_event_datetimes',
295
+					),
296
+					'event_editor_event_tickets_help_tab'              => array(
297
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
298
+						'filename' => 'event_editor_event_tickets',
299
+					),
300
+					'event_editor_event_registration_options_help_tab' => array(
301
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
302
+						'filename' => 'event_editor_event_registration_options',
303
+					),
304
+					'event_editor_tags_categories_help_tab'            => array(
305
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
306
+						'filename' => 'event_editor_tags_categories',
307
+					),
308
+					'event_editor_questions_registrants_help_tab'      => array(
309
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
310
+						'filename' => 'event_editor_questions_registrants',
311
+					),
312
+					'event_editor_save_new_event_help_tab'             => array(
313
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
314
+						'filename' => 'event_editor_save_new_event',
315
+					),
316
+					'event_editor_other_help_tab'                      => array(
317
+						'title'    => esc_html__('Event Other', 'event_espresso'),
318
+						'filename' => 'event_editor_other',
319
+					),
320
+				),
321
+				'help_tour'     => array(
322
+					'Event_Editor_Help_Tour',
323
+				),
324
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
325
+				'require_nonce' => false,
326
+			),
327
+			'edit'                   => array(
328
+				'nav'           => array(
329
+					'label'      => esc_html__('Edit Event', 'event_espresso'),
330
+					'order'      => 5,
331
+					'persistent' => false,
332
+					'url'        => isset($this->_req_data['post'])
333
+						? EE_Admin_Page::add_query_args_and_nonce(
334
+							array('post' => $this->_req_data['post'], 'action' => 'edit'),
335
+							$this->_current_page_view_url
336
+						)
337
+						: $this->_admin_base_url,
338
+				),
339
+				'metaboxes'     => array('_register_event_editor_meta_boxes'),
340
+				'help_tabs'     => array(
341
+					'event_editor_help_tab'                            => array(
342
+						'title'    => esc_html__('Event Editor', 'event_espresso'),
343
+						'filename' => 'event_editor',
344
+					),
345
+					'event_editor_title_richtexteditor_help_tab'       => array(
346
+						'title'    => esc_html__('Event Title & Rich Text Editor', 'event_espresso'),
347
+						'filename' => 'event_editor_title_richtexteditor',
348
+					),
349
+					'event_editor_venue_details_help_tab'              => array(
350
+						'title'    => esc_html__('Event Venue Details', 'event_espresso'),
351
+						'filename' => 'event_editor_venue_details',
352
+					),
353
+					'event_editor_event_datetimes_help_tab'            => array(
354
+						'title'    => esc_html__('Event Datetimes', 'event_espresso'),
355
+						'filename' => 'event_editor_event_datetimes',
356
+					),
357
+					'event_editor_event_tickets_help_tab'              => array(
358
+						'title'    => esc_html__('Event Tickets', 'event_espresso'),
359
+						'filename' => 'event_editor_event_tickets',
360
+					),
361
+					'event_editor_event_registration_options_help_tab' => array(
362
+						'title'    => esc_html__('Event Registration Options', 'event_espresso'),
363
+						'filename' => 'event_editor_event_registration_options',
364
+					),
365
+					'event_editor_tags_categories_help_tab'            => array(
366
+						'title'    => esc_html__('Event Tags & Categories', 'event_espresso'),
367
+						'filename' => 'event_editor_tags_categories',
368
+					),
369
+					'event_editor_questions_registrants_help_tab'      => array(
370
+						'title'    => esc_html__('Questions for Registrants', 'event_espresso'),
371
+						'filename' => 'event_editor_questions_registrants',
372
+					),
373
+					'event_editor_save_new_event_help_tab'             => array(
374
+						'title'    => esc_html__('Save New Event', 'event_espresso'),
375
+						'filename' => 'event_editor_save_new_event',
376
+					),
377
+					'event_editor_other_help_tab'                      => array(
378
+						'title'    => esc_html__('Event Other', 'event_espresso'),
379
+						'filename' => 'event_editor_other',
380
+					),
381
+				),
382
+				/*'help_tour' => array(
383 383
 					'Event_Edit_Help_Tour'
384 384
 				),*/
385
-                'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
386
-                'require_nonce' => false,
387
-            ),
388
-            'default_event_settings' => array(
389
-                'nav'           => array(
390
-                    'label' => esc_html__('Default Settings', 'event_espresso'),
391
-                    'order' => 40,
392
-                ),
393
-                'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
394
-                'labels'        => array(
395
-                    'publishbox' => esc_html__('Update Settings', 'event_espresso'),
396
-                ),
397
-                'help_tabs'     => array(
398
-                    'default_settings_help_tab'        => array(
399
-                        'title'    => esc_html__('Default Event Settings', 'event_espresso'),
400
-                        'filename' => 'events_default_settings',
401
-                    ),
402
-                    'default_settings_status_help_tab' => array(
403
-                        'title'    => esc_html__('Default Registration Status', 'event_espresso'),
404
-                        'filename' => 'events_default_settings_status',
405
-                    ),
406
-                ),
407
-                'help_tour'     => array('Event_Default_Settings_Help_Tour'),
408
-                'require_nonce' => false,
409
-            ),
410
-            //template settings
411
-            'template_settings'      => array(
412
-                'nav'           => array(
413
-                    'label' => esc_html__('Templates', 'event_espresso'),
414
-                    'order' => 30,
415
-                ),
416
-                'metaboxes'     => $this->_default_espresso_metaboxes,
417
-                'help_tabs'     => array(
418
-                    'general_settings_templates_help_tab' => array(
419
-                        'title'    => esc_html__('Templates', 'event_espresso'),
420
-                        'filename' => 'general_settings_templates',
421
-                    ),
422
-                ),
423
-                'help_tour'     => array('Templates_Help_Tour'),
424
-                'require_nonce' => false,
425
-            ),
426
-            //event category stuff
427
-            'add_category'           => array(
428
-                'nav'           => array(
429
-                    'label'      => esc_html__('Add Category', 'event_espresso'),
430
-                    'order'      => 15,
431
-                    'persistent' => false,
432
-                ),
433
-                'help_tabs'     => array(
434
-                    'add_category_help_tab' => array(
435
-                        'title'    => esc_html__('Add New Event Category', 'event_espresso'),
436
-                        'filename' => 'events_add_category',
437
-                    ),
438
-                ),
439
-                'help_tour'     => array('Event_Add_Category_Help_Tour'),
440
-                'metaboxes'     => array('_publish_post_box'),
441
-                'require_nonce' => false,
442
-            ),
443
-            'edit_category'          => array(
444
-                'nav'           => array(
445
-                    'label'      => esc_html__('Edit Category', 'event_espresso'),
446
-                    'order'      => 15,
447
-                    'persistent' => false,
448
-                    'url'        => isset($this->_req_data['EVT_CAT_ID'])
449
-                        ? add_query_arg(
450
-                            array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
451
-                            $this->_current_page_view_url
452
-                        )
453
-                        : $this->_admin_base_url,
454
-                ),
455
-                'help_tabs'     => array(
456
-                    'edit_category_help_tab' => array(
457
-                        'title'    => esc_html__('Edit Event Category', 'event_espresso'),
458
-                        'filename' => 'events_edit_category',
459
-                    ),
460
-                ),
461
-                /*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
462
-                'metaboxes'     => array('_publish_post_box'),
463
-                'require_nonce' => false,
464
-            ),
465
-            'category_list'          => array(
466
-                'nav'           => array(
467
-                    'label' => esc_html__('Categories', 'event_espresso'),
468
-                    'order' => 20,
469
-                ),
470
-                'list_table'    => 'Event_Categories_Admin_List_Table',
471
-                'help_tabs'     => array(
472
-                    'events_categories_help_tab'                       => array(
473
-                        'title'    => esc_html__('Event Categories', 'event_espresso'),
474
-                        'filename' => 'events_categories',
475
-                    ),
476
-                    'events_categories_table_column_headings_help_tab' => array(
477
-                        'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
478
-                        'filename' => 'events_categories_table_column_headings',
479
-                    ),
480
-                    'events_categories_view_help_tab'                  => array(
481
-                        'title'    => esc_html__('Event Categories Views', 'event_espresso'),
482
-                        'filename' => 'events_categories_views',
483
-                    ),
484
-                    'events_categories_other_help_tab'                 => array(
485
-                        'title'    => esc_html__('Event Categories Other', 'event_espresso'),
486
-                        'filename' => 'events_categories_other',
487
-                    ),
488
-                ),
489
-                'help_tour'     => array(
490
-                    'Event_Categories_Help_Tour',
491
-                ),
492
-                'metaboxes'     => $this->_default_espresso_metaboxes,
493
-                'require_nonce' => false,
494
-            ),
495
-        );
496
-    }
497
-
498
-
499
-
500
-    protected function _add_screen_options()
501
-    {
502
-        //todo
503
-    }
504
-
505
-
506
-
507
-    protected function _add_screen_options_default()
508
-    {
509
-        $this->_per_page_screen_option();
510
-    }
511
-
512
-
513
-
514
-    protected function _add_screen_options_category_list()
515
-    {
516
-        $page_title = $this->_admin_page_title;
517
-        $this->_admin_page_title = esc_html__('Categories', 'event_espresso');
518
-        $this->_per_page_screen_option();
519
-        $this->_admin_page_title = $page_title;
520
-    }
521
-
522
-
523
-
524
-    protected function _add_feature_pointers()
525
-    {
526
-        //todo
527
-    }
528
-
529
-
530
-
531
-    public function load_scripts_styles()
532
-    {
533
-        wp_register_style(
534
-            'events-admin-css',
535
-            EVENTS_ASSETS_URL . 'events-admin-page.css',
536
-            array(),
537
-            EVENT_ESPRESSO_VERSION
538
-        );
539
-        wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
540
-        wp_enqueue_style('events-admin-css');
541
-        wp_enqueue_style('ee-cat-admin');
542
-        //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
543
-        //registers for all views
544
-        //scripts
545
-        wp_register_script(
546
-            'event_editor_js',
547
-            EVENTS_ASSETS_URL . 'event_editor.js',
548
-            array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
549
-            EVENT_ESPRESSO_VERSION,
550
-            true
551
-        );
552
-    }
553
-
554
-
555
-
556
-    /**
557
-     * enqueuing scripts and styles specific to this view
558
-     *
559
-     * @return void
560
-     */
561
-    public function load_scripts_styles_create_new()
562
-    {
563
-        $this->load_scripts_styles_edit();
564
-    }
565
-
566
-
567
-
568
-    /**
569
-     * enqueuing scripts and styles specific to this view
570
-     *
571
-     * @return void
572
-     */
573
-    public function load_scripts_styles_edit()
574
-    {
575
-        //styles
576
-        wp_enqueue_style('espresso-ui-theme');
577
-        wp_register_style(
578
-            'event-editor-css',
579
-            EVENTS_ASSETS_URL . 'event-editor.css',
580
-            array('ee-admin-css'),
581
-            EVENT_ESPRESSO_VERSION
582
-        );
583
-        wp_enqueue_style('event-editor-css');
584
-        //scripts
585
-        wp_register_script(
586
-            'event-datetime-metabox',
587
-            EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
588
-            array('event_editor_js', 'ee-datepicker'),
589
-            EVENT_ESPRESSO_VERSION
590
-        );
591
-        wp_enqueue_script('event-datetime-metabox');
592
-    }
593
-
594
-
595
-
596
-    public function load_scripts_styles_add_category()
597
-    {
598
-        $this->load_scripts_styles_edit_category();
599
-    }
600
-
601
-
602
-
603
-    public function load_scripts_styles_edit_category()
604
-    {
605
-    }
606
-
607
-
608
-
609
-    protected function _set_list_table_views_category_list()
610
-    {
611
-        $this->_views = array(
612
-            'all' => array(
613
-                'slug'        => 'all',
614
-                'label'       => esc_html__('All', 'event_espresso'),
615
-                'count'       => 0,
616
-                'bulk_action' => array(
617
-                    'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
618
-                ),
619
-            ),
620
-        );
621
-    }
622
-
623
-
624
-
625
-    public function admin_init()
626
-    {
627
-        EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
628
-            'Do you really want to delete this image? Please remember to update your event to complete the removal.',
629
-            'event_espresso'
630
-        );
631
-    }
632
-
633
-
634
-
635
-    //nothing needed for events with these methods.
636
-    public function admin_notices()
637
-    {
638
-    }
639
-
640
-
641
-
642
-    public function admin_footer_scripts()
643
-    {
644
-    }
645
-
646
-
647
-
648
-    /**
649
-     * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
650
-     * warning (via EE_Error::add_error());
651
-     *
652
-     * @param  EE_Event $event Event object
653
-     * @access public
654
-     * @return void
655
-     */
656
-    public function verify_event_edit($event = null)
657
-    {
658
-        // no event?
659
-        if (empty($event)) {
660
-            // set event
661
-            $event = $this->_cpt_model_obj;
662
-        }
663
-        // STILL no event?
664
-        if (empty ($event)) {
665
-            return;
666
-        }
667
-        $orig_status = $event->status();
668
-        // first check if event is active.
669
-        if (
670
-            $orig_status === EEM_Event::cancelled
671
-            || $orig_status === EEM_Event::postponed
672
-            || $event->is_expired()
673
-            || $event->is_inactive()
674
-        ) {
675
-            return;
676
-        }
677
-        //made it here so it IS active... next check that any of the tickets are sold.
678
-        if ($event->is_sold_out(true)) {
679
-            if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
680
-                EE_Error::add_attention(
681
-                    sprintf(
682
-                        esc_html__(
683
-                            'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
684
-                            'event_espresso'
685
-                        ),
686
-                        EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
687
-                    )
688
-                );
689
-            }
690
-            return;
691
-        } else if ($orig_status === EEM_Event::sold_out) {
692
-            EE_Error::add_attention(
693
-                sprintf(
694
-                    esc_html__(
695
-                        'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
696
-                        'event_espresso'
697
-                    ),
698
-                    EEH_Template::pretty_status($event->status(), false, 'sentence')
699
-                )
700
-            );
701
-        }
702
-        //now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
703
-        if ( ! $event->tickets_on_sale()) {
704
-            return;
705
-        }
706
-        //made it here so show warning
707
-        $this->_edit_event_warning();
708
-    }
709
-
710
-
711
-
712
-    /**
713
-     * This is the text used for when an event is being edited that is public and has tickets for sale.
714
-     * When needed, hook this into a EE_Error::add_error() notice.
715
-     *
716
-     * @access protected
717
-     * @return void
718
-     */
719
-    protected function _edit_event_warning()
720
-    {
721
-        // we don't want to add warnings during these requests
722
-        if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
723
-            return;
724
-        }
725
-        EE_Error::add_attention(
726
-            esc_html__(
727
-                'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
728
-                'event_espresso'
729
-            )
730
-        );
731
-    }
732
-
733
-
734
-
735
-    /**
736
-     * When a user is creating a new event, notify them if they haven't set their timezone.
737
-     * Otherwise, do the normal logic
738
-     *
739
-     * @return string
740
-     * @throws \EE_Error
741
-     */
742
-    protected function _create_new_cpt_item()
743
-    {
744
-        $gmt_offset = get_option('gmt_offset');
745
-        //only nag them about setting their timezone if it's their first event, and they haven't already done it
746
-        if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
747
-            EE_Error::add_attention(
748
-                sprintf(
749
-                    __(
750
-                        'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
751
-                        'event_espresso'
752
-                    ),
753
-                    '<a href="' . admin_url('options-general.php') . '">',
754
-                    '</a>'
755
-                ),
756
-                __FILE__,
757
-                __FUNCTION__,
758
-                __LINE__
759
-            );
760
-        }
761
-        return parent::_create_new_cpt_item();
762
-    }
763
-
764
-
765
-
766
-    protected function _set_list_table_views_default()
767
-    {
768
-        $this->_views = array(
769
-            'all'   => array(
770
-                'slug'        => 'all',
771
-                'label'       => esc_html__('View All Events', 'event_espresso'),
772
-                'count'       => 0,
773
-                'bulk_action' => array(
774
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
775
-                ),
776
-            ),
777
-            'draft' => array(
778
-                'slug'        => 'draft',
779
-                'label'       => esc_html__('Draft', 'event_espresso'),
780
-                'count'       => 0,
781
-                'bulk_action' => array(
782
-                    'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
783
-                ),
784
-            ),
785
-        );
786
-        if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
787
-            $this->_views['trash'] = array(
788
-                'slug'        => 'trash',
789
-                'label'       => esc_html__('Trash', 'event_espresso'),
790
-                'count'       => 0,
791
-                'bulk_action' => array(
792
-                    'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
793
-                    'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
794
-                ),
795
-            );
796
-        }
797
-    }
798
-
799
-
800
-
801
-    /**
802
-     * @return array
803
-     */
804
-    protected function _event_legend_items()
805
-    {
806
-        $items = array(
807
-            'view_details'   => array(
808
-                'class' => 'dashicons dashicons-search',
809
-                'desc'  => esc_html__('View Event', 'event_espresso'),
810
-            ),
811
-            'edit_event'     => array(
812
-                'class' => 'ee-icon ee-icon-calendar-edit',
813
-                'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
814
-            ),
815
-            'view_attendees' => array(
816
-                'class' => 'dashicons dashicons-groups',
817
-                'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
818
-            ),
819
-        );
820
-        $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
821
-        $statuses = array(
822
-            'sold_out_status'  => array(
823
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
824
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
825
-            ),
826
-            'active_status'    => array(
827
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
828
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
829
-            ),
830
-            'upcoming_status'  => array(
831
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
832
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
833
-            ),
834
-            'postponed_status' => array(
835
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
836
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
837
-            ),
838
-            'cancelled_status' => array(
839
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
840
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
841
-            ),
842
-            'expired_status'   => array(
843
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
844
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
845
-            ),
846
-            'inactive_status'  => array(
847
-                'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
848
-                'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
849
-            ),
850
-        );
851
-        $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
852
-        return array_merge($items, $statuses);
853
-    }
854
-
855
-
856
-
857
-    /**
858
-     * _event_model
859
-     *
860
-     * @return EEM_Event
861
-     */
862
-    private function _event_model()
863
-    {
864
-        if ( ! $this->_event_model instanceof EEM_Event) {
865
-            $this->_event_model = EE_Registry::instance()->load_model('Event');
866
-        }
867
-        return $this->_event_model;
868
-    }
869
-
870
-
871
-
872
-    /**
873
-     * Adds extra buttons to the WP CPT permalink field row.
874
-     * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
875
-     *
876
-     * @param  string $return    the current html
877
-     * @param  int    $id        the post id for the page
878
-     * @param  string $new_title What the title is
879
-     * @param  string $new_slug  what the slug is
880
-     * @return string            The new html string for the permalink area
881
-     */
882
-    public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
883
-    {
884
-        //make sure this is only when editing
885
-        if ( ! empty($id)) {
886
-            $post = get_post($id);
887
-            $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
888
-                       . esc_html__('Shortcode', 'event_espresso')
889
-                       . '</a> ';
890
-            $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
891
-                       . $post->ID
892
-                       . ']">';
893
-        }
894
-        return $return;
895
-    }
896
-
897
-
898
-
899
-    /**
900
-     * _events_overview_list_table
901
-     * This contains the logic for showing the events_overview list
902
-     *
903
-     * @access protected
904
-     * @return void
905
-     * @throws \EE_Error
906
-     */
907
-    protected function _events_overview_list_table()
908
-    {
909
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
910
-        $this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
911
-            ? (array)$this->_template_args['after_list_table']
912
-            : array();
913
-        $this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
914
-                                                                              . EEH_Template::get_button_or_link(
915
-                get_post_type_archive_link('espresso_events'),
916
-                esc_html__("View Event Archive Page", "event_espresso"),
917
-                'button'
918
-            );
919
-        $this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
920
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
921
-                'create_new',
922
-                'add',
923
-                array(),
924
-                'add-new-h2'
925
-            );
926
-        $this->display_admin_list_table_page_with_no_sidebar();
927
-    }
928
-
929
-
930
-
931
-    /**
932
-     * this allows for extra misc actions in the default WP publish box
933
-     *
934
-     * @return void
935
-     */
936
-    public function extra_misc_actions_publish_box()
937
-    {
938
-        $this->_generate_publish_box_extra_content();
939
-    }
940
-
941
-
942
-
943
-    /**
944
-     * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
945
-     * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
946
-     * data.
947
-     * Keep in mind also that "save_post" runs on EVERY post update to the database.
948
-     * ALSO very important.  When a post transitions from scheduled to published, the save_post action is fired but you
949
-     * will NOT have any _POST data containing any extra info you may have from other meta saves.  So MAKE sure that
950
-     * you handle this accordingly.
951
-     *
952
-     * @access protected
953
-     * @abstract
954
-     * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
955
-     * @param  object $post    The post object of the cpt that was saved.
956
-     * @return void
957
-     */
958
-    protected function _insert_update_cpt_item($post_id, $post)
959
-    {
960
-        if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
961
-            //get out we're not processing an event save.
962
-            return;
963
-        }
964
-        $event_values = array(
965
-            'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
966
-            'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
967
-            'EVT_additional_limit'            => min(
968
-                apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
969
-                ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
970
-            ),
971
-            'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
972
-                ? $this->_req_data['EVT_default_registration_status']
973
-                : EE_Registry::instance()->CFG->registration->default_STS_ID,
974
-            'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
975
-            'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
976
-            'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
977
-                ? $this->_req_data['timezone_string'] : null,
978
-            'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
979
-                ? $this->_req_data['externalURL'] : null,
980
-            'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
981
-                ? $this->_req_data['event_phone'] : null,
982
-        );
983
-        //update event
984
-        $success = $this->_event_model()->update_by_ID($event_values, $post_id);
985
-        //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
986
-        $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
987
-        $event = $this->_event_model()->get_one(array($get_one_where));
988
-        //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
989
-        $event_update_callbacks = apply_filters(
990
-            'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
991
-            array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
992
-        );
993
-        $att_success = true;
994
-        foreach ($event_update_callbacks as $e_callback) {
995
-            $_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
996
-            $att_success = ! $att_success ? $att_success
997
-                : $_succ; //if ANY of these updates fail then we want the appropriate global error message
998
-        }
999
-        //any errors?
1000
-        if ($success && false === $att_success) {
1001
-            EE_Error::add_error(
1002
-                esc_html__(
1003
-                    'Event Details saved successfully but something went wrong with saving attachments.',
1004
-                    'event_espresso'
1005
-                ),
1006
-                __FILE__,
1007
-                __FUNCTION__,
1008
-                __LINE__
1009
-            );
1010
-        } else if ($success === false) {
1011
-            EE_Error::add_error(
1012
-                esc_html__('Event Details did not save successfully.', 'event_espresso'),
1013
-                __FILE__,
1014
-                __FUNCTION__,
1015
-                __LINE__
1016
-            );
1017
-        }
1018
-    }
1019
-
1020
-
1021
-
1022
-    /**
1023
-     * @see parent::restore_item()
1024
-     * @param int $post_id
1025
-     * @param int $revision_id
1026
-     */
1027
-    protected function _restore_cpt_item($post_id, $revision_id)
1028
-    {
1029
-        //copy existing event meta to new post
1030
-        $post_evt = $this->_event_model()->get_one_by_ID($post_id);
1031
-        if ($post_evt instanceof EE_Event) {
1032
-            //meta revision restore
1033
-            $post_evt->restore_revision($revision_id);
1034
-            //related objs restore
1035
-            $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1036
-        }
1037
-    }
1038
-
1039
-
1040
-
1041
-    /**
1042
-     * Attach the venue to the Event
1043
-     *
1044
-     * @param  \EE_Event $evtobj Event Object to add the venue to
1045
-     * @param  array     $data   The request data from the form
1046
-     * @return bool           Success or fail.
1047
-     */
1048
-    protected function _default_venue_update(\EE_Event $evtobj, $data)
1049
-    {
1050
-        require_once(EE_MODELS . 'EEM_Venue.model.php');
1051
-        $venue_model = EE_Registry::instance()->load_model('Venue');
1052
-        $rows_affected = null;
1053
-        $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1054
-        // very important.  If we don't have a venue name...
1055
-        // then we'll get out because not necessary to create empty venue
1056
-        if (empty($data['venue_title'])) {
1057
-            return false;
1058
-        }
1059
-        $venue_array = array(
1060
-            'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1061
-            'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1062
-            'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1063
-            'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1064
-            'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1065
-                : null,
1066
-            'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1067
-            'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1068
-            'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1069
-            'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1070
-            'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1071
-            'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1072
-            'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1073
-            'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1074
-            'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1075
-            'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1076
-            'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1077
-            'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1078
-            'status'              => 'publish',
1079
-        );
1080
-        //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1081
-        if ( ! empty($venue_id)) {
1082
-            $update_where = array($venue_model->primary_key_name() => $venue_id);
1083
-            $rows_affected = $venue_model->update($venue_array, array($update_where));
1084
-            //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1085
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1086
-            return $rows_affected > 0 ? true : false;
1087
-        } else {
1088
-            //we insert the venue
1089
-            $venue_id = $venue_model->insert($venue_array);
1090
-            $evtobj->_add_relation_to($venue_id, 'Venue');
1091
-            return ! empty($venue_id) ? true : false;
1092
-        }
1093
-        //when we have the ancestor come in it's already been handled by the revision save.
1094
-    }
1095
-
1096
-
1097
-
1098
-    /**
1099
-     * Handles saving everything related to Tickets (datetimes, tickets, prices)
1100
-     *
1101
-     * @param  EE_Event $evtobj The Event object we're attaching data to
1102
-     * @param  array    $data   The request data from the form
1103
-     * @return array
1104
-     */
1105
-    protected function _default_tickets_update(EE_Event $evtobj, $data)
1106
-    {
1107
-        $success = true;
1108
-        $saved_dtt = null;
1109
-        $saved_tickets = array();
1110
-        $incoming_date_formats = array('Y-m-d', 'h:i a');
1111
-        foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1112
-            //trim all values to ensure any excess whitespace is removed.
1113
-            $dtt = array_map('trim', $dtt);
1114
-            $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1115
-                : $dtt['DTT_EVT_start'];
1116
-            $datetime_values = array(
1117
-                'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1118
-                'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1119
-                'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1120
-                'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1121
-                'DTT_order'     => $row,
1122
-            );
1123
-            //if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1124
-            if ( ! empty($dtt['DTT_ID'])) {
1125
-                $DTM = EE_Registry::instance()
1126
-                                  ->load_model('Datetime', array($evtobj->get_timezone()))
1127
-                                  ->get_one_by_ID($dtt['DTT_ID']);
1128
-                $DTM->set_date_format($incoming_date_formats[0]);
1129
-                $DTM->set_time_format($incoming_date_formats[1]);
1130
-                foreach ($datetime_values as $field => $value) {
1131
-                    $DTM->set($field, $value);
1132
-                }
1133
-                //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1134
-                $saved_dtts[$DTM->ID()] = $DTM;
1135
-            } else {
1136
-                $DTM = EE_Registry::instance()->load_class(
1137
-                    'Datetime',
1138
-                    array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1139
-                    false,
1140
-                    false
1141
-                );
1142
-                foreach ($datetime_values as $field => $value) {
1143
-                    $DTM->set($field, $value);
1144
-                }
1145
-            }
1146
-            $DTM->save();
1147
-            $DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1148
-            //load DTT helper
1149
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1150
-            if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1151
-                $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1152
-                $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1153
-                $DTT->save();
1154
-            }
1155
-            //now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1156
-            $saved_dtt = $DTT;
1157
-            $success = ! $success ? $success : $DTT;
1158
-            //if ANY of these updates fail then we want the appropriate global error message.
1159
-            // //todo this is actually sucky we need a better error message but this is what it is for now.
1160
-        }
1161
-        //no dtts get deleted so we don't do any of that logic here.
1162
-        //update tickets next
1163
-        $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1164
-        foreach ($data['edit_tickets'] as $row => $tkt) {
1165
-            $incoming_date_formats = array('Y-m-d', 'h:i a');
1166
-            $update_prices = false;
1167
-            $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1168
-                ? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1169
-            // trim inputs to ensure any excess whitespace is removed.
1170
-            $tkt = array_map('trim', $tkt);
1171
-            if (empty($tkt['TKT_start_date'])) {
1172
-                //let's use now in the set timezone.
1173
-                $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1174
-                $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1175
-            }
1176
-            if (empty($tkt['TKT_end_date'])) {
1177
-                //use the start date of the first datetime
1178
-                $dtt = $evtobj->first_datetime();
1179
-                $tkt['TKT_end_date'] = $dtt->start_date_and_time(
1180
-                    $incoming_date_formats[0],
1181
-                    $incoming_date_formats[1]
1182
-                );
1183
-            }
1184
-            $TKT_values = array(
1185
-                'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1186
-                'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1187
-                'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1188
-                'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1189
-                'TKT_start_date'  => $tkt['TKT_start_date'],
1190
-                'TKT_end_date'    => $tkt['TKT_end_date'],
1191
-                'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1192
-                'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1193
-                'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1194
-                'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1195
-                'TKT_row'         => $row,
1196
-                'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1197
-                'TKT_price'       => $ticket_price,
1198
-            );
1199
-            //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1200
-            if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1201
-                $TKT_values['TKT_ID'] = 0;
1202
-                $TKT_values['TKT_is_default'] = 0;
1203
-                $TKT_values['TKT_price'] = $ticket_price;
1204
-                $update_prices = true;
1205
-            }
1206
-            //if we have a TKT_ID then we need to get that existing TKT_obj and update it
1207
-            //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1208
-            //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1209
-            if ( ! empty($tkt['TKT_ID'])) {
1210
-                $TKT = EE_Registry::instance()
1211
-                                  ->load_model('Ticket', array($evtobj->get_timezone()))
1212
-                                  ->get_one_by_ID($tkt['TKT_ID']);
1213
-                if ($TKT instanceof EE_Ticket) {
1214
-                    $ticket_sold = $TKT->count_related(
1215
-                        'Registration',
1216
-                        array(
1217
-                            array(
1218
-                                'STS_ID' => array(
1219
-                                    'NOT IN',
1220
-                                    array(EEM_Registration::status_id_incomplete),
1221
-                                ),
1222
-                            ),
1223
-                        )
1224
-                    ) > 0 ? true : false;
1225
-                    //let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1226
-                    $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1227
-                                      && ! $TKT->get(
1228
-                        'TKT_deleted'
1229
-                    ) ? true : false;
1230
-                    $TKT->set_date_format($incoming_date_formats[0]);
1231
-                    $TKT->set_time_format($incoming_date_formats[1]);
1232
-                    //set new values
1233
-                    foreach ($TKT_values as $field => $value) {
1234
-                        if ($field == 'TKT_qty') {
1235
-                            $TKT->set_qty($value);
1236
-                        } else {
1237
-                            $TKT->set($field, $value);
1238
-                        }
1239
-                    }
1240
-                    //if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1241
-                    if ($create_new_TKT) {
1242
-                        //archive the old ticket first
1243
-                        $TKT->set('TKT_deleted', 1);
1244
-                        $TKT->save();
1245
-                        //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1246
-                        $saved_tickets[$TKT->ID()] = $TKT;
1247
-                        //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1248
-                        $TKT = clone $TKT;
1249
-                        $TKT->set('TKT_ID', 0);
1250
-                        $TKT->set('TKT_deleted', 0);
1251
-                        $TKT->set('TKT_price', $ticket_price);
1252
-                        $TKT->set('TKT_sold', 0);
1253
-                        //now we need to make sure that $new prices are created as well and attached to new ticket.
1254
-                        $update_prices = true;
1255
-                    }
1256
-                    //make sure price is set if it hasn't been already
1257
-                    $TKT->set('TKT_price', $ticket_price);
1258
-                }
1259
-            } else {
1260
-                //no TKT_id so a new TKT
1261
-                $TKT_values['TKT_price'] = $ticket_price;
1262
-                $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1263
-                if ($TKT instanceof EE_Ticket) {
1264
-                    //need to reset values to properly account for the date formats
1265
-                    $TKT->set_date_format($incoming_date_formats[0]);
1266
-                    $TKT->set_time_format($incoming_date_formats[1]);
1267
-                    $TKT->set_timezone($evtobj->get_timezone());
1268
-                    //set new values
1269
-                    foreach ($TKT_values as $field => $value) {
1270
-                        if ($field == 'TKT_qty') {
1271
-                            $TKT->set_qty($value);
1272
-                        } else {
1273
-                            $TKT->set($field, $value);
1274
-                        }
1275
-                    }
1276
-                    $update_prices = true;
1277
-                }
1278
-            }
1279
-            // cap ticket qty by datetime reg limits
1280
-            $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1281
-            //update ticket.
1282
-            $TKT->save();
1283
-            //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1284
-            if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1285
-                $TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1286
-                $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1287
-                $TKT->save();
1288
-            }
1289
-            //initially let's add the ticket to the dtt
1290
-            $saved_dtt->_add_relation_to($TKT, 'Ticket');
1291
-            $saved_tickets[$TKT->ID()] = $TKT;
1292
-            //add prices to ticket
1293
-            $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1294
-        }
1295
-        //however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1296
-        $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1297
-        $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1298
-        foreach ($tickets_removed as $id) {
1299
-            $id = absint($id);
1300
-            //get the ticket for this id
1301
-            $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1302
-            //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1303
-            $dtts = $tkt_to_remove->get_many_related('Datetime');
1304
-            foreach ($dtts as $dtt) {
1305
-                $tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1306
-            }
1307
-            //need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1308
-            $tkt_to_remove->delete_related_permanently('Price');
1309
-            //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1310
-            $tkt_to_remove->delete_permanently();
1311
-        }
1312
-        return array($saved_dtt, $saved_tickets);
1313
-    }
1314
-
1315
-
1316
-
1317
-    /**
1318
-     * This attaches a list of given prices to a ticket.
1319
-     * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1320
-     * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1321
-     * price info and prices are automatically "archived" via the ticket.
1322
-     *
1323
-     * @access  private
1324
-     * @param array     $prices     Array of prices from the form.
1325
-     * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1326
-     * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1327
-     * @return  void
1328
-     */
1329
-    private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1330
-    {
1331
-        foreach ($prices as $row => $prc) {
1332
-            $PRC_values = array(
1333
-                'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1334
-                'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1335
-                'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1336
-                'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1337
-                'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1338
-                'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1339
-                'PRC_order'      => $row,
1340
-            );
1341
-            if ($new_prices || empty($PRC_values['PRC_ID'])) {
1342
-                $PRC_values['PRC_ID'] = 0;
1343
-                $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1344
-            } else {
1345
-                $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1346
-                //update this price with new values
1347
-                foreach ($PRC_values as $field => $newprc) {
1348
-                    $PRC->set($field, $newprc);
1349
-                }
1350
-                $PRC->save();
1351
-            }
1352
-            $ticket->_add_relation_to($PRC, 'Price');
1353
-        }
1354
-    }
1355
-
1356
-
1357
-
1358
-    /**
1359
-     * Add in our autosave ajax handlers
1360
-     *
1361
-     * @return void
1362
-     */
1363
-    protected function _ee_autosave_create_new()
1364
-    {
1365
-        // $this->_ee_autosave_edit();
1366
-    }
1367
-
1368
-
1369
-
1370
-    protected function _ee_autosave_edit()
1371
-    {
1372
-        return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1373
-    }
1374
-
1375
-
1376
-
1377
-    /**
1378
-     *    _generate_publish_box_extra_content
1379
-     *
1380
-     * @access private
1381
-     * @return void
1382
-     */
1383
-    private function _generate_publish_box_extra_content()
1384
-    {
1385
-        //load formatter helper
1386
-        //args for getting related registrations
1387
-        $approved_query_args = array(
1388
-            array(
1389
-                'REG_deleted' => 0,
1390
-                'STS_ID'      => EEM_Registration::status_id_approved,
1391
-            ),
1392
-        );
1393
-        $not_approved_query_args = array(
1394
-            array(
1395
-                'REG_deleted' => 0,
1396
-                'STS_ID'      => EEM_Registration::status_id_not_approved,
1397
-            ),
1398
-        );
1399
-        $pending_payment_query_args = array(
1400
-            array(
1401
-                'REG_deleted' => 0,
1402
-                'STS_ID'      => EEM_Registration::status_id_pending_payment,
1403
-            ),
1404
-        );
1405
-        // publish box
1406
-        $publish_box_extra_args = array(
1407
-            'view_approved_reg_url'        => add_query_arg(
1408
-                array(
1409
-                    'action'      => 'default',
1410
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1411
-                    '_reg_status' => EEM_Registration::status_id_approved,
1412
-                ),
1413
-                REG_ADMIN_URL
1414
-            ),
1415
-            'view_not_approved_reg_url'    => add_query_arg(
1416
-                array(
1417
-                    'action'      => 'default',
1418
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1419
-                    '_reg_status' => EEM_Registration::status_id_not_approved,
1420
-                ),
1421
-                REG_ADMIN_URL
1422
-            ),
1423
-            'view_pending_payment_reg_url' => add_query_arg(
1424
-                array(
1425
-                    'action'      => 'default',
1426
-                    'event_id'    => $this->_cpt_model_obj->ID(),
1427
-                    '_reg_status' => EEM_Registration::status_id_pending_payment,
1428
-                ),
1429
-                REG_ADMIN_URL
1430
-            ),
1431
-            'approved_regs'                => $this->_cpt_model_obj->count_related(
1432
-                'Registration',
1433
-                $approved_query_args
1434
-            ),
1435
-            'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1436
-                'Registration',
1437
-                $not_approved_query_args
1438
-            ),
1439
-            'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1440
-                'Registration',
1441
-                $pending_payment_query_args
1442
-            ),
1443
-            'misc_pub_section_class'       => apply_filters(
1444
-                'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1445
-                'misc-pub-section'
1446
-            ),
1447
-            //'email_attendees_url' => add_query_arg(
1448
-            //	array(
1449
-            //		'event_admin_reports' => 'event_newsletter',
1450
-            //		'event_id' => $this->_cpt_model_obj->id
1451
-            //	),
1452
-            //	'admin.php?page=espresso_registrations'
1453
-            //),
1454
-        );
1455
-        ob_start();
1456
-        do_action(
1457
-            'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1458
-            $this->_cpt_model_obj
1459
-        );
1460
-        $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1461
-        // load template
1462
-        EEH_Template::display_template(
1463
-            EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1464
-            $publish_box_extra_args
1465
-        );
1466
-    }
1467
-
1468
-
1469
-
1470
-    /**
1471
-     * This just returns whatever is set as the _event object property
1472
-     * //todo this will become obsolete once the models are in place
1473
-     *
1474
-     * @return object
1475
-     */
1476
-    public function get_event_object()
1477
-    {
1478
-        return $this->_cpt_model_obj;
1479
-    }
1480
-
1481
-
1482
-
1483
-
1484
-    /** METABOXES * */
1485
-    /**
1486
-     * _register_event_editor_meta_boxes
1487
-     * add all metaboxes related to the event_editor
1488
-     *
1489
-     * @return void
1490
-     */
1491
-    protected function _register_event_editor_meta_boxes()
1492
-    {
1493
-        $this->verify_cpt_object();
1494
-        add_meta_box(
1495
-            'espresso_event_editor_tickets',
1496
-            esc_html__('Event Datetime & Ticket', 'event_espresso'),
1497
-            array($this, 'ticket_metabox'),
1498
-            $this->page_slug,
1499
-            'normal',
1500
-            'high'
1501
-        );
1502
-        add_meta_box(
1503
-            'espresso_event_editor_event_options',
1504
-            esc_html__('Event Registration Options', 'event_espresso'),
1505
-            array($this, 'registration_options_meta_box'),
1506
-            $this->page_slug,
1507
-            'side',
1508
-            'default'
1509
-        );
1510
-        // NOTE: if you're looking for other metaboxes in here,
1511
-        // where a metabox has a related management page in the admin
1512
-        // you will find it setup in the related management page's "_Hooks" file.
1513
-        // i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1514
-    }
1515
-
1516
-
1517
-
1518
-    public function ticket_metabox()
1519
-    {
1520
-        $existing_datetime_ids = $existing_ticket_ids = array();
1521
-        //defaults for template args
1522
-        $template_args = array(
1523
-            'existing_datetime_ids'    => '',
1524
-            'event_datetime_help_link' => '',
1525
-            'ticket_options_help_link' => '',
1526
-            'time'                     => null,
1527
-            'ticket_rows'              => '',
1528
-            'existing_ticket_ids'      => '',
1529
-            'total_ticket_rows'        => 1,
1530
-            'ticket_js_structure'      => '',
1531
-            'trash_icon'               => 'ee-lock-icon',
1532
-            'disabled'                 => '',
1533
-        );
1534
-        $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1535
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1536
-        /**
1537
-         * 1. Start with retrieving Datetimes
1538
-         * 2. Fore each datetime get related tickets
1539
-         * 3. For each ticket get related prices
1540
-         */
1541
-        $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1542
-        /** @type EE_Datetime $first_datetime */
1543
-        $first_datetime = reset($times);
1544
-        //do we get related tickets?
1545
-        if ($first_datetime instanceof EE_Datetime
1546
-            && $first_datetime->ID() !== 0
1547
-        ) {
1548
-            $existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1549
-            $template_args['time'] = $first_datetime;
1550
-            $related_tickets = $first_datetime->tickets(
1551
-                array(
1552
-                    array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1553
-                    'default_where_conditions' => 'none',
1554
-                )
1555
-            );
1556
-            if ( ! empty($related_tickets)) {
1557
-                $template_args['total_ticket_rows'] = count($related_tickets);
1558
-                $row = 0;
1559
-                foreach ($related_tickets as $ticket) {
1560
-                    $existing_ticket_ids[] = $ticket->get('TKT_ID');
1561
-                    $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1562
-                    $row++;
1563
-                }
1564
-            } else {
1565
-                $template_args['total_ticket_rows'] = 1;
1566
-                /** @type EE_Ticket $ticket */
1567
-                $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1568
-                $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1569
-            }
1570
-        } else {
1571
-            $template_args['time'] = $times[0];
1572
-            /** @type EE_Ticket $ticket */
1573
-            $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1574
-            $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1575
-            // NOTE: we're just sending the first default row
1576
-            // (decaf can't manage default tickets so this should be sufficient);
1577
-        }
1578
-        $template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1579
-            'event_editor_event_datetimes_help_tab'
1580
-        );
1581
-        $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1582
-        $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1583
-        $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1584
-        $template_args['ticket_js_structure'] = $this->_get_ticket_row(
1585
-            EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1586
-            true
1587
-        );
1588
-        $template = apply_filters(
1589
-            'FHEE__Events_Admin_Page__ticket_metabox__template',
1590
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1591
-        );
1592
-        EEH_Template::display_template($template, $template_args);
1593
-    }
1594
-
1595
-
1596
-
1597
-    /**
1598
-     * Setup an individual ticket form for the decaf event editor page
1599
-     *
1600
-     * @access private
1601
-     * @param  EE_Ticket $ticket   the ticket object
1602
-     * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1603
-     * @param int        $row
1604
-     * @return string generated html for the ticket row.
1605
-     */
1606
-    private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1607
-    {
1608
-        $template_args = array(
1609
-            'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1610
-            'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1611
-                : '',
1612
-            'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1613
-            'TKT_ID'              => $ticket->get('TKT_ID'),
1614
-            'TKT_name'            => $ticket->get('TKT_name'),
1615
-            'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1616
-            'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1617
-            'TKT_is_default'      => $ticket->get('TKT_is_default'),
1618
-            'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1619
-            'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1620
-            'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1621
-            'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1622
-                                     && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1623
-                ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1624
-            'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1625
-                : ' disabled=disabled',
1626
-        );
1627
-        $price = $ticket->ID() !== 0
1628
-            ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1629
-            : EE_Registry::instance()->load_model('Price')->create_default_object();
1630
-        $price_args = array(
1631
-            'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1632
-            'PRC_amount'            => $price->get('PRC_amount'),
1633
-            'PRT_ID'                => $price->get('PRT_ID'),
1634
-            'PRC_ID'                => $price->get('PRC_ID'),
1635
-            'PRC_is_default'        => $price->get('PRC_is_default'),
1636
-        );
1637
-        //make sure we have default start and end dates if skeleton
1638
-        //handle rows that should NOT be empty
1639
-        if (empty($template_args['TKT_start_date'])) {
1640
-            //if empty then the start date will be now.
1641
-            $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1642
-        }
1643
-        if (empty($template_args['TKT_end_date'])) {
1644
-            //get the earliest datetime (if present);
1645
-            $earliest_dtt = $this->_cpt_model_obj->ID() > 0
1646
-                ? $this->_cpt_model_obj->get_first_related(
1647
-                    'Datetime',
1648
-                    array('order_by' => array('DTT_EVT_start' => 'ASC'))
1649
-                )
1650
-                : null;
1651
-            if ( ! empty($earliest_dtt)) {
1652
-                $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1653
-            } else {
1654
-                $template_args['TKT_end_date'] = date(
1655
-                    'Y-m-d h:i a',
1656
-                    mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1657
-                );
1658
-            }
1659
-        }
1660
-        $template_args = array_merge($template_args, $price_args);
1661
-        $template = apply_filters(
1662
-            'FHEE__Events_Admin_Page__get_ticket_row__template',
1663
-            EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1664
-            $ticket
1665
-        );
1666
-        return EEH_Template::display_template($template, $template_args, true);
1667
-    }
1668
-
1669
-
1670
-
1671
-    public function registration_options_meta_box()
1672
-    {
1673
-        $yes_no_values = array(
1674
-            array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1675
-            array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1676
-        );
1677
-        $default_reg_status_values = EEM_Registration::reg_status_array(
1678
-            array(
1679
-                EEM_Registration::status_id_cancelled,
1680
-                EEM_Registration::status_id_declined,
1681
-                EEM_Registration::status_id_incomplete,
1682
-            ),
1683
-            true
1684
-        );
1685
-        //$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1686
-        $template_args['_event'] = $this->_cpt_model_obj;
1687
-        $template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1688
-        $template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1689
-        $template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1690
-            'default_reg_status',
1691
-            $default_reg_status_values,
1692
-            $this->_cpt_model_obj->default_registration_status()
1693
-        );
1694
-        $template_args['display_description'] = EEH_Form_Fields::select_input(
1695
-            'display_desc',
1696
-            $yes_no_values,
1697
-            $this->_cpt_model_obj->display_description()
1698
-        );
1699
-        $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1700
-            'display_ticket_selector',
1701
-            $yes_no_values,
1702
-            $this->_cpt_model_obj->display_ticket_selector(),
1703
-            '',
1704
-            '',
1705
-            false
1706
-        );
1707
-        $template_args['additional_registration_options'] = apply_filters(
1708
-            'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1709
-            '',
1710
-            $template_args,
1711
-            $yes_no_values,
1712
-            $default_reg_status_values
1713
-        );
1714
-        EEH_Template::display_template(
1715
-            EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1716
-            $template_args
1717
-        );
1718
-    }
1719
-
1720
-
1721
-
1722
-    /**
1723
-     * _get_events()
1724
-     * This method simply returns all the events (for the given _view and paging)
1725
-     *
1726
-     * @access public
1727
-     * @param int  $per_page     count of items per page (20 default);
1728
-     * @param int  $current_page what is the current page being viewed.
1729
-     * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1730
-     *                           If FALSE then we return an array of event objects
1731
-     *                           that match the given _view and paging parameters.
1732
-     * @return array an array of event objects.
1733
-     */
1734
-    public function get_events($per_page = 10, $current_page = 1, $count = false)
1735
-    {
1736
-        $EEME = $this->_event_model();
1737
-        $offset = ($current_page - 1) * $per_page;
1738
-        $limit = $count ? null : $offset . ',' . $per_page;
1739
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1740
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1741
-        if (isset($this->_req_data['month_range'])) {
1742
-            $pieces = explode(' ', $this->_req_data['month_range'], 3);
1743
-            $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
1744
-            $year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1745
-        }
1746
-        $where = array();
1747
-        $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1748
-        //determine what post_status our condition will have for the query.
1749
-        switch ($status) {
1750
-            case 'month' :
1751
-            case 'today' :
1752
-            case null :
1753
-            case 'all' :
1754
-                break;
1755
-            case 'draft' :
1756
-                $where['status'] = array('IN', array('draft', 'auto-draft'));
1757
-                break;
1758
-            default :
1759
-                $where['status'] = $status;
1760
-        }
1761
-        //categories?
1762
-        $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1763
-            ? $this->_req_data['EVT_CAT'] : null;
1764
-        if ( ! empty ($category)) {
1765
-            $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1766
-            $where['Term_Taxonomy.term_id'] = $category;
1767
-        }
1768
-        //date where conditions
1769
-        $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1770
-        if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1771
-            $DateTime = new DateTime(
1772
-                $year_r . '-' . $month_r . '-01 00:00:00',
1773
-                new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1774
-            );
1775
-            $start = $DateTime->format(implode(' ', $start_formats));
1776
-            $end = $DateTime->setDate($year_r, $month_r, $DateTime
1777
-                ->format('t'))->setTime(23, 59, 59)
1778
-                            ->format(implode(' ', $start_formats));
1779
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1780
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1781
-            $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1782
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1783
-            $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1784
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1785
-        } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1786
-            $now = date('Y-m-01');
1787
-            $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1788
-            $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1789
-            $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1790
-                            ->setTime(23, 59, 59)
1791
-                            ->format(implode(' ', $start_formats));
1792
-            $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1793
-        }
1794
-        if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1795
-            $where['EVT_wp_user'] = get_current_user_id();
1796
-        } else {
1797
-            if ( ! isset($where['status'])) {
1798
-                if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1799
-                    $where['OR'] = array(
1800
-                        'status*restrict_private' => array('!=', 'private'),
1801
-                        'AND'                     => array(
1802
-                            'status*inclusive' => array('=', 'private'),
1803
-                            'EVT_wp_user'      => get_current_user_id(),
1804
-                        ),
1805
-                    );
1806
-                }
1807
-            }
1808
-        }
1809
-        if (isset($this->_req_data['EVT_wp_user'])) {
1810
-            if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1811
-                && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1812
-            ) {
1813
-                $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1814
-            }
1815
-        }
1816
-        //search query handling
1817
-        if (isset($this->_req_data['s'])) {
1818
-            $search_string = '%' . $this->_req_data['s'] . '%';
1819
-            $where['OR'] = array(
1820
-                'EVT_name'       => array('LIKE', $search_string),
1821
-                'EVT_desc'       => array('LIKE', $search_string),
1822
-                'EVT_short_desc' => array('LIKE', $search_string),
1823
-            );
1824
-        }
1825
-        $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1826
-        $query_params = apply_filters(
1827
-            'FHEE__Events_Admin_Page__get_events__query_params',
1828
-            array(
1829
-                $where,
1830
-                'limit'    => $limit,
1831
-                'order_by' => $orderby,
1832
-                'order'    => $order,
1833
-                'group_by' => 'EVT_ID',
1834
-            ),
1835
-            $this->_req_data
1836
-        );
1837
-        //let's first check if we have special requests coming in.
1838
-        if (isset($this->_req_data['active_status'])) {
1839
-            switch ($this->_req_data['active_status']) {
1840
-                case 'upcoming' :
1841
-                    return $EEME->get_upcoming_events($query_params, $count);
1842
-                    break;
1843
-                case 'expired' :
1844
-                    return $EEME->get_expired_events($query_params, $count);
1845
-                    break;
1846
-                case 'active' :
1847
-                    return $EEME->get_active_events($query_params, $count);
1848
-                    break;
1849
-                case 'inactive' :
1850
-                    return $EEME->get_inactive_events($query_params, $count);
1851
-                    break;
1852
-            }
1853
-        }
1854
-        $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1855
-        return $events;
1856
-    }
1857
-
1858
-
1859
-
1860
-    /**
1861
-     * handling for WordPress CPT actions (trash, restore, delete)
1862
-     *
1863
-     * @param string $post_id
1864
-     */
1865
-    public function trash_cpt_item($post_id)
1866
-    {
1867
-        $this->_req_data['EVT_ID'] = $post_id;
1868
-        $this->_trash_or_restore_event('trash', false);
1869
-    }
1870
-
1871
-
1872
-
1873
-    /**
1874
-     * @param string $post_id
1875
-     */
1876
-    public function restore_cpt_item($post_id)
1877
-    {
1878
-        $this->_req_data['EVT_ID'] = $post_id;
1879
-        $this->_trash_or_restore_event('draft', false);
1880
-    }
1881
-
1882
-
1883
-
1884
-    /**
1885
-     * @param string $post_id
1886
-     */
1887
-    public function delete_cpt_item($post_id)
1888
-    {
1889
-        $this->_req_data['EVT_ID'] = $post_id;
1890
-        $this->_delete_event(false);
1891
-    }
1892
-
1893
-
1894
-
1895
-    /**
1896
-     * _trash_or_restore_event
1897
-     *
1898
-     * @access protected
1899
-     * @param  string $event_status
1900
-     * @param bool    $redirect_after
1901
-     */
1902
-    protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1903
-    {
1904
-        //determine the event id and set to array.
1905
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1906
-        // loop thru events
1907
-        if ($EVT_ID) {
1908
-            // clean status
1909
-            $event_status = sanitize_key($event_status);
1910
-            // grab status
1911
-            if ( ! empty($event_status)) {
1912
-                $success = $this->_change_event_status($EVT_ID, $event_status);
1913
-            } else {
1914
-                $success = false;
1915
-                $msg = esc_html__(
1916
-                    'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1917
-                    'event_espresso'
1918
-                );
1919
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1920
-            }
1921
-        } else {
1922
-            $success = false;
1923
-            $msg = esc_html__(
1924
-                'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1925
-                'event_espresso'
1926
-            );
1927
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1928
-        }
1929
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1930
-        if ($redirect_after) {
1931
-            $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1932
-        }
1933
-    }
1934
-
1935
-
1936
-
1937
-    /**
1938
-     * _trash_or_restore_events
1939
-     *
1940
-     * @access protected
1941
-     * @param  string $event_status
1942
-     * @return void
1943
-     */
1944
-    protected function _trash_or_restore_events($event_status = 'trash')
1945
-    {
1946
-        // clean status
1947
-        $event_status = sanitize_key($event_status);
1948
-        // grab status
1949
-        if ( ! empty($event_status)) {
1950
-            $success = true;
1951
-            //determine the event id and set to array.
1952
-            $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1953
-            // loop thru events
1954
-            foreach ($EVT_IDs as $EVT_ID) {
1955
-                if ($EVT_ID = absint($EVT_ID)) {
1956
-                    $results = $this->_change_event_status($EVT_ID, $event_status);
1957
-                    $success = $results !== false ? $success : false;
1958
-                } else {
1959
-                    $msg = sprintf(
1960
-                        esc_html__(
1961
-                            'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1962
-                            'event_espresso'
1963
-                        ),
1964
-                        $EVT_ID
1965
-                    );
1966
-                    EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1967
-                    $success = false;
1968
-                }
1969
-            }
1970
-        } else {
1971
-            $success = false;
1972
-            $msg = esc_html__(
1973
-                'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1974
-                'event_espresso'
1975
-            );
1976
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1977
-        }
1978
-        // in order to force a pluralized result message we need to send back a success status greater than 1
1979
-        $success = $success ? 2 : false;
1980
-        $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1981
-        $this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1982
-    }
1983
-
1984
-
1985
-
1986
-    /**
1987
-     * _trash_or_restore_events
1988
-     *
1989
-     * @access  private
1990
-     * @param  int    $EVT_ID
1991
-     * @param  string $event_status
1992
-     * @return bool
1993
-     */
1994
-    private function _change_event_status($EVT_ID = 0, $event_status = '')
1995
-    {
1996
-        // grab event id
1997
-        if ( ! $EVT_ID) {
1998
-            $msg = esc_html__(
1999
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2000
-                'event_espresso'
2001
-            );
2002
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2003
-            return false;
2004
-        }
2005
-        $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2006
-        // clean status
2007
-        $event_status = sanitize_key($event_status);
2008
-        // grab status
2009
-        if (empty($event_status)) {
2010
-            $msg = esc_html__(
2011
-                'An error occurred. No Event Status or an invalid Event Status was received.',
2012
-                'event_espresso'
2013
-            );
2014
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2015
-            return false;
2016
-        }
2017
-        // was event trashed or restored ?
2018
-        switch ($event_status) {
2019
-            case 'draft' :
2020
-                $action = 'restored from the trash';
2021
-                $hook = 'AHEE_event_restored_from_trash';
2022
-                break;
2023
-            case 'trash' :
2024
-                $action = 'moved to the trash';
2025
-                $hook = 'AHEE_event_moved_to_trash';
2026
-                break;
2027
-            default :
2028
-                $action = 'updated';
2029
-                $hook = false;
2030
-        }
2031
-        //use class to change status
2032
-        $this->_cpt_model_obj->set_status($event_status);
2033
-        $success = $this->_cpt_model_obj->save();
2034
-        if ($success === false) {
2035
-            $msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2036
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2037
-            return false;
2038
-        }
2039
-        if ($hook) {
2040
-            do_action($hook);
2041
-        }
2042
-        return true;
2043
-    }
2044
-
2045
-
2046
-
2047
-    /**
2048
-     * _delete_event
2049
-     *
2050
-     * @access protected
2051
-     * @param bool $redirect_after
2052
-     */
2053
-    protected function _delete_event($redirect_after = true)
2054
-    {
2055
-        //determine the event id and set to array.
2056
-        $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2057
-        $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2058
-        // loop thru events
2059
-        if ($EVT_ID) {
2060
-            $success = $this->_permanently_delete_event($EVT_ID);
2061
-            // get list of events with no prices
2062
-            $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2063
-            // remove this event from the list of events with no prices
2064
-            if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2065
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2066
-            }
2067
-            update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2068
-        } else {
2069
-            $success = false;
2070
-            $msg = esc_html__(
2071
-                'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2072
-                'event_espresso'
2073
-            );
2074
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2075
-        }
2076
-        if ($redirect_after) {
2077
-            $this->_redirect_after_action(
2078
-                $success,
2079
-                'Event',
2080
-                'deleted',
2081
-                array('action' => 'default', 'status' => 'trash')
2082
-            );
2083
-        }
2084
-    }
2085
-
2086
-
2087
-
2088
-    /**
2089
-     * _delete_events
2090
-     *
2091
-     * @access protected
2092
-     * @return void
2093
-     */
2094
-    protected function _delete_events()
2095
-    {
2096
-        $success = true;
2097
-        // get list of events with no prices
2098
-        $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2099
-        //determine the event id and set to array.
2100
-        $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2101
-        // loop thru events
2102
-        foreach ($EVT_IDs as $EVT_ID) {
2103
-            $EVT_ID = absint($EVT_ID);
2104
-            if ($EVT_ID) {
2105
-                $results = $this->_permanently_delete_event($EVT_ID);
2106
-                $success = $results !== false ? $success : false;
2107
-                // remove this event from the list of events with no prices
2108
-                unset($espresso_no_ticket_prices[$EVT_ID]);
2109
-            } else {
2110
-                $success = false;
2111
-                $msg = esc_html__(
2112
-                    'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2113
-                    'event_espresso'
2114
-                );
2115
-                EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2116
-            }
2117
-        }
2118
-        update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2119
-        // in order to force a pluralized result message we need to send back a success status greater than 1
2120
-        $success = $success ? 2 : false;
2121
-        $this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2122
-    }
2123
-
2124
-
2125
-
2126
-    /**
2127
-     * _permanently_delete_event
2128
-     *
2129
-     * @access  private
2130
-     * @param  int $EVT_ID
2131
-     * @return bool
2132
-     */
2133
-    private function _permanently_delete_event($EVT_ID = 0)
2134
-    {
2135
-        // grab event id
2136
-        if ( ! $EVT_ID) {
2137
-            $msg = esc_html__(
2138
-                'An error occurred. No Event ID or an invalid Event ID was received.',
2139
-                'event_espresso'
2140
-            );
2141
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2142
-            return false;
2143
-        }
2144
-        if (
2145
-            ! $this->_cpt_model_obj instanceof EE_Event
2146
-            || $this->_cpt_model_obj->ID() !== $EVT_ID
2147
-        ) {
2148
-            $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2149
-        }
2150
-        if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2151
-            return false;
2152
-        }
2153
-        //need to delete related tickets and prices first.
2154
-        $datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2155
-        foreach ($datetimes as $datetime) {
2156
-            $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2157
-            $tickets = $datetime->get_many_related('Ticket');
2158
-            foreach ($tickets as $ticket) {
2159
-                $ticket->_remove_relation_to($datetime, 'Datetime');
2160
-                $ticket->delete_related_permanently('Price');
2161
-                $ticket->delete_permanently();
2162
-            }
2163
-            $datetime->delete();
2164
-        }
2165
-        //what about related venues or terms?
2166
-        $venues = $this->_cpt_model_obj->get_many_related('Venue');
2167
-        foreach ($venues as $venue) {
2168
-            $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2169
-        }
2170
-        //any attached question groups?
2171
-        $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2172
-        if ( ! empty($question_groups)) {
2173
-            foreach ($question_groups as $question_group) {
2174
-                $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2175
-            }
2176
-        }
2177
-        //Message Template Groups
2178
-        $this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2179
-        /** @type EE_Term_Taxonomy[] $term_taxonomies */
2180
-        $term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2181
-        foreach ($term_taxonomies as $term_taxonomy) {
2182
-            $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2183
-        }
2184
-        $success = $this->_cpt_model_obj->delete_permanently();
2185
-        // did it all go as planned ?
2186
-        if ($success) {
2187
-            $msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2188
-            EE_Error::add_success($msg);
2189
-        } else {
2190
-            $msg = sprintf(
2191
-                esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2192
-                $EVT_ID
2193
-            );
2194
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2195
-            return false;
2196
-        }
2197
-        do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2198
-        return true;
2199
-    }
2200
-
2201
-
2202
-
2203
-    /**
2204
-     * get total number of events
2205
-     *
2206
-     * @access public
2207
-     * @return int
2208
-     */
2209
-    public function total_events()
2210
-    {
2211
-        $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2212
-        return $count;
2213
-    }
2214
-
2215
-
2216
-
2217
-    /**
2218
-     * get total number of draft events
2219
-     *
2220
-     * @access public
2221
-     * @return int
2222
-     */
2223
-    public function total_events_draft()
2224
-    {
2225
-        $where = array(
2226
-            'status' => array('IN', array('draft', 'auto-draft')),
2227
-        );
2228
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2229
-        return $count;
2230
-    }
2231
-
2232
-
2233
-
2234
-    /**
2235
-     * get total number of trashed events
2236
-     *
2237
-     * @access public
2238
-     * @return int
2239
-     */
2240
-    public function total_trashed_events()
2241
-    {
2242
-        $where = array(
2243
-            'status' => 'trash',
2244
-        );
2245
-        $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2246
-        return $count;
2247
-    }
2248
-
2249
-
2250
-
2251
-    /**
2252
-     *    _default_event_settings
2253
-     *    This generates the Default Settings Tab
2254
-     *
2255
-     * @return void
2256
-     */
2257
-    protected function _default_event_settings()
2258
-    {
2259
-        $this->_template_args['values'] = $this->_yes_no_values;
2260
-        $this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2261
-        // exclude array
2262
-            array(
2263
-                EEM_Registration::status_id_cancelled,
2264
-                EEM_Registration::status_id_declined,
2265
-                EEM_Registration::status_id_incomplete,
2266
-                EEM_Registration::status_id_wait_list,
2267
-            ),
2268
-            // translated
2269
-            true
2270
-        );
2271
-        $this->_template_args['default_reg_status'] = isset(
2272
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID
2273
-                                                      )
2274
-                                                      && array_key_exists(
2275
-                                                          EE_Registry::instance()->CFG->registration->default_STS_ID,
2276
-                                                          $this->_template_args['reg_status_array']
2277
-                                                      )
2278
-            ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2279
-            : EEM_Registration::status_id_pending_payment;
2280
-        $this->_set_add_edit_form_tags('update_default_event_settings');
2281
-        $this->_set_publish_post_box_vars(null, false, false, null, false);
2282
-        $this->_template_args['admin_page_content'] = EEH_Template::display_template(
2283
-            EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2284
-            $this->_template_args,
2285
-            true
2286
-        );
2287
-        $this->display_admin_page_with_sidebar();
2288
-    }
2289
-
2290
-
2291
-
2292
-    /**
2293
-     * _update_default_event_settings
2294
-     *
2295
-     * @access protected
2296
-     * @return void
2297
-     */
2298
-    protected function _update_default_event_settings()
2299
-    {
2300
-        EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2301
-            ? sanitize_text_field($this->_req_data['default_reg_status'])
2302
-            : EEM_Registration::status_id_pending_payment;
2303
-        $what = 'Default Event Settings';
2304
-        $success = $this->_update_espresso_configuration(
2305
-            $what,
2306
-            EE_Config::instance(),
2307
-            __FILE__,
2308
-            __FUNCTION__,
2309
-            __LINE__
2310
-        );
2311
-        $this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2312
-    }
2313
-
2314
-
2315
-
2316
-    /*************        Templates        *************/
2317
-    protected function _template_settings()
2318
-    {
2319
-        $this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2320
-        $this->_template_args['preview_img'] = '<img src="'
2321
-                                               . EVENTS_ASSETS_URL
2322
-                                               . DS
2323
-                                               . 'images'
2324
-                                               . DS
2325
-                                               . 'caffeinated_template_features.jpg" alt="'
2326
-                                               . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2327
-                                               . '" />';
2328
-        $this->_template_args['preview_text'] = '<strong>' . esc_html__(
2329
-                'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2330
-                'event_espresso'
2331
-            ) . '</strong>';
2332
-        $this->display_admin_caf_preview_page('template_settings_tab');
2333
-    }
2334
-
2335
-
2336
-    /** Event Category Stuff **/
2337
-    /**
2338
-     * set the _category property with the category object for the loaded page.
2339
-     *
2340
-     * @access private
2341
-     * @return void
2342
-     */
2343
-    private function _set_category_object()
2344
-    {
2345
-        if (isset($this->_category->id) && ! empty($this->_category->id)) {
2346
-            return;
2347
-        } //already have the category object so get out.
2348
-        //set default category object
2349
-        $this->_set_empty_category_object();
2350
-        //only set if we've got an id
2351
-        if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2352
-            return;
2353
-        }
2354
-        $category_id = absint($this->_req_data['EVT_CAT_ID']);
2355
-        $term = get_term($category_id, 'espresso_event_categories');
2356
-        if ( ! empty($term)) {
2357
-            $this->_category->category_name = $term->name;
2358
-            $this->_category->category_identifier = $term->slug;
2359
-            $this->_category->category_desc = $term->description;
2360
-            $this->_category->id = $term->term_id;
2361
-            $this->_category->parent = $term->parent;
2362
-        }
2363
-    }
2364
-
2365
-
2366
-
2367
-    private function _set_empty_category_object()
2368
-    {
2369
-        $this->_category = new stdClass();
2370
-        $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2371
-        $this->_category->id = $this->_category->parent = 0;
2372
-    }
2373
-
2374
-
2375
-
2376
-    protected function _category_list_table()
2377
-    {
2378
-        do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2379
-        $this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2380
-        $this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2381
-                'add_category',
2382
-                'add_category',
2383
-                array(),
2384
-                'add-new-h2'
2385
-            );
2386
-        $this->display_admin_list_table_page_with_sidebar();
2387
-    }
2388
-
2389
-
2390
-
2391
-    /**
2392
-     * @param $view
2393
-     */
2394
-    protected function _category_details($view)
2395
-    {
2396
-        //load formatter helper
2397
-        //load field generator helper
2398
-        $route = $view == 'edit' ? 'update_category' : 'insert_category';
2399
-        $this->_set_add_edit_form_tags($route);
2400
-        $this->_set_category_object();
2401
-        $id = ! empty($this->_category->id) ? $this->_category->id : '';
2402
-        $delete_action = 'delete_category';
2403
-        //custom redirect
2404
-        $redirect = EE_Admin_Page::add_query_args_and_nonce(
2405
-            array('action' => 'category_list'),
2406
-            $this->_admin_base_url
2407
-        );
2408
-        $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2409
-        //take care of contents
2410
-        $this->_template_args['admin_page_content'] = $this->_category_details_content();
2411
-        $this->display_admin_page_with_sidebar();
2412
-    }
2413
-
2414
-
2415
-
2416
-    /**
2417
-     * @return mixed
2418
-     */
2419
-    protected function _category_details_content()
2420
-    {
2421
-        $editor_args['category_desc'] = array(
2422
-            'type'          => 'wp_editor',
2423
-            'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2424
-            'class'         => 'my_editor_custom',
2425
-            'wpeditor_args' => array('media_buttons' => false),
2426
-        );
2427
-        $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2428
-        $all_terms = get_terms(
2429
-            array('espresso_event_categories'),
2430
-            array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2431
-        );
2432
-        //setup category select for term parents.
2433
-        $category_select_values[] = array(
2434
-            'text' => esc_html__('No Parent', 'event_espresso'),
2435
-            'id'   => 0,
2436
-        );
2437
-        foreach ($all_terms as $term) {
2438
-            $category_select_values[] = array(
2439
-                'text' => $term->name,
2440
-                'id'   => $term->term_id,
2441
-            );
2442
-        }
2443
-        $category_select = EEH_Form_Fields::select_input(
2444
-            'category_parent',
2445
-            $category_select_values,
2446
-            $this->_category->parent
2447
-        );
2448
-        $template_args = array(
2449
-            'category'                 => $this->_category,
2450
-            'category_select'          => $category_select,
2451
-            'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2452
-            'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2453
-            'disable'                  => '',
2454
-            'disabled_message'         => false,
2455
-        );
2456
-        $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2457
-        return EEH_Template::display_template($template, $template_args, true);
2458
-    }
2459
-
2460
-
2461
-
2462
-    protected function _delete_categories()
2463
-    {
2464
-        $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2465
-            : (array)$this->_req_data['category_id'];
2466
-        foreach ($cat_ids as $cat_id) {
2467
-            $this->_delete_category($cat_id);
2468
-        }
2469
-        //doesn't matter what page we're coming from... we're going to the same place after delete.
2470
-        $query_args = array(
2471
-            'action' => 'category_list',
2472
-        );
2473
-        $this->_redirect_after_action(0, '', '', $query_args);
2474
-    }
2475
-
2476
-
2477
-
2478
-    /**
2479
-     * @param $cat_id
2480
-     */
2481
-    protected function _delete_category($cat_id)
2482
-    {
2483
-        $cat_id = absint($cat_id);
2484
-        wp_delete_term($cat_id, 'espresso_event_categories');
2485
-    }
2486
-
2487
-
2488
-
2489
-    /**
2490
-     * @param $new_category
2491
-     */
2492
-    protected function _insert_or_update_category($new_category)
2493
-    {
2494
-        $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2495
-        $success = 0; //we already have a success message so lets not send another.
2496
-        if ($cat_id) {
2497
-            $query_args = array(
2498
-                'action'     => 'edit_category',
2499
-                'EVT_CAT_ID' => $cat_id,
2500
-            );
2501
-        } else {
2502
-            $query_args = array('action' => 'add_category');
2503
-        }
2504
-        $this->_redirect_after_action($success, '', '', $query_args, true);
2505
-    }
2506
-
2507
-
2508
-
2509
-    /**
2510
-     * @param bool $update
2511
-     * @return bool|mixed|string
2512
-     */
2513
-    private function _insert_category($update = false)
2514
-    {
2515
-        $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2516
-        $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2517
-        $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2518
-        $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2519
-        if (empty($category_name)) {
2520
-            $msg = esc_html__('You must add a name for the category.', 'event_espresso');
2521
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2522
-            return false;
2523
-        }
2524
-        $term_args = array(
2525
-            'name'        => $category_name,
2526
-            'description' => $category_desc,
2527
-            'parent'      => $category_parent,
2528
-        );
2529
-        //was the category_identifier input disabled?
2530
-        if (isset($this->_req_data['category_identifier'])) {
2531
-            $term_args['slug'] = $this->_req_data['category_identifier'];
2532
-        }
2533
-        $insert_ids = $update
2534
-            ? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2535
-            : wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2536
-        if ( ! is_array($insert_ids)) {
2537
-            $msg = esc_html__(
2538
-                'An error occurred and the category has not been saved to the database.',
2539
-                'event_espresso'
2540
-            );
2541
-            EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2542
-        } else {
2543
-            $cat_id = $insert_ids['term_id'];
2544
-            $msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2545
-            EE_Error::add_success($msg);
2546
-        }
2547
-        return $cat_id;
2548
-    }
2549
-
2550
-
2551
-
2552
-    /**
2553
-     * @param int  $per_page
2554
-     * @param int  $current_page
2555
-     * @param bool $count
2556
-     * @return \EE_Base_Class[]|int
2557
-     */
2558
-    public function get_categories($per_page = 10, $current_page = 1, $count = false)
2559
-    {
2560
-        //testing term stuff
2561
-        $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2562
-        $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2563
-        $limit = ($current_page - 1) * $per_page;
2564
-        $where = array('taxonomy' => 'espresso_event_categories');
2565
-        if (isset($this->_req_data['s'])) {
2566
-            $sstr = '%' . $this->_req_data['s'] . '%';
2567
-            $where['OR'] = array(
2568
-                'Term.name'   => array('LIKE', $sstr),
2569
-                'description' => array('LIKE', $sstr),
2570
-            );
2571
-        }
2572
-        $query_params = array(
2573
-            $where,
2574
-            'order_by'   => array($orderby => $order),
2575
-            'limit'      => $limit . ',' . $per_page,
2576
-            'force_join' => array('Term'),
2577
-        );
2578
-        $categories = $count
2579
-            ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2580
-            : EEM_Term_Taxonomy::instance()->get_all($query_params);
2581
-        return $categories;
2582
-    }
2583
-
2584
-
2585
-
2586
-    /* end category stuff */
2587
-    /**************/
385
+				'qtips'         => array('EE_Event_Editor_Decaf_Tips'),
386
+				'require_nonce' => false,
387
+			),
388
+			'default_event_settings' => array(
389
+				'nav'           => array(
390
+					'label' => esc_html__('Default Settings', 'event_espresso'),
391
+					'order' => 40,
392
+				),
393
+				'metaboxes'     => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')),
394
+				'labels'        => array(
395
+					'publishbox' => esc_html__('Update Settings', 'event_espresso'),
396
+				),
397
+				'help_tabs'     => array(
398
+					'default_settings_help_tab'        => array(
399
+						'title'    => esc_html__('Default Event Settings', 'event_espresso'),
400
+						'filename' => 'events_default_settings',
401
+					),
402
+					'default_settings_status_help_tab' => array(
403
+						'title'    => esc_html__('Default Registration Status', 'event_espresso'),
404
+						'filename' => 'events_default_settings_status',
405
+					),
406
+				),
407
+				'help_tour'     => array('Event_Default_Settings_Help_Tour'),
408
+				'require_nonce' => false,
409
+			),
410
+			//template settings
411
+			'template_settings'      => array(
412
+				'nav'           => array(
413
+					'label' => esc_html__('Templates', 'event_espresso'),
414
+					'order' => 30,
415
+				),
416
+				'metaboxes'     => $this->_default_espresso_metaboxes,
417
+				'help_tabs'     => array(
418
+					'general_settings_templates_help_tab' => array(
419
+						'title'    => esc_html__('Templates', 'event_espresso'),
420
+						'filename' => 'general_settings_templates',
421
+					),
422
+				),
423
+				'help_tour'     => array('Templates_Help_Tour'),
424
+				'require_nonce' => false,
425
+			),
426
+			//event category stuff
427
+			'add_category'           => array(
428
+				'nav'           => array(
429
+					'label'      => esc_html__('Add Category', 'event_espresso'),
430
+					'order'      => 15,
431
+					'persistent' => false,
432
+				),
433
+				'help_tabs'     => array(
434
+					'add_category_help_tab' => array(
435
+						'title'    => esc_html__('Add New Event Category', 'event_espresso'),
436
+						'filename' => 'events_add_category',
437
+					),
438
+				),
439
+				'help_tour'     => array('Event_Add_Category_Help_Tour'),
440
+				'metaboxes'     => array('_publish_post_box'),
441
+				'require_nonce' => false,
442
+			),
443
+			'edit_category'          => array(
444
+				'nav'           => array(
445
+					'label'      => esc_html__('Edit Category', 'event_espresso'),
446
+					'order'      => 15,
447
+					'persistent' => false,
448
+					'url'        => isset($this->_req_data['EVT_CAT_ID'])
449
+						? add_query_arg(
450
+							array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']),
451
+							$this->_current_page_view_url
452
+						)
453
+						: $this->_admin_base_url,
454
+				),
455
+				'help_tabs'     => array(
456
+					'edit_category_help_tab' => array(
457
+						'title'    => esc_html__('Edit Event Category', 'event_espresso'),
458
+						'filename' => 'events_edit_category',
459
+					),
460
+				),
461
+				/*'help_tour' => array('Event_Edit_Category_Help_Tour'),*/
462
+				'metaboxes'     => array('_publish_post_box'),
463
+				'require_nonce' => false,
464
+			),
465
+			'category_list'          => array(
466
+				'nav'           => array(
467
+					'label' => esc_html__('Categories', 'event_espresso'),
468
+					'order' => 20,
469
+				),
470
+				'list_table'    => 'Event_Categories_Admin_List_Table',
471
+				'help_tabs'     => array(
472
+					'events_categories_help_tab'                       => array(
473
+						'title'    => esc_html__('Event Categories', 'event_espresso'),
474
+						'filename' => 'events_categories',
475
+					),
476
+					'events_categories_table_column_headings_help_tab' => array(
477
+						'title'    => esc_html__('Event Categories Table Column Headings', 'event_espresso'),
478
+						'filename' => 'events_categories_table_column_headings',
479
+					),
480
+					'events_categories_view_help_tab'                  => array(
481
+						'title'    => esc_html__('Event Categories Views', 'event_espresso'),
482
+						'filename' => 'events_categories_views',
483
+					),
484
+					'events_categories_other_help_tab'                 => array(
485
+						'title'    => esc_html__('Event Categories Other', 'event_espresso'),
486
+						'filename' => 'events_categories_other',
487
+					),
488
+				),
489
+				'help_tour'     => array(
490
+					'Event_Categories_Help_Tour',
491
+				),
492
+				'metaboxes'     => $this->_default_espresso_metaboxes,
493
+				'require_nonce' => false,
494
+			),
495
+		);
496
+	}
497
+
498
+
499
+
500
+	protected function _add_screen_options()
501
+	{
502
+		//todo
503
+	}
504
+
505
+
506
+
507
+	protected function _add_screen_options_default()
508
+	{
509
+		$this->_per_page_screen_option();
510
+	}
511
+
512
+
513
+
514
+	protected function _add_screen_options_category_list()
515
+	{
516
+		$page_title = $this->_admin_page_title;
517
+		$this->_admin_page_title = esc_html__('Categories', 'event_espresso');
518
+		$this->_per_page_screen_option();
519
+		$this->_admin_page_title = $page_title;
520
+	}
521
+
522
+
523
+
524
+	protected function _add_feature_pointers()
525
+	{
526
+		//todo
527
+	}
528
+
529
+
530
+
531
+	public function load_scripts_styles()
532
+	{
533
+		wp_register_style(
534
+			'events-admin-css',
535
+			EVENTS_ASSETS_URL . 'events-admin-page.css',
536
+			array(),
537
+			EVENT_ESPRESSO_VERSION
538
+		);
539
+		wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION);
540
+		wp_enqueue_style('events-admin-css');
541
+		wp_enqueue_style('ee-cat-admin');
542
+		//todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details
543
+		//registers for all views
544
+		//scripts
545
+		wp_register_script(
546
+			'event_editor_js',
547
+			EVENTS_ASSETS_URL . 'event_editor.js',
548
+			array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'),
549
+			EVENT_ESPRESSO_VERSION,
550
+			true
551
+		);
552
+	}
553
+
554
+
555
+
556
+	/**
557
+	 * enqueuing scripts and styles specific to this view
558
+	 *
559
+	 * @return void
560
+	 */
561
+	public function load_scripts_styles_create_new()
562
+	{
563
+		$this->load_scripts_styles_edit();
564
+	}
565
+
566
+
567
+
568
+	/**
569
+	 * enqueuing scripts and styles specific to this view
570
+	 *
571
+	 * @return void
572
+	 */
573
+	public function load_scripts_styles_edit()
574
+	{
575
+		//styles
576
+		wp_enqueue_style('espresso-ui-theme');
577
+		wp_register_style(
578
+			'event-editor-css',
579
+			EVENTS_ASSETS_URL . 'event-editor.css',
580
+			array('ee-admin-css'),
581
+			EVENT_ESPRESSO_VERSION
582
+		);
583
+		wp_enqueue_style('event-editor-css');
584
+		//scripts
585
+		wp_register_script(
586
+			'event-datetime-metabox',
587
+			EVENTS_ASSETS_URL . 'event-datetime-metabox.js',
588
+			array('event_editor_js', 'ee-datepicker'),
589
+			EVENT_ESPRESSO_VERSION
590
+		);
591
+		wp_enqueue_script('event-datetime-metabox');
592
+	}
593
+
594
+
595
+
596
+	public function load_scripts_styles_add_category()
597
+	{
598
+		$this->load_scripts_styles_edit_category();
599
+	}
600
+
601
+
602
+
603
+	public function load_scripts_styles_edit_category()
604
+	{
605
+	}
606
+
607
+
608
+
609
+	protected function _set_list_table_views_category_list()
610
+	{
611
+		$this->_views = array(
612
+			'all' => array(
613
+				'slug'        => 'all',
614
+				'label'       => esc_html__('All', 'event_espresso'),
615
+				'count'       => 0,
616
+				'bulk_action' => array(
617
+					'delete_categories' => esc_html__('Delete Permanently', 'event_espresso'),
618
+				),
619
+			),
620
+		);
621
+	}
622
+
623
+
624
+
625
+	public function admin_init()
626
+	{
627
+		EE_Registry::$i18n_js_strings['image_confirm'] = esc_html__(
628
+			'Do you really want to delete this image? Please remember to update your event to complete the removal.',
629
+			'event_espresso'
630
+		);
631
+	}
632
+
633
+
634
+
635
+	//nothing needed for events with these methods.
636
+	public function admin_notices()
637
+	{
638
+	}
639
+
640
+
641
+
642
+	public function admin_footer_scripts()
643
+	{
644
+	}
645
+
646
+
647
+
648
+	/**
649
+	 * Call this function to verify if an event is public and has tickets for sale.  If it does, then we need to show a
650
+	 * warning (via EE_Error::add_error());
651
+	 *
652
+	 * @param  EE_Event $event Event object
653
+	 * @access public
654
+	 * @return void
655
+	 */
656
+	public function verify_event_edit($event = null)
657
+	{
658
+		// no event?
659
+		if (empty($event)) {
660
+			// set event
661
+			$event = $this->_cpt_model_obj;
662
+		}
663
+		// STILL no event?
664
+		if (empty ($event)) {
665
+			return;
666
+		}
667
+		$orig_status = $event->status();
668
+		// first check if event is active.
669
+		if (
670
+			$orig_status === EEM_Event::cancelled
671
+			|| $orig_status === EEM_Event::postponed
672
+			|| $event->is_expired()
673
+			|| $event->is_inactive()
674
+		) {
675
+			return;
676
+		}
677
+		//made it here so it IS active... next check that any of the tickets are sold.
678
+		if ($event->is_sold_out(true)) {
679
+			if ($orig_status !== EEM_Event::sold_out && $event->status() !== $orig_status) {
680
+				EE_Error::add_attention(
681
+					sprintf(
682
+						esc_html__(
683
+							'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event.  However, this change is not permanent until you update the event.  You can change the status back to something else before updating if you wish.',
684
+							'event_espresso'
685
+						),
686
+						EEH_Template::pretty_status(EEM_Event::sold_out, false, 'sentence')
687
+					)
688
+				);
689
+			}
690
+			return;
691
+		} else if ($orig_status === EEM_Event::sold_out) {
692
+			EE_Error::add_attention(
693
+				sprintf(
694
+					esc_html__(
695
+						'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets.  However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.',
696
+						'event_espresso'
697
+					),
698
+					EEH_Template::pretty_status($event->status(), false, 'sentence')
699
+				)
700
+			);
701
+		}
702
+		//now we need to determine if the event has any tickets on sale.  If not then we dont' show the error
703
+		if ( ! $event->tickets_on_sale()) {
704
+			return;
705
+		}
706
+		//made it here so show warning
707
+		$this->_edit_event_warning();
708
+	}
709
+
710
+
711
+
712
+	/**
713
+	 * This is the text used for when an event is being edited that is public and has tickets for sale.
714
+	 * When needed, hook this into a EE_Error::add_error() notice.
715
+	 *
716
+	 * @access protected
717
+	 * @return void
718
+	 */
719
+	protected function _edit_event_warning()
720
+	{
721
+		// we don't want to add warnings during these requests
722
+		if (isset($this->_req_data['action']) && $this->_req_data['action'] === 'editpost') {
723
+			return;
724
+		}
725
+		EE_Error::add_attention(
726
+			esc_html__(
727
+				'Please be advised that this event has been published and is open for registrations on your website. If you update any registration-related details (i.e. custom questions, messages, tickets, datetimes, etc.) while a registration is in process, the registration process could be interrupted and result in errors for the person registering and potentially incorrect registration or transaction data inside Event Espresso. We recommend editing events during a period of slow traffic, or even temporarily changing the status of an event to "Draft" until your edits are complete.',
728
+				'event_espresso'
729
+			)
730
+		);
731
+	}
732
+
733
+
734
+
735
+	/**
736
+	 * When a user is creating a new event, notify them if they haven't set their timezone.
737
+	 * Otherwise, do the normal logic
738
+	 *
739
+	 * @return string
740
+	 * @throws \EE_Error
741
+	 */
742
+	protected function _create_new_cpt_item()
743
+	{
744
+		$gmt_offset = get_option('gmt_offset');
745
+		//only nag them about setting their timezone if it's their first event, and they haven't already done it
746
+		if ($gmt_offset === '0' && ! EEM_Event::instance()->exists(array())) {
747
+			EE_Error::add_attention(
748
+				sprintf(
749
+					__(
750
+						'Your website\'s timezone is currently set to UTC + 0. We recommend updating your timezone to a city or region near you before you create an event. Your timezone can be updated through the %1$sGeneral Settings%2$s page.',
751
+						'event_espresso'
752
+					),
753
+					'<a href="' . admin_url('options-general.php') . '">',
754
+					'</a>'
755
+				),
756
+				__FILE__,
757
+				__FUNCTION__,
758
+				__LINE__
759
+			);
760
+		}
761
+		return parent::_create_new_cpt_item();
762
+	}
763
+
764
+
765
+
766
+	protected function _set_list_table_views_default()
767
+	{
768
+		$this->_views = array(
769
+			'all'   => array(
770
+				'slug'        => 'all',
771
+				'label'       => esc_html__('View All Events', 'event_espresso'),
772
+				'count'       => 0,
773
+				'bulk_action' => array(
774
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
775
+				),
776
+			),
777
+			'draft' => array(
778
+				'slug'        => 'draft',
779
+				'label'       => esc_html__('Draft', 'event_espresso'),
780
+				'count'       => 0,
781
+				'bulk_action' => array(
782
+					'trash_events' => esc_html__('Move to Trash', 'event_espresso'),
783
+				),
784
+			),
785
+		);
786
+		if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) {
787
+			$this->_views['trash'] = array(
788
+				'slug'        => 'trash',
789
+				'label'       => esc_html__('Trash', 'event_espresso'),
790
+				'count'       => 0,
791
+				'bulk_action' => array(
792
+					'restore_events' => esc_html__('Restore From Trash', 'event_espresso'),
793
+					'delete_events'  => esc_html__('Delete Permanently', 'event_espresso'),
794
+				),
795
+			);
796
+		}
797
+	}
798
+
799
+
800
+
801
+	/**
802
+	 * @return array
803
+	 */
804
+	protected function _event_legend_items()
805
+	{
806
+		$items = array(
807
+			'view_details'   => array(
808
+				'class' => 'dashicons dashicons-search',
809
+				'desc'  => esc_html__('View Event', 'event_espresso'),
810
+			),
811
+			'edit_event'     => array(
812
+				'class' => 'ee-icon ee-icon-calendar-edit',
813
+				'desc'  => esc_html__('Edit Event Details', 'event_espresso'),
814
+			),
815
+			'view_attendees' => array(
816
+				'class' => 'dashicons dashicons-groups',
817
+				'desc'  => esc_html__('View Registrations for Event', 'event_espresso'),
818
+			),
819
+		);
820
+		$items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items);
821
+		$statuses = array(
822
+			'sold_out_status'  => array(
823
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out,
824
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::sold_out, false, 'sentence'),
825
+			),
826
+			'active_status'    => array(
827
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active,
828
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::active, false, 'sentence'),
829
+			),
830
+			'upcoming_status'  => array(
831
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming,
832
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::upcoming, false, 'sentence'),
833
+			),
834
+			'postponed_status' => array(
835
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed,
836
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::postponed, false, 'sentence'),
837
+			),
838
+			'cancelled_status' => array(
839
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled,
840
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::cancelled, false, 'sentence'),
841
+			),
842
+			'expired_status'   => array(
843
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired,
844
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::expired, false, 'sentence'),
845
+			),
846
+			'inactive_status'  => array(
847
+				'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive,
848
+				'desc'  => EEH_Template::pretty_status(EE_Datetime::inactive, false, 'sentence'),
849
+			),
850
+		);
851
+		$statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses);
852
+		return array_merge($items, $statuses);
853
+	}
854
+
855
+
856
+
857
+	/**
858
+	 * _event_model
859
+	 *
860
+	 * @return EEM_Event
861
+	 */
862
+	private function _event_model()
863
+	{
864
+		if ( ! $this->_event_model instanceof EEM_Event) {
865
+			$this->_event_model = EE_Registry::instance()->load_model('Event');
866
+		}
867
+		return $this->_event_model;
868
+	}
869
+
870
+
871
+
872
+	/**
873
+	 * Adds extra buttons to the WP CPT permalink field row.
874
+	 * Method is called from parent and is hooked into the wp 'get_sample_permalink_html' filter.
875
+	 *
876
+	 * @param  string $return    the current html
877
+	 * @param  int    $id        the post id for the page
878
+	 * @param  string $new_title What the title is
879
+	 * @param  string $new_slug  what the slug is
880
+	 * @return string            The new html string for the permalink area
881
+	 */
882
+	public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug)
883
+	{
884
+		//make sure this is only when editing
885
+		if ( ! empty($id)) {
886
+			$post = get_post($id);
887
+			$return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#"  tabindex="-1">'
888
+					   . esc_html__('Shortcode', 'event_espresso')
889
+					   . '</a> ';
890
+			$return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id='
891
+					   . $post->ID
892
+					   . ']">';
893
+		}
894
+		return $return;
895
+	}
896
+
897
+
898
+
899
+	/**
900
+	 * _events_overview_list_table
901
+	 * This contains the logic for showing the events_overview list
902
+	 *
903
+	 * @access protected
904
+	 * @return void
905
+	 * @throws \EE_Error
906
+	 */
907
+	protected function _events_overview_list_table()
908
+	{
909
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
910
+		$this->_template_args['after_list_table'] = ! empty($this->_template_args['after_list_table'])
911
+			? (array)$this->_template_args['after_list_table']
912
+			: array();
913
+		$this->_template_args['after_list_table']['view_event_list_button'] = EEH_HTML::br()
914
+																			  . EEH_Template::get_button_or_link(
915
+				get_post_type_archive_link('espresso_events'),
916
+				esc_html__("View Event Archive Page", "event_espresso"),
917
+				'button'
918
+			);
919
+		$this->_template_args['after_list_table']['legend'] = $this->_display_legend($this->_event_legend_items());
920
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
921
+				'create_new',
922
+				'add',
923
+				array(),
924
+				'add-new-h2'
925
+			);
926
+		$this->display_admin_list_table_page_with_no_sidebar();
927
+	}
928
+
929
+
930
+
931
+	/**
932
+	 * this allows for extra misc actions in the default WP publish box
933
+	 *
934
+	 * @return void
935
+	 */
936
+	public function extra_misc_actions_publish_box()
937
+	{
938
+		$this->_generate_publish_box_extra_content();
939
+	}
940
+
941
+
942
+
943
+	/**
944
+	 * This is hooked into the WordPress do_action('save_post') hook and runs after the custom post type has been
945
+	 * saved.  Child classes are required to declare this method.  Typically you would use this to save any additional
946
+	 * data.
947
+	 * Keep in mind also that "save_post" runs on EVERY post update to the database.
948
+	 * ALSO very important.  When a post transitions from scheduled to published, the save_post action is fired but you
949
+	 * will NOT have any _POST data containing any extra info you may have from other meta saves.  So MAKE sure that
950
+	 * you handle this accordingly.
951
+	 *
952
+	 * @access protected
953
+	 * @abstract
954
+	 * @param  string $post_id The ID of the cpt that was saved (so you can link relationally)
955
+	 * @param  object $post    The post object of the cpt that was saved.
956
+	 * @return void
957
+	 */
958
+	protected function _insert_update_cpt_item($post_id, $post)
959
+	{
960
+		if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') {
961
+			//get out we're not processing an event save.
962
+			return;
963
+		}
964
+		$event_values = array(
965
+			'EVT_display_desc'                => ! empty($this->_req_data['display_desc']) ? 1 : 0,
966
+			'EVT_display_ticket_selector'     => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0,
967
+			'EVT_additional_limit'            => min(
968
+				apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255),
969
+				! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : null
970
+			),
971
+			'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status'])
972
+				? $this->_req_data['EVT_default_registration_status']
973
+				: EE_Registry::instance()->CFG->registration->default_STS_ID,
974
+			'EVT_member_only'                 => ! empty($this->_req_data['member_only']) ? 1 : 0,
975
+			'EVT_allow_overflow'              => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0,
976
+			'EVT_timezone_string'             => ! empty($this->_req_data['timezone_string'])
977
+				? $this->_req_data['timezone_string'] : null,
978
+			'EVT_external_URL'                => ! empty($this->_req_data['externalURL'])
979
+				? $this->_req_data['externalURL'] : null,
980
+			'EVT_phone'                       => ! empty($this->_req_data['event_phone'])
981
+				? $this->_req_data['event_phone'] : null,
982
+		);
983
+		//update event
984
+		$success = $this->_event_model()->update_by_ID($event_values, $post_id);
985
+		//get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id!
986
+		$get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status);
987
+		$event = $this->_event_model()->get_one(array($get_one_where));
988
+		//the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons.
989
+		$event_update_callbacks = apply_filters(
990
+			'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks',
991
+			array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))
992
+		);
993
+		$att_success = true;
994
+		foreach ($event_update_callbacks as $e_callback) {
995
+			$_succ = call_user_func_array($e_callback, array($event, $this->_req_data));
996
+			$att_success = ! $att_success ? $att_success
997
+				: $_succ; //if ANY of these updates fail then we want the appropriate global error message
998
+		}
999
+		//any errors?
1000
+		if ($success && false === $att_success) {
1001
+			EE_Error::add_error(
1002
+				esc_html__(
1003
+					'Event Details saved successfully but something went wrong with saving attachments.',
1004
+					'event_espresso'
1005
+				),
1006
+				__FILE__,
1007
+				__FUNCTION__,
1008
+				__LINE__
1009
+			);
1010
+		} else if ($success === false) {
1011
+			EE_Error::add_error(
1012
+				esc_html__('Event Details did not save successfully.', 'event_espresso'),
1013
+				__FILE__,
1014
+				__FUNCTION__,
1015
+				__LINE__
1016
+			);
1017
+		}
1018
+	}
1019
+
1020
+
1021
+
1022
+	/**
1023
+	 * @see parent::restore_item()
1024
+	 * @param int $post_id
1025
+	 * @param int $revision_id
1026
+	 */
1027
+	protected function _restore_cpt_item($post_id, $revision_id)
1028
+	{
1029
+		//copy existing event meta to new post
1030
+		$post_evt = $this->_event_model()->get_one_by_ID($post_id);
1031
+		if ($post_evt instanceof EE_Event) {
1032
+			//meta revision restore
1033
+			$post_evt->restore_revision($revision_id);
1034
+			//related objs restore
1035
+			$post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price'));
1036
+		}
1037
+	}
1038
+
1039
+
1040
+
1041
+	/**
1042
+	 * Attach the venue to the Event
1043
+	 *
1044
+	 * @param  \EE_Event $evtobj Event Object to add the venue to
1045
+	 * @param  array     $data   The request data from the form
1046
+	 * @return bool           Success or fail.
1047
+	 */
1048
+	protected function _default_venue_update(\EE_Event $evtobj, $data)
1049
+	{
1050
+		require_once(EE_MODELS . 'EEM_Venue.model.php');
1051
+		$venue_model = EE_Registry::instance()->load_model('Venue');
1052
+		$rows_affected = null;
1053
+		$venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : null;
1054
+		// very important.  If we don't have a venue name...
1055
+		// then we'll get out because not necessary to create empty venue
1056
+		if (empty($data['venue_title'])) {
1057
+			return false;
1058
+		}
1059
+		$venue_array = array(
1060
+			'VNU_wp_user'         => $evtobj->get('EVT_wp_user'),
1061
+			'VNU_name'            => ! empty($data['venue_title']) ? $data['venue_title'] : null,
1062
+			'VNU_desc'            => ! empty($data['venue_description']) ? $data['venue_description'] : null,
1063
+			'VNU_identifier'      => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : null,
1064
+			'VNU_short_desc'      => ! empty($data['venue_short_description']) ? $data['venue_short_description']
1065
+				: null,
1066
+			'VNU_address'         => ! empty($data['address']) ? $data['address'] : null,
1067
+			'VNU_address2'        => ! empty($data['address2']) ? $data['address2'] : null,
1068
+			'VNU_city'            => ! empty($data['city']) ? $data['city'] : null,
1069
+			'STA_ID'              => ! empty($data['state']) ? $data['state'] : null,
1070
+			'CNT_ISO'             => ! empty($data['countries']) ? $data['countries'] : null,
1071
+			'VNU_zip'             => ! empty($data['zip']) ? $data['zip'] : null,
1072
+			'VNU_phone'           => ! empty($data['venue_phone']) ? $data['venue_phone'] : null,
1073
+			'VNU_capacity'        => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : null,
1074
+			'VNU_url'             => ! empty($data['venue_url']) ? $data['venue_url'] : null,
1075
+			'VNU_virtual_phone'   => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : null,
1076
+			'VNU_virtual_url'     => ! empty($data['virtual_url']) ? $data['virtual_url'] : null,
1077
+			'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0,
1078
+			'status'              => 'publish',
1079
+		);
1080
+		//if we've got the venue_id then we're just updating the existing venue so let's do that and then get out.
1081
+		if ( ! empty($venue_id)) {
1082
+			$update_where = array($venue_model->primary_key_name() => $venue_id);
1083
+			$rows_affected = $venue_model->update($venue_array, array($update_where));
1084
+			//we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present.
1085
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1086
+			return $rows_affected > 0 ? true : false;
1087
+		} else {
1088
+			//we insert the venue
1089
+			$venue_id = $venue_model->insert($venue_array);
1090
+			$evtobj->_add_relation_to($venue_id, 'Venue');
1091
+			return ! empty($venue_id) ? true : false;
1092
+		}
1093
+		//when we have the ancestor come in it's already been handled by the revision save.
1094
+	}
1095
+
1096
+
1097
+
1098
+	/**
1099
+	 * Handles saving everything related to Tickets (datetimes, tickets, prices)
1100
+	 *
1101
+	 * @param  EE_Event $evtobj The Event object we're attaching data to
1102
+	 * @param  array    $data   The request data from the form
1103
+	 * @return array
1104
+	 */
1105
+	protected function _default_tickets_update(EE_Event $evtobj, $data)
1106
+	{
1107
+		$success = true;
1108
+		$saved_dtt = null;
1109
+		$saved_tickets = array();
1110
+		$incoming_date_formats = array('Y-m-d', 'h:i a');
1111
+		foreach ($data['edit_event_datetimes'] as $row => $dtt) {
1112
+			//trim all values to ensure any excess whitespace is removed.
1113
+			$dtt = array_map('trim', $dtt);
1114
+			$dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end']
1115
+				: $dtt['DTT_EVT_start'];
1116
+			$datetime_values = array(
1117
+				'DTT_ID'        => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : null,
1118
+				'DTT_EVT_start' => $dtt['DTT_EVT_start'],
1119
+				'DTT_EVT_end'   => $dtt['DTT_EVT_end'],
1120
+				'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'],
1121
+				'DTT_order'     => $row,
1122
+			);
1123
+			//if we have an id then let's get existing object first and then set the new values.  Otherwise we instantiate a new object for save.
1124
+			if ( ! empty($dtt['DTT_ID'])) {
1125
+				$DTM = EE_Registry::instance()
1126
+								  ->load_model('Datetime', array($evtobj->get_timezone()))
1127
+								  ->get_one_by_ID($dtt['DTT_ID']);
1128
+				$DTM->set_date_format($incoming_date_formats[0]);
1129
+				$DTM->set_time_format($incoming_date_formats[1]);
1130
+				foreach ($datetime_values as $field => $value) {
1131
+					$DTM->set($field, $value);
1132
+				}
1133
+				//make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it.  We need to do this so we dont' TRASH the parent DTT.
1134
+				$saved_dtts[$DTM->ID()] = $DTM;
1135
+			} else {
1136
+				$DTM = EE_Registry::instance()->load_class(
1137
+					'Datetime',
1138
+					array($datetime_values, $evtobj->get_timezone(), $incoming_date_formats),
1139
+					false,
1140
+					false
1141
+				);
1142
+				foreach ($datetime_values as $field => $value) {
1143
+					$DTM->set($field, $value);
1144
+				}
1145
+			}
1146
+			$DTM->save();
1147
+			$DTT = $evtobj->_add_relation_to($DTM, 'Datetime');
1148
+			//load DTT helper
1149
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1150
+			if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) {
1151
+				$DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start'));
1152
+				$DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days');
1153
+				$DTT->save();
1154
+			}
1155
+			//now we got to make sure we add the new DTT_ID to the $saved_dtts array  because it is possible there was a new one created for the autosave.
1156
+			$saved_dtt = $DTT;
1157
+			$success = ! $success ? $success : $DTT;
1158
+			//if ANY of these updates fail then we want the appropriate global error message.
1159
+			// //todo this is actually sucky we need a better error message but this is what it is for now.
1160
+		}
1161
+		//no dtts get deleted so we don't do any of that logic here.
1162
+		//update tickets next
1163
+		$old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array();
1164
+		foreach ($data['edit_tickets'] as $row => $tkt) {
1165
+			$incoming_date_formats = array('Y-m-d', 'h:i a');
1166
+			$update_prices = false;
1167
+			$ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount'])
1168
+				? $data['edit_prices'][$row][1]['PRC_amount'] : 0;
1169
+			// trim inputs to ensure any excess whitespace is removed.
1170
+			$tkt = array_map('trim', $tkt);
1171
+			if (empty($tkt['TKT_start_date'])) {
1172
+				//let's use now in the set timezone.
1173
+				$now = new DateTime('now', new DateTimeZone($evtobj->get_timezone()));
1174
+				$tkt['TKT_start_date'] = $now->format($incoming_date_formats[0] . ' ' . $incoming_date_formats[1]);
1175
+			}
1176
+			if (empty($tkt['TKT_end_date'])) {
1177
+				//use the start date of the first datetime
1178
+				$dtt = $evtobj->first_datetime();
1179
+				$tkt['TKT_end_date'] = $dtt->start_date_and_time(
1180
+					$incoming_date_formats[0],
1181
+					$incoming_date_formats[1]
1182
+				);
1183
+			}
1184
+			$TKT_values = array(
1185
+				'TKT_ID'          => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null,
1186
+				'TTM_ID'          => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0,
1187
+				'TKT_name'        => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '',
1188
+				'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '',
1189
+				'TKT_start_date'  => $tkt['TKT_start_date'],
1190
+				'TKT_end_date'    => $tkt['TKT_end_date'],
1191
+				'TKT_qty'         => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'],
1192
+				'TKT_uses'        => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'],
1193
+				'TKT_min'         => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'],
1194
+				'TKT_max'         => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'],
1195
+				'TKT_row'         => $row,
1196
+				'TKT_order'       => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row,
1197
+				'TKT_price'       => $ticket_price,
1198
+			);
1199
+			//if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well.
1200
+			if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) {
1201
+				$TKT_values['TKT_ID'] = 0;
1202
+				$TKT_values['TKT_is_default'] = 0;
1203
+				$TKT_values['TKT_price'] = $ticket_price;
1204
+				$update_prices = true;
1205
+			}
1206
+			//if we have a TKT_ID then we need to get that existing TKT_obj and update it
1207
+			//we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified.
1208
+			//keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived.
1209
+			if ( ! empty($tkt['TKT_ID'])) {
1210
+				$TKT = EE_Registry::instance()
1211
+								  ->load_model('Ticket', array($evtobj->get_timezone()))
1212
+								  ->get_one_by_ID($tkt['TKT_ID']);
1213
+				if ($TKT instanceof EE_Ticket) {
1214
+					$ticket_sold = $TKT->count_related(
1215
+						'Registration',
1216
+						array(
1217
+							array(
1218
+								'STS_ID' => array(
1219
+									'NOT IN',
1220
+									array(EEM_Registration::status_id_incomplete),
1221
+								),
1222
+							),
1223
+						)
1224
+					) > 0 ? true : false;
1225
+					//let's just check the total price for the existing ticket and determine if it matches the new total price.  if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket.
1226
+					$create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price')
1227
+									  && ! $TKT->get(
1228
+						'TKT_deleted'
1229
+					) ? true : false;
1230
+					$TKT->set_date_format($incoming_date_formats[0]);
1231
+					$TKT->set_time_format($incoming_date_formats[1]);
1232
+					//set new values
1233
+					foreach ($TKT_values as $field => $value) {
1234
+						if ($field == 'TKT_qty') {
1235
+							$TKT->set_qty($value);
1236
+						} else {
1237
+							$TKT->set($field, $value);
1238
+						}
1239
+					}
1240
+					//if $create_new_TKT is false then we can safely update the existing ticket.  Otherwise we have to create a new ticket.
1241
+					if ($create_new_TKT) {
1242
+						//archive the old ticket first
1243
+						$TKT->set('TKT_deleted', 1);
1244
+						$TKT->save();
1245
+						//make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine.
1246
+						$saved_tickets[$TKT->ID()] = $TKT;
1247
+						//create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it.
1248
+						$TKT = clone $TKT;
1249
+						$TKT->set('TKT_ID', 0);
1250
+						$TKT->set('TKT_deleted', 0);
1251
+						$TKT->set('TKT_price', $ticket_price);
1252
+						$TKT->set('TKT_sold', 0);
1253
+						//now we need to make sure that $new prices are created as well and attached to new ticket.
1254
+						$update_prices = true;
1255
+					}
1256
+					//make sure price is set if it hasn't been already
1257
+					$TKT->set('TKT_price', $ticket_price);
1258
+				}
1259
+			} else {
1260
+				//no TKT_id so a new TKT
1261
+				$TKT_values['TKT_price'] = $ticket_price;
1262
+				$TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), false, false);
1263
+				if ($TKT instanceof EE_Ticket) {
1264
+					//need to reset values to properly account for the date formats
1265
+					$TKT->set_date_format($incoming_date_formats[0]);
1266
+					$TKT->set_time_format($incoming_date_formats[1]);
1267
+					$TKT->set_timezone($evtobj->get_timezone());
1268
+					//set new values
1269
+					foreach ($TKT_values as $field => $value) {
1270
+						if ($field == 'TKT_qty') {
1271
+							$TKT->set_qty($value);
1272
+						} else {
1273
+							$TKT->set($field, $value);
1274
+						}
1275
+					}
1276
+					$update_prices = true;
1277
+				}
1278
+			}
1279
+			// cap ticket qty by datetime reg limits
1280
+			$TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit')));
1281
+			//update ticket.
1282
+			$TKT->save();
1283
+			//before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date.
1284
+			if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) {
1285
+				$TKT->set('TKT_end_date', $TKT->get('TKT_start_date'));
1286
+				$TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days');
1287
+				$TKT->save();
1288
+			}
1289
+			//initially let's add the ticket to the dtt
1290
+			$saved_dtt->_add_relation_to($TKT, 'Ticket');
1291
+			$saved_tickets[$TKT->ID()] = $TKT;
1292
+			//add prices to ticket
1293
+			$this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices);
1294
+		}
1295
+		//however now we need to handle permanently deleting tickets via the ui.  Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold.  However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db.
1296
+		$old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets;
1297
+		$tickets_removed = array_diff($old_tickets, array_keys($saved_tickets));
1298
+		foreach ($tickets_removed as $id) {
1299
+			$id = absint($id);
1300
+			//get the ticket for this id
1301
+			$tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id);
1302
+			//need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold)
1303
+			$dtts = $tkt_to_remove->get_many_related('Datetime');
1304
+			foreach ($dtts as $dtt) {
1305
+				$tkt_to_remove->_remove_relation_to($dtt, 'Datetime');
1306
+			}
1307
+			//need to do the same for prices (except these prices can also be deleted because again, tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived))
1308
+			$tkt_to_remove->delete_related_permanently('Price');
1309
+			//finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships)
1310
+			$tkt_to_remove->delete_permanently();
1311
+		}
1312
+		return array($saved_dtt, $saved_tickets);
1313
+	}
1314
+
1315
+
1316
+
1317
+	/**
1318
+	 * This attaches a list of given prices to a ticket.
1319
+	 * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change
1320
+	 * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old
1321
+	 * price info and prices are automatically "archived" via the ticket.
1322
+	 *
1323
+	 * @access  private
1324
+	 * @param array     $prices     Array of prices from the form.
1325
+	 * @param EE_Ticket $ticket     EE_Ticket object that prices are being attached to.
1326
+	 * @param bool      $new_prices Whether attach existing incoming prices or create new ones.
1327
+	 * @return  void
1328
+	 */
1329
+	private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = false)
1330
+	{
1331
+		foreach ($prices as $row => $prc) {
1332
+			$PRC_values = array(
1333
+				'PRC_ID'         => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null,
1334
+				'PRT_ID'         => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null,
1335
+				'PRC_amount'     => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0,
1336
+				'PRC_name'       => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '',
1337
+				'PRC_desc'       => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '',
1338
+				'PRC_is_default' => 0, //make sure prices are NOT set as default from this context
1339
+				'PRC_order'      => $row,
1340
+			);
1341
+			if ($new_prices || empty($PRC_values['PRC_ID'])) {
1342
+				$PRC_values['PRC_ID'] = 0;
1343
+				$PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), false, false);
1344
+			} else {
1345
+				$PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']);
1346
+				//update this price with new values
1347
+				foreach ($PRC_values as $field => $newprc) {
1348
+					$PRC->set($field, $newprc);
1349
+				}
1350
+				$PRC->save();
1351
+			}
1352
+			$ticket->_add_relation_to($PRC, 'Price');
1353
+		}
1354
+	}
1355
+
1356
+
1357
+
1358
+	/**
1359
+	 * Add in our autosave ajax handlers
1360
+	 *
1361
+	 * @return void
1362
+	 */
1363
+	protected function _ee_autosave_create_new()
1364
+	{
1365
+		// $this->_ee_autosave_edit();
1366
+	}
1367
+
1368
+
1369
+
1370
+	protected function _ee_autosave_edit()
1371
+	{
1372
+		return; //TEMPORARILY EXITING CAUSE THIS IS A TODO
1373
+	}
1374
+
1375
+
1376
+
1377
+	/**
1378
+	 *    _generate_publish_box_extra_content
1379
+	 *
1380
+	 * @access private
1381
+	 * @return void
1382
+	 */
1383
+	private function _generate_publish_box_extra_content()
1384
+	{
1385
+		//load formatter helper
1386
+		//args for getting related registrations
1387
+		$approved_query_args = array(
1388
+			array(
1389
+				'REG_deleted' => 0,
1390
+				'STS_ID'      => EEM_Registration::status_id_approved,
1391
+			),
1392
+		);
1393
+		$not_approved_query_args = array(
1394
+			array(
1395
+				'REG_deleted' => 0,
1396
+				'STS_ID'      => EEM_Registration::status_id_not_approved,
1397
+			),
1398
+		);
1399
+		$pending_payment_query_args = array(
1400
+			array(
1401
+				'REG_deleted' => 0,
1402
+				'STS_ID'      => EEM_Registration::status_id_pending_payment,
1403
+			),
1404
+		);
1405
+		// publish box
1406
+		$publish_box_extra_args = array(
1407
+			'view_approved_reg_url'        => add_query_arg(
1408
+				array(
1409
+					'action'      => 'default',
1410
+					'event_id'    => $this->_cpt_model_obj->ID(),
1411
+					'_reg_status' => EEM_Registration::status_id_approved,
1412
+				),
1413
+				REG_ADMIN_URL
1414
+			),
1415
+			'view_not_approved_reg_url'    => add_query_arg(
1416
+				array(
1417
+					'action'      => 'default',
1418
+					'event_id'    => $this->_cpt_model_obj->ID(),
1419
+					'_reg_status' => EEM_Registration::status_id_not_approved,
1420
+				),
1421
+				REG_ADMIN_URL
1422
+			),
1423
+			'view_pending_payment_reg_url' => add_query_arg(
1424
+				array(
1425
+					'action'      => 'default',
1426
+					'event_id'    => $this->_cpt_model_obj->ID(),
1427
+					'_reg_status' => EEM_Registration::status_id_pending_payment,
1428
+				),
1429
+				REG_ADMIN_URL
1430
+			),
1431
+			'approved_regs'                => $this->_cpt_model_obj->count_related(
1432
+				'Registration',
1433
+				$approved_query_args
1434
+			),
1435
+			'not_approved_regs'            => $this->_cpt_model_obj->count_related(
1436
+				'Registration',
1437
+				$not_approved_query_args
1438
+			),
1439
+			'pending_payment_regs'         => $this->_cpt_model_obj->count_related(
1440
+				'Registration',
1441
+				$pending_payment_query_args
1442
+			),
1443
+			'misc_pub_section_class'       => apply_filters(
1444
+				'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class',
1445
+				'misc-pub-section'
1446
+			),
1447
+			//'email_attendees_url' => add_query_arg(
1448
+			//	array(
1449
+			//		'event_admin_reports' => 'event_newsletter',
1450
+			//		'event_id' => $this->_cpt_model_obj->id
1451
+			//	),
1452
+			//	'admin.php?page=espresso_registrations'
1453
+			//),
1454
+		);
1455
+		ob_start();
1456
+		do_action(
1457
+			'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add',
1458
+			$this->_cpt_model_obj
1459
+		);
1460
+		$publish_box_extra_args['event_editor_overview_add'] = ob_get_clean();
1461
+		// load template
1462
+		EEH_Template::display_template(
1463
+			EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php',
1464
+			$publish_box_extra_args
1465
+		);
1466
+	}
1467
+
1468
+
1469
+
1470
+	/**
1471
+	 * This just returns whatever is set as the _event object property
1472
+	 * //todo this will become obsolete once the models are in place
1473
+	 *
1474
+	 * @return object
1475
+	 */
1476
+	public function get_event_object()
1477
+	{
1478
+		return $this->_cpt_model_obj;
1479
+	}
1480
+
1481
+
1482
+
1483
+
1484
+	/** METABOXES * */
1485
+	/**
1486
+	 * _register_event_editor_meta_boxes
1487
+	 * add all metaboxes related to the event_editor
1488
+	 *
1489
+	 * @return void
1490
+	 */
1491
+	protected function _register_event_editor_meta_boxes()
1492
+	{
1493
+		$this->verify_cpt_object();
1494
+		add_meta_box(
1495
+			'espresso_event_editor_tickets',
1496
+			esc_html__('Event Datetime & Ticket', 'event_espresso'),
1497
+			array($this, 'ticket_metabox'),
1498
+			$this->page_slug,
1499
+			'normal',
1500
+			'high'
1501
+		);
1502
+		add_meta_box(
1503
+			'espresso_event_editor_event_options',
1504
+			esc_html__('Event Registration Options', 'event_espresso'),
1505
+			array($this, 'registration_options_meta_box'),
1506
+			$this->page_slug,
1507
+			'side',
1508
+			'default'
1509
+		);
1510
+		// NOTE: if you're looking for other metaboxes in here,
1511
+		// where a metabox has a related management page in the admin
1512
+		// you will find it setup in the related management page's "_Hooks" file.
1513
+		// i.e. messages metabox is found in "espresso_events_Messages_Hooks.class.php".
1514
+	}
1515
+
1516
+
1517
+
1518
+	public function ticket_metabox()
1519
+	{
1520
+		$existing_datetime_ids = $existing_ticket_ids = array();
1521
+		//defaults for template args
1522
+		$template_args = array(
1523
+			'existing_datetime_ids'    => '',
1524
+			'event_datetime_help_link' => '',
1525
+			'ticket_options_help_link' => '',
1526
+			'time'                     => null,
1527
+			'ticket_rows'              => '',
1528
+			'existing_ticket_ids'      => '',
1529
+			'total_ticket_rows'        => 1,
1530
+			'ticket_js_structure'      => '',
1531
+			'trash_icon'               => 'ee-lock-icon',
1532
+			'disabled'                 => '',
1533
+		);
1534
+		$event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : null;
1535
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
1536
+		/**
1537
+		 * 1. Start with retrieving Datetimes
1538
+		 * 2. Fore each datetime get related tickets
1539
+		 * 3. For each ticket get related prices
1540
+		 */
1541
+		$times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id);
1542
+		/** @type EE_Datetime $first_datetime */
1543
+		$first_datetime = reset($times);
1544
+		//do we get related tickets?
1545
+		if ($first_datetime instanceof EE_Datetime
1546
+			&& $first_datetime->ID() !== 0
1547
+		) {
1548
+			$existing_datetime_ids[] = $first_datetime->get('DTT_ID');
1549
+			$template_args['time'] = $first_datetime;
1550
+			$related_tickets = $first_datetime->tickets(
1551
+				array(
1552
+					array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)),
1553
+					'default_where_conditions' => 'none',
1554
+				)
1555
+			);
1556
+			if ( ! empty($related_tickets)) {
1557
+				$template_args['total_ticket_rows'] = count($related_tickets);
1558
+				$row = 0;
1559
+				foreach ($related_tickets as $ticket) {
1560
+					$existing_ticket_ids[] = $ticket->get('TKT_ID');
1561
+					$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, false, $row);
1562
+					$row++;
1563
+				}
1564
+			} else {
1565
+				$template_args['total_ticket_rows'] = 1;
1566
+				/** @type EE_Ticket $ticket */
1567
+				$ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object();
1568
+				$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket);
1569
+			}
1570
+		} else {
1571
+			$template_args['time'] = $times[0];
1572
+			/** @type EE_Ticket $ticket */
1573
+			$ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets();
1574
+			$template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]);
1575
+			// NOTE: we're just sending the first default row
1576
+			// (decaf can't manage default tickets so this should be sufficient);
1577
+		}
1578
+		$template_args['event_datetime_help_link'] = $this->_get_help_tab_link(
1579
+			'event_editor_event_datetimes_help_tab'
1580
+		);
1581
+		$template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info');
1582
+		$template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids);
1583
+		$template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids);
1584
+		$template_args['ticket_js_structure'] = $this->_get_ticket_row(
1585
+			EE_Registry::instance()->load_model('Ticket')->create_default_object(),
1586
+			true
1587
+		);
1588
+		$template = apply_filters(
1589
+			'FHEE__Events_Admin_Page__ticket_metabox__template',
1590
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php'
1591
+		);
1592
+		EEH_Template::display_template($template, $template_args);
1593
+	}
1594
+
1595
+
1596
+
1597
+	/**
1598
+	 * Setup an individual ticket form for the decaf event editor page
1599
+	 *
1600
+	 * @access private
1601
+	 * @param  EE_Ticket $ticket   the ticket object
1602
+	 * @param  boolean   $skeleton whether we're generating a skeleton for js manipulation
1603
+	 * @param int        $row
1604
+	 * @return string generated html for the ticket row.
1605
+	 */
1606
+	private function _get_ticket_row($ticket, $skeleton = false, $row = 0)
1607
+	{
1608
+		$template_args = array(
1609
+			'tkt_status_class'    => ' tkt-status-' . $ticket->ticket_status(),
1610
+			'tkt_archive_class'   => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived'
1611
+				: '',
1612
+			'ticketrow'           => $skeleton ? 'TICKETNUM' : $row,
1613
+			'TKT_ID'              => $ticket->get('TKT_ID'),
1614
+			'TKT_name'            => $ticket->get('TKT_name'),
1615
+			'TKT_start_date'      => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'),
1616
+			'TKT_end_date'        => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'),
1617
+			'TKT_is_default'      => $ticket->get('TKT_is_default'),
1618
+			'TKT_qty'             => $ticket->get_pretty('TKT_qty', 'input'),
1619
+			'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets',
1620
+			'TKT_sold'            => $skeleton ? 0 : $ticket->get('TKT_sold'),
1621
+			'trash_icon'          => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')))
1622
+									 && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0)
1623
+				? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon',
1624
+			'disabled'            => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? ''
1625
+				: ' disabled=disabled',
1626
+		);
1627
+		$price = $ticket->ID() !== 0
1628
+			? $ticket->get_first_related('Price', array('default_where_conditions' => 'none'))
1629
+			: EE_Registry::instance()->load_model('Price')->create_default_object();
1630
+		$price_args = array(
1631
+			'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign,
1632
+			'PRC_amount'            => $price->get('PRC_amount'),
1633
+			'PRT_ID'                => $price->get('PRT_ID'),
1634
+			'PRC_ID'                => $price->get('PRC_ID'),
1635
+			'PRC_is_default'        => $price->get('PRC_is_default'),
1636
+		);
1637
+		//make sure we have default start and end dates if skeleton
1638
+		//handle rows that should NOT be empty
1639
+		if (empty($template_args['TKT_start_date'])) {
1640
+			//if empty then the start date will be now.
1641
+			$template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp'));
1642
+		}
1643
+		if (empty($template_args['TKT_end_date'])) {
1644
+			//get the earliest datetime (if present);
1645
+			$earliest_dtt = $this->_cpt_model_obj->ID() > 0
1646
+				? $this->_cpt_model_obj->get_first_related(
1647
+					'Datetime',
1648
+					array('order_by' => array('DTT_EVT_start' => 'ASC'))
1649
+				)
1650
+				: null;
1651
+			if ( ! empty($earliest_dtt)) {
1652
+				$template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a');
1653
+			} else {
1654
+				$template_args['TKT_end_date'] = date(
1655
+					'Y-m-d h:i a',
1656
+					mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))
1657
+				);
1658
+			}
1659
+		}
1660
+		$template_args = array_merge($template_args, $price_args);
1661
+		$template = apply_filters(
1662
+			'FHEE__Events_Admin_Page__get_ticket_row__template',
1663
+			EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php',
1664
+			$ticket
1665
+		);
1666
+		return EEH_Template::display_template($template, $template_args, true);
1667
+	}
1668
+
1669
+
1670
+
1671
+	public function registration_options_meta_box()
1672
+	{
1673
+		$yes_no_values = array(
1674
+			array('id' => true, 'text' => esc_html__('Yes', 'event_espresso')),
1675
+			array('id' => false, 'text' => esc_html__('No', 'event_espresso')),
1676
+		);
1677
+		$default_reg_status_values = EEM_Registration::reg_status_array(
1678
+			array(
1679
+				EEM_Registration::status_id_cancelled,
1680
+				EEM_Registration::status_id_declined,
1681
+				EEM_Registration::status_id_incomplete,
1682
+			),
1683
+			true
1684
+		);
1685
+		//$template_args['is_active_select'] = EEH_Form_Fields::select_input('is_active', $yes_no_values, $this->_cpt_model_obj->is_active());
1686
+		$template_args['_event'] = $this->_cpt_model_obj;
1687
+		$template_args['active_status'] = $this->_cpt_model_obj->pretty_active_status(false);
1688
+		$template_args['additional_limit'] = $this->_cpt_model_obj->additional_limit();
1689
+		$template_args['default_registration_status'] = EEH_Form_Fields::select_input(
1690
+			'default_reg_status',
1691
+			$default_reg_status_values,
1692
+			$this->_cpt_model_obj->default_registration_status()
1693
+		);
1694
+		$template_args['display_description'] = EEH_Form_Fields::select_input(
1695
+			'display_desc',
1696
+			$yes_no_values,
1697
+			$this->_cpt_model_obj->display_description()
1698
+		);
1699
+		$template_args['display_ticket_selector'] = EEH_Form_Fields::select_input(
1700
+			'display_ticket_selector',
1701
+			$yes_no_values,
1702
+			$this->_cpt_model_obj->display_ticket_selector(),
1703
+			'',
1704
+			'',
1705
+			false
1706
+		);
1707
+		$template_args['additional_registration_options'] = apply_filters(
1708
+			'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options',
1709
+			'',
1710
+			$template_args,
1711
+			$yes_no_values,
1712
+			$default_reg_status_values
1713
+		);
1714
+		EEH_Template::display_template(
1715
+			EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php',
1716
+			$template_args
1717
+		);
1718
+	}
1719
+
1720
+
1721
+
1722
+	/**
1723
+	 * _get_events()
1724
+	 * This method simply returns all the events (for the given _view and paging)
1725
+	 *
1726
+	 * @access public
1727
+	 * @param int  $per_page     count of items per page (20 default);
1728
+	 * @param int  $current_page what is the current page being viewed.
1729
+	 * @param bool $count        if TRUE then we just return a count of ALL events matching the given _view.
1730
+	 *                           If FALSE then we return an array of event objects
1731
+	 *                           that match the given _view and paging parameters.
1732
+	 * @return array an array of event objects.
1733
+	 */
1734
+	public function get_events($per_page = 10, $current_page = 1, $count = false)
1735
+	{
1736
+		$EEME = $this->_event_model();
1737
+		$offset = ($current_page - 1) * $per_page;
1738
+		$limit = $count ? null : $offset . ',' . $per_page;
1739
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID';
1740
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC";
1741
+		if (isset($this->_req_data['month_range'])) {
1742
+			$pieces = explode(' ', $this->_req_data['month_range'], 3);
1743
+			$month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : '';
1744
+			$year_r = ! empty($pieces[1]) ? $pieces[1] : '';
1745
+		}
1746
+		$where = array();
1747
+		$status = isset($this->_req_data['status']) ? $this->_req_data['status'] : null;
1748
+		//determine what post_status our condition will have for the query.
1749
+		switch ($status) {
1750
+			case 'month' :
1751
+			case 'today' :
1752
+			case null :
1753
+			case 'all' :
1754
+				break;
1755
+			case 'draft' :
1756
+				$where['status'] = array('IN', array('draft', 'auto-draft'));
1757
+				break;
1758
+			default :
1759
+				$where['status'] = $status;
1760
+		}
1761
+		//categories?
1762
+		$category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0
1763
+			? $this->_req_data['EVT_CAT'] : null;
1764
+		if ( ! empty ($category)) {
1765
+			$where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories';
1766
+			$where['Term_Taxonomy.term_id'] = $category;
1767
+		}
1768
+		//date where conditions
1769
+		$start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start');
1770
+		if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') {
1771
+			$DateTime = new DateTime(
1772
+				$year_r . '-' . $month_r . '-01 00:00:00',
1773
+				new DateTimeZone(EEM_Datetime::instance()->get_timezone())
1774
+			);
1775
+			$start = $DateTime->format(implode(' ', $start_formats));
1776
+			$end = $DateTime->setDate($year_r, $month_r, $DateTime
1777
+				->format('t'))->setTime(23, 59, 59)
1778
+							->format(implode(' ', $start_formats));
1779
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1780
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') {
1781
+			$DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone()));
1782
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1783
+			$end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats));
1784
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1785
+		} else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') {
1786
+			$now = date('Y-m-01');
1787
+			$DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone()));
1788
+			$start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats));
1789
+			$end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))
1790
+							->setTime(23, 59, 59)
1791
+							->format(implode(' ', $start_formats));
1792
+			$where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end));
1793
+		}
1794
+		if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) {
1795
+			$where['EVT_wp_user'] = get_current_user_id();
1796
+		} else {
1797
+			if ( ! isset($where['status'])) {
1798
+				if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) {
1799
+					$where['OR'] = array(
1800
+						'status*restrict_private' => array('!=', 'private'),
1801
+						'AND'                     => array(
1802
+							'status*inclusive' => array('=', 'private'),
1803
+							'EVT_wp_user'      => get_current_user_id(),
1804
+						),
1805
+					);
1806
+				}
1807
+			}
1808
+		}
1809
+		if (isset($this->_req_data['EVT_wp_user'])) {
1810
+			if ($this->_req_data['EVT_wp_user'] != get_current_user_id()
1811
+				&& EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')
1812
+			) {
1813
+				$where['EVT_wp_user'] = $this->_req_data['EVT_wp_user'];
1814
+			}
1815
+		}
1816
+		//search query handling
1817
+		if (isset($this->_req_data['s'])) {
1818
+			$search_string = '%' . $this->_req_data['s'] . '%';
1819
+			$where['OR'] = array(
1820
+				'EVT_name'       => array('LIKE', $search_string),
1821
+				'EVT_desc'       => array('LIKE', $search_string),
1822
+				'EVT_short_desc' => array('LIKE', $search_string),
1823
+			);
1824
+		}
1825
+		$where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);
1826
+		$query_params = apply_filters(
1827
+			'FHEE__Events_Admin_Page__get_events__query_params',
1828
+			array(
1829
+				$where,
1830
+				'limit'    => $limit,
1831
+				'order_by' => $orderby,
1832
+				'order'    => $order,
1833
+				'group_by' => 'EVT_ID',
1834
+			),
1835
+			$this->_req_data
1836
+		);
1837
+		//let's first check if we have special requests coming in.
1838
+		if (isset($this->_req_data['active_status'])) {
1839
+			switch ($this->_req_data['active_status']) {
1840
+				case 'upcoming' :
1841
+					return $EEME->get_upcoming_events($query_params, $count);
1842
+					break;
1843
+				case 'expired' :
1844
+					return $EEME->get_expired_events($query_params, $count);
1845
+					break;
1846
+				case 'active' :
1847
+					return $EEME->get_active_events($query_params, $count);
1848
+					break;
1849
+				case 'inactive' :
1850
+					return $EEME->get_inactive_events($query_params, $count);
1851
+					break;
1852
+			}
1853
+		}
1854
+		$events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params);
1855
+		return $events;
1856
+	}
1857
+
1858
+
1859
+
1860
+	/**
1861
+	 * handling for WordPress CPT actions (trash, restore, delete)
1862
+	 *
1863
+	 * @param string $post_id
1864
+	 */
1865
+	public function trash_cpt_item($post_id)
1866
+	{
1867
+		$this->_req_data['EVT_ID'] = $post_id;
1868
+		$this->_trash_or_restore_event('trash', false);
1869
+	}
1870
+
1871
+
1872
+
1873
+	/**
1874
+	 * @param string $post_id
1875
+	 */
1876
+	public function restore_cpt_item($post_id)
1877
+	{
1878
+		$this->_req_data['EVT_ID'] = $post_id;
1879
+		$this->_trash_or_restore_event('draft', false);
1880
+	}
1881
+
1882
+
1883
+
1884
+	/**
1885
+	 * @param string $post_id
1886
+	 */
1887
+	public function delete_cpt_item($post_id)
1888
+	{
1889
+		$this->_req_data['EVT_ID'] = $post_id;
1890
+		$this->_delete_event(false);
1891
+	}
1892
+
1893
+
1894
+
1895
+	/**
1896
+	 * _trash_or_restore_event
1897
+	 *
1898
+	 * @access protected
1899
+	 * @param  string $event_status
1900
+	 * @param bool    $redirect_after
1901
+	 */
1902
+	protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = true)
1903
+	{
1904
+		//determine the event id and set to array.
1905
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : false;
1906
+		// loop thru events
1907
+		if ($EVT_ID) {
1908
+			// clean status
1909
+			$event_status = sanitize_key($event_status);
1910
+			// grab status
1911
+			if ( ! empty($event_status)) {
1912
+				$success = $this->_change_event_status($EVT_ID, $event_status);
1913
+			} else {
1914
+				$success = false;
1915
+				$msg = esc_html__(
1916
+					'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1917
+					'event_espresso'
1918
+				);
1919
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1920
+			}
1921
+		} else {
1922
+			$success = false;
1923
+			$msg = esc_html__(
1924
+				'An error occurred. The event could not be moved to the trash because a valid event ID was not not supplied.',
1925
+				'event_espresso'
1926
+			);
1927
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1928
+		}
1929
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1930
+		if ($redirect_after) {
1931
+			$this->_redirect_after_action($success, 'Event', $action, array('action' => 'default'));
1932
+		}
1933
+	}
1934
+
1935
+
1936
+
1937
+	/**
1938
+	 * _trash_or_restore_events
1939
+	 *
1940
+	 * @access protected
1941
+	 * @param  string $event_status
1942
+	 * @return void
1943
+	 */
1944
+	protected function _trash_or_restore_events($event_status = 'trash')
1945
+	{
1946
+		// clean status
1947
+		$event_status = sanitize_key($event_status);
1948
+		// grab status
1949
+		if ( ! empty($event_status)) {
1950
+			$success = true;
1951
+			//determine the event id and set to array.
1952
+			$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
1953
+			// loop thru events
1954
+			foreach ($EVT_IDs as $EVT_ID) {
1955
+				if ($EVT_ID = absint($EVT_ID)) {
1956
+					$results = $this->_change_event_status($EVT_ID, $event_status);
1957
+					$success = $results !== false ? $success : false;
1958
+				} else {
1959
+					$msg = sprintf(
1960
+						esc_html__(
1961
+							'An error occurred. Event #%d could not be moved to the trash because a valid event ID was not not supplied.',
1962
+							'event_espresso'
1963
+						),
1964
+						$EVT_ID
1965
+					);
1966
+					EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1967
+					$success = false;
1968
+				}
1969
+			}
1970
+		} else {
1971
+			$success = false;
1972
+			$msg = esc_html__(
1973
+				'An error occurred. The event could not be moved to the trash because a valid event status was not not supplied.',
1974
+				'event_espresso'
1975
+			);
1976
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
1977
+		}
1978
+		// in order to force a pluralized result message we need to send back a success status greater than 1
1979
+		$success = $success ? 2 : false;
1980
+		$action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash';
1981
+		$this->_redirect_after_action($success, 'Events', $action, array('action' => 'default'));
1982
+	}
1983
+
1984
+
1985
+
1986
+	/**
1987
+	 * _trash_or_restore_events
1988
+	 *
1989
+	 * @access  private
1990
+	 * @param  int    $EVT_ID
1991
+	 * @param  string $event_status
1992
+	 * @return bool
1993
+	 */
1994
+	private function _change_event_status($EVT_ID = 0, $event_status = '')
1995
+	{
1996
+		// grab event id
1997
+		if ( ! $EVT_ID) {
1998
+			$msg = esc_html__(
1999
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2000
+				'event_espresso'
2001
+			);
2002
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2003
+			return false;
2004
+		}
2005
+		$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2006
+		// clean status
2007
+		$event_status = sanitize_key($event_status);
2008
+		// grab status
2009
+		if (empty($event_status)) {
2010
+			$msg = esc_html__(
2011
+				'An error occurred. No Event Status or an invalid Event Status was received.',
2012
+				'event_espresso'
2013
+			);
2014
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2015
+			return false;
2016
+		}
2017
+		// was event trashed or restored ?
2018
+		switch ($event_status) {
2019
+			case 'draft' :
2020
+				$action = 'restored from the trash';
2021
+				$hook = 'AHEE_event_restored_from_trash';
2022
+				break;
2023
+			case 'trash' :
2024
+				$action = 'moved to the trash';
2025
+				$hook = 'AHEE_event_moved_to_trash';
2026
+				break;
2027
+			default :
2028
+				$action = 'updated';
2029
+				$hook = false;
2030
+		}
2031
+		//use class to change status
2032
+		$this->_cpt_model_obj->set_status($event_status);
2033
+		$success = $this->_cpt_model_obj->save();
2034
+		if ($success === false) {
2035
+			$msg = sprintf(esc_html__('An error occurred. The event could not be %s.', 'event_espresso'), $action);
2036
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2037
+			return false;
2038
+		}
2039
+		if ($hook) {
2040
+			do_action($hook);
2041
+		}
2042
+		return true;
2043
+	}
2044
+
2045
+
2046
+
2047
+	/**
2048
+	 * _delete_event
2049
+	 *
2050
+	 * @access protected
2051
+	 * @param bool $redirect_after
2052
+	 */
2053
+	protected function _delete_event($redirect_after = true)
2054
+	{
2055
+		//determine the event id and set to array.
2056
+		$EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : null;
2057
+		$EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID;
2058
+		// loop thru events
2059
+		if ($EVT_ID) {
2060
+			$success = $this->_permanently_delete_event($EVT_ID);
2061
+			// get list of events with no prices
2062
+			$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2063
+			// remove this event from the list of events with no prices
2064
+			if (isset($espresso_no_ticket_prices[$EVT_ID])) {
2065
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2066
+			}
2067
+			update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2068
+		} else {
2069
+			$success = false;
2070
+			$msg = esc_html__(
2071
+				'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2072
+				'event_espresso'
2073
+			);
2074
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2075
+		}
2076
+		if ($redirect_after) {
2077
+			$this->_redirect_after_action(
2078
+				$success,
2079
+				'Event',
2080
+				'deleted',
2081
+				array('action' => 'default', 'status' => 'trash')
2082
+			);
2083
+		}
2084
+	}
2085
+
2086
+
2087
+
2088
+	/**
2089
+	 * _delete_events
2090
+	 *
2091
+	 * @access protected
2092
+	 * @return void
2093
+	 */
2094
+	protected function _delete_events()
2095
+	{
2096
+		$success = true;
2097
+		// get list of events with no prices
2098
+		$espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array());
2099
+		//determine the event id and set to array.
2100
+		$EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array)$this->_req_data['EVT_IDs'] : array();
2101
+		// loop thru events
2102
+		foreach ($EVT_IDs as $EVT_ID) {
2103
+			$EVT_ID = absint($EVT_ID);
2104
+			if ($EVT_ID) {
2105
+				$results = $this->_permanently_delete_event($EVT_ID);
2106
+				$success = $results !== false ? $success : false;
2107
+				// remove this event from the list of events with no prices
2108
+				unset($espresso_no_ticket_prices[$EVT_ID]);
2109
+			} else {
2110
+				$success = false;
2111
+				$msg = esc_html__(
2112
+					'An error occurred. An event could not be deleted because a valid event ID was not not supplied.',
2113
+					'event_espresso'
2114
+				);
2115
+				EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2116
+			}
2117
+		}
2118
+		update_option('ee_no_ticket_prices', $espresso_no_ticket_prices);
2119
+		// in order to force a pluralized result message we need to send back a success status greater than 1
2120
+		$success = $success ? 2 : false;
2121
+		$this->_redirect_after_action($success, 'Events', 'deleted', array('action' => 'default'));
2122
+	}
2123
+
2124
+
2125
+
2126
+	/**
2127
+	 * _permanently_delete_event
2128
+	 *
2129
+	 * @access  private
2130
+	 * @param  int $EVT_ID
2131
+	 * @return bool
2132
+	 */
2133
+	private function _permanently_delete_event($EVT_ID = 0)
2134
+	{
2135
+		// grab event id
2136
+		if ( ! $EVT_ID) {
2137
+			$msg = esc_html__(
2138
+				'An error occurred. No Event ID or an invalid Event ID was received.',
2139
+				'event_espresso'
2140
+			);
2141
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2142
+			return false;
2143
+		}
2144
+		if (
2145
+			! $this->_cpt_model_obj instanceof EE_Event
2146
+			|| $this->_cpt_model_obj->ID() !== $EVT_ID
2147
+		) {
2148
+			$this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID);
2149
+		}
2150
+		if ( ! $this->_cpt_model_obj instanceof EE_Event) {
2151
+			return false;
2152
+		}
2153
+		//need to delete related tickets and prices first.
2154
+		$datetimes = $this->_cpt_model_obj->get_many_related('Datetime');
2155
+		foreach ($datetimes as $datetime) {
2156
+			$this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime');
2157
+			$tickets = $datetime->get_many_related('Ticket');
2158
+			foreach ($tickets as $ticket) {
2159
+				$ticket->_remove_relation_to($datetime, 'Datetime');
2160
+				$ticket->delete_related_permanently('Price');
2161
+				$ticket->delete_permanently();
2162
+			}
2163
+			$datetime->delete();
2164
+		}
2165
+		//what about related venues or terms?
2166
+		$venues = $this->_cpt_model_obj->get_many_related('Venue');
2167
+		foreach ($venues as $venue) {
2168
+			$this->_cpt_model_obj->_remove_relation_to($venue, 'Venue');
2169
+		}
2170
+		//any attached question groups?
2171
+		$question_groups = $this->_cpt_model_obj->get_many_related('Question_Group');
2172
+		if ( ! empty($question_groups)) {
2173
+			foreach ($question_groups as $question_group) {
2174
+				$this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group');
2175
+			}
2176
+		}
2177
+		//Message Template Groups
2178
+		$this->_cpt_model_obj->_remove_relations('Message_Template_Group');
2179
+		/** @type EE_Term_Taxonomy[] $term_taxonomies */
2180
+		$term_taxonomies = $this->_cpt_model_obj->term_taxonomies();
2181
+		foreach ($term_taxonomies as $term_taxonomy) {
2182
+			$this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy);
2183
+		}
2184
+		$success = $this->_cpt_model_obj->delete_permanently();
2185
+		// did it all go as planned ?
2186
+		if ($success) {
2187
+			$msg = sprintf(esc_html__('Event ID # %d has been deleted.', 'event_espresso'), $EVT_ID);
2188
+			EE_Error::add_success($msg);
2189
+		} else {
2190
+			$msg = sprintf(
2191
+				esc_html__('An error occurred. Event ID # %d could not be deleted.', 'event_espresso'),
2192
+				$EVT_ID
2193
+			);
2194
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2195
+			return false;
2196
+		}
2197
+		do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID);
2198
+		return true;
2199
+	}
2200
+
2201
+
2202
+
2203
+	/**
2204
+	 * get total number of events
2205
+	 *
2206
+	 * @access public
2207
+	 * @return int
2208
+	 */
2209
+	public function total_events()
2210
+	{
2211
+		$count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true);
2212
+		return $count;
2213
+	}
2214
+
2215
+
2216
+
2217
+	/**
2218
+	 * get total number of draft events
2219
+	 *
2220
+	 * @access public
2221
+	 * @return int
2222
+	 */
2223
+	public function total_events_draft()
2224
+	{
2225
+		$where = array(
2226
+			'status' => array('IN', array('draft', 'auto-draft')),
2227
+		);
2228
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2229
+		return $count;
2230
+	}
2231
+
2232
+
2233
+
2234
+	/**
2235
+	 * get total number of trashed events
2236
+	 *
2237
+	 * @access public
2238
+	 * @return int
2239
+	 */
2240
+	public function total_trashed_events()
2241
+	{
2242
+		$where = array(
2243
+			'status' => 'trash',
2244
+		);
2245
+		$count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true);
2246
+		return $count;
2247
+	}
2248
+
2249
+
2250
+
2251
+	/**
2252
+	 *    _default_event_settings
2253
+	 *    This generates the Default Settings Tab
2254
+	 *
2255
+	 * @return void
2256
+	 */
2257
+	protected function _default_event_settings()
2258
+	{
2259
+		$this->_template_args['values'] = $this->_yes_no_values;
2260
+		$this->_template_args['reg_status_array'] = EEM_Registration::reg_status_array(
2261
+		// exclude array
2262
+			array(
2263
+				EEM_Registration::status_id_cancelled,
2264
+				EEM_Registration::status_id_declined,
2265
+				EEM_Registration::status_id_incomplete,
2266
+				EEM_Registration::status_id_wait_list,
2267
+			),
2268
+			// translated
2269
+			true
2270
+		);
2271
+		$this->_template_args['default_reg_status'] = isset(
2272
+														  EE_Registry::instance()->CFG->registration->default_STS_ID
2273
+													  )
2274
+													  && array_key_exists(
2275
+														  EE_Registry::instance()->CFG->registration->default_STS_ID,
2276
+														  $this->_template_args['reg_status_array']
2277
+													  )
2278
+			? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID)
2279
+			: EEM_Registration::status_id_pending_payment;
2280
+		$this->_set_add_edit_form_tags('update_default_event_settings');
2281
+		$this->_set_publish_post_box_vars(null, false, false, null, false);
2282
+		$this->_template_args['admin_page_content'] = EEH_Template::display_template(
2283
+			EVENTS_TEMPLATE_PATH . 'event_settings.template.php',
2284
+			$this->_template_args,
2285
+			true
2286
+		);
2287
+		$this->display_admin_page_with_sidebar();
2288
+	}
2289
+
2290
+
2291
+
2292
+	/**
2293
+	 * _update_default_event_settings
2294
+	 *
2295
+	 * @access protected
2296
+	 * @return void
2297
+	 */
2298
+	protected function _update_default_event_settings()
2299
+	{
2300
+		EE_Config::instance()->registration->default_STS_ID = isset($this->_req_data['default_reg_status'])
2301
+			? sanitize_text_field($this->_req_data['default_reg_status'])
2302
+			: EEM_Registration::status_id_pending_payment;
2303
+		$what = 'Default Event Settings';
2304
+		$success = $this->_update_espresso_configuration(
2305
+			$what,
2306
+			EE_Config::instance(),
2307
+			__FILE__,
2308
+			__FUNCTION__,
2309
+			__LINE__
2310
+		);
2311
+		$this->_redirect_after_action($success, $what, 'updated', array('action' => 'default_event_settings'));
2312
+	}
2313
+
2314
+
2315
+
2316
+	/*************        Templates        *************/
2317
+	protected function _template_settings()
2318
+	{
2319
+		$this->_admin_page_title = esc_html__('Template Settings (Preview)', 'event_espresso');
2320
+		$this->_template_args['preview_img'] = '<img src="'
2321
+											   . EVENTS_ASSETS_URL
2322
+											   . DS
2323
+											   . 'images'
2324
+											   . DS
2325
+											   . 'caffeinated_template_features.jpg" alt="'
2326
+											   . esc_attr__('Template Settings Preview screenshot', 'event_espresso')
2327
+											   . '" />';
2328
+		$this->_template_args['preview_text'] = '<strong>' . esc_html__(
2329
+				'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.',
2330
+				'event_espresso'
2331
+			) . '</strong>';
2332
+		$this->display_admin_caf_preview_page('template_settings_tab');
2333
+	}
2334
+
2335
+
2336
+	/** Event Category Stuff **/
2337
+	/**
2338
+	 * set the _category property with the category object for the loaded page.
2339
+	 *
2340
+	 * @access private
2341
+	 * @return void
2342
+	 */
2343
+	private function _set_category_object()
2344
+	{
2345
+		if (isset($this->_category->id) && ! empty($this->_category->id)) {
2346
+			return;
2347
+		} //already have the category object so get out.
2348
+		//set default category object
2349
+		$this->_set_empty_category_object();
2350
+		//only set if we've got an id
2351
+		if ( ! isset($this->_req_data['EVT_CAT_ID'])) {
2352
+			return;
2353
+		}
2354
+		$category_id = absint($this->_req_data['EVT_CAT_ID']);
2355
+		$term = get_term($category_id, 'espresso_event_categories');
2356
+		if ( ! empty($term)) {
2357
+			$this->_category->category_name = $term->name;
2358
+			$this->_category->category_identifier = $term->slug;
2359
+			$this->_category->category_desc = $term->description;
2360
+			$this->_category->id = $term->term_id;
2361
+			$this->_category->parent = $term->parent;
2362
+		}
2363
+	}
2364
+
2365
+
2366
+
2367
+	private function _set_empty_category_object()
2368
+	{
2369
+		$this->_category = new stdClass();
2370
+		$this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = '';
2371
+		$this->_category->id = $this->_category->parent = 0;
2372
+	}
2373
+
2374
+
2375
+
2376
+	protected function _category_list_table()
2377
+	{
2378
+		do_action('AHEE_log', __FILE__, __FUNCTION__, '');
2379
+		$this->_search_btn_label = esc_html__('Categories', 'event_espresso');
2380
+		$this->_admin_page_title .= ' ' . $this->get_action_link_or_button(
2381
+				'add_category',
2382
+				'add_category',
2383
+				array(),
2384
+				'add-new-h2'
2385
+			);
2386
+		$this->display_admin_list_table_page_with_sidebar();
2387
+	}
2388
+
2389
+
2390
+
2391
+	/**
2392
+	 * @param $view
2393
+	 */
2394
+	protected function _category_details($view)
2395
+	{
2396
+		//load formatter helper
2397
+		//load field generator helper
2398
+		$route = $view == 'edit' ? 'update_category' : 'insert_category';
2399
+		$this->_set_add_edit_form_tags($route);
2400
+		$this->_set_category_object();
2401
+		$id = ! empty($this->_category->id) ? $this->_category->id : '';
2402
+		$delete_action = 'delete_category';
2403
+		//custom redirect
2404
+		$redirect = EE_Admin_Page::add_query_args_and_nonce(
2405
+			array('action' => 'category_list'),
2406
+			$this->_admin_base_url
2407
+		);
2408
+		$this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect);
2409
+		//take care of contents
2410
+		$this->_template_args['admin_page_content'] = $this->_category_details_content();
2411
+		$this->display_admin_page_with_sidebar();
2412
+	}
2413
+
2414
+
2415
+
2416
+	/**
2417
+	 * @return mixed
2418
+	 */
2419
+	protected function _category_details_content()
2420
+	{
2421
+		$editor_args['category_desc'] = array(
2422
+			'type'          => 'wp_editor',
2423
+			'value'         => EEH_Formatter::admin_format_content($this->_category->category_desc),
2424
+			'class'         => 'my_editor_custom',
2425
+			'wpeditor_args' => array('media_buttons' => false),
2426
+		);
2427
+		$_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array');
2428
+		$all_terms = get_terms(
2429
+			array('espresso_event_categories'),
2430
+			array('hide_empty' => 0, 'exclude' => array($this->_category->id))
2431
+		);
2432
+		//setup category select for term parents.
2433
+		$category_select_values[] = array(
2434
+			'text' => esc_html__('No Parent', 'event_espresso'),
2435
+			'id'   => 0,
2436
+		);
2437
+		foreach ($all_terms as $term) {
2438
+			$category_select_values[] = array(
2439
+				'text' => $term->name,
2440
+				'id'   => $term->term_id,
2441
+			);
2442
+		}
2443
+		$category_select = EEH_Form_Fields::select_input(
2444
+			'category_parent',
2445
+			$category_select_values,
2446
+			$this->_category->parent
2447
+		);
2448
+		$template_args = array(
2449
+			'category'                 => $this->_category,
2450
+			'category_select'          => $category_select,
2451
+			'unique_id_info_help_link' => $this->_get_help_tab_link('unique_id_info'),
2452
+			'category_desc_editor'     => $_wp_editor['category_desc']['field'],
2453
+			'disable'                  => '',
2454
+			'disabled_message'         => false,
2455
+		);
2456
+		$template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php';
2457
+		return EEH_Template::display_template($template, $template_args, true);
2458
+	}
2459
+
2460
+
2461
+
2462
+	protected function _delete_categories()
2463
+	{
2464
+		$cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array)$this->_req_data['EVT_CAT_ID']
2465
+			: (array)$this->_req_data['category_id'];
2466
+		foreach ($cat_ids as $cat_id) {
2467
+			$this->_delete_category($cat_id);
2468
+		}
2469
+		//doesn't matter what page we're coming from... we're going to the same place after delete.
2470
+		$query_args = array(
2471
+			'action' => 'category_list',
2472
+		);
2473
+		$this->_redirect_after_action(0, '', '', $query_args);
2474
+	}
2475
+
2476
+
2477
+
2478
+	/**
2479
+	 * @param $cat_id
2480
+	 */
2481
+	protected function _delete_category($cat_id)
2482
+	{
2483
+		$cat_id = absint($cat_id);
2484
+		wp_delete_term($cat_id, 'espresso_event_categories');
2485
+	}
2486
+
2487
+
2488
+
2489
+	/**
2490
+	 * @param $new_category
2491
+	 */
2492
+	protected function _insert_or_update_category($new_category)
2493
+	{
2494
+		$cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(true);
2495
+		$success = 0; //we already have a success message so lets not send another.
2496
+		if ($cat_id) {
2497
+			$query_args = array(
2498
+				'action'     => 'edit_category',
2499
+				'EVT_CAT_ID' => $cat_id,
2500
+			);
2501
+		} else {
2502
+			$query_args = array('action' => 'add_category');
2503
+		}
2504
+		$this->_redirect_after_action($success, '', '', $query_args, true);
2505
+	}
2506
+
2507
+
2508
+
2509
+	/**
2510
+	 * @param bool $update
2511
+	 * @return bool|mixed|string
2512
+	 */
2513
+	private function _insert_category($update = false)
2514
+	{
2515
+		$cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : '';
2516
+		$category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : '';
2517
+		$category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : '';
2518
+		$category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0;
2519
+		if (empty($category_name)) {
2520
+			$msg = esc_html__('You must add a name for the category.', 'event_espresso');
2521
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2522
+			return false;
2523
+		}
2524
+		$term_args = array(
2525
+			'name'        => $category_name,
2526
+			'description' => $category_desc,
2527
+			'parent'      => $category_parent,
2528
+		);
2529
+		//was the category_identifier input disabled?
2530
+		if (isset($this->_req_data['category_identifier'])) {
2531
+			$term_args['slug'] = $this->_req_data['category_identifier'];
2532
+		}
2533
+		$insert_ids = $update
2534
+			? wp_update_term($cat_id, 'espresso_event_categories', $term_args)
2535
+			: wp_insert_term($category_name, 'espresso_event_categories', $term_args);
2536
+		if ( ! is_array($insert_ids)) {
2537
+			$msg = esc_html__(
2538
+				'An error occurred and the category has not been saved to the database.',
2539
+				'event_espresso'
2540
+			);
2541
+			EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__);
2542
+		} else {
2543
+			$cat_id = $insert_ids['term_id'];
2544
+			$msg = sprintf(esc_html__('The category %s was successfully saved', 'event_espresso'), $category_name);
2545
+			EE_Error::add_success($msg);
2546
+		}
2547
+		return $cat_id;
2548
+	}
2549
+
2550
+
2551
+
2552
+	/**
2553
+	 * @param int  $per_page
2554
+	 * @param int  $current_page
2555
+	 * @param bool $count
2556
+	 * @return \EE_Base_Class[]|int
2557
+	 */
2558
+	public function get_categories($per_page = 10, $current_page = 1, $count = false)
2559
+	{
2560
+		//testing term stuff
2561
+		$orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id';
2562
+		$order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
2563
+		$limit = ($current_page - 1) * $per_page;
2564
+		$where = array('taxonomy' => 'espresso_event_categories');
2565
+		if (isset($this->_req_data['s'])) {
2566
+			$sstr = '%' . $this->_req_data['s'] . '%';
2567
+			$where['OR'] = array(
2568
+				'Term.name'   => array('LIKE', $sstr),
2569
+				'description' => array('LIKE', $sstr),
2570
+			);
2571
+		}
2572
+		$query_params = array(
2573
+			$where,
2574
+			'order_by'   => array($orderby => $order),
2575
+			'limit'      => $limit . ',' . $per_page,
2576
+			'force_join' => array('Term'),
2577
+		);
2578
+		$categories = $count
2579
+			? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id')
2580
+			: EEM_Term_Taxonomy::instance()->get_all($query_params);
2581
+		return $categories;
2582
+	}
2583
+
2584
+
2585
+
2586
+	/* end category stuff */
2587
+	/**************/
2588 2588
 }
2589 2589
 //end class Events_Admin_Page
Please login to merge, or discard this patch.
modules/ticket_selector/TicketSelectorStandard.php 1 patch
Indentation   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -17,118 +17,118 @@
 block discarded – undo
17 17
 class TicketSelectorStandard extends TicketSelector
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $date_format
22
-     */
23
-    protected $date_format;
24
-
25
-    /**
26
-     * @var string $time_format
27
-     */
28
-    protected $time_format;
29
-
30
-    /**
31
-     * @var \EE_Ticket_Selector_Config $ticket_selector_config
32
-     */
33
-    protected $ticket_selector_config;
34
-
35
-    /**
36
-     * @var \EE_Tax_Config $tax_config
37
-     */
38
-    protected $tax_config;
39
-
40
-
41
-
42
-    /**
43
-     * TicketSelectorSimple constructor.
44
-     *
45
-     * @param \EE_Event                  $event
46
-     * @param \EE_Ticket[]               $tickets
47
-     * @param int                        $max_attendees
48
-     * @param array                      $template_args
49
-     * @param string                     $date_format
50
-     * @param string                     $time_format
51
-     * @param \EE_Ticket_Selector_Config $ticket_selector_config
52
-     * @param \EE_Tax_Config             $tax_config
53
-     */
54
-    public function __construct(
55
-        \EE_Event $event,
56
-        array $tickets,
57
-        $max_attendees,
58
-        array $template_args,
59
-        $date_format = 'Y-m-d',
60
-        $time_format = 'g:i a',
61
-        \EE_Ticket_Selector_Config $ticket_selector_config = null,
62
-        \EE_Tax_Config $tax_config = null
63
-    ) {
64
-        $this->date_format = $date_format;
65
-        $this->time_format = $time_format;
66
-        // get EE_Ticket_Selector_Config and TicketDetails
67
-        $this->ticket_selector_config = isset (\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector)
68
-            ? \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector
69
-            : new \EE_Ticket_Selector_Config();
70
-        // $template_settings->setDatetimeSelectorThreshold(2);
71
-        // \EEH_Debug_Tools::printr($template_settings->getShowDatetimeSelector(), 'getShowDatetimeSelector', __FILE__, __LINE__);
72
-        // \EEH_Debug_Tools::printr($template_settings->getDatetimeSelectorThreshold(), 'getDatetimeSelectorThreshold', __FILE__, __LINE__);
73
-        $this->tax_config = isset (\EE_Registry::instance()->CFG->tax_settings)
74
-            ? \EE_Registry::instance()->CFG->tax_settings
75
-            : new \EE_Tax_Config();
76
-        parent::__construct($event, $tickets, $max_attendees, $template_args);
77
-    }
78
-
79
-
80
-
81
-    /**
82
-     * sets any and all template args that are required for this Ticket Selector
83
-     *
84
-     * @return void
85
-     * @throws \EE_Error
86
-     */
87
-    protected function addTemplateArgs()
88
-    {
89
-        $row = 1;
90
-        $ticket_row_html = '';
91
-        $required_ticket_sold_out = false;
92
-        // flag to indicate that at least one taxable ticket has been encountered
93
-        $taxable_tickets = false;
94
-        $datetime_selector = new DatetimeSelector(
95
-            $this->event,
96
-            $this->tickets,
97
-            $this->ticket_selector_config,
98
-            $this->date_format,
99
-            $this->time_format
100
-        );
101
-        // loop through tickets
102
-        foreach ($this->tickets as $TKT_ID => $ticket) {
103
-            if ($ticket instanceof \EE_Ticket) {
104
-                $cols = 2;
105
-                $taxable_tickets = $ticket->taxable() ? true : $taxable_tickets;
106
-                $ticket_selector_row = new TicketSelectorRowStandard(
107
-                    $ticket,
108
-                    new TicketDetails($ticket, $this->ticket_selector_config, $this->template_args),
109
-                    $this->ticket_selector_config,
110
-                    $this->tax_config,
111
-                    $this->max_attendees,
112
-                    $row,
113
-                    $cols,
114
-                    $required_ticket_sold_out,
115
-                    $this->template_args['event_status'],
116
-                    $this->template_args['date_format'],
117
-                    $datetime_selector->getTicketDatetimeClasses($ticket)
118
-                );
119
-                $ticket_row_html .= $ticket_selector_row->getHtml();
120
-                $required_ticket_sold_out = $ticket_selector_row->getRequiredTicketSoldOut();
121
-                $row++;
122
-            }
123
-        }
124
-        $this->template_args['row'] = $row;
125
-        $this->template_args['ticket_row_html'] = $ticket_row_html;
126
-        $this->template_args['taxable_tickets'] = $taxable_tickets;
127
-        $this->template_args['datetime_selector'] = $datetime_selector->getDatetimeSelector();
128
-        $this->template_args['prices_displayed_including_taxes'] = $this->tax_config->prices_displayed_including_taxes;
129
-        $this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'standard_ticket_selector.template.php';
130
-        remove_all_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector');
131
-    }
20
+	/**
21
+	 * @var string $date_format
22
+	 */
23
+	protected $date_format;
24
+
25
+	/**
26
+	 * @var string $time_format
27
+	 */
28
+	protected $time_format;
29
+
30
+	/**
31
+	 * @var \EE_Ticket_Selector_Config $ticket_selector_config
32
+	 */
33
+	protected $ticket_selector_config;
34
+
35
+	/**
36
+	 * @var \EE_Tax_Config $tax_config
37
+	 */
38
+	protected $tax_config;
39
+
40
+
41
+
42
+	/**
43
+	 * TicketSelectorSimple constructor.
44
+	 *
45
+	 * @param \EE_Event                  $event
46
+	 * @param \EE_Ticket[]               $tickets
47
+	 * @param int                        $max_attendees
48
+	 * @param array                      $template_args
49
+	 * @param string                     $date_format
50
+	 * @param string                     $time_format
51
+	 * @param \EE_Ticket_Selector_Config $ticket_selector_config
52
+	 * @param \EE_Tax_Config             $tax_config
53
+	 */
54
+	public function __construct(
55
+		\EE_Event $event,
56
+		array $tickets,
57
+		$max_attendees,
58
+		array $template_args,
59
+		$date_format = 'Y-m-d',
60
+		$time_format = 'g:i a',
61
+		\EE_Ticket_Selector_Config $ticket_selector_config = null,
62
+		\EE_Tax_Config $tax_config = null
63
+	) {
64
+		$this->date_format = $date_format;
65
+		$this->time_format = $time_format;
66
+		// get EE_Ticket_Selector_Config and TicketDetails
67
+		$this->ticket_selector_config = isset (\EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector)
68
+			? \EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector
69
+			: new \EE_Ticket_Selector_Config();
70
+		// $template_settings->setDatetimeSelectorThreshold(2);
71
+		// \EEH_Debug_Tools::printr($template_settings->getShowDatetimeSelector(), 'getShowDatetimeSelector', __FILE__, __LINE__);
72
+		// \EEH_Debug_Tools::printr($template_settings->getDatetimeSelectorThreshold(), 'getDatetimeSelectorThreshold', __FILE__, __LINE__);
73
+		$this->tax_config = isset (\EE_Registry::instance()->CFG->tax_settings)
74
+			? \EE_Registry::instance()->CFG->tax_settings
75
+			: new \EE_Tax_Config();
76
+		parent::__construct($event, $tickets, $max_attendees, $template_args);
77
+	}
78
+
79
+
80
+
81
+	/**
82
+	 * sets any and all template args that are required for this Ticket Selector
83
+	 *
84
+	 * @return void
85
+	 * @throws \EE_Error
86
+	 */
87
+	protected function addTemplateArgs()
88
+	{
89
+		$row = 1;
90
+		$ticket_row_html = '';
91
+		$required_ticket_sold_out = false;
92
+		// flag to indicate that at least one taxable ticket has been encountered
93
+		$taxable_tickets = false;
94
+		$datetime_selector = new DatetimeSelector(
95
+			$this->event,
96
+			$this->tickets,
97
+			$this->ticket_selector_config,
98
+			$this->date_format,
99
+			$this->time_format
100
+		);
101
+		// loop through tickets
102
+		foreach ($this->tickets as $TKT_ID => $ticket) {
103
+			if ($ticket instanceof \EE_Ticket) {
104
+				$cols = 2;
105
+				$taxable_tickets = $ticket->taxable() ? true : $taxable_tickets;
106
+				$ticket_selector_row = new TicketSelectorRowStandard(
107
+					$ticket,
108
+					new TicketDetails($ticket, $this->ticket_selector_config, $this->template_args),
109
+					$this->ticket_selector_config,
110
+					$this->tax_config,
111
+					$this->max_attendees,
112
+					$row,
113
+					$cols,
114
+					$required_ticket_sold_out,
115
+					$this->template_args['event_status'],
116
+					$this->template_args['date_format'],
117
+					$datetime_selector->getTicketDatetimeClasses($ticket)
118
+				);
119
+				$ticket_row_html .= $ticket_selector_row->getHtml();
120
+				$required_ticket_sold_out = $ticket_selector_row->getRequiredTicketSoldOut();
121
+				$row++;
122
+			}
123
+		}
124
+		$this->template_args['row'] = $row;
125
+		$this->template_args['ticket_row_html'] = $ticket_row_html;
126
+		$this->template_args['taxable_tickets'] = $taxable_tickets;
127
+		$this->template_args['datetime_selector'] = $datetime_selector->getDatetimeSelector();
128
+		$this->template_args['prices_displayed_including_taxes'] = $this->tax_config->prices_displayed_including_taxes;
129
+		$this->template_args['template_path'] = TICKET_SELECTOR_TEMPLATES_PATH . 'standard_ticket_selector.template.php';
130
+		remove_all_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector');
131
+	}
132 132
 
133 133
 
134 134
 
Please login to merge, or discard this patch.
modules/ticket_selector/DatetimeSelector.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -16,175 +16,175 @@
 block discarded – undo
16 16
 class DatetimeSelector
17 17
 {
18 18
 
19
-    /**
20
-     * @var \EE_Event $event
21
-     */
22
-    protected $event;
23
-
24
-    /**
25
-     * @var \EE_Ticket[] $tickets
26
-     */
27
-    protected $tickets;
28
-
29
-    /**
30
-     * @var \EE_Datetime[] $datetimes
31
-     */
32
-    protected $datetimes;
33
-
34
-    /**
35
-     * @var \EE_Datetime[] $unique_dates
36
-     */
37
-    protected $unique_dates;
38
-
39
-    /**
40
-     * @var \EE_Ticket_Selector_Config $template_settings
41
-     */
42
-    protected $template_settings;
43
-
44
-    /**
45
-     * @var boolean $active
46
-     */
47
-    protected $active = false;
48
-
49
-
50
-
51
-    /**
52
-     * DatetimeSelector constructor.
53
-     *
54
-     * @param \EE_Event                  $event
55
-     * @param \EE_Ticket[]               $tickets
56
-     * @param \EE_Ticket_Selector_Config $template_settings
57
-     * @param string                     $date_format
58
-     * @param string                     $time_format
59
-     * @throws \EE_Error
60
-     */
61
-    public function __construct(
62
-        \EE_Event $event,
63
-        array $tickets,
64
-        \EE_Ticket_Selector_Config $template_settings,
65
-        $date_format = 'Y-m-d',
66
-        $time_format = 'g:i a'
67
-    ) {
68
-        $this->event = $event;
69
-        $this->tickets = $tickets;
70
-        $this->template_settings = $template_settings;
71
-        $this->datetimes = $this->getAllDatetimesForAllTicket($tickets);
72
-        $this->unique_dates = $this->getUniqueDatetimeOptions($date_format, $time_format);
73
-        $this->active = $this->template_settings->showDatetimeSelector($this->unique_dates);
74
-    }
75
-
76
-
77
-
78
-    /**
79
-     * @param \EE_Ticket[] $tickets
80
-     * @return array
81
-     * @throws \EE_Error
82
-     */
83
-    protected function getAllDatetimesForAllTicket($tickets = array())
84
-    {
85
-        $datetimes = array();
86
-        foreach ($tickets as $ticket) {
87
-            $datetimes = $this->getTicketDatetimes($ticket, $datetimes);
88
-        }
89
-        return $datetimes;
90
-    }
91
-
92
-
93
-
94
-    /**
95
-     * @param \EE_Ticket      $ticket
96
-     * @param  \EE_Datetime[] $datetimes
97
-     * @return \EE_Datetime[]
98
-     * @throws \EE_Error
99
-     */
100
-    protected function getTicketDatetimes(\EE_Ticket $ticket, $datetimes = array())
101
-    {
102
-        $ticket_datetimes = $ticket->datetimes(
103
-            array(
104
-                'order_by'                 => array(
105
-                    'DTT_order'     => 'ASC',
106
-                    'DTT_EVT_start' => 'ASC'
107
-                ),
108
-                'default_where_conditions' => 'none',
109
-            )
110
-        );
111
-        foreach ($ticket_datetimes as $ticket_datetime) {
112
-            if ( ! $ticket_datetime instanceof \EE_Datetime) {
113
-                continue;
114
-            }
115
-            $datetimes[ $ticket_datetime->ID() ] = $ticket_datetime;
116
-        }
117
-        return $datetimes;
118
-    }
119
-
120
-
121
-
122
-    /**
123
-     * @param \EE_Ticket                 $ticket
124
-     * @return string
125
-     * @throws \EE_Error
126
-     */
127
-    public function getTicketDatetimeClasses( \EE_Ticket $ticket ) {
128
-        if ( ! $this->active) {
129
-            return '';
130
-        }
131
-        $ticket_datetimes = $this->getTicketDatetimes($ticket);
132
-        $classes = '';
133
-        foreach ($this->datetimes as $datetime) {
134
-            if ( ! $datetime instanceof \EE_Datetime || ! in_array($datetime, $ticket_datetimes, true)) {
135
-                continue;
136
-            }
137
-            $classes .= ' ee-ticket-datetimes-' . $datetime->date_and_time_range('Y_m_d', 'H_i', '-', '_');
138
-        }
139
-        return $classes;
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * @param string $date_format
146
-     * @param string $time_format
147
-     * @return array
148
-     * @throws \EE_Error
149
-     */
150
-    public function getUniqueDatetimeOptions($date_format = 'Y-m-d', $time_format = 'g:i a') {
151
-        $datetime_options = array();
152
-        foreach ($this->datetimes as $datetime) {
153
-            if ( ! $datetime instanceof \EE_Datetime) {
154
-                continue;
155
-            }
156
-            $datetime_options[$datetime->date_and_time_range('Y_m_d', 'H_i', '-', '_')] =
157
-                $datetime->date_and_time_range($date_format, $time_format, ' - ');
158
-        }
159
-        return $datetime_options;
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * @return string
166
-     * @throws \EE_Error
167
-     */
168
-    public function getDatetimeSelector() {
169
-        if ( ! $this->active) {
170
-            return '';
171
-        }
172
-        $dropdown_selector = new \EE_Checkbox_Dropdown_Selector_Input(
173
-            $this->unique_dates,
174
-            array(
175
-                'html_id'               => 'datetime-selector-' . $this->event->ID(),
176
-                'html_name'             => 'datetime_selector_' . $this->event->ID(),
177
-                'html_class'            => 'datetime-selector',
178
-                'select_button_text'       => '<span class="dashicons dashicons-calendar-alt"></span> '
179
-                                            . esc_html__('Filter by Date', 'event_espresso'),
180
-                'other_html_attributes' => ' data-tkt_slctr_evt="' . $this->event->ID() . '"',
181
-            )
182
-        );
183
-        return \EEH_HTML::div(
184
-            $dropdown_selector->get_html_for_input(),
185
-            '', 'datetime_selector-dv'
186
-        );
187
-    }
19
+	/**
20
+	 * @var \EE_Event $event
21
+	 */
22
+	protected $event;
23
+
24
+	/**
25
+	 * @var \EE_Ticket[] $tickets
26
+	 */
27
+	protected $tickets;
28
+
29
+	/**
30
+	 * @var \EE_Datetime[] $datetimes
31
+	 */
32
+	protected $datetimes;
33
+
34
+	/**
35
+	 * @var \EE_Datetime[] $unique_dates
36
+	 */
37
+	protected $unique_dates;
38
+
39
+	/**
40
+	 * @var \EE_Ticket_Selector_Config $template_settings
41
+	 */
42
+	protected $template_settings;
43
+
44
+	/**
45
+	 * @var boolean $active
46
+	 */
47
+	protected $active = false;
48
+
49
+
50
+
51
+	/**
52
+	 * DatetimeSelector constructor.
53
+	 *
54
+	 * @param \EE_Event                  $event
55
+	 * @param \EE_Ticket[]               $tickets
56
+	 * @param \EE_Ticket_Selector_Config $template_settings
57
+	 * @param string                     $date_format
58
+	 * @param string                     $time_format
59
+	 * @throws \EE_Error
60
+	 */
61
+	public function __construct(
62
+		\EE_Event $event,
63
+		array $tickets,
64
+		\EE_Ticket_Selector_Config $template_settings,
65
+		$date_format = 'Y-m-d',
66
+		$time_format = 'g:i a'
67
+	) {
68
+		$this->event = $event;
69
+		$this->tickets = $tickets;
70
+		$this->template_settings = $template_settings;
71
+		$this->datetimes = $this->getAllDatetimesForAllTicket($tickets);
72
+		$this->unique_dates = $this->getUniqueDatetimeOptions($date_format, $time_format);
73
+		$this->active = $this->template_settings->showDatetimeSelector($this->unique_dates);
74
+	}
75
+
76
+
77
+
78
+	/**
79
+	 * @param \EE_Ticket[] $tickets
80
+	 * @return array
81
+	 * @throws \EE_Error
82
+	 */
83
+	protected function getAllDatetimesForAllTicket($tickets = array())
84
+	{
85
+		$datetimes = array();
86
+		foreach ($tickets as $ticket) {
87
+			$datetimes = $this->getTicketDatetimes($ticket, $datetimes);
88
+		}
89
+		return $datetimes;
90
+	}
91
+
92
+
93
+
94
+	/**
95
+	 * @param \EE_Ticket      $ticket
96
+	 * @param  \EE_Datetime[] $datetimes
97
+	 * @return \EE_Datetime[]
98
+	 * @throws \EE_Error
99
+	 */
100
+	protected function getTicketDatetimes(\EE_Ticket $ticket, $datetimes = array())
101
+	{
102
+		$ticket_datetimes = $ticket->datetimes(
103
+			array(
104
+				'order_by'                 => array(
105
+					'DTT_order'     => 'ASC',
106
+					'DTT_EVT_start' => 'ASC'
107
+				),
108
+				'default_where_conditions' => 'none',
109
+			)
110
+		);
111
+		foreach ($ticket_datetimes as $ticket_datetime) {
112
+			if ( ! $ticket_datetime instanceof \EE_Datetime) {
113
+				continue;
114
+			}
115
+			$datetimes[ $ticket_datetime->ID() ] = $ticket_datetime;
116
+		}
117
+		return $datetimes;
118
+	}
119
+
120
+
121
+
122
+	/**
123
+	 * @param \EE_Ticket                 $ticket
124
+	 * @return string
125
+	 * @throws \EE_Error
126
+	 */
127
+	public function getTicketDatetimeClasses( \EE_Ticket $ticket ) {
128
+		if ( ! $this->active) {
129
+			return '';
130
+		}
131
+		$ticket_datetimes = $this->getTicketDatetimes($ticket);
132
+		$classes = '';
133
+		foreach ($this->datetimes as $datetime) {
134
+			if ( ! $datetime instanceof \EE_Datetime || ! in_array($datetime, $ticket_datetimes, true)) {
135
+				continue;
136
+			}
137
+			$classes .= ' ee-ticket-datetimes-' . $datetime->date_and_time_range('Y_m_d', 'H_i', '-', '_');
138
+		}
139
+		return $classes;
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * @param string $date_format
146
+	 * @param string $time_format
147
+	 * @return array
148
+	 * @throws \EE_Error
149
+	 */
150
+	public function getUniqueDatetimeOptions($date_format = 'Y-m-d', $time_format = 'g:i a') {
151
+		$datetime_options = array();
152
+		foreach ($this->datetimes as $datetime) {
153
+			if ( ! $datetime instanceof \EE_Datetime) {
154
+				continue;
155
+			}
156
+			$datetime_options[$datetime->date_and_time_range('Y_m_d', 'H_i', '-', '_')] =
157
+				$datetime->date_and_time_range($date_format, $time_format, ' - ');
158
+		}
159
+		return $datetime_options;
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * @return string
166
+	 * @throws \EE_Error
167
+	 */
168
+	public function getDatetimeSelector() {
169
+		if ( ! $this->active) {
170
+			return '';
171
+		}
172
+		$dropdown_selector = new \EE_Checkbox_Dropdown_Selector_Input(
173
+			$this->unique_dates,
174
+			array(
175
+				'html_id'               => 'datetime-selector-' . $this->event->ID(),
176
+				'html_name'             => 'datetime_selector_' . $this->event->ID(),
177
+				'html_class'            => 'datetime-selector',
178
+				'select_button_text'       => '<span class="dashicons dashicons-calendar-alt"></span> '
179
+											. esc_html__('Filter by Date', 'event_espresso'),
180
+				'other_html_attributes' => ' data-tkt_slctr_evt="' . $this->event->ID() . '"',
181
+			)
182
+		);
183
+		return \EEH_HTML::div(
184
+			$dropdown_selector->get_html_for_input(),
185
+			'', 'datetime_selector-dv'
186
+		);
187
+	}
188 188
 
189 189
 
190 190
 
Please login to merge, or discard this patch.